n&&a.splice(p,1,n,a[p+1],o),p+=2,f=Math.min(n,o)}if(e)if(l.opaque)a.splice(t,p-t,n,"overlay "+e),p=t+2;else for(;tn.options.maxHighlightLength&&Xn(n.doc.mode,o.state),r=he(n,e,o);a&&(o.state=a),e.stateAfter=o.save(!a),e.styles=r.styles,r.classes?e.styleClasses=r.classes:e.styleClasses&&(e.styleClasses=null),t===n.doc.highlightFrontier&&(n.doc.modeFrontier=Math.max(n.doc.modeFrontier,++n.doc.highlightFrontier))}return e.styles}function xe(n,e,t){var o=n.doc,a=n.display;if(!o.mode.startState)return new _e(o,!0,e);var r=Te(n,e,t),i=r>o.first&&Jn(o,r-1).stateAfter,l=i?_e.fromSaved(o,i,r):new _e(o,$n(o.mode),r);return o.iter(r,e,(function(t){we(n,t.text,l);var o=l.line;t.stateAfter=o==e-1||o%5==0||o>=a.viewFrom&&oe.start)return r}throw new Error("Mode "+n.name+" failed to advance stream.")}_e.prototype.lookAhead=function(n){var e=this.doc.getLine(this.line+n);return null!=e&&n>this.maxLookAhead&&(this.maxLookAhead=n),e},_e.prototype.baseToken=function(n){if(!this.baseTokens)return null;for(;this.baseTokens[this.baseTokenPos]<=n;)this.baseTokenPos+=2;var e=this.baseTokens[this.baseTokenPos+1];return{type:e&&e.replace(/( |^)overlay .*/,""),size:this.baseTokens[this.baseTokenPos]-n}},_e.prototype.nextLine=function(){this.line++,this.maxLookAhead>0&&this.maxLookAhead--},_e.fromSaved=function(n,e,t){return e instanceof be?new _e(n,Xn(n.mode,e.state),t,e.lookAhead):new _e(n,Xn(n.mode,e),t)},_e.prototype.save=function(n){var e=!1!==n?Xn(this.doc.mode,this.state):this.state;return this.maxLookAhead>0?new be(e,this.maxLookAhead):e};var Ce=function(n,e,t){this.start=n.start,this.end=n.pos,this.string=n.current(),this.type=e||null,this.state=t};function Be(n,e,t,o){var a,r,i=n.doc,l=i.mode,p=Jn(i,(e=me(i,e)).line),f=xe(n,e.line,t),c=new Kn(p.text,n.options.tabSize,f);for(o&&(r=[]);(o||c.posn.options.maxHighlightLength?(l=!1,i&&we(n,e,o,d.pos),d.pos=e.length,p=null):p=Pe(ke(t,d,o.state,s),r),s){var m=s[0].name;m&&(p="m-"+(p?m+" "+p:m))}if(!l||c!=p){for(;fi;--l){if(l<=r.first)return r.first;var p=Jn(r,l-1),f=p.stateAfter;if(f&&(!t||l+(f instanceof be?f.lookAhead:0)<=r.modeFrontier))return l;var c=I(p.text,null,n.options.tabSize);(null==a||o>c)&&(a=l-1,o=c)}return a}function Me(n,e){if(n.modeFrontier=Math.min(n.modeFrontier,e),!(n.highlightFrontiert;o--){var a=Jn(n,o).stateAfter;if(a&&(!(a instanceof be)||o+a.lookAhead=e:r.to>e);(o||(o=[])).push(new Fe(i,r.from,l?null:r.to))}}return o}function He(n,e,t){var o;if(n)for(var a=0;a=e:r.to>e)||r.from==e&&"bookmark"==i.type&&(!t||r.marker.insertLeft)){var l=null==r.from||(i.inclusiveLeft?r.from<=e:r.from0&&l)for(var v=0;v0)){var c=[p,1],d=le(f.from,l.from),s=le(f.to,l.to);(d<0||!i.inclusiveLeft&&!d)&&c.push({from:f.from,to:l.from}),(s>0||!i.inclusiveRight&&!s)&&c.push({from:l.to,to:f.to}),a.splice.apply(a,c),p+=c.length-3}}return a}function je(n){var e=n.markedSpans;if(e){for(var t=0;te)&&(!t||qe(t,r.marker)<0)&&(t=r.marker)}return t}function Je(n,e,t,o,a){var r=Jn(n,e),i=ze&&r.markedSpans;if(i)for(var l=0;l=0&&d<=0||c<=0&&d>=0)&&(c<=0&&(p.marker.inclusiveRight&&a.inclusiveLeft?le(f.to,t)>=0:le(f.to,t)>0)||c>=0&&(p.marker.inclusiveRight&&a.inclusiveLeft?le(f.from,o)<=0:le(f.from,o)<0)))return!0}}}function Qe(n){for(var e;e=Ze(n);)n=e.find(-1,!0).line;return n}function nt(n){for(var e;e=$e(n);)n=e.find(1,!0).line;return n}function et(n){for(var e,t;e=$e(n);)n=e.find(1,!0).line,(t||(t=[])).push(n);return t}function tt(n,e){var t=Jn(n,e),o=Qe(t);return t==o?e:te(o)}function ot(n,e){if(e>n.lastLine())return e;var t,o=Jn(n,e);if(!at(n,o))return e;for(;t=$e(o);)o=t.find(1,!0).line;return te(o)+1}function at(n,e){var t=ze&&e.markedSpans;if(t)for(var o=void 0,a=0;ae.maxLineLength&&(e.maxLineLength=t,e.maxLine=n)}))}var ft=function(n,e,t){this.text=n,Ye(this,e),this.height=t?t(this):1};function ct(n,e,t,o){n.text=e,n.stateAfter&&(n.stateAfter=null),n.styles&&(n.styles=null),null!=n.order&&(n.order=null),je(n),Ye(n,t);var a=o?o(n):1;a!=n.height&&ee(n,a)}function dt(n){n.parent=null,je(n)}ft.prototype.lineNo=function(){return te(this)},yn(ft);var st={},mt={};function gt(n,e){if(!n||/^\s*$/.test(n))return null;var t=e.addModeClass?mt:st;return t[n]||(t[n]=n.replace(/\S+/g,"cm-$&"))}function ut(n,e){var t=L("span",null,null,p?"padding-right: .1px":null),o={pre:L("pre",[t],"CodeMirror-line"),content:t,col:0,pos:0,cm:n,trailingSpace:!1,splitSpaces:n.getOption("lineWrapping")};e.measure={};for(var a=0;a<=(e.rest?e.rest.length:0);a++){var r=a?e.rest[a-1]:e.line,i=void 0;o.pos=0,o.addToken=_t,Rn(n.display.measure)&&(i=mn(r,n.doc.direction))&&(o.addToken=vt(o.addToken,i)),o.map=[],wt(r,o,ve(n,r,e!=n.display.externalMeasured&&te(r))),r.styleClasses&&(r.styleClasses.bgClass&&(o.bgClass=F(r.styleClasses.bgClass,o.bgClass||"")),r.styleClasses.textClass&&(o.textClass=F(r.styleClasses.textClass,o.textClass||""))),0==o.map.length&&o.map.push(0,0,o.content.appendChild(Wn(n.display.measure))),0==a?(e.measure.map=o.map,e.measure.cache={}):((e.measure.maps||(e.measure.maps=[])).push(o.map),(e.measure.caches||(e.measure.caches=[])).push({}))}if(p){var l=o.content.lastChild;(/\bcm-tab\b/.test(l.className)||l.querySelector&&l.querySelector(".cm-tab"))&&(o.content.className="cm-tab-wrap-hack")}return hn(n,"renderLine",n,e.line,o.pre),o.pre.className&&(o.textClass=F(o.pre.className,o.textClass||"")),o}function bt(n){var e=M("span","•","cm-invalidchar");return e.title="\\u"+n.charCodeAt(0).toString(16),e.setAttribute("aria-label",e.title),e}function _t(n,e,t,o,a,r,p){if(e){var f,c=n.splitSpaces?ht(e,n.trailingSpace):e,d=n.cm.state.specialChars,s=!1;if(d.test(e)){f=document.createDocumentFragment();for(var m=0;;){d.lastIndex=m;var g=d.exec(e),u=g?g.index-m:e.length-m;if(u){var b=document.createTextNode(c.slice(m,m+u));i&&l<9?f.appendChild(M("span",[b])):f.appendChild(b),n.map.push(n.pos,n.pos+u,b),n.col+=u,n.pos+=u}if(!g)break;m+=u+1;var _=void 0;if("\t"==g[0]){var h=n.cm.options.tabSize,v=h-n.col%h;(_=f.appendChild(M("span",X(v),"cm-tab"))).setAttribute("role","presentation"),_.setAttribute("cm-text","\t"),n.col+=v}else"\r"==g[0]||"\n"==g[0]?((_=f.appendChild(M("span","\r"==g[0]?"␍":"","cm-invalidchar"))).setAttribute("cm-text",g[0]),n.col+=1):((_=n.cm.options.specialCharPlaceholder(g[0])).setAttribute("cm-text",g[0]),i&&l<9?f.appendChild(M("span",[_])):f.appendChild(_),n.col+=1);n.map.push(n.pos,n.pos+1,_),n.pos++}}else n.col+=e.length,f=document.createTextNode(c),n.map.push(n.pos,n.pos+e.length,f),i&&l<9&&(s=!0),n.pos+=e.length;if(n.trailingSpace=32==c.charCodeAt(e.length-1),t||o||a||s||r||p){var x=t||"";o&&(x+=o),a&&(x+=a);var w=M("span",[f],x,r);if(p)for(var y in p)p.hasOwnProperty(y)&&"style"!=y&&"class"!=y&&w.setAttribute(y,p[y]);return n.content.appendChild(w)}n.content.appendChild(f)}}function ht(n,e){if(n.length>1&&!/ /.test(n))return n;for(var t=e,o="",a=0;af&&d.from<=f);s++);if(d.to>=c)return n(t,o,a,r,i,l,p);n(t,o.slice(0,d.to-f),a,r,null,l,p),r=null,o=o.slice(d.to-f),f=d.to}}}function xt(n,e,t,o){var a=!o&&t.widgetNode;a&&n.map.push(n.pos,n.pos+e,a),!o&&n.cm.display.input.needsContentAttribute&&(a||(a=n.content.appendChild(document.createElement("span"))),a.setAttribute("cm-marker",t.id)),a&&(n.cm.display.input.setUneditable(a),n.content.appendChild(a)),n.pos+=e,n.trailingSpace=!1}function wt(n,e,t){var o=n.markedSpans,a=n.text,r=0;if(o)for(var i,l,p,f,c,d,s,m=a.length,g=0,u=1,b="",_=0;;){if(_==g){p=f=c=l="",s=null,d=null,_=1/0;for(var h=[],v=void 0,x=0;xg||y.collapsed&&w.to==g&&w.from==g)){if(null!=w.to&&w.to!=g&&_>w.to&&(_=w.to,f=""),y.className&&(p+=" "+y.className),y.css&&(l=(l?l+";":"")+y.css),y.startStyle&&w.from==g&&(c+=" "+y.startStyle),y.endStyle&&w.to==_&&(v||(v=[])).push(y.endStyle,w.to),y.title&&((s||(s={})).title=y.title),y.attributes)for(var k in y.attributes)(s||(s={}))[k]=y.attributes[k];y.collapsed&&(!d||qe(d.marker,y)<0)&&(d=w)}else w.from>g&&_>w.from&&(_=w.from)}if(v)for(var C=0;C=m)break;for(var P=Math.min(m,_);;){if(b){var S=g+b.length;if(!d){var T=S>P?b.slice(0,P-g):b;e.addToken(e,T,i?i+p:p,c,g+T.length==_?f:"",l,s)}if(S>=P){b=b.slice(P-g),g=P;break}g=S,c=""}b=a.slice(r,r=t[u++]),i=gt(t[u++],e.cm.options)}}else for(var M=1;M2&&r.push((p.bottom+f.top)/2-t.top)}}r.push(t.bottom-t.top)}}function Jt(n,e,t){if(n.line==e)return{map:n.measure.map,cache:n.measure.cache};for(var o=0;ot)return{map:n.measure.maps[a],cache:n.measure.caches[a],before:!0}}function Qt(n,e){var t=te(e=Qe(e)),o=n.display.externalMeasured=new yt(n.doc,e,t);o.lineN=t;var a=o.built=ut(n,o);return o.text=a.pre,T(n.display.lineMeasure,a.pre),o}function no(n,e,t,o){return oo(n,to(n,e),t,o)}function eo(n,e){if(e>=n.display.viewFrom&&e=t.lineN&&ee)&&(a=(r=p-l)-1,e>=p&&(i="right")),null!=a){if(o=n[f+2],l==p&&t==(o.insertLeft?"left":"right")&&(i=t),"left"==t&&0==a)for(;f&&n[f-2]==n[f-3]&&n[f-1].insertLeft;)o=n[2+(f-=3)],i="left";if("right"==t&&a==p-l)for(;f=0&&(t=n[a]).left==t.right;a--);return t}function po(n,e,t,o){var a,r=io(e.map,t,o),p=r.node,f=r.start,c=r.end,d=r.collapse;if(3==p.nodeType){for(var s=0;s<4;s++){for(;f&&rn(e.line.text.charAt(r.coverStart+f));)--f;for(;r.coverStart+c0&&(d=o="right"),a=n.options.lineWrapping&&(m=p.getClientRects()).length>1?m["right"==o?m.length-1:0]:p.getBoundingClientRect()}if(i&&l<9&&!f&&(!a||!a.left&&!a.right)){var g=p.parentNode.getClientRects()[0];a=g?{left:g.left,right:g.left+zo(n.display),top:g.top,bottom:g.bottom}:ro}for(var u=a.top-e.rect.top,b=a.bottom-e.rect.top,_=(u+b)/2,h=e.view.measure.heights,v=0;v=o.text.length?(p=o.text.length,f="before"):p<=0&&(p=0,f="after"),!l)return i("before"==f?p-1:p,"before"==f);function c(n,e,t){return i(t?n-1:n,1==l[e].level!=t)}var d=dn(l,p,f),s=cn,m=c(p,d,"before"==f);return null!=s&&(m.other=c(p,s,"before"!=f)),m}function wo(n,e){var t=0;e=me(n.doc,e),n.options.lineWrapping||(t=zo(n.display)*e.ch);var o=Jn(n.doc,e.line),a=it(o)+Vt(n.display);return{left:t,right:t,top:a,bottom:a+o.height}}function yo(n,e,t,o,a){var r=ie(n,e,t);return r.xRel=a,o&&(r.outside=o),r}function ko(n,e,t){var o=n.doc;if((t+=n.display.viewOffset)<0)return yo(o.first,0,null,-1,-1);var a=oe(o,t),r=o.first+o.size-1;if(a>r)return yo(o.first+o.size-1,Jn(o,r).text.length,null,1,1);e<0&&(e=0);for(var i=Jn(o,a);;){var l=So(n,i,a,e,t),p=Ke(i,l.ch+(l.xRel>0||l.outside>0?1:0));if(!p)return l;var f=p.find(1);if(f.line==a)return f;i=Jn(o,a=f.line)}}function Co(n,e,t,o){o-=bo(e);var a=e.text.length,r=pn((function(e){return oo(n,t,e-1).bottom<=o}),a,0);return{begin:r,end:a=pn((function(e){return oo(n,t,e).top>o}),r,a)}}function Bo(n,e,t,o){return t||(t=to(n,e)),Co(n,e,t,_o(n,e,oo(n,t,o),"line").top)}function Po(n,e,t,o){return!(n.bottom<=t)&&(n.top>t||(o?n.left:n.right)>e)}function So(n,e,t,o,a){a-=it(e);var r=to(n,e),i=bo(e),l=0,p=e.text.length,f=!0,c=mn(e,n.doc.direction);if(c){var d=(n.options.lineWrapping?Mo:To)(n,e,t,r,c,o,a);l=(f=1!=d.level)?d.from:d.to-1,p=f?d.to:d.from-1}var s,m,g=null,u=null,b=pn((function(e){var t=oo(n,r,e);return t.top+=i,t.bottom+=i,!!Po(t,o,a,!1)&&(t.top<=a&&t.left<=o&&(g=e,u=t),!0)}),l,p),_=!1;if(u){var h=o-u.left=x.bottom?1:0}return yo(t,b=ln(e.text,b,1),m,_,o-s)}function To(n,e,t,o,a,r,i){var l=pn((function(l){var p=a[l],f=1!=p.level;return Po(xo(n,ie(t,f?p.to:p.from,f?"before":"after"),"line",e,o),r,i,!0)}),0,a.length-1),p=a[l];if(l>0){var f=1!=p.level,c=xo(n,ie(t,f?p.from:p.to,f?"after":"before"),"line",e,o);Po(c,r,i,!0)&&c.top>i&&(p=a[l-1])}return p}function Mo(n,e,t,o,a,r,i){var l=Co(n,e,o,i),p=l.begin,f=l.end;/\s/.test(e.text.charAt(f-1))&&f--;for(var c=null,d=null,s=0;s=f||m.to<=p)){var g=oo(n,o,1!=m.level?Math.min(f,m.to)-1:Math.max(p,m.from)).right,u=gu)&&(c=m,d=u)}}return c||(c=a[a.length-1]),c.fromf&&(c={from:c.from,to:f,level:c.level}),c}function Lo(n){if(null!=n.cachedTextHeight)return n.cachedTextHeight;if(null==ao){ao=M("pre",null,"CodeMirror-line-like");for(var e=0;e<49;++e)ao.appendChild(document.createTextNode("x")),ao.appendChild(M("br"));ao.appendChild(document.createTextNode("x"))}T(n.measure,ao);var t=ao.offsetHeight/50;return t>3&&(n.cachedTextHeight=t),S(n.measure),t||1}function zo(n){if(null!=n.cachedCharWidth)return n.cachedCharWidth;var e=M("span","xxxxxxxxxx"),t=M("pre",[e],"CodeMirror-line-like");T(n.measure,t);var o=e.getBoundingClientRect(),a=(o.right-o.left)/10;return a>2&&(n.cachedCharWidth=a),a||10}function Wo(n){for(var e=n.display,t={},o={},a=e.gutters.clientLeft,r=e.gutters.firstChild,i=0;r;r=r.nextSibling,++i){var l=n.display.gutterSpecs[i].className;t[l]=r.offsetLeft+r.clientLeft+a,o[l]=r.clientWidth}return{fixedPos:Ro(e),gutterTotalWidth:e.gutters.offsetWidth,gutterLeft:t,gutterWidth:o,wrapperWidth:e.wrapper.clientWidth}}function Ro(n){return n.scroller.getBoundingClientRect().left-n.sizer.getBoundingClientRect().left}function Fo(n){var e=Lo(n.display),t=n.options.lineWrapping,o=t&&Math.max(5,n.display.scroller.clientWidth/zo(n.display)-3);return function(a){if(at(n.doc,a))return 0;var r=0;if(a.widgets)for(var i=0;i0&&(p=Jn(n.doc,f.line).text).length==f.ch){var c=I(p,p.length,n.options.tabSize)-p.length;f=ie(f.line,Math.max(0,Math.round((r-qt(n.display).left)/zo(n.display))-c))}return f}function Ao(n,e){if(e>=n.display.viewTo)return null;if((e-=n.display.viewFrom)<0)return null;for(var t=n.display.view,o=0;oe)&&(a.updateLineNumbers=e),n.curOp.viewChanged=!0,e>=a.viewTo)ze&&tt(n.doc,e)a.viewFrom?No(n):(a.viewFrom+=o,a.viewTo+=o);else if(e<=a.viewFrom&&t>=a.viewTo)No(n);else if(e<=a.viewFrom){var r=Eo(n,t,t+o,1);r?(a.view=a.view.slice(r.index),a.viewFrom=r.lineN,a.viewTo+=o):No(n)}else if(t>=a.viewTo){var i=Eo(n,e,e,-1);i?(a.view=a.view.slice(0,i.index),a.viewTo=i.lineN):No(n)}else{var l=Eo(n,e,e,-1),p=Eo(n,t,t+o,1);l&&p?(a.view=a.view.slice(0,l.index).concat(kt(n,l.lineN,p.lineN)).concat(a.view.slice(p.index)),a.viewTo+=o):No(n)}var f=a.externalMeasured;f&&(t=a.lineN&&e=o.viewTo)){var r=o.view[Ao(n,e)];if(null!=r.node){var i=r.changes||(r.changes=[]);-1==N(i,t)&&i.push(t)}}}function No(n){n.display.viewFrom=n.display.viewTo=n.doc.first,n.display.view=[],n.display.viewOffset=0}function Eo(n,e,t,o){var a,r=Ao(n,e),i=n.display.view;if(!ze||t==n.doc.first+n.doc.size)return{index:r,lineN:t};for(var l=n.display.viewFrom,p=0;p0){if(r==i.length-1)return null;a=l+i[r].size-e,r++}else a=l-e;e+=a,t+=a}for(;tt(n.doc,t)!=t;){if(r==(o<0?0:i.length-1))return null;t+=o*i[r-(o<0?1:0)].size,r+=o}return{index:r,lineN:t}}function Go(n,e,t){var o=n.display;0==o.view.length||e>=o.viewTo||t<=o.viewFrom?(o.view=kt(n,e,t),o.viewFrom=e):(o.viewFrom>e?o.view=kt(n,e,o.viewFrom).concat(o.view):o.viewFromt&&(o.view=o.view.slice(0,Ao(n,t)))),o.viewTo=t}function jo(n){for(var e=n.display.view,t=0,o=0;o=n.display.viewTo||l.to().line0?e.blinker=setInterval((function(){n.hasFocus()||Qo(n),e.cursorDiv.style.visibility=(t=!t)?"":"hidden"}),n.options.cursorBlinkRate):n.options.cursorBlinkRate<0&&(e.cursorDiv.style.visibility="hidden")}}function $o(n){n.hasFocus()||(n.display.input.focus(),n.state.focused||Jo(n))}function Ko(n){n.state.delayingBlurEvent=!0,setTimeout((function(){n.state.delayingBlurEvent&&(n.state.delayingBlurEvent=!1,n.state.focused&&Qo(n))}),100)}function Jo(n,e){n.state.delayingBlurEvent&&!n.state.draggingText&&(n.state.delayingBlurEvent=!1),"nocursor"!=n.options.readOnly&&(n.state.focused||(hn(n,"focus",n,e),n.state.focused=!0,R(n.display.wrapper,"CodeMirror-focused"),n.curOp||n.display.selForContextMenu==n.doc.sel||(n.display.input.reset(),p&&setTimeout((function(){return n.display.input.reset(!0)}),20)),n.display.input.receivedFocus()),Zo(n))}function Qo(n,e){n.state.delayingBlurEvent||(n.state.focused&&(hn(n,"blur",n,e),n.state.focused=!1,P(n.display.wrapper,"CodeMirror-focused")),clearInterval(n.display.blinker),setTimeout((function(){n.state.focused||(n.display.shift=!1)}),150))}function na(n){for(var e=n.display,t=e.lineDiv.offsetTop,o=0;o.005||s<-.005)&&(ee(a.line,p),ea(a.line),a.rest))for(var m=0;mn.display.sizerWidth){var g=Math.ceil(f/zo(n.display));g>n.display.maxLineLength&&(n.display.maxLineLength=g,n.display.maxLine=a.line,n.display.maxLineChanged=!0)}}}}function ea(n){if(n.widgets)for(var e=0;e=i&&(r=oe(e,it(Jn(e,p))-n.wrapper.clientHeight),i=p)}return{from:r,to:Math.max(i,r+1)}}function oa(n,e){if(!vn(n,"scrollCursorIntoView")){var t=n.display,o=t.sizer.getBoundingClientRect(),a=null;if(e.top+o.top<0?a=!0:e.bottom+o.top>(window.innerHeight||document.documentElement.clientHeight)&&(a=!1),null!=a&&!g){var r=M("div","",null,"position: absolute;\n top: "+(e.top-t.viewOffset-Vt(n.display))+"px;\n height: "+(e.bottom-e.top+Xt(n)+t.barHeight)+"px;\n left: "+e.left+"px; width: "+Math.max(2,e.right-e.left)+"px;");n.display.lineSpace.appendChild(r),r.scrollIntoView(a),n.display.lineSpace.removeChild(r)}}}function aa(n,e,t,o){var a;null==o&&(o=0),n.options.lineWrapping||e!=t||(t="before"==(e=e.ch?ie(e.line,"before"==e.sticky?e.ch-1:e.ch,"after"):e).sticky?ie(e.line,e.ch+1,"before"):e);for(var r=0;r<5;r++){var i=!1,l=xo(n,e),p=t&&t!=e?xo(n,t):l,f=ia(n,a={left:Math.min(l.left,p.left),top:Math.min(l.top,p.top)-o,right:Math.max(l.left,p.left),bottom:Math.max(l.bottom,p.bottom)+o}),c=n.doc.scrollTop,d=n.doc.scrollLeft;if(null!=f.scrollTop&&(ma(n,f.scrollTop),Math.abs(n.doc.scrollTop-c)>1&&(i=!0)),null!=f.scrollLeft&&(ua(n,f.scrollLeft),Math.abs(n.doc.scrollLeft-d)>1&&(i=!0)),!i)break}return a}function ra(n,e){var t=ia(n,e);null!=t.scrollTop&&ma(n,t.scrollTop),null!=t.scrollLeft&&ua(n,t.scrollLeft)}function ia(n,e){var t=n.display,o=Lo(n.display);e.top<0&&(e.top=0);var a=n.curOp&&null!=n.curOp.scrollTop?n.curOp.scrollTop:t.scroller.scrollTop,r=$t(n),i={};e.bottom-e.top>r&&(e.bottom=e.top+r);var l=n.doc.height+Ut(t),p=e.topl-o;if(e.topa+r){var c=Math.min(e.top,(f?l:e.bottom)-r);c!=a&&(i.scrollTop=c)}var d=n.options.fixedGutter?0:t.gutters.offsetWidth,s=n.curOp&&null!=n.curOp.scrollLeft?n.curOp.scrollLeft:t.scroller.scrollLeft-d,m=Zt(n)-t.gutters.offsetWidth,g=e.right-e.left>m;return g&&(e.right=e.left+m),e.left<10?i.scrollLeft=0:e.leftm+s-3&&(i.scrollLeft=e.right+(g?0:10)-m),i}function la(n,e){null!=e&&(da(n),n.curOp.scrollTop=(null==n.curOp.scrollTop?n.doc.scrollTop:n.curOp.scrollTop)+e)}function pa(n){da(n);var e=n.getCursor();n.curOp.scrollToPos={from:e,to:e,margin:n.options.cursorScrollMargin}}function fa(n,e,t){null==e&&null==t||da(n),null!=e&&(n.curOp.scrollLeft=e),null!=t&&(n.curOp.scrollTop=t)}function ca(n,e){da(n),n.curOp.scrollToPos=e}function da(n){var e=n.curOp.scrollToPos;e&&(n.curOp.scrollToPos=null,sa(n,wo(n,e.from),wo(n,e.to),e.margin))}function sa(n,e,t,o){var a=ia(n,{left:Math.min(e.left,t.left),top:Math.min(e.top,t.top)-o,right:Math.max(e.right,t.right),bottom:Math.max(e.bottom,t.bottom)+o});fa(n,a.scrollLeft,a.scrollTop)}function ma(n,e){Math.abs(n.doc.scrollTop-e)<2||(t||Ya(n,{top:e}),ga(n,e,!0),t&&Ya(n),Oa(n,100))}function ga(n,e,t){e=Math.max(0,Math.min(n.display.scroller.scrollHeight-n.display.scroller.clientHeight,e)),(n.display.scroller.scrollTop!=e||t)&&(n.doc.scrollTop=e,n.display.scrollbars.setScrollTop(e),n.display.scroller.scrollTop!=e&&(n.display.scroller.scrollTop=e))}function ua(n,e,t,o){e=Math.max(0,Math.min(e,n.display.scroller.scrollWidth-n.display.scroller.clientWidth)),(t?e==n.doc.scrollLeft:Math.abs(n.doc.scrollLeft-e)<2)&&!o||(n.doc.scrollLeft=e,Xa(n),n.display.scroller.scrollLeft!=e&&(n.display.scroller.scrollLeft=e),n.display.scrollbars.setScrollLeft(e))}function ba(n){var e=n.display,t=e.gutters.offsetWidth,o=Math.round(n.doc.height+Ut(n.display));return{clientHeight:e.scroller.clientHeight,viewHeight:e.wrapper.clientHeight,scrollWidth:e.scroller.scrollWidth,clientWidth:e.scroller.clientWidth,viewWidth:e.wrapper.clientWidth,barLeft:n.options.fixedGutter?t:0,docHeight:o,scrollHeight:o+Xt(n)+e.barHeight,nativeBarWidth:e.nativeBarWidth,gutterWidth:t}}var _a=function(n,e,t){this.cm=t;var o=this.vert=M("div",[M("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),a=this.horiz=M("div",[M("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");o.tabIndex=a.tabIndex=-1,n(o),n(a),un(o,"scroll",(function(){o.clientHeight&&e(o.scrollTop,"vertical")})),un(a,"scroll",(function(){a.clientWidth&&e(a.scrollLeft,"horizontal")})),this.checkedZeroWidth=!1,i&&l<8&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")};_a.prototype.update=function(n){var e=n.scrollWidth>n.clientWidth+1,t=n.scrollHeight>n.clientHeight+1,o=n.nativeBarWidth;if(t){this.vert.style.display="block",this.vert.style.bottom=e?o+"px":"0";var a=n.viewHeight-(e?o:0);this.vert.firstChild.style.height=Math.max(0,n.scrollHeight-n.clientHeight+a)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(e){this.horiz.style.display="block",this.horiz.style.right=t?o+"px":"0",this.horiz.style.left=n.barLeft+"px";var r=n.viewWidth-n.barLeft-(t?o:0);this.horiz.firstChild.style.width=Math.max(0,n.scrollWidth-n.clientWidth+r)+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedZeroWidth&&n.clientHeight>0&&(0==o&&this.zeroWidthHack(),this.checkedZeroWidth=!0),{right:t?o:0,bottom:e?o:0}},_a.prototype.setScrollLeft=function(n){this.horiz.scrollLeft!=n&&(this.horiz.scrollLeft=n),this.disableHoriz&&this.enableZeroWidthBar(this.horiz,this.disableHoriz,"horiz")},_a.prototype.setScrollTop=function(n){this.vert.scrollTop!=n&&(this.vert.scrollTop=n),this.disableVert&&this.enableZeroWidthBar(this.vert,this.disableVert,"vert")},_a.prototype.zeroWidthHack=function(){var n=h&&!m?"12px":"18px";this.horiz.style.height=this.vert.style.width=n,this.horiz.style.pointerEvents=this.vert.style.pointerEvents="none",this.disableHoriz=new H,this.disableVert=new H},_a.prototype.enableZeroWidthBar=function(n,e,t){function o(){var a=n.getBoundingClientRect();("vert"==t?document.elementFromPoint(a.right-1,(a.top+a.bottom)/2):document.elementFromPoint((a.right+a.left)/2,a.bottom-1))!=n?n.style.pointerEvents="none":e.set(1e3,o)}n.style.pointerEvents="auto",e.set(1e3,o)},_a.prototype.clear=function(){var n=this.horiz.parentNode;n.removeChild(this.horiz),n.removeChild(this.vert)};var ha=function(){};function va(n,e){e||(e=ba(n));var t=n.display.barWidth,o=n.display.barHeight;xa(n,e);for(var a=0;a<4&&t!=n.display.barWidth||o!=n.display.barHeight;a++)t!=n.display.barWidth&&n.options.lineWrapping&&na(n),xa(n,ba(n)),t=n.display.barWidth,o=n.display.barHeight}function xa(n,e){var t=n.display,o=t.scrollbars.update(e);t.sizer.style.paddingRight=(t.barWidth=o.right)+"px",t.sizer.style.paddingBottom=(t.barHeight=o.bottom)+"px",t.heightForcer.style.borderBottom=o.bottom+"px solid transparent",o.right&&o.bottom?(t.scrollbarFiller.style.display="block",t.scrollbarFiller.style.height=o.bottom+"px",t.scrollbarFiller.style.width=o.right+"px"):t.scrollbarFiller.style.display="",o.bottom&&n.options.coverGutterNextToScrollbar&&n.options.fixedGutter?(t.gutterFiller.style.display="block",t.gutterFiller.style.height=o.bottom+"px",t.gutterFiller.style.width=e.gutterWidth+"px"):t.gutterFiller.style.display=""}ha.prototype.update=function(){return{bottom:0,right:0}},ha.prototype.setScrollLeft=function(){},ha.prototype.setScrollTop=function(){},ha.prototype.clear=function(){};var wa={native:_a,null:ha};function ya(n){n.display.scrollbars&&(n.display.scrollbars.clear(),n.display.scrollbars.addClass&&P(n.display.wrapper,n.display.scrollbars.addClass)),n.display.scrollbars=new wa[n.options.scrollbarStyle]((function(e){n.display.wrapper.insertBefore(e,n.display.scrollbarFiller),un(e,"mousedown",(function(){n.state.focused&&setTimeout((function(){return n.display.input.focus()}),0)})),e.setAttribute("cm-not-content","true")}),(function(e,t){"horizontal"==t?ua(n,e):ma(n,e)}),n),n.display.scrollbars.addClass&&R(n.display.wrapper,n.display.scrollbars.addClass)}var ka=0;function Ca(n){n.curOp={cm:n,viewChanged:!1,startHeight:n.doc.height,forceUpdate:!1,updateInput:0,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,focus:!1,id:++ka},Bt(n.curOp)}function Ba(n){var e=n.curOp;e&&St(e,(function(n){for(var e=0;e=t.viewTo)||t.maxLineChanged&&e.options.lineWrapping,n.update=n.mustUpdate&&new Ia(e,n.mustUpdate&&{top:n.scrollTop,ensure:n.scrollToPos},n.forceUpdate)}function Ta(n){n.updatedDisplay=n.mustUpdate&&Ga(n.cm,n.update)}function Ma(n){var e=n.cm,t=e.display;n.updatedDisplay&&na(e),n.barMeasure=ba(e),t.maxLineChanged&&!e.options.lineWrapping&&(n.adjustWidthTo=no(e,t.maxLine,t.maxLine.text.length).left+3,e.display.sizerWidth=n.adjustWidthTo,n.barMeasure.scrollWidth=Math.max(t.scroller.clientWidth,t.sizer.offsetLeft+n.adjustWidthTo+Xt(e)+e.display.barWidth),n.maxScrollLeft=Math.max(0,t.sizer.offsetLeft+n.adjustWidthTo-Zt(e))),(n.updatedDisplay||n.selectionChanged)&&(n.preparedSelection=t.input.prepareSelection())}function La(n){var e=n.cm;null!=n.adjustWidthTo&&(e.display.sizer.style.minWidth=n.adjustWidthTo+"px",n.maxScrollLeft=n.display.viewTo)){var t=+new Date+n.options.workTime,o=xe(n,e.highlightFrontier),a=[];e.iter(o.line,Math.min(e.first+e.size,n.display.viewTo+500),(function(r){if(o.line>=n.display.viewFrom){var i=r.styles,l=r.text.length>n.options.maxHighlightLength?Xn(e.mode,o.state):null,p=he(n,r,o,!0);l&&(o.state=l),r.styles=p.styles;var f=r.styleClasses,c=p.classes;c?r.styleClasses=c:f&&(r.styleClasses=null);for(var d=!i||i.length!=r.styles.length||f!=c&&(!f||!c||f.bgClass!=c.bgClass||f.textClass!=c.textClass),s=0;!d&&st)return Oa(n,n.options.workDelay),!0})),e.highlightFrontier=o.line,e.modeFrontier=Math.max(e.modeFrontier,o.line),a.length&&Wa(n,(function(){for(var e=0;e=t.viewFrom&&e.visible.to<=t.viewTo&&(null==t.updateLineNumbers||t.updateLineNumbers>=t.viewTo)&&t.renderedView==t.view&&0==jo(n))return!1;Za(n)&&(No(n),e.dims=Wo(n));var a=o.first+o.size,r=Math.max(e.visible.from-n.options.viewportMargin,o.first),i=Math.min(a,e.visible.to+n.options.viewportMargin);t.viewFromi&&t.viewTo-i<20&&(i=Math.min(a,t.viewTo)),ze&&(r=tt(n.doc,r),i=ot(n.doc,i));var l=r!=t.viewFrom||i!=t.viewTo||t.lastWrapHeight!=e.wrapperHeight||t.lastWrapWidth!=e.wrapperWidth;Go(n,r,i),t.viewOffset=it(Jn(n.doc,t.viewFrom)),n.display.mover.style.top=t.viewOffset+"px";var p=jo(n);if(!l&&0==p&&!e.force&&t.renderedView==t.view&&(null==t.updateLineNumbers||t.updateLineNumbers>=t.viewTo))return!1;var f=Na(n);return p>4&&(t.lineDiv.style.display="none"),Va(n,t.updateLineNumbers,e.dims),p>4&&(t.lineDiv.style.display=""),t.renderedView=t.view,Ea(f),S(t.cursorDiv),S(t.selectionDiv),t.gutters.style.height=t.sizer.style.minHeight=0,l&&(t.lastWrapHeight=e.wrapperHeight,t.lastWrapWidth=e.wrapperWidth,Oa(n,400)),t.updateLineNumbers=null,!0}function ja(n,e){for(var t=e.viewport,o=!0;;o=!1){if(o&&n.options.lineWrapping&&e.oldDisplayWidth!=Zt(n))o&&(e.visible=ta(n.display,n.doc,t));else if(t&&null!=t.top&&(t={top:Math.min(n.doc.height+Ut(n.display)-$t(n),t.top)}),e.visible=ta(n.display,n.doc,t),e.visible.from>=n.display.viewFrom&&e.visible.to<=n.display.viewTo)break;if(!Ga(n,e))break;na(n);var a=ba(n);Yo(n),va(n,a),qa(n,a),e.force=!1}e.signal(n,"update",n),n.display.viewFrom==n.display.reportedViewFrom&&n.display.viewTo==n.display.reportedViewTo||(e.signal(n,"viewportChange",n,n.display.viewFrom,n.display.viewTo),n.display.reportedViewFrom=n.display.viewFrom,n.display.reportedViewTo=n.display.viewTo)}function Ya(n,e){var t=new Ia(n,e);if(Ga(n,t)){na(n),ja(n,t);var o=ba(n);Yo(n),va(n,o),qa(n,o),t.finish()}}function Va(n,e,t){var o=n.display,a=n.options.lineNumbers,r=o.lineDiv,i=r.firstChild;function l(e){var t=e.nextSibling;return p&&h&&n.display.currentWheelTarget==e?e.style.display="none":e.parentNode.removeChild(e),t}for(var f=o.view,c=o.viewFrom,d=0;d-1&&(m=!1),zt(n,s,c,t)),m&&(S(s.lineNumber),s.lineNumber.appendChild(document.createTextNode(re(n.options,c)))),i=s.node.nextSibling}else{var g=Ht(n,s,c,t);r.insertBefore(g,i)}c+=s.size}for(;i;)i=l(i)}function Ua(n){var e=n.gutters.offsetWidth;n.sizer.style.marginLeft=e+"px"}function qa(n,e){n.display.sizer.style.minHeight=e.docHeight+"px",n.display.heightForcer.style.top=e.docHeight+"px",n.display.gutters.style.height=e.docHeight+n.display.barHeight+Xt(n)+"px"}function Xa(n){var e=n.display,t=e.view;if(e.alignWidgets||e.gutters.firstChild&&n.options.fixedGutter){for(var o=Ro(e)-e.scroller.scrollLeft+n.doc.scrollLeft,a=e.gutters.offsetWidth,r=o+"px",i=0;il.clientWidth,c=l.scrollHeight>l.clientHeight;if(a&&f||r&&c){if(r&&h&&p)n:for(var s=e.target,m=i.view;s!=l;s=s.parentNode)for(var g=0;g=0&&le(n,o.to())<=0)return t}return-1};var ir=function(n,e){this.anchor=n,this.head=e};function lr(n,e,t){var o=n&&n.options.selectionsMayTouch,a=e[t];e.sort((function(n,e){return le(n.from(),e.from())})),t=N(e,a);for(var r=1;r0:p>=0){var f=de(l.from(),i.from()),c=ce(l.to(),i.to()),d=l.empty()?i.from()==i.head:l.from()==l.head;r<=t&&--t,e.splice(--r,2,new ir(d?c:f,d?f:c))}}return new rr(e,t)}function pr(n,e){return new rr([new ir(n,e||n)],0)}function fr(n){return n.text?ie(n.from.line+n.text.length-1,Z(n.text).length+(1==n.text.length?n.from.ch:0)):n.to}function cr(n,e){if(le(n,e.from)<0)return n;if(le(n,e.to)<=0)return fr(e);var t=n.line+e.text.length-(e.to.line-e.from.line)-1,o=n.ch;return n.line==e.to.line&&(o+=fr(e).ch-e.to.ch),ie(t,o)}function dr(n,e){for(var t=[],o=0;o1&&n.remove(l.line+1,g-1),n.insert(l.line+1,_)}Mt(n,"change",n,e)}function hr(n,e,t){function o(n,a,r){if(n.linked)for(var i=0;i1&&!n.done[n.done.length-2].ranges?(n.done.pop(),Z(n.done)):void 0}function Pr(n,e,t,o){var a=n.history;a.undone.length=0;var r,i,l=+new Date;if((a.lastOp==o||a.lastOrigin==e.origin&&e.origin&&("+"==e.origin.charAt(0)&&a.lastModTime>l-(n.cm?n.cm.options.historyEventDelay:500)||"*"==e.origin.charAt(0)))&&(r=Br(a,a.lastOp==o)))i=Z(r.changes),0==le(e.from,e.to)&&0==le(e.from,i.to)?i.to=fr(e):r.changes.push(kr(n,e));else{var p=Z(a.done);for(p&&p.ranges||Mr(n.sel,a.done),r={changes:[kr(n,e)],generation:a.generation},a.done.push(r);a.done.length>a.undoDepth;)a.done.shift(),a.done[0].ranges||a.done.shift()}a.done.push(t),a.generation=++a.maxGeneration,a.lastModTime=a.lastSelTime=l,a.lastOp=a.lastSelOp=o,a.lastOrigin=a.lastSelOrigin=e.origin,i||hn(n,"historyAdded")}function Sr(n,e,t,o){var a=e.charAt(0);return"*"==a||"+"==a&&t.ranges.length==o.ranges.length&&t.somethingSelected()==o.somethingSelected()&&new Date-n.history.lastSelTime<=(n.cm?n.cm.options.historyEventDelay:500)}function Tr(n,e,t,o){var a=n.history,r=o&&o.origin;t==a.lastSelOp||r&&a.lastSelOrigin==r&&(a.lastModTime==a.lastSelTime&&a.lastOrigin==r||Sr(n,r,Z(a.done),e))?a.done[a.done.length-1]=e:Mr(e,a.done),a.lastSelTime=+new Date,a.lastSelOrigin=r,a.lastSelOp=t,o&&!1!==o.clearRedo&&Cr(a.undone)}function Mr(n,e){var t=Z(e);t&&t.ranges&&t.equals(n)||e.push(n)}function Lr(n,e,t,o){var a=e["spans_"+n.id],r=0;n.iter(Math.max(n.first,t),Math.min(n.first+n.size,o),(function(t){t.markedSpans&&((a||(a=e["spans_"+n.id]={}))[r]=t.markedSpans),++r}))}function zr(n){if(!n)return null;for(var e,t=0;t-1&&(Z(l)[d]=f[d],delete f[d])}}}return o}function Dr(n,e,t,o){if(o){var a=n.anchor;if(t){var r=le(e,a)<0;r!=le(t,a)<0?(a=e,e=t):r!=le(e,t)<0&&(e=t)}return new ir(a,e)}return new ir(t||e,e)}function Or(n,e,t,o,a){null==a&&(a=n.cm&&(n.cm.display.shift||n.extend)),Gr(n,new rr([Dr(n.sel.primary(),e,t,a)],0),o)}function Ar(n,e,t){for(var o=[],a=n.cm&&(n.cm.display.shift||n.extend),r=0;r=e.ch:l.to>e.ch))){if(a&&(hn(p,"beforeCursorEnter"),p.explicitlyCleared)){if(r.markedSpans){--i;continue}break}if(!p.atomic)continue;if(t){var d=p.find(o<0?1:-1),s=void 0;if((o<0?c:f)&&(d=Zr(n,d,-o,d&&d.line==e.line?r:null)),d&&d.line==e.line&&(s=le(d,t))&&(o<0?s<0:s>0))return qr(n,d,e,o,a)}var m=p.find(o<0?-1:1);return(o<0?f:c)&&(m=Zr(n,m,o,m.line==e.line?r:null)),m?qr(n,m,e,o,a):null}}return e}function Xr(n,e,t,o,a){var r=o||1,i=qr(n,e,t,r,a)||!a&&qr(n,e,t,r,!0)||qr(n,e,t,-r,a)||!a&&qr(n,e,t,-r,!0);return i||(n.cantEdit=!0,ie(n.first,0))}function Zr(n,e,t,o){return t<0&&0==e.ch?e.line>n.first?me(n,ie(e.line-1)):null:t>0&&e.ch==(o||Jn(n,e.line)).text.length?e.line=0;--a)Qr(n,{from:o[a].from,to:o[a].to,text:a?[""]:e.text,origin:e.origin});else Qr(n,e)}}function Qr(n,e){if(1!=e.text.length||""!=e.text[0]||0!=le(e.from,e.to)){var t=dr(n,e);Pr(n,e,t,n.cm?n.cm.curOp.id:NaN),ti(n,e,t,Ne(n,e));var o=[];hr(n,(function(n,t){t||-1!=N(o,n.history)||(li(n.history,e),o.push(n.history)),ti(n,e,null,Ne(n,e))}))}}function ni(n,e,t){var o=n.cm&&n.cm.state.suppressEdits;if(!o||t){for(var a,r=n.history,i=n.sel,l="undo"==e?r.done:r.undone,p="undo"==e?r.undone:r.done,f=0;f=0;--m){var g=s(m);if(g)return g.v}}}}function ei(n,e){if(0!=e&&(n.first+=e,n.sel=new rr($(n.sel.ranges,(function(n){return new ir(ie(n.anchor.line+e,n.anchor.ch),ie(n.head.line+e,n.head.ch))})),n.sel.primIndex),n.cm)){Io(n.cm,n.first,n.first-e,e);for(var t=n.cm.display,o=t.viewFrom;on.lastLine())){if(e.from.liner&&(e={from:e.from,to:ie(r,Jn(n,r).text.length),text:[e.text[0]],origin:e.origin}),e.removed=Qn(n,e.from,e.to),t||(t=dr(n,e)),n.cm?oi(n.cm,e,o):_r(n,e,o),jr(n,t,j),n.cantEdit&&Xr(n,ie(n.firstLine(),0))&&(n.cantEdit=!1)}}function oi(n,e,t){var o=n.doc,a=n.display,r=e.from,i=e.to,l=!1,p=r.line;n.options.lineWrapping||(p=te(Qe(Jn(o,r.line))),o.iter(p,i.line+1,(function(n){if(n==a.maxLine)return l=!0,!0}))),o.sel.contains(e.from,e.to)>-1&&xn(n),_r(o,e,t,Fo(n)),n.options.lineWrapping||(o.iter(p,r.line+e.text.length,(function(n){var e=lt(n);e>a.maxLineLength&&(a.maxLine=n,a.maxLineLength=e,a.maxLineChanged=!0,l=!1)})),l&&(n.curOp.updateMaxLine=!0)),Me(o,r.line),Oa(n,400);var f=e.text.length-(i.line-r.line)-1;e.full?Io(n):r.line!=i.line||1!=e.text.length||br(n.doc,e)?Io(n,r.line,i.line+1,f):Ho(n,r.line,"text");var c=wn(n,"changes"),d=wn(n,"change");if(d||c){var s={from:r,to:i,text:e.text,removed:e.removed,origin:e.origin};d&&Mt(n,"change",n,s),c&&(n.curOp.changeObjs||(n.curOp.changeObjs=[])).push(s)}n.display.selForContextMenu=null}function ai(n,e,t,o,a){var r;o||(o=t),le(o,t)<0&&(t=(r=[o,t])[0],o=r[1]),"string"==typeof e&&(e=n.splitLines(e)),Jr(n,{from:t,to:o,text:e,origin:a})}function ri(n,e,t,o){t1||!(this.children[0]instanceof fi))){var l=[];this.collapse(l),this.children=[new fi(l)],this.children[0].parent=this}},collapse:function(n){for(var e=0;e50){for(var i=a.lines.length%25+25,l=i;l10);n.parent.maybeSpill()}},iterN:function(n,e,t){for(var o=0;o0||0==i&&!1!==r.clearWhenEmpty)return r;if(r.replacedWith&&(r.collapsed=!0,r.widgetNode=L("span",[r.replacedWith],"CodeMirror-widget"),o.handleMouseEvents||r.widgetNode.setAttribute("cm-ignore-events","true"),o.insertLeft&&(r.widgetNode.insertLeft=!0)),r.collapsed){if(Je(n,e.line,e,t,r)||e.line!=t.line&&Je(n,t.line,e,t,r))throw new Error("Inserting collapsed marker partially overlapping an existing one");Re()}r.addToHistory&&Pr(n,{from:e,to:t,origin:"markText"},n.sel,NaN);var l,p=e.line,f=n.cm;if(n.iter(p,t.line+1,(function(n){f&&r.collapsed&&!f.options.lineWrapping&&Qe(n)==f.display.maxLine&&(l=!0),r.collapsed&&p!=e.line&&ee(n,0),Ae(n,new Fe(r,p==e.line?e.ch:null,p==t.line?t.ch:null)),++p})),r.collapsed&&n.iter(e.line,t.line+1,(function(e){at(n,e)&&ee(e,0)})),r.clearOnEnter&&un(r,"beforeCursorEnter",(function(){return r.clear()})),r.readOnly&&(We(),(n.history.done.length||n.history.undone.length)&&n.clearHistory()),r.collapsed&&(r.id=++gi,r.atomic=!0),f){if(l&&(f.curOp.updateMaxLine=!0),r.collapsed)Io(f,e.line,t.line+1);else if(r.className||r.startStyle||r.endStyle||r.css||r.attributes||r.title)for(var c=e.line;c<=t.line;c++)Ho(f,c,"text");r.atomic&&Vr(f.doc),Mt(f,"markerAdded",f,r)}return r}ui.prototype.clear=function(){if(!this.explicitlyCleared){var n=this.doc.cm,e=n&&!n.curOp;if(e&&Ca(n),wn(this,"clear")){var t=this.find();t&&Mt(this,"clear",t.from,t.to)}for(var o=null,a=null,r=0;rn.display.maxLineLength&&(n.display.maxLine=f,n.display.maxLineLength=c,n.display.maxLineChanged=!0)}null!=o&&n&&this.collapsed&&Io(n,o,a+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,n&&Vr(n.doc)),n&&Mt(n,"markerCleared",n,this,o,a),e&&Ba(n),this.parent&&this.parent.clear()}},ui.prototype.find=function(n,e){var t,o;null==n&&"bookmark"==this.type&&(n=1);for(var a=0;a=0;p--)Jr(this,o[p]);l?Er(this,l):this.cm&&pa(this.cm)})),undo:Da((function(){ni(this,"undo")})),redo:Da((function(){ni(this,"redo")})),undoSelection:Da((function(){ni(this,"undo",!0)})),redoSelection:Da((function(){ni(this,"redo",!0)})),setExtending:function(n){this.extend=n},getExtending:function(){return this.extend},historySize:function(){for(var n=this.history,e=0,t=0,o=0;o=n.ch)&&e.push(a.marker.parent||a.marker)}return e},findMarks:function(n,e,t){n=me(this,n),e=me(this,e);var o=[],a=n.line;return this.iter(n.line,e.line+1,(function(r){var i=r.markedSpans;if(i)for(var l=0;l=p.to||null==p.from&&a!=n.line||null!=p.from&&a==e.line&&p.from>=e.ch||t&&!t(p.marker)||o.push(p.marker.parent||p.marker)}++a})),o},getAllMarks:function(){var n=[];return this.iter((function(e){var t=e.markedSpans;if(t)for(var o=0;on)return e=n,!0;n-=r,++t})),me(this,ie(t,e))},indexFromPos:function(n){var e=(n=me(this,n)).ch;if(n.linee&&(e=n.from),null!=n.to&&n.to-1)return e.state.draggingText(n),void setTimeout((function(){return e.display.input.focus()}),20);try{var d=n.dataTransfer.getData("Text");if(d){var s;if(e.state.draggingText&&!e.state.draggingText.copy&&(s=e.listSelections()),jr(e.doc,pr(t,t)),s)for(var m=0;m=0;e--)ai(n.doc,"",o[e].from,o[e].to,"+delete");pa(n)}))}function qi(n,e,t){var o=ln(n.text,e+t,t);return o<0||o>n.text.length?null:o}function Xi(n,e,t){var o=qi(n,e.ch,t);return null==o?null:new ie(e.line,o,t<0?"after":"before")}function Zi(n,e,t,o,a){if(n){"rtl"==e.doc.direction&&(a=-a);var r=mn(t,e.doc.direction);if(r){var i,l=a<0?Z(r):r[0],p=a<0==(1==l.level)?"after":"before";if(l.level>0||"rtl"==e.doc.direction){var f=to(e,t);i=a<0?t.text.length-1:0;var c=oo(e,f,i).top;i=pn((function(n){return oo(e,f,n).top==c}),a<0==(1==l.level)?l.from:l.to-1,i),"before"==p&&(i=qi(t,i,1))}else i=a<0?l.to:l.from;return new ie(o,i,p)}}return new ie(o,a<0?t.text.length:0,a<0?"before":"after")}function $i(n,e,t,o){var a=mn(e,n.doc.direction);if(!a)return Xi(e,t,o);t.ch>=e.text.length?(t.ch=e.text.length,t.sticky="before"):t.ch<=0&&(t.ch=0,t.sticky="after");var r=dn(a,t.ch,t.sticky),i=a[r];if("ltr"==n.doc.direction&&i.level%2==0&&(o>0?i.to>t.ch:i.from=i.from&&s>=c.begin)){var m=d?"before":"after";return new ie(t.line,s,m)}}var g=function(n,e,o){for(var r=function(n,e){return e?new ie(t.line,p(n,1),"before"):new ie(t.line,n,"after")};n>=0&&n0==(1!=i.level),f=l?o.begin:p(o.end,-1);if(i.from<=f&&f0?c.end:p(c.begin,-1);return null==b||o>0&&b==e.text.length||!(u=g(o>0?0:a.length-1,o,f(b)))?null:u}Ii.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},Ii.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},Ii.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars","Ctrl-O":"openLine"},Ii.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},Ii.default=h?Ii.macDefault:Ii.pcDefault;var Ki={selectAll:$r,singleSelection:function(n){return n.setSelection(n.getCursor("anchor"),n.getCursor("head"),j)},killLine:function(n){return Ui(n,(function(e){if(e.empty()){var t=Jn(n.doc,e.head.line).text.length;return e.head.ch==t&&e.head.line0)a=new ie(a.line,a.ch+1),n.replaceRange(r.charAt(a.ch-1)+r.charAt(a.ch-2),ie(a.line,a.ch-2),a,"+transpose");else if(a.line>n.doc.first){var i=Jn(n.doc,a.line-1).text;i&&(a=new ie(a.line,1),n.replaceRange(r.charAt(0)+n.doc.lineSeparator()+i.charAt(i.length-1),ie(a.line-1,i.length-1),a,"+transpose"))}t.push(new ir(a,a))}n.setSelections(t)}))},newlineAndIndent:function(n){return Wa(n,(function(){for(var e=n.listSelections(),t=e.length-1;t>=0;t--)n.replaceRange(n.doc.lineSeparator(),e[t].anchor,e[t].head,"+input");e=n.listSelections();for(var o=0;o-1&&(le((a=l.ranges[a]).from(),e)<0||e.xRel>0)&&(le(a.to(),e)>0||e.xRel<0)?yl(n,o,e,r):Cl(n,o,e,r)}function yl(n,e,t,o){var a=n.display,r=!1,f=Ra(n,(function(e){p&&(a.scroller.draggable=!1),n.state.draggingText=!1,n.state.delayingBlurEvent&&(n.hasFocus()?n.state.delayingBlurEvent=!1:Ko(n)),_n(a.wrapper.ownerDocument,"mouseup",f),_n(a.wrapper.ownerDocument,"mousemove",c),_n(a.scroller,"dragstart",d),_n(a.scroller,"drop",f),r||(kn(e),o.addNew||Or(n.doc,t,null,null,o.extend),p&&!s||i&&9==l?setTimeout((function(){a.wrapper.ownerDocument.body.focus({preventScroll:!0}),a.input.focus()}),20):a.input.focus())})),c=function(n){r=r||Math.abs(e.clientX-n.clientX)+Math.abs(e.clientY-n.clientY)>=10},d=function(){return r=!0};p&&(a.scroller.draggable=!0),n.state.draggingText=f,f.copy=!o.moveOnDrag,un(a.wrapper.ownerDocument,"mouseup",f),un(a.wrapper.ownerDocument,"mousemove",c),un(a.scroller,"dragstart",d),un(a.scroller,"drop",f),n.state.delayingBlurEvent=!0,setTimeout((function(){return a.input.focus()}),20),a.scroller.dragDrop&&a.scroller.dragDrop()}function kl(n,e,t){if("char"==t)return new ir(e,e);if("word"==t)return n.findWordAt(e);if("line"==t)return new ir(ie(e.line,0),me(n.doc,ie(e.line+1,0)));var o=t(n,e);return new ir(o.from,o.to)}function Cl(n,e,t,o){i&&Ko(n);var a=n.display,r=n.doc;kn(e);var l,p,f=r.sel,c=f.ranges;if(o.addNew&&!o.extend?(p=r.sel.contains(t),l=p>-1?c[p]:new ir(t,t)):(l=r.sel.primary(),p=r.sel.primIndex),"rectangle"==o.unit)o.addNew||(l=new ir(t,t)),t=Oo(n,e,!0,!0),p=-1;else{var d=kl(n,t,o.unit);l=o.extend?Dr(l,d.anchor,d.head,o.extend):d}o.addNew?-1==p?(p=c.length,Gr(r,lr(n,c.concat([l]),p),{scroll:!1,origin:"*mouse"})):c.length>1&&c[p].empty()&&"char"==o.unit&&!o.extend?(Gr(r,lr(n,c.slice(0,p).concat(c.slice(p+1)),0),{scroll:!1,origin:"*mouse"}),f=r.sel):Ir(r,p,l,Y):(p=0,Gr(r,new rr([l],0),Y),f=r.sel);var s=t;function m(e){if(0!=le(s,e))if(s=e,"rectangle"==o.unit){for(var a=[],i=n.options.tabSize,c=I(Jn(r,t.line).text,t.ch,i),d=I(Jn(r,e.line).text,e.ch,i),m=Math.min(c,d),g=Math.max(c,d),u=Math.min(t.line,e.line),b=Math.min(n.lastLine(),Math.max(t.line,e.line));u<=b;u++){var _=Jn(r,u).text,h=U(_,m,i);m==g?a.push(new ir(ie(u,h),ie(u,h))):_.length>h&&a.push(new ir(ie(u,h),ie(u,U(_,g,i))))}a.length||a.push(new ir(t,t)),Gr(r,lr(n,f.ranges.slice(0,p).concat(a),p),{origin:"*mouse",scroll:!1}),n.scrollIntoView(e)}else{var v,x=l,w=kl(n,e,o.unit),y=x.anchor;le(w.anchor,y)>0?(v=w.head,y=de(x.from(),w.anchor)):(v=w.anchor,y=ce(x.to(),w.head));var k=f.ranges.slice(0);k[p]=Bl(n,new ir(me(r,y),v)),Gr(r,lr(n,k,p),Y)}}var g=a.wrapper.getBoundingClientRect(),u=0;function b(e){var t=++u,i=Oo(n,e,!0,"rectangle"==o.unit);if(i)if(0!=le(i,s)){n.curOp.focus=W(),m(i);var l=ta(a,r);(i.line>=l.to||i.lineg.bottom?20:0;p&&setTimeout(Ra(n,(function(){u==t&&(a.scroller.scrollTop+=p,b(e))})),50)}}function _(e){n.state.selectingText=!1,u=1/0,e&&(kn(e),a.input.focus()),_n(a.wrapper.ownerDocument,"mousemove",h),_n(a.wrapper.ownerDocument,"mouseup",v),r.history.lastSelOrigin=null}var h=Ra(n,(function(n){0!==n.buttons&&Tn(n)?b(n):_(n)})),v=Ra(n,_);n.state.selectingText=v,un(a.wrapper.ownerDocument,"mousemove",h),un(a.wrapper.ownerDocument,"mouseup",v)}function Bl(n,e){var t=e.anchor,o=e.head,a=Jn(n.doc,t.line);if(0==le(t,o)&&t.sticky==o.sticky)return e;var r=mn(a);if(!r)return e;var i=dn(r,t.ch,t.sticky),l=r[i];if(l.from!=t.ch&&l.to!=t.ch)return e;var p,f=i+(l.from==t.ch==(1!=l.level)?0:1);if(0==f||f==r.length)return e;if(o.line!=t.line)p=(o.line-t.line)*("ltr"==n.doc.direction?1:-1)>0;else{var c=dn(r,o.ch,o.sticky),d=c-i||(o.ch-t.ch)*(1==l.level?-1:1);p=c==f-1||c==f?d<0:d>0}var s=r[f+(p?-1:0)],m=p==(1==s.level),g=m?s.from:s.to,u=m?"after":"before";return t.ch==g&&t.sticky==u?e:new ir(new ie(t.line,g,u),o)}function Pl(n,e,t,o){var a,r;if(e.touches)a=e.touches[0].clientX,r=e.touches[0].clientY;else try{a=e.clientX,r=e.clientY}catch(n){return!1}if(a>=Math.floor(n.display.gutters.getBoundingClientRect().right))return!1;o&&kn(e);var i=n.display,l=i.lineDiv.getBoundingClientRect();if(r>l.bottom||!wn(n,t))return Bn(e);r-=l.top-i.viewOffset;for(var p=0;p=a)return hn(n,t,n,oe(n.doc,r),n.display.gutterSpecs[p].className,e),Bn(e)}}function Sl(n,e){return Pl(n,e,"gutterClick",!0)}function Tl(n,e){Yt(n.display,e)||Ml(n,e)||vn(n,e,"contextmenu")||k||n.display.input.onContextMenu(e)}function Ml(n,e){return!!wn(n,"gutterContextMenu")&&Pl(n,e,"gutterContextMenu",!1)}function Ll(n){n.display.wrapper.className=n.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+n.options.theme.replace(/(^|\s)\s*/g," cm-s-"),mo(n)}bl.prototype.compare=function(n,e,t){return this.time+ul>n&&0==le(e,this.pos)&&t==this.button};var zl={toString:function(){return"CodeMirror.Init"}},Wl={},Rl={};function Fl(n){var e=n.optionHandlers;function t(t,o,a,r){n.defaults[t]=o,a&&(e[t]=r?function(n,e,t){t!=zl&&a(n,e,t)}:a)}n.defineOption=t,n.Init=zl,t("value","",(function(n,e){return n.setValue(e)}),!0),t("mode",null,(function(n,e){n.doc.modeOption=e,gr(n)}),!0),t("indentUnit",2,gr,!0),t("indentWithTabs",!1),t("smartIndent",!0),t("tabSize",4,(function(n){ur(n),mo(n),Io(n)}),!0),t("lineSeparator",null,(function(n,e){if(n.doc.lineSep=e,e){var t=[],o=n.doc.first;n.doc.iter((function(n){for(var a=0;;){var r=n.text.indexOf(e,a);if(-1==r)break;a=r+e.length,t.push(ie(o,r))}o++}));for(var a=t.length-1;a>=0;a--)ai(n.doc,e,t[a],ie(t[a].line,t[a].ch+e.length))}})),t("specialChars",/[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200c\u200e\u200f\u2028\u2029\ufeff\ufff9-\ufffc]/g,(function(n,e,t){n.state.specialChars=new RegExp(e.source+(e.test("\t")?"":"|\t"),"g"),t!=zl&&n.refresh()})),t("specialCharPlaceholder",bt,(function(n){return n.refresh()}),!0),t("electricChars",!0),t("inputStyle",_?"contenteditable":"textarea",(function(){throw new Error("inputStyle can not (yet) be changed in a running editor")}),!0),t("spellcheck",!1,(function(n,e){return n.getInputField().spellcheck=e}),!0),t("autocorrect",!1,(function(n,e){return n.getInputField().autocorrect=e}),!0),t("autocapitalize",!1,(function(n,e){return n.getInputField().autocapitalize=e}),!0),t("rtlMoveVisually",!x),t("wholeLineUpdateBefore",!0),t("theme","default",(function(n){Ll(n),Ja(n)}),!0),t("keyMap","default",(function(n,e,t){var o=Vi(e),a=t!=zl&&Vi(t);a&&a.detach&&a.detach(n,o),o.attach&&o.attach(n,a||null)})),t("extraKeys",null),t("configureMouse",null),t("lineWrapping",!1,Ol,!0),t("gutters",[],(function(n,e){n.display.gutterSpecs=$a(e,n.options.lineNumbers),Ja(n)}),!0),t("fixedGutter",!0,(function(n,e){n.display.gutters.style.left=e?Ro(n.display)+"px":"0",n.refresh()}),!0),t("coverGutterNextToScrollbar",!1,(function(n){return va(n)}),!0),t("scrollbarStyle","native",(function(n){ya(n),va(n),n.display.scrollbars.setScrollTop(n.doc.scrollTop),n.display.scrollbars.setScrollLeft(n.doc.scrollLeft)}),!0),t("lineNumbers",!1,(function(n,e){n.display.gutterSpecs=$a(n.options.gutters,e),Ja(n)}),!0),t("firstLineNumber",1,Ja,!0),t("lineNumberFormatter",(function(n){return n}),Ja,!0),t("showCursorWhenSelecting",!1,Yo,!0),t("resetSelectionOnContextMenu",!0),t("lineWiseCopyCut",!0),t("pasteLinesPerSelection",!0),t("selectionsMayTouch",!1),t("readOnly",!1,(function(n,e){"nocursor"==e&&(Qo(n),n.display.input.blur()),n.display.input.readOnlyChanged(e)})),t("screenReaderLabel",null,(function(n,e){e=""===e?null:e,n.display.input.screenReaderLabelChanged(e)})),t("disableInput",!1,(function(n,e){e||n.display.input.reset()}),!0),t("dragDrop",!0,Dl),t("allowDropFileTypes",null),t("cursorBlinkRate",530),t("cursorScrollMargin",0),t("cursorHeight",1,Yo,!0),t("singleCursorHeightPerLine",!0,Yo,!0),t("workTime",100),t("workDelay",100),t("flattenSpans",!0,ur,!0),t("addModeClass",!1,ur,!0),t("pollInterval",100),t("undoDepth",200,(function(n,e){return n.doc.history.undoDepth=e})),t("historyEventDelay",1250),t("viewportMargin",10,(function(n){return n.refresh()}),!0),t("maxHighlightLength",1e4,ur,!0),t("moveInputWithCursor",!0,(function(n,e){e||n.display.input.resetPosition()})),t("tabindex",null,(function(n,e){return n.display.input.getField().tabIndex=e||""})),t("autofocus",null),t("direction","ltr",(function(n,e){return n.doc.setDirection(e)}),!0),t("phrases",null)}function Dl(n,e,t){if(!e!=!(t&&t!=zl)){var o=n.display.dragFunctions,a=e?un:_n;a(n.display.scroller,"dragstart",o.start),a(n.display.scroller,"dragenter",o.enter),a(n.display.scroller,"dragover",o.over),a(n.display.scroller,"dragleave",o.leave),a(n.display.scroller,"drop",o.drop)}}function Ol(n){n.options.lineWrapping?(R(n.display.wrapper,"CodeMirror-wrap"),n.display.sizer.style.minWidth="",n.display.sizerWidth=null):(P(n.display.wrapper,"CodeMirror-wrap"),pt(n)),Do(n),Io(n),mo(n),setTimeout((function(){return va(n)}),100)}function Al(n,e){var t=this;if(!(this instanceof Al))return new Al(n,e);this.options=e=e?A(e):{},A(Wl,e,!1);var o=e.value;"string"==typeof o?o=new ki(o,e.mode,null,e.lineSeparator,e.direction):e.mode&&(o.modeOption=e.mode),this.doc=o;var a=new Al.inputStyles[e.inputStyle](this),r=this.display=new Qa(n,o,a,e);for(var f in r.wrapper.CodeMirror=this,Ll(this),e.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),ya(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 H,keySeq:null,specialChars:null},e.autofocus&&!_&&r.input.focus(),i&&l<11&&setTimeout((function(){return t.display.input.reset(!0)}),20),Il(this),zi(),Ca(this),this.curOp.forceUpdate=!0,vr(this,o),e.autofocus&&!_||this.hasFocus()?setTimeout((function(){t.hasFocus()&&!t.state.focused&&Jo(t)}),20):Qo(this),Rl)Rl.hasOwnProperty(f)&&Rl[f](this,e[f],zl);Za(this),e.finishInit&&e.finishInit(this);for(var c=0;c400}un(e.scroller,"touchstart",(function(a){if(!vn(n,a)&&!r(a)&&!Sl(n,a)){e.input.ensurePolled(),clearTimeout(t);var i=+new Date;e.activeTouch={start:i,moved:!1,prev:i-o.end<=300?o:null},1==a.touches.length&&(e.activeTouch.left=a.touches[0].pageX,e.activeTouch.top=a.touches[0].pageY)}})),un(e.scroller,"touchmove",(function(){e.activeTouch&&(e.activeTouch.moved=!0)})),un(e.scroller,"touchend",(function(t){var o=e.activeTouch;if(o&&!Yt(e,t)&&null!=o.left&&!o.moved&&new Date-o.start<300){var r,i=n.coordsChar(e.activeTouch,"page");r=!o.prev||p(o,o.prev)?new ir(i,i):!o.prev.prev||p(o,o.prev.prev)?n.findWordAt(i):new ir(ie(i.line,0),me(n.doc,ie(i.line+1,0))),n.setSelection(r.anchor,r.head),n.focus(),kn(t)}a()})),un(e.scroller,"touchcancel",a),un(e.scroller,"scroll",(function(){e.scroller.clientHeight&&(ma(n,e.scroller.scrollTop),ua(n,e.scroller.scrollLeft,!0),hn(n,"scroll",n))})),un(e.scroller,"mousewheel",(function(e){return ar(n,e)})),un(e.scroller,"DOMMouseScroll",(function(e){return ar(n,e)})),un(e.wrapper,"scroll",(function(){return e.wrapper.scrollTop=e.wrapper.scrollLeft=0})),e.dragFunctions={enter:function(e){vn(n,e)||Pn(e)},over:function(e){vn(n,e)||(Si(n,e),Pn(e))},start:function(e){return Pi(n,e)},drop:Ra(n,Bi),leave:function(e){vn(n,e)||Ti(n)}};var f=e.input.getField();un(f,"keyup",(function(e){return dl.call(n,e)})),un(f,"keydown",Ra(n,fl)),un(f,"keypress",Ra(n,sl)),un(f,"focus",(function(e){return Jo(n,e)})),un(f,"blur",(function(e){return Qo(n,e)}))}Al.defaults=Wl,Al.optionHandlers=Rl;var Hl=[];function Nl(n,e,t,o){var a,r=n.doc;null==t&&(t="add"),"smart"==t&&(r.mode.indent?a=xe(n,e).state:t="prev");var i=n.options.tabSize,l=Jn(r,e),p=I(l.text,null,i);l.stateAfter&&(l.stateAfter=null);var f,c=l.text.match(/^\s*/)[0];if(o||/\S/.test(l.text)){if("smart"==t&&((f=r.mode.indent(a,l.text.slice(c.length),l.text))==G||f>150)){if(!o)return;t="prev"}}else f=0,t="not";"prev"==t?f=e>r.first?I(Jn(r,e-1).text,null,i):0:"add"==t?f=p+n.options.indentUnit:"subtract"==t?f=p-n.options.indentUnit:"number"==typeof t&&(f=p+t),f=Math.max(0,f);var d="",s=0;if(n.options.indentWithTabs)for(var m=Math.floor(f/i);m;--m)s+=i,d+="\t";if(si,p=Dn(e),f=null;if(l&&o.ranges.length>1)if(El&&El.text.join("\n")==e){if(o.ranges.length%El.text.length==0){f=[];for(var c=0;c=0;s--){var m=o.ranges[s],g=m.from(),u=m.to();m.empty()&&(t&&t>0?g=ie(g.line,g.ch-t):n.state.overwrite&&!l?u=ie(u.line,Math.min(Jn(r,u.line).text.length,u.ch+Z(p).length)):l&&El&&El.lineWise&&El.text.join("\n")==p.join("\n")&&(g=u=ie(g.line,0)));var b={from:g,to:u,text:f?f[s%f.length]:p,origin:a||(l?"paste":n.state.cutIncoming>i?"cut":"+input")};Jr(n.doc,b),Mt(n,"inputRead",n,b)}e&&!l&&Vl(n,e),pa(n),n.curOp.updateInput<2&&(n.curOp.updateInput=d),n.curOp.typing=!0,n.state.pasteIncoming=n.state.cutIncoming=-1}function Yl(n,e){var t=n.clipboardData&&n.clipboardData.getData("Text");if(t)return n.preventDefault(),e.isReadOnly()||e.options.disableInput||Wa(e,(function(){return jl(e,t,0,null,"paste")})),!0}function Vl(n,e){if(n.options.electricChars&&n.options.smartIndent)for(var t=n.doc.sel,o=t.ranges.length-1;o>=0;o--){var a=t.ranges[o];if(!(a.head.ch>100||o&&t.ranges[o-1].head.line==a.head.line)){var r=n.getModeAt(a.head),i=!1;if(r.electricChars){for(var l=0;l-1){i=Nl(n,a.head.line,"smart");break}}else r.electricInput&&r.electricInput.test(Jn(n.doc,a.head.line).text.slice(0,a.head.ch))&&(i=Nl(n,a.head.line,"smart"));i&&Mt(n,"electricInput",n,a.head.line)}}}function Ul(n){for(var e=[],t=[],o=0;ot&&(Nl(this,a.head.line,n,!0),t=a.head.line,o==this.doc.sel.primIndex&&pa(this));else{var r=a.from(),i=a.to(),l=Math.max(t,r.line);t=Math.min(this.lastLine(),i.line-(i.ch?0:1))+1;for(var p=l;p0&&Ir(this.doc,o,new ir(r,f[o].to()),j)}}})),getTokenAt:function(n,e){return Be(this,n,e)},getLineTokens:function(n,e){return Be(this,ie(n),e,!0)},getTokenTypeAt:function(n){n=me(this.doc,n);var e,t=ve(this,Jn(this.doc,n.line)),o=0,a=(t.length-1)/2,r=n.ch;if(0==r)e=t[2];else for(;;){var i=o+a>>1;if((i?t[2*i-1]:0)>=r)a=i;else{if(!(t[2*i+1]r&&(n=r,a=!0),o=Jn(this.doc,n)}else o=n;return _o(this,o,{top:0,left:0},e||"page",t||a).top+(a?this.doc.height-it(o):0)},defaultTextHeight:function(){return Lo(this.display)},defaultCharWidth:function(){return zo(this.display)},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(n,e,t,o,a){var r=this.display,i=(n=xo(this,me(this.doc,n))).bottom,l=n.left;if(e.style.position="absolute",e.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(e),r.sizer.appendChild(e),"over"==o)i=n.top;else if("above"==o||"near"==o){var p=Math.max(r.wrapper.clientHeight,this.doc.height),f=Math.max(r.sizer.clientWidth,r.lineSpace.clientWidth);("above"==o||n.bottom+e.offsetHeight>p)&&n.top>e.offsetHeight?i=n.top-e.offsetHeight:n.bottom+e.offsetHeight<=p&&(i=n.bottom),l+e.offsetWidth>f&&(l=f-e.offsetWidth)}e.style.top=i+"px",e.style.left=e.style.right="","right"==a?(l=r.sizer.clientWidth-e.offsetWidth,e.style.right="0px"):("left"==a?l=0:"middle"==a&&(l=(r.sizer.clientWidth-e.offsetWidth)/2),e.style.left=l+"px"),t&&ra(this,{left:l,top:i,right:l+e.offsetWidth,bottom:i+e.offsetHeight})},triggerOnKeyDown:Fa(fl),triggerOnKeyPress:Fa(sl),triggerOnKeyUp:dl,triggerOnMouseDown:Fa(hl),execCommand:function(n){if(Ki.hasOwnProperty(n))return Ki[n].call(null,this)},triggerElectric:Fa((function(n){Vl(this,n)})),findPosH:function(n,e,t,o){var a=1;e<0&&(a=-1,e=-e);for(var r=me(this.doc,n),i=0;i0&&i(e.charAt(t-1));)--t;for(;o.5||this.options.lineWrapping)&&Do(this),hn(this,"refresh",this)})),swapDoc:Fa((function(n){var e=this.doc;return e.cm=null,this.state.selectingText&&this.state.selectingText(),vr(this,n),mo(this),this.display.input.reset(),fa(this,n.scrollLeft,n.scrollTop),this.curOp.forceScroll=!0,Mt(this,"swapDoc",this,e),e})),phrase:function(n){var e=this.options.phrases;return e&&Object.prototype.hasOwnProperty.call(e,n)?e[n]:n},getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},yn(n),n.registerHelper=function(e,o,a){t.hasOwnProperty(e)||(t[e]=n[e]={_global:[]}),t[e][o]=a},n.registerGlobalHelper=function(e,o,a,r){n.registerHelper(e,o,r),t[e]._global.push({pred:a,val:r})}}function $l(n,e,t,o,a){var r=e,i=t,l=Jn(n,e.line),p=a&&"rtl"==n.direction?-t:t;function f(){var t=e.line+p;return!(t=n.first+n.size)&&(e=new ie(t,e.ch,e.sticky),l=Jn(n,t))}function c(r){var i;if("codepoint"==o){var c=l.text.charCodeAt(e.ch+(o>0?0:-1));i=isNaN(c)?null:new ie(e.line,Math.max(0,Math.min(l.text.length,e.ch+t*(c>=55296&&c<56320?2:1))),-t)}else i=a?$i(n.cm,l,e,t):Xi(l,e,t);if(null==i){if(r||!f())return!1;e=Zi(a,n.cm,l,e.line,p)}else e=i;return!0}if("char"==o||"codepoint"==o)c();else if("column"==o)c(!0);else if("word"==o||"group"==o)for(var d=null,s="group"==o,m=n.cm&&n.cm.getHelper(e,"wordChars"),g=!0;!(t<0)||c(!g);g=!1){var u=l.text.charAt(e.ch)||"\n",b=tn(u,m)?"w":s&&"\n"==u?"n":!s||/\s/.test(u)?null:"p";if(!s||g||b||(b="s"),d&&d!=b){t<0&&(t=1,c(),e.sticky="after");break}if(b&&(d=b),t>0&&!c(!g))break}var _=Xr(n,e,r,i,!0);return pe(r,_)&&(_.hitSide=!0),_}function Kl(n,e,t,o){var a,r,i=n.doc,l=e.left;if("page"==o){var p=Math.min(n.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),f=Math.max(p-.5*Lo(n.display),3);a=(t>0?e.bottom:e.top)+t*f}else"line"==o&&(a=t>0?e.bottom+3:e.top-3);for(;(r=ko(n,l,a)).outside;){if(t<0?a<=0:a>=i.height){r.hitSide=!0;break}a+=5*t}return r}var Jl=function(n){this.cm=n,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new H,this.composing=null,this.gracePeriod=!1,this.readDOMTimeout=null};function Ql(n,e){var t=eo(n,e.line);if(!t||t.hidden)return null;var o=Jn(n.doc,e.line),a=Jt(t,o,e.line),r=mn(o,n.doc.direction),i="left";r&&(i=dn(r,e.ch)%2?"right":"left");var l=io(a.map,e.ch,i);return l.offset="right"==l.collapse?l.end:l.start,l}function np(n){for(var e=n;e;e=e.parentNode)if(/CodeMirror-gutter-wrapper/.test(e.className))return!0;return!1}function ep(n,e){return e&&(n.bad=!0),n}function tp(n,e,t,o,a){var r="",i=!1,l=n.doc.lineSeparator(),p=!1;function f(n){return function(e){return e.id==n}}function c(){i&&(r+=l,p&&(r+=l),i=p=!1)}function d(n){n&&(c(),r+=n)}function s(e){if(1==e.nodeType){var t=e.getAttribute("cm-text");if(t)return void d(t);var r,m=e.getAttribute("cm-marker");if(m){var g=n.findMarks(ie(o,0),ie(a+1,0),f(+m));return void(g.length&&(r=g[0].find(0))&&d(Qn(n.doc,r.from,r.to).join(l)))}if("false"==e.getAttribute("contenteditable"))return;var u=/^(pre|div|p|li|table|br)$/i.test(e.nodeName);if(!/^br$/i.test(e.nodeName)&&0==e.textContent.length)return;u&&c();for(var b=0;b=e.display.viewTo||r.line=e.display.viewFrom&&Ql(e,a)||{node:p[0].measure.map[2],offset:0},c=r.lineo.firstLine()&&(i=ie(i.line-1,Jn(o.doc,i.line-1).length)),l.ch==Jn(o.doc,l.line).text.length&&l.linea.viewTo-1)return!1;i.line==a.viewFrom||0==(n=Ao(o,i.line))?(e=te(a.view[0].line),t=a.view[0].node):(e=te(a.view[n].line),t=a.view[n-1].node.nextSibling);var p,f,c=Ao(o,l.line);if(c==a.view.length-1?(p=a.viewTo-1,f=a.lineDiv.lastChild):(p=te(a.view[c+1].line)-1,f=a.view[c+1].node.previousSibling),!t)return!1;for(var d=o.doc.splitLines(tp(o,t,f,e,p)),s=Qn(o.doc,ie(e,0),ie(p,Jn(o.doc,p).text.length));d.length>1&&s.length>1;)if(Z(d)==Z(s))d.pop(),s.pop(),p--;else{if(d[0]!=s[0])break;d.shift(),s.shift(),e++}for(var m=0,g=0,u=d[0],b=s[0],_=Math.min(u.length,b.length);m<_&&u.charCodeAt(m)==b.charCodeAt(m);)++m;for(var h=Z(d),v=Z(s),x=Math.min(h.length-(1==d.length?m:0),v.length-(1==s.length?m:0));gi.ch&&h.charCodeAt(h.length-g-1)==v.charCodeAt(v.length-g-1);)m--,g++;d[d.length-1]=h.slice(0,h.length-g).replace(/^\u200b+/,""),d[0]=d[0].slice(m).replace(/\u200b+$/,"");var w=ie(e,m),y=ie(p,s.length?Z(s).length-g:0);return d.length>1||d[0]||le(w,y)?(ai(o.doc,d,w,y,"+input"),!0):void 0},Jl.prototype.ensurePolled=function(){this.forceCompositionEnd()},Jl.prototype.reset=function(){this.forceCompositionEnd()},Jl.prototype.forceCompositionEnd=function(){this.composing&&(clearTimeout(this.readDOMTimeout),this.composing=null,this.updateFromDOM(),this.div.blur(),this.div.focus())},Jl.prototype.readFromDOMSoon=function(){var n=this;null==this.readDOMTimeout&&(this.readDOMTimeout=setTimeout((function(){if(n.readDOMTimeout=null,n.composing){if(!n.composing.done)return;n.composing=null}n.updateFromDOM()}),80))},Jl.prototype.updateFromDOM=function(){var n=this;!this.cm.isReadOnly()&&this.pollContent()||Wa(this.cm,(function(){return Io(n.cm)}))},Jl.prototype.setUneditable=function(n){n.contentEditable="false"},Jl.prototype.onKeyPress=function(n){0==n.charCode||this.composing||(n.preventDefault(),this.cm.isReadOnly()||Ra(this.cm,jl)(this.cm,String.fromCharCode(null==n.charCode?n.keyCode:n.charCode),0))},Jl.prototype.readOnlyChanged=function(n){this.div.contentEditable=String("nocursor"!=n)},Jl.prototype.onContextMenu=function(){},Jl.prototype.resetPosition=function(){},Jl.prototype.needsContentAttribute=!0;var rp=function(n){this.cm=n,this.prevInput="",this.pollingFast=!1,this.polling=new H,this.hasSelection=!1,this.composing=null};function ip(n,e){if((e=e?A(e):{}).value=n.value,!e.tabindex&&n.tabIndex&&(e.tabindex=n.tabIndex),!e.placeholder&&n.placeholder&&(e.placeholder=n.placeholder),null==e.autofocus){var t=W();e.autofocus=t==n||null!=n.getAttribute("autofocus")&&t==document.body}function o(){n.value=l.getValue()}var a;if(n.form&&(un(n.form,"submit",o),!e.leaveSubmitMethodAlone)){var r=n.form;a=r.submit;try{var i=r.submit=function(){o(),r.submit=a,r.submit(),r.submit=i}}catch(n){}}e.finishInit=function(t){t.save=o,t.getTextArea=function(){return n},t.toTextArea=function(){t.toTextArea=isNaN,o(),n.parentNode.removeChild(t.getWrapperElement()),n.style.display="",n.form&&(_n(n.form,"submit",o),e.leaveSubmitMethodAlone||"function"!=typeof n.form.submit||(n.form.submit=a))}},n.style.display="none";var l=Al((function(e){return n.parentNode.insertBefore(e,n.nextSibling)}),e);return l}function lp(n){n.off=_n,n.on=un,n.wheelEventPixels=or,n.Doc=ki,n.splitLines=Dn,n.countColumn=I,n.findColumn=U,n.isWordChar=en,n.Pass=G,n.signal=hn,n.Line=ft,n.changeEnd=fr,n.scrollbarModel=wa,n.Pos=ie,n.cmpPos=le,n.modes=Nn,n.mimeModes=En,n.resolveMode=Yn,n.getMode=Vn,n.modeExtensions=Un,n.extendMode=qn,n.copyState=Xn,n.startState=$n,n.innerMode=Zn,n.commands=Ki,n.keyMap=Ii,n.keyName=Yi,n.isModifierKey=Gi,n.lookupKey=Ei,n.normalizeKeyMap=Ni,n.StringStream=Kn,n.SharedTextMarker=_i,n.TextMarker=ui,n.LineWidget=di,n.e_preventDefault=kn,n.e_stopPropagation=Cn,n.e_stop=Pn,n.addClass=R,n.contains=z,n.rmClass=P,n.keyNames=Fi}rp.prototype.init=function(n){var e=this,t=this,o=this.cm;this.createField(n);var a=this.textarea;function r(n){if(!vn(o,n)){if(o.somethingSelected())Gl({lineWise:!1,text:o.getSelections()});else{if(!o.options.lineWiseCopyCut)return;var e=Ul(o);Gl({lineWise:!0,text:e.text}),"cut"==n.type?o.setSelections(e.ranges,null,j):(t.prevInput="",a.value=e.text.join("\n"),D(a))}"cut"==n.type&&(o.state.cutIncoming=+new Date)}}n.wrapper.insertBefore(this.wrapper,n.wrapper.firstChild),u&&(a.style.width="0px"),un(a,"input",(function(){i&&l>=9&&e.hasSelection&&(e.hasSelection=null),t.poll()})),un(a,"paste",(function(n){vn(o,n)||Yl(n,o)||(o.state.pasteIncoming=+new Date,t.fastPoll())})),un(a,"cut",r),un(a,"copy",r),un(n.scroller,"paste",(function(e){if(!Yt(n,e)&&!vn(o,e)){if(!a.dispatchEvent)return o.state.pasteIncoming=+new Date,void t.focus();var r=new Event("paste");r.clipboardData=e.clipboardData,a.dispatchEvent(r)}})),un(n.lineSpace,"selectstart",(function(e){Yt(n,e)||kn(e)})),un(a,"compositionstart",(function(){var n=o.getCursor("from");t.composing&&t.composing.range.clear(),t.composing={start:n,range:o.markText(n,o.getCursor("to"),{className:"CodeMirror-composing"})}})),un(a,"compositionend",(function(){t.composing&&(t.poll(),t.composing.range.clear(),t.composing=null)}))},rp.prototype.createField=function(n){this.wrapper=Xl(),this.textarea=this.wrapper.firstChild},rp.prototype.screenReaderLabelChanged=function(n){n?this.textarea.setAttribute("aria-label",n):this.textarea.removeAttribute("aria-label")},rp.prototype.prepareSelection=function(){var n=this.cm,e=n.display,t=n.doc,o=Vo(n);if(n.options.moveInputWithCursor){var a=xo(n,t.sel.primary().head,"div"),r=e.wrapper.getBoundingClientRect(),i=e.lineDiv.getBoundingClientRect();o.teTop=Math.max(0,Math.min(e.wrapper.clientHeight-10,a.top+i.top-r.top)),o.teLeft=Math.max(0,Math.min(e.wrapper.clientWidth-10,a.left+i.left-r.left))}return o},rp.prototype.showSelection=function(n){var e=this.cm.display;T(e.cursorDiv,n.cursors),T(e.selectionDiv,n.selection),null!=n.teTop&&(this.wrapper.style.top=n.teTop+"px",this.wrapper.style.left=n.teLeft+"px")},rp.prototype.reset=function(n){if(!this.contextMenuPending&&!this.composing){var e=this.cm;if(e.somethingSelected()){this.prevInput="";var t=e.getSelection();this.textarea.value=t,e.state.focused&&D(this.textarea),i&&l>=9&&(this.hasSelection=t)}else n||(this.prevInput=this.textarea.value="",i&&l>=9&&(this.hasSelection=null))}},rp.prototype.getField=function(){return this.textarea},rp.prototype.supportsTouch=function(){return!1},rp.prototype.focus=function(){if("nocursor"!=this.cm.options.readOnly&&(!_||W()!=this.textarea))try{this.textarea.focus()}catch(n){}},rp.prototype.blur=function(){this.textarea.blur()},rp.prototype.resetPosition=function(){this.wrapper.style.top=this.wrapper.style.left=0},rp.prototype.receivedFocus=function(){this.slowPoll()},rp.prototype.slowPoll=function(){var n=this;this.pollingFast||this.polling.set(this.cm.options.pollInterval,(function(){n.poll(),n.cm.state.focused&&n.slowPoll()}))},rp.prototype.fastPoll=function(){var n=!1,e=this;function t(){e.poll()||n?(e.pollingFast=!1,e.slowPoll()):(n=!0,e.polling.set(60,t))}e.pollingFast=!0,e.polling.set(20,t)},rp.prototype.poll=function(){var n=this,e=this.cm,t=this.textarea,o=this.prevInput;if(this.contextMenuPending||!e.state.focused||On(t)&&!o&&!this.composing||e.isReadOnly()||e.options.disableInput||e.state.keySeq)return!1;var a=t.value;if(a==o&&!e.somethingSelected())return!1;if(i&&l>=9&&this.hasSelection===a||h&&/[\uf700-\uf7ff]/.test(a))return e.display.input.reset(),!1;if(e.doc.sel==e.display.selForContextMenu){var r=a.charCodeAt(0);if(8203!=r||o||(o=""),8666==r)return this.reset(),this.cm.execCommand("undo")}for(var p=0,f=Math.min(o.length,a.length);p1e3||a.indexOf("\n")>-1?t.value=n.prevInput="":n.prevInput=a,n.composing&&(n.composing.range.clear(),n.composing.range=e.markText(n.composing.start,e.getCursor("to"),{className:"CodeMirror-composing"}))})),!0},rp.prototype.ensurePolled=function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},rp.prototype.onKeyPress=function(){i&&l>=9&&(this.hasSelection=null),this.fastPoll()},rp.prototype.onContextMenu=function(n){var e=this,t=e.cm,o=t.display,a=e.textarea;e.contextMenuPending&&e.contextMenuPending();var r=Oo(t,n),f=o.scroller.scrollTop;if(r&&!d){t.options.resetSelectionOnContextMenu&&-1==t.doc.sel.contains(r)&&Ra(t,Gr)(t.doc,pr(r),j);var c,s=a.style.cssText,m=e.wrapper.style.cssText,g=e.wrapper.offsetParent.getBoundingClientRect();if(e.wrapper.style.cssText="position: static",a.style.cssText="position: absolute; width: 30px; height: 30px;\n top: "+(n.clientY-g.top-5)+"px; left: "+(n.clientX-g.left-5)+"px;\n z-index: 1000; background: "+(i?"rgba(255, 255, 255, .05)":"transparent")+";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",p&&(c=window.scrollY),o.input.focus(),p&&window.scrollTo(null,c),o.input.reset(),t.somethingSelected()||(a.value=e.prevInput=" "),e.contextMenuPending=_,o.selForContextMenu=t.doc.sel,clearTimeout(o.detectingSelectAll),i&&l>=9&&b(),k){Pn(n);var u=function(){_n(window,"mouseup",u),setTimeout(_,20)};un(window,"mouseup",u)}else setTimeout(_,50)}function b(){if(null!=a.selectionStart){var n=t.somethingSelected(),r=""+(n?a.value:"");a.value="⇚",a.value=r,e.prevInput=n?"":"",a.selectionStart=1,a.selectionEnd=r.length,o.selForContextMenu=t.doc.sel}}function _(){if(e.contextMenuPending==_&&(e.contextMenuPending=!1,e.wrapper.style.cssText=m,a.style.cssText=s,i&&l<9&&o.scrollbars.setScrollTop(o.scroller.scrollTop=f),null!=a.selectionStart)){(!i||i&&l<9)&&b();var n=0,r=function(){o.selForContextMenu==t.doc.sel&&0==a.selectionStart&&a.selectionEnd>0&&""==e.prevInput?Ra(t,$r)(t):n++<10?o.detectingSelectAll=setTimeout(r,500):(o.selForContextMenu=null,o.input.reset())};o.detectingSelectAll=setTimeout(r,200)}}},rp.prototype.readOnlyChanged=function(n){n||this.reset(),this.textarea.disabled="nocursor"==n,this.textarea.readOnly=!!n},rp.prototype.setUneditable=function(){},rp.prototype.needsContentAttribute=!1,Fl(Al),Zl(Al);var pp="iter insert remove copy getEditor constructor".split(" ");for(var fp in ki.prototype)ki.prototype.hasOwnProperty(fp)&&N(pp,fp)<0&&(Al.prototype[fp]=function(n){return function(){return n.apply(this.doc,arguments)}}(ki.prototype[fp]));return yn(ki),Al.inputStyles={textarea:rp,contenteditable:Jl},Al.defineMode=function(n){Al.defaults.mode||"null"==n||(Al.defaults.mode=n),Gn.apply(this,arguments)},Al.defineMIME=jn,Al.defineMode("null",(function(){return{token:function(n){return n.skipToEnd()}}})),Al.defineMIME("text/plain","null"),Al.defineExtension=function(n,e){Al.prototype[n]=e},Al.defineDocExtension=function(n,e){ki.prototype[n]=e},Al.fromTextArea=ip,lp(Al),Al.version="5.58.3",Al}()}));un((function(n,e){!function(n){function e(e,o){function a(){e.display.wrapper.offsetHeight?(t(e,o),e.display.lastWrapHeight!=e.display.wrapper.clientHeight&&e.refresh()):o.timeout=setTimeout(a,o.delay)}o.timeout=setTimeout(a,o.delay),o.hurry=function(){clearTimeout(o.timeout),o.timeout=setTimeout(a,50)},n.on(window,"mouseup",o.hurry),n.on(window,"keyup",o.hurry)}function t(e,t){clearTimeout(t.timeout),n.off(window,"mouseup",t.hurry),n.off(window,"keyup",t.hurry)}n.defineOption("autoRefresh",!1,(function(n,o){n.state.autoRefresh&&(t(n,n.state.autoRefresh),n.state.autoRefresh=null),o&&0==n.display.wrapper.offsetHeight&&e(n,n.state.autoRefresh={delay:o.delay||250})}))}(bn)})),un((function(n,e){var t,o,a;o={autoSelfClosers:{area:!0,base:!0,br:!0,col:!0,command:!0,embed:!0,frame:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0,menuitem:!0},implicitlyClosed:{dd:!0,li:!0,optgroup:!0,option:!0,p:!0,rp:!0,rt:!0,tbody:!0,td:!0,tfoot:!0,th:!0,tr:!0},contextGrabbers:{dd:{dd:!0,dt:!0},dt:{dd:!0,dt:!0},li:{li:!0},option:{option:!0,optgroup:!0},optgroup:{optgroup:!0},p:{address:!0,article:!0,aside:!0,blockquote:!0,dir:!0,div:!0,dl:!0,fieldset:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,menu:!0,nav:!0,ol:!0,p:!0,pre:!0,section:!0,table:!0,ul:!0},rp:{rp:!0,rt:!0},rt:{rp:!0,rt:!0},tbody:{tbody:!0,tfoot:!0},td:{td:!0,th:!0},tfoot:{tbody:!0},th:{td:!0,th:!0},thead:{tbody:!0,tfoot:!0},tr:{tr:!0}},doNotIndent:{pre:!0},allowUnquoted:!0,allowMissing:!0,caseFold:!0},a={autoSelfClosers:{},implicitlyClosed:{},contextGrabbers:{},doNotIndent:{},allowUnquoted:!1,allowMissing:!1,allowMissingTagName:!1,caseFold:!1},(t=bn).defineMode("xml",(function(n,e){var r,i,l=n.indentUnit,p={},f=e.htmlMode?o:a;for(var c in f)p[c]=f[c];for(var c in e)p[c]=e[c];function d(n,e){function t(t){return e.tokenize=t,t(n,e)}var o=n.next();return"<"==o?n.eat("!")?n.eat("[")?n.match("CDATA[")?t(g("atom","]]>")):null:n.match("--")?t(g("comment","--\x3e")):n.match("DOCTYPE",!0,!0)?(n.eatWhile(/[\w\._\-]/),t(u(1))):null:n.eat("?")?(n.eatWhile(/[\w\._\-]/),e.tokenize=g("meta","?>"),"meta"):(r=n.eat("/")?"closeTag":"openTag",e.tokenize=s,"tag bracket"):"&"==o?(n.eat("#")?n.eat("x")?n.eatWhile(/[a-fA-F\d]/)&&n.eat(";"):n.eatWhile(/[\d]/)&&n.eat(";"):n.eatWhile(/[\w\.\-:]/)&&n.eat(";"))?"atom":"error":(n.eatWhile(/[^&<]/),null)}function s(n,e){var t=n.next();if(">"==t||"/"==t&&n.eat(">"))return e.tokenize=d,r=">"==t?"endTag":"selfcloseTag","tag bracket";if("="==t)return r="equals",null;if("<"==t){e.tokenize=d,e.state=v,e.tagName=e.tagStart=null;var o=e.tokenize(n,e);return o?o+" tag error":"tag error"}return/[\'\"]/.test(t)?(e.tokenize=m(t),e.stringStartCol=n.column(),e.tokenize(n,e)):(n.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/),"word")}function m(n){var e=function(e,t){for(;!e.eol();)if(e.next()==n){t.tokenize=s;break}return"string"};return e.isInAttribute=!0,e}function g(n,e){return function(t,o){for(;!t.eol();){if(t.match(e)){o.tokenize=d;break}t.next()}return n}}function u(n){return function(e,t){for(var o;null!=(o=e.next());){if("<"==o)return t.tokenize=u(n+1),t.tokenize(e,t);if(">"==o){if(1==n){t.tokenize=d;break}return t.tokenize=u(n-1),t.tokenize(e,t)}}return"meta"}}function b(n,e,t){this.prev=n.context,this.tagName=e||"",this.indent=n.indented,this.startOfLine=t,(p.doNotIndent.hasOwnProperty(e)||n.context&&n.context.noIndent)&&(this.noIndent=!0)}function _(n){n.context&&(n.context=n.context.prev)}function h(n,e){for(var t;;){if(!n.context)return;if(t=n.context.tagName,!p.contextGrabbers.hasOwnProperty(t)||!p.contextGrabbers[t].hasOwnProperty(e))return;_(n)}}function v(n,e,t){return"openTag"==n?(t.tagStart=e.column(),x):"closeTag"==n?w:v}function x(n,e,t){return"word"==n?(t.tagName=e.current(),i="tag",C):p.allowMissingTagName&&"endTag"==n?(i="tag bracket",C(n,e,t)):(i="error",x)}function w(n,e,t){if("word"==n){var o=e.current();return t.context&&t.context.tagName!=o&&p.implicitlyClosed.hasOwnProperty(t.context.tagName)&&_(t),t.context&&t.context.tagName==o||!1===p.matchClosing?(i="tag",y):(i="tag error",k)}return p.allowMissingTagName&&"endTag"==n?(i="tag bracket",y(n,e,t)):(i="error",k)}function y(n,e,t){return"endTag"!=n?(i="error",y):(_(t),v)}function k(n,e,t){return i="error",y(n,e,t)}function C(n,e,t){if("word"==n)return i="attribute",B;if("endTag"==n||"selfcloseTag"==n){var o=t.tagName,a=t.tagStart;return t.tagName=t.tagStart=null,"selfcloseTag"==n||p.autoSelfClosers.hasOwnProperty(o)?h(t,o):(h(t,o),t.context=new b(t,o,a==t.indented)),v}return i="error",C}function B(n,e,t){return"equals"==n?P:(p.allowMissing||(i="error"),C(n,e,t))}function P(n,e,t){return"string"==n?S:"word"==n&&p.allowUnquoted?(i="string",C):(i="error",C(n,e,t))}function S(n,e,t){return"string"==n?S:C(n,e,t)}return d.isInText=!0,{startState:function(n){var e={tokenize:d,state:v,indented:n||0,tagName:null,tagStart:null,context:null};return null!=n&&(e.baseIndent=n),e},token:function(n,e){if(!e.tagName&&n.sol()&&(e.indented=n.indentation()),n.eatSpace())return null;r=null;var t=e.tokenize(n,e);return(t||r)&&"comment"!=t&&(i=null,e.state=e.state(r||t,n,e),i&&(t="error"==i?t+" error":i)),t},indent:function(n,e,o){var a=n.context;if(n.tokenize.isInAttribute)return n.tagStart==n.indented?n.stringStartCol+1:n.indented+l;if(a&&a.noIndent)return t.Pass;if(n.tokenize!=s&&n.tokenize!=d)return o?o.match(/^(\s*)/)[0].length:0;if(n.tagName)return!1!==p.multilineTagIndentPastTag?n.tagStart+n.tagName.length+2:n.tagStart+l*(p.multilineTagIndentFactor||1);if(p.alignCDATA&&/$/,blockCommentStart:"\x3c!--",blockCommentEnd:"--\x3e",configuration:p.htmlMode?"html":"xml",helperType:p.htmlMode?"html":"xml",skipAttribute:function(n){n.state==P&&(n.state=C)},xmlCurrentTag:function(n){return n.tagName?{name:n.tagName,close:"closeTag"==n.type}:null},xmlCurrentContext:function(n){for(var e=[],t=n.context;t;t=t.prev)e.push(t.tagName);return e.reverse()}}})),t.defineMIME("text/xml","xml"),t.defineMIME("application/xml","xml"),t.mimeModes.hasOwnProperty("text/html")||t.defineMIME("text/html",{name:"xml",htmlMode:!0})})),un((function(n,e){var t;(t=bn).defineMode("yaml",(function(){var n=new RegExp("\\b(("+["true","false","on","off","yes","no"].join(")|(")+"))$","i");return{token:function(e,t){var o=e.peek(),a=t.escaped;if(t.escaped=!1,"#"==o&&(0==e.pos||/\s/.test(e.string.charAt(e.pos-1))))return e.skipToEnd(),"comment";if(e.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/))return"string";if(t.literal&&e.indentation()>t.keyCol)return e.skipToEnd(),"string";if(t.literal&&(t.literal=!1),e.sol()){if(t.keyCol=0,t.pair=!1,t.pairStart=!1,e.match(/---/))return"def";if(e.match(/\.\.\./))return"def";if(e.match(/\s*-\s+/))return"meta"}if(e.match(/^(\{|\}|\[|\])/))return"{"==o?t.inlinePairs++:"}"==o?t.inlinePairs--:"["==o?t.inlineList++:t.inlineList--,"meta";if(t.inlineList>0&&!a&&","==o)return e.next(),"meta";if(t.inlinePairs>0&&!a&&","==o)return t.keyCol=0,t.pair=!1,t.pairStart=!1,e.next(),"meta";if(t.pairStart){if(e.match(/^\s*(\||\>)\s*/))return t.literal=!0,"meta";if(e.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i))return"variable-2";if(0==t.inlinePairs&&e.match(/^\s*-?[0-9\.\,]+\s?$/))return"number";if(t.inlinePairs>0&&e.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/))return"number";if(e.match(n))return"keyword"}return!t.pair&&e.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)?(t.pair=!0,t.keyCol=e.indentation(),"atom"):t.pair&&e.match(/^:\s*/)?(t.pairStart=!0,"meta"):(t.pairStart=!1,t.escaped="\\"==o,e.next(),null)},startState:function(){return{pair:!1,pairStart:!1,keyCol:0,inlinePairs:0,inlineList:0,literal:!1,escaped:!1}},lineComment:"#",fold:"indent"}})),t.defineMIME("text/x-yaml","yaml"),t.defineMIME("text/yaml","yaml")})),un((function(n,e){!function(n){function e(n){return new RegExp("^(("+n.join(")|(")+"))\\b")}var t=e(["and","or","not","is"]),o=["as","assert","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","lambda","pass","raise","return","try","while","with","yield","in"],a=["abs","all","any","bin","bool","bytearray","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip","__import__","NotImplemented","Ellipsis","__debug__"];function r(n){return n.scopes[n.scopes.length-1]}n.registerHelper("hintWords","python",o.concat(a)),n.defineMode("python",(function(i,l){for(var p="error",f=l.delimiters||l.singleDelimiters||/^[\(\)\[\]\{\}@,:`=;\.\\]/,c=[l.singleOperators,l.doubleOperators,l.doubleDelimiters,l.tripleDelimiters,l.operators||/^([-+*/%\/&|^]=?|[<>=]+|\/\/=?|\*\*=?|!=|[~!@]|\.\.\.)/],d=0;do?C(e):a0&&P(n,e)&&(i+=" "+p),i}return w(n,e)}function w(n,e,o){if(n.eatSpace())return null;if(!o&&n.match(/^#.*/))return"comment";if(n.match(/^[0-9\.]/,!1)){var a=!1;if(n.match(/^[\d_]*\.\d+(e[\+\-]?\d+)?/i)&&(a=!0),n.match(/^[\d_]+\.\d*/)&&(a=!0),n.match(/^\.\d+/)&&(a=!0),a)return n.eat(/J/i),"number";var r=!1;if(n.match(/^0x[0-9a-f_]+/i)&&(r=!0),n.match(/^0b[01_]+/i)&&(r=!0),n.match(/^0o[0-7_]+/i)&&(r=!0),n.match(/^[1-9][\d_]*(e[\+\-]?[\d_]+)?/)&&(n.eat(/J/i),r=!0),n.match(/^0(?![\dx])/i)&&(r=!0),r)return n.eat(/L/i),"number"}if(n.match(_))return-1!==n.current().toLowerCase().indexOf("f")?(e.tokenize=y(n.current(),e.tokenize),e.tokenize(n,e)):(e.tokenize=k(n.current(),e.tokenize),e.tokenize(n,e));for(var i=0;i=0;)n=n.substr(1);var t=1==n.length,o="string";function a(n){return function(e,t){var o=w(e,t,!0);return"punctuation"==o&&("{"==e.current()?t.tokenize=a(n+1):"}"==e.current()&&(t.tokenize=n>1?a(n-1):r)),o}}function r(r,i){for(;!r.eol();)if(r.eatWhile(/[^'"\{\}\\]/),r.eat("\\")){if(r.next(),t&&r.eol())return o}else{if(r.match(n))return i.tokenize=e,o;if(r.match("{{"))return o;if(r.match("{",!1))return i.tokenize=a(0),r.current()?o:i.tokenize(r,i);if(r.match("}}"))return o;if(r.match("}"))return p;r.eat(/['"]/)}if(t){if(l.singleLineStringErrors)return p;i.tokenize=e}return o}return r.isString=!0,r}function k(n,e){for(;"rubf".indexOf(n.charAt(0).toLowerCase())>=0;)n=n.substr(1);var t=1==n.length,o="string";function a(a,r){for(;!a.eol();)if(a.eatWhile(/[^'"\\]/),a.eat("\\")){if(a.next(),t&&a.eol())return o}else{if(a.match(n))return r.tokenize=e,o;a.eat(/['"]/)}if(t){if(l.singleLineStringErrors)return p;r.tokenize=e}return o}return a.isString=!0,a}function C(n){for(;"py"!=r(n).type;)n.scopes.pop();n.scopes.push({offset:r(n).offset+i.indentUnit,type:"py",align:null})}function B(n,e,t){var o=n.match(/^([\s\[\{\(]|#.*)*$/,!1)?null:n.column()+1;e.scopes.push({offset:e.indent+s,type:t,align:o})}function P(n,e){for(var t=n.indentation();e.scopes.length>1&&r(e).offset>t;){if("py"!=r(e).type)return!0;e.scopes.pop()}return r(e).offset!=t}function S(n,e){n.sol()&&(e.beginningOfLine=!0);var t=e.tokenize(n,e),o=n.current();if(e.beginningOfLine&&"@"==o)return n.match(b,!1)?"meta":u?"operator":p;if(/\S/.test(o)&&(e.beginningOfLine=!1),"variable"!=t&&"builtin"!=t||"meta"!=e.lastToken||(t="meta"),"pass"!=o&&"return"!=o||(e.dedent+=1),"lambda"==o&&(e.lambda=!0),":"!=o||e.lambda||"py"!=r(e).type||C(e),1==o.length&&!/string|comment/.test(t)){var a="[({".indexOf(o);if(-1!=a&&B(n,e,"])}".slice(a,a+1)),-1!=(a="])}".indexOf(o))){if(r(e).type!=o)return p;e.indent=e.scopes.pop().offset-s}}return e.dedent>0&&n.eol()&&"py"==r(e).type&&(e.scopes.length>1&&e.scopes.pop(),e.dedent-=1),t}return{startState:function(n){return{tokenize:x,scopes:[{offset:n||0,type:"py",align:null}],indent:n||0,lastToken:null,lambda:!1,dedent:0}},token:function(n,e){var t=e.errorToken;t&&(e.errorToken=!1);var o=S(n,e);return o&&"comment"!=o&&(e.lastToken="keyword"==o||"punctuation"==o?n.current():o),"punctuation"==o&&(o=null),n.eol()&&e.lambda&&(e.lambda=!1),t?o+" "+p:o},indent:function(e,t){if(e.tokenize!=x)return e.tokenize.isString?n.Pass:0;var o=r(e),a=o.type==t.charAt(0);return null!=o.align?o.align-(a?1:0):o.offset-(a?s:0)},electricInput:/^\s*[\}\]\)]$/,closeBrackets:{triples:"'\""},lineComment:"#",fold:"indent"}})),n.defineMIME("text/x-python","python");var i=function(n){return n.split(" ")};n.defineMIME("text/x-cython",{name:"python",extra_keywords:i("by cdef cimport cpdef ctypedef enum except extern gil include nogil property public readonly struct union DEF IF ELIF ELSE")})}(bn)}));let _n=class extends tn{constructor(){super(...arguments),this.readOnly=!1,this.mode="yaml"}createRenderRoot(){return this}firstUpdated(){const n=this.querySelector("textarea");n&&(this.editor=bn.fromTextArea(n,{mode:this.mode,theme:"monokai",lineNumbers:!1,readOnly:this.readOnly,autoRefresh:!0}),this.editor.on("blur",(n=>{var e;null===(e=this.editor)||void 0===e||e.save()})))}};n([$()],_n.prototype,"readOnly",void 0),n([$()],_n.prototype,"mode",void 0),_n=n([X("pb-codemirror")],_n);let hn=class extends tn{constructor(){super();const n=this.querySelector(".pf-c-dropdown__menu");this.querySelectorAll("button.pf-c-dropdown__toggle").forEach((e=>{e.addEventListener("click",(e=>{n.hidden=!n.hidden}))}))}render(){return A`