a&&o.push(new ot(a,m.from,d));let g=m.direction==ei!=!(d%2);Es(i,g?n+1:n,r,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(l?N[p]!=O:N[p]==O))break;p++}f?js(i,a,p,n+1,r,f,o):ae;){let l=!0,c=!1;if(!h||a>s[h-1].to){let m=N[a-1];m!=O&&(l=!1,c=m==16)}let f=!l&&O==1?[]:null,d=l?n:n+1,p=a;e:for(;;)if(h&&p==s[h-1].to){if(c)break e;let m=s[--h];if(!l)for(let g=m.from,$=h;;){if(g==e)break e;if($&&s[$-1].to==g)g=s[--$].from;else{if(N[g-1]==O)break e;break}}if(f)f.push(m);else{m.toN.length;)N[N.length]=256;let n=[],r=e==ei?0:1;return Es(i,r,r,t,0,i.length,n),n}function Kl(i){return[new ot(0,i,0)]}var Jl="";function yp(i,e,t,n,r){var s;let o=n.head-i.from,O=ot.find(e,o,(s=n.bidiLevel)!==null&&s!==void 0?s:-1,n.assoc),a=e[O],h=a.side(r,t);if(o==h){let f=O+=r?1:-1;if(f<0||f>=e.length)return null;a=e[O=f],o=a.side(!r,t),h=a.side(r,t)}let l=le(i.text,o,a.forward(r,t));(la.to)&&(l=h),Jl=i.text.slice(Math.min(o,l),Math.max(o,l));let c=O==(r?e.length-1:0)?null:e[O+(r?1:-1)];return c&&l==h&&c.level+(r?0:1)i.some(e=>e)}),Oh=W.define({combine:i=>i.some(e=>e)}),ah=W.define(),en=class i{constructor(e,t="nearest",n="nearest",r=5,s=5,o=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=s,this.isSnapshot=o}map(e){return e.empty?this:new i(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 i(S.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},Fn=D.define({map:(i,e)=>i.map(e)}),lh=D.define();function Me(i,e,t){let n=i.facet(nh);n.length?n[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}var Tt=W.define({combine:i=>i.length?i[0]:!0}),bp=0,Ii=W.define(),Ge=class i{constructor(e,t,n,r,s){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.extension=s(this)}static define(e,t){let{eventHandlers:n,eventObservers:r,provide:s,decorations:o}=t||{};return new i(bp++,e,n,r,O=>{let a=[Ii.of(O)];return o&&a.push(cn.of(h=>{let l=h.plugin(O);return l?o(l):j.none})),s&&a.push(s(O)),a})}static fromClass(e,t){return i.define(n=>new e(n),t)}},tn=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(n){if(Me(t.state,n,"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){Me(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(n){Me(e.state,n,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}},hh=W.define(),yo=W.define(),cn=W.define(),ch=W.define(),Po=W.define(),fh=W.define();function ol(i,e){let t=i.state.facet(fh);if(!t.length)return t;let n=t.map(s=>s instanceof Function?s(i):s),r=[];return F.spans(n,e.from,e.to,{point(){},span(s,o,O,a){let h=s-e.from,l=o-e.from,c=r;for(let f=O.length-1;f>=0;f--,a--){let d=O[f].spec.bidiIsolate,p;if(d==null&&(d=Pp(e.text,h,l)),a>0&&c.length&&(p=c[c.length-1]).to==h&&p.direction==d)p.to=l,c=p.inner;else{let m={from:h,to:l,direction:d,inner:[]};c.push(m),c=m.inner}}}}),r}var uh=W.define();function dh(i){let e=0,t=0,n=0,r=0;for(let s of i.state.facet(uh)){let o=s(i);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(n=Math.max(n,o.top)),o.bottom!=null&&(r=Math.max(r,o.bottom)))}return{left:e,right:t,top:n,bottom:r}}var Bi=W.define(),Ot=class i{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(e){return new i(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,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toAl)break;s+=2}if(!a)return n;new i(a.fromA,a.toA,a.fromB,a.toB).addToSet(n),o=a.toA,O=a.toB}}},ur=class i{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=me.empty(this.startState.doc.length);for(let s of n)this.changes=this.changes.compose(s.changes);let r=[];this.changes.iterChangedRanges((s,o,O,a)=>r.push(new Ot(s,o,O,a))),this.changedRanges=r}static create(e,t,n){return new i(e,t,n)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},dr=class extends H{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=j.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 he],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ot(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let n=e.changedRanges;this.minWidth>0&&n.length&&(n.every(({fromA:h,toA:l})=>lthis.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 r=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?r=this.domChanged.newSel.head:!Wp(e.changes,this.hasComposition)&&!e.selectionSet&&(r=e.state.selection.main.head));let s=r>-1?kp(this.view,e.changes,r):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:h,to:l}=this.hasComposition;n=new Ot(h,l,e.changes.mapPos(h,-1),e.changes.mapPos(l,1)).addToSet(n.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(z.ie||z.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,O=this.updateDeco(),a=vp(o,O,e.changes);return n=Ot.extendWithRanges(n,a),!(this.flags&7)&&n.length==0?!1:(this.updateInner(n,e.startState.doc.length,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,n){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,n);let{observer:r}=this.view;r.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=z.chrome||z.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||r.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let s=[];if(this.view.viewport.from||this.view.viewport.to=0?r[o]:null;if(!O)break;let{fromA:a,toA:h,fromB:l,toB:c}=O,f,d,p,m;if(n&&n.range.fromBl){let k=Ji.build(this.view.state.doc,l,n.range.fromB,this.decorations,this.dynamicDecorationMap),y=Ji.build(this.view.state.doc,n.range.toB,c,this.decorations,this.dynamicDecorationMap);d=k.breakAtStart,p=k.openStart,m=y.openEnd;let w=this.compositionView(n);y.breakAtStart?w.breakAfter=1:y.content.length&&w.merge(w.length,w.length,y.content[0],!1,y.openStart,0)&&(w.breakAfter=y.content[0].breakAfter,y.content.shift()),k.content.length&&w.merge(0,0,k.content[k.content.length-1],!0,0,k.openEnd)&&k.content.pop(),f=k.content.concat(w).concat(y.content)}else({content:f,breakAtStart:d,openStart:p,openEnd:m}=Ji.build(this.view.state.doc,l,c,this.decorations,this.dynamicDecorationMap));let{i:g,off:$}=s.findPos(h,1),{i:Q,off:b}=s.findPos(a,-1);jl(this,Q,b,g,$,f,d,p,m)}n&&this.fixCompositionDOM(n)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let n of t.effects)n.is(lh)&&(this.editContextFormatting=n.value)}compositionView(e){let t=new lt(e.text.nodeValue);t.flags|=8;for(let{deco:r}of e.marks)t=new Wt(r,[t],t.length);let n=new he;return n.append(t,0),n}fixCompositionDOM(e){let t=(s,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let O=H.get(s);O&&O!=o&&(O.dom=null),o.setDOM(s)},n=this.childPos(e.range.fromB,1),r=this.children[n.i];t(e.line,r);for(let s=e.marks.length-1;s>=-1;s--)n=r.childPos(n.off,1),r=r.children[n.i],t(s>=0?e.marks[s].node:e.text,r)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let n=this.view.root.activeElement,r=n==this.dom,s=!r&&nr(this.dom,this.view.observer.selectionRange)&&!(n&&this.dom.contains(n));if(!(r||t||s))return;let o=this.forceSelection;this.forceSelection=!1;let O=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(O.anchor)),h=O.empty?a:this.moveToLine(this.domAtPos(O.head));if(z.gecko&&O.empty&&!this.hasComposition&&xp(a)){let c=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(c,a.node.childNodes[a.offset]||null)),a=h=new $e(c,0),o=!0}let l=this.view.observer.selectionRange;(o||!l.focusNode||(!Ki(a.node,a.offset,l.anchorNode,l.anchorOffset)||!Ki(h.node,h.offset,l.focusNode,l.focusOffset))&&!this.suppressWidgetCursorChange(l,O))&&(this.view.observer.ignore(()=>{z.android&&z.chrome&&this.dom.contains(l.focusNode)&&zp(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let c=sn(this.view.root);if(c)if(O.empty){if(z.gecko){let f=wp(a.node,a.offset);if(f&&f!=3){let d=(f==1?Al:_l)(a.node,a.offset);d&&(a=new $e(d.node,d.offset))}}c.collapse(a.node,a.offset),O.bidiLevel!=null&&c.caretBidiLevel!==void 0&&(c.caretBidiLevel=O.bidiLevel)}else if(c.extend){c.collapse(a.node,a.offset);try{c.extend(h.node,h.offset)}catch{}}else{let f=document.createRange();O.anchor>O.head&&([a,h]=[h,a]),f.setEnd(h.node,h.offset),f.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(f)}s&&this.view.root.activeElement==this.dom&&(this.dom.blur(),n&&n.focus())}),this.view.observer.setSelectionRange(a,h)),this.impreciseAnchor=a.precise?null:new $e(l.anchorNode,l.anchorOffset),this.impreciseHead=h.precise?null:new $e(l.focusNode,l.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Ki(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,n=sn(e.root),{anchorNode:r,anchorOffset:s}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let o=he.find(this,t.head);if(!o)return;let O=o.posAtStart;if(t.head==O||t.head==O+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let l=this.domAtPos(t.head+t.assoc);n.collapse(l.node,l.offset),n.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&&n.collapse(r,s)}moveToLine(e){let t=this.dom,n;if(e.node!=t)return e;for(let r=e.offset;!n&&r=0;r--){let s=H.get(t.childNodes[r]);s instanceof he&&(n=s.domAtPos(s.length))}return n?new $e(n.node,n.offset,!0):e}nearest(e){for(let t=e;t;){let n=H.get(t);if(n&&n.rootView==this)return n;t=t.parentNode}return null}posFromDOM(e,t){let n=this.nearest(e);if(!n)throw new RangeError("Trying to find position for a DOM position outside of the document");return n.localPosFromDOM(e,t)+n.posAtStart}domAtPos(e){let{i:t,off:n}=this.childCursor().findPos(e,-1);for(;t=0;o--){let O=this.children[o],a=s-O.breakAfter,h=a-O.length;if(ae||O.covers(1))&&(!n||O instanceof he&&!(n instanceof he&&t>=0)))n=O,r=h;else if(n&&h==e&&a==e&&O instanceof Ht&&Math.abs(t)<2){if(O.deco.startSide<0)break;o&&(n=null)}s=h}return n?n.coordsAt(e-r,t):null}coordsForChar(e){let{i:t,off:n}=this.childPos(e,1),r=this.children[t];if(!(r instanceof he))return null;for(;r.children.length;){let{i:O,off:a}=r.childPos(n,1);for(;;O++){if(O==r.children.length)return null;if((r=r.children[O]).length)break}n=a}if(!(r instanceof lt))return null;let s=le(r.text,n);if(s==n)return null;let o=Jt(r.dom,n,s).getClientRects();for(let O=0;OMath.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,O=-1,a=this.view.textDirection==J.LTR;for(let h=0,l=0;lr)break;if(h>=n){let d=c.dom.getBoundingClientRect();if(t.push(d.height),o){let p=c.dom.lastChild,m=p?on(p):[];if(m.length){let g=m[m.length-1],$=a?g.right-d.left:d.right-g.left;$>O&&(O=$,this.minWidth=s,this.minWidthFrom=h,this.minWidthTo=f)}}}h=f+c.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?J.RTL:J.LTR}measureTextSize(){for(let s of this.children)if(s instanceof he){let o=s.measureTextSize();if(o)return o}let e=document.createElement("div"),t,n,r;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let s=on(e.firstChild)[0];t=e.getBoundingClientRect().height,n=s?s.width/27:7,r=s?s.height:t,e.remove()}),{lineHeight:t,charWidth:n,textHeight:r}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new hr(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let s=r==t.viewports.length?null:t.viewports[r],o=s?s.from-1:this.length;if(o>n){let O=(t.lineBlockAt(o).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(j.replace({widget:new hn(O),block:!0,inclusive:!0,isBlockGap:!0}).range(n,o))}if(!s)break;n=s.to+1}return j.set(e)}updateDeco(){let e=1,t=this.view.state.facet(cn).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),n=!1,r=this.view.state.facet(ch).map((s,o)=>{let O=typeof s=="function";return O&&(n=!0),O?s(this.view):s});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push(F.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];et.anchor?-1:1),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let s=dh(this.view),o={left:n.left-s.left,top:n.top-s.top,right:n.right+s.right,bottom:n.bottom+s.bottom},{offsetWidth:O,offsetHeight:a}=this.view.scrollDOM;sp(this.view.scrollDOM,o,t.head{ne.from&&(t=!0)}),t}function Rp(i,e,t=1){let n=i.charCategorizer(e),r=i.doc.lineAt(e),s=e-r.from;if(r.length==0)return S.cursor(e);s==0?t=1:s==r.length&&(t=-1);let o=s,O=s;t<0?o=le(r.text,s,!1):O=le(r.text,s);let a=n(r.text.slice(o,O));for(;o>0;){let h=le(r.text,o,!1);if(n(r.text.slice(h,o))!=a)break;o=h}for(;Oi?e.left-i:Math.max(0,i-e.right)}function Zp(i,e){return e.top>i?e.top-i:Math.max(0,i-e.bottom)}function vs(i,e){return i.tope.top+1}function Ol(i,e){return ei.bottom?{top:i.top,left:i.left,right:i.right,bottom:e}:i}function Gs(i,e,t){let n,r,s,o,O=!1,a,h,l,c;for(let p=i.firstChild;p;p=p.nextSibling){let m=on(p);for(let g=0;gb||o==b&&s>Q){n=p,r=$,s=Q,o=b;let k=b?t<$.top?-1:1:Q?e<$.left?-1:1:0;O=!k||(k>0?g0)}Q==0?t>$.bottom&&(!l||l.bottom<$.bottom)?(a=p,l=$):t<$.top&&(!c||c.top>$.top)&&(h=p,c=$):l&&vs(l,$)?l=al(l,$.bottom):c&&vs(c,$)&&(c=Ol(c,$.top))}}if(l&&l.bottom>=t?(n=a,r=l):c&&c.top<=t&&(n=h,r=c),!n)return{node:i,offset:0};let f=Math.max(r.left,Math.min(r.right,e));if(n.nodeType==3)return ll(n,f,t);if(O&&n.contentEditable!="false")return Gs(n,f,t);let d=Array.prototype.indexOf.call(i.childNodes,n)+(e>=(r.left+r.right)/2?1:0);return{node:i,offset:d}}function ll(i,e,t){let n=i.nodeValue.length,r=-1,s=1e9,o=0;for(let O=0;Ot?l.top-t:t-l.bottom)-1;if(l.left-1<=e&&l.right+1>=e&&c=(l.left+l.right)/2,d=f;if((z.chrome||z.gecko)&&Jt(i,O).getBoundingClientRect().left==l.right&&(d=!f),c<=0)return{node:i,offset:O+(d?1:0)};r=O+(d?1:0),s=c}}}return{node:i,offset:r>-1?r:o>0?i.nodeValue.length:0}}function mh(i,e,t,n=-1){var r,s;let o=i.contentDOM.getBoundingClientRect(),O=o.top+i.viewState.paddingTop,a,{docHeight:h}=i.viewState,{x:l,y:c}=e,f=c-O;if(f<0)return 0;if(f>h)return i.state.doc.length;for(let k=i.viewState.heightOracle.textHeight/2,y=!1;a=i.elementAtHeight(f),a.type!=Qe.Text;)for(;f=n>0?a.bottom+k:a.top-k,!(f>=0&&f<=h);){if(y)return t?null:0;y=!0,n=-n}c=O+f;let d=a.from;if(di.viewport.to)return i.viewport.to==i.state.doc.length?i.state.doc.length:t?null:hl(i,o,a,l,c);let p=i.dom.ownerDocument,m=i.root.elementFromPoint?i.root:p,g=m.elementFromPoint(l,c);g&&!i.contentDOM.contains(g)&&(g=null),g||(l=Math.max(o.left+1,Math.min(o.right-1,l)),g=m.elementFromPoint(l,c),g&&!i.contentDOM.contains(g)&&(g=null));let $,Q=-1;if(g&&((r=i.docView.nearest(g))===null||r===void 0?void 0:r.isEditable)!=!1){if(p.caretPositionFromPoint){let k=p.caretPositionFromPoint(l,c);k&&({offsetNode:$,offset:Q}=k)}else if(p.caretRangeFromPoint){let k=p.caretRangeFromPoint(l,c);k&&({startContainer:$,startOffset:Q}=k,(!i.contentDOM.contains($)||z.safari&&qp($,Q,l)||z.chrome&&Vp($,Q,l))&&($=void 0))}$&&(Q=Math.min(at($),Q))}if(!$||!i.docView.dom.contains($)){let k=he.find(i.docView,d);if(!k)return f>a.top+a.height/2?a.to:a.from;({node:$,offset:Q}=Gs(k.dom,l,c))}let b=i.docView.nearest($);if(!b)return null;if(b.isWidget&&((s=b.dom)===null||s===void 0?void 0:s.nodeType)==1){let k=b.dom.getBoundingClientRect();return e.yi.defaultLineHeight*1.5){let O=i.viewState.heightOracle.textHeight,a=Math.floor((r-t.top-(i.defaultLineHeight-O)*.5)/O);s+=a*i.viewState.heightOracle.lineLength}let o=i.state.sliceDoc(t.from,t.to);return t.from+In(o,s,i.state.tabSize)}function qp(i,e,t){let n;if(i.nodeType!=3||e!=(n=i.nodeValue.length))return!1;for(let r=i.nextSibling;r;r=r.nextSibling)if(r.nodeType!=1||r.nodeName!="BR")return!1;return Jt(i,n-1,n).getBoundingClientRect().left>t}function Vp(i,e,t){if(e!=0)return!1;for(let r=i;;){let s=r.parentNode;if(!s||s.nodeType!=1||s.firstChild!=r)return!1;if(s.classList.contains("cm-line"))break;r=s}let n=i.nodeType==1?i.getBoundingClientRect():Jt(i,0,Math.max(i.nodeValue.length,1)).getBoundingClientRect();return t-n.left>5}function Ls(i,e){let t=i.lineBlockAt(e);if(Array.isArray(t.type)){for(let n of t.type)if(n.to>e||n.to==e&&(n.to==t.to||n.type==Qe.Text))return n}return t}function Cp(i,e,t,n){let r=Ls(i,e.head),s=!n||r.type!=Qe.Text||!(i.lineWrapping||r.widgetLineBreaks)?null:i.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head);if(s){let o=i.dom.getBoundingClientRect(),O=i.textDirectionAt(r.from),a=i.posAtCoords({x:t==(O==J.LTR)?o.right-1:o.left+1,y:(s.top+s.bottom)/2});if(a!=null)return S.cursor(a,t?-1:1)}return S.cursor(t?r.to:r.from,t?-1:1)}function cl(i,e,t,n){let r=i.state.doc.lineAt(e.head),s=i.bidiSpans(r),o=i.textDirectionAt(r.from);for(let O=e,a=null;;){let h=yp(r,s,o,O,t),l=Jl;if(!h){if(r.number==(t?i.state.doc.lines:1))return O;l=`
-`,r=i.state.doc.line(r.number+(t?1:-1)),s=i.bidiSpans(r),h=i.visualLineSide(r,!t)}if(a){if(!a(l))return O}else{if(!n)return h;a=n(l)}O=h}}function Yp(i,e,t){let n=i.state.charCategorizer(e),r=n(t);return s=>{let o=n(s);return r==_e.Space&&(r=o),r==o}}function Up(i,e,t,n){let r=e.head,s=t?1:-1;if(r==(t?i.state.doc.length:0))return S.cursor(r,e.assoc);let o=e.goalColumn,O,a=i.contentDOM.getBoundingClientRect(),h=i.coordsAtPos(r,e.assoc||-1),l=i.documentTop;if(h)o==null&&(o=h.left-a.left),O=s<0?h.top:h.bottom;else{let d=i.viewState.lineBlockAt(r);o==null&&(o=Math.min(a.right-a.left,i.defaultCharacterWidth*(r-d.from))),O=(s<0?d.top:d.bottom)+l}let c=a.left+o,f=n??i.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=O+(f+d)*s,m=mh(i,{x:c,y:p},!1,s);if(pa.bottom||(s<0?mr)){let g=i.docView.coordsForChar(m),$=!g||p{if(e>s&&er(i)),t.from,e.head>t.from?-1:1);return n==t.from?t:S.cursor(n,ns)&&this.lineBreak(),r=o}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,o=1,O;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,n),o=this.lineSeparator.length):(O=r.exec(t))&&(s=O.index,o=O[0].length),this.append(t.slice(n,s<0?t.length:s)),s<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);n=s+o}}readNode(e){if(e.cmIgnore)return;let t=H.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let r=n.iter();!r.next().done;)r.lineBreak?this.lineBreak():this.append(r.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(e.nodeType==3?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(Ap(e,n.node,n.offset)?t:0))}};function Ap(i,e,t){for(;;){if(!e||t-1;let{impreciseHead:s,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,n,0))){let O=s||o?[]:Ep(e),a=new Ds(O,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Mp(O,this.bounds.from)}else{let O=e.observer.selectionRange,a=s&&s.node==O.focusNode&&s.offset==O.focusOffset||!Xs(e.contentDOM,O.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(O.focusNode,O.focusOffset),h=o&&o.node==O.anchorNode&&o.offset==O.anchorOffset||!Xs(e.contentDOM,O.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(O.anchorNode,O.anchorOffset),l=e.viewport;if((z.ios||z.chrome)&&e.state.selection.main.empty&&a!=h&&(l.from>0||l.toDate.now()-100?i.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:O}=e.bounds,a=r.from,h=null;(s===8||z.android&&e.text.length=r.from&&t.to<=r.to&&(t.from!=r.from||t.to!=r.to)&&r.to-r.from-(t.to-t.from)<=4?t={from:r.from,to:r.to,insert:i.state.doc.slice(r.from,t.from).append(t.insert).append(i.state.doc.slice(t.to,r.to))}:(z.mac||z.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&i.contentDOM.getAttribute("autocorrect")=="off"?(n&&t.insert.length==2&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:r.from,to:r.to,insert:Y.of([" "])}):z.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==`
- `&&i.lineWrapping&&(n&&(n=S.single(n.main.anchor-1,n.main.head-1)),t={from:r.from,to:r.to,insert:Y.of([" "])}),t)return bo(i,t,n,s);if(n&&!n.main.eq(r)){let o=!1,O="select";return i.inputState.lastSelectionTime>Date.now()-50&&(i.inputState.lastSelectionOrigin=="select"&&(o=!0),O=i.inputState.lastSelectionOrigin),i.dispatch({selection:n,scrollIntoView:o,userEvent:O}),!0}else return!1}function bo(i,e,t,n=-1){if(z.ios&&i.inputState.flushIOSKey(e))return!0;let r=i.state.selection.main;if(z.android&&(e.to==r.to&&(e.from==r.from||e.from==r.from-1&&i.state.sliceDoc(e.from,r.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&bi(i.contentDOM,"Enter",13)||(e.from==r.from-1&&e.to==r.to&&e.insert.length==0||n==8&&e.insert.lengthr.head)&&bi(i.contentDOM,"Backspace",8)||e.from==r.from&&e.to==r.to+1&&e.insert.length==0&&bi(i.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();i.inputState.composing>=0&&i.inputState.composing++;let o,O=()=>o||(o=_p(i,e,t));return i.state.facet(rh).some(a=>a(i,e.from,e.to,s,O))||i.dispatch(O()),!0}function _p(i,e,t){let n,r=i.state,s=r.selection.main;if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&i.inputState.composing<0){let O=s.frome.to?r.sliceDoc(e.to,s.to):"";n=r.replaceSelection(i.state.toText(O+e.insert.sliceString(0,void 0,i.state.lineBreak)+a))}else{let O=r.changes(e),a=t&&t.main.to<=O.newLength?t.main:void 0;if(r.selection.ranges.length>1&&i.inputState.composing>=0&&e.to<=s.to&&e.to>=s.to-10){let h=i.state.sliceDoc(e.from,e.to),l,c=t&&ph(i,t.main.head);if(c){let p=e.insert.length-(e.to-e.from);l={from:c.from,to:c.to-p}}else l=i.state.doc.lineAt(s.head);let f=s.to-e.to,d=s.to-s.from;n=r.changeByRange(p=>{if(p.from==s.from&&p.to==s.to)return{changes:O,range:a||p.map(O)};let m=p.to-f,g=m-h.length;if(p.to-p.from!=d||i.state.sliceDoc(g,m)!=h||p.to>=l.from&&p.from<=l.to)return{range:p};let $=r.changes({from:g,to:m,insert:e.insert}),Q=p.to-s.to;return{changes:$,range:a?S.range(Math.max(0,a.anchor+Q),Math.max(0,a.head+Q)):p.map($)}})}else n={changes:O,selection:a&&r.selection.replaceRange(a)}}let o="input.type";return(i.composing||i.inputState.compositionPendingChange&&i.inputState.compositionEndedAt>Date.now()-50)&&(i.inputState.compositionPendingChange=!1,o+=".compose",i.inputState.compositionFirstChange&&(o+=".start",i.inputState.compositionFirstChange=!1)),r.update(n,{userEvent:o,scrollIntoView:!0})}function jp(i,e,t,n){let r=Math.min(i.length,e.length),s=0;for(;s0&&O>0&&i.charCodeAt(o-1)==e.charCodeAt(O-1);)o--,O--;if(n=="end"){let a=Math.max(0,s-Math.min(o,O));t-=o+a-s}if(o=o?s-t:0;s-=a,O=s+(O-o),o=s}else if(O=O?s-t:0;s-=a,o=s+(o-O),O=s}return{from:s,toA:o,toB:O}}function Ep(i){let e=[];if(i.root.activeElement!=i.contentDOM)return e;let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}=i.observer.selectionRange;return t&&(e.push(new pr(t,n)),(r!=t||s!=n)&&e.push(new pr(r,s))),e}function Mp(i,e){if(i.length==0)return null;let t=i[0].pos,n=i.length==2?i[1].pos:t;return t>-1&&n>-1?S.single(t+e,n+e):null}var Bs=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){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,z.safari&&e.contentDOM.addEventListener("input",()=>null),z.gecko&&rm(e.contentDOM.ownerDocument)}handleEvent(e){!Fp(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||this.runHandlers(e.type,e)}runHandlers(e,t){let n=this.handlers[e];if(n){for(let r of n.observers)r(this.view,t);for(let r of n.handlers){if(t.defaultPrevented)break;if(r(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Gp(e),n=this.handlers,r=this.view.contentDOM;for(let s in t)if(s!="scroll"){let o=!t[s].handlers.length,O=n[s];O&&o!=!O.handlers.length&&(r.removeEventListener(s,this.handleEvent),O=null),O||r.addEventListener(s,this.handleEvent,{passive:o})}for(let s in n)s!="scroll"&&!t[s]&&r.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Qh.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),z.android&&z.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return z.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=$h.find(n=>n.keyCode==e.keyCode))&&!e.ctrlKey||Lp.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from0?!0:z.safari&&!z.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}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 fl(i,e){return(t,n)=>{try{return e.call(i,n,t)}catch(r){Me(t.state,r)}}}function Gp(i){let e=Object.create(null);function t(n){return e[n]||(e[n]={observers:[],handlers:[]})}for(let n of i){let r=n.spec;if(r&&r.domEventHandlers)for(let s in r.domEventHandlers){let o=r.domEventHandlers[s];o&&t(s).handlers.push(fl(n.value,o))}if(r&&r.domEventObservers)for(let s in r.domEventObservers){let o=r.domEventObservers[s];o&&t(s).observers.push(fl(n.value,o))}}for(let n in Fe)t(n).handlers.push(Fe[n]);for(let n in Le)t(n).observers.push(Le[n]);return e}var $h=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Lp="dthko",Qh=[16,17,18,20,91,92,224,225],Hn=6;function Kn(i){return Math.max(0,i)*.7+8}function Dp(i,e){return Math.max(Math.abs(i.clientX-e.clientX),Math.abs(i.clientY-e.clientY))}var Ns=class{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=op(e.contentDOM),this.atoms=e.state.facet(Po).map(o=>o(e));let s=e.contentDOM.ownerDocument;s.addEventListener("mousemove",this.move=this.move.bind(this)),s.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(I.allowMultipleSelections)&&Ip(e,t),this.dragging=Np(e,t)&&Ph(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Dp(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,s=0,o=this.view.win.innerWidth,O=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:O}=this.scrollParents.y.getBoundingClientRect());let a=dh(this.view);e.clientX-a.left<=r+Hn?t=-Kn(r-e.clientX):e.clientX+a.right>=o-Hn&&(t=Kn(e.clientX-o)),e.clientY-a.top<=s+Hn?n=-Kn(s-e.clientY):e.clientY+a.bottom>=O-Hn&&(n=Kn(e.clientY-O)),this.setScrollSpeed(t,n)}up(e){this.dragging==null&&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),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let n=0;nt.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Ip(i,e){let t=i.state.facet(eh);return t.length?t[0](e):z.mac?e.metaKey:e.ctrlKey}function Bp(i,e){let t=i.state.facet(th);return t.length?t[0](e):z.mac?!e.altKey:!e.ctrlKey}function Np(i,e){let{main:t}=i.state.selection;if(t.empty)return!1;let n=sn(i.root);if(!n||n.rangeCount==0)return!0;let r=n.getRangeAt(0).getClientRects();for(let s=0;s=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Fp(i,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,n;t!=i.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(n=H.get(t))&&n.ignoreEvent(e))return!1;return!0}var Fe=Object.create(null),Le=Object.create(null),Sh=z.ie&&z.ie_version<15||z.ios&&z.webkit_version<604;function Hp(i){let e=i.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{i.focus(),t.remove(),yh(i,t.value)},50)}function xr(i,e,t){for(let n of i.facet(e))t=n(t,i);return t}function yh(i,e){e=xr(i.state,Qo,e);let{state:t}=i,n,r=1,s=t.toText(e),o=s.lines==t.selection.ranges.length;if(Fs!=null&&t.selection.ranges.every(a=>a.empty)&&Fs==s.toString()){let a=-1;n=t.changeByRange(h=>{let l=t.doc.lineAt(h.from);if(l.from==a)return{range:h};a=l.from;let c=t.toText((o?s.line(r++).text:e)+t.lineBreak);return{changes:{from:l.from,insert:c},range:S.cursor(h.from+c.length)}})}else o?n=t.changeByRange(a=>{let h=s.line(r++);return{changes:{from:a.from,to:a.to,insert:h.text},range:S.cursor(a.from+h.length)}}):n=t.replaceSelection(s);i.dispatch(n,{userEvent:"input.paste",scrollIntoView:!0})}Le.scroll=i=>{i.inputState.lastScrollTop=i.scrollDOM.scrollTop,i.inputState.lastScrollLeft=i.scrollDOM.scrollLeft};Fe.keydown=(i,e)=>(i.inputState.setSelectionOrigin("select"),e.keyCode==27&&i.inputState.tabFocusMode!=0&&(i.inputState.tabFocusMode=Date.now()+2e3),!1);Le.touchstart=(i,e)=>{i.inputState.lastTouchTime=Date.now(),i.inputState.setSelectionOrigin("select.pointer")};Le.touchmove=i=>{i.inputState.setSelectionOrigin("select.pointer")};Fe.mousedown=(i,e)=>{if(i.observer.flush(),i.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let n of i.state.facet(ih))if(t=n(i,e),t)break;if(!t&&e.button==0&&(t=em(i,e)),t){let n=!i.hasFocus;i.inputState.startMouseSelection(new Ns(i,e,t,n)),n&&i.observer.ignore(()=>{Cl(i.contentDOM);let s=i.root.activeElement;s&&!s.contains(i.contentDOM)&&s.blur()});let r=i.inputState.mouseSelection;if(r)return r.start(e),r.dragging===!1}return!1};function ul(i,e,t,n){if(n==1)return S.cursor(e,t);if(n==2)return Rp(i.state,e,t);{let r=he.find(i.docView,e),s=i.state.doc.lineAt(r?r.posAtEnd:e),o=r?r.posAtStart:s.from,O=r?r.posAtEnd:s.to;return Oe>=t.top&&e<=t.bottom&&i>=t.left&&i<=t.right;function Kp(i,e,t,n){let r=he.find(i.docView,e);if(!r)return 1;let s=e-r.posAtStart;if(s==0)return 1;if(s==r.length)return-1;let o=r.coordsAt(s,-1);if(o&&dl(t,n,o))return-1;let O=r.coordsAt(s,1);return O&&dl(t,n,O)?1:o&&o.bottom>=n?-1:1}function pl(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Kp(i,t,e.clientX,e.clientY)}}var Jp=z.ie&&z.ie_version<=11,ml=null,gl=0,$l=0;function Ph(i){if(!Jp)return i.detail;let e=ml,t=$l;return ml=i,$l=Date.now(),gl=!e||t>Date.now()-400&&Math.abs(e.clientX-i.clientX)<2&&Math.abs(e.clientY-i.clientY)<2?(gl+1)%3:1}function em(i,e){let t=pl(i,e),n=Ph(e),r=i.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),r=r.map(s.changes))},get(s,o,O){let a=pl(i,s),h,l=ul(i,a.pos,a.bias,n);if(t.pos!=a.pos&&!o){let c=ul(i,t.pos,t.bias,n),f=Math.min(c.from,l.from),d=Math.max(c.to,l.to);l=f1&&(h=tm(r,a.pos))?h:O?r.addRange(l):S.create([l])}}}function tm(i,e){for(let t=0;t=e)return S.create(i.ranges.slice(0,t).concat(i.ranges.slice(t+1)),i.mainIndex==t?0:i.mainIndex-(i.mainIndex>t?1:0))}return null}Fe.dragstart=(i,e)=>{let{selection:{main:t}}=i.state;if(e.target.draggable){let r=i.docView.nearest(e.target);if(r&&r.isWidget){let s=r.posAtStart,o=s+r.length;(s>=t.to||o<=t.from)&&(t=S.range(s,o))}}let{inputState:n}=i;return n.mouseSelection&&(n.mouseSelection.dragging=!0),n.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",xr(i.state,So,i.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Fe.dragend=i=>(i.inputState.draggedContent=null,!1);function Ql(i,e,t,n){if(t=xr(i.state,Qo,t),!t)return;let r=i.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=i.inputState,o=n&&s&&Bp(i,e)?{from:s.from,to:s.to}:null,O={from:r,insert:t},a=i.state.changes(o?[o,O]:O);i.focus(),i.dispatch({changes:a,selection:{anchor:a.mapPos(r,-1),head:a.mapPos(r,1)},userEvent:o?"move.drop":"input.drop"}),i.inputState.draggedContent=null}Fe.drop=(i,e)=>{if(!e.dataTransfer)return!1;if(i.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let n=Array(t.length),r=0,s=()=>{++r==t.length&&Ql(i,e,n.filter(o=>o!=null).join(i.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(O.result)||(n[o]=O.result),s()},O.readAsText(t[o])}return!0}else{let n=e.dataTransfer.getData("Text");if(n)return Ql(i,e,n,!0),!0}return!1};Fe.paste=(i,e)=>{if(i.state.readOnly)return!0;i.observer.flush();let t=Sh?null:e.clipboardData;return t?(yh(i,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Hp(i),!1)};function im(i,e){let t=i.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.value=e,n.focus(),n.selectionEnd=e.length,n.selectionStart=0,setTimeout(()=>{n.remove(),i.focus()},50)}function nm(i){let e=[],t=[],n=!1;for(let r of i.selection.ranges)r.empty||(e.push(i.sliceDoc(r.from,r.to)),t.push(r));if(!e.length){let r=-1;for(let{from:s}of i.selection.ranges){let o=i.doc.lineAt(s);o.number>r&&(e.push(o.text),t.push({from:o.from,to:Math.min(i.doc.length,o.to+1)})),r=o.number}n=!0}return{text:xr(i,So,e.join(i.lineBreak)),ranges:t,linewise:n}}var Fs=null;Fe.copy=Fe.cut=(i,e)=>{let{text:t,ranges:n,linewise:r}=nm(i.state);if(!t&&!r)return!1;Fs=r?t:null,e.type=="cut"&&!i.state.readOnly&&i.dispatch({changes:n,scrollIntoView:!0,userEvent:"delete.cut"});let s=Sh?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(im(i,t),!1)};var bh=ke.define();function xh(i,e){let t=[];for(let n of i.facet(sh)){let r=n(i,e);r&&t.push(r)}return t?i.update({effects:t,annotations:bh.of(!0)}):null}function kh(i){setTimeout(()=>{let e=i.hasFocus;if(e!=i.inputState.notifiedFocused){let t=xh(i.state,e);t?i.dispatch(t):i.update([])}},10)}Le.focus=i=>{i.inputState.lastFocusTime=Date.now(),!i.scrollDOM.scrollTop&&(i.inputState.lastScrollTop||i.inputState.lastScrollLeft)&&(i.scrollDOM.scrollTop=i.inputState.lastScrollTop,i.scrollDOM.scrollLeft=i.inputState.lastScrollLeft),kh(i)};Le.blur=i=>{i.observer.clearSelectionRange(),kh(i)};Le.compositionstart=Le.compositionupdate=i=>{i.observer.editContext||(i.inputState.compositionFirstChange==null&&(i.inputState.compositionFirstChange=!0),i.inputState.composing<0&&(i.inputState.composing=0))};Le.compositionend=i=>{i.observer.editContext||(i.inputState.composing=-1,i.inputState.compositionEndedAt=Date.now(),i.inputState.compositionPendingKey=!0,i.inputState.compositionPendingChange=i.observer.pendingRecords().length>0,i.inputState.compositionFirstChange=null,z.chrome&&z.android?i.observer.flushSoon():i.inputState.compositionPendingChange?Promise.resolve().then(()=>i.observer.flush()):setTimeout(()=>{i.inputState.composing<0&&i.docView.hasComposition&&i.update([])},50))};Le.contextmenu=i=>{i.inputState.lastContextMenu=Date.now()};Fe.beforeinput=(i,e)=>{var t,n;if(e.inputType=="insertReplacementText"&&i.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(s&&o.length){let O=o[0],a=i.posAtDOM(O.startContainer,O.startOffset),h=i.posAtDOM(O.endContainer,O.endOffset);return bo(i,{from:a,to:h,insert:i.state.toText(s)},null),!0}}let r;if(z.chrome&&z.android&&(r=$h.find(s=>s.inputType==e.inputType))&&(i.observer.delayAndroidKey(r.key,r.keyCode),r.key=="Backspace"||r.key=="Delete")){let s=((n=window.visualViewport)===null||n===void 0?void 0:n.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>s+10&&i.hasFocus&&(i.contentDOM.blur(),i.focus())},100)}return z.ios&&e.inputType=="deleteContentForward"&&i.observer.flushSoon(),z.safari&&e.inputType=="insertText"&&i.inputState.composing>=0&&setTimeout(()=>Le.compositionend(i,e),20),!1};var Sl=new Set;function rm(i){Sl.has(i)||(Sl.add(i),i.addEventListener("copy",()=>{}),i.addEventListener("cut",()=>{}))}var yl=["pre-wrap","normal","pre-line","break-spaces"],xi=!1;function Pl(){xi=!1}var Hs=class{constructor(e){this.lineWrapping=e,this.doc=Y.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return yl.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=O;if(this.lineWrapping=O,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=s,a){this.heightSamples={};for(let h=0;h0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>sr&&(xi=!0),this.height=e)}replace(e,t,n){return i.of(n)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let s=this,o=n.doc;for(let O=r.length-1;O>=0;O--){let{fromA:a,toA:h,fromB:l,toB:c}=r[O],f=s.lineAt(a,K.ByPosNoHeight,n.setDoc(t),0,0),d=f.to>=h?f:s.lineAt(h,K.ByPosNoHeight,n,0,0);for(c+=d.to-h,h=d.to;O>0&&f.from<=r[O-1].toA;)a=r[O-1].fromA,l=r[O-1].fromB,O--,as*2){let O=e[t-1];O.break?e.splice(--t,1,O.left,null,O.right):e.splice(--t,1,O.left,O.right),n+=1+O.break,r-=O.size}else if(s>r*2){let O=e[n];O.break?e.splice(n,1,O.left,null,O.right):e.splice(n,1,O.left,O.right),n+=2+O.break,s-=O.size}else break;else if(r=s&&o(this.blockAt(0,n,r,s))}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setHeight(r.heights[r.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},Ee=class i extends gr{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,n,r){return new st(r,this.length,n,this.height,this.breaks)}replace(e,t,n){let r=n[0];return n.length==1&&(r instanceof i||r instanceof zt&&r.flags&4)&&Math.abs(this.length-r.length)<10?(r instanceof zt?r=new i(r.length,this.height):r.height=this.height,this.outdated||(r.outdated=!1),r):Ze.of(n)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setHeight(r.heights[r.index++]):(n||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:""})`}},zt=class i extends Ze{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,s=r-n+1,o,O=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*s);o=a/s,this.length>s+1&&(O=(this.height-a)/(this.length-s-1))}else o=this.height/s;return{firstLine:n,lastLine:r,perLine:o,perChar:O}}blockAt(e,t,n,r){let{firstLine:s,lastLine:o,perLine:O,perChar:a}=this.heightMetrics(t,r);if(t.lineWrapping){let h=r+(e0){let s=n[n.length-1];s instanceof i?n[n.length-1]=new i(s.length+r):n.push(null,new i(r-1))}if(e>0){let s=n[0];s instanceof i?n[0]=new i(e+s.length):n.unshift(new i(e-1),null)}return Ze.of(n)}decomposeLeft(e,t){t.push(new i(e-1),null)}decomposeRight(e,t){t.push(null,new i(this.length-e-1))}updateHeight(e,t=0,n=!1,r){let s=t+this.length;if(r&&r.from<=t+this.length&&r.more){let o=[],O=Math.max(t,r.from),a=-1;for(r.from>t&&o.push(new i(r.from-t-1).updateHeight(e,t));O<=s&&r.more;){let l=e.doc.lineAt(O).length;o.length&&o.push(null);let c=r.heights[r.index++];a==-1?a=c:Math.abs(c-a)>=sr&&(a=-2);let f=new Ee(l,c);f.outdated=!1,o.push(f),O+=l+1}O<=s&&o.push(null,new i(s-O).updateHeight(e,O));let h=Ze.of(o);return(a<0||Math.abs(h.height-this.height)>=sr||Math.abs(a-this.heightMetrics(e,t).perLine)>=sr)&&(xi=!0),mr(this,h)}else(n||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Js=class extends Ze{constructor(e,t,n){super(e.length+t+n.length,e.height+n.height,t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let s=n+this.left.height;return eO))return h;let l=t==K.ByPosNoHeight?K.ByPosNoHeight:K.ByPos;return a?h.join(this.right.lineAt(O,l,n,o,O)):this.left.lineAt(O,l,n,r,s).join(h)}forEachLine(e,t,n,r,s,o){let O=r+this.left.height,a=s+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,n,O,a,o);else{let h=this.lineAt(a,K.ByPos,n,r,s);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,n,O,a,o)}}replace(e,t,n){let r=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let s=[];e>0&&this.decomposeLeft(e,s);let o=s.length;for(let O of n)s.push(O);if(e>0&&bl(s,o-1),t=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e2*t.size||t.size>2*e.size?Ze.of(this.break?[e,null,t]:[e,t]):(this.left=mr(this.left,e),this.right=mr(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,n=!1,r){let{left:s,right:o}=this,O=t+s.length+this.break,a=null;return r&&r.from<=t+s.length&&r.more?a=s=s.updateHeight(e,t,n,r):s.updateHeight(e,t,n),r&&r.from<=O+o.length&&r.more?a=o=o.updateHeight(e,O,n,r):o.updateHeight(e,O,n),a?this.balanced(s,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function bl(i,e){let t,n;i[e]==null&&(t=i[e-1])instanceof zt&&(n=i[e+1])instanceof zt&&i.splice(e-1,3,new zt(t.length+1+n.length))}var sm=5,eo=class i{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 n=Math.min(t,this.lineEnd),r=this.nodes[this.nodes.length-1];r instanceof Ee?r.length+=n-this.pos:(n>this.pos||!this.isCovered)&&this.nodes.push(new Ee(n-this.pos,-1)),this.writtenTo=n,t>n&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e=sm)&&this.addLineDeco(r,s,o)}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 Ee(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let n=new zt(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ee)return e;let t=new Ee(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,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos=this.pos+n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ee)&&!this.isCovered?this.nodes.push(new Ee(0,-1)):(this.writtenTol.clientHeight||l.scrollWidth>l.clientWidth)&&c.overflow!="visible"){let f=l.getBoundingClientRect();s=Math.max(s,f.left),o=Math.min(o,f.right),O=Math.max(O,f.top),a=Math.min(h==i.parentNode?r.innerHeight:a,f.bottom)}h=c.position=="absolute"||c.position=="fixed"?l.offsetParent:l.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,o)-t.left,top:O-(t.top+e),bottom:Math.max(O,a)-(t.top+e)}}function am(i,e){let t=i.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var nn=class{constructor(e,t,n,r){this.from=e,this.to=t,this.size=n,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;ntypeof n!="function"&&n.class=="cm-lineWrapping");this.heightOracle=new Hs(t),this.stateDeco=e.facet(cn).filter(n=>typeof n!="function"),this.heightMap=Ze.empty().applyChanges(this.stateDeco,Y.empty,this.heightOracle.setDoc(e.doc),[new Ot(0,0,0,e.doc.length)]);for(let n=0;n<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());n++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=j.set(this.lineGaps.map(n=>n.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:s,to:o})=>r>=s&&r<=o)){let{from:s,to:o}=this.lineBlockAt(r);e.push(new yi(s,o))}}return this.viewports=e.sort((n,r)=>n.from-r.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?xl:new no(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(Fi(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=this.state.facet(cn).filter(l=>typeof l!="function");let r=e.changedRanges,s=Ot.extendWithRanges(r,om(n,this.stateDeco,e?e.changes:me.empty(this.state.doc.length))),o=this.heightMap.height,O=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Pl(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=o||xi)&&(e.flags|=2),O?(this.scrollAnchorPos=e.changes.mapPos(O.from,-1),this.scrollAnchorHeight=O.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.heada.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Oh)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,s=n.whiteSpace;this.defaultTextDirection=n.direction=="rtl"?J.RTL:J.LTR;let o=this.heightOracle.mustRefreshForWrapping(s),O=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=O.height;this.contentDOMHeight=O.height,this.mustMeasureContent=!1;let h=0,l=0;if(O.width&&O.height){let{scaleX:k,scaleY:y}=Vl(t,O);(k>.005&&Math.abs(this.scaleX-k)>.005||y>.005&&Math.abs(this.scaleY-y)>.005)&&(this.scaleX=k,this.scaleY=y,h|=8,o=a=!0)}let c=(parseInt(n.paddingTop)||0)*this.scaleY,f=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=f)&&(this.paddingTop=c,this.paddingBottom=f,h|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Ul(e.scrollDOM);let p=(this.printing?am:Om)(t,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let $=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if($!=this.inView&&(this.inView=$,$&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let Q=O.width;if((this.contentDOMWidth!=Q||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=O.width,this.editorHeight=e.scrollDOM.clientHeight,h|=8),a){let k=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(k)&&(o=!0),o||r.lineWrapping&&Math.abs(Q-this.contentDOMWidth)>r.charWidth){let{lineHeight:y,charWidth:w,textHeight:T}=e.docView.measureTextSize();o=y>0&&r.refresh(s,y,w,T,Q/w,k),o&&(e.docView.minWidth=0,h|=8)}m>0&&g>0?l=Math.max(m,g):m<0&&g<0&&(l=Math.min(m,g)),Pl();for(let y of this.viewports){let w=y.from==this.viewport.from?k:e.docView.measureVisibleLineHeights(y);this.heightMap=(o?Ze.empty().applyChanges(this.stateDeco,Y.empty,this.heightOracle,[new Ot(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,o,new Ks(y.from,w))}xi&&(h|=2)}let b=!this.viewportIsAppropriate(this.viewport,l)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return b&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(l,this.scrollTarget),h|=this.updateForViewport()),(h&2||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,s=this.heightOracle,{visibleTop:o,visibleBottom:O}=this,a=new yi(r.lineAt(o-n*1e3,K.ByHeight,s,0,0).from,r.lineAt(O+(1-n)*1e3,K.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(ha.to){let l=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=r.lineAt(h,K.ByPos,s,0,0),f;t.y=="center"?f=(c.top+c.bottom)/2-l/2:t.y=="start"||t.y=="nearest"&&h=O+Math.max(10,Math.min(n,250)))&&r>o-2*1e3&&s>1,o=r<<1;if(this.defaultTextDirection!=J.LTR&&!n)return[];let O=[],a=(l,c,f,d)=>{if(c-ll&&$$.from>=f.from&&$.to<=f.to&&Math.abs($.from-l)$.fromQ));if(!g){if(cb.from<=c&&b.to>=c)){let b=t.moveToLineBoundary(S.cursor(c),!1,!0).head;b>l&&(c=b)}let $=this.gapSize(f,l,c,d),Q=n||$<2e6?$:2e6;g=new nn(l,c,$,Q)}O.push(g)},h=l=>{if(l.length2e6)for(let w of e)w.from>=l.from&&w.froml.from&&a(l.from,d,l,c),pt.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];F.spans(e,this.viewport.from,this.viewport.to,{span(r,s){t.push({from:r,to:s})},point(){}},20);let n=t.length!=this.visibleRanges.length||this.visibleRanges.some((r,s)=>r.from!=t[s].from||r.to!=t[s].to);return this.visibleRanges=t,n?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Fi(this.heightMap.lineAt(e,K.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Fi(this.heightMap.lineAt(this.scaler.fromDOM(e),K.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Fi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},yi=class{constructor(e,t){this.from=e,this.to=t}};function lm(i,e,t){let n=[],r=i,s=0;return F.spans(t,i,e,{span(){},point(o,O){o>r&&(n.push({from:r,to:o}),s+=o-r),r=O}},20),r=1)return e[e.length-1].to;let n=Math.floor(i*t);for(let r=0;;r++){let{from:s,to:o}=e[r],O=o-s;if(n<=O)return s+n;n-=O}}function er(i,e){let t=0;for(let{from:n,to:r}of i.ranges){if(e<=r){t+=e-n;break}t+=r-n}return t/i.total}function hm(i,e){for(let t of i)if(e(t))return t}var xl={toDOM(i){return i},fromDOM(i){return i},scale:1,eq(i){return i==this}},no=class i{constructor(e,t,n){let r=0,s=0,o=0;this.viewports=n.map(({from:O,to:a})=>{let h=t.lineAt(O,K.ByPos,e,0,0).top,l=t.lineAt(a,K.ByPos,e,0,0).bottom;return r+=l-h,{from:O,to:a,top:h,bottom:l,domTop:0,domBottom:0}}),this.scale=(7e6-r)/(t.height-r);for(let O of this.viewports)O.domTop=o+(O.top-s)*this.scale,o=O.domBottom=O.domTop+(O.bottom-O.top),s=O.bottom}toDOM(e){for(let t=0,n=0,r=0;;t++){let s=tt.from==e.viewports[n].from&&t.to==e.viewports[n].to):!1}};function Fi(i,e){if(e.scale==1)return i;let t=e.toDOM(i.top),n=e.toDOM(i.bottom);return new st(i.from,i.length,t,n-t,Array.isArray(i._content)?i._content.map(r=>Fi(r,e)):i._content)}var tr=W.define({combine:i=>i.join(" ")}),ro=W.define({combine:i=>i.indexOf(!0)>-1}),so=je.newName(),wh=je.newName(),Th=je.newName(),vh={"&light":"."+wh,"&dark":"."+Th};function oo(i,e,t){return new je(e,{finish(n){return/&/.test(n)?n.replace(/&\w*/,r=>{if(r=="&")return i;if(!t||!t[r])throw new RangeError(`Unsupported selector: ${r}`);return t[r]}):i+" "+n}})}var cm=oo("."+so,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},vh),fm={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Ws=z.ie&&z.ie_version<=11,Oo=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Zs,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let n of t)this.queue.push(n);(z.ie&&z.ie_version<=11||z.ios&&e.composing)&&t.some(n=>n.type=="childList"&&n.removedNodes.length||n.type=="characterData"&&n.oldValue.length>n.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&e.constructor.EDIT_CONTEXT!==!1&&!(z.chrome&&z.chrome_version<126)&&(this.editContext=new ao(e),e.state.facet(Tt)&&(e.contentDOM.editContext=this.editContext.editContext)),Ws&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(Tt)?n.root.activeElement!=this.dom:!nr(this.dom,r))return;let s=r.anchorNode&&n.docView.nearest(r.anchorNode);if(s&&s.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(z.ie&&z.ie_version<=11||z.android&&z.chrome)&&!n.state.selection.main.empty&&r.focusNode&&Ki(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=sn(e.root);if(!t)return!1;let n=z.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&um(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=nr(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&bi(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(r)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let s of e){let o=this.readMutation(s);o&&(o.typeOver&&(r=!0),t==-1?{from:t,to:n}=o:(t=Math.min(o.from,t),n=Math.max(o.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&nr(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new Is(this.view,e,t,n);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let n=this.view.state,r=gh(this.view,t);return this.view.state==n&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),r}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let n=kl(t,e.previousSibling||e.target.previousSibling,-1),r=kl(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Tt)!=e.state.facet(Tt)&&(e.view.contentDOM.editContext=e.state.facet(Tt)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(n=this.resizeScroll)===null||n===void 0||n.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function kl(i,e,t){for(;e;){let n=H.get(e);if(n&&n.parent==i)return n;let r=e.parentNode;e=r!=i.dom?r:t>0?e.nextSibling:e.previousSibling}return null}function wl(i,e){let t=e.startContainer,n=e.startOffset,r=e.endContainer,s=e.endOffset,o=i.docView.domAtPos(i.state.selection.main.anchor);return Ki(o.node,o.offset,r,s)&&([t,n,r,s]=[r,s,t,n]),{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:s}}function um(i,e){if(e.getComposedRanges){let r=e.getComposedRanges(i.root)[0];if(r)return wl(i,r)}let t=null;function n(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return i.contentDOM.addEventListener("beforeinput",n,!0),i.dom.ownerDocument.execCommand("indent"),i.contentDOM.removeEventListener("beforeinput",n,!0),t?wl(i,t):null}var ao=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let{anchor:r}=e.state.selection.main,s={from:this.toEditorPos(n.updateRangeStart),to:this.toEditorPos(n.updateRangeEnd),insert:Y.of(n.text.split(`
-`))};s.from==this.from&&rthis.to&&(s.to=r),!(s.from==s.to&&!s.insert.length)&&(this.pendingContextChange=s,e.state.readOnly||bo(e,s,S.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd))),this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)))},this.handlers.characterboundsupdate=n=>{let r=[],s=null;for(let o=this.toEditorPos(n.rangeStart),O=this.toEditorPos(n.rangeEnd);o{let r=[];for(let s of n.getTextFormats()){let o=s.underlineStyle,O=s.underlineThickness;if(o!="None"&&O!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${O=="Thin"?1:2}px`;r.push(j.mark({attributes:{style:a}}).range(this.toEditorPos(s.rangeStart),this.toEditorPos(s.rangeEnd)))}}e.dispatch({effects:lh.of(j.set(r))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{e.inputState.composing=-1,e.inputState.compositionFirstChange=null};for(let n in this.handlers)t.addEventListener(n,this.handlers[n]);this.measureReq={read:n=>{this.editContext.updateControlBounds(n.contentDOM.getBoundingClientRect());let r=sn(n.root);r&&r.rangeCount&&this.editContext.updateSelectionBounds(r.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((s,o,O,a,h)=>{if(n)return;let l=h.length-(o-s);if(r&&o>=r.to)if(r.from==s&&r.to==o&&r.insert.eq(h)){r=this.pendingContextChange=null,t+=l,this.to+=l;return}else r=null,this.revertPending(e.state);if(s+=t,o+=t,o<=this.from)this.from+=l,this.to+=l;else if(sthis.to||this.to-this.from+h.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(o),h.toString()),this.to+=l}t+=l}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange;!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.resetRange(e.state),this.editContext.updateText(0,this.editContext.text.length,e.state.doc.sliceString(this.from,this.to)),this.setSelection(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to1e4*3)}toEditorPos(e){return e+this.from}toContextPos(e){return e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},v=class i{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:n}=e;this.dispatchTransactions=e.dispatchTransactions||n&&(r=>r.forEach(s=>n(s,this)))||(r=>this.update(r)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Op(e.parent)||document,this.viewState=new $r(e.state||I.create(e)),e.scrollTo&&e.scrollTo.is(Fn)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ii).map(r=>new tn(r));for(let r of this.plugins)r.update(this);this.observer=new Oo(this),this.inputState=new Bs(this),this.inputState.ensureHandlers(this.plugins),this.docView=new dr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...e){let t=e.length==1&&e[0]instanceof ne?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,n=!1,r,s=this.state;for(let f of e){if(f.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=f.state}if(this.destroyed){this.viewState.state=s;return}let o=this.hasFocus,O=0,a=null;e.some(f=>f.annotation(bh))?(this.inputState.notifiedFocused=o,O=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=xh(s,o),a||(O=1));let h=this.observer.delayedAndroidKey,l=null;if(h?(this.observer.clearDelayedAndroidKey(),l=this.observer.readChange(),(l&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(l=null)):this.observer.clear(),s.facet(I.phrases)!=this.state.facet(I.phrases))return this.setState(s);r=ur.create(this,s,e),r.flags|=O;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(c&&(c=c.map(f.changes)),f.scrollIntoView){let{main:d}=f.state.selection;c=new en(d.empty?d:S.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of f.effects)d.is(Fn)&&(c=d.value.clip(this.state))}this.viewState.update(r,c),this.bidiCache=Qr.update(this.bidiCache,r.changes),r.empty||(this.updatePlugins(r),this.inputState.update(r)),t=this.docView.update(r),this.state.facet(Bi)!=this.styleModules&&this.mountStyles(),n=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(r.startState.facet(tr)!=r.state.facet(tr)&&(this.viewState.mustMeasureContent=!0),(t||n||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!r.empty)for(let f of this.state.facet(Ms))try{f(r)}catch(d){Me(this.state,d,"update listener")}(a||l)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),l&&!gh(this,l)&&h.force&&bi(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let n of this.plugins)n.destroy(this);this.viewState=new $r(e),this.plugins=e.facet(Ii).map(n=>new tn(n)),this.pluginMap.clear();for(let n of this.plugins)n.update(this);this.docView.destroy(),this.docView=new dr(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ii),n=e.state.facet(Ii);if(t!=n){let r=[];for(let s of n){let o=t.indexOf(s);if(o<0)r.push(new tn(s));else{let O=this.plugins[o];O.mustUpdate=e,r.push(O)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let r of this.plugins)r.mustUpdate=e;for(let r=0;r-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.scrollDOM,r=n.scrollTop*this.scaleY,{scrollAnchorPos:s,scrollAnchorHeight:o}=this.viewState;Math.abs(r-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let O=0;;O++){if(o<0)if(Ul(n))s=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(r);s=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(O>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let l=h.map(d=>{try{return d.read(this)}catch(p){return Me(this.state,p),Tl}}),c=ur.create(this,this.state,[]),f=!1;c.flags|=a,t?t.flags|=a:t=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),f=this.docView.update(c),f&&this.docViewUpdate());for(let d=0;d1||p<-1){r=r+p,n.scrollTop=r/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let O of this.state.facet(Ms))O(t)}get themeClasses(){return so+" "+(this.state.facet(ro)?Th:wh)+" "+this.state.facet(tr)}updateAttrs(){let e=vl(this,hh,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Tt)?"true":"false",class:"cm-content",style:`${z.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),vl(this,yo,t);let n=this.observer.ignore(()=>{let r=Us(this.contentDOM,this.contentAttrs,t),s=Us(this.dom,this.editorAttrs,e);return r||s});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(e){let t=!0;for(let n of e)for(let r of n.effects)if(r.is(i.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=r.value}}mountStyles(){this.styleModules=this.state.facet(Bi);let e=this.state.facet(i.cspNonce);je.mount(this.root,this.styleModules.concat(cm).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;tn.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return zs(this,e,cl(this,e,t,n))}moveByGroup(e,t){return zs(this,e,cl(this,e,t,n=>Yp(this,e.head,n)))}visualLineSide(e,t){let n=this.bidiSpans(e),r=this.textDirectionAt(e.from),s=n[t?n.length-1:0];return S.cursor(s.side(t,r)+e.from,s.forward(!t,r)?1:-1)}moveToLineBoundary(e,t,n=!0){return Cp(this,e,t,n)}moveVertically(e,t,n){return zs(this,e,Up(this,e,t,n))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),mh(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.docView.coordsAt(e,t);if(!n||n.left==n.right)return n;let r=this.state.doc.lineAt(e),s=this.bidiSpans(r),o=s[ot.find(s,e-r.from,-1,t)];return Pr(n,o.dir==J.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(oh)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>dm)return Kl(e.length);let t=this.textDirectionAt(e.from),n;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||Hl(s.isolates,n=ol(this,e))))return s.order;n||(n=ol(this,e));let r=Sp(e.text,t,n);return this.bidiCache.push(new Qr(e.from,e.to,t,n,!0,r)),r}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||z.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Cl(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Fn.of(new en(typeof e=="number"?S.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return Fn.of(new en(S.cursor(n.from),"start","start",n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Ge.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Ge.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=je.newName(),r=[tr.of(n),Bi.of(oo(`.${n}`,e))];return t&&t.dark&&r.push(ro.of(!0)),r}static baseTheme(e){return nt.lowest(Bi.of(oo("."+so,e,vh)))}static findFromDOM(e){var t;let n=e.querySelector(".cm-content"),r=n&&H.get(n)||H.get(e);return((t=r?.rootView)===null||t===void 0?void 0:t.view)||null}};v.styleModule=Bi;v.inputHandler=rh;v.clipboardInputFilter=Qo;v.clipboardOutputFilter=So;v.scrollHandler=ah;v.focusChangeEffect=sh;v.perLineTextDirection=oh;v.exceptionSink=nh;v.updateListener=Ms;v.editable=Tt;v.mouseSelectionStyle=ih;v.dragMovesSelection=th;v.clickAddsSelectionRange=eh;v.decorations=cn;v.outerDecorations=ch;v.atomicRanges=Po;v.bidiIsolatedRanges=fh;v.scrollMargins=uh;v.darkTheme=ro;v.cspNonce=W.define({combine:i=>i.length?i[0]:""});v.contentAttributes=yo;v.editorAttributes=hh;v.lineWrapping=v.contentAttributes.of({class:"cm-lineWrapping"});v.announce=D.define();var dm=4096,Tl={},Qr=class i{constructor(e,t,n,r,s,o){this.from=e,this.to=t,this.dir=n,this.isolates=r,this.fresh=s,this.order=o}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let n=[],r=e.length?e[e.length-1].dir:J.LTR;for(let s=Math.max(0,e.length-10);s=0;r--){let s=n[r],o=typeof s=="function"?s(i):s;o&&Ys(o,t)}return t}var pm=z.mac?"mac":z.windows?"win":z.linux?"linux":"key";function mm(i,e){let t=i.split(/-(?!$)/),n=t[t.length-1];n=="Space"&&(n=" ");let r,s,o,O;for(let a=0;an.concat(r),[]))),t}var vt=null,Qm=4e3;function Sm(i,e=pm){let t=Object.create(null),n=Object.create(null),r=(o,O)=>{let a=n[o];if(a==null)n[o]=O;else if(a!=O)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},s=(o,O,a,h,l)=>{var c,f;let d=t[o]||(t[o]=Object.create(null)),p=O.split(/ (?!$)/).map($=>mm($,e));for(let $=1;${let k=vt={view:b,prefix:Q,scope:o};return setTimeout(()=>{vt==k&&(vt=null)},Qm),!0}]})}let m=p.join(" ");r(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((f=(c=d._any)===null||c===void 0?void 0:c.run)===null||f===void 0?void 0:f.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),l&&(g.stopPropagation=!0)};for(let o of i){let O=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of O){let l=t[h]||(t[h]=Object.create(null));l._any||(l._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let f in l)l[f].run.push(d=>c(d,lo))}let a=o[e]||o.key;if(a)for(let h of O)s(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&s(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}var lo=null;function ym(i,e,t,n){lo=e;let r=Ka(e),s=pi(r,0),o=Mi(s)==r.length&&r!=" ",O="",a=!1,h=!1,l=!1;vt&&vt.view==t&&vt.scope==n&&(O=vt.prefix+" ",Qh.indexOf(e.keyCode)<0&&(h=!0,vt=null));let c=new Set,f=g=>{if(g){for(let $ of g.run)if(!c.has($)&&(c.add($),$(t)))return g.stopPropagation&&(l=!0),!0;g.preventDefault&&(g.stopPropagation&&(l=!0),h=!0)}return!1},d=i[n],p,m;return d&&(f(d[O+ir(r,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(z.windows&&e.ctrlKey&&e.altKey)&&(p=gt[e.keyCode])&&p!=r?(f(d[O+ir(p,e,!0)])||e.shiftKey&&(m=Qi[e.keyCode])!=r&&m!=p&&f(d[O+ir(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&f(d[O+ir(r,e,!0)])&&(a=!0),!a&&f(d._any)&&(a=!0)),h&&(a=!0),a&&l&&e.stopPropagation(),lo=null,a}var fn=class i{constructor(e,t,n,r,s){this.className=e,this.left=t,this.top=n,this.width=r,this.height=s}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,n){if(n.empty){let r=e.coordsAtPos(n.head,n.assoc||1);if(!r)return[];let s=zh(e);return[new i(t,r.left-s.left,r.top-s.top,null,r.bottom-r.top)]}else return Pm(e,t,n)}};function zh(i){let e=i.scrollDOM.getBoundingClientRect();return{left:(i.textDirection==J.LTR?e.left:e.right-i.scrollDOM.clientWidth*i.scaleX)-i.scrollDOM.scrollLeft*i.scaleX,top:e.top-i.scrollDOM.scrollTop*i.scaleY}}function Wl(i,e,t,n){let r=i.coordsAtPos(e,t*2);if(!r)return n;let s=i.dom.getBoundingClientRect(),o=(r.top+r.bottom)/2,O=i.posAtCoords({x:s.left+1,y:o}),a=i.posAtCoords({x:s.right-1,y:o});return O==null||a==null?n:{from:Math.max(n.from,Math.min(O,a)),to:Math.min(n.to,Math.max(O,a))}}function Pm(i,e,t){if(t.to<=i.viewport.from||t.from>=i.viewport.to)return[];let n=Math.max(t.from,i.viewport.from),r=Math.min(t.to,i.viewport.to),s=i.textDirection==J.LTR,o=i.contentDOM,O=o.getBoundingClientRect(),a=zh(i),h=o.querySelector(".cm-line"),l=h&&window.getComputedStyle(h),c=O.left+(l?parseInt(l.paddingLeft)+Math.min(0,parseInt(l.textIndent)):0),f=O.right-(l?parseInt(l.paddingRight):0),d=Ls(i,n),p=Ls(i,r),m=d.type==Qe.Text?d:null,g=p.type==Qe.Text?p:null;if(m&&(i.lineWrapping||d.widgetLineBreaks)&&(m=Wl(i,n,1,m)),g&&(i.lineWrapping||p.widgetLineBreaks)&&(g=Wl(i,r,-1,g)),m&&g&&m.from==g.from&&m.to==g.to)return Q(b(t.from,t.to,m));{let y=m?b(t.from,null,m):k(d,!1),w=g?b(null,t.to,g):k(p,!0),T=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&y.bottom+i.defaultLineHeight/2q&&M.from=be)break;se>te&&C(Math.max(Ue,te),y==null&&Ue<=q,Math.min(se,be),w==null&&se>=B,Re.dir)}if(te=xe.to+1,te>=be)break}return A.length==0&&C(q,y==null,B,w==null,i.textDirection),{top:E,bottom:U,horizontal:A}}function k(y,w){let T=O.top+(w?y.top:y.bottom);return{top:T,bottom:T,horizontal:[]}}}function bm(i,e){return i.constructor==e.constructor&&i.eq(e)}var ho=class{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(or)!=e.state.facet(or)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,n=e.facet(or);for(;t!bm(t,this.drawn[n]))){let t=this.dom.firstChild,n=0;for(let r of e)r.update&&t&&r.constructor&&this.drawn[n].constructor&&r.update(t,this.drawn[n])?(t=t.nextSibling,n++):this.dom.insertBefore(r.draw(),t);for(;t;){let r=t.nextSibling;t.remove(),t=r}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},or=W.define();function Wh(i){return[Ge.define(e=>new ho(e,i)),or.of(i)]}var Rh=!z.ios,un=W.define({combine(i){return wt(i,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Xh(i={}){return[un.of(i),xm,km,wm,Oh.of(!0)]}function Zh(i){return i.startState.facet(un)!=i.state.facet(un)}var xm=Wh({above:!0,markers(i){let{state:e}=i,t=e.facet(un),n=[];for(let r of e.selection.ranges){let s=r==e.selection.main;if(r.empty?!s||Rh:t.drawRangeCursor){let o=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",O=r.empty?r:S.cursor(r.head,r.head>r.anchor?-1:1);for(let a of fn.forRange(i,o,O))n.push(a)}}return n},update(i,e){i.transactions.some(n=>n.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Zh(i);return t&&Rl(i.state,e),i.docChanged||i.selectionSet||t},mount(i,e){Rl(e.state,i)},class:"cm-cursorLayer"});function Rl(i,e){e.style.animationDuration=i.facet(un).cursorBlinkRate+"ms"}var km=Wh({above:!1,markers(i){return i.state.selection.ranges.map(e=>e.empty?[]:fn.forRange(i,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(i,e){return i.docChanged||i.selectionSet||i.viewportChanged||Zh(i)},class:"cm-selectionLayer"}),co={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};Rh&&(co[".cm-line"].caretColor=co[".cm-content"].caretColor="transparent !important");var wm=nt.highest(v.theme(co)),qh=D.define({map(i,e){return i==null?null:e.mapPos(i)}}),Hi=ge.define({create(){return null},update(i,e){return i!=null&&(i=e.changes.mapPos(i)),e.effects.reduce((t,n)=>n.is(qh)?n.value:t,i)}}),Tm=Ge.fromClass(class{constructor(i){this.view=i,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(i){var e;let t=i.state.field(Hi);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(i.startState.field(Hi)!=t||i.docChanged||i.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:i}=this,e=i.state.field(Hi),t=e!=null&&i.coordsAtPos(e);if(!t)return null;let n=i.scrollDOM.getBoundingClientRect();return{left:t.left-n.left+i.scrollDOM.scrollLeft*i.scaleX,top:t.top-n.top+i.scrollDOM.scrollTop*i.scaleY,height:t.bottom-t.top}}drawCursor(i){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;i?(this.cursor.style.left=i.left/e+"px",this.cursor.style.top=i.top/t+"px",this.cursor.style.height=i.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(i){this.view.state.field(Hi)!=i&&this.view.dispatch({effects:qh.of(i)})}},{eventObservers:{dragover(i){this.setDropPos(this.view.posAtCoords({x:i.clientX,y:i.clientY}))},dragleave(i){(i.target==this.view.contentDOM||!this.view.contentDOM.contains(i.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Vh(){return[Hi,Tm]}var RP=/x/.unicode!=null?"gu":"g";function xo(){return zm}var vm=j.line({class:"cm-activeLine"}),zm=Ge.fromClass(class{constructor(i){this.decorations=this.getDeco(i)}update(i){(i.docChanged||i.selectionSet)&&(this.decorations=this.getDeco(i.view))}getDeco(i){let e=-1,t=[];for(let n of i.state.selection.ranges){let r=i.lineBlockAt(n.head);r.from>e&&(t.push(vm.range(r.from)),e=r.from)}return j.set(t)}},{decorations:i=>i.decorations});var fo=2e3;function Wm(i,e,t){let n=Math.min(e.line,t.line),r=Math.max(e.line,t.line),s=[];if(e.off>fo||t.off>fo||e.col<0||t.col<0){let o=Math.min(e.off,t.off),O=Math.max(e.off,t.off);for(let a=n;a<=r;a++){let h=i.doc.line(a);h.length<=O&&s.push(S.range(h.from+o,h.to+O))}}else{let o=Math.min(e.col,t.col),O=Math.max(e.col,t.col);for(let a=n;a<=r;a++){let h=i.doc.line(a),l=In(h.text,o,i.tabSize,!0);if(l<0)s.push(S.cursor(h.to));else{let c=In(h.text,O,i.tabSize);s.push(S.range(h.from+l,h.from+c))}}}return s}function Rm(i,e){let t=i.coordsAtPos(i.viewport.from);return t?Math.round(Math.abs((t.left-e)/i.defaultCharacterWidth)):-1}function Xl(i,e){let t=i.posAtCoords({x:e.clientX,y:e.clientY},!1),n=i.state.doc.lineAt(t),r=t-n.from,s=r>fo?-1:r==n.length?Rm(i,e.clientX):we(n.text,i.state.tabSize,t-n.from);return{line:n.number,col:s,off:r}}function Xm(i,e){let t=Xl(i,e),n=i.state.selection;return t?{update(r){if(r.docChanged){let s=r.changes.mapPos(r.startState.doc.line(t.line).from),o=r.state.doc.lineAt(s);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},n=n.map(r.changes)}},get(r,s,o){let O=Xl(i,r);if(!O)return n;let a=Wm(i.state,t,O);return a.length?o?S.create(a.concat(n.ranges)):S.create(a):n}}:null}function Ch(i){let e=i?.eventFilter||(t=>t.altKey&&t.button==0);return v.mouseSelectionStyle.of((t,n)=>e(n)?Xm(t,n):null)}var XP=v.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}});var He=class extends Ne{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};He.prototype.elementClass="";He.prototype.toDOM=void 0;He.prototype.mapMode=ae.TrackBefore;He.prototype.startSide=He.prototype.endSide=-1;He.prototype.point=!0;var Or=W.define(),Zm=W.define();var ar=W.define();var uo=W.define({combine:i=>i.some(e=>e)});function qm(i){let e=[Vm];return i&&i.fixed===!1&&e.push(uo.of(!0)),e}var Vm=Ge.fromClass(class{constructor(i){this.view=i,this.prevViewport=i.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=i.state.facet(ar).map(e=>new Sr(i,e));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!i.state.facet(uo),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),i.scrollDOM.insertBefore(this.dom,i.contentDOM)}update(i){if(this.updateGutters(i)){let e=this.prevViewport,t=i.view.viewport,n=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(n<(t.to-t.from)*.8)}i.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(uo)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=i.view.viewport}syncGutters(i){let e=this.dom.nextSibling;i&&this.dom.remove();let t=F.iter(this.view.state.facet(Or),this.view.viewport.from),n=[],r=this.gutters.map(s=>new mo(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(n.length&&(n=[]),Array.isArray(s.type)){let o=!0;for(let O of s.type)if(O.type==Qe.Text&&o){po(t,n,O.from);for(let a of r)a.line(this.view,O,n);o=!1}else if(O.widget)for(let a of r)a.widget(this.view,O)}else if(s.type==Qe.Text){po(t,n,s.from);for(let o of r)o.line(this.view,s,n)}else if(s.widget)for(let o of r)o.widget(this.view,s);for(let s of r)s.finish();i&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(i){let e=i.startState.facet(ar),t=i.state.facet(ar),n=i.docChanged||i.heightChanged||i.viewportChanged||!F.eq(i.startState.facet(Or),i.state.facet(Or),i.view.viewport.from,i.view.viewport.to);if(e==t)for(let r of this.gutters)r.update(i)&&(n=!0);else{n=!0;let r=[];for(let s of t){let o=e.indexOf(s);o<0?r.push(new Sr(this.view,s)):(this.gutters[o].update(i),r.push(this.gutters[o]))}for(let s of this.gutters)s.dom.remove(),r.indexOf(s)<0&&s.destroy();for(let s of r)this.dom.appendChild(s.dom);this.gutters=r}return n}destroy(){for(let i of this.gutters)i.destroy();this.dom.remove()}},{provide:i=>v.scrollMargins.of(e=>{let t=e.plugin(i);return!t||t.gutters.length==0||!t.fixed?null:e.textDirection==J.LTR?{left:t.dom.offsetWidth*e.scaleX}:{right:t.dom.offsetWidth*e.scaleX}})});function Zl(i){return Array.isArray(i)?i:[i]}function po(i,e,t){for(;i.value&&i.from<=t;)i.from==t&&e.push(i.value),i.next()}var mo=class{constructor(e,t,n){this.gutter=e,this.height=n,this.i=0,this.cursor=F.iter(e.markers,t.from)}addElement(e,t,n){let{gutter:r}=this,s=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==r.elements.length){let O=new yr(e,o,s,n);r.elements.push(O),r.dom.appendChild(O.dom)}else r.elements[this.i].update(e,o,s,n);this.height=t.bottom,this.i++}line(e,t,n){let r=[];po(this.cursor,r,t.from),n.length&&(r=r.concat(n));let s=this.gutter.config.lineMarker(e,t,r);s&&r.unshift(s);let o=this.gutter;r.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,r)}widget(e,t){let n=this.gutter.config.widgetMarker(e,t.widget,t),r=n?[n]:null;for(let s of e.state.facet(Zm)){let o=s(e,t.widget,t);o&&(r||(r=[])).push(o)}r&&this.addElement(e,t,r)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Sr=class{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let n in t.domEventHandlers)this.dom.addEventListener(n,r=>{let s=r.target,o;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let a=s.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=r.clientY;let O=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[n](e,O,r)&&r.preventDefault()});this.markers=Zl(t.markers(e)),t.initialSpacer&&(this.spacer=new yr(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Zl(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let r=this.config.updateSpacer(this.spacer.markers[0],e);r!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[r])}let n=e.view.viewport;return!F.eq(this.markers,t,n.from,n.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},yr=class{constructor(e,t,n,r){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,n,r)}update(e,t,n,r){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=n&&(this.dom.style.marginTop=(this.above=n)?n+"px":""),Cm(this.markers,r)||this.setMarkers(e,r)}setMarkers(e,t){let n="cm-gutterElement",r=this.dom.firstChild;for(let s=0,o=0;;){let O=o,a=ss(O,a,h)||o(O,a,h):o}return n}})}}),rn=class extends He{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Rs(i,e){return i.state.facet(Pi).formatNumber(e,i.state)}var Am=ar.compute([Pi],i=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(Ym)},lineMarker(e,t,n){return n.some(r=>r.toDOM)?null:new rn(Rs(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,n)=>{for(let r of e.state.facet(Um)){let s=r(e,t,n);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Pi)!=e.state.facet(Pi),initialSpacer(e){return new rn(Rs(e,ql(e.state.doc.lines)))},updateSpacer(e,t){let n=Rs(t.view,ql(t.view.state.doc.lines));return n==e.number?e:new rn(n)},domEventHandlers:i.facet(Pi).domEventHandlers}));function Yh(i={}){return[Pi.of(i),qm(),Am]}function ql(i){let e=9;for(;e{let e=[],t=-1;for(let n of i.selection.ranges){let r=i.doc.lineAt(n.head).from;r>t&&(t=r,e.push(_m.range(r)))}return F.of(e)});function ko(){return jm}async function Uh(i){if(window.isSecureContext&&navigator.clipboard){await navigator.clipboard.writeText(i);return}let e=document.createElement("textarea");e.setAttribute("style","position: absolute; left: -1000px; top: -1000px;"),e.value=i,document.body.appendChild(e),e.select(),document.execCommand("copy"),document.body.removeChild(e)}var Em=0,ve=class{constructor(e,t){this.from=e,this.to=t}},Z=class{constructor(e={}){this.id=Em++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=ie.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};Z.closedBy=new Z({deserialize:i=>i.split(" ")});Z.openedBy=new Z({deserialize:i=>i.split(" ")});Z.group=new Z({deserialize:i=>i.split(" ")});Z.isolate=new Z({deserialize:i=>{if(i&&i!="rtl"&&i!="ltr"&&i!="auto")throw new RangeError("Invalid value for isolate: "+i);return i||"auto"}});Z.contextHash=new Z({perNode:!0});Z.lookAhead=new Z({perNode:!0});Z.mounted=new Z({perNode:!0});var ti=class{constructor(e,t,n){this.tree=e,this.overlay=t,this.parser=n}static get(e){return e&&e.props&&e.props[Z.mounted.id]}},Mm=Object.create(null),ie=class i{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(e){let t=e.props&&e.props.length?Object.create(null):Mm,n=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),r=new i(e.name||"",t,e.id,n);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(r)),s){if(s[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[s[0].id]=s[1]}}return r}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(Z.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(" "))t[r]=e[n];return n=>{for(let r=n.prop(Z.group),s=-1;s<(r?r.length:0);s++){let o=t[s<0?n.name:r[s]];if(o)return o}}}};ie.none=new ie("",Object.create(null),0,8);var $t=class i{constructor(e){this.types=e;for(let t=0;t0;for(let a=this.cursor(o|L.IncludeAnonymous);;){let h=!1;if(a.from<=s&&a.to>=r&&(!O&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&n&&(O||!a.type.isAnonymous)&&n(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Co(ie.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new i(this.type,t,n,r,this.propValues),e.makeTree||((t,n,r)=>new i(ie.none,t,n,r)))}static build(e){return Lm(e)}};V.empty=new V(ie.none,[],[],0);var wo=class i{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new i(this.buffer,this.index)}},qt=class i{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return ie.none}toString(){let e=[];for(let t=0;t0));a=o[a+3]);return O}slice(e,t,n){let r=this.buffer,s=new Uint16Array(t-e),o=0;for(let O=e,a=0;O=e&&te;case 1:return t<=e&&n>e;case 2:return n>e;case 4:return!0}}function dn(i,e,t,n){for(var r;i.from==i.to||(t<1?i.from>=e:i.from>e)||(t>-1?i.to<=e:i.to0?O.length:-1;e!=h;e+=t){let l=O[e],c=a[e]+o.from;if(Dh(r,n,c,c+l.length)){if(l instanceof qt){if(s&L.ExcludeBuffers)continue;let f=l.findChild(0,l.buffer.length,t,n-c,r);if(f>-1)return new ii(new vo(o,l,e,c),null,f)}else if(s&L.IncludeAnonymous||!l.type.isAnonymous||Vo(l)){let f;if(!(s&L.IgnoreMounts)&&(f=ti.get(l))&&!f.overlay)return new i(f.tree,c,e,o);let d=new i(l,c,e,o);return s&L.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?l.children.length-1:0,t,n,r)}}}if(s&L.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,n=0){let r;if(!(n&L.IgnoreOverlays)&&(r=ti.get(this._tree))&&r.overlay){let s=e-this.from;for(let{from:o,to:O}of r.overlay)if((t>0?o<=s:o=s:O>s))return new i(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,n)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function _h(i,e,t,n){let r=i.cursor(),s=[];if(!r.firstChild())return s;if(t!=null){for(let o=!1;!o;)if(o=r.type.is(t),!r.nextSibling())return s}for(;;){if(n!=null&&r.type.is(n))return s;if(r.type.is(e)&&s.push(r.node),!r.nextSibling())return n==null?s:[]}}function To(i,e,t=e.length-1){for(let n=i.parent;t>=0;n=n.parent){if(!n)return!1;if(!n.type.isAnonymous){if(e[t]&&e[t]!=n.name)return!1;t--}}return!0}var vo=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},ii=class i extends Tr{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(e,t,n){let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.context.start,n);return s<0?null:new i(this.context,this,s)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,n=0){if(n&L.ExcludeBuffers)return null;let{buffer:r}=this.context,s=r.findChild(this.index+4,r.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new i(this.context,this,s)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new i(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new i(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,s=n.buffer[this.index+3];if(s>r){let o=n.buffer[this.index+1];e.push(n.slice(r,s,o)),t.push(0)}return new V(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Ih(i){if(!i.length)return null;let e=0,t=i[0];for(let s=1;st.from||o.to=e){let O=new ze(o.tree,o.overlay[0].from+s.from,-1,s);(r||(r=[n])).push(dn(O,e,t,!1))}}return r?Ih(r):n}var ki=class{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof ze)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let n=e._parent;n;n=n._parent)this.stack.unshift(n.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof ze?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,s=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return s<0?!1:(this.stack.push(this.index),this.yieldBuf(s))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&L.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&L.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&L.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let r=n<0?0:this.stack[n]+4;if(this.index!=r)return this.yieldBuf(t.findChild(r,this.index,-1,0,4))}else{let r=t.buffer[this.index+3];if(r<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(r)}return n<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index-1)for(let s=t+e,o=e<0?-1:n._tree.children.length;s!=o;s+=e){let O=n._tree.children[s];if(this.mode&L.IncludeAnonymous||O instanceof qt||!O.type.isAnonymous||Vo(O))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to=0;){for(let o=e;o;o=o._parent)if(o.index==r){if(r==this.index)return o;t=o,n=s+1;break e}r=this.stack[--s]}for(let r=n;r=0;s--){if(s<0)return To(this.node,e,r);let o=n[t.buffer[this.stack[s]]];if(!o.isAnonymous){if(e[r]&&e[r]!=o.name)return!1;r--}}return!0}};function Vo(i){return i.children.some(e=>e instanceof qt||!e.type.isAnonymous||Vo(e))}function Lm(i){var e;let{buffer:t,nodeSet:n,maxBufferLength:r=1024,reused:s=[],minRepeatType:o=n.types.length}=i,O=Array.isArray(t)?new wo(t,t.length):t,a=n.types,h=0,l=0;function c(y,w,T,E,U,A){let{id:C,start:q,end:B,size:M}=O,te=l;for(;M<0;)if(O.next(),M==-1){let se=s[C];T.push(se),E.push(q-y);return}else if(M==-3){h=C;return}else if(M==-4){l=C;return}else throw new RangeError(`Unrecognized record size: ${M}`);let be=a[C],xe,Re,Ue=q-y;if(B-q<=r&&(Re=g(O.pos-w,U))){let se=new Uint16Array(Re.size-Re.skip),Ae=O.pos-Re.size,it=se.length;for(;O.pos>Ae;)it=$(Re.start,se,it);xe=new qt(se,B-Re.start,n),Ue=Re.start-y}else{let se=O.pos-M;O.next();let Ae=[],it=[],Lt=C>=o?C:-1,ci=0,Yn=B;for(;O.pos>se;)Lt>=0&&O.id==Lt&&O.size>=0?(O.end<=Yn-r&&(p(Ae,it,q,ci,O.end,Yn,Lt,te),ci=Ae.length,Yn=O.end),O.next()):A>2500?f(q,se,Ae,it):c(q,se,Ae,it,Lt,A+1);if(Lt>=0&&ci>0&&ci-1&&ci>0){let Ta=d(be);xe=Co(be,Ae,it,0,Ae.length,0,B-q,Ta,Ta)}else xe=m(be,Ae,it,B-q,te-B)}T.push(xe),E.push(Ue)}function f(y,w,T,E){let U=[],A=0,C=-1;for(;O.pos>w;){let{id:q,start:B,end:M,size:te}=O;if(te>4)O.next();else{if(C>-1&&B=0;M-=3)q[te++]=U[M],q[te++]=U[M+1]-B,q[te++]=U[M+2]-B,q[te++]=te;T.push(new qt(q,U[2]-B,n)),E.push(B-y)}}function d(y){return(w,T,E)=>{let U=0,A=w.length-1,C,q;if(A>=0&&(C=w[A])instanceof V){if(!A&&C.type==y&&C.length==E)return C;(q=C.prop(Z.lookAhead))&&(U=T[A]+C.length+q)}return m(y,w,T,E,U)}}function p(y,w,T,E,U,A,C,q){let B=[],M=[];for(;y.length>E;)B.push(y.pop()),M.push(w.pop()+T-U);y.push(m(n.types[C],B,M,A-U,q-A)),w.push(U-T)}function m(y,w,T,E,U=0,A){if(h){let C=[Z.contextHash,h];A=A?[C].concat(A):[C]}if(U>25){let C=[Z.lookAhead,U];A=A?[C].concat(A):[C]}return new V(y,w,T,E,A)}function g(y,w){let T=O.fork(),E=0,U=0,A=0,C=T.end-r,q={size:0,start:0,skip:0};e:for(let B=T.pos-y;T.pos>B;){let M=T.size;if(T.id==w&&M>=0){q.size=E,q.start=U,q.skip=A,A+=4,E+=4,T.next();continue}let te=T.pos-M;if(M<0||te=o?4:0,xe=T.start;for(T.next();T.pos>te;){if(T.size<0)if(T.size==-3)be+=4;else break e;else T.id>=o&&(be+=4);T.next()}U=xe,E+=M,A+=be}return(w<0||E==y)&&(q.size=E,q.start=U,q.skip=A),q.size>4?q:void 0}function $(y,w,T){let{id:E,start:U,end:A,size:C}=O;if(O.next(),C>=0&&E4){let B=O.pos-(C-4);for(;O.pos>B;)T=$(y,w,T)}w[--T]=q,w[--T]=A-y,w[--T]=U-y,w[--T]=E}else C==-3?h=E:C==-4&&(l=E);return T}let Q=[],b=[];for(;O.pos>0;)c(i.start||0,i.bufferStart||0,Q,b,-1,0);let k=(e=i.length)!==null&&e!==void 0?e:Q.length?b[0]+Q[0].length:0;return new V(a[i.topID],Q.reverse(),b.reverse(),k)}var jh=new WeakMap;function wr(i,e){if(!i.isAnonymous||e instanceof qt||e.type!=i)return 1;let t=jh.get(e);if(t==null){t=1;for(let n of e.children){if(n.type!=i||!(n instanceof V)){t=1;break}t+=wr(i,n)}jh.set(e,t)}return t}function Co(i,e,t,n,r,s,o,O,a){let h=0;for(let p=n;p=l)break;w+=T}if(b==k+1){if(w>l){let T=p[k];d(T.children,T.positions,0,T.children.length,m[k]+Q);continue}c.push(p[k])}else{let T=m[b-1]+p[b-1].length-y;c.push(Co(i,p,m,k,b,y,T,null,a))}f.push(y+Q-s)}}return d(e,t,n,r,0),(O||a)(c,f,o)}var wi=class{constructor(){this.map=new WeakMap}setBuffer(e,t,n){let r=this.map.get(e);r||this.map.set(e,r=new Map),r.set(t,n)}getBuffer(e,t){let n=this.map.get(e);return n&&n.get(t)}set(e,t){e instanceof ii?this.setBuffer(e.context.buffer,e.index,t):e instanceof ze&&this.map.set(e.tree,t)}get(e){return e instanceof ii?this.getBuffer(e.context.buffer,e.index):e instanceof ze?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}},Qt=class i{constructor(e,t,n,r,s=!1,o=!1){this.from=e,this.to=t,this.tree=n,this.offset=r,this.open=(s?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],n=!1){let r=[new i(0,e.length,e,0,!1,n)];for(let s of t)s.to>e.length&&r.push(s);return r}static applyChanges(e,t,n=128){if(!t.length)return e;let r=[],s=1,o=e.length?e[0]:null;for(let O=0,a=0,h=0;;O++){let l=O=n)for(;o&&o.from=f.from||c<=f.to||h){let d=Math.max(f.from,a)-h,p=Math.min(f.to,c)-h;f=d>=p?null:new i(d,p,f.tree,f.offset+h,O>0,!!l)}if(f&&r.push(f),o.to>c)break;o=snew ve(r.from,r.to)):[new ve(0,0)]:[new ve(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let r=this.startParse(e,t,n);for(;;){let s=r.advance();if(s)return s}}},Wo=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};function Ti(i){return(e,t,n,r)=>new Zo(e,i,t,n,r)}var vr=class{constructor(e,t,n,r,s){this.parser=e,this.parse=t,this.overlay=n,this.target=r,this.from=s}};function Eh(i){if(!i.length||i.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(i))}var Ro=class{constructor(e,t,n,r,s,o,O){this.parser=e,this.predicate=t,this.mounts=n,this.index=r,this.start=s,this.target=o,this.prev=O,this.depth=0,this.ranges=[]}},Xo=new Z({perNode:!0}),Zo=class{constructor(e,t,n,r,s){this.nest=t,this.input=n,this.fragments=r,this.ranges=s,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let n=this.baseParse.advance();if(!n)return null;if(this.baseParse=null,this.baseTree=n,this.startInner(),this.stoppedAt!=null)for(let r of this.inner)r.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let n=this.baseTree;return this.stoppedAt!=null&&(n=new V(n.type,n.children,n.positions,n.length,n.propValues.concat([[Xo,this.stoppedAt]]))),n}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let n=Object.assign(Object.create(null),e.target.props);n[Z.mounted.id]=new ti(t,e.overlay,e.parser),e.target.props=n}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t=this.stoppedAt)O=!1;else if(e.hasNode(r)){if(t){let h=t.mounts.find(l=>l.frag.from<=r.from&&l.frag.to>=r.to&&l.mount.overlay);if(h)for(let l of h.mount.overlay){let c=l.from+h.pos,f=l.to+h.pos;c>=r.from&&f<=r.to&&!t.ranges.some(d=>d.fromc)&&t.ranges.push({from:c,to:f})}}O=!1}else if(n&&(o=Dm(n.ranges,r.from,r.to)))O=o!=2;else if(!r.type.isAnonymous&&(s=this.nest(r,this.input))&&(r.fromnew ve(c.from-r.from,c.to-r.from)):null,r.tree,l.length?l[0].from:r.from)),s.overlay?l.length&&(n={ranges:l,depth:0,prev:n}):O=!1}}else t&&(a=t.predicate(r))&&(a===!0&&(a=new ve(r.from,r.to)),a.fromnew ve(l.from-t.start,l.to-t.start)),t.target,h[0].from))),t=t.prev}n&&!--n.depth&&(n=n.prev)}}}};function Dm(i,e,t){for(let n of i){if(n.from>=t)break;if(n.to>e)return n.from<=e&&n.to>=t?2:1}return 0}function Mh(i,e,t,n,r,s){if(e=e&&t.enter(n,1,L.IgnoreOverlays|L.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof V)t=t.children[0];else break}return!1}},qo=class{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let n=this.curFrag=e[0];this.curTo=(t=n.tree.prop(Xo))!==null&&t!==void 0?t:n.to,this.inner=new zr(n.tree,-n.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Xo))!==null&&e!==void 0?e:t.to,this.inner=new zr(t.tree,-t.offset)}}findMounts(e,t){var n;let r=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let s=this.inner.cursor.node;s;s=s.parent){let o=(n=s.tree)===null||n===void 0?void 0:n.prop(Z.mounted);if(o&&o.parser==t)for(let O=this.fragI;O=s.to)break;a.tree==this.curFrag.tree&&r.push({frag:a,pos:s.from-a.offset,mount:o})}}}return r}};function Gh(i,e){let t=null,n=e;for(let r=1,s=0;r=O)break;a.to<=o||(t||(n=t=e.slice()),a.fromO&&t.splice(s+1,0,new ve(O,a.to))):a.to>O?t[s--]=new ve(O,a.to):t.splice(s--,1))}}return n}function Bm(i,e,t,n){let r=0,s=0,o=!1,O=!1,a=-1e9,h=[];for(;;){let l=r==i.length?1e9:o?i[r].to:i[r].from,c=s==e.length?1e9:O?e[s].to:e[s].from;if(o!=O){let f=Math.max(a,t),d=Math.min(l,c,n);fnew ve(f.from+n,f.to+n)),c=Bm(e,l,a,h);for(let f=0,d=a;;f++){let p=f==c.length,m=p?h:c[f].from;if(m>d&&t.push(new Qt(d,m,r.tree,-o,s.from>=d||s.openStart,s.to<=m||s.openEnd)),p)break;d=c[f].to}}else t.push(new Qt(a,h,r.tree,-o,s.from>=o||s.openStart,s.to<=O||s.openEnd))}return t}var Nm=0,qe=class i{constructor(e,t,n,r){this.name=e,this.set=t,this.base=n,this.modified=r,this.id=Nm++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let n=typeof e=="string"?e:"?";if(e instanceof i&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let r=new i(n,[],null,[]);if(r.set.push(r),t)for(let s of t.set)r.set.push(s);return r}static defineModifier(e){let t=new Zr(e);return n=>n.modified.indexOf(t)>-1?n:Zr.get(n.base||n,n.modified.concat(t).sort((r,s)=>r.id-s.id))}},Fm=0,Zr=class i{constructor(e){this.name=e,this.instances=[],this.id=Fm++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find(O=>O.base==e&&Hm(t,O.modified));if(n)return n;let r=[],s=new qe(e.name,r,e,t);for(let O of t)O.instances.push(s);let o=Km(t);for(let O of e.set)if(!O.modified.length)for(let a of o)r.push(i.get(O,a));return s}};function Hm(i,e){return i.length==e.length&&i.every((t,n)=>t==e[n])}function Km(i){let e=[[]];for(let t=0;tn.length-t.length)}function oe(i){let e=Object.create(null);for(let t in i){let n=i[t];Array.isArray(n)||(n=[n]);for(let r of t.split(" "))if(r){let s=[],o=2,O=r;for(let c=0;;){if(O=="..."&&c>0&&c+3==r.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(O);if(!f)throw new RangeError("Invalid path: "+r);if(s.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),c+=f[0].length,c==r.length)break;let d=r[c++];if(c==r.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+r);O=r.slice(c)}let a=s.length-1,h=s[a];if(!h)throw new RangeError("Invalid path: "+r);let l=new vi(n,o,a>0?s.slice(0,a):null);e[h]=l.sort(e[h])}}return Fh.add(e)}var Fh=new Z,vi=class{constructor(e,t,n,r){this.tags=e,this.mode=t,this.context=n,this.next=r}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth{let o=r;for(let O of s)for(let a of O.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:n}}function Jm(i,e){let t=null;for(let n of i){let r=n.style(e);r&&(t=t?t+" "+r:r)}return t}function Hh(i,e,t,n=0,r=i.length){let s=new Uo(n,Array.isArray(e)?e:[e],t);s.highlightRange(i.cursor(),n,r,"",s.highlighters),s.flush(r)}var Uo=class{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,r,s){let{type:o,from:O,to:a}=e;if(O>=n||a<=t)return;o.isTop&&(s=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=r,l=eg(e)||vi.empty,c=Jm(s,l.tags);if(c&&(h&&(h+=" "),h+=c,l.mode==1&&(r+=(r?" ":"")+c)),this.startSpan(Math.max(t,O),h),l.opaque)return;let f=e.tree&&e.tree.prop(Z.mounted);if(f&&f.overlay){let d=e.node.enter(f.overlay[0].from+O,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,$=O;;g++){let Q=g=b||!e.nextSibling())););if(!Q||b>n)break;$=Q.to+O,$>t&&(this.highlightRange(d.cursor(),Math.max(t,Q.from+O),Math.min(n,$),"",p),this.startSpan(Math.min(n,$),h))}m&&e.parent()}else if(e.firstChild()){f&&(r="");do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,r,s),this.startSpan(Math.min(n,e.to),h)}while(e.nextSibling());e.parent()}}};function eg(i){let e=i.type.prop(Fh);for(;e&&e.context&&!i.matchContext(e.context);)e=e.next;return e||null}var x=qe.define,Wr=x(),Vt=x(),Bh=x(Vt),Nh=x(Vt),Ct=x(),Rr=x(Ct),Yo=x(Ct),ut=x(),ni=x(ut),ct=x(),ft=x(),Ao=x(),pn=x(Ao),Xr=x(),u={comment:Wr,lineComment:x(Wr),blockComment:x(Wr),docComment:x(Wr),name:Vt,variableName:x(Vt),typeName:Bh,tagName:x(Bh),propertyName:Nh,attributeName:x(Nh),className:x(Vt),labelName:x(Vt),namespace:x(Vt),macroName:x(Vt),literal:Ct,string:Rr,docString:x(Rr),character:x(Rr),attributeValue:x(Rr),number:Yo,integer:x(Yo),float:x(Yo),bool:x(Ct),regexp:x(Ct),escape:x(Ct),color:x(Ct),url:x(Ct),keyword:ct,self:x(ct),null:x(ct),atom:x(ct),unit:x(ct),modifier:x(ct),operatorKeyword:x(ct),controlKeyword:x(ct),definitionKeyword:x(ct),moduleKeyword:x(ct),operator:ft,derefOperator:x(ft),arithmeticOperator:x(ft),logicOperator:x(ft),bitwiseOperator:x(ft),compareOperator:x(ft),updateOperator:x(ft),definitionOperator:x(ft),typeOperator:x(ft),controlOperator:x(ft),punctuation:Ao,separator:x(Ao),bracket:pn,angleBracket:x(pn),squareBracket:x(pn),paren:x(pn),brace:x(pn),content:ut,heading:ni,heading1:x(ni),heading2:x(ni),heading3:x(ni),heading4:x(ni),heading5:x(ni),heading6:x(ni),contentSeparator:x(ut),list:x(ut),quote:x(ut),emphasis:x(ut),strong:x(ut),link:x(ut),monospace:x(ut),strikethrough:x(ut),inserted:x(),deleted:x(),changed:x(),invalid:x(),meta:Xr,documentMeta:x(Xr),annotation:x(Xr),processingInstruction:x(Xr),definition:qe.defineModifier("definition"),constant:qe.defineModifier("constant"),function:qe.defineModifier("function"),standard:qe.defineModifier("standard"),local:qe.defineModifier("local"),special:qe.defineModifier("special")};for(let i in u){let e=u[i];e instanceof qe&&(e.name=i)}var jP=_o([{tag:u.link,class:"tok-link"},{tag:u.heading,class:"tok-heading"},{tag:u.emphasis,class:"tok-emphasis"},{tag:u.strong,class:"tok-strong"},{tag:u.keyword,class:"tok-keyword"},{tag:u.atom,class:"tok-atom"},{tag:u.bool,class:"tok-bool"},{tag:u.url,class:"tok-url"},{tag:u.labelName,class:"tok-labelName"},{tag:u.inserted,class:"tok-inserted"},{tag:u.deleted,class:"tok-deleted"},{tag:u.literal,class:"tok-literal"},{tag:u.string,class:"tok-string"},{tag:u.number,class:"tok-number"},{tag:[u.regexp,u.escape,u.special(u.string)],class:"tok-string2"},{tag:u.variableName,class:"tok-variableName"},{tag:u.local(u.variableName),class:"tok-variableName tok-local"},{tag:u.definition(u.variableName),class:"tok-variableName tok-definition"},{tag:u.special(u.variableName),class:"tok-variableName2"},{tag:u.definition(u.propertyName),class:"tok-propertyName tok-definition"},{tag:u.typeName,class:"tok-typeName"},{tag:u.namespace,class:"tok-namespace"},{tag:u.className,class:"tok-className"},{tag:u.macroName,class:"tok-macroName"},{tag:u.propertyName,class:"tok-propertyName"},{tag:u.operator,class:"tok-operator"},{tag:u.comment,class:"tok-comment"},{tag:u.meta,class:"tok-meta"},{tag:u.invalid,class:"tok-invalid"},{tag:u.punctuation,class:"tok-punctuation"}]);var jo,yt=new Z;function Wi(i){return W.define({combine:i?e=>e.concat(i):void 0})}var Yr=new Z,fe=class{constructor(e,t,n=[],r=""){this.data=e,this.name=r,I.prototype.hasOwnProperty("tree")||Object.defineProperty(I.prototype,"tree",{get(){return G(this)}}),this.parser=t,this.extension=[zi.of(this),I.languageData.of((s,o,O)=>{let a=Kh(s,o,O),h=a.type.prop(yt);if(!h)return[];let l=s.facet(h),c=a.type.prop(Yr);if(c){let f=a.resolve(o-a.from,O);for(let d of c)if(d.test(f,s)){let p=s.facet(d.facet);return d.type=="replace"?p:p.concat(l)}}return l})].concat(n)}isActiveAt(e,t,n=-1){return Kh(e,t,n).type.prop(yt)==this.data}findRegions(e){let t=e.facet(zi);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],r=(s,o)=>{if(s.prop(yt)==this.data){n.push({from:o,to:o+s.length});return}let O=s.prop(Z.mounted);if(O){if(O.tree.prop(yt)==this.data){if(O.overlay)for(let a of O.overlay)n.push({from:a.from+o,to:a.to+o});else n.push({from:o,to:o+s.length});return}else if(O.overlay){let a=n.length;if(r(O.tree,O.overlay[0].from+o),n.length>a)return}}for(let a=0;an.isTop?t:void 0)]}),e.name)}configure(e,t){return new i(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function G(i){let e=i.field(fe.state,!1);return e?e.tree:V.empty}var Lo=class{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}},mn=null,ri=class i{constructor(e,t,n=[],r,s,o,O,a){this.parser=e,this.state=t,this.fragments=n,this.tree=r,this.treeLen=s,this.viewport=o,this.skipped=O,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new i(e,t,[],V.empty,0,n,[],null)}startParse(){return this.parser.startParse(new Lo(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=V.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let r=Date.now()+e;e=()=>Date.now()>r}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Qt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=mn;mn=this;try{return e()}finally{mn=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Jh(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:r,treeLen:s,viewport:o,skipped:O}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,l,c,f)=>a.push({fromA:h,toA:l,fromB:c,toB:f})),n=Qt.applyChanges(n,a),r=V.empty,s=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){O=[];for(let h of this.skipped){let l=e.mapPos(h.from,1),c=e.mapPos(h.to,-1);le.from&&(this.fragments=Jh(this.fragments,r,s),this.skipped.splice(n--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends St{createParse(t,n,r){let s=r[0].from,o=r[r.length-1].to;return{parsedPos:s,advance(){let a=mn;if(a){for(let h of r)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new V(ie.none,[],[],o-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return mn}};function Jh(i,e,t){return Qt.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}var gn=class i{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new i(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=ri.create(e.facet(zi).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new i(n)}};fe.state=ge.define({create:gn.init,update(i,e){for(let t of e.effects)if(t.is(fe.setState))return t.value;return e.startState.facet(zi)!=e.state.facet(zi)?gn.init(e.state):i.apply(e)}});var rc=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(rc=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var Eo=typeof navigator<"u"&&(!((jo=navigator.scheduling)===null||jo===void 0)&&jo.isInputPending)?()=>navigator.scheduling.isInputPending():null,tg=Ge.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(fe.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(fe.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=rc(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd