l&&o.push(new Bh(l,f.from,d)),Nh(e,f.direction==Dh!=!(d%2)?n+1:n,r,f.inner,f.from,f.to,o),l=f.to}p=f.to}else{if(p==i||(t?Yh[p]!=a:Yh[p]==a))break;p++}u?Wh(e,l,p,n+1,r,u,o):lt;){let i=!0,c=!1;if(!h||l>s[h-1].to){let e=Yh[l-1];e!=a&&(i=!1,c=16==e)}let u=i||1!=a?null:[],d=i?n:n+1,p=l;e:for(;;)if(h&&p==s[h-1].to){if(c)break e;let f=s[--h];if(!i)for(let e=f.from,i=h;;){if(e==t)break e;if(!i||s[i-1].to!=e){if(Yh[e-1]==a)break e;break}e=s[--i].from}if(u)u.push(f);else{f.to=0;e-=3)if(Ih[e+1]==-i){let t=Ih[e+2],i=2&t?r:4&t?1&t?s:r:0;i&&(Yh[o]=Yh[Ih[e]]=i),a=e;break}}else{if(189==Ih.length)break;Ih[a++]=o,Ih[a++]=t,Ih[a++]=l}else if(2==(n=Yh[o])||1==n){let e=n==r;l=e?0:1;for(let t=a-3;t>=0;t-=3){let i=Ih[t+2];if(2&i)break;if(e)Ih[t+2]|=2;else{if(4&i)break;Ih[t+2]|=4}}}}}(e,r,s,n,a),function(e,t,i,n){for(let r=0,s=n;r<=i.length;r++){let o=r?i[r-1].to:e,a=rl;)t==s&&(t=i[--n].from,s=n?i[n-1].to:e),Yh[--t]=c;l=o}else s=o,l++}}}(r,s,n,a),Wh(e,r,s,t,i,n,o)}function Gh(e){return[new Bh(0,e,0)]}let Uh="";function Hh(e,t,i,n,r){var s;let o=n.head-e.from,a=Bh.find(t,o,null!==(s=n.bidiLevel)&&void 0!==s?s:-1,n.assoc),l=t[a],h=l.side(r,i);if(o==h){let e=a+=r?1:-1;if(e<0||e>=t.length)return null;l=t[a=e],o=l.side(!r,i),h=l.side(r,i)}let c=Lo(e.text,o,l.forward(r,i));(cl.to)&&(c=h),Uh=e.text.slice(Math.min(o,c),Math.max(o,c));let u=a==(r?t.length-1:0)?null:t[a+(r?1:-1)];return u&&c==h&&u.level+(r?0:1)e.some((e=>e))}),hc=ta.define({combine:e=>e.some((e=>e))}),cc=ta.define();class uc{constructor(e,t="nearest",i="nearest",n=5,r=5,s=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=s}map(e){return e.empty?this:new uc(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new uc(Ko.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const dc=Aa.define({map:(e,t)=>e.map(t)}),pc=Aa.define();function fc(e,t,i){let n=e.facet(ic);n.length?n[0](t):window.onerror&&window.onerror(String(t),i,void 0,void 0,t)}const mc=ta.define({combine:e=>!e.length||e[0]});let Oc=0;const gc=ta.define();class vc{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:s}=t||{};return new vc(Oc++,e,i,n,(e=>{let t=[gc.of(e)];return s&&t.push(xc.of((t=>{let i=t.plugin(e);return i?s(i):xh.none}))),r&&t.push(r(e)),t}))}static fromClass(e,t){return vc.define((t=>new e(t)),t)}}class bc{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(fc(e.state,t,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(_$){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){fc(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(null===(t=this.value)||void 0===t?void 0:t.destroy)try{this.value.destroy()}catch(i){fc(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const yc=ta.define(),kc=ta.define(),xc=ta.define(),wc=ta.define(),Sc=ta.define(),Qc=ta.define();function $c(e,t){let i=e.state.facet(Qc);if(!i.length)return i;let n=i.map((t=>t instanceof Function?t(e):t)),r=[];return Ga.spans(n,t.from,t.to,{point(){},span(e,i,n,s){let o=e-t.from,a=i-t.from,l=r;for(let r=n.length-1;r>=0;r--,s--){let e,i=n[r].spec.bidiIsolate;if(null==i&&(i=Kh(t.text,o,a)),s>0&&l.length&&(e=l[l.length-1]).to==o&&e.direction==i)e.to=a,l=e.inner;else{let e={from:o,to:a,direction:i,inner:[]};l.push(e),l=e.inner}}}}),r}const _c=ta.define();function Pc(e){let t=0,i=0,n=0,r=0;for(let s of e.state.facet(_c)){let o=s(e);o&&(null!=o.left&&(t=Math.max(t,o.left)),null!=o.right&&(i=Math.max(i,o.right)),null!=o.top&&(n=Math.max(n,o.top)),null!=o.bottom&&(r=Math.max(r,o.bottom)))}return{left:t,right:i,top:n,bottom:r}}const Cc=ta.define();class Tc{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new Tc(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toAh)break;r+=2}if(!a)return i;new Tc(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),s=a.toA,o=a.toB}}}class Ac{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=Bo.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges(((e,t,i,r)=>n.push(new Tc(e,t,i,r)))),this.changedRanges=n}static create(e,t,i){return new Ac(e,t,i)}get viewportChanged(){return(4&this.flags)>0}get viewportMoved(){return(8&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(18&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((e=>e.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}class Ec extends Bl{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=xh.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new Ph],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Tc(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every((({fromA:e,toA:t})=>tthis.minWidthTo))?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&((null===(t=this.domChanged)||void 0===t?void 0:t.newSel)?n=this.domChanged.newSel.head:function(e,t){let i=!1;t&&e.iterChangedRanges(((e,n)=>{et.from&&(i=!0)}));return i}(e.changes,this.hasComposition)||e.selectionSet||(n=e.state.selection.main.head));let r=n>-1?function(e,t,i){let n=Mc(e,i);if(!n)return null;let{node:r,from:s,to:o}=n,a=r.nodeValue;if(/[\n\r]/.test(a))return null;if(e.state.doc.sliceString(n.from,n.to)!=a)return null;let l=t.invertedDesc,h=new Tc(l.mapPos(s),l.mapPos(o),s,o),c=[];for(let u=r.parentNode;;u=u.parentNode){let t=Bl.get(u);if(t instanceof lh)c.push({node:u,deco:t.mark});else{if(t instanceof Ph||"DIV"==u.nodeName&&u.parentNode==e.contentDOM)return{range:h,text:r,marks:c,line:u};if(u==e.contentDOM)return null;c.push({node:u,deco:new wh({inclusive:!0,attributes:bh(u),tagName:u.tagName.toLowerCase()})})}}}(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:t,to:n}=this.hasComposition;i=new Tc(t,n,e.changes.mapPos(t,-1),e.changes.mapPos(n,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(oh.ie||oh.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let s=function(e,t,i){let n=new Rc;return Ga.compare(e,t,i,n),n.changes}(this.decorations,this.updateDeco(),e.changes);return i=Tc.extendWithRanges(i,s),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:n}=this.view;n.ignore((()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let e=oh.chrome||oh.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,e),this.flags&=-8,e&&(e.written||n.selectionRange.focusNode!=e.node)&&(this.forceSelection=!0),this.dom.style.height=""})),this.markedForComposition.forEach((e=>e.flags&=-9));let r=[];if(this.view.viewport.from||this.view.viewport.to=0?n[s]:null;if(!e)break;let t,o,a,l,{fromA:h,toA:c,fromB:u,toB:d}=e;if(i&&i.range.fromBu){let e=Ah.build(this.view.state.doc,u,i.range.fromB,this.decorations,this.dynamicDecorationMap),n=Ah.build(this.view.state.doc,i.range.toB,d,this.decorations,this.dynamicDecorationMap);o=e.breakAtStart,a=e.openStart,l=n.openEnd;let r=this.compositionView(i);n.breakAtStart?r.breakAfter=1:n.content.length&&r.merge(r.length,r.length,n.content[0],!1,n.openStart,0)&&(r.breakAfter=n.content[0].breakAfter,n.content.shift()),e.content.length&&r.merge(0,0,e.content[e.content.length-1],!0,0,e.openEnd)&&e.content.pop(),t=e.content.concat(r).concat(n.content)}else({content:t,breakAtStart:o,openStart:a,openEnd:l}=Ah.build(this.view.state.doc,u,d,this.decorations,this.dynamicDecorationMap));let{i:p,off:f}=r.findPos(c,1),{i:m,off:O}=r.findPos(h,-1);Wl(this,m,O,p,f,t,o,a,l)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(pc)&&(this.editContextFormatting=e.value)}compositionView(e){let t=new ah(e.text.nodeValue);t.flags|=8;for(let{deco:n}of e.marks)t=new lh(n,[t],t.length);let i=new Ph;return i.append(t,0),i}fixCompositionDOM(e){let t=(e,t)=>{t.flags|=8|(t.children.some((e=>7&e.flags))?1:0),this.markedForComposition.add(t);let i=Bl.get(e);i&&i!=t&&(i.dom=null),t.setDOM(e)},i=this.childPos(e.range.fromB,1),n=this.children[i.i];t(e.line,n);for(let r=e.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],t(r>=0?e.marks[r].node:e.text,n)}updateSelection(e=!1,t=!1){!e&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&!(this.view.state.facet(mc)||this.dom.tabIndex>-1)&&xl(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||t||r))return;let s=this.forceSelection;this.forceSelection=!1;let o=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(o.anchor)),l=o.empty?a:this.moveToLine(this.domAtPos(o.head));if(oh.gecko&&o.empty&&!this.hasComposition&&(1==(h=a).node.nodeType&&h.node.firstChild&&(0==h.offset||"false"==h.node.childNodes[h.offset-1].contentEditable)&&(h.offset==h.node.childNodes.length||"false"==h.node.childNodes[h.offset].contentEditable))){let e=document.createTextNode("");this.view.observer.ignore((()=>a.node.insertBefore(e,a.node.childNodes[a.offset]||null))),a=l=new zl(e,0),s=!0}var h;let c=this.view.observer.selectionRange;!s&&c.focusNode&&(Sl(a.node,a.offset,c.anchorNode,c.anchorOffset)&&Sl(l.node,l.offset,c.focusNode,c.focusOffset)||this.suppressWidgetCursorChange(c,o))||(this.view.observer.ignore((()=>{oh.android&&oh.chrome&&this.dom.contains(c.focusNode)&&function(e,t){for(let i=e;i&&i!=t;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let e=yl(this.view.root);if(e)if(o.empty){if(oh.gecko){let e=(t=a.node,n=a.offset,1!=t.nodeType?0:(n&&"false"==t.childNodes[n-1].contentEditable?1:0)|(no.head&&([a,l]=[l,a]),t.setEnd(l.node,l.offset),t.setStart(a.node,a.offset),e.removeAllRanges(),e.addRange(t)}else;var t,n;r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())})),this.view.observer.setSelectionRange(a,l)),this.impreciseAnchor=a.precise?null:new zl(c.anchorNode,c.anchorOffset),this.impreciseHead=l.precise?null:new zl(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Sl(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=yl(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!(i&&t.empty&&t.assoc&&i.modify))return;let s=Ph.find(this,t.head);if(!s)return;let o=s.posAtStart;if(t.head==o||t.head==o+s.length)return;let a=this.coordsAt(t.head,-1),l=this.coordsAt(t.head,1);if(!a||!l||a.bottom>l.top)return;let h=this.domAtPos(t.head+t.assoc);i.collapse(h.node,h.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(n,r)}moveToLine(e){let t,i=this.dom;if(e.node!=i)return e;for(let n=e.offset;!t&&n=0;n--){let e=Bl.get(i.childNodes[n]);e instanceof Ph&&(t=e.domAtPos(e.length))}return t?new zl(t.node,t.offset,!0):e}nearest(e){for(let t=e;t;){let e=Bl.get(t);if(e&&e.rootView==this)return e;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t=0;s--){let o=this.children[s],a=r-o.breakAfter,l=a-o.length;if(ae||o.covers(1))&&(!i||o instanceof Ph&&!(i instanceof Ph&&t>=0)))i=o,n=l;else if(i&&l==e&&a==e&&o instanceof Ch&&Math.abs(t)<2){if(o.deco.startSide<0)break;s&&(i=null)}r=l}return i?i.coordsAt(e-n,t):null}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),n=this.children[t];if(!(n instanceof Ph))return null;for(;n.children.length;){let{i:e,off:t}=n.childPos(i,1);for(;;e++){if(e==n.children.length)return null;if((n=n.children[e]).length)break}i=t}if(!(n instanceof ah))return null;let r=Lo(n.text,i);if(r==i)return null;let s=Zl(n.dom,i,r).getClientRects();for(let o=0;oMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,a=this.view.textDirection==Rh.LTR;for(let l=0,h=0;hn)break;if(l>=i){let i=e.dom.getBoundingClientRect();if(t.push(i.height),s){let t=e.dom.lastChild,n=t?wl(t):[];if(n.length){let e=n[n.length-1],t=a?e.right-i.left:i.right-e.left;t>o&&(o=t,this.minWidth=r,this.minWidthFrom=l,this.minWidthTo=c)}}}l=c+e.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return"rtl"==getComputedStyle(this.children[t].dom).direction?Rh.RTL:Rh.LTR}measureTextSize(){for(let r of this.children)if(r instanceof Ph){let e=r.measureTextSize();if(e)return e}let e,t,i,n=document.createElement("div");return n.className="cm-line",n.style.width="99999px",n.style.position="absolute",n.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(n);let r=wl(n.firstChild)[0];e=n.getBoundingClientRect().height,t=r?r.width/27:7,i=r?r.height:e,n.remove()})),{lineHeight:e,charWidth:t,textHeight:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Yl(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],s=r?r.from-1:this.length;if(s>i){let n=(t.lineBlockAt(s).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(xh.replace({widget:new Th(n),block:!0,inclusive:!0,isBlockGap:!0}).range(i,s))}if(!r)break;i=r.to+1}return xh.set(e)}updateDeco(){let e=1,t=this.view.state.facet(xc).map((t=>(this.dynamicDecorationMap[e++]="function"==typeof t)?t(this.view):t)),i=!1,n=this.view.state.facet(wc).map(((e,t)=>{let n="function"==typeof e;return n&&(i=!0),n?e(this.view):e}));for(n.length&&(this.dynamicDecorationMap[e++]=i,t.push(Ga.join(n))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];ei.anchor?-1:1);if(!n)return;!i.empty&&(t=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(n={left:Math.min(n.left,t.left),top:Math.min(n.top,t.top),right:Math.max(n.right,t.right),bottom:Math.max(n.bottom,t.bottom)});let r=Pc(this.view),s={left:n.left-r.left,top:n.top-r.top,right:n.right+r.right,bottom:n.bottom+r.bottom},{offsetWidth:o,offsetHeight:a}=this.view.scrollDOM;!function(e,t,i,n,r,s,o,a){let l=e.ownerDocument,h=l.defaultView||window;for(let c=e,u=!1;c&&!u;)if(1==c.nodeType){let e,d=c==l.body,p=1,f=1;if(d)e=Tl(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let t=c.getBoundingClientRect();({scaleX:p,scaleY:f}=Al(c,t)),e={left:t.left,right:t.left+c.clientWidth*p,top:t.top,bottom:t.top+c.clientHeight*f}}let m=0,O=0;if("nearest"==r)t.top0&&t.bottom>e.bottom+O&&(O=t.bottom-e.bottom+o)):t.bottom>e.bottom&&(O=t.bottom-e.bottom+o,i<0&&t.top-O0&&t.right>e.right+m&&(m=t.right-e.right+s)):t.right>e.right&&(m=t.right-e.right+s,i<0&&t.lefte.bottom||t.lefte.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),c=c.assignedSlot||c.parentNode}else{if(11!=c.nodeType)break;c=c.host}}(this.view.scrollDOM,s,i.heade?t.left-e:Math.max(0,e-t.right)}function Zc(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function Lc(e,t){return e.topt.top+1}function Xc(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function Vc(e,t,i){let n,r,s,o,a,l,h,c,u=!1;for(let p=e.firstChild;p;p=p.nextSibling){let e=wl(p);for(let d=0;dO||o==O&&s>m){n=p,r=f,s=m,o=O;let a=O?i0?d0)}0==m?i>f.bottom&&(!h||h.bottomf.top)&&(l=p,c=f):h&&Lc(h,f)?h=qc(h,f.bottom):c&&Lc(c,f)&&(c=Xc(c,f.top))}}if(h&&h.bottom>=i?(n=a,r=h):c&&c.top<=i&&(n=l,r=c),!n)return{node:e,offset:0};let d=Math.max(r.left,Math.min(r.right,t));return 3==n.nodeType?Ic(n,d,i):u&&"false"!=n.contentEditable?Vc(n,d,i):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,n)+(t>=(r.left+r.right)/2?1:0)}}function Ic(e,t,i){let n=e.nodeValue.length,r=-1,s=1e9,o=0;for(let a=0;ai?h.top-i:i-h.bottom)-1;if(h.left-1<=t&&h.right+1>=t&&c=(h.left+h.right)/2,n=i;if(oh.chrome||oh.gecko){Zl(e,a).getBoundingClientRect().left==h.right&&(n=!i)}if(c<=0)return{node:e,offset:a+(n?1:0)};r=a+(n?1:0),s=c}}}return{node:e,offset:r>-1?r:o>0?e.nodeValue.length:0}}function zc(e,t,i,n=-1){var r,s;let o,a=e.contentDOM.getBoundingClientRect(),l=a.top+e.viewState.paddingTop,{docHeight:h}=e.viewState,{x:c,y:u}=t,d=u-l;if(d<0)return 0;if(d>h)return e.state.doc.length;for(let y=e.viewState.heightOracle.textHeight/2,k=!1;o=e.elementAtHeight(d),o.type!=kh.Text;)for(;d=n>0?o.bottom+y:o.top-y,!(d>=0&&d<=h);){if(k)return i?null:0;k=!0,n=-n}u=l+d;let p=o.from;if(pe.viewport.to)return e.viewport.to==e.state.doc.length?e.state.doc.length:i?null:jc(e,a,o,c,u);let f=e.dom.ownerDocument,m=e.root.elementFromPoint?e.root:f,O=m.elementFromPoint(c,u);O&&!e.contentDOM.contains(O)&&(O=null),O||(c=Math.max(a.left+1,Math.min(a.right-1,c)),O=m.elementFromPoint(c,u),O&&!e.contentDOM.contains(O)&&(O=null));let g,v=-1;if(O&&0!=(null===(r=e.docView.nearest(O))||void 0===r?void 0:r.isEditable)){if(f.caretPositionFromPoint){let e=f.caretPositionFromPoint(c,u);e&&({offsetNode:g,offset:v}=e)}else if(f.caretRangeFromPoint){let t=f.caretRangeFromPoint(c,u);t&&(({startContainer:g,startOffset:v}=t),(!e.contentDOM.contains(g)||oh.safari&&function(e,t,i){let n;if(3!=e.nodeType||t!=(n=e.nodeValue.length))return!1;for(let r=e.nextSibling;r;r=r.nextSibling)if(1!=r.nodeType||"BR"!=r.nodeName)return!1;return Zl(e,n-1,n).getBoundingClientRect().left>i}(g,v,c)||oh.chrome&&function(e,t,i){if(0!=t)return!1;for(let r=e;;){let e=r.parentNode;if(!e||1!=e.nodeType||e.firstChild!=r)return!1;if(e.classList.contains("cm-line"))break;r=e}let n=1==e.nodeType?e.getBoundingClientRect():Zl(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect();return i-n.left>5}(g,v,c))&&(g=void 0))}g&&(v=Math.min(Pl(g),v))}if(!g||!e.docView.dom.contains(g)){let t=Ph.find(e.docView,p);if(!t)return d>o.top+o.height/2?o.to:o.from;({node:g,offset:v}=Vc(t.dom,c,u))}let b=e.docView.nearest(g);if(!b)return null;if(b.isWidget&&1==(null===(s=b.dom)||void 0===s?void 0:s.nodeType)){let e=b.dom.getBoundingClientRect();return t.y1.5*e.defaultLineHeight){let t=e.viewState.heightOracle.textHeight;s+=Math.floor((r-i.top-.5*(e.defaultLineHeight-t))/t)*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(i.from,i.to);return i.from+function(e,t,i){for(let n=0,r=0;;){if(r>=t)return n;if(n==e.length)break;r+=9==e.charCodeAt(n)?i-r%i:1,n=Lo(e,n)}return e.length}(o,s,e.state.tabSize)}function Bc(e,t,i){let n=e.lineBlockAt(t);if(Array.isArray(n.type)){let e;for(let r of n.type){if(r.from>t)break;if(!(r.tot)return r;e&&(r.type!=kh.Text||e.type==r.type&&!(i<0?r.fromt))||(e=r)}}return e||n}return n}function Fc(e,t,i,n){let r=e.state.doc.lineAt(t.head),s=e.bidiSpans(r),o=e.textDirectionAt(r.from);for(let a=t,l=null;;){let t=Hh(r,s,o,a,i),h=Uh;if(!t){if(r.number==(i?e.state.doc.lines:1))return a;h="\n",r=e.state.doc.line(r.number+(i?1:-1)),s=e.bidiSpans(r),t=e.visualLineSide(r,!i)}if(l){if(!l(h))return a}else{if(!n)return t;l=n(h)}a=t}}function Yc(e,t,i){for(;;){let n=0;for(let r of e)r.between(t-1,t+1,((e,r,s)=>{if(t>e&&tt(e))),i.from,t.head>i.from?-1:1);return n==i.from?i:Ko.cursor(n,ne)&&this.lineBreak(),n=r}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r,s=-1,o=1;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(r=n.exec(t))&&(s=r.index,o=r[0].length),this.append(t.slice(i,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=o-1);i=s+o}}readNode(e){if(e.cmIgnore)return;let t=Bl.get(e),i=t&&t.overrideDOMText;if(null!=i){this.findPointInside(e,i.length);for(let e=i.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else 3==e.nodeType?this.readTextNode(e):"BR"==e.nodeName?e.nextSibling&&this.lineBreak():1==e.nodeType&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(3==e.nodeType?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(Uc(e,i.node,i.offset)?t:0))}}function Uc(e,t,i){for(;;){if(!t||i-1;let{impreciseHead:r,impreciseAnchor:s}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let t=r||s?[]:function(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:s}=e.observer.selectionRange;i&&(t.push(new Hc(i,n)),r==i&&s==n||t.push(new Hc(r,s)));return t}(e),i=new Gc(t,e.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(e,t){if(0==e.length)return null;let i=e[0].pos,n=2==e.length?e[1].pos:i;return i>-1&&n>-1?Ko.single(i+t,n+t):null}(t,this.bounds.from)}else{let t=e.observer.selectionRange,i=r&&r.node==t.focusNode&&r.offset==t.focusOffset||!kl(e.contentDOM,t.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),n=s&&s.node==t.anchorNode&&s.offset==t.anchorOffset||!kl(e.contentDOM,t.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),o=e.viewport;if((oh.ios||oh.chrome)&&e.state.selection.main.empty&&i!=n&&(o.from>0||o.toDate.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:n,to:o}=t.bounds,a=r.from,l=null;(8===s||oh.android&&t.text.length0&&a>0&&e.charCodeAt(o-1)==t.charCodeAt(a-1);)o--,a--;if("end"==n){i-=o+Math.max(0,s-Math.min(o,a))-s}if(o=o?s-i:0,a=s+(a-o),o=s}else if(a=a?s-i:0,o=s+(o-a),a=s}return{from:s,toA:o,toB:a}}(e.state.doc.sliceString(n,o,Nc),t.text,a-n,l);h&&(oh.chrome&&13==s&&h.toB==h.from+2&&t.text.slice(h.from,h.toB)==Nc+Nc&&h.toB--,i={from:n+h.from,to:n+h.toA,insert:_o.of(t.text.slice(h.from,h.toB).split(Nc))})}else n&&(!e.hasFocus&&e.state.facet(mc)||n.main.eq(r))&&(n=null);if(!i&&!n)return!1;if(!i&&t.typeOver&&!r.empty&&n&&n.main.empty?i={from:r.from,to:r.to,insert:e.state.doc.slice(r.from,r.to)}:(oh.mac||oh.android)&&i&&i.from==i.to&&i.from==r.head-1&&/^\. ?$/.test(i.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(n&&2==i.insert.length&&(n=Ko.single(n.main.anchor-1,n.main.head-1)),i={from:i.from,to:i.to,insert:_o.of([i.insert.toString().replace("."," ")])}):i&&i.from>=r.from&&i.to<=r.to&&(i.from!=r.from||i.to!=r.to)&&r.to-r.from-(i.to-i.from)<=4?i={from:r.from,to:r.to,insert:e.state.doc.slice(r.from,i.from).append(i.insert).append(e.state.doc.slice(i.to,r.to))}:oh.chrome&&i&&i.from==i.to&&i.from==r.head&&"\n "==i.insert.toString()&&e.lineWrapping&&(n&&(n=Ko.single(n.main.anchor-1,n.main.head-1)),i={from:r.from,to:r.to,insert:_o.of([" "])}),i)return eu(e,i,n,s);if(n&&!n.main.eq(r)){let t=!1,i="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),i=e.inputState.lastSelectionOrigin),e.dispatch({selection:n,scrollIntoView:t,userEvent:i}),!0}return!1}function eu(e,t,i,n=-1){if(oh.ios&&e.inputState.flushIOSKey(t))return!0;let r=e.state.selection.main;if(oh.android&&(t.to==r.to&&(t.from==r.from||t.from==r.from-1&&" "==e.state.sliceDoc(t.from,r.from))&&1==t.insert.length&&2==t.insert.lines&&Ll(e.contentDOM,"Enter",13)||(t.from==r.from-1&&t.to==r.to&&0==t.insert.length||8==n&&t.insert.lengthr.head)&&Ll(e.contentDOM,"Backspace",8)||t.from==r.from&&t.to==r.to+1&&0==t.insert.length&&Ll(e.contentDOM,"Delete",46)))return!0;let s,o=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let a=()=>s||(s=function(e,t,i){let n,r=e.state,s=r.selection.main;if(t.from>=s.from&&t.to<=s.to&&t.to-t.from>=(s.to-s.from)/3&&(!i||i.main.empty&&i.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let i=s.fromt.to?r.sliceDoc(t.to,s.to):"";n=r.replaceSelection(e.state.toText(i+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=r.changes(t),a=i&&i.main.to<=o.newLength?i.main:void 0;if(r.selection.ranges.length>1&&e.inputState.composing>=0&&t.to<=s.to&&t.to>=s.to-10){let l,h=e.state.sliceDoc(t.from,t.to),c=i&&Mc(e,i.main.head);if(c){let e=t.insert.length-(t.to-t.from);l={from:c.from,to:c.to-e}}else l=e.state.doc.lineAt(s.head);let u=s.to-t.to,d=s.to-s.from;n=r.changeByRange((i=>{if(i.from==s.from&&i.to==s.to)return{changes:o,range:a||i.map(o)};let n=i.to-u,c=n-h.length;if(i.to-i.from!=d||e.state.sliceDoc(c,n)!=h||i.to>=l.from&&i.from<=l.to)return{range:i};let p=r.changes({from:c,to:n,insert:t.insert}),f=i.to-s.to;return{changes:p,range:a?Ko.range(Math.max(0,a.anchor+f),Math.max(0,a.head+f)):i.map(p)}}))}else n={changes:o,selection:a&&r.selection.replaceRange(a)}}let o="input.type";(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,o+=".compose",e.inputState.compositionFirstChange&&(o+=".start",e.inputState.compositionFirstChange=!1));return r.update(n,{userEvent:o,scrollIntoView:!0})}(e,t,i));return e.state.facet(rc).some((i=>i(e,t.from,t.to,o,a)))||e.dispatch(a()),!0}class tu{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){var t;this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,oh.safari&&e.contentDOM.addEventListener("input",(()=>null)),oh.gecko&&(t=e.contentDOM.ownerDocument,_u.has(t)||(_u.add(t),t.addEventListener("copy",(()=>{})),t.addEventListener("cut",(()=>{}))))}handleEvent(e){(function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let i,n=t.target;n!=e.contentDOM;n=n.parentNode)if(!n||11==n.nodeType||(i=Bl.get(n))&&i.ignoreEvent(t))return!1;return!0})(this.view,e)&&!this.ignoreDuringComposition(e)&&("keydown"==e.type&&this.keydown(e)||(0!=this.view.updateState?Promise.resolve().then((()=>this.runHandlers(e.type,e))):this.runHandlers(e.type,e)))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let e of i.observers)e(this.view,t);for(let e of i.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=function(e){let t=Object.create(null);function i(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let n of e){let e=n.spec;if(e&&e.domEventHandlers)for(let t in e.domEventHandlers){let r=e.domEventHandlers[t];r&&i(t).handlers.push(iu(n.value,r))}if(e&&e.domEventObservers)for(let t in e.domEventObservers){let r=e.domEventObservers[t];r&&i(t).observers.push(iu(n.value,r))}}for(let n in lu)i(n).handlers.push(lu[n]);for(let n in hu)i(n).observers.push(hu[n]);return t}(e),i=this.handlers,n=this.view.contentDOM;for(let r in t)if("scroll"!=r){let e=!t[r].handlers.length,s=i[r];s&&e!=!s.handlers.length&&(n.removeEventListener(r,this.handleEvent),s=null),s||n.addEventListener(r,this.handleEvent,{passive:e})}for(let r in i)"scroll"==r||t[r]||n.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),9==e.keyCode&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&27!=e.keyCode&&su.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),oh.android&&oh.chrome&&!e.synthetic&&(13==e.keyCode||8==e.keyCode))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return!oh.ios||e.synthetic||e.altKey||e.metaKey||!((t=nu.find((t=>t.keyCode==e.keyCode)))&&!e.ctrlKey||ru.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(229!=e.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=t||e,setTimeout((()=>this.flushIOSKey()),250),!0)}flushIOSKey(e){let t=this.pendingIOSKey;return!!t&&(!("Enter"==t.key&&e&&e.from0||!!(oh.safari&&!oh.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function iu(e,t){return(i,n)=>{try{return t.call(e,n,i)}catch(r){fc(i.state,r)}}}const nu=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],ru="dthko",su=[16,17,18,20,91,92,224,225];function ou(e){return.7*Math.max(0,e)+8}class au{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=function(e){let t,i,n=e.ownerDocument;for(let r=e.parentNode;r&&!(r==n.body||t&&i);)if(1==r.nodeType)!i&&r.scrollHeight>r.clientHeight&&(i=r),!t&&r.scrollWidth>r.clientWidth&&(t=r),r=r.assignedSlot||r.parentNode;else{if(11!=r.nodeType)break;r=r.host}return{x:t,y:i}}(e.contentDOM),this.atoms=e.state.facet(Sc).map((t=>t(e)));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(ja.allowMultipleSelections)&&function(e,t){let i=e.state.facet(Jh);return i.length?i[0](t):oh.mac?t.metaKey:t.ctrlKey}(e,t),this.dragging=!(!function(e,t){let{main:i}=e.state.selection;if(i.empty)return!1;let n=yl(e.root);if(!n||0==n.rangeCount)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s=t.clientX&&e.top<=t.clientY&&e.bottom>=t.clientY)return!0}return!1}(e,t)||1!=ku(t))&&null}start(e){!1===this.dragging&&this.select(e)}move(e){if(0==e.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(t=this.startEvent,i=e,Math.max(Math.abs(t.clientX-i.clientX),Math.abs(t.clientY-i.clientY))<10))return;var t,i;this.select(this.lastEvent=e);let n=0,r=0,s=0,o=0,a=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:a}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:o,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=Pc(this.view);e.clientX-h.left<=s+6?n=-ou(s-e.clientX):e.clientX+h.right>=a-6&&(n=ou(e.clientX-a)),e.clientY-h.top<=o+6?r=-ou(o-e.clientY):e.clientY+h.bottom>=l-6&&(r=ou(e.clientY-l)),this.setScrollSpeed(n,r)}up(e){null==this.dragging&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval((()=>this.scroll()),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;ie.isUserEvent("input.type")))?this.destroy():this.style.update(e)&&setTimeout((()=>this.select(this.lastEvent)),20)}}const lu=Object.create(null),hu=Object.create(null),cu=oh.ie&&oh.ie_version<15||oh.ios&&oh.webkit_version<604;function uu(e,t,i){for(let n of e.facet(t))i=n(i,e);return i}function du(e,t){t=uu(e.state,oc,t);let i,{state:n}=e,r=1,s=n.toText(t),o=s.lines==n.selection.ranges.length;if(null!=wu&&n.selection.ranges.every((e=>e.empty))&&wu==s.toString()){let e=-1;i=n.changeByRange((i=>{let a=n.doc.lineAt(i.from);if(a.from==e)return{range:i};e=a.from;let l=n.toText((o?s.line(r++).text:t)+n.lineBreak);return{changes:{from:a.from,insert:l},range:Ko.cursor(i.from+l.length)}}))}else i=o?n.changeByRange((e=>{let t=s.line(r++);return{changes:{from:e.from,to:e.to,insert:t.text},range:Ko.cursor(e.from+t.length)}})):n.replaceSelection(s);e.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function pu(e,t,i,n){if(1==n)return Ko.cursor(t,i);if(2==n)return function(e,t,i=1){let n=e.charCategorizer(t),r=e.doc.lineAt(t),s=t-r.from;if(0==r.length)return Ko.cursor(t);0==s?i=1:s==r.length&&(i=-1);let o=s,a=s;i<0?o=Lo(r.text,s,!1):a=Lo(r.text,s);let l=n(r.text.slice(o,a));for(;o>0;){let e=Lo(r.text,o,!1);if(n(r.text.slice(e,o))!=l)break;o=e}for(;a{e.inputState.lastScrollTop=e.scrollDOM.scrollTop,e.inputState.lastScrollLeft=e.scrollDOM.scrollLeft},lu.keydown=(e,t)=>(e.inputState.setSelectionOrigin("select"),27==t.keyCode&&0!=e.inputState.tabFocusMode&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),hu.touchstart=(e,t)=>{e.inputState.lastTouchTime=Date.now(),e.inputState.setSelectionOrigin("select.pointer")},hu.touchmove=e=>{e.inputState.setSelectionOrigin("select.pointer")},lu.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let n of e.state.facet(tc))if(i=n(e,t),i)break;if(i||0!=t.button||(i=function(e,t){let i=Ou(e,t),n=ku(t),r=e.state.selection;return{update(e){e.docChanged&&(i.pos=e.changes.mapPos(i.pos),r=r.map(e.changes))},get(t,s,o){let a,l=Ou(e,t),h=pu(e,l.pos,l.bias,n);if(i.pos!=l.pos&&!s){let t=pu(e,i.pos,i.bias,n),r=Math.min(t.from,h.from),s=Math.max(t.to,h.to);h=r1&&(a=function(e,t){for(let i=0;i=t)return Ko.create(e.ranges.slice(0,i).concat(e.ranges.slice(i+1)),e.mainIndex==i?0:e.mainIndex-(e.mainIndex>i?1:0))}return null}(r,l.pos))?a:o?r.addRange(h):Ko.create([h])}}}(e,t)),i){let n=!e.hasFocus;e.inputState.startMouseSelection(new au(e,t,i,n)),n&&e.observer.ignore((()=>{Dl(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()}));let r=e.inputState.mouseSelection;if(r)return r.start(t),!1===r.dragging}return!1};let fu=(e,t,i)=>t>=i.top&&t<=i.bottom&&e>=i.left&&e<=i.right;function mu(e,t,i,n){let r=Ph.find(e.docView,t);if(!r)return 1;let s=t-r.posAtStart;if(0==s)return 1;if(s==r.length)return-1;let o=r.coordsAt(s,-1);if(o&&fu(i,n,o))return-1;let a=r.coordsAt(s,1);return a&&fu(i,n,a)?1:o&&o.bottom>=n?-1:1}function Ou(e,t){let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:i,bias:mu(e,i,t.clientX,t.clientY)}}const gu=oh.ie&&oh.ie_version<=11;let vu=null,bu=0,yu=0;function ku(e){if(!gu)return e.detail;let t=vu,i=yu;return vu=e,yu=Date.now(),bu=!t||i>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(bu+1)%3:1}function xu(e,t,i,n){if(!(i=uu(e.state,oc,i)))return;let r=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:s}=e.inputState,o=n&&s&&function(e,t){let i=e.state.facet(ec);return i.length?i[0](t):oh.mac?!t.altKey:!t.ctrlKey}(e,t)?{from:s.from,to:s.to}:null,a={from:r,insert:i},l=e.state.changes(o?[o,a]:a);e.focus(),e.dispatch({changes:l,selection:{anchor:l.mapPos(r,-1),head:l.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),e.inputState.draggedContent=null}lu.dragstart=(e,t)=>{let{selection:{main:i}}=e.state;if(t.target.draggable){let n=e.docView.nearest(t.target);if(n&&n.isWidget){let e=n.posAtStart,t=e+n.length;(e>=i.to||t<=i.from)&&(i=Ko.range(e,t))}}let{inputState:n}=e;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=i,t.dataTransfer&&(t.dataTransfer.setData("Text",uu(e.state,ac,e.state.sliceDoc(i.from,i.to))),t.dataTransfer.effectAllowed="copyMove"),!1},lu.dragend=e=>(e.inputState.draggedContent=null,!1),lu.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let i=t.dataTransfer.files;if(i&&i.length){let n=Array(i.length),r=0,s=()=>{++r==i.length&&xu(e,t,n.filter((e=>null!=e)).join(e.state.lineBreak),!1)};for(let e=0;e{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(n[e]=t.result),s()},t.readAsText(i[e])}return!0}{let i=t.dataTransfer.getData("Text");if(i)return xu(e,t,i,!0),!0}return!1},lu.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let i=cu?null:t.clipboardData;return i?(du(e,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(e){let t=e.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{e.focus(),i.remove(),du(e,i.value)}),50)}(e),!1)};let wu=null;lu.copy=lu.cut=(e,t)=>{let{text:i,ranges:n,linewise:r}=function(e){let t=[],i=[],n=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),i.push(r));if(!t.length){let r=-1;for(let{from:n}of e.selection.ranges){let s=e.doc.lineAt(n);s.number>r&&(t.push(s.text),i.push({from:s.from,to:Math.min(e.doc.length,s.to+1)})),r=s.number}n=!0}return{text:uu(e,ac,t.join(e.lineBreak)),ranges:i,linewise:n}}(e.state);if(!i&&!r)return!1;wu=r?i:null,"cut"!=t.type||e.state.readOnly||e.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=cu?null:t.clipboardData;return s?(s.clearData(),s.setData("text/plain",i),!0):(function(e,t){let i=e.dom.parentNode;if(!i)return;let n=i.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=t,n.focus(),n.selectionEnd=t.length,n.selectionStart=0,setTimeout((()=>{n.remove(),e.focus()}),50)}(e,i),!1)};const Su=Pa.define();function Qu(e,t){let i=[];for(let n of e.facet(sc)){let r=n(e,t);r&&i.push(r)}return i.length?e.update({effects:i,annotations:Su.of(!0)}):null}function $u(e){setTimeout((()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let i=Qu(e.state,t);i?e.dispatch(i):e.update([])}}),10)}hu.focus=e=>{e.inputState.lastFocusTime=Date.now(),e.scrollDOM.scrollTop||!e.inputState.lastScrollTop&&!e.inputState.lastScrollLeft||(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),$u(e)},hu.blur=e=>{e.observer.clearSelectionRange(),$u(e)},hu.compositionstart=hu.compositionupdate=e=>{e.observer.editContext||(null==e.inputState.compositionFirstChange&&(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0))},hu.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,oh.chrome&&oh.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then((()=>e.observer.flush())):setTimeout((()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])}),50))},hu.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},lu.beforeinput=(e,t)=>{var i,n;if("insertReplacementText"==t.inputType&&e.observer.editContext){let n=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("text/plain"),r=t.getTargetRanges();if(n&&r.length){let t=r[0],i=e.posAtDOM(t.startContainer,t.startOffset),s=e.posAtDOM(t.endContainer,t.endOffset);return eu(e,{from:i,to:s,insert:e.state.toText(n)},null),!0}}let r;if(oh.chrome&&oh.android&&(r=nu.find((e=>e.inputType==t.inputType)))&&(e.observer.delayAndroidKey(r.key,r.keyCode),"Backspace"==r.key||"Delete"==r.key)){let t=(null===(n=window.visualViewport)||void 0===n?void 0:n.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())}),100)}return oh.ios&&"deleteContentForward"==t.inputType&&e.observer.flushSoon(),oh.safari&&"insertText"==t.inputType&&e.inputState.composing>=0&&setTimeout((()=>hu.compositionend(e,t)),20),!1};const _u=new Set;const Pu=["pre-wrap","normal","pre-line","break-spaces"];let Cu=!1;function Tu(){Cu=!1}class Au{constructor(e){this.lineWrapping=e,this.doc=_o.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Pu.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=i,this.textHeight=n,this.lineLength=r,a){this.heightSamples={};for(let e=0;e0}set outdated(e){this.flags=(e?2:0)|-3&this.flags}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Du&&(Cu=!0),this.height=e)}replace(e,t,i){return Zu.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let r=this,s=i.doc;for(let o=n.length-1;o>=0;o--){let{fromA:a,toA:l,fromB:h,toB:c}=n[o],u=r.lineAt(a,Ru.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=l?u:r.lineAt(l,Ru.ByPosNoHeight,i,0,0);for(c+=d.to-l,l=d.to;o>0&&u.from<=n[o-1].toA;)a=n[o-1].fromA,h=n[o-1].fromB,o--,a2*r){let r=e[t-1];r.break?e.splice(--t,1,r.left,null,r.right):e.splice(--t,1,r.left,r.right),i+=1+r.break,n-=r.size}else{if(!(r>2*n))break;{let t=e[i];t.break?e.splice(i,1,t.left,null,t.right):e.splice(i,1,t.left,t.right),i+=2+t.break,r-=t.size}}else if(n=r&&s(this.blockAt(0,i,n,r))}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class qu extends Xu{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,n){return new Mu(n,this.length,i,this.height,this.breaks)}replace(e,t,i){let n=i[0];return 1==i.length&&(n instanceof qu||n instanceof Vu&&4&n.flags)&&Math.abs(this.length-n.length)<10?(n instanceof Vu?n=new qu(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):Zu.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class Vu extends Zu{constructor(e){super(e,0)}heightMetrics(e,t){let i,n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,o=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*s);i=t/s,this.length>s+1&&(o=(this.height-t)/(this.length-s-1))}else i=this.height/s;return{firstLine:n,lastLine:r,perLine:i,perChar:o}}blockAt(e,t,i,n){let{firstLine:r,lastLine:s,perLine:o,perChar:a}=this.heightMetrics(t,n);if(t.lineWrapping){let r=n+(e0){let e=i[i.length-1];e instanceof Vu?i[i.length-1]=new Vu(e.length+n):i.push(null,new Vu(n-1))}if(e>0){let t=i[0];t instanceof Vu?i[0]=new Vu(e+t.length):i.unshift(new Vu(e-1),null)}return Zu.of(i)}decomposeLeft(e,t){t.push(new Vu(e-1),null)}decomposeRight(e,t){t.push(null,new Vu(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let r=t+this.length;if(n&&n.from<=t+this.length&&n.more){let i=[],s=Math.max(t,n.from),o=-1;for(n.from>t&&i.push(new Vu(n.from-t-1).updateHeight(e,t));s<=r&&n.more;){let t=e.doc.lineAt(s).length;i.length&&i.push(null);let r=n.heights[n.index++];-1==o?o=r:Math.abs(r-o)>=Du&&(o=-2);let a=new qu(t,r);a.outdated=!1,i.push(a),s+=t+1}s<=r&&i.push(null,new Vu(r-s).updateHeight(e,s));let a=Zu.of(i);return(o<0||Math.abs(a.height-this.height)>=Du||Math.abs(o-this.heightMetrics(e,t).perLine)>=Du)&&(Cu=!0),Lu(this,a)}return(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class Iu extends Zu{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return 1&this.flags}blockAt(e,t,i,n){let r=i+this.left.height;return eo))return l;let h=t==Ru.ByPosNoHeight?Ru.ByPosNoHeight:Ru.ByPos;return a?l.join(this.right.lineAt(o,h,i,s,o)):this.left.lineAt(o,h,i,n,r).join(l)}forEachLine(e,t,i,n,r,s){let o=n+this.left.height,a=r+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,o,a,s);else{let l=this.lineAt(a,Ru.ByPos,i,n,r);e=e&&l.from<=t&&s(l),t>l.to&&this.right.forEachLine(l.to+1,t,i,o,a,s)}}replace(e,t,i){let n=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let s=r.length;for(let o of i)r.push(o);if(e>0&&zu(r,s-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e2*t.size||t.size>2*e.size?Zu.of(this.break?[e,null,t]:[e,t]):(this.left=Lu(this.left,e),this.right=Lu(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:r,right:s}=this,o=t+r.length+this.break,a=null;return n&&n.from<=t+r.length&&n.more?a=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=o+s.length&&n.more?a=s=s.updateHeight(e,o,i,n):s.updateHeight(e,o,i),a?this.balanced(r,s):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function zu(e,t){let i,n;null==e[t]&&(i=e[t-1])instanceof Vu&&(n=e[t+1])instanceof Vu&&e.splice(t-1,3,new Vu(i.length+1+n.length))}class ju{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof qu?i.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new qu(e-this.pos,-1)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=5)&&this.addLineDeco(n,r,s)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new qu(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new Vu(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof qu)return e;let t=new qu(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||t instanceof qu||this.isCovered?(this.writtenTot.clientHeight||t.scrollWidth>t.clientWidth)&&"visible"!=i.overflow){let i=t.getBoundingClientRect();s=Math.max(s,i.left),o=Math.min(o,i.right),a=Math.max(a,i.top),l=Math.min(h==e.parentNode?r.innerHeight:l,i.bottom)}h="absolute"==i.position||"fixed"==i.position?t.offsetParent:t.parentNode}else{if(11!=h.nodeType)break;h=h.host}return{left:s-i.left,right:Math.max(s,o)-i.left,top:a-(i.top+t),bottom:Math.max(a,l)-(i.top+t)}}function Yu(e,t){let i=e.getBoundingClientRect();return{left:0,right:i.right-i.left,top:t,bottom:i.bottom-(i.top+t)}}class Wu{constructor(e,t,i,n){this.from=e,this.to=t,this.size=i,this.displaySize=n}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i"function"!=typeof e&&"cm-lineWrapping"==e.class));this.heightOracle=new Au(t),this.stateDeco=e.facet(xc).filter((e=>"function"!=typeof e)),this.heightMap=Zu.empty().applyChanges(this.stateDeco,_o.empty,this.heightOracle.setDoc(e.doc),[new Tc(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=xh.set(this.lineGaps.map((e=>e.draw(this,!1)))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some((({from:e,to:t})=>n>=e&&n<=t))){let{from:t,to:i}=this.lineBlockAt(n);e.push(new Uu(t,i))}}return this.viewports=e.sort(((e,t)=>e.from-t.from)),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ju:new ed(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,(e=>{this.viewportLines.push(td(e,this.scaler))}))}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(xc).filter((e=>"function"!=typeof e));let n=e.changedRanges,r=Tc.extendWithRanges(n,function(e,t,i){let n=new Bu;return Ga.compare(e,t,i,n,0),n.changes}(i,this.stateDeco,e?e.changes:Bo.empty(this.state.doc.length))),s=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Tu(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=s||Cu)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=s);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head