a&&o.push(new ze(a,g.from,d));let m=g.direction==$i!=!(d%2);qr(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==t||(f?I[p]!=l:I[p]==l))break;p++}u?Mr(n,a,p,i+1,s,u,o):ae;){let f=!0,c=!1;if(!h||a>r[h-1].to){let g=I[a-1];g!=l&&(f=!1,c=g==16)}let u=!f&&l==1?[]:null,d=f?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(c)break e;let g=r[--h];if(!f)for(let m=g.from,O=h;;){if(m==e)break e;if(O&&r[O-1].to==m)m=r[--O].from;else{if(I[m-1]==l)break e;break}}if(u)u.push(g);else{g.toI.length;)I[I.length]=256;let i=[],s=e==$i?0:1;return qr(n,s,s,t,0,n.length,i),i}function vh(n){return[new ze(0,n,0)]}var Ph="";function Cd(n,e,t,i,s){var r;let o=i.head-n.from,l=-1;if(o==0){if(!s||!n.length)return null;e[0].level!=t&&(o=e[0].side(!1,t),l=0)}else if(o==n.length){if(s)return null;let u=e[e.length-1];u.level!=t&&(o=u.side(!0,t),l=e.length-1)}l<0&&(l=ze.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc));let a=e[l];o==a.side(s,t)&&(a=e[l+=s?1:-1],o=a.side(!s,t));let h=s==(a.dir==t),f=re(n.text,o,h);if(Ph=n.text.slice(Math.min(o,f),Math.max(o,f)),f!=a.side(s,t))return S.cursor(f+n.from,h?-1:1,a.level);let c=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return!c&&a.level!=t?S.cursor(s?n.to:n.from,s?-1:1,t):c&&c.level0&&t.length&&(t.every(({fromA:l,toA:a})=>athis.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0);let i=this.view.inputState.composing<0?null:Qd(this.view,e.changes);if(this.hasComposition){this.markedForComposition.clear();let{from:l,to:a}=this.hasComposition;t=new Ze(l,a,e.changes.mapPos(l,-1),e.changes.mapPos(a,1)).addToSet(t.slice())}this.hasComposition=i?{from:i.range.fromB,to:i.range.toB}:null,(A.ie||A.chrome)&&!i&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let s=this.decorations,r=this.updateDeco(),o=qd(s,r,e.changes);return t=Ze.extendWithRanges(t,o),!(this.flags&7)&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length,i),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=A.chrome||A.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||s.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to=0?s[o]:null;if(!l)break;let{fromA:a,toA:h,fromB:f,toB:c}=l,u,d,p,g;if(i&&i.range.fromBf){let b=ki.build(this.view.state.doc,f,i.range.fromB,this.decorations,this.dynamicDecorationMap),y=ki.build(this.view.state.doc,i.range.toB,c,this.decorations,this.dynamicDecorationMap);d=b.breakAtStart,p=b.openStart,g=y.openEnd;let w=this.compositionView(i);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()),b.content.length&&w.merge(0,0,b.content[b.content.length-1],!0,0,b.openEnd)&&b.content.pop(),u=b.content.concat(w).concat(y.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=ki.build(this.view.state.doc,f,c,this.decorations,this.dynamicDecorationMap));let{i:m,off:O}=r.findPos(h,1),{i:k,off:v}=r.findPos(a,-1);ih(this,k,v,m,O,u,d,p,g)}i&&this.fixCompositionDOM(i)}compositionView(e){let t=new nt(e.text.nodeValue);t.flags|=8;for(let{deco:s}of e.marks)t=new ct(s,[t],t.length);let i=new Te;return i.append(t,0),i}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=G.get(r);l!=o&&(l&&(l.dom=null),o.setDOM(r))},i=this.childPos(e.range.fromB,1),s=this.children[i.i];t(e.line,s);for(let r=e.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],t(r>=0?e.marks[r].node:e.text,s)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&Pn(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||t||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.domAtPos(l.anchor),h=l.empty?a:this.domAtPos(l.head);if(A.gecko&&l.empty&&!this.hasComposition&&Ad(a)){let c=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(c,a.node.childNodes[a.offset]||null)),a=h=new be(c,0),o=!0}let f=this.view.observer.selectionRange;(o||!f.focusNode||!En(a.node,a.offset,f.anchorNode,f.anchorOffset)||!En(h.node,h.offset,f.focusNode,f.focusOffset))&&(this.view.observer.ignore(()=>{A.android&&A.chrome&&this.dom.contains(f.focusNode)&&Ed(f.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let c=qn(this.view.root);if(c)if(l.empty){if(A.gecko){let u=Rd(a.node,a.offset);if(u&&u!=3){let d=Ah(a.node,a.offset,u==1?1:-1);d&&(a=new be(d,u==1?0:d.nodeValue.length))}}c.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!=null&&(f.caretBidiLevel=l.bidiLevel)}else if(c.extend){c.collapse(a.node,a.offset);try{c.extend(h.node,h.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,h]=[h,a]),u.setEnd(h.node,h.offset),u.setStart(a.node,a.offset),c.removeAllRanges(),c.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,h)),this.impreciseAnchor=a.precise?null:new be(f.anchorNode,f.anchorOffset),this.impreciseHead=h.precise?null:new be(f.focusNode,f.focusOffset)}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=qn(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=Te.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+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 f=this.domAtPos(t.head+t.assoc);i.collapse(f.node,f.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let c=e.observer.selectionRange;e.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=t.from&&i.collapse(s,r)}nearest(e){for(let t=e;t;){let i=G.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;to||e==o&&r.type!=Z.WidgetBefore&&r.type!=Z.WidgetAfter&&(!s||t==2||this.children[s-1].breakAfter||this.children[s-1].type==Z.WidgetBefore&&t>-2))return r.coordsAt(e-o,t);i=o}}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),s=this.children[t];if(!(s instanceof Te))return null;for(;s.children.length;){let{i:l,off:a}=s.childPos(i,1);for(;;l++){if(l==s.children.length)return null;if((s=s.children[l]).length)break}i=a}if(!(s instanceof nt))return null;let r=re(s.text,i);if(r==i)return null;let o=At(s.dom,i,r).getClientRects();return!o.length||o[0].top>=o[0].bottom?null:o[0]}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==F.LTR;for(let h=0,f=0;fs)break;if(h>=i){let d=c.dom.getBoundingClientRect();if(t.push(d.height),o){let p=c.dom.lastChild,g=p?Ai(p):[];if(g.length){let m=g[g.length-1],O=a?m.right-d.left:d.right-m.left;O>l&&(l=O,this.minWidth=r,this.minWidthFrom=h,this.minWidthTo=u)}}}h=u+c.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?F.RTL:F.LTR}measureTextSize(){for(let r of this.children)if(r instanceof Te){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,i,s;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 r=Ai(e.firstChild)[0];t=e.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:i,textHeight:s}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new $n(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(R.replace({widget:new Yn(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return R.set(e)}updateDeco(){let e=this.view.state.facet(Di).map((t,i)=>(this.dynamicDecorationMap[i]=typeof t=="function")?t(this.view):t);for(let t=e.length;tt.anchor?-1:1),s;if(!i)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=yh(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom};hd(this.view.scrollDOM,o,t.head-1)return null;a+=d.text.length}if(h=h.parentNode,!h)return null;let f=G.get(h);if(f){r=f.posAtStart+a,o=r+l;break}}}return{from:r,to:o,node:i}}function Qd(n,e){let t=Ch(n,e.newLength-e.length);if(!t)return null;let{from:i,to:s,node:r}=t,o=e.mapPos(i,-1),l=e.mapPos(s,1),a=r.nodeValue;if(/[\n\r]/.test(a))return null;if(l-o!=a.length){let u=e.mapPos(i,1),d=e.mapPos(s,-1);if(d-u==a.length)o=u,l=d;else if(n.state.doc.sliceString(l-a.length,l)==a)o=l-a.length;else if(n.state.doc.sliceString(o,o+a.length)==a)l=o+a.length;else return null}let{main:h}=n.state.selection;if(n.state.doc.sliceString(o,l)!=a||o>h.head||l0)i=i.childNodes[s-1],s=ft(i);else break}if(t>=0)for(let i=n,s=e;;){if(i.nodeType==3)return i;if(i.nodeType==1&&s=0)i=i.childNodes[s],s=0;else break}return null}function Rd(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e0;){let h=re(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;ln?e.left-n:Math.max(0,n-e.right)}function Wd(n,e){return e.top>n?e.top-n:Math.max(0,n-e.bottom)}function mr(n,e){return n.tope.top+1}function ya(n,e){return en.bottom?{top:n.top,left:n.left,right:n.right,bottom:e}:n}function Er(n,e,t){let i,s,r,o,l=!1,a,h,f,c;for(let p=n.firstChild;p;p=p.nextSibling){let g=Ai(p);for(let m=0;mv||o==v&&r>k){i=p,s=O,r=k,o=v;let b=v?t0?m0)}k==0?t>O.bottom&&(!f||f.bottomO.top)&&(h=p,c=O):f&&mr(f,O)?f=wa(f,O.bottom):c&&mr(c,O)&&(c=ya(c,O.top))}}if(f&&f.bottom>=t?(i=a,s=f):c&&c.top<=t&&(i=h,s=c),!i)return{node:n,offset:0};let u=Math.max(s.left,Math.min(s.right,e));if(i.nodeType==3)return ka(i,u,t);if(l&&i.contentEditable!="false")return Er(i,u,t);let d=Array.prototype.indexOf.call(n.childNodes,i)+(e>=(s.left+s.right)/2?1:0);return{node:n,offset:d}}function ka(n,e,t){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;lt?f.top-t:t-f.bottom)-1;if(f.left-1<=e&&f.right+1>=e&&c=(f.left+f.right)/2,d=u;if((A.chrome||A.gecko)&&At(n,l).getBoundingClientRect().left==f.right&&(d=!u),c<=0)return{node:n,offset:l+(d?1:0)};s=l+(d?1:0),r=c}}}return{node:n,offset:s>-1?s:o>0?n.nodeValue.length:0}}function Qh(n,e,t,i=-1){var s,r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,a,{docHeight:h}=n.viewState,{x:f,y:c}=e,u=c-l;if(u<0)return 0;if(u>h)return n.state.doc.length;for(let b=n.viewState.heightOracle.textHeight/2,y=!1;a=n.elementAtHeight(u),a.type!=Z.Text;)for(;u=i>0?a.bottom+b:a.top-b,!(u>=0&&u<=h);){if(y)return t?null:0;y=!0,i=-i}c=l+u;let d=a.from;if(dn.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:t?null:Ta(n,o,a,f,c);let p=n.dom.ownerDocument,g=n.root.elementFromPoint?n.root:p,m=g.elementFromPoint(f,c);m&&!n.contentDOM.contains(m)&&(m=null),m||(f=Math.max(o.left+1,Math.min(o.right-1,f)),m=g.elementFromPoint(f,c),m&&!n.contentDOM.contains(m)&&(m=null));let O,k=-1;if(m&&((s=n.docView.nearest(m))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let b=p.caretPositionFromPoint(f,c);b&&({offsetNode:O,offset:k}=b)}else if(p.caretRangeFromPoint){let b=p.caretRangeFromPoint(f,c);b&&({startContainer:O,startOffset:k}=b,(!n.contentDOM.contains(O)||A.safari&&Vd(O,k,f)||A.chrome&&Bd(O,k,f))&&(O=void 0))}}if(!O||!n.docView.dom.contains(O)){let b=Te.find(n.docView,d);if(!b)return u>a.top+a.height/2?a.to:a.from;({node:O,offset:k}=Er(b.dom,f,c))}let v=n.docView.nearest(O);if(!v)return null;if(v.isWidget&&((r=v.dom)===null||r===void 0?void 0:r.nodeType)==1){let b=v.dom.getBoundingClientRect();return e.yn.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+gn(o,r,n.state.tabSize)}function Vd(n,e,t){let i;if(n.nodeType!=3||e!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return At(n,i-1,i).getBoundingClientRect().left>t}function Bd(n,e,t){if(e!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():At(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function Dr(n,e){let t=n.lineBlockAt(e);if(Array.isArray(t.type)){for(let i of t.type)if(i.to>e||i.to==e&&(i.to==t.to||i.type==Z.Text))return i}return t}function Ld(n,e,t,i){let s=Dr(n,e.head),r=!i||s.type!=Z.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==F.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return S.cursor(a,t?-1:1)}return S.cursor(t?s.to:s.from,t?-1:1)}function va(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let h=Cd(s,r,o,l,t),f=Ph;if(!h){if(s.number==(t?n.state.doc.lines:1))return l;f=`
-`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),h=S.cursor(t?s.from:s.to)}if(a){if(!a(f))return l}else{if(!i)return h;a=i(f)}l=h}}function Xd(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==L.Space&&(s=o),s==o}}function Id(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return S.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s),f=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let d=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+f}let c=a.left+o,u=i??n.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=Qh(n,{x:c,y:p},!1,r);if(pa.bottom||(r<0?gs))return S.cursor(g,e.assoc,void 0,o)}}function Cn(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&es(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:S.cursor(i,i{this.ignoreDuringComposition(s)||s.type=="keydown"&&this.keydown(e,s)||(this.mustFlushObserver(s)&&e.observer.forceFlush(),this.runCustomHandlers(s.type,e,s)?s.preventDefault():i(e,s))};for(let i in te){let s=te[i];e.contentDOM.addEventListener(i,r=>{Pa(e,r)&&t(s,r)},Vr[i]),this.registeredEvents.push(i)}e.scrollDOM.addEventListener("mousedown",i=>{if(i.target==e.scrollDOM&&i.clientY>e.contentDOM.getBoundingClientRect().bottom&&(t(te.mousedown,i),!i.defaultPrevented&&i.button==2)){let s=e.contentDOM.style.minHeight;e.contentDOM.style.minHeight="100%",setTimeout(()=>e.contentDOM.style.minHeight=s,200)}}),e.scrollDOM.addEventListener("drop",i=>{i.target==e.scrollDOM&&i.clientY>e.contentDOM.getBoundingClientRect().bottom&&t(te.drop,i)}),A.chrome&&A.chrome_version==102&&e.scrollDOM.addEventListener("wheel",()=>{this.chromeScrollHack<0?e.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout(()=>{this.chromeScrollHack=-1,e.contentDOM.style.pointerEvents=""},100)},{passive:!0}),this.notifiedFocused=e.hasFocus,A.safari&&e.contentDOM.addEventListener("input",()=>null),A.gecko&&ep(e.contentDOM.ownerDocument)}ensureHandlers(e,t){var i;let s;this.customHandlers=[];for(let r of t)if(s=(i=r.update(e).spec)===null||i===void 0?void 0:i.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let o in s)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),e.contentDOM.addEventListener(o,l=>{Pa(e,l)&&this.runCustomHandlers(o,e,l)&&l.preventDefault()}))}}runCustomHandlers(e,t,i){for(let s of this.customHandlers){let r=s.handlers[e];if(r)try{if(r.call(s.plugin,i,t)||i.defaultPrevented)return!0}catch(o){ge(t.state,o)}}return!1}runScrollHandlers(e,t){this.lastScrollTop=e.scrollDOM.scrollTop,this.lastScrollLeft=e.scrollDOM.scrollLeft;for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,t,e)}catch(r){ge(e.state,r)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&Date.now()s.keyCode==t.keyCode))&&!t.ctrlKey||Yd.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=i||t,setTimeout(()=>this.flushIOSKey(e),250),!0):!1}flushIOSKey(e){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,Jt(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:A.safari&&!A.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}mustFlushObserver(e){return e.type=="keydown"&&e.keyCode!=229}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}},Rh=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Yd="dthko",Mh=[16,17,18,20,91,92,224,225],Sn=6;function bn(n){return Math.max(0,n)*.7+8}function Nd(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}var Wr=class{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=fd(e.contentDOM),this.atoms=e.state.facet(uo).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(X.allowMultipleSelections)&&Fd(e,t),this.dragging=zd(e,t)&&$h(t)==1?null:!1}start(e){this.dragging===!1&&(e.preventDefault(),this.select(e))}move(e){var t;if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Nd(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let i=0,s=0,r=((t=this.scrollParent)===null||t===void 0?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=yh(this.view);e.clientX-o.left<=r.left+Sn?i=-bn(r.left-e.clientX):e.clientX+o.right>=r.right-Sn&&(i=bn(e.clientX-r.right)),e.clientY-o.top<=r.top+Sn?s=-bn(r.top-e.clientY):e.clientY+o.bottom>=r.bottom-Sn&&(s=bn(e.clientY-r.bottom)),this.setScrollSpeed(i,s)}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=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(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;ithis.select(this.lastEvent),20)}};function Fd(n,e){let t=n.state.facet(fh);return t.length?t[0](e):A.mac?e.metaKey:e.ctrlKey}function Gd(n,e){let t=n.state.facet(ch);return t.length?t[0](e):A.mac?!e.altKey:!e.ctrlKey}function zd(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=qn(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Pa(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=G.get(t))&&i.ignoreEvent(e))return!1;return!0}var te=Object.create(null),Vr=Object.create(null),qh=A.ie&&A.ie_version<15||A.ios&&A.webkit_version<604;function Zd(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),Eh(n,t.value)},50)}function Eh(n,e){let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Br!=null&&t.selection.ranges.every(a=>a.empty)&&Br==r.toString()){let a=-1;i=t.changeByRange(h=>{let f=t.doc.lineAt(h.from);if(f.from==a)return{range:h};a=f.from;let c=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:c},range:S.cursor(h.from+c.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:S.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}te.keydown=(n,e)=>{n.inputState.setSelectionOrigin("select"),e.keyCode==27&&(n.inputState.lastEscPress=Date.now())};te.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};te.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Vr.touchstart=Vr.touchmove={passive:!0};te.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return;let t=null;for(let i of n.state.facet(uh))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=_d(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new Wr(n,e,t,i)),i&&n.observer.ignore(()=>Ja(n.contentDOM)),n.inputState.mouseSelection&&n.inputState.mouseSelection.start(e)}};function Ca(n,e,t,i){if(i==1)return S.cursor(e,t);if(i==2)return Dd(n.state,e,t);{let s=Te.find(n.docView,e),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return ln>=e.top&&n<=e.bottom,Aa=(n,e,t)=>Dh(e,t)&&n>=t.left&&n<=t.right;function Ud(n,e,t,i){let s=Te.find(n.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Aa(t,i,o))return-1;let l=s.coordsAt(r,1);return l&&Aa(t,i,l)?1:o&&Dh(i,o)?-1:1}function Qa(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Ud(n,t,e.clientX,e.clientY)}}var Hd=A.ie&&A.ie_version<=11,Ra=null,Ma=0,qa=0;function $h(n){if(!Hd)return n.detail;let e=Ra,t=qa;return Ra=n,qa=Date.now(),Ma=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Ma+1)%3:1}function _d(n,e){let t=Qa(n,e),i=$h(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=Qa(n,r),h,f=Ca(n,a.pos,a.bias,i);if(t.pos!=a.pos&&!o){let c=Ca(n,t.pos,t.bias,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u1&&(h=jd(s,a.pos))?h:l?s.addRange(f):S.create([f])}}}function jd(n,e){for(let t=0;t=e)return S.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}te.dragstart=(n,e)=>{let{selection:{main:t}}=n.state,{mouseSelection:i}=n.inputState;i&&(i.dragging=t),e.dataTransfer&&(e.dataTransfer.setData("Text",n.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove")};function Ea(n,e,t,i){if(!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:r}=n.inputState,o=i&&r&&r.dragging&&Gd(n,e)?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}te.drop=(n,e)=>{if(!e.dataTransfer)return;if(n.state.readOnly)return e.preventDefault();let t=e.dataTransfer.files;if(t&&t.length){e.preventDefault();let i=Array(t.length),s=0,r=()=>{++s==t.length&&Ea(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}}else Ea(n,e,e.dataTransfer.getData("Text"),!0)};te.paste=(n,e)=>{if(n.state.readOnly)return e.preventDefault();n.observer.flush();let t=qh?null:e.clipboardData;t?(Eh(n,t.getData("text/plain")||t.getData("text/uri-text")),e.preventDefault()):Zd(n)};function Kd(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Jd(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:e.join(n.lineBreak),ranges:t,linewise:i}}var Br=null;te.copy=te.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=Jd(n.state);if(!t&&!s)return;Br=s?t:null;let r=qh?null:e.clipboardData;r?(e.preventDefault(),r.clearData(),r.setData("text/plain",t)):Kd(n,t),e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};var Wh=Se.define();function Vh(n,e){let t=[];for(let i of n.facet(mh)){let s=i(n,e);s&&t.push(s)}return t?n.update({effects:t,annotations:Wh.of(!0)}):null}function Bh(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=Vh(n.state,e);t?n.dispatch(t):n.update([])}},10)}te.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),Bh(n)};te.blur=n=>{n.observer.clearSelectionRange(),Bh(n)};te.compositionstart=te.compositionupdate=n=>{n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0)};te.compositionend=n=>{n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,A.chrome&&A.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50)};te.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};te.beforeinput=(n,e)=>{var t;let i;if(A.chrome&&A.android&&(i=Rh.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}};var Da=new Set;function ep(n){Da.has(n)||(Da.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}var $a=["pre-wrap","normal","pre-line","break-spaces"],Lr=class{constructor(e){this.lineWrapping=e,this.doc=W.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){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 $a.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>An&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return n.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:f,toB:c}=s[l],u=r.lineAt(a,N.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,N.ByPosNoHeight,i,0,0);for(c+=d.to-h,h=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,f=s[l-1].fromB,l--,ar*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s=r&&o(this.blockAt(0,i,s,r))}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(e,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}},De=class n extends Nn{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,s){return new Ge(s,this.length,i,this.height,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof n||s instanceof ht&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ht?s=new n(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):Pe.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setHeight(e,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(e,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:""})`}},ht=class n extends Pe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let h=s+Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length),f=t.doc.lineAt(h),c=l+f.length*a,u=Math.max(i,e-c/2);return new Ge(f.from,f.length,u,c,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:f,length:c}=t.doc.line(r+h);return new Ge(f,c,i+l*h,l,0)}}lineAt(e,t,i,s,r){if(t==N.ByHeight)return this.blockAt(e,i,s,r);if(t==N.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Ge(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),f=l+h.length*a,c=h.number-o,u=s+l*c+a*(h.from-r-c);return new Ge(h.from,h.length,Math.max(s,Math.min(u,s+this.height-f)),f,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let f=e,c=s;f<=t;){let u=i.doc.lineAt(f);if(f==e){let p=u.number-l;c+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new Ge(u.from,u.length,c,d,0)),c+=d,f=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof n?i[i.length-1]=new n(r.length+s):i.push(null,new n(s-1))}if(e>0){let r=i[0];r instanceof n?i[0]=new n(e+r.length):i.unshift(new n(e-1),null)}return Pe.of(i)}decomposeLeft(e,t){t.push(new n(e-1),null)}decomposeRight(e,t){t.push(null,new n(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new n(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let c=s.heights[s.index++];a==-1?a=c:Math.abs(c-a)>=An&&(a=-2);let u=new De(f,c);u.outdated=!1,o.push(u),l+=f+1}l<=r&&o.push(null,new n(r-l).updateHeight(e,l));let h=Pe.of(o);return(a<0||Math.abs(h.height-this.height)>=An||Math.abs(a-this.heightMetrics(e,t).perLine)>=An)&&(e.heightChanged=!0),h}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},Ir=class extends Pe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return el))return h;let f=t==N.ByPosNoHeight?N.ByPosNoHeight:N.ByPos;return a?h.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,N.ByPos,i,s,r);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Wa(r,o-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e2*t.size||t.size>2*e.size?Pe.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Wa(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof ht&&(i=n[e+1])instanceof ht&&n.splice(e-1,3,new ht(t.length+1+i.length))}var tp=5,Yr=class n{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 i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof De?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new De(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=tp)&&this.addLineDeco(s,r,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 De(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new ht(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof De)return e;let t=new De(0,-1);return this.nodes.push(t),t}addBlock(e){var t;this.enterLine();let i=(t=e.deco)===null||t===void 0?void 0:t.type;i==Z.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,i!=Z.WidgetBefore&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof De)&&!this.isCovered?this.nodes.push(new De(0,-1)):(this.writtenTof.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=h==n.parentNode?u.bottom:Math.min(a,u.bottom)}h=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function sp(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var vi=class{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;itypeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Lr(t),this.stateDeco=e.facet(Di).filter(i=>typeof i!="function"),this.heightMap=Pe.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle.setDoc(e.doc),[new Ze(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=R.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new _t(r,o))}}this.viewports=e.sort((i,s)=>i.from-s.from),this.scaler=this.heightMap.height<=7e6?Va:new Gr(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:yi(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Di).filter(f=>typeof f!="function");let s=e.changedRanges,r=Ze.extendWithRanges(s,ip(i,this.stateDeco,e?e.changes:me.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.heada.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=!e.changes.empty||e.flags&2||a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,this.updateForViewport(),h&&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,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?F.RTL:F.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,f=0;if(l.width&&l.height){let b=l.width/t.offsetWidth,y=l.height/t.offsetHeight;b>.995&&b<1.005&&(b=1),y>.995&&y<1.005&&(y=1),(this.scaleX!=b||this.scaleY!=y)&&(this.scaleX=b,this.scaleY=y,h|=8,o=a=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,h|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.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=th(e.scrollDOM);let p=(this.printing?sp:np)(t,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let O=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(O!=this.inView&&(this.inView=O,O&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let k=l.width;if((this.contentDOMWidth!=k||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=8),a){let b=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(b)&&(o=!0),o||s.lineWrapping&&Math.abs(k-this.contentDOMWidth)>s.charWidth){let{lineHeight:y,charWidth:w,textHeight:Q}=e.docView.measureTextSize();o=y>0&&s.refresh(r,y,w,Q,k/w,b),o&&(e.docView.minWidth=0,h|=8)}g>0&&m>0?f=Math.max(g,m):g<0&&m<0&&(f=Math.min(g,m)),s.heightChanged=!1;for(let y of this.viewports){let w=y.from==this.viewport.from?b:e.docView.measureVisibleLineHeights(y);this.heightMap=(o?Pe.empty().applyChanges(this.stateDeco,W.empty,this.heightOracle,[new Ze(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Xr(y.from,w))}s.heightChanged&&(h|=2)}let v=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return v&&(this.viewport=this.getViewport(f,this.scrollTarget)),this.updateForViewport(),(h&2||v)&&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 i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new _t(s.lineAt(o-i*1e3,N.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,N.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(ha.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=s.lineAt(h,N.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&h=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r>1,o=s<<1;if(this.defaultTextDirection!=F.LTR&&!i)return[];let l=[],a=(h,f,c,u)=>{if(f-hh&&mm.from>=c.from&&m.to<=c.to&&Math.abs(m.from-h)m.fromO));if(!g){if(fm.from<=f&&m.to>=f)){let m=t.moveToLineBoundary(S.cursor(f),!1,!0).head;m>h&&(f=m)}g=new vi(h,f,this.gapSize(c,h,f,u))}l.push(g)};for(let h of this.viewportLines){if(h.lengthh.from&&a(h.from,u,h,f),dt.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];V.spans(e,this.viewport.from,this.viewport.to,{span(s,r){t.push({from:s,to:r})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=t[r].from||s.to!=t[r].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||yi(this.heightMap.lineAt(e,N.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return yi(this.heightMap.lineAt(this.scaler.fromDOM(e),N.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 yi(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}},_t=class{constructor(e,t){this.from=e,this.to=t}};function rp(n,e,t){let i=[],s=n,r=0;return V.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function wn(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function op(n,e){for(let t of n)if(e(t))return t}var Va={toDOM(n){return n},fromDOM(n){return n},scale:1},Gr=class{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,N.ByPos,e,0,0).top,f=t.lineAt(a,N.ByPos,e,0,0).bottom;return s+=f-h,{from:l,to:a,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=tyi(s,e)):n._content)}var kn=P.define({combine:n=>n.join(" ")}),zr=P.define({combine:n=>n.indexOf(!0)>-1}),Zr=Ee.newName(),Lh=Ee.newName(),Xh=Ee.newName(),Ih={"&light":"."+Lh,"&dark":"."+Xh};function Ur(n,e,t){return new Ee(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}var lp=Ur("."+Zr,{"&":{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},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",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"},"&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},"&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:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".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"}},Ih),Hr=class{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=r||o?[]:fp(e),a=new Wn(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=cp(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!yr(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!yr(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=S.single(h,a)}}};function Yh(n,e){let t,{newSel:i}=e,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,h=null;(r===8||A.android&&e.text.length=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,s.to))}:(A.mac||A.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=S.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:W.of([" "])}):A.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
- `&&n.lineWrapping&&(i&&(i=S.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:W.of([" "])}),t){if(A.ios&&n.inputState.flushIOSKey(n)||A.android&&(t.from==s.from&&t.to==s.to&&t.insert.length==1&&t.insert.lines==2&&Jt(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||r==8&&t.insert.lengths.head)&&Jt(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&Jt(n.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,a=()=>l||(l=ap(n,t,i));return n.state.facet(ph).some(h=>h(n,t.from,t.to,o,a))||n.dispatch(a()),!0}else if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function ap(n,e,t){let i,s=n.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=r.frome.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+a))}else{let l=s.changes(e),a=t&&t.main.to<=l.newLength?t.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let h=n.state.sliceDoc(e.from,e.to),f=Ch(n,e.insert.length-(e.to-e.from))||n.state.doc.lineAt(r.head),c=r.to-e.to,u=r.to-r.from;i=s.changeByRange(d=>{if(d.from==r.from&&d.to==r.to)return{changes:l,range:a||d.map(l)};let p=d.to-c,g=p-h.length;if(d.to-d.from!=u||n.state.sliceDoc(g,p)!=h||f&&d.to>=f.from&&d.from<=f.to)return{range:d};let m=s.changes({from:g,to:p,insert:e.insert}),O=d.to-r.to;return{changes:m,range:a?S.range(Math.max(0,a.anchor+O),Math.max(0,a.head+O)):d.map(m)}})}else i={changes:l,selection:a&&s.selection.replaceRange(a)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:o,scrollIntoView:!0})}function hp(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function fp(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new Vn(t,i)),(s!=t||r!=i)&&e.push(new Vn(s,r))),e}function cp(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?S.single(t+e,i+e):null}var up={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Or=A.ie&&A.ie_version<=11,_r=class{constructor(e){this.view=e,this.active=!1,this.selectionRange=new wr,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.resizeContent=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(A.ie&&A.ie_version<=11||A.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Or&&(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),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)this.view.requestMeasure()),this.resizeContent.observe(e.contentDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{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.runScrollHandlers(this.view,e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){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,i)=>t!=e[i]))){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:i}=this,s=this.selectionRange;if(i.state.facet(jn)?i.root.activeElement!=this.dom:!Pn(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(A.ie&&A.ie_version<=11||A.android&&A.chrome)&&!i.state.selection.main.empty&&s.focusNode&&En(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=A.safari&&e.root.nodeType==11&&ld(this.dom.ownerDocument)==this.dom&&dp(this.view)||qn(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=Pn(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Jt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!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,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&Pn(this.dom,this.selectionRange);return e<0&&!s?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new Hr(this.view,e,t,i))}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return!1;let i=this.view.state,s=Yh(this.view,t);return this.view.state==i&&this.view.update([]),s}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 i=Ba(t,e.previousSibling||e.target.previousSibling,-1),s=Ba(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):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),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),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var e,t,i,s;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect(),(s=this.resizeContent)===null||s===void 0||s.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)}};function Ba(n,e,t){for(;e;){let i=G.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function dp(n){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(n.contentDOM.addEventListener("beforeinput",t,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,s=e.startOffset,r=e.endContainer,o=e.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return En(l.node,l.offset,r,o)&&([i,s,r,o]=[r,o,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:o}}var C=class n{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={}){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.style.cssText="position: fixed; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(i=>i.forEach(s=>t(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||cd(e.parent)||document,this.viewState=new Fn(e.state||X.create(e)),this.plugins=this.state.facet(Si).map(i=>new Ti(i));for(let i of this.plugins)i.update(this);this.observer=new _r(this),this.inputState=new $r(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new In(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}dispatch(...e){let t=e.length==1&&e[0]instanceof oe?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,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(Wh))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=Vh(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(f=null)):this.observer.clear(),r.facet(X.phrases)!=this.state.facet(X.phrases))return this.setState(r);s=Xn.create(this,r,e),s.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;c=new Ln(d.empty?d:S.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Sa)&&(c=d.value)}this.viewState.update(s,c),this.bidiCache=Gn.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(bi)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(kn)!=s.state.facet(kn)&&(this.viewState.mustMeasureContent=!0),(t||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!s.empty)for(let u of this.state.facet(Qr))u(s);(a||f)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),f&&!Yh(this,f)&&h.force&&Jt(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 i of this.plugins)i.destroy(this);this.viewState=new Fn(e),this.plugins=e.facet(Si).map(i=>new Ti(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new In(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Si),i=e.state.facet(Si);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new Ti(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s-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,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(th(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=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(l>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 f=h.map(d=>{try{return d.read(this)}catch(p){return ge(this.state,p),La}}),c=Xn.create(this,this.state,[]),u=!1;c.flags|=a,t?t.flags|=a:t=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c));for(let d=0;d1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Qr))l(t)}get themeClasses(){return Zr+" "+(this.state.facet(zr)?Xh:Lh)+" "+this.state.facet(kn)}updateAttrs(){let e=Xa(this,xh,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(jn)?"true":"false",class:"cm-content",style:`${A.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Xa(this,co,t);let i=this.observer.ignore(()=>{let s=Cr(this.contentDOM,this.contentAttrs,t),r=Cr(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(n.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(bi);let e=this.state.facet(n.cspNonce);Ee.mount(this.root,this.styleModules.concat(lp).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;ti.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,i){return gr(this,e,va(this,e,t,i))}moveByGroup(e,t){return gr(this,e,va(this,e,t,i=>Xd(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return Ld(this,e,t,i)}moveVertically(e,t,i){return gr(this,e,Id(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),Qh(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[ze.find(r,e-s.from,-1,t)];return ao(i,o.dir==F.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(gh)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>pp)return vh(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Th(r.isolates,i=ba(this,e.from,e.to))))return r.order;i||(i=ba(this,e.from,e.to));let s=Pd(e.text,t,i);return this.bidiCache.push(new Gn(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||A.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ja(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(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Sa.of(new Ln(typeof e=="number"?S.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return U.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=Ee.newName(),s=[kn.of(i),bi.of(Ur(`.${i}`,e))];return t&&t.dark&&s.push(zr.of(!0)),s}static baseTheme(e){return Le.lowest(bi.of(Ur("."+Zr,e,Ih)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&G.get(i)||G.get(e);return((t=s?.rootView)===null||t===void 0?void 0:t.view)||null}};C.styleModule=bi;C.inputHandler=ph;C.focusChangeEffect=mh;C.perLineTextDirection=gh;C.exceptionSink=dh;C.updateListener=Qr;C.editable=jn;C.mouseSelectionStyle=uh;C.dragMovesSelection=ch;C.clickAddsSelectionRange=fh;C.decorations=Di;C.atomicRanges=uo;C.bidiIsolatedRanges=Sh;C.scrollMargins=bh;C.darkTheme=zr;C.cspNonce=P.define({combine:n=>n.length?n[0]:""});C.contentAttributes=co;C.editorAttributes=xh;C.lineWrapping=C.contentAttributes.of({class:"cm-lineWrapping"});C.announce=M.define();var pp=4096,La={},Gn=class n{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:F.LTR;for(let r=Math.max(0,e.length-10);r=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&Pr(o,t)}return t}var mp=A.mac?"mac":A.windows?"win":A.linux?"linux":"key";function gp(n,e){let t=n.split(/-(?!$)/),i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;ai.concat(s),[]))),t}function Fh(n,e,t){return Gh(Nh(n.state),e,n,t)}var at=null,xp=4e3;function Sp(n,e=mp){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,f)=>{var c,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(O=>gp(O,e));for(let O=1;O{let b=at={view:v,prefix:k,scope:o};return setTimeout(()=>{at==b&&(at=null)},xp),!0}]})}let g=p.join(" ");s(g,!1);let m=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});a&&m.run.push(a),h&&(m.preventDefault=!0),f&&(m.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let f=t[h]||(t[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let c in f)f[c].run.push(o.any)}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}function Gh(n,e,t,i){let s=fa(e),r=J(s,0),o=pe(r)==s.length&&s!=" ",l="",a=!1,h=!1,f=!1;at&&at.view==t&&at.scope==i&&(l=at.prefix+" ",Mh.indexOf(e.keyCode)<0&&(h=!0,at=null));let c=new Set,u=m=>{if(m){for(let O of m.run)if(!c.has(O)&&(c.add(O),O(t,e)))return m.stopPropagation&&(f=!0),!0;m.preventDefault&&(m.stopPropagation&&(f=!0),h=!0)}return!1},d=n[i],p,g;return d&&(u(d[l+Tn(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(A.windows&&e.ctrlKey&&e.altKey)&&(p=it[e.keyCode])&&p!=s?(u(d[l+Tn(p,e,!0)])||e.shiftKey&&(g=Zt[e.keyCode])!=s&&g!=p&&u(d[l+Tn(g,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Tn(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&f&&e.stopPropagation(),a}var Wi=class n{constructor(e,t,i,s,r){this.className=e,this.left=t,this.top=i,this.width=s,this.height=r}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,i){if(i.empty){let s=e.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=zh(e);return[new n(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return bp(e,t,i)}};function zh(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==F.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function Ya(n,e,t){let i=S.cursor(e);return{from:Math.max(t.from,n.moveToLineBoundary(i,!1,!0).from),to:Math.min(t.to,n.moveToLineBoundary(i,!0,!0).from),type:Z.Text}}function bp(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let i=Math.max(t.from,n.viewport.from),s=Math.min(t.to,n.viewport.to),r=n.textDirection==F.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=zh(n),h=o.querySelector(".cm-line"),f=h&&window.getComputedStyle(h),c=l.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),u=l.right-(f?parseInt(f.paddingRight):0),d=Dr(n,i),p=Dr(n,s),g=d.type==Z.Text?d:null,m=p.type==Z.Text?p:null;if(g&&(n.lineWrapping||d.widgetLineBreaks)&&(g=Ya(n,i,g)),m&&(n.lineWrapping||p.widgetLineBreaks)&&(m=Ya(n,s,m)),g&&m&&g.from==m.from)return k(v(t.from,t.to,g));{let y=g?v(t.from,null,g):b(d,!1),w=m?v(null,t.to,m):b(p,!0),Q=[];return(g||d).to<(m||p).from-(g&&m?1:0)||d.widgetLineBreaks>1&&y.bottom+n.defaultLineHeight/2ie&&Oe.from=he)break;ne>le&&Y(Math.max(_,le),y==null&&_<=ie,Math.min(ne,he),w==null&&ne>=ae,xe.dir)}if(le=Ne.to+1,le>=he)break}return D.length==0&&Y(ie,y==null,ae,w==null,n.textDirection),{top:$,bottom:E,horizontal:D}}function b(y,w){let Q=l.top+(w?y.top:y.bottom);return{top:Q,bottom:Q,horizontal:[]}}}function yp(n,e){return n.constructor==e.constructor&&n.eq(e)}var jr=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(Qn)!=e.state.facet(Qn)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}setOrder(e){let t=0,i=e.facet(Qn);for(;t!yp(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[i].constructor&&s.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}},Qn=P.define();function Zh(n){return[U.define(e=>new jr(e,n)),Qn.of(n)]}var Uh=!A.ios,Vi=P.define({combine(n){return ce(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Hh(n={}){return[Vi.of(n),wp,kp,Tp,Oh.of(!0)]}function _h(n){return n.startState.facet(Vi)!=n.state.facet(Vi)}var wp=Zh({above:!0,markers(n){let{state:e}=n,t=e.facet(Vi),i=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty?!r||Uh:t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:S.cursor(s.head,s.head>s.anchor?-1:1);for(let a of Wi.forRange(n,o,l))i.push(a)}}return i},update(n,e){n.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=_h(n);return t&&Na(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){Na(e.state,n)},class:"cm-cursorLayer"});function Na(n,e){e.style.animationDuration=n.facet(Vi).cursorBlinkRate+"ms"}var kp=Zh({above:!1,markers(n){return n.state.selection.ranges.map(e=>e.empty?[]:Wi.forRange(n,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||_h(n)},class:"cm-selectionLayer"}),jh={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Uh&&(jh[".cm-line"].caretColor="transparent !important");var Tp=Le.highest(C.theme(jh)),Kh=M.define({map(n,e){return n==null?null:e.mapPos(n)}}),wi=z.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(Kh)?i.value:t,n)}}),vp=U.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(wi);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"),(n.startState.field(wi)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,e=n.state.field(wi),t=e!=null&&n.coordsAtPos(e);if(!t)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:t.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:t.bottom-t.top}}drawCursor(n){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;n?(this.cursor.style.left=n.left/e+"px",this.cursor.style.top=n.top/t+"px",this.cursor.style.height=n.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(wi)!=n&&this.view.dispatch({effects:Kh.of(n)})}},{eventHandlers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Jh(){return[wi,vp]}function Fa(n,e,t,i,s){e.lastIndex=0;for(let r=n.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,l)}function Pp(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let i=[];for(let{from:s,to:r}of t)s=Math.max(n.state.doc.lineAt(s).from,s-e),r=Math.min(n.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}var Kr=class{constructor(e){let{regexp:t,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,h,f)=>s(f,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,f)=>{let c=i(l,a,h);c&&f(h,h+l[0].length,c)};else if(i)this.addMatch=(l,a,h,f)=>f(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new Be,i=t.add.bind(t);for(let{from:s,to:r}of Pp(e,this.maxLength))Fa(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),i,s):t}updateRange(e,t,i,s){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let a=e.state.doc.lineAt(o),h=a.toa.from;o--)if(this.boundary.test(a.text[o-1-a.from])){f=o;break}for(;lu.push(O.range(g,m));if(a==h)for(this.regexp.lastIndex=f-a.from;(d=this.regexp.exec(a.text))&&d.indexthis.addMatch(m,e,g,p));t=t.update({filterFrom:f,filterTo:c,filter:(g,m)=>gc,add:u})}}return t}},Jr=/x/.unicode!=null?"gu":"g",Cp=new RegExp(`[\0-\b
--\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\u2066\u2067\u2069\uFEFF\uFFF9-\uFFFC]`,Jr),Ap={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"},xr=null;function Qp(){var n;if(xr==null&&typeof document<"u"&&document.body){let e=document.body.style;xr=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return xr||!1}var Rn=P.define({combine(n){let e=ce(n,{render:null,specialChars:Cp,addSpecialChars:null});return(e.replaceTabs=!Qp())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Jr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Jr)),e}});function ef(n={}){return[Rn.of(n),Rp()]}var Ga=null;function Rp(){return Ga||(Ga=U.fromClass(class{constructor(n){this.view=n,this.decorations=R.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(Rn)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Kr({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=J(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,a=tt(o.text,l,i-o.from);return R.replace({widget:new to((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=R.replace({widget:new eo(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(Rn);n.startState.facet(Rn)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}var Mp="\u2022";function qp(n){return n>=32?Mp:n==10?"\u2424":String.fromCharCode(9216+n)}var eo=class extends ye{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=qp(this.code),i=e.state.phrase("Control character")+" "+(Ap[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}},to=class extends ye{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}};function tf(){return Dp}var Ep=R.line({class:"cm-activeLine"}),Dp=U.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>e&&(t.push(Ep.range(s.from)),e=s.from)}return R.set(t)}},{decorations:n=>n.decorations});var io=2e3;function $p(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>io||t.off>io||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=s;a++){let h=n.doc.line(a);h.length<=l&&r.push(S.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),f=gn(h.text,o,n.tabSize,!0);if(f<0)r.push(S.cursor(h.to));else{let c=gn(h.text,l,n.tabSize);r.push(S.range(h.from+f,h.from+c))}}}return r}function Wp(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function za(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=n.state.doc.lineAt(t),s=t-i.from,r=s>io?-1:s==i.length?Wp(n,e.clientX):tt(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function Vp(n,e){let t=za(n,e),i=n.state.selection;return t?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(t.line).from),o=s.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=za(n,s);if(!l)return i;let a=$p(n.state,t,l);return a.length?o?S.create(a.concat(i.ranges)):S.create(a):i}}:null}function nf(n){let e=n?.eventFilter||(t=>t.altKey&&t.button==0);return C.mouseSelectionStyle.of((t,i)=>e(i)?Vp(t,i):null)}var Bp={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},Lp={style:"cursor: crosshair"};function sf(n={}){let[e,t]=Bp[n.key||"Alt"],i=U.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventHandlers:{keydown(s){this.set(s.keyCode==e||t(s))},keyup(s){(s.keyCode==e||!t(s))&&this.set(!1)},mousemove(s){this.set(t(s))}}});return[i,C.contentAttributes.of(s=>{var r;return!((r=s.plugin(i))===null||r===void 0)&&r.isDown?Lp:null})]}var vn="-10000px",zn=class{constructor(e,t,i){this.facet=t,this.createTooltipView=i,this.input=e.state.facet(t),this.tooltips=this.input.filter(s=>s),this.tooltipViews=this.tooltips.map(i)}update(e){var t;let i=e.state.facet(this.facet),s=i.filter(o=>o);if(i===this.input){for(let o of this.tooltipViews)o.update&&o.update(e);return!1}let r=[];for(let o=0;o{var e,t,i;return{position:A.ios?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Xp}}}),Za=new WeakMap,rf=U.fromClass(class{constructor(n){this.view=n,this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Sr);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new zn(n,Bi,t=>this.createTooltip(t)),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Sr);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n){let e=n.create(this.view);if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",e.dom.appendChild(t)}return e.dom.style.position=this.position,e.dom.style.top=vn,this.container.appendChild(e.dom),e.mount&&e.mount(this.view),e}destroy(){var n,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let t of this.manager.tooltipViews)t.dom.remove(),(n=t.destroy)===null||n===void 0||n.call(t);(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect(),e=1,t=1,i=!1;if(this.position=="fixed"){let s=this.manager.tooltipViews;i=s.length>0&&s[0].dom.offsetParent!=this.container.ownerDocument.body}if(i||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(e=s.width/this.parent.offsetWidth,t=s.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((s,r)=>{let o=this.manager.tooltipViews[r];return o.getCoords?o.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(Sr).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:i}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:t,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l=Math.min(t.bottom,i.bottom)||c.rightMath.min(t.right,i.right)+.1){f.style.top=vn;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,m=(e=Za.get(h))!==null&&e!==void 0?e:u.bottom-u.top,O=h.offset||Yp,k=this.view.textDirection==F.LTR,v=u.width>i.right-i.left?k?i.left:i.right-u.width:k?Math.min(c.left-(d?14:0)+O.x,i.right-g):Math.max(i.left,c.left-g+(d?14:0)-O.x),b=!!a.above;!a.strictSide&&(b?c.top-(u.bottom-u.top)-O.yi.bottom)&&b==i.bottom-c.bottom>c.top-i.top&&(b=!b);let y=(b?c.top-i.top:i.bottom-c.bottom)-p;if(yv&&$.topw&&(w=b?$.top-m-2-p:$.bottom+p+2);if(this.position=="absolute"?(f.style.top=(w-n.parent.top)/r+"px",f.style.left=(v-n.parent.left)/s+"px"):(f.style.top=w/r+"px",f.style.left=v/s+"px"),d){let $=c.left+(k?O.x:-O.x)-(v+14-7);d.style.left=$/s+"px"}h.overlap!==!0&&o.push({left:v,top:w,right:Q,bottom:w+m}),f.classList.toggle("cm-tooltip-above",b),f.classList.toggle("cm-tooltip-below",!b),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=vn}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Ip=C.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"}}}),Yp={x:0,y:0},Bi=P.define({enables:[rf,Ip]}),Zn=P.define(),no=class n{static create(e){return new n(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new zn(e,Zn,t=>this.createHostedView(t))}createHostedView(e){let t=e.create(this.view);return t.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(t.dom),this.mounted&&t.mount&&t.mount(this.view),t}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}},Np=Bi.compute([Zn],n=>{let e=n.facet(Zn).filter(t=>t);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.filter(t=>t.end!=null).map(t=>t.end)),create:no.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),so=class{constructor(e,t,i,s,r){this.view=e,this.source=t,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)return;let e=Date.now()-this.lastMove.time;el.bottom||t.xl.right+e.defaultCharacterWidth)return;let a=e.bidiSpans(e.state.doc.lineAt(s)).find(f=>f.from<=s&&f.to>=s),h=a&&a.dir==F.RTL?-1:1;r=t.x{this.pending==l&&(this.pending=null,a&&e.dispatch({effects:this.setHover.of(a)}))},a=>ge(e.state,a,"hover tooltip"))}else o&&e.dispatch({effects:this.setHover.of(o)})}mousemove(e){var t;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let i=this.active;if(i&&!Ua(this.lastMove.target)||this.pending){let{pos:s}=i||this.pending,r=(t=i?.end)!==null&&t!==void 0?t:s;(s==r?this.view.posAtCoords(this.lastMove)!=s:!Fp(this.view,s,r,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of(null)}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1,this.active&&!Ua(e.relatedTarget)&&this.view.dispatch({effects:this.setHover.of(null)})}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}};function Ua(n){for(let e=n;e;e=e.parentNode)if(e.nodeType==1&&e.classList.contains("cm-tooltip"))return!0;return!1}function Fp(n,e,t,i,s,r){let o=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(o.left>i||o.rights||Math.min(o.bottom,l)=e&&a<=t}function of(n,e={}){let t=M.define(),i=z.define({create(){return null},update(s,r){if(s&&(e.hideOnChange&&(r.docChanged||r.selection)||e.hideOn&&e.hideOn(r,s)))return null;if(s&&r.docChanged){let o=r.changes.mapPos(s.pos,-1,se.TrackDel);if(o==null)return null;let l=Object.assign(Object.create(null),s);l.pos=o,s.end!=null&&(l.end=r.changes.mapPos(s.end)),s=l}for(let o of r.effects)o.is(t)&&(s=o.value),o.is(Gp)&&(s=null);return s},provide:s=>Zn.from(s)});return[i,U.define(s=>new so(s,n,i,t,e.hoverTime||300)),Np]}function po(n,e){let t=n.plugin(rf);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}var Gp=M.define();var Ha=P.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Rt(n,e){let t=n.plugin(lf),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}var lf=U.fromClass(class{constructor(n){this.input=n.state.facet(Qt),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(Ha);this.top=new jt(n,!0,e.topContainer),this.bottom=new jt(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(Ha);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new jt(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new jt(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(Qt);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),f;h<0?(f=a(n.view),l.push(f)):(f=this.panels[h],f.update&&f.update(n)),s.push(f),(f.top?r:o).push(f)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>C.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})}),jt=class{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=_a(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=_a(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}};function _a(n){let e=n.nextSibling;return n.remove(),e}var Qt=P.define({enables:lf}),Ce=class extends Ve{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Ce.prototype.elementClass="";Ce.prototype.toDOM=void 0;Ce.prototype.mapMode=se.TrackBefore;Ce.prototype.startSide=Ce.prototype.endSide=-1;Ce.prototype.point=!0;var Mn=P.define(),zp={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>V.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},Pi=P.define();function mo(n){return[af(),Pi.of(Object.assign(Object.assign({},zp),n))]}var ro=P.define({combine:n=>n.some(e=>e)});function af(n){let e=[Zp];return n&&n.fixed===!1&&e.push(ro.of(!0)),e}var Zp=U.fromClass(class{constructor(n){this.view=n,this.prevViewport=n.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=n.state.facet(Pi).map(e=>new Un(n,e));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!n.state.facet(ro),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}n.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(ro)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&this.dom.remove();let t=V.iter(this.view.state.facet(Mn),this.view.viewport.from),i=[],s=this.gutters.map(r=>new lo(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==Z.Text&&o){oo(t,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==Z.Text){oo(t,i,r.from);for(let o of s)o.line(this.view,r,i)}for(let r of s)r.finish();n&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(n){let e=n.startState.facet(Pi),t=n.state.facet(Pi),i=n.docChanged||n.heightChanged||n.viewportChanged||!V.eq(n.startState.facet(Mn),n.state.facet(Mn),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new Un(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove()}},{provide:n=>C.scrollMargins.of(e=>{let t=e.plugin(n);return!t||t.gutters.length==0||!t.fixed?null:e.textDirection==F.LTR?{left:t.dom.offsetWidth*e.scaleX}:{right:t.dom.offsetWidth*e.scaleX}})});function ja(n){return Array.isArray(n)?n:[n]}function oo(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}var lo=class{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=V.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:s}=this,r=t.top-this.height;if(this.i==s.elements.length){let o=new Hn(e,t.height,r,i);s.elements.push(o),s.dom.appendChild(o.dom)}else s.elements[this.i].update(e,t.height,r,i);this.height=t.bottom,this.i++}line(e,t,i){let s=[];oo(this.cursor,s,t.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t);i&&this.addElement(e,t,[i])}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Un=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 i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,s)&&s.preventDefault()});this.markers=ja(t.markers(e)),t.initialSpacer&&(this.spacer=new Hn(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=ja(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!V.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}},Hn=class{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.height=t,this.dom.style.height=t/e.scaleY+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i/e.scaleY+"px":""),Up(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=rr(l,a,h)||o(l,a,h):o}return i}})}}),Ci=class extends Ce{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function br(n,e){return n.state.facet(Kt).formatNumber(e,n.state)}var _p=Pi.compute([Kt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(Hp)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new Ci(br(e,e.state.doc.lineAt(t.from).number))},widgetMarker:()=>null,lineMarkerChange:e=>e.startState.facet(Kt)!=e.state.facet(Kt),initialSpacer(e){return new Ci(br(e,Ka(e.state.doc.lines)))},updateSpacer(e,t){let i=br(t.view,Ka(t.view.state.doc.lines));return i==e.number?e:new Ci(i)},domEventHandlers:n.facet(Kt).domEventHandlers}));function hf(n={}){return[Kt.of(n),af(),_p]}function Ka(n){let e=9;for(;e{let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(jp.range(s)))}return V.of(e)});function ff(){return Kp}var Jp=0,Li=class{constructor(e,t){this.from=e,this.to=t}},q=class{constructor(e={}){this.id=Jp++,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=ue.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}};q.closedBy=new q({deserialize:n=>n.split(" ")});q.openedBy=new q({deserialize:n=>n.split(" ")});q.group=new q({deserialize:n=>n.split(" ")});q.contextHash=new q({perNode:!0});q.lookAhead=new q({perNode:!0});q.mounted=new q({perNode:!0});var em=Object.create(null),ue=class n{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):em,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new n(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}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(q.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(q.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}};ue.none=new ue("",Object.create(null),0,8);var Xi=class n{constructor(e){this.types=e;for(let t=0;t0;for(let a=this.cursor(o|H.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(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:bo(ue.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new n(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new n(ue.none,t,i,s)))}static build(e){return tm(e)}};j.empty=new j(ue.none,[],[],0);var go=class n{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 n(this.buffer,this.index)}},Mt=class n{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ue.none}toString(){let e=[];for(let t=0;t0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l=e&&te;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function pf(n,e){let t=n.childBefore(e);for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(n=t,t=i.prevSibling):t=i}return n}function ei(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to0?l.length:-1;e!=h;e+=t){let f=l[e],c=a[e]+o.from;if(df(s,i,c,c+f.length)){if(f instanceof Mt){if(r&H.ExcludeBuffers)continue;let u=f.findChild(0,f.buffer.length,t,i-c,s);if(u>-1)return new qt(new Oo(o,f,e,c),null,u)}else if(r&H.IncludeAnonymous||!f.type.isAnonymous||So(f)){let u;if(!(r&H.IgnoreMounts)&&f.props&&(u=f.prop(q.mounted))&&!u.overlay)return new n(u.tree,c,e,o);let d=new n(f,c,e,o);return r&H.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?f.children.length-1:0,t,i,s)}}}if(r&H.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,i=0){let s;if(!(i&H.IgnoreOverlays)&&(s=this._tree.prop(q.mounted))&&s.overlay){let r=e-this.from;for(let{from:o,to:l}of s.overlay)if((t>0?o<=r:o=r:l>r))return new n(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}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}cursor(e=0){return new ti(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return ei(this,e,t,!1)}resolveInner(e,t=0){return ei(this,e,t,!0)}enterUnfinishedNodesBefore(e){return pf(this,e)}getChild(e,t=null,i=null){let s=es(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return es(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return ts(this,e)}};function es(n,e,t,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(;!s.type.is(t);)if(!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function ts(n,e,t=e.length-1){for(let i=n.parent;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}var Oo=class{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}},qt=class n{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,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new n(this.context,this,r)}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,i=0){if(i&H.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new n(this.context,this,r)}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 n(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 n(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new ti(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1];e.push(i.slice(s,r,o)),t.push(0)}return new j(this.type,e,t,this.to-this.from)}resolve(e,t=0){return ei(this,e,t,!1)}resolveInner(e,t=0){return ei(this,e,t,!0)}enterUnfinishedNodesBefore(e){return pf(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let s=es(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return es(this,e,t,i)}get node(){return this}matchContext(e){return ts(this,e)}},ti=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 st)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.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:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof st?(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,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}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,i=this.mode){return this.buffer?i&H.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&H.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&H.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,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<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,i,{buffer:s}=this;if(s){if(e>0){if(this.index-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&H.IncludeAnonymous||l instanceof Mt||!l.type.isAnonymous||So(l))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==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}for(let s=i;s=0;r--){if(r<0)return ts(this.node,e,s);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}};function So(n){return n.children.some(e=>e instanceof Mt||!e.type.isAnonymous||So(e))}function tm(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=1024,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new go(t,t.length):t,a=i.types,h=0,f=0;function c(b,y,w,Q,$){let{id:E,start:D,end:Y,size:ie}=l,ae=f;for(;ie<0;)if(l.next(),ie==-1){let xe=r[E];w.push(xe),Q.push(D-b);return}else if(ie==-3){h=E;return}else if(ie==-4){f=E;return}else throw new RangeError(`Unrecognized record size: ${ie}`);let Oe=a[E],le,he,Ne=D-b;if(Y-D<=s&&(he=g(l.pos-y,$))){let xe=new Uint16Array(he.size-he.skip),_=l.pos-he.size,ne=xe.length;for(;l.pos>_;)ne=m(he.start,xe,ne);le=new Mt(xe,Y-he.start,i),Ne=he.start-b}else{let xe=l.pos-ie;l.next();let _=[],ne=[],kt=E>=o?E:-1,It=0,rn=Y;for(;l.pos>xe;)kt>=0&&l.id==kt&&l.size>=0?(l.end<=rn-s&&(d(_,ne,D,It,l.end,rn,kt,ae),It=_.length,rn=l.end),l.next()):c(D,xe,_,ne,kt);if(kt>=0&&It>0&&It<_.length&&d(_,ne,D,It,D,rn,kt,ae),_.reverse(),ne.reverse(),kt>-1&&It>0){let Bl=u(Oe);le=bo(Oe,_,ne,0,_.length,0,Y-D,Bl,Bl)}else le=p(Oe,_,ne,Y-D,ae-Y)}w.push(le),Q.push(Ne)}function u(b){return(y,w,Q)=>{let $=0,E=y.length-1,D,Y;if(E>=0&&(D=y[E])instanceof j){if(!E&&D.type==b&&D.length==Q)return D;(Y=D.prop(q.lookAhead))&&($=w[E]+D.length+Y)}return p(b,y,w,Q,$)}}function d(b,y,w,Q,$,E,D,Y){let ie=[],ae=[];for(;b.length>Q;)ie.push(b.pop()),ae.push(y.pop()+w-$);b.push(p(i.types[D],ie,ae,E-$,Y-E)),y.push($-w)}function p(b,y,w,Q,$=0,E){if(h){let D=[q.contextHash,h];E=E?[D].concat(E):[D]}if($>25){let D=[q.lookAhead,$];E=E?[D].concat(E):[D]}return new j(b,y,w,Q,E)}function g(b,y){let w=l.fork(),Q=0,$=0,E=0,D=w.end-s,Y={size:0,start:0,skip:0};e:for(let ie=w.pos-b;w.pos>ie;){let ae=w.size;if(w.id==y&&ae>=0){Y.size=Q,Y.start=$,Y.skip=E,E+=4,Q+=4,w.next();continue}let Oe=w.pos-ae;if(ae<0||Oe=o?4:0,he=w.start;for(w.next();w.pos>Oe;){if(w.size<0)if(w.size==-3)le+=4;else break e;else w.id>=o&&(le+=4);w.next()}$=he,Q+=ae,E+=le}return(y<0||Q==b)&&(Y.size=Q,Y.start=$,Y.skip=E),Y.size>4?Y:void 0}function m(b,y,w){let{id:Q,start:$,end:E,size:D}=l;if(l.next(),D>=0&&Q4){let ie=l.pos-(D-4);for(;l.pos>ie;)w=m(b,y,w)}y[--w]=Y,y[--w]=E-b,y[--w]=$-b,y[--w]=Q}else D==-3?h=Q:D==-4&&(f=Q);return w}let O=[],k=[];for(;l.pos>0;)c(n.start||0,n.bufferStart||0,O,k,-1);let v=(e=n.length)!==null&&e!==void 0?e:O.length?k[0]+O[0].length:0;return new j(a[n.topID],O.reverse(),k.reverse(),v)}var uf=new WeakMap;function Jn(n,e){if(!n.isAnonymous||e instanceof Mt||e.type!=n)return 1;let t=uf.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof j)){t=1;break}t+=Jn(n,i)}uf.set(e,t)}return t}function bo(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p=f)break;w+=Q}if(v==b+1){if(w>f){let Q=p[b];d(Q.children,Q.positions,0,Q.children.length,g[b]+k);continue}c.push(p[b])}else{let Q=g[v-1]+p[v-1].length-y;c.push(bo(n,p,g,b,v,y,Q,null,a))}u.push(y+k-r)}}return d(e,t,i,s,0),(l||a)(c,u,o)}var is=class{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let s=this.map.get(e);s||this.map.set(e,s=new Map),s.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof qt?this.setBuffer(e.context.buffer,e.index,t):e instanceof st&&this.map.set(e.tree,t)}get(e){return e instanceof qt?this.getBuffer(e.context.buffer,e.index):e instanceof st?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)}},Et=class n{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new n(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let f=l=i)for(;o&&o.from=u.from||c<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,c)-h;u=d>=p?null:new n(d,p,u.tree,u.offset+h,l>0,!!f)}if(u&&s.push(u),o.to>c)break;o=rnew Li(s.from,s.to)):[new Li(0,0)]:[new Li(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}},xo=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)}};var Ex=new q({perNode:!0});var im=0,je=class n{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=im++}static define(e){if(e?.base)throw new Error("Can not derive from a modified tag");let t=new n([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new os;return t=>t.modified.indexOf(e)>-1?t:os.get(t.base||t,t.modified.concat(e).sort((i,s)=>i.id-s.id))}},nm=0,os=class n{constructor(){this.instances=[],this.id=nm++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&sm(t,l.modified));if(i)return i;let s=[],r=new je(s,e,t);for(let l of t)l.instances.push(r);let o=rm(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(n.get(l,a));return r}};function sm(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function rm(n){let e=[[]];for(let t=0;ti.length-t.length)}function ls(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let c=0;;){if(l=="..."&&c>0&&c+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==s.length)break;let d=s[c++];if(c==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(c)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let f=new ni(i,o,a>0?r.slice(0,a):null);e[h]=f.sort(e[h])}}return Of.add(e)}var Of=new q,ni=class{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth{let o=s;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function om(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function xf(n,e,t,i=0,s=n.length){let r=new wo(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}var wo=class{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,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,i,s,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,f=lm(e)||ni.empty,c=om(r,f.tags);if(c&&(h&&(h+=" "),h+=c,f.mode==1&&(s+=(s?" ":"")+c)),this.startSpan(Math.max(t,l),h),f.opaque)return;let u=e.tree&&e.tree.prop(q.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=e.firstChild();for(let m=0,O=l;;m++){let k=m=v||!e.nextSibling())););if(!k||v>i)break;O=k.to+l,O>t&&(this.highlightRange(d.cursor(),Math.max(t,k.from+l),Math.min(i,O),"",p),this.startSpan(Math.min(i,O),h))}g&&e.parent()}else if(e.firstChild()){u&&(s="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}};function lm(n){let e=n.type.prop(Of);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}var T=je.define,ns=T(),pt=T(),mf=T(pt),gf=T(pt),mt=T(),ss=T(mt),yo=T(mt),_e=T(),Dt=T(_e),Ue=T(),He=T(),ko=T(),Ii=T(ko),rs=T(),x={comment:ns,lineComment:T(ns),blockComment:T(ns),docComment:T(ns),name:pt,variableName:T(pt),typeName:mf,tagName:T(mf),propertyName:gf,attributeName:T(gf),className:T(pt),labelName:T(pt),namespace:T(pt),macroName:T(pt),literal:mt,string:ss,docString:T(ss),character:T(ss),attributeValue:T(ss),number:yo,integer:T(yo),float:T(yo),bool:T(mt),regexp:T(mt),escape:T(mt),color:T(mt),url:T(mt),keyword:Ue,self:T(Ue),null:T(Ue),atom:T(Ue),unit:T(Ue),modifier:T(Ue),operatorKeyword:T(Ue),controlKeyword:T(Ue),definitionKeyword:T(Ue),moduleKeyword:T(Ue),operator:He,derefOperator:T(He),arithmeticOperator:T(He),logicOperator:T(He),bitwiseOperator:T(He),compareOperator:T(He),updateOperator:T(He),definitionOperator:T(He),typeOperator:T(He),controlOperator:T(He),punctuation:ko,separator:T(ko),bracket:Ii,angleBracket:T(Ii),squareBracket:T(Ii),paren:T(Ii),brace:T(Ii),content:_e,heading:Dt,heading1:T(Dt),heading2:T(Dt),heading3:T(Dt),heading4:T(Dt),heading5:T(Dt),heading6:T(Dt),contentSeparator:T(_e),list:T(_e),quote:T(_e),emphasis:T(_e),strong:T(_e),link:T(_e),monospace:T(_e),strikethrough:T(_e),inserted:T(),deleted:T(),changed:T(),invalid:T(),meta:rs,documentMeta:T(rs),annotation:T(rs),processingInstruction:T(rs),definition:je.defineModifier(),constant:je.defineModifier(),function:je.defineModifier(),standard:je.defineModifier(),local:je.defineModifier(),special:je.defineModifier()},Wx=To([{tag:x.link,class:"tok-link"},{tag:x.heading,class:"tok-heading"},{tag:x.emphasis,class:"tok-emphasis"},{tag:x.strong,class:"tok-strong"},{tag:x.keyword,class:"tok-keyword"},{tag:x.atom,class:"tok-atom"},{tag:x.bool,class:"tok-bool"},{tag:x.url,class:"tok-url"},{tag:x.labelName,class:"tok-labelName"},{tag:x.inserted,class:"tok-inserted"},{tag:x.deleted,class:"tok-deleted"},{tag:x.literal,class:"tok-literal"},{tag:x.string,class:"tok-string"},{tag:x.number,class:"tok-number"},{tag:[x.regexp,x.escape,x.special(x.string)],class:"tok-string2"},{tag:x.variableName,class:"tok-variableName"},{tag:x.local(x.variableName),class:"tok-variableName tok-local"},{tag:x.definition(x.variableName),class:"tok-variableName tok-definition"},{tag:x.special(x.variableName),class:"tok-variableName2"},{tag:x.definition(x.propertyName),class:"tok-propertyName tok-definition"},{tag:x.typeName,class:"tok-typeName"},{tag:x.namespace,class:"tok-namespace"},{tag:x.className,class:"tok-className"},{tag:x.macroName,class:"tok-macroName"},{tag:x.propertyName,class:"tok-propertyName"},{tag:x.operator,class:"tok-operator"},{tag:x.comment,class:"tok-comment"},{tag:x.meta,class:"tok-meta"},{tag:x.invalid,class:"tok-invalid"},{tag:x.punctuation,class:"tok-punctuation"}]);var vo,si=new q;function am(n){return P.define({combine:n?e=>e.concat(n):void 0})}var hm=new q,Ae=class{constructor(e,t,i=[],s=""){this.data=e,this.name=s,X.prototype.hasOwnProperty("tree")||Object.defineProperty(X.prototype,"tree",{get(){return K(this)}}),this.parser=t,this.extension=[gt.of(this),X.languageData.of((r,o,l)=>{let a=Sf(r,o,l),h=a.type.prop(si);if(!h)return[];let f=r.facet(h),c=a.type.prop(hm);if(c){let u=a.resolve(o-a.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(e,t,i=-1){return Sf(e,t,i).type.prop(si)==this.data}findRegions(e){let t=e.facet(gt);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(si)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(q.mounted);if(l){if(l.tree.prop(si)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;ai.isTop?t:void 0)]}),e.name)}configure(e,t){return new n(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}};function K(n){let e=n.field(Ae.state,!1);return e?e.tree:j.empty}var Qo=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 i=this.cursorPos-this.string.length;return e=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}},Yi=null,Ro=class n{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new n(e,t,[],j.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Qo(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=j.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}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(Et.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Yi;Yi=this;try{return e()}finally{Yi=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=bf(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,f,c,u)=>a.push({fromA:h,toA:f,fromB:c,toB:u})),i=Et.applyChanges(i,a),s=j.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let f=e.mapPos(h.from,1),c=e.mapPos(h.to,-1);fe.from&&(this.fragments=bf(this.fragments,s,r),this.skipped.splice(i--,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 ii{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=Yi;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new j(ue.none,[],[],o-r)},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 Yi}};function bf(n,e,t){return Et.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}var Fi=class n{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),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new n(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Ro.create(e.facet(gt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new n(i)}};Ae.state=z.define({create:Fi.init,update(n,e){for(let t of e.effects)if(t.is(Ae.setState))return t.value;return e.startState.facet(gt)!=e.state.facet(gt)?Fi.init(e.state):n.apply(e)}});var Tf=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Tf=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var Po=typeof navigator<"u"&&(!((vo=navigator.scheduling)===null||vo===void 0)&&vo.isInputPending)?()=>navigator.scheduling.isInputPending():null,fm=U.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(Ae.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Ae.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Tf(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnds+1e3,a=r.context.work(()=>Po&&Po()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Ae.setState.of(new Fi(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>ge(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),gt=P.define({combine(n){return n.length?n[0]:null},enables:n=>[Ae.state,fm,C.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]}),hs=class{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}};var cm=P.define(),Ot=P.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Gi(n){let e=n.facet(Ot);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function ri(n,e){let t="",i=n.tabSize,s=n.facet(Ot)[0];if(s==" "){for(;e>=i;)t+=" ",e-=i;s=" "}for(let r=0;r=e?um(n,t,e):null}var $t=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=Gi(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return tt(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},Vo=new q;function um(n,e,t){return vf(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,n)}function dm(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function pm(n){let e=n.type.prop(Vo);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(q.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>Pf(o,!0,1,void 0,r&&!dm(o)?s.from:void 0)}return n.parent==null?mm:null}function vf(n,e,t){for(;n;n=n.parent){let i=pm(n);if(i)return i(Mo.create(t,e,n))}return null}function mm(){return 0}var Mo=class n extends $t{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.node=i}static create(e,t,i){return new n(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(gm(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){let e=this.node.parent;return e?vf(e,this.pos,this.base):0}};function gm(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function Om(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.fromPf(i,e,t,n)}function Pf(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=e?Om(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}var xm=200;function Cf(){return X.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,s=t.lineAt(i);if(i>s.from+xm)return n;let r=t.sliceString(s.from,i);if(!e.some(h=>h.test(r)))return n;let{state:o}=n,l=-1,a=[];for(let{head:h}of o.selection.ranges){let f=o.doc.lineAt(h);if(f.from==l)continue;l=f.from;let c=ds(o,f.from);if(c==null)continue;let u=/^\s*/.exec(f.text)[0],d=ri(o,c);u!=d&&a.push({from:f.from,to:f.from+u.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}var Sm=P.define(),Bo=new q;function Af(n){let e=n.firstChild,t=n.lastChild;return e&&e.tot)continue;if(r&&o.from=e&&a.to>t&&(r=a)}}return r}function ym(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function fs(n,e,t){for(let i of n.facet(Sm)){let s=i(n,e,t);if(s)return s}return bm(n,e,t)}function Qf(n,e){let t=e.mapPos(n.from,1),i=e.mapPos(n.to,-1);return t>=i?void 0:{from:t,to:i}}var ms=M.define({map:Qf}),zi=M.define({map:Qf});function Rf(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(n.lineBlockAt(t));return e}var Wt=z.define({create(){return R.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)if(t.is(ms)&&!wm(n,t.value.from,t.value.to)){let{preparePlaceholder:i}=e.state.facet(Lo),s=i?R.replace({widget:new qo(i(e.state,t.value))}):yf;n=n.update({add:[s.range(t.value.from,t.value.to)]})}else t.is(zi)&&(n=n.update({filter:(i,s)=>t.value.from!=i||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));if(e.selection){let t=!1,{head:i}=e.selection.main;n.between(i,i,(s,r)=>{si&&(t=!0)}),t&&(n=n.update({filterFrom:i,filterTo:i,filter:(s,r)=>r<=i||s>=i}))}return n},provide:n=>C.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(i,s)=>{t.push(i,s)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t{(!s||s.from>r)&&(s={from:r,to:o})}),s}function wm(n,e,t){let i=!1;return n.between(e,e,(s,r)=>{s==e&&r==t&&(i=!0)}),i}function Mf(n,e){return n.field(Wt,!1)?e:e.concat(M.appendConfig.of(Df()))}var km=n=>{for(let e of Rf(n)){let t=fs(n.state,e.from,e.to);if(t)return n.dispatch({effects:Mf(n.state,[ms.of(t),qf(n,t)])}),!0}return!1},Tm=n=>{if(!n.state.field(Wt,!1))return!1;let e=[];for(let t of Rf(n)){let i=cs(n.state,t.from,t.to);i&&e.push(zi.of(i),qf(n,i,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function qf(n,e,t=!0){let i=n.state.doc.lineAt(e.from).number,s=n.state.doc.lineAt(e.to).number;return C.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${n.state.phrase("to")} ${s}.`)}var vm=n=>{let{state:e}=n,t=[];for(let i=0;i{let e=n.state.field(Wt,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(i,s)=>{t.push(zi.of({from:i,to:s}))}),n.dispatch({effects:t}),!0};var Ef=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:km},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:Tm},{key:"Ctrl-Alt-[",run:vm},{key:"Ctrl-Alt-]",run:Pm}],Cm={placeholderDOM:null,preparePlaceholder:null,placeholderText:"\u2026"},Lo=P.define({combine(n){return ce(n,Cm)}});function Df(n){let e=[Wt,Qm];return n&&e.push(Lo.of(n)),e}function $f(n,e){let{state:t}=n,i=t.facet(Lo),s=o=>{let l=n.lineBlockAt(n.posAtDOM(o.target)),a=cs(n.state,l.from,l.to);a&&n.dispatch({effects:zi.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(n,s,e);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}var yf=R.replace({widget:new class extends ye{toDOM(n){return $f(n,null)}}}),qo=class extends ye{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return $f(e,this.value)}},Am={openText:"\u2304",closedText:"\u203A",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1},Ni=class extends Ce{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}};function Wf(n={}){let e=Object.assign(Object.assign({},Am),n),t=new Ni(e,!0),i=new Ni(e,!1),s=U.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(gt)!=o.state.facet(gt)||o.startState.field(Wt,!1)!=o.state.field(Wt,!1)||K(o.startState)!=K(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new Be;for(let a of o.viewportLineBlocks){let h=cs(o.state,a.from,a.to)?i:fs(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:r}=e;return[s,mo({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||V.empty},initialSpacer(){return new Ni(e,!1)},domEventHandlers:Object.assign(Object.assign({},r),{click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let h=cs(o.state,l.from,l.to);if(h)return o.dispatch({effects:zi.of(h)}),!0;let f=fs(o.state,l.from,l.to);return f?(o.dispatch({effects:ms.of(f)}),!0):!1}})}),Df()]}var Qm=C.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}}),us=class n{constructor(e,t){this.specs=e;let i;function s(l){let a=Ee.newName();return(i||(i=Object.create(null)))["."+a]=l,a}let r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof Ae?l=>l.prop(si)==o.data:o?l=>l==o:void 0,this.style=To(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new Ee(i):null,this.themeType=t.themeType}static define(e,t){return new n(e,t||{})}},Eo=P.define(),Vf=P.define({combine(n){return n.length?[n[0]]:null}});function Co(n){let e=n.facet(Eo);return e.length?e:n.facet(Vf)}function Bf(n,e){let t=[Rm],i;return n instanceof us&&(n.module&&t.push(C.styleModule.of(n.module)),i=n.themeType),e?.fallback?t.push(Vf.of(n)):i?t.push(Eo.computeN([C.darkTheme],s=>s.facet(C.darkTheme)==(i=="dark")?[n]:[])):t.push(Eo.of(n)),t}var Do=class{constructor(e){this.markCache=Object.create(null),this.tree=K(e.state),this.decorations=this.buildDeco(e,Co(e.state))}update(e){let t=K(e.state),i=Co(e.state),s=i!=Co(e.startState);t.length{i.add(o,l,this.markCache[a]||(this.markCache[a]=R.mark({class:a})))},s,r);return i.finish()}},Rm=Le.high(U.fromClass(Do,{decorations:n=>n.decorations})),Lf=us.define([{tag:x.meta,color:"#404740"},{tag:x.link,textDecoration:"underline"},{tag:x.heading,textDecoration:"underline",fontWeight:"bold"},{tag:x.emphasis,fontStyle:"italic"},{tag:x.strong,fontWeight:"bold"},{tag:x.strikethrough,textDecoration:"line-through"},{tag:x.keyword,color:"#708"},{tag:[x.atom,x.bool,x.url,x.contentSeparator,x.labelName],color:"#219"},{tag:[x.literal,x.inserted],color:"#164"},{tag:[x.string,x.deleted],color:"#a11"},{tag:[x.regexp,x.escape,x.special(x.string)],color:"#e40"},{tag:x.definition(x.variableName),color:"#00f"},{tag:x.local(x.variableName),color:"#30a"},{tag:[x.typeName,x.namespace],color:"#085"},{tag:x.className,color:"#167"},{tag:[x.special(x.variableName),x.macroName],color:"#256"},{tag:x.definition(x.propertyName),color:"#00c"},{tag:x.comment,color:"#940"},{tag:x.invalid,color:"#f00"}]),Mm=C.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Xf=1e4,If="()[]{}",Yf=P.define({combine(n){return ce(n,{afterCursor:!0,brackets:If,maxScanDistance:Xf,renderMatch:Dm})}}),qm=R.mark({class:"cm-matchingBracket"}),Em=R.mark({class:"cm-nonmatchingBracket"});function Dm(n){let e=[],t=n.matched?qm:Em;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}var $m=z.define({create(){return R.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(Yf);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=Xe(e.state,s.head,-1,i)||s.head>0&&Xe(e.state,s.head-1,1,i)||i.afterCursor&&(Xe(e.state,s.head,1,i)||s.headC.decorations.from(n)}),Wm=[$m,Mm];function Nf(n={}){return[Yf.of(n),Wm]}var Vm=new q;function $o(n,e,t){let i=n.prop(e<0?q.openedBy:q.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function Wo(n){let e=n.type.prop(Vm);return e?e(n.node):n}function Xe(n,e,t,i={}){let s=i.maxScanDistance||Xf,r=i.brackets||If,o=K(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=$o(a.type,t,r);if(h&&a.from0?e>=f.from&&ef.from&&e<=f.to))return Bm(n,e,t,a,f,h,r)}}return Lm(n,e,t,o,l.type,s,r)}function Bm(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},h=0,f=l?.cursor();if(f&&(t<0?f.childBefore(i.from):f.childAfter(i.to)))do if(t<0?f.to<=i.from:f.from>=i.to){if(h==0&&r.indexOf(f.type.name)>-1&&f.from0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},f=n.doc.iterRange(e,t>0?n.doc.length:0),c=0;for(let u=0;!f.next().done&&u<=r;){let d=f.value;t<0&&(u+=d.length);let p=e+u*t;for(let g=t>0?0:d.length-1,m=t>0?d.length:-1;g!=m;g+=t){let O=o.indexOf(d[g]);if(!(O<0||i.resolveInner(p+g,1).type!=s))if(O%2==0==t>0)c++;else{if(c==1)return{start:h,end:{from:p+g,to:p+g+1},matched:O>>1==a>>1};c--}}t>0&&(u+=d.length)}return f.done?{start:h,matched:!1}:null}var Xm=Object.create(null),wf=[ue.none];var kf=[],Im=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Im[n]=Ym(Xm,e);function Ao(n,e){kf.indexOf(n)>-1||(kf.push(n),console.warn(e))}function Ym(n,e){let t=null;for(let r of e.split(".")){let o=n[r]||x[r];o?typeof o=="function"?t?t=o(t):Ao(r,`Modifier ${r} used at start of tag`):t?Ao(r,`Tag ${r} used as modifier`):t=o:Ao(r,`Unknown highlighting tag ${r}`)}if(!t)return 0;let i=e.replace(/ /g,"_"),s=ue.define({id:wf.length,name:i,props:[ls({[i]:t})]});return wf.push(s),s.id}var Nm=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=zo(n.state,t.from);return i.line?Fm(n):i.block?zm(n):!1};function Go(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}var Fm=Go(Hm,0);var Gm=Go(jf,0);var zm=Go((n,e)=>jf(n,e,Um(e)),0);function zo(n,e){let t=n.languageDataAt("commentTokens",e);return t.length?t[0]:{}}var Zi=50;function Zm(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-Zi,i),o=n.sliceDoc(s,s+Zi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let f,c;s-i<=2*Zi?f=c=n.sliceDoc(i,s):(f=n.sliceDoc(i,i+Zi),c=n.sliceDoc(s-Zi,s));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function Um(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to),r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function jf(n,e,t=e.selection.ranges){let i=t.map(r=>zo(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>Zm(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;os&&(r==o||o>c.from)){s=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+h.length)==h?u:-1;ur.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:f,single:c}of i)(c||!f)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,f=h+a.length;o.text[f-o.from]==" "&&f++,r.push({from:h,to:f})}return{changes:r}}return null}var Io=Se.define(),_m=Se.define(),jm=P.define(),Kf=P.define({combine(n){return ce(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}});function Km(n){let e=0;return n.iterChangedRanges((t,i)=>e=i),e}var Jf=z.define({create(){return Vt.empty},update(n,e){let t=e.state.facet(Kf),i=e.annotation(Io);if(i){let a=e.docChanged?S.single(Km(e.changes)):void 0,h=Ie.fromTransaction(e,a),f=i.side,c=f==0?n.undone:n.done;return h?c=Os(c,c.length,t.minDepth,h):c=nc(c,e.startState.selection),new Vt(f==0?i.rest:c,f==0?c:i.rest)}let s=e.annotation(_m);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(oe.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=Ie.fromTransaction(e),o=e.annotation(oe.time),l=e.annotation(oe.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new Vt(n.done.map(Ie.fromJSON),n.undone.map(Ie.fromJSON))}});function ec(n={}){return[Jf,Kf.of(n),C.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?tc:e.inputType=="historyRedo"?Yo:null;return i?(e.preventDefault(),i(t)):!1}})]}function xs(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(Jf,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}var tc=xs(0,!1),Yo=xs(1,!1),Jm=xs(0,!0),eg=xs(1,!0);var Ie=class n{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new n(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new n(e.changes&&me.fromJSON(e.changes),[],e.mapped&&et.fromJSON(e.mapped),e.startSelection&&S.fromJSON(e.startSelection),e.selectionsAfter.map(S.fromJSON))}static fromTransaction(e,t){let i=$e;for(let s of e.startState.facet(jm)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new n(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,$e)}static selection(e){return new n(void 0,$e,void 0,void 0,e)}};function Os(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function tg(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a=h&&o<=f&&(i=!0)}}),i}function ig(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function ic(n,e){return n.length?e.length?n.concat(e):n:e}var $e=[],ng=200;function nc(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-ng));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),Os(n,n.length-1,1e9,t.setSelAfter(i)))}else return[Ie.selection([e])]}function sg(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Xo(n,e){if(!n.length)return n;let t=n.length,i=$e;for(;t;){let s=rg(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[Ie.selection(i)]:$e}function rg(n,e,t){let i=ic(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):$e,t);if(!n.changes)return Ie.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new Ie(s,M.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}var og=/^(input\.type|delete)($|\.)/,Vt=class n{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new n(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||og.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?n.moveByChar(t,e):Ss(t,e))}function de(n){return n.textDirectionAt(n.state.selection.main.head)==F.LTR}var oc=n=>rc(n,!de(n)),lc=n=>rc(n,de(n));function ac(n,e){return Ye(n,t=>t.empty?n.moveByGroup(t,e):Ss(t,e))}var lg=n=>ac(n,!de(n)),ag=n=>ac(n,de(n));var Kx=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function hg(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function bs(n,e,t){let i=K(n).resolveInner(e.head),s=t?q.closedBy:q.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;hg(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?Xe(n,i.from,1):Xe(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,S.cursor(l,t?-1:1)}var fg=n=>Ye(n,e=>bs(n.state,e,!de(n))),cg=n=>Ye(n,e=>bs(n.state,e,de(n)));function hc(n,e){return Ye(n,t=>{if(!t.empty)return Ss(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}var fc=n=>hc(n,!1),cc=n=>hc(n,!0);function uc(n){let e=n.scrollDOM.clientHeighto.empty?n.moveVertically(o,e,t.height):Ss(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottomdc(n,!1),No=n=>dc(n,!0);function xt(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=S.cursor(i.from+r))}return s}var ug=n=>Ye(n,e=>xt(n,e,!0)),dg=n=>Ye(n,e=>xt(n,e,!1)),pg=n=>Ye(n,e=>xt(n,e,!de(n))),mg=n=>Ye(n,e=>xt(n,e,de(n))),gg=n=>Ye(n,e=>S.cursor(n.lineBlockAt(e.head).from,1)),Og=n=>Ye(n,e=>S.cursor(n.lineBlockAt(e.head).to,-1));function xg(n,e,t){let i=!1,s=oi(n.selection,r=>{let o=Xe(n,r.head,-1)||Xe(n,r.head,1)||r.head>0&&Xe(n,r.head-1,1)||r.headxg(n,e,!1);function We(n,e){let t=oi(n.state.selection,i=>{let s=e(i);return S.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Ke(n.state,t)),!0)}function pc(n,e){return We(n,t=>n.moveByChar(t,e))}var mc=n=>pc(n,!de(n)),gc=n=>pc(n,de(n));function Oc(n,e){return We(n,t=>n.moveByGroup(t,e))}var bg=n=>Oc(n,!de(n)),yg=n=>Oc(n,de(n));var wg=n=>We(n,e=>bs(n.state,e,!de(n))),kg=n=>We(n,e=>bs(n.state,e,de(n)));function xc(n,e){return We(n,t=>n.moveVertically(t,e))}var Sc=n=>xc(n,!1),bc=n=>xc(n,!0);function yc(n,e){return We(n,t=>n.moveVertically(t,e,uc(n).height))}var Gf=n=>yc(n,!1),zf=n=>yc(n,!0),Tg=n=>We(n,e=>xt(n,e,!0)),vg=n=>We(n,e=>xt(n,e,!1)),Pg=n=>We(n,e=>xt(n,e,!de(n))),Cg=n=>We(n,e=>xt(n,e,de(n))),Ag=n=>We(n,e=>S.cursor(n.lineBlockAt(e.head).from)),Qg=n=>We(n,e=>S.cursor(n.lineBlockAt(e.head).to)),Zf=({state:n,dispatch:e})=>(e(Ke(n,{anchor:0})),!0),Uf=({state:n,dispatch:e})=>(e(Ke(n,{anchor:n.doc.length})),!0),Hf=({state:n,dispatch:e})=>(e(Ke(n,{anchor:n.selection.main.anchor,head:0})),!0),_f=({state:n,dispatch:e})=>(e(Ke(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),Rg=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Mg=({state:n,dispatch:e})=>{let t=ws(n).map(({from:i,to:s})=>S.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:S.create(t),userEvent:"select"})),!0},qg=({state:n,dispatch:e})=>{let t=oi(n.selection,i=>{var s;let r=K(n).resolveInner(i.head,1);for(;!(r.from=i.to||r.to>i.to&&r.from<=i.from||!(!((s=r.parent)===null||s===void 0)&&s.parent));)r=r.parent;return S.range(r.to,r.from)});return e(Ke(n,t)),!0},Eg=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=S.create([t.main]):t.main.empty||(i=S.create([S.cursor(t.main.head)])),i?(e(Ke(n,i)),!0):!1};function ys(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(o);ao&&(t="delete.forward",a=gs(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=gs(n,o,!1),l=gs(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:S.cursor(o)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?C.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function gs(n,e,t){if(n instanceof C)for(let i of n.state.facet(C.atomicRanges).map(s=>s(n)))i.between(e,e,(s,r)=>{se&&(e=t?r:s)});return e}var wc=(n,e)=>ys(n,t=>{let{state:i}=n,s=i.doc.lineAt(t),r,o;if(!e&&t>s.from&&twc(n,!1),kc=n=>wc(n,!0),Tc=(n,e)=>ys(n,t=>{let i=t,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=re(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),f=o(h);if(l!=null&&f!=l)break;(h!=" "||i!=t)&&(l=f),i=a}return i}),vc=n=>Tc(n,!1),Dg=n=>Tc(n,!0),Pc=n=>ys(n,e=>{let t=n.lineBlockAt(e).to;return eys(n,e=>{let t=n.lineBlockAt(e).from;return e>t?t:Math.max(0,e-1)});var Wg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:W.of(["",""])},range:S.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},Vg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:re(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:re(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:S.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function ws(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function Cc(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of ws(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(S.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(S.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:S.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var Bg=({state:n,dispatch:e})=>Cc(n,e,!1),Lg=({state:n,dispatch:e})=>Cc(n,e,!0);function Ac(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of ws(n))t?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});return e(n.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}var Xg=({state:n,dispatch:e})=>Ac(n,e,!1),Ig=({state:n,dispatch:e})=>Ac(n,e,!0),Yg=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(ws(e).map(({from:s,to:r})=>(s>0?s--:rn.moveVertically(s,!0)).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Ng(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=K(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(q.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}var Fg=Qc(!1),Gg=Qc(!0);function Qc(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&Ng(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new $t(e,{simulateBreak:r,simulateDoubleBreak:!!a}),f=ds(h,r);for(f==null&&(f=tt(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));ol.from&&r{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:S.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}var zg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new $t(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=Zo(n,(r,o,l)=>{let a=ds(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],f=ri(n,a);(h!=f||l.fromn.readOnly?!1:(e(n.update(Zo(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Ot)})}),{userEvent:"input.indent"})),!0),Mc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(Zo(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=tt(s,n.tabSize),o=0,l=ri(n,Math.max(0,r-Gi(n)));for(;o({mac:n.key,run:n.run,shift:n.shift}))),qc=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:fg,shift:wg},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:cg,shift:kg},{key:"Alt-ArrowUp",run:Bg},{key:"Shift-Alt-ArrowUp",run:Xg},{key:"Alt-ArrowDown",run:Lg},{key:"Shift-Alt-ArrowDown",run:Ig},{key:"Escape",run:Eg},{key:"Mod-Enter",run:Gg},{key:"Alt-l",mac:"Ctrl-l",run:Mg},{key:"Mod-i",run:qg,preventDefault:!0},{key:"Mod-[",run:Mc},{key:"Mod-]",run:Rc},{key:"Mod-Alt-\\",run:zg},{key:"Shift-Mod-k",run:Yg},{key:"Shift-Mod-\\",run:Sg},{key:"Mod-/",run:Nm},{key:"Alt-A",run:Gm}].concat(Ug),Ec={key:"Tab",run:Rc,shift:Mc};function B(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var s=t[i];typeof s=="string"?n.setAttribute(i,s):s!=null&&(n[i]=s)}e++}for(;en.normalize("NFKD"):n=>n,bt=class{constructor(e,t,i=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r($c(l)):$c,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return J(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=xi(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=pe(e);let s=this.normalize(t);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o);if(r==s.length-1){if(a)return this.value=a,this;break}o==i&&rthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=As(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(ithis.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length=i||s.to<=t){let l=new n(t,e.sliceString(t,i));return Uo.set(e,l),l}if(s.from==t&&s.to==i)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,s=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this.matchPos=As(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Ps.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<"u"&&(vs.prototype[Symbol.iterator]=Cs.prototype[Symbol.iterator]=function(){return this});function Hg(n){try{return new RegExp(n,el),!0}catch{return!1}}function As(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e=56320&&i<57344;)e++;return e}function Ho(n){let e=B("input",{class:"cm-textfield",name:"line"}),t=B("form",{class:"cm-gotoLine",onkeydown:s=>{s.keyCode==27?(s.preventDefault(),n.dispatch({effects:Qs.of(!1)}),n.focus()):s.keyCode==13&&(s.preventDefault(),i())},onsubmit:s=>{s.preventDefault(),i()}},B("label",n.state.phrase("Go to line"),": ",e)," ",B("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function i(){let s=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!s)return;let{state:r}=n,o=r.doc.lineAt(r.selection.main.head),[,l,a,h,f]=s,c=h?+h.slice(1):0,u=a?+a:o.number;if(a&&f){let g=u/100;l&&(g=g*(l=="-"?-1:1)+o.number/r.doc.lines),u=Math.round(r.doc.lines*g)}else a&&l&&(u=u*(l=="-"?-1:1)+o.number);let d=r.doc.line(Math.max(1,Math.min(r.doc.lines,u))),p=S.cursor(d.from+Math.max(0,Math.min(c,d.length)));n.dispatch({effects:[Qs.of(!1),C.scrollIntoView(p.from,{y:"center"})],selection:p}),n.focus()}return{dom:t}}var Qs=M.define(),Wc=z.define({create(){return!0},update(n,e){for(let t of e.effects)t.is(Qs)&&(n=t.value);return n},provide:n=>Qt.from(n,e=>e?Ho:null)}),_g=n=>{let e=Rt(n,Ho);if(!e){let t=[Qs.of(!0)];n.state.field(Wc,!1)==null&&t.push(M.appendConfig.of([Wc,jg])),n.dispatch({effects:t}),e=Rt(n,Ho)}return e&&e.dom.querySelector("input").focus(),!0},jg=C.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Kg={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Xc=P.define({combine(n){return ce(n,Kg,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Ic(n){let e=[nO,iO];return n&&e.push(Xc.of(n)),e}var Jg=R.mark({class:"cm-selectionMatch"}),eO=R.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Vc(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=L.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=L.Word)}function tO(n,e,t,i){return n(e.sliceDoc(t,t+1))==L.Word&&n(e.sliceDoc(i-1,i))==L.Word}var iO=U.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(Xc),{state:t}=n,i=t.selection;if(i.ranges.length>1)return R.none;let s=i.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return R.none;let a=t.wordAt(s.head);if(!a)return R.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a200)return R.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Vc(o,t,s.from,s.to)&&tO(o,t,s.from,s.to)))return R.none}else if(r=t.sliceDoc(s.from,s.to).trim(),!r)return R.none}let l=[];for(let a of n.visibleRanges){let h=new bt(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:f,to:c}=h.value;if((!o||Vc(o,t,f,c))&&(s.empty&&f<=s.from&&c>=s.to?l.push(eO.range(f,c)):(f>=s.to||c<=s.from)&&l.push(Jg.range(f,c)),l.length>e.maxMatches))return R.none}}return R.set(l)}},{decorations:n=>n.decorations}),nO=C.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),sO=({state:n,dispatch:e})=>{let{selection:t}=n,i=S.create(t.ranges.map(s=>n.wordAt(s.head)||S.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function rO(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new bt(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new bt(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}var oO=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return sO({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=rO(n,i);return s?(e(n.update({selection:n.selection.addRange(S.range(s.from,s.to),!1),effects:C.scrollIntoView(s.to)})),!0):!1},hi=P.define({combine(n){return ce(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Jo(e),scrollToMatch:e=>C.scrollIntoView(e)})}});var Rs=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Hg(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
-`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new jo(this):new _o(this)}getCursor(e,t=0,i){let s=e.doc?e:X.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?ai(this,s,t,i):li(this,s,t,i)}},Ms=class{constructor(e){this.spec=e}};function li(n,e,t,i){return new bt(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?lO(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function lO(n,e){return(t,i,s,r)=>((r>t||r+s.length