pharaoh
Version:
ABANDONED. A desktop app for the Pharaoh live programming tool.
2 lines • 426 kB
JavaScript
!function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)return define([],e);(this||window).CodeMirror=e()}}(function(){"use strict";function e(r,n){if(!(this instanceof e))return new e(r,n);this.options=n=n?Ii(n):{},Ii(Jo,n,!1),p(n);var i=n.value;"string"==typeof i&&(i=new _a(i,n.mode,null,n.lineSeparator)),this.doc=i;var o=new e.inputStyles[n.inputStyle](this),a=this.display=new t(r,i,o);a.wrapper.CodeMirror=this,c(this),s(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!Ao&&a.input.focus(),v(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,delayingBlurEvent:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,selectingText:!1,draggingText:!1,highlight:new Oi,keySeq:null,specialChars:null};var l=this;bo&&11>xo&&setTimeout(function(){l.display.input.reset(!0)},20),Dt(this),Xi(),xt(this),this.curOp.forceUpdate=!0,Zn(this,i),n.autofocus&&!Ao||l.hasFocus()?setTimeout(Wi(gr,this),20):vr(this);for(var u in ea)ea.hasOwnProperty(u)&&ea[u](this,n[u],ta);w(this),n.finishInit&&n.finishInit(this);for(var d=0;d<oa.length;++d)oa[d](this);wt(this),ko&&n.lineWrapping&&"optimizelegibility"==getComputedStyle(a.lineDiv).textRendering&&(a.lineDiv.style.textRendering="auto")}function t(e,t,r){var n=this;this.input=r,n.scrollbarFiller=Di("div",null,"CodeMirror-scrollbar-filler"),n.scrollbarFiller.setAttribute("cm-not-content","true"),n.gutterFiller=Di("div",null,"CodeMirror-gutter-filler"),n.gutterFiller.setAttribute("cm-not-content","true"),n.lineDiv=Di("div",null,"CodeMirror-code"),n.selectionDiv=Di("div",null,null,"position: relative; z-index: 1"),n.cursorDiv=Di("div",null,"CodeMirror-cursors"),n.measure=Di("div",null,"CodeMirror-measure"),n.lineMeasure=Di("div",null,"CodeMirror-measure"),n.lineSpace=Di("div",[n.measure,n.lineMeasure,n.selectionDiv,n.cursorDiv,n.lineDiv],null,"position: relative; outline: none"),n.mover=Di("div",[Di("div",[n.lineSpace],"CodeMirror-lines")],null,"position: relative"),n.sizer=Di("div",[n.mover],"CodeMirror-sizer"),n.sizerWidth=null,n.heightForcer=Di("div",null,null,"position: absolute; height: "+Na+"px; width: 1px;"),n.gutters=Di("div",null,"CodeMirror-gutters"),n.lineGutter=null,n.scroller=Di("div",[n.sizer,n.heightForcer,n.gutters],"CodeMirror-scroll"),n.scroller.setAttribute("tabIndex","-1"),n.wrapper=Di("div",[n.scrollbarFiller,n.gutterFiller,n.scroller],"CodeMirror"),bo&&8>xo&&(n.gutters.style.zIndex=-1,n.scroller.style.paddingRight=0),ko||go&&Ao||(n.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(n.wrapper):e(n.wrapper)),n.viewFrom=n.viewTo=t.first,n.reportedViewFrom=n.reportedViewTo=t.first,n.view=[],n.renderedView=null,n.externalMeasured=null,n.viewOffset=0,n.lastWrapHeight=n.lastWrapWidth=0,n.updateLineNumbers=null,n.nativeBarWidth=n.barHeight=n.barWidth=0,n.scrollbarsClipped=!1,n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null,n.alignWidgets=!1,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null,n.maxLine=null,n.maxLineLength=0,n.maxLineChanged=!1,n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null,n.shift=!1,n.selForContextMenu=null,n.activeTouch=null,r.init(n)}function r(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),n(t)}function n(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,Fe(e,100),e.state.modeGen++,e.curOp&&jt(e)}function i(e){e.options.lineWrapping?(Ya(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(Za(e.display.wrapper,"CodeMirror-wrap"),f(e)),a(e),jt(e),st(e),setTimeout(function(){y(e)},100)}function o(e){var t=yt(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/bt(e.display)-3);return function(i){if(wn(e.doc,i))return 0;var o=0;if(i.widgets)for(var a=0;a<i.widgets.length;a++)i.widgets[a].height&&(o+=i.widgets[a].height);return r?o+(Math.ceil(i.text.length/n)||1)*t:o+t}}function a(e){var t=e.doc,r=o(e);t.iter(function(e){var t=r(e);t!=e.height&&ei(e,t)})}function s(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),st(e)}function l(e){c(e),jt(e),setTimeout(function(){k(e)},20)}function c(e){var t=e.display.gutters,r=e.options.gutters;$i(t);for(var n=0;n<r.length;++n){var i=r[n],o=t.appendChild(Di("div",null,"CodeMirror-gutter "+i));"CodeMirror-linenumbers"==i&&(e.display.lineGutter=o,o.style.width=(e.display.lineNumWidth||1)+"px")}t.style.display=n?"":"none",u(e)}function u(e){var t=e.display.gutters.offsetWidth;e.display.sizer.style.marginLeft=t+"px"}function d(e){if(0==e.height)return 0;for(var t,r=e.text.length,n=e;t=mn(n);){var i=t.find(0,!0);n=i.from.line,r+=i.from.ch-i.to.ch}for(n=e;t=gn(n);){var i=t.find(0,!0);r-=n.text.length-i.from.ch,n=i.to.line,r+=n.text.length-i.to.ch}return r}function f(e){var t=e.display,r=e.doc;t.maxLine=Yn(r,r.first),t.maxLineLength=d(t.maxLine),t.maxLineChanged=!0,r.iter(function(e){var r=d(e);r>t.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function p(e){var t=zi(e.gutters,"CodeMirror-linenumbers");-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function h(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Be(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?r:0,docHeight:n,scrollHeight:n+Ge(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function m(e,t,r){this.cm=r;var n=this.vert=Di("div",[Di("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=Di("div",[Di("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(n),e(i),Aa(n,"scroll",function(){n.clientHeight&&t(n.scrollTop,"vertical")}),Aa(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedZeroWidth=!1,bo&&8>xo&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function g(){}function v(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&Za(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),Aa(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,r){"horizontal"==r?ir(t,e):nr(t,e)},t),t.display.scrollbars.addClass&&Ya(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=h(e));var r=e.display.barWidth,n=e.display.barHeight;b(e,t);for(var i=0;4>i&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&q(e),b(e,h(e)),r=e.display.barWidth,n=e.display.barHeight}function b(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function x(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-$e(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=ri(t,n),a=ri(t,i);if(r&&r.ensure){var s=r.ensure.from.line,l=r.ensure.to.line;o>s?(o=s,a=ri(t,ni(Yn(t,s))+e.wrapper.clientHeight)):Math.min(l,t.lastLine())>=a&&(o=ri(t,ni(Yn(t,l))-e.wrapper.clientHeight),a=l)}return{from:o,to:Math.max(a,o+1)}}function k(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=C(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",a=0;a<r.length;a++)if(!r[a].hidden){e.options.fixedGutter&&r[a].gutter&&(r[a].gutter.style.left=o);var s=r[a].alignable;if(s)for(var l=0;l<s.length;l++)s[l].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=n+i+"px")}}function w(e){if(!e.options.lineNumbers)return!1;var t=e.doc,r=_(e.options,t.first+t.size-1),n=e.display;if(r.length!=n.lineNumChars){var i=n.measure.appendChild(Di("div",[Di("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),o=i.firstChild.offsetWidth,a=i.offsetWidth-o;return n.lineGutter.style.width="",n.lineNumInnerWidth=Math.max(o,n.lineGutter.offsetWidth-a)+1,n.lineNumWidth=n.lineNumInnerWidth+a,n.lineNumChars=n.lineNumInnerWidth?r.length:-1,n.lineGutter.style.width=n.lineNumWidth+"px",u(e),!0}return!1}function _(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function C(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function S(e,t,r){var n=e.display;this.viewport=t,this.visible=x(n,e.doc,t),this.editorIsHidden=!n.wrapper.offsetWidth,this.wrapperHeight=n.wrapper.clientHeight,this.wrapperWidth=n.wrapper.clientWidth,this.oldDisplayWidth=Ve(e),this.force=r,this.dims=z(e),this.events=[]}function M(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=Ge(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=Ge(e)+"px",t.scrollbarsClipped=!0)}function T(e,t){var r=e.display,n=e.doc;if(t.editorIsHidden)return It(e),!1;if(!t.force&&t.visible.from>=r.viewFrom&&t.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==Rt(e))return!1;w(e)&&(It(e),t.dims=z(e));var i=n.first+n.size,o=Math.max(t.visible.from-e.options.viewportMargin,n.first),a=Math.min(i,t.visible.to+e.options.viewportMargin);r.viewFrom<o&&o-r.viewFrom<20&&(o=Math.max(n.first,r.viewFrom)),r.viewTo>a&&r.viewTo-a<20&&(a=Math.min(i,r.viewTo)),Po&&(o=xn(e.doc,o),a=kn(e.doc,a));var s=o!=r.viewFrom||a!=r.viewTo||r.lastWrapHeight!=t.wrapperHeight||r.lastWrapWidth!=t.wrapperWidth;Ht(e,o,a),r.viewOffset=ni(Yn(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var l=Rt(e);if(!s&&0==l&&!t.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var c=Ui();return l>4&&(r.lineDiv.style.display="none"),N(e,r.updateLineNumbers,t.dims),l>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,c&&Ui()!=c&&c.offsetHeight&&c.focus(),$i(r.cursorDiv),$i(r.selectionDiv),r.gutters.style.height=r.sizer.style.minHeight=0,s&&(r.lastWrapHeight=t.wrapperHeight,r.lastWrapWidth=t.wrapperWidth,Fe(e,400)),r.updateLineNumbers=null,!0}function L(e,t){for(var r=t.viewport,n=!0;(n&&e.options.lineWrapping&&t.oldDisplayWidth!=Ve(e)||(r&&null!=r.top&&(r={top:Math.min(e.doc.height+Be(e.display)-Ke(e),r.top)}),t.visible=x(e.display,e.doc,r),!(t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)))&&T(e,t);n=!1){q(e);var i=h(e);Ne(e),O(e,i),y(e,i)}t.signal(e,"update",e),(e.display.viewFrom!=e.display.reportedViewFrom||e.display.viewTo!=e.display.reportedViewTo)&&(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function A(e,t){var r=new S(e,t);if(T(e,r)){q(e),L(e,r);var n=h(e);Ne(e),O(e,n),y(e,n),r.finish()}}function O(e,t){e.display.sizer.style.minHeight=t.docHeight+"px";var r=t.docHeight+e.display.barHeight;e.display.heightForcer.style.top=r+"px",e.display.gutters.style.height=Math.max(r+Ge(e),t.clientHeight)+"px"}function q(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;n<t.view.length;n++){var i,o=t.view[n];if(!o.hidden){if(bo&&8>xo){var a=o.node.offsetTop+o.node.offsetHeight;i=a-r,r=a}else{var s=o.node.getBoundingClientRect();i=s.bottom-s.top}var l=o.line.height-i;if(2>i&&(i=yt(t)),(l>.001||-.001>l)&&(ei(o.line,i),E(o.line),o.rest))for(var c=0;c<o.rest.length;c++)E(o.rest[c])}}}function E(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.parentNode.offsetHeight}function z(e){for(var t=e.display,r={},n={},i=t.gutters.clientLeft,o=t.gutters.firstChild,a=0;o;o=o.nextSibling,++a)r[e.options.gutters[a]]=o.offsetLeft+o.clientLeft+i,n[e.options.gutters[a]]=o.clientWidth;return{fixedPos:C(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:r,gutterWidth:n,wrapperWidth:t.wrapper.clientWidth}}function N(e,t,r){function n(t){var r=t.nextSibling;return ko&&Oo&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),r}for(var i=e.display,o=e.options.lineNumbers,a=i.lineDiv,s=a.firstChild,l=i.view,c=i.viewFrom,u=0;u<l.length;u++){var d=l[u];if(d.hidden);else if(d.node&&d.node.parentNode==a){for(;s!=d.node;)s=n(s);var f=o&&null!=t&&c>=t&&d.lineNumber;d.changes&&(zi(d.changes,"gutter")>-1&&(f=!1),j(e,d,c,r)),f&&($i(d.lineNumber),d.lineNumber.appendChild(document.createTextNode(_(e.options,c)))),s=d.node.nextSibling}else{var p=$(e,d,c,r);a.insertBefore(p,s)}c+=d.size}for(;s;)s=n(s)}function j(e,t,r,n){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?F(e,t):"gutter"==o?R(e,t,r,n):"class"==o?H(t):"widget"==o&&D(e,t,n)}t.changes=null}function P(e){return e.node==e.text&&(e.node=Di("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),bo&&8>xo&&(e.node.style.zIndex=2)),e.node}function I(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=P(e);e.background=r.insertBefore(Di("div",null,t),r.firstChild)}}function W(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):Wn(e,t)}function F(e,t){var r=t.text.className,n=W(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,H(t)):r&&(t.text.className=r)}function H(e){I(e),e.line.wrapClass?P(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function R(e,t,r,n){if(t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null),t.gutterBackground&&(t.node.removeChild(t.gutterBackground),t.gutterBackground=null),t.line.gutterClass){var i=P(t);t.gutterBackground=Di("div",null,"CodeMirror-gutter-background "+t.line.gutterClass,"left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px; width: "+n.gutterTotalWidth+"px"),i.insertBefore(t.gutterBackground,t.text)}var o=t.line.gutterMarkers;if(e.options.lineNumbers||o){var i=P(t),a=t.gutter=Di("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px");if(e.display.input.setUneditable(a),i.insertBefore(a,t.text),t.line.gutterClass&&(a.className+=" "+t.line.gutterClass),!e.options.lineNumbers||o&&o["CodeMirror-linenumbers"]||(t.lineNumber=a.appendChild(Di("div",_(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+n.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),o)for(var s=0;s<e.options.gutters.length;++s){var l=e.options.gutters[s],c=o.hasOwnProperty(l)&&o[l];c&&a.appendChild(Di("div",[c],"CodeMirror-gutter-elt","left: "+n.gutterLeft[l]+"px; width: "+n.gutterWidth[l]+"px"))}}}function D(e,t,r){t.alignable&&(t.alignable=null);for(var n,i=t.node.firstChild;i;i=n){var n=i.nextSibling;"CodeMirror-linewidget"==i.className&&t.node.removeChild(i)}B(e,t,r)}function $(e,t,r,n){var i=W(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),H(t),R(e,t,r,n),B(e,t,n),t.node}function B(e,t,r){if(U(e,t.line,t,r,!0),t.rest)for(var n=0;n<t.rest.length;n++)U(e,t.rest[n],t,r,!1)}function U(e,t,r,n,i){if(t.widgets)for(var o=P(r),a=0,s=t.widgets;a<s.length;++a){var l=s[a],c=Di("div",[l.node],"CodeMirror-linewidget");l.handleMouseEvents||c.setAttribute("cm-ignore-events","true"),G(l,c,r,n),e.display.input.setUneditable(c),i&&l.above?o.insertBefore(c,r.gutter||r.text):o.appendChild(c),Ci(l,"redraw")}}function G(e,t,r,n){if(e.noHScroll){(r.alignable||(r.alignable=[])).push(t);var i=n.wrapperWidth;t.style.left=n.fixedPos+"px",e.coverGutter||(i-=n.gutterTotalWidth,t.style.paddingLeft=n.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-n.gutterTotalWidth+"px"))}function V(e){return Io(e.line,e.ch)}function K(e,t){return Wo(e,t)<0?t:e}function X(e,t){return Wo(e,t)<0?e:t}function Z(e){e.state.focused||(e.display.input.focus(),gr(e))}function Y(e,t,r,n,i){var o=e.doc;e.display.shift=!1,n||(n=o.sel);var a=e.state.pasteIncoming||"paste"==i,s=o.splitLines(t),l=null;if(a&&n.ranges.length>1)if(Fo&&Fo.join("\n")==t){if(n.ranges.length%Fo.length==0){l=[];for(var c=0;c<Fo.length;c++)l.push(o.splitLines(Fo[c]))}}else s.length==n.ranges.length&&(l=Ni(s,function(e){return[e]}));for(var c=n.ranges.length-1;c>=0;c--){var u=n.ranges[c],d=u.from(),f=u.to();u.empty()&&(r&&r>0?d=Io(d.line,d.ch-r):e.state.overwrite&&!a&&(f=Io(f.line,Math.min(Yn(o,f.line).text.length,f.ch+Ei(s).length))));var p=e.curOp.updateInput,h={from:d,to:f,text:l?l[c%l.length]:s,origin:i||(a?"paste":e.state.cutIncoming?"cut":"+input")};Sr(e.doc,h),Ci(e,"inputRead",e,h)}t&&!a&&J(e,t),Ir(e),e.curOp.updateInput=p,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function Q(e,t){var r=e.clipboardData&&e.clipboardData.getData("text/plain");return r?(e.preventDefault(),t.isReadOnly()||t.options.disableInput||At(t,function(){Y(t,r,0,null,"paste")}),!0):void 0}function J(e,t){if(e.options.electricChars&&e.options.smartIndent)for(var r=e.doc.sel,n=r.ranges.length-1;n>=0;n--){var i=r.ranges[n];if(!(i.head.ch>100||n&&r.ranges[n-1].head.line==i.head.line)){var o=e.getModeAt(i.head),a=!1;if(o.electricChars){for(var s=0;s<o.electricChars.length;s++)if(t.indexOf(o.electricChars.charAt(s))>-1){a=Fr(e,i.head.line,"smart");break}}else o.electricInput&&o.electricInput.test(Yn(e.doc,i.head.line).text.slice(0,i.head.ch))&&(a=Fr(e,i.head.line,"smart"));a&&Ci(e,"electricInput",e,i.head.line)}}}function ee(e){for(var t=[],r=[],n=0;n<e.doc.sel.ranges.length;n++){var i=e.doc.sel.ranges[n].head.line,o={anchor:Io(i,0),head:Io(i+1,0)};r.push(o),t.push(e.getRange(o.anchor,o.head))}return{text:t,ranges:r}}function te(e){e.setAttribute("autocorrect","off"),e.setAttribute("autocapitalize","off"),e.setAttribute("spellcheck","false")}function re(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new Oi,this.inaccurateSelection=!1,this.hasSelection=!1,this.composing=null}function ne(){var e=Di("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none"),t=Di("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return ko?e.style.width="1000px":e.setAttribute("wrap","off"),Lo&&(e.style.border="1px solid black"),te(e),t}function ie(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new Oi,this.gracePeriod=!1}function oe(e,t){var r=Je(e,t.line);if(!r||r.hidden)return null;var n=Yn(e.doc,t.line),i=Ze(r,n,t.line),o=ii(n),a="left";if(o){var s=co(o,t.ch);a=s%2?"right":"left"}var l=rt(i.map,t.ch,a);return l.offset="right"==l.collapse?l.end:l.start,l}function ae(e,t){return t&&(e.bad=!0),e}function se(e,t,r){var n;if(t==e.display.lineDiv){if(n=e.display.lineDiv.childNodes[r],!n)return ae(e.clipPos(Io(e.display.viewTo-1)),!0);t=null,r=0}else for(n=t;;n=n.parentNode){if(!n||n==e.display.lineDiv)return null;if(n.parentNode&&n.parentNode==e.display.lineDiv)break}for(var i=0;i<e.display.view.length;i++){var o=e.display.view[i];if(o.node==n)return le(o,t,r)}}function le(e,t,r){function n(t,r,n){for(var i=-1;i<(u?u.length:0);i++)for(var o=0>i?c.map:u[i],a=0;a<o.length;a+=3){var s=o[a+2];if(s==t||s==r){var l=ti(0>i?e.line:e.rest[i]),d=o[a]+n;return(0>n||s!=t)&&(d=o[a+(n?1:0)]),Io(l,d)}}}var i=e.text.firstChild,o=!1;if(!t||!Va(i,t))return ae(Io(ti(e.line),0),!0);if(t==i&&(o=!0,t=i.childNodes[r],r=0,!t)){var a=e.rest?Ei(e.rest):e.line;return ae(Io(ti(a),a.text.length),o)}var s=3==t.nodeType?t:null,l=t;for(s||1!=t.childNodes.length||3!=t.firstChild.nodeType||(s=t.firstChild,r&&(r=s.nodeValue.length));l.parentNode!=i;)l=l.parentNode;var c=e.measure,u=c.maps,d=n(s,l,r);if(d)return ae(d,o);for(var f=l.nextSibling,p=s?s.nodeValue.length-r:0;f;f=f.nextSibling){if(d=n(f,f.firstChild,0))return ae(Io(d.line,d.ch-p),o);p+=f.textContent.length}for(var h=l.previousSibling,p=r;h;h=h.previousSibling){if(d=n(h,h.firstChild,-1))return ae(Io(d.line,d.ch+p),o);p+=f.textContent.length}}function ce(e,t,r,n,i){function o(e){return function(t){return t.id==e}}function a(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(null!=r)return""==r&&(r=t.textContent.replace(/\u200b/g,"")),void(s+=r);var u,d=t.getAttribute("cm-marker");if(d){var f=e.findMarks(Io(n,0),Io(i+1,0),o(+d));return void(f.length&&(u=f[0].find())&&(s+=Qn(e.doc,u.from,u.to).join(c)))}if("false"==t.getAttribute("contenteditable"))return;for(var p=0;p<t.childNodes.length;p++)a(t.childNodes[p]);/^(pre|div|p)$/i.test(t.nodeName)&&(l=!0)}else if(3==t.nodeType){var h=t.nodeValue;if(!h)return;l&&(s+=c,l=!1),s+=h}}for(var s="",l=!1,c=e.doc.lineSeparator();a(t),t!=r;)t=t.nextSibling;return s}function ue(e,t){this.ranges=e,this.primIndex=t}function de(e,t){this.anchor=e,this.head=t}function fe(e,t){var r=e[t];e.sort(function(e,t){return Wo(e.from(),t.from())}),t=zi(e,r);for(var n=1;n<e.length;n++){var i=e[n],o=e[n-1];if(Wo(o.to(),i.from())>=0){var a=X(o.from(),i.from()),s=K(o.to(),i.to()),l=o.empty()?i.from()==i.head:o.from()==o.head;t>=n&&--t,e.splice(--n,2,new de(l?s:a,l?a:s))}}return new ue(e,t)}function pe(e,t){return new ue([new de(e,t||e)],0)}function he(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function me(e,t){if(t.line<e.first)return Io(e.first,0);var r=e.first+e.size-1;return t.line>r?Io(r,Yn(e,r).text.length):ge(t,Yn(e,t.line).text.length)}function ge(e,t){var r=e.ch;return null==r||r>t?Io(e.line,t):0>r?Io(e.line,0):e}function ve(e,t){return t>=e.first&&t<e.first+e.size}function ye(e,t){for(var r=[],n=0;n<t.length;n++)r[n]=me(e,t[n]);return r}function be(e,t,r,n){if(e.cm&&e.cm.display.shift||e.extend){var i=t.anchor;if(n){var o=Wo(r,i)<0;o!=Wo(n,i)<0?(i=r,r=n):o!=Wo(r,n)<0&&(r=n)}return new de(i,r)}return new de(n||r,r)}function xe(e,t,r,n){Me(e,new ue([be(e,e.sel.primary(),t,r)],0),n)}function ke(e,t,r){for(var n=[],i=0;i<e.sel.ranges.length;i++)n[i]=be(e,e.sel.ranges[i],t[i],null);var o=fe(n,e.sel.primIndex);Me(e,o,r)}function we(e,t,r,n){var i=e.sel.ranges.slice(0);i[t]=r,Me(e,fe(i,e.sel.primIndex),n)}function _e(e,t,r,n){Me(e,pe(t,r),n)}function Ce(e,t,r){var n={ranges:t.ranges,update:function(t){this.ranges=[];for(var r=0;r<t.length;r++)this.ranges[r]=new de(me(e,t[r].anchor),me(e,t[r].head))},origin:r&&r.origin};return Ea(e,"beforeSelectionChange",e,n),e.cm&&Ea(e.cm,"beforeSelectionChange",e.cm,n),n.ranges!=t.ranges?fe(n.ranges,n.ranges.length-1):t}function Se(e,t,r){var n=e.history.done,i=Ei(n);i&&i.ranges?(n[n.length-1]=t,Te(e,t,r)):Me(e,t,r)}function Me(e,t,r){Te(e,t,r),di(e,e.sel,e.cm?e.cm.curOp.id:0/0,r)}function Te(e,t,r){(Li(e,"beforeSelectionChange")||e.cm&&Li(e.cm,"beforeSelectionChange"))&&(t=Ce(e,t,r));var n=r&&r.bias||(Wo(t.primary().head,e.sel.primary().head)<0?-1:1);Le(e,Oe(e,t,n,!0)),r&&r.scroll===!1||!e.cm||Ir(e.cm)}function Le(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=!0,Ti(e.cm)),Ci(e,"cursorActivity",e))}function Ae(e){Le(e,Oe(e,e.sel,null,!1),Pa)}function Oe(e,t,r,n){for(var i,o=0;o<t.ranges.length;o++){var a=t.ranges[o],s=t.ranges.length==e.sel.ranges.length&&e.sel.ranges[o],l=Ee(e,a.anchor,s&&s.anchor,r,n),c=Ee(e,a.head,s&&s.head,r,n);(i||l!=a.anchor||c!=a.head)&&(i||(i=t.ranges.slice(0,o)),i[o]=new de(l,c))}return i?fe(i,t.primIndex):t}function qe(e,t,r,n,i){var o=Yn(e,t.line);if(o.markedSpans)for(var a=0;a<o.markedSpans.length;++a){var s=o.markedSpans[a],l=s.marker;if((null==s.from||(l.inclusiveLeft?s.from<=t.ch:s.from<t.ch))&&(null==s.to||(l.inclusiveRight?s.to>=t.ch:s.to>t.ch))){if(i&&(Ea(l,"beforeCursorEnter"),l.explicitlyCleared)){if(o.markedSpans){--a;continue}break}if(!l.atomic)continue;if(r){var c,u=l.find(0>n?1:-1);if((0>n?l.inclusiveRight:l.inclusiveLeft)&&(u=ze(e,u,-n,o)),u&&u.line==t.line&&(c=Wo(u,r))&&(0>n?0>c:c>0))return qe(e,u,t,n,i)}var d=l.find(0>n?-1:1);return(0>n?l.inclusiveLeft:l.inclusiveRight)&&(d=ze(e,d,n,o)),d?qe(e,d,t,n,i):null}}return t}function Ee(e,t,r,n,i){var o=n||1,a=qe(e,t,r,o,i)||!i&&qe(e,t,r,o,!0)||qe(e,t,r,-o,i)||!i&&qe(e,t,r,-o,!0);return a?a:(e.cantEdit=!0,Io(e.first,0))}function ze(e,t,r,n){return 0>r&&0==t.ch?t.line>e.first?me(e,Io(t.line-1)):null:r>0&&t.ch==(n||Yn(e,t.line)).text.length?t.line<e.first+e.size-1?Io(t.line+1,0):null:new Io(t.line,t.ch+r)}function Ne(e){e.display.input.showSelection(e.display.input.prepareSelection())}function je(e,t){for(var r=e.doc,n={},i=n.cursors=document.createDocumentFragment(),o=n.selection=document.createDocumentFragment(),a=0;a<r.sel.ranges.length;a++)if(t!==!1||a!=r.sel.primIndex){var s=r.sel.ranges[a],l=s.empty();(l||e.options.showCursorWhenSelecting)&&Pe(e,s.head,i),l||Ie(e,s,o)}return n}function Pe(e,t,r){var n=pt(e,t,"div",null,null,!e.options.singleCursorHeightPerLine),i=r.appendChild(Di("div"," ","CodeMirror-cursor"));if(i.style.left=n.left+"px",i.style.top=n.top+"px",i.style.height=Math.max(0,n.bottom-n.top)*e.options.cursorHeight+"px",n.other){var o=r.appendChild(Di("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));o.style.display="",o.style.left=n.other.left+"px",o.style.top=n.other.top+"px",o.style.height=.85*(n.other.bottom-n.other.top)+"px"}}function Ie(e,t,r){function n(e,t,r,n){0>t&&(t=0),t=Math.round(t),n=Math.round(n),s.appendChild(Di("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==r?u-e:r)+"px; height: "+(n-t)+"px"))}function i(t,r,i){function o(r,n){return ft(e,Io(t,r),"div",d,n)}var s,l,d=Yn(a,t),f=d.text.length;return eo(ii(d),r||0,null==i?f:i,function(e,t,a){var d,p,h,m=o(e,"left");if(e==t)d=m,p=h=m.left;else{if(d=o(t-1,"right"),"rtl"==a){var g=m;m=d,d=g}p=m.left,h=d.right}null==r&&0==e&&(p=c),d.top-m.top>3&&(n(p,m.top,null,m.bottom),p=c,m.bottom<d.top&&n(p,m.bottom,null,d.top)),null==i&&t==f&&(h=u),(!s||m.top<s.top||m.top==s.top&&m.left<s.left)&&(s=m),(!l||d.bottom>l.bottom||d.bottom==l.bottom&&d.right>l.right)&&(l=d),c+1>p&&(p=c),n(p,d.top,h-p,d.bottom)}),{start:s,end:l}}var o=e.display,a=e.doc,s=document.createDocumentFragment(),l=Ue(e.display),c=l.left,u=Math.max(o.sizerWidth,Ve(e)-o.sizer.offsetLeft)-l.right,d=t.from(),f=t.to();if(d.line==f.line)i(d.line,d.ch,f.ch);else{var p=Yn(a,d.line),h=Yn(a,f.line),m=yn(p)==yn(h),g=i(d.line,d.ch,m?p.text.length+1:null).end,v=i(f.line,m?0:null,f.ch).start;m&&(g.top<v.top-2?(n(g.right,g.top,null,g.bottom),n(c,v.top,v.left,v.bottom)):n(g.right,g.top,v.left-g.right,g.bottom)),g.bottom<v.top&&n(c,g.bottom,null,v.top)}r.appendChild(s)}function We(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var r=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function Fe(e,t){e.doc.mode.startState&&e.doc.frontier<e.display.viewTo&&e.state.highlight.set(t,Wi(He,e))}function He(e){var t=e.doc;if(t.frontier<t.first&&(t.frontier=t.first),!(t.frontier>=e.display.viewTo)){var r=+new Date+e.options.workTime,n=sa(t.mode,De(e,t.frontier)),i=[];t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var a=o.styles,s=o.text.length>e.options.maxHighlightLength,l=Nn(e,o,s?sa(t.mode,n):n,!0);o.styles=l.styles;var c=o.styleClasses,u=l.classes;u?o.styleClasses=u:c&&(o.styleClasses=null);for(var d=!a||a.length!=o.styles.length||c!=u&&(!c||!u||c.bgClass!=u.bgClass||c.textClass!=u.textClass),f=0;!d&&f<a.length;++f)d=a[f]!=o.styles[f];d&&i.push(t.frontier),o.stateAfter=s?n:sa(t.mode,n)}else o.text.length<=e.options.maxHighlightLength&&Pn(e,o.text,n),o.stateAfter=t.frontier%5==0?sa(t.mode,n):null;return++t.frontier,+new Date>r?(Fe(e,e.options.workDelay),!0):void 0}),i.length&&At(e,function(){for(var t=0;t<i.length;t++)Pt(e,i[t],"text")})}}function Re(e,t,r){for(var n,i,o=e.doc,a=r?-1:t-(e.doc.mode.innerMode?1e3:100),s=t;s>a;--s){if(s<=o.first)return o.first;var l=Yn(o,s-1);if(l.stateAfter&&(!r||s<=o.frontier))return s;var c=Fa(l.text,null,e.options.tabSize);(null==i||n>c)&&(i=s-1,n=c)}return i}function De(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=Re(e,t,r),a=o>n.first&&Yn(n,o-1).stateAfter;return a=a?sa(n.mode,a):la(n.mode),n.iter(o,t,function(r){Pn(e,r.text,a);var s=o==t-1||o%5==0||o>=i.viewFrom&&o<i.viewTo;r.stateAfter=s?sa(n.mode,a):null,++o}),r&&(n.frontier=o),a}function $e(e){return e.lineSpace.offsetTop}function Be(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Ue(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=Bi(e.measure,Di("pre","x")),r=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,n={left:parseInt(r.paddingLeft),right:parseInt(r.paddingRight)};return isNaN(n.left)||isNaN(n.right)||(e.cachedPaddingH=n),n}function Ge(e){return Na-e.display.nativeBarWidth}function Ve(e){return e.display.scroller.clientWidth-Ge(e)-e.display.barWidth}function Ke(e){return e.display.scroller.clientHeight-Ge(e)-e.display.barHeight}function Xe(e,t,r){var n=e.options.lineWrapping,i=n&&Ve(e);if(!t.measure.heights||n&&t.measure.width!=i){var o=t.measure.heights=[];if(n){t.measure.width=i;for(var a=t.text.firstChild.getClientRects(),s=0;s<a.length-1;s++){var l=a[s],c=a[s+1];Math.abs(l.bottom-c.bottom)>2&&o.push((l.bottom+c.top)/2-r.top)}}o.push(r.bottom-r.top)}}function Ze(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;n<e.rest.length;n++)if(e.rest[n]==t)return{map:e.measure.maps[n],cache:e.measure.caches[n]};for(var n=0;n<e.rest.length;n++)if(ti(e.rest[n])>r)return{map:e.measure.maps[n],cache:e.measure.caches[n],before:!0}}function Ye(e,t){t=yn(t);var r=ti(t),n=e.display.externalMeasured=new zt(e.doc,t,r);n.lineN=r;var i=n.built=Wn(e,n);return n.text=i.pre,Bi(e.display.lineMeasure,i.pre),n}function Qe(e,t,r,n){return tt(e,et(e,t),r,n)}function Je(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[Wt(e,t)];var r=e.display.externalMeasured;return r&&t>=r.lineN&&t<r.lineN+r.size?r:void 0}function et(e,t){var r=ti(t),n=Je(e,r);n&&!n.text?n=null:n&&n.changes&&(j(e,n,r,z(e)),e.curOp.forceUpdate=!0),n||(n=Ye(e,t));var i=Ze(n,t,r);return{line:t,view:n,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function tt(e,t,r,n,i){t.before&&(r=-1);var o,a=r+(n||"");return t.cache.hasOwnProperty(a)?o=t.cache[a]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(Xe(e,t.view,t.rect),t.hasHeights=!0),o=nt(e,t,r,n),o.bogus||(t.cache[a]=o)),{left:o.left,right:o.right,top:i?o.rtop:o.top,bottom:i?o.rbottom:o.bottom}}function rt(e,t,r){for(var n,i,o,a,s=0;s<e.length;s+=3){var l=e[s],c=e[s+1];if(l>t?(i=0,o=1,a="left"):c>t?(i=t-l,o=i+1):(s==e.length-3||t==c&&e[s+3]>t)&&(o=c-l,i=o-1,t>=c&&(a="right")),null!=i){if(n=e[s+2],l==c&&r==(n.insertLeft?"left":"right")&&(a=r),"left"==r&&0==i)for(;s&&e[s-2]==e[s-3]&&e[s-1].insertLeft;)n=e[(s-=3)+2],a="left";if("right"==r&&i==c-l)for(;s<e.length-3&&e[s+3]==e[s+4]&&!e[s+5].insertLeft;)n=e[(s+=3)+2],
a="right";break}}return{node:n,start:i,end:o,collapse:a,coverStart:l,coverEnd:c}}function nt(e,t,r,n){var i,o=rt(t.map,r,n),a=o.node,s=o.start,l=o.end,c=o.collapse;if(3==a.nodeType){for(var u=0;4>u;u++){for(;s&&Ri(t.line.text.charAt(o.coverStart+s));)--s;for(;o.coverStart+l<o.coverEnd&&Ri(t.line.text.charAt(o.coverStart+l));)++l;if(bo&&9>xo&&0==s&&l==o.coverEnd-o.coverStart)i=a.parentNode.getBoundingClientRect();else if(bo&&e.options.lineWrapping){var d=$a(a,s,l).getClientRects();i=d.length?d["right"==n?d.length-1:0]:$o}else i=$a(a,s,l).getBoundingClientRect()||$o;if(i.left||i.right||0==s)break;l=s,s-=1,c="right"}bo&&11>xo&&(i=it(e.display.measure,i))}else{s>0&&(c=n="right");var d;i=e.options.lineWrapping&&(d=a.getClientRects()).length>1?d["right"==n?d.length-1:0]:a.getBoundingClientRect()}if(bo&&9>xo&&!s&&(!i||!i.left&&!i.right)){var f=a.parentNode.getClientRects()[0];i=f?{left:f.left,right:f.left+bt(e.display),top:f.top,bottom:f.bottom}:$o}for(var p=i.top-t.rect.top,h=i.bottom-t.rect.top,m=(p+h)/2,g=t.view.measure.heights,u=0;u<g.length-1&&!(m<g[u]);u++);var v=u?g[u-1]:0,y=g[u],b={left:("right"==c?i.right:i.left)-t.rect.left,right:("left"==c?i.left:i.right)-t.rect.left,top:v,bottom:y};return i.left||i.right||(b.bogus=!0),e.options.singleCursorHeightPerLine||(b.rtop=p,b.rbottom=h),b}function it(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!Ji(e))return t;var r=screen.logicalXDPI/screen.deviceXDPI,n=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*r,right:t.right*r,top:t.top*n,bottom:t.bottom*n}}function ot(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function at(e){e.display.externalMeasure=null,$i(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)ot(e.display.view[t])}function st(e){at(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function lt(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function ct(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function ut(e,t,r,n){if(t.widgets)for(var i=0;i<t.widgets.length;++i)if(t.widgets[i].above){var o=Sn(t.widgets[i]);r.top+=o,r.bottom+=o}if("line"==n)return r;n||(n="local");var a=ni(t);if("local"==n?a+=$e(e.display):a-=e.display.viewOffset,"page"==n||"window"==n){var s=e.display.lineSpace.getBoundingClientRect();a+=s.top+("window"==n?0:ct());var l=s.left+("window"==n?0:lt());r.left+=l,r.right+=l}return r.top+=a,r.bottom+=a,r}function dt(e,t,r){if("div"==r)return t;var n=t.left,i=t.top;if("page"==r)n-=lt(),i-=ct();else if("local"==r||!r){var o=e.display.sizer.getBoundingClientRect();n+=o.left,i+=o.top}var a=e.display.lineSpace.getBoundingClientRect();return{left:n-a.left,top:i-a.top}}function ft(e,t,r,n,i){return n||(n=Yn(e.doc,t.line)),ut(e,n,Qe(e,n,t.ch,i),r)}function pt(e,t,r,n,i,o){function a(t,a){var s=tt(e,i,t,a?"right":"left",o);return a?s.left=s.right:s.right=s.left,ut(e,n,s,r)}function s(e,t){var r=l[t],n=r.level%2;return e==to(r)&&t&&r.level<l[t-1].level?(r=l[--t],e=ro(r)-(r.level%2?0:1),n=!0):e==ro(r)&&t<l.length-1&&r.level<l[t+1].level&&(r=l[++t],e=to(r)-r.level%2,n=!1),n&&e==r.to&&e>r.from?a(e-1):a(e,n)}n=n||Yn(e.doc,t.line),i||(i=et(e,n));var l=ii(n),c=t.ch;if(!l)return a(c);var u=co(l,c),d=s(c,u);return null!=os&&(d.other=s(c,os)),d}function ht(e,t){var r=0,t=me(e.doc,t);e.options.lineWrapping||(r=bt(e.display)*t.ch);var n=Yn(e.doc,t.line),i=ni(n)+$e(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function mt(e,t,r,n){var i=Io(e,t);return i.xRel=n,r&&(i.outside=!0),i}function gt(e,t,r){var n=e.doc;if(r+=e.display.viewOffset,0>r)return mt(n.first,0,!0,-1);var i=ri(n,r),o=n.first+n.size-1;if(i>o)return mt(n.first+n.size-1,Yn(n,o).text.length,!0,1);0>t&&(t=0);for(var a=Yn(n,i);;){var s=vt(e,a,i,t,r),l=gn(a),c=l&&l.find(0,!0);if(!l||!(s.ch>c.from.ch||s.ch==c.from.ch&&s.xRel>0))return s;i=ti(a=c.to.line)}}function vt(e,t,r,n,i){function o(n){var i=pt(e,Io(r,n),"line",t,c);return s=!0,a>i.bottom?i.left-l:a<i.top?i.left+l:(s=!1,i.left)}var a=i-ni(t),s=!1,l=2*e.display.wrapper.clientWidth,c=et(e,t),u=ii(t),d=t.text.length,f=no(t),p=io(t),h=o(f),m=s,g=o(p),v=s;if(n>g)return mt(r,p,v,1);for(;;){if(u?p==f||p==fo(t,f,1):1>=p-f){for(var y=h>n||g-n>=n-h?f:p,b=n-(y==f?h:g);Ri(t.text.charAt(y));)++y;var x=mt(r,y,y==f?m:v,-1>b?-1:b>1?1:0);return x}var k=Math.ceil(d/2),w=f+k;if(u){w=f;for(var _=0;k>_;++_)w=fo(t,w,1)}var C=o(w);C>n?(p=w,g=C,(v=s)&&(g+=1e3),d=k):(f=w,h=C,m=s,d-=k)}}function yt(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Ho){Ho=Di("pre");for(var t=0;49>t;++t)Ho.appendChild(document.createTextNode("x")),Ho.appendChild(Di("br"));Ho.appendChild(document.createTextNode("x"))}Bi(e.measure,Ho);var r=Ho.offsetHeight/50;return r>3&&(e.cachedTextHeight=r),$i(e.measure),r||1}function bt(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=Di("span","xxxxxxxxxx"),r=Di("pre",[t]);Bi(e.measure,r);var n=t.getBoundingClientRect(),i=(n.right-n.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function xt(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++Uo},Bo?Bo.ops.push(e.curOp):e.curOp.ownsGroup=Bo={ops:[e.curOp],delayedCallbacks:[]}}function kt(e){var t=e.delayedCallbacks,r=0;do{for(;r<t.length;r++)t[r].call(null);for(var n=0;n<e.ops.length;n++){var i=e.ops[n];if(i.cursorActivityHandlers)for(;i.cursorActivityCalled<i.cursorActivityHandlers.length;)i.cursorActivityHandlers[i.cursorActivityCalled++].call(null,i.cm)}}while(r<t.length)}function wt(e){var t=e.curOp,r=t.ownsGroup;if(r)try{kt(r)}finally{Bo=null;for(var n=0;n<r.ops.length;n++)r.ops[n].cm.curOp=null;_t(r)}}function _t(e){for(var t=e.ops,r=0;r<t.length;r++)Ct(t[r]);for(var r=0;r<t.length;r++)St(t[r]);for(var r=0;r<t.length;r++)Mt(t[r]);for(var r=0;r<t.length;r++)Tt(t[r]);for(var r=0;r<t.length;r++)Lt(t[r])}function Ct(e){var t=e.cm,r=t.display;M(t),e.updateMaxLine&&f(t),e.mustUpdate=e.viewChanged||e.forceUpdate||null!=e.scrollTop||e.scrollToPos&&(e.scrollToPos.from.line<r.viewFrom||e.scrollToPos.to.line>=r.viewTo)||r.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new S(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function St(e){e.updatedDisplay=e.mustUpdate&&T(e.cm,e.update)}function Mt(e){var t=e.cm,r=t.display;e.updatedDisplay&&q(t),e.barMeasure=h(t),r.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=Qe(t,r.maxLine,r.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+e.adjustWidthTo+Ge(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+e.adjustWidthTo-Ve(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=r.input.prepareSelection())}function Tt(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&ir(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1),e.preparedSelection&&t.display.input.showSelection(e.preparedSelection),e.updatedDisplay&&O(t,e.barMeasure),(e.updatedDisplay||e.startHeight!=t.doc.height)&&y(t,e.barMeasure),e.selectionChanged&&We(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing),!e.focus||e.focus!=Ui()||document.hasFocus&&!document.hasFocus()||Z(e.cm)}function Lt(e){var t=e.cm,r=t.display,n=t.doc;if(e.updatedDisplay&&L(t,e.update),null==r.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(r.wheelStartX=r.wheelStartY=null),null==e.scrollTop||r.scroller.scrollTop==e.scrollTop&&!e.forceScroll||(n.scrollTop=Math.max(0,Math.min(r.scroller.scrollHeight-r.scroller.clientHeight,e.scrollTop)),r.scrollbars.setScrollTop(n.scrollTop),r.scroller.scrollTop=n.scrollTop),null==e.scrollLeft||r.scroller.scrollLeft==e.scrollLeft&&!e.forceScroll||(n.scrollLeft=Math.max(0,Math.min(r.scroller.scrollWidth-Ve(t),e.scrollLeft)),r.scrollbars.setScrollLeft(n.scrollLeft),r.scroller.scrollLeft=n.scrollLeft,k(t)),e.scrollToPos){var i=zr(t,me(n,e.scrollToPos.from),me(n,e.scrollToPos.to),e.scrollToPos.margin);e.scrollToPos.isCursor&&t.state.focused&&Er(t,i)}var o=e.maybeHiddenMarkers,a=e.maybeUnhiddenMarkers;if(o)for(var s=0;s<o.length;++s)o[s].lines.length||Ea(o[s],"hide");if(a)for(var s=0;s<a.length;++s)a[s].lines.length&&Ea(a[s],"unhide");r.wrapper.offsetHeight&&(n.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&Ea(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function At(e,t){if(e.curOp)return t();xt(e);try{return t()}finally{wt(e)}}function Ot(e,t){return function(){if(e.curOp)return t.apply(e,arguments);xt(e);try{return t.apply(e,arguments)}finally{wt(e)}}}function qt(e){return function(){if(this.curOp)return e.apply(this,arguments);xt(this);try{return e.apply(this,arguments)}finally{wt(this)}}}function Et(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);xt(t);try{return e.apply(this,arguments)}finally{wt(t)}}}function zt(e,t,r){this.line=t,this.rest=bn(t),this.size=this.rest?ti(Ei(this.rest))-r+1:1,this.node=this.text=null,this.hidden=wn(e,t)}function Nt(e,t,r){for(var n,i=[],o=t;r>o;o=n){var a=new zt(e.doc,Yn(e.doc,o),o);n=o+a.size,i.push(a)}return i}function jt(e,t,r,n){null==t&&(t=e.doc.first),null==r&&(r=e.doc.first+e.doc.size),n||(n=0);var i=e.display;if(n&&r<i.viewTo&&(null==i.updateLineNumbers||i.updateLineNumbers>t)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Po&&xn(e.doc,t)<i.viewTo&&It(e);else if(r<=i.viewFrom)Po&&kn(e.doc,r+n)>i.viewFrom?It(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)It(e);else if(t<=i.viewFrom){var o=Ft(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):It(e)}else if(r>=i.viewTo){var o=Ft(e,t,t,-1);o?(i.view=i.view.slice(0,o.index),i.viewTo=o.lineN):It(e)}else{var a=Ft(e,t,t,-1),s=Ft(e,r,r+n,1);a&&s?(i.view=i.view.slice(0,a.index).concat(Nt(e,a.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=n):It(e)}var l=i.externalMeasured;l&&(r<l.lineN?l.lineN+=n:t<l.lineN+l.size&&(i.externalMeasured=null))}function Pt(e,t,r){e.curOp.viewChanged=!0;var n=e.display,i=e.display.externalMeasured;if(i&&t>=i.lineN&&t<i.lineN+i.size&&(n.externalMeasured=null),!(t<n.viewFrom||t>=n.viewTo)){var o=n.view[Wt(e,t)];if(null!=o.node){var a=o.changes||(o.changes=[]);-1==zi(a,r)&&a.push(r)}}}function It(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function Wt(e,t){if(t>=e.display.viewTo)return null;if(t-=e.display.viewFrom,0>t)return null;for(var r=e.display.view,n=0;n<r.length;n++)if(t-=r[n].size,0>t)return n}function Ft(e,t,r,n){var i,o=Wt(e,t),a=e.display.view;if(!Po||r==e.doc.first+e.doc.size)return{index:o,lineN:r};for(var s=0,l=e.display.viewFrom;o>s;s++)l+=a[s].size;if(l!=t){if(n>0){if(o==a.length-1)return null;i=l+a[o].size-t,o++}else i=l-t;t+=i,r+=i}for(;xn(e.doc,r)!=r;){if(o==(0>n?0:a.length-1))return null;r+=n*a[o-(0>n?1:0)].size,o+=n}return{index:o,lineN:r}}function Ht(e,t,r){var n=e.display,i=n.view;0==i.length||t>=n.viewTo||r<=n.viewFrom?(n.view=Nt(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=Nt(e,t,n.viewFrom).concat(n.view):n.viewFrom<t&&(n.view=n.view.slice(Wt(e,t))),n.viewFrom=t,n.viewTo<r?n.view=n.view.concat(Nt(e,n.viewTo,r)):n.viewTo>r&&(n.view=n.view.slice(0,Wt(e,r)))),n.viewTo=r}function Rt(e){for(var t=e.display.view,r=0,n=0;n<t.length;n++){var i=t[n];i.hidden||i.node&&!i.changes||++r}return r}function Dt(e){function t(){i.activeTouch&&(o=setTimeout(function(){i.activeTouch=null},1e3),a=i.activeTouch,a.end=+new Date)}function r(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}function n(e,t){if(null==t.left)return!0;var r=t.left-e.left,n=t.top-e.top;return r*r+n*n>400}var i=e.display;Aa(i.scroller,"mousedown",Ot(e,Vt)),bo&&11>xo?Aa(i.scroller,"dblclick",Ot(e,function(t){if(!Mi(e,t)){var r=Gt(e,t);if(r&&!Qt(e,t)&&!Ut(e.display,t)){Ma(t);var n=e.findWordAt(r);xe(e.doc,n.anchor,n.head)}}})):Aa(i.scroller,"dblclick",function(t){Mi(e,t)||Ma(t)}),No||Aa(i.scroller,"contextmenu",function(t){yr(e,t)});var o,a={end:0};Aa(i.scroller,"touchstart",function(t){if(!Mi(e,t)&&!r(t)){clearTimeout(o);var n=+new Date;i.activeTouch={start:n,moved:!1,prev:n-a.end<=300?a:null},1==t.touches.length&&(i.activeTouch.left=t.touches[0].pageX,i.activeTouch.top=t.touches[0].pageY)}}),Aa(i.scroller,"touchmove",function(){i.activeTouch&&(i.activeTouch.moved=!0)}),Aa(i.scroller,"touchend",function(r){var o=i.activeTouch;if(o&&!Ut(i,r)&&null!=o.left&&!o.moved&&new Date-o.start<300){var a,s=e.coordsChar(i.activeTouch,"page");a=!o.prev||n(o,o.prev)?new de(s,s):!o.prev.prev||n(o,o.prev.prev)?e.findWordAt(s):new de(Io(s.line,0),me(e.doc,Io(s.line+1,0))),e.setSelection(a.anchor,a.head),e.focus(),Ma(r)}t()}),Aa(i.scroller,"touchcancel",t),Aa(i.scroller,"scroll",function(){i.scroller.clientHeight&&(nr(e,i.scroller.scrollTop),ir(e,i.scroller.scrollLeft,!0),Ea(e,"scroll",e))}),Aa(i.scroller,"mousewheel",function(t){or(e,t)}),Aa(i.scroller,"DOMMouseScroll",function(t){or(e,t)}),Aa(i.wrapper,"scroll",function(){i.wrapper.scrollTop=i.wrapper.scrollLeft=0}),i.dragFunctions={enter:function(t){Mi(e,t)||La(t)},over:function(t){Mi(e,t)||(tr(e,t),La(t))},start:function(t){er(e,t)},drop:Ot(e,Jt),leave:function(){rr(e)}};var s=i.input.getField();Aa(s,"keyup",function(t){pr.call(e,t)}),Aa(s,"keydown",Ot(e,dr)),Aa(s,"keypress",Ot(e,hr)),Aa(s,"focus",Wi(gr,e)),Aa(s,"blur",Wi(vr,e))}function $t(t,r,n){var i=n&&n!=e.Init;if(!r!=!i){var o=t.display.dragFunctions,a=r?Aa:qa;a(t.display.scroller,"dragstart",o.start),a(t.display.scroller,"dragenter",o.enter),a(t.display.scroller,"dragover",o.over),a(t.display.scroller,"dragleave",o.leave),a(t.display.scroller,"drop",o.drop)}}function Bt(e){var t=e.display;(t.lastWrapHeight!=t.wrapper.clientHeight||t.lastWrapWidth!=t.wrapper.clientWidth)&&(t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize())}function Ut(e,t){for(var r=ki(t);r!=e.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==e.sizer&&r!=e.mover)return!0}function Gt(e,t,r,n){var i=e.display;if(!r&&"true"==ki(t).getAttribute("cm-not-content"))return null;var o,a,s=i.lineSpace.getBoundingClientRect();try{o=t.clientX-s.left,a=t.clientY-s.top}catch(t){return null}var l,c=gt(e,o,a);if(n&&1==c.xRel&&(l=Yn(e.doc,c.line).text).length==c.ch){var u=Fa(l,l.length,e.options.tabSize)-l.length;c=Io(c.line,Math.max(0,Math.round((o-Ue(e.display).left)/bt(e.display))-u))}return c}function Vt(e){var t=this,r=t.display;if(!(Mi(t,e)||r.activeTouch&&r.input.supportsTouch())){if(r.shift=e.shiftKey,Ut(r,e))return void(ko||(r.scroller.draggable=!1,setTimeout(function(){r.scroller.draggable=!0},100)));if(!Qt(t,e)){var n=Gt(t,e);switch(window.focus(),wi(e)){case 1:t.state.selectingText?t.state.selectingText(e):n?Kt(t,e,n):ki(e)==r.scroller&&Ma(e);break;case 2:ko&&(t.state.lastMiddleDown=+new Date),n&&xe(t.doc,n),setTimeout(function(){r.input.focus()},20),Ma(e);break;case 3:No?yr(t,e):mr(t)}}}}function Kt(e,t,r){bo?setTimeout(Wi(Z,e),0):e.curOp.focus=Ui();var n,i=+new Date;Do&&Do.time>i-400&&0==Wo(Do.pos,r)?n="triple":Ro&&Ro.time>i-400&&0==Wo(Ro.pos,r)?(n="double",Do={time:i,pos:r}):(n="single",Ro={time:i,pos:r});var o,a=e.doc.sel,s=Oo?t.metaKey:t.ctrlKey;e.options.dragDrop&&Ja&&!e.isReadOnly()&&"single"==n&&(o=a.contains(r))>-1&&(Wo((o=a.ranges[o]).from(),r)<0||r.xRel>0)&&(Wo(o.to(),r)>0||r.xRel<0)?Xt(e,t,r,s):Zt(e,t,r,n,s)}function Xt(e,t,r,n){var i=e.display,o=+new Date,a=Ot(e,function(s){ko&&(i.scroller.draggable=!1),e.state.draggingText=!1,qa(document,"mouseup",a),qa(i.scroller,"drop",a),Math.abs(t.clientX-s.clientX)+Math.abs(t.clientY-s.clientY)<10&&(Ma(s),!n&&+new Date-200<o&&xe(e.doc,r),ko||bo&&9==xo?setTimeout(function(){document.body.focus(),i.input.focus()},20):i.input.focus())});ko&&(i.scroller.draggable=!0),e.state.draggingText=a,i.scroller.dragDrop&&i.scroller.dragDrop(),Aa(document,"mouseup",a),Aa(i.scroller,"drop",a)}function Zt(e,t,r,n,i){function o(t){if(0!=Wo(g,t))if(g=t,"rect"==n){for(var i=[],o=e.options.tabSize,a=Fa(Yn(c,r.line).text,r.ch,o),s=Fa(Yn(c,t.line).text,t.ch,o),l=Math.min(a,s),p=Math.max(a,s),h=Math.min(r.line,t.line),m=Math.min(e.lastLine(),Math.max(r.line,t.line));m>=h;h++){var v=Yn(c,h).text,y=Ha(v,l,o);l==p?i.push(new de(Io(h,y),Io(h,y))):v.length>y&&i.push(new de(Io(h,y),Io(h,Ha(v,p,o))))}i.length||i.push(new de(r,r)),Me(c,fe(f.ranges.slice(0,d).concat(i),d),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b=u,x=b.anchor,k=t;if("single"!=n){if("double"==n)var w=e.findWordAt(t);else var w=new de(Io(t.line,0),me(c,Io(t.line+1,0)));Wo(w.anchor,x)>0?(k=w.head,x=X(b.from(),w.anchor)):(k=w.anchor,x=K(b.to(),w.head))}var i=f.ranges.slice(0);i[d]=new de(me(c,x),k),Me(c,fe(i,d),Ia)}}function a(t){var r=++y,i=Gt(e,t,!0,"rect"==n);if(i)if(0!=Wo(i,g)){e.curOp.focus=Ui(),o(i);var s=x(l,c);(i.line>=s.to||i.line<s.from)&&setTimeout(Ot(e,function(){y==r&&a(t)}),150)}else{var u=t.clientY<v.top?-20:t.clientY>v.bottom?20:0;u&&setTimeout(Ot(e,function(){y==r&&(l.scroller.scrollTop+=u,a(t))}),50)}}function s(t){e.state.selectingText=!1,y=1/0,Ma(t),l.input.focus(),qa(document,"mousemove",b),qa(document,"mouseup",k),c.history.lastSelOrigin=null}var l=e.display,c=e.doc;Ma(t);var u,d,f=c.sel,p=f.ranges;if(i&&!t.shiftKey?(d=c.sel.contains(r),u=d>-1?p[d]:new de(r,r)):(u=c.sel.primary(),d=c.sel.primIndex),t.altKey)n="rect",i||(u=new de(r,r)),r=Gt(e,t,!0,!0),d=-1;else if("double"==n){var h=e.findWordAt(r);u=e.display.shift||c.extend?be(c,u,h.anchor,h.he