0)?kt.before(this.dom):kt.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.dom.getClientRects(),o=null;if(!i.length)return dt;for(let t=e>0?i.length-1:0;o=i[t],!(e>0?0==t:t==i.length-1||o.top0?-1:1);return this.length?o:ct(o,this.side>0)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Wt extends Nt{domAtPos(e){let{topView:t,text:i}=this.widget;return t?qt(e,0,t,i,this.length-t.length,((e,t)=>e.domAtPos(t)),((e,t)=>new kt(e,Math.min(t,e.nodeValue.length)))):new kt(i,Math.min(e,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(e,t){let{topView:i,text:o}=this.widget;return i?_t(e,t,i,o,this.length-i.length):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:i,text:o}=this.widget;return i?qt(e,t,i,o,this.length-i.length,((e,t,i)=>e.coordsAt(t,i)),((e,t,i)=>Vt(e,t,i))):Vt(o,e,t)}destroy(){var e;super.destroy(),null===(e=this.widget.topView)||void 0===e||e.destroy()}get isEditable(){return!0}canReuseDOM(){return!0}}function qt(e,t,i,o,n,a,r){if(i instanceof zt){for(let s=i.dom.firstChild;s;s=s.nextSibling){let i=Ot.get(s);if(i){let l=ot(s,o),p=i.length+(l?n:0);if(e0?kt.before(this.dom):kt.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){let t=this.dom.getBoundingClientRect(),i=function(e,t){let i=e.parent,o=i?i.children.indexOf(e):-1;for(;i&&o>=0;)if(t<0?o>0:o0?-1:1);return i&&i.topt.top?{left:t.left,right:t.right,top:i.top,bottom:i.bottom}:t}get overrideDOMText(){return e.empty}get isHidden(){return!0}}function Ut(e,t){let i=e.dom,{children:o}=e,n=0;for(let e=0;ne&&t0;e--){let t=o[e-1];if(t.dom.parentNode==i)return t.domAtPos(t.length)}for(let e=n;e0&&t instanceof zt&&n.length&&(o=n[n.length-1])instanceof zt&&o.mark.eq(t.mark)?Ht(o,t.children[0],i-1):(n.push(t),t.setParent(e)),e.length+=t.length}function Yt(e,t,i){let o=null,n=-1,a=null,r=-1;!function e(t,s){for(let l=0,p=0;l=s&&(d.children.length?e(d,s-p):(!a||a instanceof Zt&&i>0)&&(c>s||p==c&&d.getSide()>0)?(a=d,r=s-p):(p0?3e8:-4e8:t>0?1e8:-1e8,new ri(e,t,t,i,e.widget||null,!1)}static replace(e){let t,i,o=!!e.block;if(e.isBlockGap)t=-5e8,i=4e8;else{let{start:n,end:a}=si(e,o);t=(n?o?-3e8:-1:5e8)-1,i=1+(a?o?2e8:1:-6e8)}return new ri(e,t,i,o,e.widget||null,!0)}static line(e){return new ai(e)}static set(e,t=!1){return Qe.of(e,t)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}oi.none=Qe.empty;class ni extends oi{constructor(e){let{start:t,end:i}=si(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){return this==e||e instanceof ni&&this.tagName==e.tagName&&this.class==e.class&&Jt(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}ni.prototype.point=!1;class ai extends oi{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof ai&&this.spec.class==e.spec.class&&Jt(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}ai.prototype.mapMode=O.TrackBefore,ai.prototype.point=!0;class ri extends oi{constructor(e,t,i,o,n,a){super(t,i,n,e),this.block=o,this.isReplace=a,this.mapMode=o?t<=0?O.TrackBefore:O.TrackAfter:O.TrackDel}get type(){return this.startSide=5}eq(e){return e instanceof ri&&(t=this.widget,i=e.widget,t==i||!!(t&&i&&t.compare(i)))&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide;var t,i}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}function si(e,t=!1){let{inclusiveStart:i,inclusiveEnd:o}=e;return null==i&&(i=e.inclusive),null==o&&(o=e.inclusive),{start:null!=i?i:t,end:null!=o?o:t}}function li(e,t,i,o=0){let n=i.length-1;n>=0&&i[n]+o>=e?i[n]=Math.max(i[n],t):i.push(e,t)}ri.prototype.point=!0;class pi extends Ot{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,o,n,a){if(i){if(!(i instanceof pi))return!1;this.dom||i.transferDOM(this)}return o&&this.setDeco(i?i.attrs:null),Pt(this,e,t,i?i.children:[],n,a),!0}split(e){let t=new pi;if(t.breakAfter=this.breakAfter,0==this.length)return t;let{i:i,off:o}=this.childPos(e);o&&(t.append(this.children[i].split(o),0),this.children[i].merge(o,this.children[i].length,null,!1,0,0),i++);for(let e=i;e0&&0==this.children[i-1].length;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=void 0===this.prevAttrs?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Jt(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Ht(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=Kt(t,this.attrs||{})),i&&(this.attrs=Kt({class:i},this.attrs||{}))}domAtPos(e){return Ut(this,e)}reuseDOM(e){"DIV"==e.nodeName&&(this.setDOM(e),this.dirty|=6)}sync(e,t){var i;this.dom?4&this.dirty&&(wt(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),void 0!==this.prevAttrs&&(ei(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let o=this.dom.lastChild;for(;o&&Ot.get(o)instanceof zt;)o=o.lastChild;if(!(o&&this.length&&("BR"==o.nodeName||0!=(null===(i=Ot.get(o))||void 0===i?void 0:i.isEditable)||Gt.ios&&this.children.some((e=>e instanceof $t))))){let e=document.createElement("BR");e.cmIgnore=!0,this.dom.appendChild(e)}}measureTextSize(){if(0==this.children.length||this.length>20)return null;let e,t=0;for(let i of this.children){if(!(i instanceof $t)||/[^ -~]/.test(i.text))return null;let o=at(i.dom);if(1!=o.length)return null;t+=o[0].width,e=o[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(e,t){let i=Yt(this,e,t);if(!this.children.length&&i&&this.parent){let{heightOracle:e}=this.parent.view.viewState,t=i.bottom-i.top;if(Math.abs(t-e.lineHeight)<2&&e.textHeight=t){if(n instanceof pi)return n;if(a>t)break}o=a+n.breakAfter}return null}}class di extends Ot{constructor(e,t,i){super(),this.widget=e,this.length=t,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,o,n,a){return!(i&&(!(i instanceof di&&this.widget.compare(i.widget))||e>0&&n<=0||t0;){if(this.textOff==this.text.length){let{value:t,lineBreak:i,done:o}=this.cursor.next(this.skip);if(this.skip=0,o)throw new Error("Ran out of text content when drawing inline views");if(i){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}this.text=t,this.textOff=0}let o=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(hi(new $t(this.text.slice(this.textOff,this.textOff+o)),t),i),this.atCursorPos=!0,this.textOff+=o,e-=o,i=0}}span(e,t,i,o){this.buildText(t-e,i,o),this.pos=t,this.openStart<0&&(this.openStart=o)}point(e,t,i,o,n,a){if(this.disallowBlockEffectsFor[a]&&i instanceof ri){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let r=t-e;if(i instanceof ri)if(i.block){let{type:e}=i;e!=ii.WidgetAfter||this.posCovered()||this.getLine(),this.addBlockWidget(new di(i.widget||new fi("div"),r,e))}else{let a=Nt.create(i.widget||new fi("span"),r,r?0:i.startSide),s=this.atCursorPos&&!a.isEditable&&n<=o.length&&(e0),l=!a.isEditable&&(eo.length||i.startSide<=0),p=this.getLine();2!=this.pendingBuffer||s||a.isEditable||(this.pendingBuffer=0),this.flushBuffer(o),s&&(p.append(hi(new Zt(1),o),n),n=o.length+Math.max(0,n-o.length)),p.append(hi(a,o),n),this.atCursorPos=l,this.pendingBuffer=l?eo.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=o.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);r&&(this.textOff+r<=this.text.length?this.textOff+=r:(this.skip+=r-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=n)}static build(e,t,i,o,n){let a=new ci(e,t,i,n);return a.openEnd=Qe.spans(o,t,i,a),a.openStart<0&&(a.openStart=a.openEnd),a.finish(a.openEnd),a}}function hi(e,t){for(let i of t)e=new zt(i,[e],e.length);return e}class fi extends ti{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}const yi=L.define(),ui=L.define(),mi=L.define(),gi=L.define(),bi=L.define(),wi=L.define(),ki=L.define(),vi=L.define({combine:e=>e.some((e=>e))}),Oi=L.define({combine:e=>e.some((e=>e))});class xi{constructor(e,t="nearest",i="nearest",o=5,n=5){this.range=e,this.y=t,this.x=i,this.yMargin=o,this.xMargin=n}map(e){return e.empty?this:new xi(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}}const Si=ce.define({map:(e,t)=>e.map(t)});function Ci(e,t,i){let o=e.facet(gi);o.length?o[0](t):window.onerror?window.onerror(String(t),i,void 0,void 0,t):i?console.error(i+":",t):console.error(t)}const Pi=L.define({combine:e=>!e.length||e[0]});let Di=0;const Ti=L.define();class Qi{constructor(e,t,i,o){this.id=e,this.create=t,this.domEventHandlers=i,this.extension=o(this)}static define(e,t){const{eventHandlers:i,provide:o,decorations:n}=t||{};return new Qi(Di++,e,i,(e=>{let t=[Ti.of(e)];return n&&t.push(Ei.of((t=>{let i=t.plugin(e);return i?n(i):oi.none}))),o&&t.push(o(e)),t}))}static fromClass(e,t){return Qi.define((t=>new e(t)),t)}}class Ri{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(Ci(e.state,t,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(e){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){Ci(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(null===(t=this.value)||void 0===t?void 0:t.destroy)try{this.value.destroy()}catch(t){Ci(e.state,t,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ai=L.define(),Mi=L.define(),Ei=L.define(),Fi=L.define(),Li=L.define(),Bi=L.define();class Ii{constructor(e,t,i,o){this.fromA=e,this.toA=t,this.fromB=i,this.toB=o}join(e){return new Ii(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let o=e[t-1];if(!(o.fromA>i.toA)){if(o.toAp)break;n+=2}if(!s)return i;new Ii(s.fromA,s.toA,s.fromB,s.toB).addToSet(i),a=s.toA,r=s.toB}}}class Gi{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=S.empty(this.startState.doc.length);for(let e of i)this.changes=this.changes.compose(e.changes);let o=[];this.changes.iterChangedRanges(((e,t,i,n)=>o.push(new Ii(e,t,i,n)))),this.changedRanges=o}static create(e,t,i){return new Gi(e,t,i)}get viewportChanged(){return(4&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(10&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((e=>e.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}var $i=function(e){return e[e.LTR=0]="LTR",e[e.RTL=1]="RTL",e}($i||($i={}));const zi=$i.LTR,Vi=$i.RTL;function Ni(e){let t=[];for(let i=0;i=t){if(r.level==i)return a;(n<0||(0!=o?o<0?r.fromt:e[n].level>r.level))&&(n=a)}}if(n<0)throw new RangeError("Index out of range");return n}}const Ui=[];function Hi(e){return[new Zi(0,e,0)]}let Yi="";function Ki(e,t,i,o,n){var a;let r=o.head-e.from,s=-1;if(0==r){if(!n||!e.length)return null;t[0].level!=i&&(r=t[0].side(!1,i),s=0)}else if(r==e.length){if(n)return null;let e=t[t.length-1];e.level!=i&&(r=e.side(!0,i),s=t.length-1)}s<0&&(s=Zi.find(t,r,null!==(a=o.bidiLevel)&&void 0!==a?a:-1,o.assoc));let l=t[s];r==l.side(n,i)&&(l=t[s+=n?1:-1],r=l.side(!n,i));let p=n==(l.dir==i),d=f(e.text,r,p);if(Yi=e.text.slice(Math.min(r,d),Math.max(r,d)),d!=l.side(n,i))return M.cursor(d+e.from,p?-1:1,l.level);let c=s==(n?t.length-1:0)?null:t[s+(n?1:-1)];return c||l.level==i?c&&c.level1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=r-1);i=a+r}}readNode(e){if(e.cmIgnore)return;let t=Ot.get(e),i=t&&t.overrideDOMText;if(null!=i){this.findPointInside(e,i.length);for(let e=i.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else 3==e.nodeType?this.readTextNode(e):"BR"==e.nodeName?e.nextSibling&&this.lineBreak():1==e.nodeType&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(3==e.nodeType?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+Math.min(t,i.offset))}}function to(e){return 1==e.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}class io{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class oo extends Ot{constructor(e){super(),this.view=e,this.compositionDeco=oi.none,this.decorations=[],this.dynamicDecorationMap=[],this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new pi],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ii(0,0,0,e.state.doc.length)],0)}get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every((({fromA:e,toA:t})=>tthis.minWidthTo))?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.view.inputState.composing<0?this.compositionDeco=oi.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=function(e,t){let i=ao(e);if(!i)return oi.none;let{from:o,to:n,node:a,text:r}=i,s=t.mapPos(o,1),l=Math.max(s,t.mapPos(n,-1)),{state:p}=e,d=3==a.nodeType?a.nodeValue:new eo([],p).readRange(a.firstChild,null).text;if(l-s{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let e=Gt.chrome||Gt.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,e),this.dirty=0,e&&(e.written||i.selectionRange.focusNode!=e.node)&&(this.forceSelection=!0),this.dom.style.height=""}));let o=[];if(this.view.viewport.from||this.view.viewport.to=0?e[t]:null;if(!o)break;let{fromA:n,toA:a,fromB:r,toB:s}=o,{content:l,breakAtStart:p,openStart:d,openEnd:c}=ci.build(this.view.state.doc,r,s,this.decorations,this.dynamicDecorationMap),{i:h,off:f}=i.findPos(a,1),{i:y,off:u}=i.findPos(n,-1);Ct(this,y,u,h,f,l,p,d,c)}}updateSelection(e=!1,t=!1){!e&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,o=i==this.dom,n=!o&&nt(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(o||t||n))return;let a=this.forceSelection;this.forceSelection=!1;let r=this.view.state.selection.main,s=this.domAtPos(r.anchor),l=r.empty?s:this.domAtPos(r.head);if(Gt.gecko&&r.empty&&!this.compositionDeco.size&&(1==(p=s).node.nodeType&&p.node.firstChild&&(0==p.offset||"false"==p.node.childNodes[p.offset-1].contentEditable)&&(p.offset==p.node.childNodes.length||"false"==p.node.childNodes[p.offset].contentEditable))){let e=document.createTextNode("");this.view.observer.ignore((()=>s.node.insertBefore(e,s.node.childNodes[s.offset]||null))),s=l=new kt(e,0),a=!0}var p;let d=this.view.observer.selectionRange;!a&&d.focusNode&&rt(s.node,s.offset,d.anchorNode,d.anchorOffset)&&rt(l.node,l.offset,d.focusNode,d.focusOffset)||(this.view.observer.ignore((()=>{Gt.android&&Gt.chrome&&this.dom.contains(d.focusNode)&&function(e,t){for(let i=e;i&&i!=t;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(d.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let e=it(this.view.root);if(e)if(r.empty){if(Gt.gecko){let e=(t=s.node,o=s.offset,1!=t.nodeType?0:(o&&"false"==t.childNodes[o-1].contentEditable?1:0)|(or.head&&([s,l]=[l,s]),t.setEnd(l.node,l.offset),t.setStart(s.node,s.offset),e.removeAllRanges(),e.addRange(t)}else;var t,o;n&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())})),this.view.observer.setSelectionRange(s,l)),this.impreciseAnchor=s.precise?null:new kt(d.anchorNode,d.anchorOffset),this.impreciseHead=l.precise?null:new kt(d.focusNode,d.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let{view:e}=this,t=e.state.selection.main,i=it(e.root),{anchorNode:o,anchorOffset:n}=e.observer.selectionRange;if(!(i&&t.empty&&t.assoc&&i.modify))return;let a=pi.find(this,t.head);if(!a)return;let r=a.posAtStart;if(t.head==r||t.head==r+a.length)return;let s=this.coordsAt(t.head,-1),l=this.coordsAt(t.head,1);if(!s||!l||s.bottom>l.top)return;let p=this.domAtPos(t.head+t.assoc);i.collapse(p.node,p.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let d=e.observer.selectionRange;e.docView.posFromDOM(d.anchorNode,d.anchorOffset)!=t.from&&i.collapse(o,n)}nearest(e){for(let t=e;t;){let e=Ot.get(t);if(e&&e.rootView==this)return e;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;ta||e==a&&n.type!=ii.WidgetBefore&&n.type!=ii.WidgetAfter&&(!o||2==t||this.children[o-1].breakAfter||this.children[o-1].type==ii.WidgetBefore&&t>-2))return n.coordsAt(e-a,t);i=a}}measureVisibleLineHeights(e){let t=[],{from:i,to:o}=e,n=this.view.contentDOM.clientWidth,a=n>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,r=-1,s=this.view.textDirection==$i.LTR;for(let e=0,l=0;lo)break;if(e>=i){let i=p.dom.getBoundingClientRect();if(t.push(i.height),a){let t=p.dom.lastChild,o=t?at(t):[];if(o.length){let t=o[o.length-1],a=s?t.right-i.left:i.right-t.left;a>r&&(r=a,this.minWidth=n,this.minWidthFrom=e,this.minWidthTo=d)}}}e=d+p.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return"rtl"==getComputedStyle(this.children[t].dom).direction?$i.RTL:$i.LTR}measureTextSize(){for(let e of this.children)if(e instanceof pi){let t=e.measureTextSize();if(t)return t}let e,t,i,o=document.createElement("div");return o.className="cm-line",o.style.width="99999px",o.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(o);let n=at(o.firstChild)[0];e=o.getBoundingClientRect().height,t=n?n.width/27:7,i=n?n.height:e,o.remove()})),{lineHeight:e,charWidth:t,textHeight:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new St(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,o=0;;o++){let n=o==t.viewports.length?null:t.viewports[o],a=n?n.from-1:this.length;if(a>i){let o=t.lineBlockAt(a).bottom-t.lineBlockAt(i).top;e.push(oi.replace({widget:new no(o),block:!0,inclusive:!0,isBlockGap:!0}).range(i,a))}if(!n)break;i=n.to+1}return oi.set(e)}updateDeco(){let e=this.view.state.facet(Ei).map(((e,t)=>(this.dynamicDecorationMap[t]="function"==typeof e)?e(this.view):e));for(let t=e.length;ti.anchor?-1:1);if(!o)return;!i.empty&&(t=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(o={left:Math.min(o.left,t.left),top:Math.min(o.top,t.top),right:Math.max(o.right,t.right),bottom:Math.max(o.bottom,t.bottom)});let n=0,a=0,r=0,s=0;for(let e of this.view.state.facet(Li).map((e=>e(this.view))))if(e){let{left:t,right:i,top:o,bottom:l}=e;null!=t&&(n=Math.max(n,t)),null!=i&&(a=Math.max(a,i)),null!=o&&(r=Math.max(r,o)),null!=l&&(s=Math.max(s,l))}let l={left:o.left-n,top:o.top-r,right:o.right+a,bottom:o.bottom+s};!function(e,t,i,o,n,a,r,s){let l=e.ownerDocument,p=l.defaultView||window;for(let d=e;d;)if(1==d.nodeType){let e,c=d==l.body;if(c)e=ht(p);else{if(d.scrollHeight<=d.clientHeight&&d.scrollWidth<=d.clientWidth){d=d.assignedSlot||d.parentNode;continue}let t=d.getBoundingClientRect();e={left:t.left,right:t.left+d.clientWidth,top:t.top,bottom:t.top+d.clientHeight}}let h=0,f=0;if("nearest"==n)t.top0&&t.bottom>e.bottom+f&&(f=t.bottom-e.bottom+f+r)):t.bottom>e.bottom&&(f=t.bottom-e.bottom+r,i<0&&t.top-f0&&t.right>e.right+h&&(h=t.right-e.right+h+a)):t.right>e.right&&(h=t.right-e.right+a,i<0&&t.left0))break;i=i.childNodes[o-1],o=pt(i)}if(i>=0)for(let o=e,n=t;;){if(3==o.nodeType)return o;if(!(1==o.nodeType&&n=0))break;o=o.childNodes[n],n=0}return null}class lo{constructor(){this.changes=[]}compareRange(e,t){li(e,t,this.changes)}comparePoint(e,t){li(e,t,this.changes)}}function po(e,t){return t.left>e?t.left-e:Math.max(0,e-t.right)}function co(e,t){return t.top>e?t.top-e:Math.max(0,e-t.bottom)}function ho(e,t){return e.topt.top+1}function fo(e,t){return te.bottom?{top:e.top,left:e.left,right:e.right,bottom:t}:e}function uo(e,t,i){let o,n,a,r,s,l,p,d,c=!1;for(let h=e.firstChild;h;h=h.nextSibling){let e=at(h);for(let f=0;fm||r==m&&a>u){o=h,n=y,a=u,r=m;let s=m?i0?f0)}0==u?i>y.bottom&&(!p||p.bottomy.top)&&(l=h,d=y):p&&ho(p,y)?p=yo(p,y.bottom):d&&ho(d,y)&&(d=fo(d,y.top))}}if(p&&p.bottom>=i?(o=s,n=p):d&&d.top<=i&&(o=l,n=d),!o)return{node:e,offset:0};let h=Math.max(n.left,Math.min(n.right,t));return 3==o.nodeType?mo(o,h,i):c&&"false"!=o.contentEditable?uo(o,h,i):{node:e,offset:Array.prototype.indexOf.call(e.childNodes,o)+(t>=(n.left+n.right)/2?1:0)}}function mo(e,t,i){let o=e.nodeValue.length,n=-1,a=1e9,r=0;for(let s=0;si?p.top-i:i-p.bottom)-1;if(p.left-1<=t&&p.right+1>=t&&d=(p.left+p.right)/2,o=i;if(Gt.chrome||Gt.gecko){gt(e,s).getBoundingClientRect().left==p.right&&(o=!i)}if(d<=0)return{node:e,offset:s+(o?1:0)};n=s+(o?1:0),a=d}}}return{node:e,offset:n>-1?n:r>0?e.nodeValue.length:0}}function go(e,t,i,o=-1){var n,a;let r,s=e.contentDOM.getBoundingClientRect(),l=s.top+e.viewState.paddingTop,{docHeight:p}=e.viewState,{x:d,y:c}=t,h=c-l;if(h<0)return 0;if(h>p)return e.state.doc.length;for(let t=e.defaultLineHeight/2,n=!1;r=e.elementAtHeight(h),r.type!=ii.Text;)for(;h=o>0?r.bottom+t:r.top-t,!(h>=0&&h<=p);){if(n)return i?null:0;n=!0,o=-o}c=l+h;let f=r.from;if(fe.viewport.to)return e.viewport.to==e.state.doc.length?e.state.doc.length:i?null:bo(e,s,r,d,c);let y=e.dom.ownerDocument,u=e.root.elementFromPoint?e.root:y,m=u.elementFromPoint(d,c);m&&!e.contentDOM.contains(m)&&(m=null),m||(d=Math.max(s.left+1,Math.min(s.right-1,d)),m=u.elementFromPoint(d,c),m&&!e.contentDOM.contains(m)&&(m=null));let g,b=-1;if(m&&0!=(null===(n=e.docView.nearest(m))||void 0===n?void 0:n.isEditable))if(y.caretPositionFromPoint){let e=y.caretPositionFromPoint(d,c);e&&({offsetNode:g,offset:b}=e)}else if(y.caretRangeFromPoint){let t=y.caretRangeFromPoint(d,c);t&&(({startContainer:g,startOffset:b}=t),(!e.contentDOM.contains(g)||Gt.safari&&function(e,t,i){let o;if(3!=e.nodeType||t!=(o=e.nodeValue.length))return!1;for(let t=e.nextSibling;t;t=t.nextSibling)if(1!=t.nodeType||"BR"!=t.nodeName)return!1;return gt(e,o-1,o).getBoundingClientRect().left>i}(g,b,d)||Gt.chrome&&function(e,t,i){if(0!=t)return!1;for(let t=e;;){let e=t.parentNode;if(!e||1!=e.nodeType||e.firstChild!=t)return!1;if(e.classList.contains("cm-line"))break;t=e}let o=1==e.nodeType?e.getBoundingClientRect():gt(e,0,Math.max(e.nodeValue.length,1)).getBoundingClientRect();return i-o.left>5}(g,b,d))&&(g=void 0))}if(!g||!e.docView.dom.contains(g)){let t=pi.find(e.docView,f);if(!t)return h>r.top+r.height/2?r.to:r.from;({node:g,offset:b}=uo(t.dom,d,c))}let w=e.docView.nearest(g);if(!w)return null;if(w.isWidget&&1==(null===(a=w.dom)||void 0===a?void 0:a.nodeType)){let e=w.dom.getBoundingClientRect();return t.y1.5*e.defaultLineHeight){a+=Math.floor((n-i.top)/e.defaultLineHeight)*e.viewState.heightOracle.lineLength}let r=e.state.sliceDoc(i.from,i.to);return i.from+function(e,t,i,o){for(let o=0,n=0;;){if(n>=t)return o;if(o==e.length)break;n+=9==e.charCodeAt(o)?i-n%i:1,o=f(e,o)}return!0===o?-1:e.length}(r,a,e.state.tabSize)}function wo(e,t,i,o){let n=e.state.doc.lineAt(t.head),a=e.bidiSpans(n),r=e.textDirectionAt(n.from);for(let s=t,l=null;;){let t=Ki(n,a,r,s,i),p=Yi;if(!t){if(n.number==(i?e.state.doc.lines:1))return s;p="\n",n=e.state.doc.line(n.number+(i?1:-1)),a=e.bidiSpans(n),t=M.cursor(i?n.from:n.to)}if(l){if(!l(p))return s}else{if(!o)return t;l=o(p)}s=t}}function ko(e,t,i,o){let n=e.state.facet(Fi).map((t=>t(e)));for(;;){let e=!1;for(let a of n)a.between(i.from-1,i.from+1,((n,a,r)=>{i.from>n&&i.fromi.from?M.cursor(n,1):M.cursor(a,-1),e=!0,r.widget.skipPosition&&(i=r.widget.skipPosition(i,t,o)))}));if(!e)return i}}class vo{constructor(e){this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null;let t=(t,i)=>{this.ignoreDuringComposition(i)||"keydown"==i.type&&this.keydown(e,i)||(this.mustFlushObserver(i)&&e.observer.forceFlush(),this.runCustomHandlers(i.type,e,i)?i.preventDefault():t(e,i))};for(let i in To){let o=To[i];e.contentDOM.addEventListener(i,(i=>{Do(e,i)&&t(o,i)}),Qo[i]),this.registeredEvents.push(i)}e.scrollDOM.addEventListener("mousedown",(i=>{if(i.target==e.scrollDOM&&i.clientY>e.contentDOM.getBoundingClientRect().bottom&&(t(To.mousedown,i),!i.defaultPrevented&&2==i.button)){let t=e.contentDOM.style.minHeight;e.contentDOM.style.minHeight="100%",setTimeout((()=>e.contentDOM.style.minHeight=t),200)}})),Gt.chrome&&102==Gt.chrome_version&&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,Gt.safari&&e.contentDOM.addEventListener("input",(()=>null))}setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}ensureHandlers(e,t){var i;let o;this.customHandlers=[];for(let n of t)if(o=null===(i=n.update(e).spec)||void 0===i?void 0:i.domEventHandlers){this.customHandlers.push({plugin:n.value,handlers:o});for(let t in o)this.registeredEvents.indexOf(t)<0&&"scroll"!=t&&(this.registeredEvents.push(t),e.contentDOM.addEventListener(t,(i=>{Do(e,i)&&this.runCustomHandlers(t,e,i)&&i.preventDefault()})))}}runCustomHandlers(e,t,i){for(let o of this.customHandlers){let n=o.handlers[e];if(n)try{if(n.call(o.plugin,i,t)||i.defaultPrevented)return!0}catch(e){Ci(t.state,e)}}return!1}runScrollHandlers(e,t){this.lastScrollTop=e.scrollDOM.scrollTop,this.lastScrollLeft=e.scrollDOM.scrollLeft;for(let i of this.customHandlers){let o=i.handlers.scroll;if(o)try{o.call(i.plugin,t,e)}catch(t){Ci(e.state,t)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&Date.now()e.keyCode==t.keyCode)))&&!t.ctrlKey||xo.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey))&&(this.pendingIOSKey=i||t,setTimeout((()=>this.flushIOSKey(e)),250),!0)}flushIOSKey(e){let t=this.pendingIOSKey;return!!t&&(this.pendingIOSKey=void 0,bt(e.contentDOM,t.key,t.keyCode))}ignoreDuringComposition(e){return!!/^key/.test(e.type)&&(this.composing>0||!!(Gt.safari&&!Gt.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}mustFlushObserver(e){return"keydown"==e.type&&229!=e.keyCode}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()}}const Oo=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],xo="dthko",So=[16,17,18,20,91,92,224,225];function Co(e){return.7*Math.max(0,e)+8}class Po{constructor(e,t,i,o){this.view=e,this.style=i,this.mustSelect=o,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=function(e){let t=e.ownerDocument;for(let i=e.parentNode;i&&i!=t.body;)if(1==i.nodeType){if(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)return i;i=i.assignedSlot||i.parentNode}else{if(11!=i.nodeType)break;i=i.host}return null}(e.contentDOM);let n=e.contentDOM.ownerDocument;n.addEventListener("mousemove",this.move=this.move.bind(this)),n.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(xe.allowMultipleSelections)&&function(e,t){let i=e.state.facet(yi);return i.length?i[0](t):Gt.mac?t.metaKey:t.ctrlKey}(e,t),this.dragMove=function(e,t){let i=e.state.facet(ui);return i.length?i[0](t):Gt.mac?!t.altKey:!t.ctrlKey}(e,t),this.dragging=!(!function(e,t){let{main:i}=e.state.selection;if(i.empty)return!1;let o=it(e.root);if(!o||0==o.rangeCount)return!0;let n=o.getRangeAt(0).getClientRects();for(let e=0;e=t.clientX&&i.top<=t.clientY&&i.bottom>=t.clientY)return!0}return!1}(e,t)||1!=Vo(t))&&null}start(e){!1===this.dragging&&(e.preventDefault(),this.select(e))}move(e){var t;if(0==e.buttons)return this.destroy();if(!1!==this.dragging)return;this.select(this.lastEvent=e);let i=0,o=0,n=(null===(t=this.scrollParent)||void 0===t?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight};e.clientX<=n.left+6?i=-Co(n.left-e.clientX):e.clientX>=n.right-6&&(i=Co(e.clientX-n.right)),e.clientY<=n.top+6?o=-Co(n.top-e.clientY):e.clientY>=n.bottom-6&&(o=Co(e.clientY-n.bottom)),this.setScrollSpeed(i,o)}up(e){null==this.dragging&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=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),!1===this.dragging&&this.select(this.lastEvent)}select(e){let t=this.style.get(e,this.extend,this.multiple);!this.mustSelect&&t.eq(this.view.state.selection)&&t.main.assoc==this.view.state.selection.main.assoc||this.view.dispatch({selection:t,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.docChanged&&this.dragging&&(this.dragging=this.dragging.map(e.changes)),this.style.update(e)&&setTimeout((()=>this.select(this.lastEvent)),20)}}function Do(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let i,o=t.target;o!=e.contentDOM;o=o.parentNode)if(!o||11==o.nodeType||(i=Ot.get(o))&&i.ignoreEvent(t))return!1;return!0}const To=Object.create(null),Qo=Object.create(null),Ro=Gt.ie&&Gt.ie_version<15||Gt.ios&&Gt.webkit_version<604;function Ao(e,t){let i,{state:o}=e,n=1,a=o.toText(t),r=a.lines==o.selection.ranges.length;if(null!=Wo&&o.selection.ranges.every((e=>e.empty))&&Wo==a.toString()){let e=-1;i=o.changeByRange((i=>{let s=o.doc.lineAt(i.from);if(s.from==e)return{range:i};e=s.from;let l=o.toText((r?a.line(n++).text:t)+o.lineBreak);return{changes:{from:s.from,insert:l},range:M.cursor(i.from+l.length)}}))}else i=r?o.changeByRange((e=>{let t=a.line(n++);return{changes:{from:e.from,to:e.to,insert:t.text},range:M.cursor(e.from+t.length)}})):o.replaceSelection(a);e.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function Mo(e,t,i,o){if(1==o)return M.cursor(t,i);if(2==o)return function(e,t,i=1){let o=e.charCategorizer(t),n=e.doc.lineAt(t),a=t-n.from;if(0==n.length)return M.cursor(t);0==a?i=1:a==n.length&&(i=-1);let r=a,s=a;i<0?r=f(n.text,a,!1):s=f(n.text,a);let l=o(n.text.slice(r,s));for(;r>0;){let e=f(n.text,r,!1);if(o(n.text.slice(e,r))!=l)break;r=e}for(;s{e.inputState.setSelectionOrigin("select"),27==t.keyCode&&(e.inputState.lastEscPress=Date.now())},To.touchstart=(e,t)=>{e.inputState.lastTouchTime=Date.now(),e.inputState.setSelectionOrigin("select.pointer")},To.touchmove=e=>{e.inputState.setSelectionOrigin("select.pointer")},Qo.touchstart=Qo.touchmove={passive:!0},To.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return;let i=null;for(let o of e.state.facet(mi))if(i=o(e,t),i)break;if(i||0!=t.button||(i=function(e,t){let i=Bo(e,t),o=Vo(t),n=e.state.selection;return{update(e){e.docChanged&&(i.pos=e.changes.mapPos(i.pos),n=n.map(e.changes))},get(t,a,r){let s,l=Bo(e,t),p=Mo(e,l.pos,l.bias,o);if(i.pos!=l.pos&&!a){let t=Mo(e,i.pos,i.bias,o),n=Math.min(t.from,p.from),a=Math.max(t.to,p.to);p=n1&&(s=function(e,t){for(let i=0;i=t)return M.create(e.ranges.slice(0,i).concat(e.ranges.slice(i+1)),e.mainIndex==i?0:e.mainIndex-(e.mainIndex>i?1:0))}return null}(n,l.pos))?s:r?n.addRange(p):M.create([p])}}}(e,t)),i){let o=e.root.activeElement!=e.contentDOM;e.inputState.startMouseSelection(new Po(e,t,i,o)),o&&e.observer.ignore((()=>mt(e.contentDOM))),e.inputState.mouseSelection&&e.inputState.mouseSelection.start(t)}};let Eo=(e,t)=>e>=t.top&&e<=t.bottom,Fo=(e,t,i)=>Eo(t,i)&&e>=i.left&&e<=i.right;function Lo(e,t,i,o){let n=pi.find(e.docView,t);if(!n)return 1;let a=t-n.posAtStart;if(0==a)return 1;if(a==n.length)return-1;let r=n.coordsAt(a,-1);if(r&&Fo(i,o,r))return-1;let s=n.coordsAt(a,1);return s&&Fo(i,o,s)?1:r&&Eo(o,r)?-1:1}function Bo(e,t){let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:i,bias:Lo(e,i,t.clientX,t.clientY)}}const Io=Gt.ie&&Gt.ie_version<=11;let Go=null,$o=0,zo=0;function Vo(e){if(!Io)return e.detail;let t=Go,i=zo;return Go=e,zo=Date.now(),$o=!t||i>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?($o+1)%3:1}function No(e,t,i,o){if(!i)return;let n=e.posAtCoords({x:t.clientX,y:t.clientY},!1);t.preventDefault();let{mouseSelection:a}=e.inputState,r=o&&a&&a.dragging&&a.dragMove?{from:a.dragging.from,to:a.dragging.to}:null,s={from:n,insert:i},l=e.state.changes(r?[r,s]:s);e.focus(),e.dispatch({changes:l,selection:{anchor:l.mapPos(n,-1),head:l.mapPos(n,1)},userEvent:r?"move.drop":"input.drop"})}To.dragstart=(e,t)=>{let{selection:{main:i}}=e.state,{mouseSelection:o}=e.inputState;o&&(o.dragging=i),t.dataTransfer&&(t.dataTransfer.setData("Text",e.state.sliceDoc(i.from,i.to)),t.dataTransfer.effectAllowed="copyMove")},To.drop=(e,t)=>{if(!t.dataTransfer)return;if(e.state.readOnly)return t.preventDefault();let i=t.dataTransfer.files;if(i&&i.length){t.preventDefault();let o=Array(i.length),n=0,a=()=>{++n==i.length&&No(e,t,o.filter((e=>null!=e)).join(e.state.lineBreak),!1)};for(let e=0;e{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(o[e]=t.result),a()},t.readAsText(i[e])}}else No(e,t,t.dataTransfer.getData("Text"),!0)},To.paste=(e,t)=>{if(e.state.readOnly)return t.preventDefault();e.observer.flush();let i=Ro?null:t.clipboardData;i?(Ao(e,i.getData("text/plain")||i.getData("text/uri-text")),t.preventDefault()):function(e){let t=e.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{e.focus(),i.remove(),Ao(e,i.value)}),50)}(e)};let Wo=null;To.copy=To.cut=(e,t)=>{let{text:i,ranges:o,linewise:n}=function(e){let t=[],i=[],o=!1;for(let o of e.selection.ranges)o.empty||(t.push(e.sliceDoc(o.from,o.to)),i.push(o));if(!t.length){let n=-1;for(let{from:o}of e.selection.ranges){let a=e.doc.lineAt(o);a.number>n&&(t.push(a.text),i.push({from:a.from,to:Math.min(e.doc.length,a.to+1)})),n=a.number}o=!0}return{text:t.join(e.lineBreak),ranges:i,linewise:o}}(e.state);if(!i&&!n)return;Wo=n?i:null;let a=Ro?null:t.clipboardData;a?(t.preventDefault(),a.clearData(),a.setData("text/plain",i)):function(e,t){let i=e.dom.parentNode;if(!i)return;let o=i.appendChild(document.createElement("textarea"));o.style.cssText="position: fixed; left: -10000px; top: 10px",o.value=t,o.focus(),o.selectionEnd=t.length,o.selectionStart=0,setTimeout((()=>{o.remove(),e.focus()}),50)}(e,i),"cut"!=t.type||e.state.readOnly||e.dispatch({changes:o,scrollIntoView:!0,userEvent:"delete.cut"})};const qo=le.define();function jo(e,t){let i=[];for(let o of e.facet(ki)){let n=o(e,t);n&&i.push(n)}return i?e.update({effects:i,annotations:qo.of(!0)}):null}function _o(e){setTimeout((()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let i=jo(e.state,t);i?e.dispatch(i):e.update([])}}),10)}To.focus=e=>{e.inputState.lastFocusTime=Date.now(),e.scrollDOM.scrollTop||!e.inputState.lastScrollTop&&!e.inputState.lastScrollLeft||(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),_o(e)},To.blur=e=>{e.observer.clearSelectionRange(),_o(e)},To.compositionstart=To.compositionupdate=e=>{null==e.inputState.compositionFirstChange&&(e.inputState.compositionFirstChange=!0),e.inputState.composing<0&&(e.inputState.composing=0)},To.compositionend=e=>{e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,Gt.chrome&&Gt.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then((()=>e.observer.flush())):setTimeout((()=>{e.inputState.composing<0&&e.docView.compositionDeco.size&&e.update([])}),50)},To.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},To.beforeinput=(e,t)=>{var i;let o;if(Gt.chrome&&Gt.android&&(o=Oo.find((e=>e.inputType==t.inputType)))&&(e.observer.delayAndroidKey(o.key,o.keyCode),"Backspace"==o.key||"Delete"==o.key)){let t=(null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())}),100)}};const Xo=["pre-wrap","normal","pre-line","break-spaces"];class Zo{constructor(t){this.lineWrapping=t,this.doc=e.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){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Xo.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,s=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=r;if(this.lineWrapping=r,this.lineHeight=t,this.charWidth=i,this.textHeight=o,this.lineLength=n,s){this.heightSamples={};for(let e=0;e0}set outdated(e){this.flags=(e?2:0)|-3&this.flags}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>Ko&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return Jo.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,o){let n=this,a=i.doc;for(let r=o.length-1;r>=0;r--){let{fromA:s,toA:l,fromB:p,toB:d}=o[r],c=n.lineAt(s,Yo.ByPosNoHeight,i.setDoc(t),0,0),h=c.to>=l?c:n.lineAt(l,Yo.ByPosNoHeight,i,0,0);for(d+=h.to-l,l=h.to;r>0&&c.from<=o[r-1].toA;)s=o[r-1].fromA,p=o[r-1].fromB,r--,s2*n){let n=e[t-1];n.break?e.splice(--t,1,n.left,null,n.right):e.splice(--t,1,n.left,n.right),i+=1+n.break,o-=n.size}else{if(!(n>2*o))break;{let t=e[i];t.break?e.splice(i,1,t.left,null,t.right):e.splice(i,1,t.left,t.right),i+=2+t.break,n-=t.size}}else if(o=n&&a(this.blockAt(0,i,o,n))}updateHeight(e,t=0,i=!1,o){return o&&o.from<=t&&o.more&&this.setHeight(e,o.heights[o.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class tn extends en{constructor(e,t){super(e,t,ii.Text),this.collapsed=0,this.widgetHeight=0}replace(e,t,i){let o=i[0];return 1==i.length&&(o instanceof tn||o instanceof on&&4&o.flags)&&Math.abs(this.length-o.length)<10?(o instanceof on?o=new tn(o.length,this.height):o.height=this.height,this.outdated||(o.outdated=!1),o):Jo.of(i)}updateHeight(e,t=0,i=!1,o){return o&&o.from<=t&&o.more?this.setHeight(e,o.heights[o.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class on extends Jo{constructor(e){super(e,0)}heightMetrics(e,t){let i,o=e.doc.lineAt(t).number,n=e.doc.lineAt(t+this.length).number,a=n-o+1,r=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*a);i=t/a,this.length>a+1&&(r=(this.height-t)/(this.length-a-1))}else i=this.height/a;return{firstLine:o,lastLine:n,perLine:i,perChar:r}}blockAt(e,t,i,o){let{firstLine:n,lastLine:a,perLine:r,perChar:s}=this.heightMetrics(t,o);if(t.lineWrapping){let n=o+Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length),a=t.doc.lineAt(n),l=r+a.length*s,p=Math.max(i,e-l/2);return new Ho(a.from,a.length,p,l,ii.Text)}{let o=Math.max(0,Math.min(a-n,Math.floor((e-i)/r))),{from:s,length:l}=t.doc.line(n+o);return new Ho(s,l,i+r*o,r,ii.Text)}}lineAt(e,t,i,o,n){if(t==Yo.ByHeight)return this.blockAt(e,i,o,n);if(t==Yo.ByPosNoHeight){let{from:t,to:o}=i.doc.lineAt(e);return new Ho(t,o-t,0,0,ii.Text)}let{firstLine:a,perLine:r,perChar:s}=this.heightMetrics(i,n),l=i.doc.lineAt(e),p=r+l.length*s,d=l.number-a,c=o+r*d+s*(l.from-n-d);return new Ho(l.from,l.length,Math.max(o,Math.min(c,o+this.height-p)),p,ii.Text)}forEachLine(e,t,i,o,n,a){e=Math.max(e,n),t=Math.min(t,n+this.length);let{firstLine:r,perLine:s,perChar:l}=this.heightMetrics(i,n);for(let p=e,d=o;p<=t;){let t=i.doc.lineAt(p);if(p==e){let i=t.number-r;d+=s*i+l*(e-n-i)}let o=s+l*t.length;a(new Ho(t.from,t.length,d,o,ii.Text)),d+=o,p=t.to+1}}replace(e,t,i){let o=this.length-t;if(o>0){let e=i[i.length-1];e instanceof on?i[i.length-1]=new on(e.length+o):i.push(null,new on(o-1))}if(e>0){let t=i[0];t instanceof on?i[0]=new on(e+t.length):i.unshift(new on(e-1),null)}return Jo.of(i)}decomposeLeft(e,t){t.push(new on(e-1),null)}decomposeRight(e,t){t.push(null,new on(this.length-e-1))}updateHeight(e,t=0,i=!1,o){let n=t+this.length;if(o&&o.from<=t+this.length&&o.more){let i=[],a=Math.max(t,o.from),r=-1;for(o.from>t&&i.push(new on(o.from-t-1).updateHeight(e,t));a<=n&&o.more;){let t=e.doc.lineAt(a).length;i.length&&i.push(null);let n=o.heights[o.index++];-1==r?r=n:Math.abs(n-r)>=Ko&&(r=-2);let s=new tn(t,n);s.outdated=!1,i.push(s),a+=t+1}a<=n&&i.push(null,new on(n-a).updateHeight(e,a));let s=Jo.of(i);return(r<0||Math.abs(s.height-this.height)>=Ko||Math.abs(r-this.heightMetrics(e,t).perLine)>=Ko)&&(e.heightChanged=!0),s}return(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class nn extends Jo{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return 1&this.flags}blockAt(e,t,i,o){let n=i+this.left.height;return er))return l;let p=t==Yo.ByPosNoHeight?Yo.ByPosNoHeight:Yo.ByPos;return s?l.join(this.right.lineAt(r,p,i,a,r)):this.left.lineAt(r,p,i,o,n).join(l)}forEachLine(e,t,i,o,n,a){let r=o+this.left.height,s=n+this.left.length+this.break;if(this.break)e=s&&this.right.forEachLine(e,t,i,r,s,a);else{let l=this.lineAt(s,Yo.ByPos,i,o,n);e=e&&l.from<=t&&a(l),t>l.to&&this.right.forEachLine(l.to+1,t,i,r,s,a)}}replace(e,t,i){let o=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-o,t-o,i));let n=[];e>0&&this.decomposeLeft(e,n);let a=n.length;for(let e of i)n.push(e);if(e>0&&an(n,a-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,o=i+this.break;if(e>=o)return this.right.decomposeRight(e-o,t);e2*t.size||t.size>2*e.size?Jo.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,o){let{left:n,right:a}=this,r=t+n.length+this.break,s=null;return o&&o.from<=t+n.length&&o.more?s=n=n.updateHeight(e,t,i,o):n.updateHeight(e,t,i),o&&o.from<=r+a.length&&o.more?s=a=a.updateHeight(e,r,i,o):a.updateHeight(e,r,i),s?this.balanced(n,a):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function an(e,t){let i,o;null==e[t]&&(i=e[t-1])instanceof on&&(o=e[t+1])instanceof on&&e.splice(t-1,3,new on(i.length+1+o.length))}class rn{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof tn?i.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new tn(e-this.pos,-1)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=5)&&this.addLineDeco(o,n)}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 tn(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new on(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 tn)return e;let t=new tn(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine(),e.type!=ii.WidgetAfter||this.isCovered||this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=ii.WidgetBefore&&(this.covering=e)}addLineDeco(e,t){let i=this.ensureLine();i.length+=t,i.collapsed+=t,i.widgetHeight=Math.max(i.widgetHeight,e),this.writtenTo=this.pos=this.pos+t}finish(e){let t=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||t instanceof tn||this.isCovered?(this.writtenToi.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=o.overflow){let o=i.getBoundingClientRect();a=Math.max(a,o.left),r=Math.min(r,o.right),s=Math.max(s,o.top),l=t==e.parentNode?o.bottom:Math.min(l,o.bottom)}t="absolute"==o.position||"fixed"==o.position?i.offsetParent:i.parentNode}else{if(11!=t.nodeType)break;t=t.host}return{left:a-i.left,right:Math.max(a,r)-i.left,top:s-(i.top+t),bottom:Math.max(s,l)-(i.top+t)}}function pn(e,t){let i=e.getBoundingClientRect();return{left:0,right:i.right-i.left,top:t,bottom:i.bottom-(i.top+t)}}class dn{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;i"function"!=typeof e&&"cm-lineWrapping"==e.class));this.heightOracle=new Zo(i),this.stateDeco=t.facet(Ei).filter((e=>"function"!=typeof e)),this.heightMap=Jo.empty().applyChanges(this.stateDeco,e.empty,this.heightOracle.setDoc(t.doc),[new Ii(0,0,0,t.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=oi.set(this.lineGaps.map((e=>e.draw(!1)))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let o=i?t.head:t.anchor;if(!e.some((({from:e,to:t})=>o>=e&&o<=t))){let{from:t,to:i}=this.lineBlockAt(o);e.push(new fn(t,i))}}this.viewports=e.sort(((e,t)=>e.from-t.from)),this.scaler=this.heightMap.height<=7e6?gn:new bn(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(1==this.scaler.scale?e:wn(e,this.scaler))}))}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Ei).filter((e=>"function"!=typeof e));let o=e.changedRanges,n=Ii.extendWithRanges(o,function(e,t,i){let o=new sn;return Qe.compare(e,t,i,o,0),o.changes}(i,this.stateDeco,e?e.changes:S.empty(this.state.doc.length))),a=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),n),this.heightMap.height!=a&&(e.flags|=2);let r=n.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.headr.to)||!this.viewportIsAppropriate(r))&&(r=this.getViewport(0,t));let s=!e.changes.empty||2&e.flags||r.from!=this.viewport.from||r.to!=this.viewport.to;this.viewport=r,this.updateForViewport(),s&&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(Oi)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let i=t.contentDOM,o=window.getComputedStyle(i),n=this.heightOracle,a=o.whiteSpace;this.defaultTextDirection="rtl"==o.direction?$i.RTL:$i.LTR;let r=this.heightOracle.mustRefreshForWrapping(a),s=i.getBoundingClientRect(),l=r||this.mustMeasureContent||this.contentDOMHeight!=s.height;this.contentDOMHeight=s.height,this.mustMeasureContent=!1;let p=0,d=0,c=parseInt(o.paddingTop)||0,h=parseInt(o.paddingBottom)||0;this.paddingTop==c&&this.paddingBottom==h||(this.paddingTop=c,this.paddingBottom=h,p|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(l=!0),this.editorWidth=t.scrollDOM.clientWidth,p|=8);let f=(this.printing?pn:ln)(i,this.paddingTop),y=f.top-this.pixelViewport.top,u=f.bottom-this.pixelViewport.bottom;this.pixelViewport=f;let m=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(m!=this.inView&&(this.inView=m,m&&(l=!0)),!this.inView&&!this.scrollTarget)return 0;let g=s.width;if(this.contentDOMWidth==g&&this.editorHeight==t.scrollDOM.clientHeight||(this.contentDOMWidth=s.width,this.editorHeight=t.scrollDOM.clientHeight,p|=8),l){let i=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(i)&&(r=!0),r||n.lineWrapping&&Math.abs(g-this.contentDOMWidth)>n.charWidth){let{lineHeight:e,charWidth:o,textHeight:s}=t.docView.measureTextSize();r=e>0&&n.refresh(a,e,o,s,g/o,i),r&&(t.docView.minWidth=0,p|=8)}y>0&&u>0?d=Math.max(y,u):y<0&&u<0&&(d=Math.min(y,u)),n.heightChanged=!1;for(let o of this.viewports){let a=o.from==this.viewport.from?i:t.docView.measureVisibleLineHeights(o);this.heightMap=(r?Jo.empty().applyChanges(this.stateDeco,e.empty,this.heightOracle,[new Ii(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,r,new Uo(o.from,a))}n.heightChanged&&(p|=2)}let b=!this.viewportIsAppropriate(this.viewport,d)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return b&&(this.viewport=this.getViewport(d,this.scrollTarget)),this.updateForViewport(),(2&p||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(r?[]:this.lineGaps,t)),p|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),p}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)),o=this.heightMap,n=this.heightOracle,{visibleTop:a,visibleBottom:r}=this,s=new fn(o.lineAt(a-1e3*i,Yo.ByHeight,n,0,0).from,o.lineAt(r+1e3*(1-i),Yo.ByHeight,n,0,0).to);if(t){let{head:e}=t.range;if(es.to){let i,a=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),r=o.lineAt(e,Yo.ByPos,n,0,0);i="center"==t.y?(r.top+r.bottom)/2-a/2:"start"==t.y||"nearest"==t.y&&e=r+Math.max(10,Math.min(i,250)))&&o>a-2e3&&n>1,a=o<<1;if(this.defaultTextDirection!=$i.LTR&&!i)return[];let r=[],s=(o,a,l,p)=>{if(a-oo&&ee.from>=l.from&&e.to<=l.to&&Math.abs(e.from-o)e.fromt))));if(!h){if(ae.from<=a&&e.to>=a))){let e=t.moveToLineBoundary(M.cursor(a),!1,!0).head;e>o&&(a=e)}h=new dn(o,a,this.gapSize(l,o,a,p))}r.push(h)};for(let e of this.viewportLines){if(e.lengthe.from&&s(e.from,n,e,t),re.draw(this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];Qe.spans(e,this.viewport.from,this.viewport.to,{span(e,i){t.push({from:e,to:i})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some(((e,i)=>e.from!=t[i].from||e.to!=t[i].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))||wn(this.heightMap.lineAt(e,Yo.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return wn(this.heightMap.lineAt(this.scaler.fromDOM(e),Yo.ByHeight,this.heightOracle,0,0),this.scaler)}elementAtHeight(e){return wn(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}}class fn{constructor(e,t){this.from=e,this.to=t}}function yn(e,t,i){let o=[],n=e,a=0;return Qe.spans(i,e,t,{span(){},point(e,t){e>n&&(o.push({from:n,to:e}),a+=e-n),n=t}},20),n=1)return t[t.length-1].to;let o=Math.floor(e*i);for(let e=0;;e++){let{from:i,to:n}=t[e],a=n-i;if(o<=a)return i+o;o-=a}}function mn(e,t){let i=0;for(let{from:o,to:n}of e.ranges){if(t<=n){i+=t-o;break}i+=n-o}return i/e.total}const gn={toDOM:e=>e,fromDOM:e=>e,scale:1};class bn{constructor(e,t,i){let o=0,n=0,a=0;this.viewports=i.map((({from:i,to:n})=>{let a=t.lineAt(i,Yo.ByPos,e,0,0).top,r=t.lineAt(n,Yo.ByPos,e,0,0).bottom;return o+=r-a,{from:i,to:n,top:a,bottom:r,domTop:0,domBottom:0}})),this.scale=(7e6-o)/(t.height-o);for(let e of this.viewports)e.domTop=a+(e.top-n)*this.scale,a=e.domBottom=e.domTop+(e.bottom-e.top),n=e.bottom}toDOM(e){for(let t=0,i=0,o=0;;t++){let n=twn(e,t))):e.type)}const kn=L.define({combine:e=>e.join(" ")}),vn=L.define({combine:e=>e.indexOf(!0)>-1}),On=je.newName(),xn=je.newName(),Sn=je.newName(),Cn={"&light":"."+xn,"&dark":"."+Sn};function Pn(e,t,i){return new je(t,{finish:t=>/&/.test(t)?t.replace(/&\w*/,(t=>{if("&"==t)return e;if(!i||!i[t])throw new RangeError(`Unsupported selector: ${t}`);return i[t]})):e+" "+t})}const Dn=Pn("."+On,{"&":{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",left: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"}},Cn);class Tn{constructor(e,t,i,o){this.typeOver=o,this.bounds=null,this.text="";let{impreciseHead:n,impreciseAnchor:a}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let t=n||a?[]:function(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:i,anchorOffset:o,focusNode:n,focusOffset:a}=e.observer.selectionRange;i&&(t.push(new io(i,o)),n==i&&a==o||t.push(new io(n,a)));return t}(e),i=new eo(t,e.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(e,t){if(0==e.length)return null;let i=e[0].pos,o=2==e.length?e[1].pos:i;return i>-1&&o>-1?M.single(i+t,o+t):null}(t,this.bounds.from)}else{let t=e.observer.selectionRange,i=n&&n.node==t.focusNode&&n.offset==t.focusOffset||!ot(e.contentDOM,t.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),o=a&&a.node==t.anchorNode&&a.offset==t.anchorOffset||!ot(e.contentDOM,t.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset);this.newSel=M.single(o,i)}}}function Qn(t,i){let o,{newSel:n}=i,a=t.state.selection.main;if(i.bounds){let{from:n,to:r}=i.bounds,s=a.from,l=null;(8===t.inputState.lastKeyCode&&t.inputState.lastKeyTime>Date.now()-100||Gt.android&&i.text.length0&&s>0&&e.charCodeAt(r-1)==t.charCodeAt(s-1);)r--,s--;if("end"==o){i-=r+Math.max(0,a-Math.min(r,s))-a}if(r=r?a-i:0,s=a+(s-r),r=a}else if(s=s?a-i:0,r=a+(r-s),s=a}return{from:a,toA:r,toB:s}}(t.state.doc.sliceString(n,r,Ji),i.text,s-n,l);p&&(Gt.chrome&&13==t.inputState.lastKeyCode&&p.toB==p.from+2&&i.text.slice(p.from,p.toB)==Ji+Ji&&p.toB--,o={from:n+p.from,to:n+p.toA,insert:e.of(i.text.slice(p.from,p.toB).split(Ji))})}else n&&(!t.hasFocus&&t.state.facet(Pi)||n.main.eq(a))&&(n=null);if(!o&&!n)return!1;if(!o&&i.typeOver&&!a.empty&&n&&n.main.empty?o={from:a.from,to:a.to,insert:t.state.doc.slice(a.from,a.to)}:o&&o.from>=a.from&&o.to<=a.to&&(o.from!=a.from||o.to!=a.to)&&a.to-a.from-(o.to-o.from)<=4?o={from:a.from,to:a.to,insert:t.state.doc.slice(a.from,o.from).append(o.insert).append(t.state.doc.slice(o.to,a.to))}:(Gt.mac||Gt.android)&&o&&o.from==o.to&&o.from==a.head-1&&/^\. ?$/.test(o.insert.toString())&&"off"==t.contentDOM.getAttribute("autocorrect")?(n&&2==o.insert.length&&(n=M.single(n.main.anchor-1,n.main.head-1)),o={from:a.from,to:a.to,insert:e.of([" "])}):Gt.chrome&&o&&o.from==o.to&&o.from==a.head&&"\n "==o.insert.toString()&&t.lineWrapping&&(n&&(n=M.single(n.main.anchor-1,n.main.head-1)),o={from:a.from,to:a.to,insert:e.of([" "])}),o){let e=t.state;if(Gt.ios&&t.inputState.flushIOSKey(t))return!0;if(Gt.android&&(o.from==a.from&&o.to==a.to&&1==o.insert.length&&2==o.insert.lines&&bt(t.contentDOM,"Enter",13)||o.from==a.from-1&&o.to==a.to&&0==o.insert.length&&bt(t.contentDOM,"Backspace",8)||o.from==a.from&&o.to==a.to+1&&0==o.insert.length&&bt(t.contentDOM,"Delete",46)))return!0;let i,r=o.insert.toString();if(t.state.facet(wi).some((e=>e(t,o.from,o.to,r))))return!0;if(t.inputState.composing>=0&&t.inputState.composing++,o.from>=a.from&&o.to<=a.to&&o.to-o.from>=(a.to-a.from)/3&&(!n||n.main.empty&&n.main.from==o.from+o.insert.length)&&t.inputState.composing<0){let n=a.fromo.to?e.sliceDoc(o.to,a.to):"";i=e.replaceSelection(t.state.toText(n+o.insert.sliceString(0,void 0,t.state.lineBreak)+r))}else{let r=e.changes(o),s=n&&n.main.to<=r.newLength?n.main:void 0;if(e.selection.ranges.length>1&&t.inputState.composing>=0&&o.to<=a.to&&o.to>=a.to-10){let n=t.state.sliceDoc(o.from,o.to),l=ao(t)||t.state.doc.lineAt(a.head),p=a.to-o.to,d=a.to-a.from;i=e.changeByRange((i=>{if(i.from==a.from&&i.to==a.to)return{changes:r,range:s||i.map(r)};let c=i.to-p,h=c-n.length;if(i.to-i.from!=d||t.state.sliceDoc(h,c)!=n||l&&i.to>=l.from&&i.from<=l.to)return{range:i};let f=e.changes({from:h,to:c,insert:o.insert}),y=i.to-a.to;return{changes:f,range:s?M.range(Math.max(0,s.anchor+y),Math.max(0,s.head+y)):i.map(f)}}))}else i={changes:r,selection:s&&e.selection.replaceRange(s)}}let s="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,s+=".compose",t.inputState.compositionFirstChange&&(s+=".start",t.inputState.compositionFirstChange=!1)),t.dispatch(i,{scrollIntoView:!0,userEvent:s}),!0}if(n&&!n.main.eq(a)){let e=!1,i="select";return t.inputState.lastSelectionTime>Date.now()-50&&("select"==t.inputState.lastSelectionOrigin&&(e=!0),i=t.inputState.lastSelectionOrigin),t.dispatch({selection:n,scrollIntoView:e,userEvent:i}),!0}return!1}const Rn={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},An=Gt.ie&&Gt.ie_version<=11;class Mn{constructor(e){this.view=e,this.active=!1,this.selectionRange=new ft,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 e of t)this.queue.push(e);(Gt.ie&&Gt.ie_version<=11||Gt.ios&&e.composing)&&t.some((e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length))?this.flushSoon():this.flush()})),An&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.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),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver((()=>{var e;(null===(e=this.view.docView)||void 0===e?void 0:e.lastUpdate)this.view.requestMeasure())),this.resizeContent.observe(e.contentDOM)),this.addWindowListeners(this.win=e.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver((e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((e=>{e.length>0&&e[e.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,o=this.selectionRange;if(i.state.facet(Pi)?i.root.activeElement!=this.dom:!nt(i.dom,o))return;let n=o.anchorNode&&i.docView.nearest(o.anchorNode);n&&n.ignoreEvent(e)?t||(this.selectionChanged=!1):(Gt.ie&&Gt.ie_version<=11||Gt.android&&Gt.chrome)&&!i.state.selection.main.empty&&o.focusNode&&rt(o.focusNode,o.focusOffset,o.anchorNode,o.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Gt.safari&&11==e.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e){let t=null;function i(e){e.preventDefault(),e.stopImmediatePropagation(),t=e.getTargetRanges()[0]}if(e.contentDOM.addEventListener("beforeinput",i,!0),e.dom.ownerDocument.execCommand("indent"),e.contentDOM.removeEventListener("beforeinput",i,!0),!t)return null;let o=t.startContainer,n=t.startOffset,a=t.endContainer,r=t.endOffset,s=e.docView.domAtPos(e.state.selection.main.anchor);rt(s.node,s.offset,a,r)&&([o,n,a,r]=[a,r,o,n]);return{anchorNode:o,anchorOffset:n,focusNode:a,focusOffset:r}}(this.view)||it(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=nt(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let e=this.delayedAndroidKey;e&&(this.clearDelayedAndroidKey(),!this.flush()&&e.force&&bt(this.dom,e.key,e.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}this.delayedAndroidKey&&"Enter"!=e||(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,o=!1;for(let n of e){let e=this.readMutation(n);e&&(e.typeOver&&(o=!0),-1==t?({from:t,to:i}=e):(t=Math.min(e.from,t),i=Math.max(e.to,i)))}return{from:t,to:i,typeOver:o}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),o=this.selectionChanged&&nt(this.dom,this.selectionRange);return e<0&&!o?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new Tn(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,o=Qn(this.view,t);return this.view.state==i&&this.view.update([]),o}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty("attributes"==e.type),"attributes"==e.type&&(t.dirty|=4),"childList"==e.type){let i=En(t,e.previousSibling||e.target.previousSibling,-1),o=En(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:o?t.posBefore(o):t.posAtEnd,typeOver:!1}}return"characterData"==e.type?{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,o;this.stop(),null===(e=this.intersection)||void 0===e||e.disconnect(),null===(t=this.gapIntersection)||void 0===t||t.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect(),null===(o=this.resizeContent)||void 0===o||o.disconnect();for(let e of this.scrollTargets)e.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 En(e,t,i){for(;t;){let o=Ot.get(t);if(o&&o.parent==e)return o;let n=t.parentNode;t=n!=e.dom?n:i>0?t.nextSibling:t.previousSibling}return null}class Fn{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),this._dispatch=e.dispatch||(e=>this.update([e])),this.dispatch=this.dispatch.bind(this),this._root=e.root||function(e){for(;e;){if(e&&(9==e.nodeType||11==e.nodeType&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}(e.parent)||document,this.viewState=new hn(e.state||xe.create(e)),this.plugins=this.state.facet(Ti).map((e=>new Ri(e)));for(let e of this.plugins)e.update(this);this.observer=new Mn(this),this.inputState=new vo(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new oo(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}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}dispatch(...e){this._dispatch(1==e.length&&e[0]instanceof he?e[0]:this.state.update(...e))}update(e){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t,i=!1,o=!1,n=this.state;for(let t of e){if(t.startState!=n)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");n=t.state}if(this.destroyed)return void(this.viewState.state=n);let a=this.hasFocus,r=0,s=null;e.some((e=>e.annotation(qo)))?(this.inputState.notifiedFocused=a,r=1):a!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=a,s=jo(n,a),s||(r=1));let l=this.observer.delayedAndroidKey,p=null;if(l?(this.observer.clearDelayedAndroidKey(),p=this.observer.readChange(),(p&&!this.state.doc.eq(n.doc)||!this.state.selection.eq(n.selection))&&(p=null)):this.observer.clear(),n.facet(xe.phrases)!=this.state.facet(xe.phrases))return this.setState(n);t=Gi.create(this,n,e),t.flags|=r;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let t of e){if(d&&(d=d.map(t.changes)),t.scrollIntoView){let{main:e}=t.state.selection;d=new xi(e.empty?e:M.cursor(e.head,e.head>e.anchor?-1:1))}for(let e of t.effects)e.is(Si)&&(d=e.value)}this.viewState.update(t,d),this.bidiCache=In.update(this.bidiCache,t.changes),t.empty||(this.updatePlugins(t),this.inputState.update(t)),i=this.docView.update(t),this.state.facet(Bi)!=this.styleModules&&this.mountStyles(),o=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(i,e.some((e=>e.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(t.startState.facet(kn)!=t.state.facet(kn)&&(this.viewState.mustMeasureContent=!0),(i||o||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!t.empty)for(let e of this.state.facet(bi))e(t);(s||p)&&Promise.resolve().then((()=>{s&&this.state==s.startState&&this.dispatch(s),p&&!Qn(this,p)&&l.force&&bt(this.contentDOM,l.key,l.keyCode)}))}setState(e){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=e);this.updateState=2;let t=this.hasFocus;try{for(let e of this.plugins)e.destroy(this);this.viewState=new hn(e),this.plugins=e.facet(Ti).map((e=>new Ri(e))),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView=new oo(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(Ti),i=e.state.facet(Ti);if(t!=i){let o=[];for(let n of i){let i=t.indexOf(n);if(i<0)o.push(new Ri(n));else{let t=this.plugins[i];t.mustUpdate=e,o.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=o,this.pluginMap.clear(),this.inputState.ensureHandlers(this,this.plugins)}else for(let t of this.plugins)t.mustUpdate=e;for(let e=0;e-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,{scrollHeight:i,scrollTop:o,clientHeight:n}=this.scrollDOM,a=o>i-n-4?i:o;try{for(let e=0;;e++){this.updateState=1;let i=this.viewport,o=this.viewState.lineBlockAtHeight(a),n=this.viewState.measure(this);if(!n&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(e>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let r=[];4&n||([this.measureRequests,r]=[r,this.measureRequests]);let s=r.map((e=>{try{return e.read(this)}catch(e){return Ci(this.state,e),Bn}})),l=Gi.create(this,this.state,[]),p=!1,d=!1;l.flags|=n,t?t.flags|=n:t=l,this.updateState=2,l.empty||(this.updatePlugins(l),this.inputState.update(l),this.updateAttrs(),p=this.docView.update(l));for(let e=0;e1||e<-1)&&(this.scrollDOM.scrollTop+=e,d=!0)}if(p&&this.docView.updateSelection(!0),this.viewport.from==i.from&&this.viewport.to==i.to&&!d&&0==this.measureRequests.length)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let e of this.state.facet(bi))e(t)}get themeClasses(){return On+" "+(this.state.facet(vn)?Sn:xn)+" "+this.state.facet(kn)}updateAttrs(){let e=Gn(this,Ai,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Pi)?"true":"false",class:"cm-content",style:`${Gt.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Gn(this,Mi,t);let i=this.observer.ignore((()=>{let i=ei(this.contentDOM,this.contentAttrs,t),o=ei(this.dom,this.editorAttrs,e);return i||o}));return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let e of i.effects)if(e.is(Fn.announce)){t&&(this.announceDOM.textContent=""),t=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=e.value}}mountStyles(){this.styleModules=this.state.facet(Bi),je.mount(this.root,this.styleModules.concat(Dn).reverse())}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&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(null!=e.key)for(let t=0;tt.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}}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 ko(this,e,wo(this,e,t,i))}moveByCharSelected(e,t,i){return ko(this,e,wo(this,e,t,i),!0)}moveByGroup(e,t){return ko(this,e,wo(this,e,t,(t=>function(e,t,i){let o=e.state.charCategorizer(t),n=o(i);return e=>{let t=o(e);return n==we.Space&&(n=t),n==t}}(this,e.head,t))))}moveToLineBoundary(e,t,i=!0){return function(e,t,i,o){let n=e.state.doc.lineAt(t.head),a=o&&e.lineWrapping?e.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head):null;if(a){let t=e.dom.getBoundingClientRect(),o=e.textDirectionAt(n.from),r=e.posAtCoords({x:i==(o==$i.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(null!=r)return M.cursor(r,i?-1:1)}let r=pi.find(e.docView,t.head),s=r?i?r.posAtEnd:r.posAtStart:i?n.to:n.from;return M.cursor(s,i?-1:1)}(this,e,t,i)}moveVertically(e,t,i){return ko(this,e,function(e,t,i,o){let n=t.head,a=i?1:-1;if(n==(i?e.state.doc.length:0))return M.cursor(n,t.assoc);let r,s=t.goalColumn,l=e.contentDOM.getBoundingClientRect(),p=e.coordsAtPos(n),d=e.documentTop;if(p)null==s&&(s=p.left-l.left),r=a<0?p.top:p.bottom;else{let t=e.viewState.lineBlockAt(n);null==s&&(s=Math.min(l.right-l.left,e.defaultCharacterWidth*(n-t.from))),r=(a<0?t.top:t.bottom)+d}let c=l.left+s,h=null!=o?o:e.defaultLineHeight>>1;for(let i=0;;i+=10){let o=r+(h+i)*a,p=go(e,{x:c,y:o},!1,a);if(ol.bottom||(a<0?pn))return M.cursor(p,t.assoc,void 0,s)}}(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(),go(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 o=this.state.doc.lineAt(e),n=this.bidiSpans(o);return ct(i,n[Zi.find(n,e-o.from,-1,t)].dir==$i.LTR==t>0)}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(vi)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Ln)return Hi(e.length);let t=this.textDirectionAt(e.from);for(let i of this.bidiCache)if(i.from==e.from&&i.dir==t)return i.order;let i=function(e,t){let i=e.length,o=t==zi?1:2,n=t==zi?2:1;if(!e||1==o&&!Xi.test(e))return Hi(i);for(let t=0,n=o,r=o;t=0;e-=3)if(_i[e+1]==-a){let t=_i[e+2],i=2&t?o:4&t?1&t?n:o:0;i&&(Ui[s]=Ui[_i[e]]=i),l=e;break}}else{if(189==_i.length)break;_i[l++]=s,_i[l++]=t,_i[l++]=p}else if(2==(r=Ui[s])||1==r){let e=r==o;p=e?0:1;for(let t=l-3;t>=0;t-=3){let i=_i[t+2];if(2&i)break;if(e)_i[t+2]|=2;else{if(4&i)break;_i[t+2]|=4}}}for(let e=0;et;){let e=i,o=2!=Ui[--i];for(;i>t&&o==(2!=Ui[i-1]);)i--;r.push(new Zi(i,e,o?2:1))}else r.push(new Zi(t,e,0))}else for(let e=0;eDate.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{mt(this.contentDOM),this.docView.updateSelection()}))}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((9==e.nodeType?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 Si.of(new xi("number"==typeof e?M.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return Qi.define((()=>({})),{eventHandlers:e})}static theme(e,t){let i=je.newName(),o=[kn.of(i),Bi.of(Pn(`.${i}`,e))];return t&&t.dark&&o.push(vn.of(!0)),o}static baseTheme(e){return Z.lowest(Bi.of(Pn("."+On,e,Cn)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),o=i&&Ot.get(i)||Ot.get(e);return(null===(t=null==o?void 0:o.rootView)||void 0===t?void 0:t.view)||null}}Fn.styleModule=Bi,Fn.inputHandler=wi,Fn.focusChangeEffect=ki,Fn.perLineTextDirection=vi,Fn.exceptionSink=gi,Fn.updateListener=bi,Fn.editable=Pi,Fn.mouseSelectionStyle=mi,Fn.dragMovesSelection=ui,Fn.clickAddsSelectionRange=yi,Fn.decorations=Ei,Fn.atomicRanges=Fi,Fn.scrollMargins=Li,Fn.darkTheme=vn,Fn.contentAttributes=Mi,Fn.editorAttributes=Ai,Fn.lineWrapping=Fn.contentAttributes.of({class:"cm-lineWrapping"}),Fn.announce=ce.define();const Ln=4096,Bn={};class In{constructor(e,t,i,o){this.from=e,this.to=t,this.dir=i,this.order=o}static update(e,t){if(t.empty)return e;let i=[],o=e.length?e[e.length-1].dir:$i.LTR;for(let n=Math.max(0,e.length-10);n=0;n--){let t=o[n],a="function"==typeof t?t(e):t;a&&Kt(a,i)}return i}const $n=Gt.mac?"mac":Gt.windows?"win":Gt.linux?"linux":"key";function zn(e,t,i){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),!1!==i&&t.shiftKey&&(e="Shift-"+e),e}const Vn=Z.default(Fn.domEventHandlers({keydown:(e,t)=>function(e,t,i,o){let n=function(e){var t=!(Je&&(e.ctrlKey||e.altKey||e.metaKey)||Ke&&e.shiftKey&&e.key&&1==e.key.length||"Unidentified"==e.key)&&e.key||(e.shiftKey?Ue:Ze)[e.keyCode]||e.key||"Unidentified";return"Esc"==t&&(t="Escape"),"Del"==t&&(t="Delete"),"Left"==t&&(t="ArrowLeft"),"Up"==t&&(t="ArrowUp"),"Right"==t&&(t="ArrowRight"),"Down"==t&&(t="ArrowDown"),t}(t),a=b(n,0),r=k(a)==n.length&&" "!=n,s="",l=!1;qn&&qn.view==i&&qn.scope==o&&(s=qn.prefix+" ",(l=So.indexOf(t.keyCode)<0)&&(qn=null));let p,d,c=new Set,h=e=>{if(e){for(let o of e.run)if(!c.has(o)&&(c.add(o),o(i,t)))return!0;e.preventDefault&&(l=!0)}return!1},f=e[o];if(f){if(h(f[s+zn(n,t,!r)]))return!0;if(r&&(t.altKey||t.metaKey||t.ctrlKey)&&!(Gt.windows&&t.ctrlKey&&t.altKey)&&(p=Ze[t.keyCode])&&p!=n){if(h(f[s+zn(p,t,!0)]))return!0;if(t.shiftKey&&(d=Ue[t.keyCode])!=n&&d!=p&&h(f[s+zn(d,t,!1)]))return!0}else if(r&&t.shiftKey&&h(f[s+zn(n,t,!0)]))return!0;if(h(f._any))return!0}return l}(function(e){let t=e.facet(Nn),i=Wn.get(t);i||Wn.set(t,i=function(e,t=$n){let i=Object.create(null),o=Object.create(null),n=(e,t)=>{let i=o[e];if(null==i)o[e]=t;else if(i!=t)throw new Error("Key binding "+e+" is used both as a regular binding and as a multi-stroke prefix")},a=(e,o,a,r)=>{var s,l;let p=i[e]||(i[e]=Object.create(null)),d=o.split(/ (?!$)/).map((e=>function(e,t){const i=e.split(/-(?!$)/);let o,n,a,r,s=i[i.length-1];"Space"==s&&(s=" ");for(let e=0;e{let o=qn={view:t,prefix:i,scope:e};return setTimeout((()=>{qn==o&&(qn=null)}),jn),!0}]})}let c=d.join(" ");n(c,!1);let h=p[c]||(p[c]={preventDefault:!1,run:(null===(l=null===(s=p._any)||void 0===s?void 0:s.run)||void 0===l?void 0:l.slice())||[]});a&&h.run.push(a),r&&(h.preventDefault=!0)};for(let o of e){let e=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let t of e){let e=i[t]||(i[t]=Object.create(null));e._any||(e._any={preventDefault:!1,run:[]});for(let t in e)e[t].run.push(o.any)}let n=o[t]||o.key;if(n)for(let t of e)a(t,n,o.run,o.preventDefault),o.shift&&a(t,"Shift-"+n,o.shift,o.preventDefault)}return i}(t.reduce(((e,t)=>e.concat(t)),[])));return i}(t.state),e,t,"editor")})),Nn=L.define({enables:Vn}),Wn=new WeakMap;let qn=null;const jn=4e3;class _n{constructor(e,t,i,o,n){this.className=e,this.left=t,this.top=i,this.width=o,this.height=n}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className==this.className&&(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",null!=this.width&&(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 o=e.coordsAtPos(i.head,i.assoc||1);if(!o)return[];let n=Xn(e);return[new _n(t,o.left-n.left,o.top-n.top,null,o.bottom-o.top)]}return function(e,t,i){if(i.to<=e.viewport.from||i.from>=e.viewport.to)return[];let o=Math.max(i.from,e.viewport.from),n=Math.min(i.to,e.viewport.to),a=e.textDirection==$i.LTR,r=e.contentDOM,s=r.getBoundingClientRect(),l=Xn(e),p=r.querySelector(".cm-line"),d=p&&window.getComputedStyle(p),c=s.left+(d?parseInt(d.paddingLeft)+Math.min(0,parseInt(d.textIndent)):0),h=s.right-(d?parseInt(d.paddingRight):0),f=Un(e,o),y=Un(e,n),u=f.type==ii.Text?f:null,m=y.type==ii.Text?y:null;e.lineWrapping&&(u&&(u=Zn(e,o,u)),m&&(m=Zn(e,n,m)));if(u&&m&&u.from==m.from)return b(w(i.from,i.to,u));{let t=u?w(i.from,null,u):k(f,!1),o=m?w(null,i.to,m):k(y,!0),n=[];return(u||f).to<(m||y).from-1?n.push(g(c,t.bottom,h,o.top)):t.bottomp&&o.from=a)break;s>n&&l(Math.max(e,n),null==t&&e<=p,Math.min(s,a),null==i&&s>=d,r.dir)}if(n=o.to+1,n>=a)break}return 0==s.length&&l(p,null==t,d,null==i,e.textDirection),{top:n,bottom:r,horizontal:s}}function k(e,t){let i=s.top+(t?e.top:e.bottom);return{top:i,bottom:i,horizontal:[]}}}(e,t,i)}}function Xn(e){let t=e.scrollDOM.getBoundingClientRect();return{left:(e.textDirection==$i.LTR?t.left:t.right-e.scrollDOM.clientWidth)-e.scrollDOM.scrollLeft,top:t.top-e.scrollDOM.scrollTop}}function Zn(e,t,i){let o=M.cursor(t);return{from:Math.max(i.from,e.moveToLineBoundary(o,!1,!0).from),to:Math.min(i.to,e.moveToLineBoundary(o,!0,!0).from),type:ii.Text}}function Un(e,t){let i=e.lineBlockAt(t);if(Array.isArray(i.type))for(let e of i.type)if(e.to>t||e.to==t&&(e.to==i.to||e.type==ii.Text))return e;return i}class Hn{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],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.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(Yn)!=e.state.facet(Yn)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&e.view.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(Yn);for(;t{return i=e,o=this.drawn[t],!(i.constructor==o.constructor&&i.eq(o));var i,o}))){let t=this.dom.firstChild,i=0;for(let o of e)o.update&&t&&o.constructor&&this.drawn[i].constructor&&o.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(o.draw(),t);for(;t;){let e=t.nextSibling;t.remove(),t=e}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Yn=L.define();function Kn(e){return[Qi.define((t=>new Hn(t,e))),Yn.of(e)]}const Jn=!Gt.ios,ea=L.define({combine:e=>Se(e,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})});function ta(e={}){return[ea.of(e),oa,aa,sa,Oi.of(!0)]}function ia(e){return e.startState.facet(ea)!=e.state.facet(ea)}const oa=Kn({above:!0,markers(e){let{state:t}=e,i=t.facet(ea),o=[];for(let n of t.selection.ranges){let a=n==t.selection.main;if(n.empty?!a||Jn:i.drawRangeCursor){let t=a?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=n.empty?n:M.cursor(n.head,n.head>n.anchor?-1:1);for(let n of _n.forRange(e,t,i))o.push(n)}}return o},update(e,t){e.transactions.some((e=>e.selection))&&(t.style.animationName="cm-blink"==t.style.animationName?"cm-blink2":"cm-blink");let i=ia(e);return i&&na(e.state,t),e.docChanged||e.selectionSet||i},mount(e,t){na(t.state,e)},class:"cm-cursorLayer"});function na(e,t){t.style.animationDuration=e.facet(ea).cursorBlinkRate+"ms"}const aa=Kn({above:!1,markers:e=>e.state.selection.ranges.map((t=>t.empty?[]:_n.forRange(e,"cm-selectionBackground",t))).reduce(((e,t)=>e.concat(t))),update:(e,t)=>e.docChanged||e.selectionSet||e.viewportChanged||ia(e),class:"cm-selectionLayer"}),ra={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Jn&&(ra[".cm-line"].caretColor="transparent !important");const sa=Z.highest(Fn.theme(ra)),la=ce.define({map:(e,t)=>null==e?null:t.mapPos(e)}),pa=N.define({create:()=>null,update:(e,t)=>(null!=e&&(e=t.changes.mapPos(e)),t.effects.reduce(((e,t)=>t.is(la)?t.value:e),e))}),da=Qi.fromClass(class{constructor(e){this.view=e,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(e){var t;let i=e.state.field(pa);null==i?null!=this.cursor&&(null===(t=this.cursor)||void 0===t||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(e.startState.field(pa)!=i||e.docChanged||e.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let e=this.view.state.field(pa),t=null!=e&&this.view.coordsAtPos(e);if(!t)return null;let i=this.view.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+this.view.scrollDOM.scrollLeft,top:t.top-i.top+this.view.scrollDOM.scrollTop,height:t.bottom-t.top}}drawCursor(e){this.cursor&&(e?(this.cursor.style.left=e.left+"px",this.cursor.style.top=e.top+"px",this.cursor.style.height=e.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(e){this.view.state.field(pa)!=e&&this.view.dispatch({effects:la.of(e)})}},{eventHandlers:{dragover(e){this.setDropPos(this.view.posAtCoords({x:e.clientX,y:e.clientY}))},dragleave(e){e.target!=this.view.contentDOM&&this.view.contentDOM.contains(e.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function ca(){return[pa,da]}function ha(e,t,i,o,n){t.lastIndex=0;for(let a,r=e.iterRange(i,o),s=i;!r.next().done;s+=r.value.length)if(!r.lineBreak)for(;a=t.exec(r.value);)n(s+a.index,a)}class fa{constructor(e){const{regexp:t,decoration:i,decorate:o,boundary:n,maxLength:a=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,o)this.addMatch=(e,t,i,n)=>o(n,i,i+e[0].length,e,t);else if("function"==typeof i)this.addMatch=(e,t,o,n)=>{let a=i(e,t,o);a&&n(o,o+e[0].length,a)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(e,t,o,n)=>n(o,o+e[0].length,i)}this.boundary=n,this.maxLength=a}createDeco(e){let t=new Re,i=t.add.bind(t);for(let{from:t,to:o}of function(e,t){let i=e.visibleRanges;if(1==i.length&&i[0].from==e.viewport.from&&i[0].to==e.viewport.to)return i;let o=[];for(let{from:n,to:a}of i)n=Math.max(e.state.doc.lineAt(n).from,n-t),a=Math.min(e.state.doc.lineAt(a).to,a+t),o.length&&o[o.length-1].to>=n?o[o.length-1].to=a:o.push({from:n,to:a});return o}(e,this.maxLength))ha(e.state.doc,this.regexp,t,o,((t,o)=>this.addMatch(o,e,t,i)));return t.finish()}updateDeco(e,t){let i=1e9,o=-1;return e.docChanged&&e.changes.iterChanges(((t,n,a,r)=>{r>e.view.viewport.from&&a1e3?this.createDeco(e.view):o>-1?this.updateRange(e.view,t.map(e.changes),i,o):t}updateRange(e,t,i,o){for(let n of e.visibleRanges){let a=Math.max(n.from,i),r=Math.min(n.to,o);if(r>a){let i=e.state.doc.lineAt(a),o=i.toi.from;a--)if(this.boundary.test(i.text[a-1-i.from])){s=a;break}for(;rd.push(i.range(e,t));if(i==o)for(this.regexp.lastIndex=s-i.from;(p=this.regexp.exec(i.text))&&p.indexthis.addMatch(i,e,t,c)));t=t.update({filterFrom:s,filterTo:l,filter:(e,t)=>el,add:d})}}return t}}const ya=null!=/x/.unicode?"gu":"g",ua=new RegExp("[\0-\b\n--\u2028\u2029\ufeff-]",ya),ma={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"};let ga=null;const ba=L.define({combine(e){let t=Se(e,{render:null,specialChars:ua,addSpecialChars:null});return(t.replaceTabs=!function(){var e;if(null==ga&&"undefined"!=typeof document&&document.body){let t=document.body.style;ga=null!=(null!==(e=t.tabSize)&&void 0!==e?e:t.MozTabSize)}return ga||!1}())&&(t.specialChars=new RegExp("\t|"+t.specialChars.source,ya)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,ya)),t}});function wa(e={}){return[ba.of(e),ka||(ka=Qi.fromClass(class{constructor(e){this.view=e,this.decorations=oi.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(e.state.facet(ba)),this.decorations=this.decorator.createDeco(e)}makeDecorator(e){return new fa({regexp:e.specialChars,decoration:(t,i,o)=>{let{doc:n}=i.state,a=b(t[0],0);if(9==a){let e=n.lineAt(o),t=i.state.tabSize,a=Ve(e.text,t,o-e.from);return oi.replace({widget:new Oa((t-a%t)*this.view.defaultCharacterWidth)})}return this.decorationCache[a]||(this.decorationCache[a]=oi.replace({widget:new va(e,a)}))},boundary:e.replaceTabs?void 0:/[^]/})}update(e){let t=e.state.facet(ba);e.startState.facet(ba)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(e.view)):this.decorations=this.decorator.updateDeco(e,this.decorations)}},{decorations:e=>e.decorations}))]}let ka=null;class va extends ti{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=function(e){return e>=32?"•":10==e?"":String.fromCharCode(9216+e)}(this.code),i=e.state.phrase("Control character")+" "+(ma[this.code]||"0x"+this.code.toString(16)),o=this.options.render&&this.options.render(this.code,i,t);if(o)return o;let n=document.createElement("span");return n.textContent=t,n.title=i,n.setAttribute("aria-label",i),n.className="cm-specialChar",n}ignoreEvent(){return!1}}class Oa extends ti{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent="\t",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}class xa extends ti{constructor(e){super(),this.content=e}toDOM(){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild("string"==typeof this.content?document.createTextNode(this.content):this.content),"string"==typeof this.content?e.setAttribute("aria-label","placeholder "+this.content):e.setAttribute("aria-hidden","true"),e}ignoreEvent(){return!1}}const Sa="-10000px";class Ca{constructor(e,t,i){this.facet=t,this.createTooltipView=i,this.input=e.state.facet(t),this.tooltips=this.input.filter((e=>e)),this.tooltipViews=this.tooltips.map(i)}update(e){var t;let i=e.state.facet(this.facet),o=i.filter((e=>e));if(i===this.input){for(let t of this.tooltipViews)t.update&&t.update(e);return!1}let n=[];for(let t=0;t{var t,i,o;return{position:Gt.ios?"absolute":(null===(t=e.find((e=>e.position)))||void 0===t?void 0:t.position)||"fixed",parent:(null===(i=e.find((e=>e.parent)))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(o=e.find((e=>e.tooltipSpace)))||void 0===o?void 0:o.tooltipSpace)||Pa}}}),Ta=new WeakMap,Qa=Qi.fromClass(class{constructor(e){this.view=e,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let t=e.state.facet(Da);this.position=t.position,this.parent=t.parent,this.classes=e.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.manager=new Ca(e,Ma,(e=>this.createTooltip(e))),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver((e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()}),{threshold:[1]}):null,this.observeIntersection(),e.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 e of this.manager.tooltipViews)this.intersectionObserver.observe(e.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1,this.maybeMeasure()}),50))}update(e){e.transactions.length&&(this.lastTransaction=Date.now());let t=this.manager.update(e);t&&this.observeIntersection();let i=t||e.geometryChanged,o=e.state.facet(Da);if(o.position!=this.position){this.position=o.position;for(let e of this.manager.tooltipViews)e.dom.style.position=this.position;i=!0}if(o.parent!=this.parent){this.parent&&this.container.remove(),this.parent=o.parent,this.createContainer();for(let e of this.manager.tooltipViews)this.container.appendChild(e.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(e){let t=e.create(this.view);if(t.dom.classList.add("cm-tooltip"),e.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let e=document.createElement("div");e.className="cm-tooltip-arrow",t.dom.appendChild(e)}return t.dom.style.position=this.position,t.dom.style.top=Sa,this.container.appendChild(t.dom),t.mount&&t.mount(this.view),t}destroy(){var e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let t of this.manager.tooltipViews)t.dom.remove(),null===(e=t.destroy)||void 0===e||e.call(t);null===(t=this.intersectionObserver)||void 0===t||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let e=this.view.dom.getBoundingClientRect();return{editor:e,parent:this.parent?this.container.getBoundingClientRect():e,pos:this.manager.tooltips.map(((e,t)=>{let i=this.manager.tooltipViews[t];return i.getCoords?i.getCoords(e.pos):this.view.coordsAtPos(e.pos)})),size:this.manager.tooltipViews.map((({dom:e})=>e.getBoundingClientRect())),space:this.view.state.facet(Da).tooltipSpace(this.view)}}writeMeasure(e){var t;let{editor:i,space:o}=e,n=[];for(let a=0;a=Math.min(i.bottom,o.bottom)||p.rightMath.min(i.right,o.right)+.1){l.style.top=Sa;continue}let c=r.arrow?s.dom.querySelector(".cm-tooltip-arrow"):null,h=c?7:0,f=d.right-d.left,y=null!==(t=Ta.get(s))&&void 0!==t?t:d.bottom-d.top,u=s.offset||Aa,m=this.view.textDirection==$i.LTR,g=d.width>o.right-o.left?m?o.left:o.right-d.width:m?Math.min(p.left-(c?14:0)+u.x,o.right-f):Math.max(o.left,p.left-f+(c?14:0)-u.x),b=!!r.above;!r.strictSide&&(b?p.top-(d.bottom-d.top)-u.yo.bottom)&&b==o.bottom-p.bottom>p.top-o.top&&(b=!b);let w=(b?p.top-o.top:o.bottom-p.bottom)-h;if(wg&&e.topk&&(k=b?e.top-y-2-h:e.bottom+h+2);"absolute"==this.position?(l.style.top=k-e.parent.top+"px",l.style.left=g-e.parent.left+"px"):(l.style.top=k+"px",l.style.left=g+"px"),c&&(c.style.left=p.left+(m?u.x:-u.x)-(g+14-7)+"px"),!0!==s.overlap&&n.push({left:g,top:k,right:v,bottom:k+y}),l.classList.toggle("cm-tooltip-above",b),l.classList.toggle("cm-tooltip-below",!b),s.positioned&&s.positioned(e.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 e of this.manager.tooltipViews)e.dom.style.top=Sa}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Ra=Fn.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:"14px",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"}}}),Aa={x:0,y:0},Ma=L.define({enables:[Qa,Ra]});function Ea(e,t){let i=e.plugin(Qa);if(!i)return null;let o=i.manager.tooltips.indexOf(t);return o<0?null:i.manager.tooltipViews[o]}class Fa extends Ce{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Fa.prototype.elementClass="",Fa.prototype.toDOM=void 0,Fa.prototype.mapMode=O.TrackBefore,Fa.prototype.startSide=Fa.prototype.endSide=-1,Fa.prototype.point=!0;const La=L.define(),Ba=L.define(),Ia=L.define({combine:e=>e.some((e=>e))});function Ga(e){let t=[$a];return e&&!1===e.fixed&&t.push(Ia.of(!0)),t}const $a=Qi.fromClass(class{constructor(e){this.view=e,this.prevViewport=e.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight+"px",this.gutters=e.state.facet(Ba).map((t=>new Wa(e,t)));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!e.state.facet(Ia),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),e.scrollDOM.insertBefore(this.dom,e.contentDOM)}update(e){if(this.updateGutters(e)){let t=this.prevViewport,i=e.view.viewport,o=Math.min(t.to,i.to)-Math.max(t.from,i.from);this.syncGutters(o<.8*(i.to-i.from))}e.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(Ia)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=e.view.viewport}syncGutters(e){let t=this.dom.nextSibling;e&&this.dom.remove();let i=Qe.iter(this.view.state.facet(La),this.view.viewport.from),o=[],n=this.gutters.map((e=>new Na(e,this.view.viewport,-this.view.documentPadding.top)));for(let e of this.view.viewportLineBlocks){let t;if(Array.isArray(e.type)){for(let i of e.type)if(i.type==ii.Text){t=i;break}}else t=e.type==ii.Text?e:void 0;if(t){o.length&&(o=[]),Va(i,o,e.from);for(let e of n)e.line(this.view,t,o)}}for(let e of n)e.finish();e&&this.view.scrollDOM.insertBefore(this.dom,t)}updateGutters(e){let t=e.startState.facet(Ba),i=e.state.facet(Ba),o=e.docChanged||e.heightChanged||e.viewportChanged||!Qe.eq(e.startState.facet(La),e.state.facet(La),e.view.viewport.from,e.view.viewport.to);if(t==i)for(let t of this.gutters)t.update(e)&&(o=!0);else{o=!0;let n=[];for(let o of i){let i=t.indexOf(o);i<0?n.push(new Wa(this.view,o)):(this.gutters[i].update(e),n.push(this.gutters[i]))}for(let e of this.gutters)e.dom.remove(),n.indexOf(e)<0&&e.destroy();for(let e of n)this.dom.appendChild(e.dom);this.gutters=n}return o}destroy(){for(let e of this.gutters)e.destroy();this.dom.remove()}},{provide:e=>Fn.scrollMargins.of((t=>{let i=t.plugin(e);return i&&0!=i.gutters.length&&i.fixed?t.textDirection==$i.LTR?{left:i.dom.offsetWidth}:{right:i.dom.offsetWidth}:null}))});function za(e){return Array.isArray(e)?e:[e]}function Va(e,t,i){for(;e.value&&e.from<=i;)e.from==i&&t.push(e.value),e.next()}class Na{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=Qe.iter(e.markers,t.from)}line(e,t,i){let o=[];Va(this.cursor,o,t.from),i.length&&(o=o.concat(i));let n=this.gutter.config.lineMarker(e,t,o);n&&o.unshift(n);let a=this.gutter;if(0==o.length&&!a.config.renderEmptyElements)return;let r=t.top-this.height;if(this.i==a.elements.length){let i=new qa(e,t.height,r,o);a.elements.push(i),a.dom.appendChild(i.dom)}else a.elements[this.i].update(e,t.height,r,o);this.height=t.bottom,this.i++}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class Wa{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,(o=>{let n,a=o.target;if(a!=this.dom&&this.dom.contains(a)){for(;a.parentNode!=this.dom;)a=a.parentNode;let e=a.getBoundingClientRect();n=(e.top+e.bottom)/2}else n=o.clientY;let r=e.lineBlockAtHeight(n-e.documentTop);t.domEventHandlers[i](e,r,o)&&o.preventDefault()}));this.markers=za(t.markers(e)),t.initialSpacer&&(this.spacer=new qa(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=za(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let t=this.config.updateSpacer(this.spacer.markers[0],e);t!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[t])}let i=e.view.viewport;return!Qe.eq(this.markers,t,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(e)}destroy(){for(let e of this.elements)e.destroy()}}class qa{constructor(e,t,i,o){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,o)}update(e,t,i,o){this.height!=t&&(this.dom.style.height=(this.height=t)+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(e,t){if(e.length!=t.length)return!1;for(let i=0;iSe(e,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let e in t){let o=i[e],n=t[e];i[e]=o?(e,t,i)=>o(e,t,i)||n(e,t,i):n}return i}})});class Xa extends Fa{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Za(e,t){return e.state.facet(_a).formatNumber(t,e.state)}const Ua=Ba.compute([_a],(e=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:e=>e.state.facet(ja),lineMarker:(e,t,i)=>i.some((e=>e.toDOM))?null:new Xa(Za(e,e.state.doc.lineAt(t.from).number)),lineMarkerChange:e=>e.startState.facet(_a)!=e.state.facet(_a),initialSpacer:e=>new Xa(Za(e,Ha(e.state.doc.lines))),updateSpacer(e,t){let i=Za(t.view,Ha(t.view.state.doc.lines));return i==e.number?e:new Xa(i)},domEventHandlers:e.facet(_a).domEventHandlers})));function Ha(e){let t=9;for(;t{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"function"!=typeof e&&(e=or.match(e)),t=>{let i=e(t);return void 0===i?null:[this,i]}}}er.closedBy=new er({deserialize:e=>e.split(" ")}),er.openedBy=new er({deserialize:e=>e.split(" ")}),er.group=new er({deserialize:e=>e.split(" ")}),er.contextHash=new er({perNode:!0}),er.lookAhead=new er({perNode:!0}),er.mounted=new er({perNode:!0});class tr{constructor(e,t,i){this.tree=e,this.overlay=t,this.parser=i}}const ir=Object.create(null);class or{constructor(e,t,i,o=0){this.name=e,this.props=t,this.id=i,this.flags=o}static define(e){let t=e.props&&e.props.length?Object.create(null):ir,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(null==e.name?8:0),o=new or(e.name||"",t,e.id,i);if(e.props)for(let i of e.props)if(Array.isArray(i)||(i=i(o)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[i[0].id]=i[1]}return o}prop(e){return this.props[e.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(e){if("string"==typeof e){if(this.name==e)return!0;let t=this.prop(er.group);return!!t&&t.indexOf(e)>-1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let o of i.split(" "))t[o]=e[i];return e=>{for(let i=e.prop(er.group),o=-1;o<(i?i.length:0);o++){let n=t[o<0?e.name:i[o]];if(n)return n}}}}or.none=new or("",Object.create(null),0,8);class nr{constructor(e){this.types=e;for(let t=0;t=o&&(a.type.isAnonymous||!1!==t(a))){if(a.firstChild())continue;e=!0}for(;e&&i&&!a.type.isAnonymous&&i(a),!a.nextSibling();){if(!a.parent())return;e=!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:xr(or.none,this.children,this.positions,0,this.children.length,0,this.length,((e,t,i)=>new lr(this.type,e,t,i,this.propValues)),e.makeTree||((e,t,i)=>new lr(or.none,e,t,i)))}static build(e){return function(e){var t;let{buffer:i,nodeSet:o,maxBufferLength:n=Ya,reused:a=[],minRepeatType:r=o.types.length}=e,s=Array.isArray(i)?new pr(i,i.length):i,l=o.types,p=0,d=0;function c(e,t,i,g,b){let{id:w,start:k,end:v,size:O}=s,x=d;for(;O<0;){if(s.next(),-1==O){let t=a[w];return i.push(t),void g.push(k-e)}if(-3==O)return void(p=w);if(-4==O)return void(d=w);throw new RangeError(`Unrecognized record size: ${O}`)}let S,C,P=l[w],D=k-e;if(v-k<=n&&(C=u(s.pos-t,b))){let t=new Uint16Array(C.size-C.skip),i=s.pos-C.size,n=t.length;for(;s.pos>i;)n=m(C.start,t,n);S=new dr(t,v-C.start,o),D=C.start-e}else{let e=s.pos-O;s.next();let t=[],i=[],o=w>=r?w:-1,a=0,l=v;for(;s.pos>e;)o>=0&&s.id==o&&s.size>=0?(s.end<=l-n&&(f(t,i,k,a,s.end,l,o,x),a=t.length,l=s.end),s.next()):c(k,e,t,i,o);if(o>=0&&a>0&&a-1&&a>0){let e=h(P);S=xr(P,t,i,0,t.length,0,v-k,e,e)}else S=y(P,t,i,v-k,x-v)}i.push(S),g.push(D)}function h(e){return(t,i,o)=>{let n,a,r=0,s=t.length-1;if(s>=0&&(n=t[s])instanceof lr){if(!s&&n.type==e&&n.length==o)return n;(a=n.prop(er.lookAhead))&&(r=i[s]+n.length+a)}return y(e,t,i,o,r)}}function f(e,t,i,n,a,r,s,l){let p=[],d=[];for(;e.length>n;)p.push(e.pop()),d.push(t.pop()+i-a);e.push(y(o.types[s],p,d,r-a,l-r)),t.push(a-i)}function y(e,t,i,o,n=0,a){if(p){let e=[er.contextHash,p];a=a?[e].concat(a):[e]}if(n>25){let e=[er.lookAhead,n];a=a?[e].concat(a):[e]}return new lr(e,t,i,o,a)}function u(e,t){let i=s.fork(),o=0,a=0,l=0,p=i.end-n,d={size:0,start:0,skip:0};e:for(let n=i.pos-e;i.pos>n;){let e=i.size;if(i.id==t&&e>=0){d.size=o,d.start=a,d.skip=l,l+=4,o+=4,i.next();continue}let s=i.pos-e;if(e<0||s=r?4:0,h=i.start;for(i.next();i.pos>s;){if(i.size<0){if(-3!=i.size)break e;c+=4}else i.id>=r&&(c+=4);i.next()}a=h,o+=e,l+=c}return(t<0||o==e)&&(d.size=o,d.start=a,d.skip=l),d.size>4?d:void 0}function m(e,t,i){let{id:o,start:n,end:a,size:l}=s;if(s.next(),l>=0&&o4){let o=s.pos-(l-4);for(;s.pos>o;)i=m(e,t,i)}t[--i]=r,t[--i]=a-e,t[--i]=n-e,t[--i]=o}else-3==l?p=o:-4==l&&(d=o);return i}let g=[],b=[];for(;s.pos>0;)c(e.start||0,e.bufferStart||0,g,b,-1);let w=null!==(t=e.length)&&void 0!==t?t:g.length?b[0]+g[0].length:0;return new lr(l[e.topID],g.reverse(),b.reverse(),w)}(e)}}lr.empty=new lr(or.none,[],[],0);class pr{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 pr(this.buffer,this.index)}}class dr{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return or.none}toString(){let e=[];for(let t=0;t0));s=a[s+3]);return r}slice(e,t,i){let o=this.buffer,n=new Uint16Array(t-e),a=0;for(let r=e,s=0;r=t&⁢case 1:return i<=t&&o>t;case 2:return o>t;case 4:return!0}}function hr(e,t){let i=e.childBefore(t);for(;i;){let t=i.lastChild;if(!t||t.to!=i.to)break;t.type.isError&&t.from==t.to?(e=i,i=t.prevSibling):i=t}return e}function fr(e,t,i,o){for(var n;e.from==e.to||(i<1?e.from>=t:e.from>t)||(i>-1?e.to<=t:e.to0?r.length:-1;e!=l;e+=t){let l=r[e],p=s[e]+a.from;if(cr(o,i,p,p+l.length))if(l instanceof dr){if(n&sr.ExcludeBuffers)continue;let r=l.findChild(0,l.buffer.length,t,i-p,o);if(r>-1)return new br(new gr(a,l,e,p),null,r)}else if(n&sr.IncludeAnonymous||!l.type.isAnonymous||kr(l)){let r;if(!(n&sr.IgnoreMounts)&&l.props&&(r=l.prop(er.mounted))&&!r.overlay)return new yr(r.tree,p,e,a);let s=new yr(l,p,e,a);return n&sr.IncludeAnonymous||!s.type.isAnonymous?s:s.nextChild(t<0?l.children.length-1:0,t,i,o)}}if(n&sr.IncludeAnonymous||!a.type.isAnonymous)return null;if(e=a.index>=0?a.index+t:t<0?-1:a._parent._tree.children.length,a=a._parent,!a)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 o;if(!(i&sr.IgnoreOverlays)&&(o=this._tree.prop(er.mounted))&&o.overlay){let i=e-this.from;for(let{from:e,to:n}of o.overlay)if((t>0?e<=i:e=i:n>i))return new yr(o.tree,o.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 wr(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return fr(this,e,t,!1)}resolveInner(e,t=0){return fr(this,e,t,!0)}enterUnfinishedNodesBefore(e){return hr(this,e)}getChild(e,t=null,i=null){let o=ur(this,e,t,i);return o.length?o[0]:null}getChildren(e,t=null,i=null){return ur(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return mr(this,e)}}function ur(e,t,i,o){let n=e.cursor(),a=[];if(!n.firstChild())return a;if(null!=i)for(;!n.type.is(i);)if(!n.nextSibling())return a;for(;;){if(null!=o&&n.type.is(o))return a;if(n.type.is(t)&&a.push(n.node),!n.nextSibling())return null==o?a:[]}}function mr(e,t,i=t.length-1){for(let o=e.parent;i>=0;o=o.parent){if(!o)return!1;if(!o.type.isAnonymous){if(t[i]&&t[i]!=o.name)return!1;i--}}return!0}class gr{constructor(e,t,i,o){this.parent=e,this.buffer=t,this.index=i,this.start=o}}class br{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:o}=this.context,n=o.findChild(this.index+4,o.buffer[this.index+3],e,t-this.context.start,i);return n<0?null:new br(this.context,this,n)}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&sr.ExcludeBuffers)return null;let{buffer:o}=this.context,n=o.findChild(this.index+4,o.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return n<0?null:new br(this.context,this,n)}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 br(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 br(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new wr(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,o=this.index+4,n=i.buffer[this.index+3];if(n>o){let a=i.buffer[this.index+1];e.push(i.slice(o,n,a)),t.push(0)}return new lr(this.type,e,t,this.to-this.from)}resolve(e,t=0){return fr(this,e,t,!1)}resolveInner(e,t=0){return fr(this,e,t,!0)}enterUnfinishedNodesBefore(e){return hr(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let o=ur(this,e,t,i);return o.length?o[0]:null}getChildren(e,t=null,i=null){return ur(this,e,t,i)}get node(){return this}matchContext(e){return mr(this,e)}}class wr{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 yr)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.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)}yieldBuf(e,t){this.index=e;let{start:i,buffer:o}=this.buffer;return this.type=t||o.set.types[o.buffer[e]],this.from=i+o.buffer[e+1],this.to=i+o.buffer[e+2],!0}yield(e){return!!e&&(e instanceof yr?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)))}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:o}=this.buffer,n=o.findChild(this.index+4,o.buffer[this.index+3],e,t-this.buffer.start,i);return!(n<0)&&(this.stack.push(this.index),this.yieldBuf(n))}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&sr.ExcludeBuffers)&&this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&sr.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&sr.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));let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let e=i<0?0:this.stack[i]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(e)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:o}=this;if(o){if(e>0){if(this.index-1)for(let o=t+e,n=e<0?-1:i._tree.children.length;o!=n;o+=e){let e=i._tree.children[o];if(this.mode&sr.IncludeAnonymous||e instanceof dr||!e.type.isAnonymous||kr(e))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 a=e;a;a=a._parent)if(a.index==o){if(o==this.index)return a;t=a,i=n+1;break e}o=this.stack[--n]}for(let e=i;e=0;n--){if(n<0)return mr(this.node,e,o);let a=i[t.buffer[this.stack[n]]];if(!a.isAnonymous){if(e[o]&&e[o]!=a.name)return!1;o--}}return!0}}function kr(e){return e.children.some((e=>e instanceof dr||!e.type.isAnonymous||kr(e)))}const vr=new WeakMap;function Or(e,t){if(!e.isAnonymous||t instanceof dr||t.type!=e)return 1;let i=vr.get(t);if(null==i){i=1;for(let o of t.children){if(o.type!=e||!(o instanceof lr)){i=1;break}i+=Or(e,o)}vr.set(t,i)}return i}function xr(e,t,i,o,n,a,r,s,l){let p=0;for(let i=o;i=d)break;y+=t}if(p==n+1){if(y>d){let e=i[n];t(e.children,e.positions,0,e.children.length,o[n]+s);continue}c.push(i[n])}else{let t=o[p-1]+i[p-1].length-f;c.push(xr(e,i,o,n,p,f,t,null,l))}h.push(f+s-a)}}(t,i,o,n,0),(s||l)(c,h,r)}class Sr{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let o=this.map.get(e);o||this.map.set(e,o=new Map),o.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof br?this.setBuffer(e.context.buffer,e.index,t):e instanceof yr&&this.map.set(e.tree,t)}get(e){return e instanceof br?this.getBuffer(e.context.buffer,e.index):e instanceof yr?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)}}class Cr{constructor(e,t,i,o,n=!1,a=!1){this.from=e,this.to=t,this.tree=i,this.offset=o,this.open=(n?1:0)|(a?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(e,t=[],i=!1){let o=[new Cr(0,e.length,e,0,!1,i)];for(let i of t)i.to>e.length&&o.push(i);return o}static applyChanges(e,t,i=128){if(!t.length)return e;let o=[],n=1,a=e.length?e[0]:null;for(let r=0,s=0,l=0;;r++){let p=r=i)for(;a&&a.from=t.from||d<=t.to||l){let e=Math.max(t.from,s)-l,i=Math.min(t.to,d)-l;t=e>=i?null:new Cr(e,i,t.tree,t.offset+l,r>0,!!p)}if(t&&o.push(t),a.to>d)break;a=nnew Ja(e.from,e.to))):[new Ja(0,0)]:[new Ja(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let o=this.startParse(e,t,i);for(;;){let e=o.advance();if(e)return e}}}class Dr{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function Tr(e){return(t,i,o,n)=>new Mr(t,e,i,o,n)}class Qr{constructor(e,t,i,o,n){this.parser=e,this.parse=t,this.overlay=i,this.target=o,this.ranges=n}}class Rr{constructor(e,t,i,o,n,a,r){this.parser=e,this.predicate=t,this.mounts=i,this.index=o,this.start=n,this.target=a,this.prev=r,this.depth=0,this.ranges=[]}}const Ar=new er({perNode:!0});class Mr{constructor(e,t,i,o,n){this.nest=t,this.input=i,this.fragments=o,this.ranges=n,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let e=this.baseParse.advance();if(!e)return null;if(this.baseParse=null,this.baseTree=e,this.startInner(),null!=this.stoppedAt)for(let e of this.inner)e.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let e=this.baseTree;return null!=this.stoppedAt&&(e=new lr(e.type,e.children,e.positions,e.length,e.propValues.concat([[Ar,this.stoppedAt]]))),e}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[er.mounted.id]=new tr(t,e.overlay,e.parser),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;te.frag.from<=o.from&&e.frag.to>=o.to&&e.mount.overlay));if(e)for(let i of e.mount.overlay){let n=i.from+e.pos,a=i.to+e.pos;n>=o.from&&a<=o.to&&!t.ranges.some((e=>e.fromn))&&t.ranges.push({from:n,to:a})}}s=!1}else if(i&&(a=Er(i.ranges,o.from,o.to)))s=2!=a;else if(!o.type.isAnonymous&&o.fromnew Ja(e.from-o.from,e.to-o.from))):null,o.tree,e)),n.overlay?e.length&&(i={ranges:e,depth:0,prev:i}):s=!1}}else t&&(r=t.predicate(o))&&(!0===r&&(r=new Ja(o.from,o.to)),r.fromnew Ja(e.from-t.start,e.to-t.start))),t.target,e)),t=t.prev}i&&! --i.depth&&(i=i.prev)}}}}function Er(e,t,i){for(let o of e){if(o.from>=i)break;if(o.to>t)return o.from<=t&&o.to>=i?2:1}return 0}function Fr(e,t,i,o,n,a){if(t=t.to);o++);let r=n.children[o],s=r.buffer;n.children[o]=function e(i,o,n,l,p){let d=i;for(;s[d+2]+a<=t.from;)d=s[d+3];let c=[],h=[];Fr(r,i,d,c,h,l);let f=s[d+1],y=s[d+2],u=f+a==t.from&&y+a==t.to&&s[d]==t.type.id;return c.push(u?t.toTree():e(d+4,s[d+3],r.set.types[s[d]],f,y-f)),h.push(f-l),Fr(r,s[d+3],o,c,h,l),new lr(n,c,h,p)}(0,s.length,or.none,0,r.length);for(let o=0;o<=i;o++)e.childAfter(t.from)}class Br{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(sr.IncludeAnonymous|sr.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from=e&&t.enter(i,1,sr.IgnoreOverlays|sr.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(!(t.children.length&&0==t.positions[0]&&t.children[0]instanceof lr))break;t=t.children[0]}return!1}}let Ir=class{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=null!==(t=i.tree.prop(Ar))&&void 0!==t?t:i.to,this.inner=new Br(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=null!==(e=t.tree.prop(Ar))&&void 0!==e?e:t.to,this.inner=new Br(t.tree,-t.offset)}}findMounts(e,t){var i;let o=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let e=this.inner.cursor.node;e;e=e.parent){let n=null===(i=e.tree)||void 0===i?void 0:i.prop(er.mounted);if(n&&n.parser==t)for(let t=this.fragI;t=e.to)break;i.tree==this.curFrag.tree&&o.push({frag:i,pos:e.from-i.offset,mount:n})}}}return o}};function Gr(e,t){let i=null,o=t;for(let n=1,a=0;n=s)break;e.to<=r||(i||(o=i=t.slice()),e.froms&&i.splice(a+1,0,new Ja(s,e.to))):e.to>s?i[a--]=new Ja(s,e.to):i.splice(a--,1))}}return o}function $r(e,t,i,o){let n=0,a=0,r=!1,s=!1,l=-1e9,p=[];for(;;){let d=n==e.length?1e9:r?e[n].to:e[n].from,c=a==t.length?1e9:s?t[a].to:t[a].from;if(r!=s){let e=Math.max(l,i),t=Math.min(d,c,o);enew Ja(e.from+o,e.to+o))),s,l);for(let t=0,o=s;;t++){let s=t==r.length,p=s?l:r[t].from;if(p>o&&i.push(new Cr(o,p,n.tree,-e,a.from>=o||a.openStart,a.to<=p||a.openEnd)),s)break;o=r[t].to}}else i.push(new Cr(s,l,n.tree,-e,a.from>=e||a.openStart,a.to<=r||a.openEnd))}return i}let Vr=0;class Nr{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=Vr++}static define(e){if(null==e?void 0:e.base)throw new Error("Can not derive from a modified tag");let t=new Nr([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new qr;return t=>t.modified.indexOf(e)>-1?t:qr.get(t.base||t,t.modified.concat(e).sort(((e,t)=>e.id-t.id)))}}let Wr=0;class qr{constructor(){this.instances=[],this.id=Wr++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find((i=>{return i.base==e&&(o=t,n=i.modified,o.length==n.length&&o.every(((e,t)=>e==n[t])));var o,n}));if(i)return i;let o=[],n=new Nr(o,e,t);for(let e of t)e.instances.push(n);let a=function(e){let t=[[]];for(let i=0;it.length-e.length))}(t);for(let t of e.set)if(!t.modified.length)for(let e of a)o.push(qr.get(t,e));return n}}function jr(e){let t=Object.create(null);for(let i in e){let o=e[i];Array.isArray(o)||(o=[o]);for(let e of i.split(" "))if(e){let i=[],n=2,a=e;for(let t=0;;){if("..."==a&&t>0&&t+3==e.length){n=1;break}let o=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(a);if(!o)throw new RangeError("Invalid path: "+e);if(i.push("*"==o[0]?"":'"'==o[0][0]?JSON.parse(o[0]):o[0]),t+=o[0].length,t==e.length)break;let r=e[t++];if(t==e.length&&"!"==r){n=0;break}if("/"!=r)throw new RangeError("Invalid path: "+e);a=e.slice(t)}let r=i.length-1,s=i[r];if(!s)throw new RangeError("Invalid path: "+e);let l=new Xr(o,n,r>0?i.slice(0,r):null);t[s]=l.sort(t[s])}}return _r.add(t)}const _r=new er;class Xr{constructor(e,t,i,o){this.tags=e,this.mode=t,this.context=i,this.next=o}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(e){return!e||e.depth{let t=n;for(let o of e)for(let e of o.set){let o=i[e.id];if(o){t=t?t+" "+o:o;break}}return t},scope:o}}function Ur(e,t,i,o=0,n=e.length){let a=new Hr(o,Array.isArray(t)?t:[t],i);a.highlightRange(e.cursor(),o,n,"",a.highlighters),a.flush(n)}Xr.empty=new Xr([],2,null);class Hr{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,o,n){let{type:a,from:r,to:s}=e;if(r>=i||s<=t)return;a.isTop&&(n=this.highlighters.filter((e=>!e.scope||e.scope(a))));let l=o,p=function(e){let t=e.type.prop(_r);for(;t&&t.context&&!e.matchContext(t.context);)t=t.next;return t||null}(e)||Xr.empty,d=function(e,t){let i=null;for(let o of e){let e=o.style(t);e&&(i=i?i+" "+e:e)}return i}(n,p.tags);if(d&&(l&&(l+=" "),l+=d,1==p.mode&&(o+=(o?" ":"")+d)),this.startSpan(e.from,l),p.opaque)return;let c=e.tree&&e.tree.prop(er.mounted);if(c&&c.overlay){let a=e.node.enter(c.overlay[0].from+r,1),p=this.highlighters.filter((e=>!e.scope||e.scope(c.tree.type))),d=e.firstChild();for(let h=0,f=r;;h++){let y=h=u)&&e.nextSibling()););if(!y||u>i)break;f=y.to+r,f>t&&(this.highlightRange(a.cursor(),Math.max(t,y.from+r),Math.min(i,f),o,p),this.startSpan(f,l))}d&&e.parent()}else if(e.firstChild()){do{if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,o,n),this.startSpan(Math.min(i,e.to),l)}}while(e.nextSibling());e.parent()}}}const Yr=Nr.define,Kr=Yr(),Jr=Yr(),es=Yr(Jr),ts=Yr(Jr),is=Yr(),os=Yr(is),ns=Yr(is),as=Yr(),rs=Yr(as),ss=Yr(),ls=Yr(),ps=Yr(),ds=Yr(ps),cs=Yr(),hs={comment:Kr,lineComment:Yr(Kr),blockComment:Yr(Kr),docComment:Yr(Kr),name:Jr,variableName:Yr(Jr),typeName:es,tagName:Yr(es),propertyName:ts,attributeName:Yr(ts),className:Yr(Jr),labelName:Yr(Jr),namespace:Yr(Jr),macroName:Yr(Jr),literal:is,string:os,docString:Yr(os),character:Yr(os),attributeValue:Yr(os),number:ns,integer:Yr(ns),float:Yr(ns),bool:Yr(is),regexp:Yr(is),escape:Yr(is),color:Yr(is),url:Yr(is),keyword:ss,self:Yr(ss),null:Yr(ss),atom:Yr(ss),unit:Yr(ss),modifier:Yr(ss),operatorKeyword:Yr(ss),controlKeyword:Yr(ss),definitionKeyword:Yr(ss),moduleKeyword:Yr(ss),operator:ls,derefOperator:Yr(ls),arithmeticOperator:Yr(ls),logicOperator:Yr(ls),bitwiseOperator:Yr(ls),compareOperator:Yr(ls),updateOperator:Yr(ls),definitionOperator:Yr(ls),typeOperator:Yr(ls),controlOperator:Yr(ls),punctuation:ps,separator:Yr(ps),bracket:ds,angleBracket:Yr(ds),squareBracket:Yr(ds),paren:Yr(ds),brace:Yr(ds),content:as,heading:rs,heading1:Yr(rs),heading2:Yr(rs),heading3:Yr(rs),heading4:Yr(rs),heading5:Yr(rs),heading6:Yr(rs),contentSeparator:Yr(as),list:Yr(as),quote:Yr(as),emphasis:Yr(as),strong:Yr(as),link:Yr(as),monospace:Yr(as),strikethrough:Yr(as),inserted:Yr(),deleted:Yr(),changed:Yr(),invalid:Yr(),meta:cs,documentMeta:Yr(cs),annotation:Yr(cs),processingInstruction:Yr(cs),definition:Nr.defineModifier(),constant:Nr.defineModifier(),function:Nr.defineModifier(),standard:Nr.defineModifier(),local:Nr.defineModifier(),special:Nr.defineModifier()};var fs;Zr([{tag:hs.link,class:"tok-link"},{tag:hs.heading,class:"tok-heading"},{tag:hs.emphasis,class:"tok-emphasis"},{tag:hs.strong,class:"tok-strong"},{tag:hs.keyword,class:"tok-keyword"},{tag:hs.atom,class:"tok-atom"},{tag:hs.bool,class:"tok-bool"},{tag:hs.url,class:"tok-url"},{tag:hs.labelName,class:"tok-labelName"},{tag:hs.inserted,class:"tok-inserted"},{tag:hs.deleted,class:"tok-deleted"},{tag:hs.literal,class:"tok-literal"},{tag:hs.string,class:"tok-string"},{tag:hs.number,class:"tok-number"},{tag:[hs.regexp,hs.escape,hs.special(hs.string)],class:"tok-string2"},{tag:hs.variableName,class:"tok-variableName"},{tag:hs.local(hs.variableName),class:"tok-variableName tok-local"},{tag:hs.definition(hs.variableName),class:"tok-variableName tok-definition"},{tag:hs.special(hs.variableName),class:"tok-variableName2"},{tag:hs.definition(hs.propertyName),class:"tok-propertyName tok-definition"},{tag:hs.typeName,class:"tok-typeName"},{tag:hs.namespace,class:"tok-namespace"},{tag:hs.className,class:"tok-className"},{tag:hs.macroName,class:"tok-macroName"},{tag:hs.propertyName,class:"tok-propertyName"},{tag:hs.operator,class:"tok-operator"},{tag:hs.comment,class:"tok-comment"},{tag:hs.meta,class:"tok-meta"},{tag:hs.invalid,class:"tok-invalid"},{tag:hs.punctuation,class:"tok-punctuation"}]);const ys=new er;function us(e){return L.define({combine:e?t=>t.concat(e):void 0})}const ms=new er;class gs{constructor(e,t,i=[],o=""){this.data=e,this.name=o,xe.prototype.hasOwnProperty("tree")||Object.defineProperty(xe.prototype,"tree",{get(){return ks(this)}}),this.parser=t,this.extension=[Qs.of(this),xe.languageData.of(((e,t,i)=>{let o=bs(e,t,i),n=o.type.prop(ys);if(!n)return[];let a=e.facet(n),r=o.type.prop(ms);if(r){let n=o.resolve(t-o.from,i);for(let t of r)if(t.test(n,e)){let i=e.facet(t.facet);return"replace"==t.type?i:i.concat(a)}}return a}))].concat(i)}isActiveAt(e,t,i=-1){return bs(e,t,i).type.prop(ys)==this.data}findRegions(e){let t=e.facet(Qs);if((null==t?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],o=(e,t)=>{if(e.prop(ys)==this.data)return void i.push({from:t,to:t+e.length});let n=e.prop(er.mounted);if(n){if(n.tree.prop(ys)==this.data){if(n.overlay)for(let e of n.overlay)i.push({from:e.from+t,to:e.to+t});else i.push({from:t,to:t+e.length});return}if(n.overlay){let e=i.length;if(o(n.tree,n.overlay[0].from+t),i.length>e)return}}for(let i=0;ie.isTop?t:void 0))]}),e.name)}configure(e,t){return new ws(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ks(e){let t=e.field(gs.state,!1);return t?t.tree:lr.empty}class vs{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)}}let Os=null;class xs{constructor(e,t,i=[],o,n,a,r,s){this.parser=e,this.state=t,this.fragments=i,this.tree=o,this.treeLen=n,this.viewport=a,this.skipped=r,this.scheduleOn=s,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new xs(e,t,[],lr.empty,0,i,[],null)}startParse(){return this.parser.startParse(new vs(this.state.doc),this.fragments)}work(e,t){return null!=t&&t>=this.state.doc.length&&(t=void 0),this.tree!=lr.empty&&this.isDone(null!=t?t:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var i;if("number"==typeof e){let t=Date.now()+e;e=()=>Date.now()>t}for(this.parse||(this.parse=this.startParse()),null!=t&&(null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&t=this.treeLen&&((null==this.parse.stoppedAt||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(Cr.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Os;Os=this;try{return e()}finally{Os=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Ss(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:o,treeLen:n,viewport:a,skipped:r}=this;if(this.takeTree(),!e.empty){let t=[];if(e.iterChangedRanges(((e,i,o,n)=>t.push({fromA:e,toA:i,fromB:o,toB:n}))),i=Cr.applyChanges(i,t),o=lr.empty,n=0,a={from:e.mapPos(a.from,-1),to:e.mapPos(a.to,1)},this.skipped.length){r=[];for(let t of this.skipped){let i=e.mapPos(t.from,1),o=e.mapPos(t.to,-1);ie.from&&(this.fragments=Ss(this.fragments,i,o),this.skipped.splice(t--,1))}return!(this.skipped.length>=t)&&(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 Pr{createParse(t,i,o){let n=o[0].from,a=o[o.length-1].to;return{parsedPos:n,advance(){let t=Os;if(t){for(let e of o)t.tempSkipped.push(e);e&&(t.scheduleOn=t.scheduleOn?Promise.all([t.scheduleOn,e]):e)}return this.parsedPos=a,new lr(or.none,[],[],a-n)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&0==t[0].from&&t[0].to>=e}static get(){return Os}}function Ss(e,t,i){return Cr.applyChanges(e,[{fromA:t,toA:i,fromB:t,toB:i}])}class Cs{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 Cs(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=xs.create(e.facet(Qs).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Cs(i)}}gs.state=N.define({create:Cs.init,update(e,t){for(let e of t.effects)if(e.is(gs.setState))return e.value;return t.startState.facet(Qs)!=t.state.facet(Qs)?Cs.init(t.state):e.apply(t)}});let Ps=e=>{let t=setTimeout((()=>e()),500);return()=>clearTimeout(t)};"undefined"!=typeof requestIdleCallback&&(Ps=e=>{let t=-1,i=setTimeout((()=>{t=requestIdleCallback(e,{timeout:400})}),100);return()=>t<0?clearTimeout(i):cancelIdleCallback(t)});const Ds="undefined"!=typeof navigator&&(null===(fs=navigator.scheduling)||void 0===fs?void 0:fs.isInputPending)?()=>navigator.scheduling.isInputPending():null,Ts=Qi.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(gs.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(gs.state);t.tree==t.context.tree&&t.context.isDone(e.doc.length)||(this.working=Ps(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEndo+1e3,s=n.context.work((()=>Ds&&Ds()||Date.now()>a),o+(r?0:1e5));this.chunkBudget-=Date.now()-t,(s||this.chunkBudget<=0)&&(n.context.takeTree(),this.view.dispatch({effects:gs.setState.of(new Cs(n.context))})),this.chunkBudget>0&&(!s||r)&&this.scheduleWork(),this.checkAsyncSchedule(n.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then((()=>this.scheduleWork())).catch((e=>Ci(this.view.state,e))).then((()=>this.workScheduled--)),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Qs=L.define({combine:e=>e.length?e[0]:null,enables:e=>[gs.state,Ts,Fn.contentAttributes.compute([e],(t=>{let i=t.facet(e);return i&&i.name?{"data-language":i.name}:{}}))]});class Rs{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class As{constructor(e,t,i,o,n,a=void 0){this.name=e,this.alias=t,this.extensions=i,this.filename=o,this.loadFunc=n,this.support=a,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then((e=>this.support=e),(e=>{throw this.loading=null,e})))}static of(e){let{load:t,support:i}=e;if(!t){if(!i)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(i)}return new As(e.name,(e.alias||[]).concat(e.name).map((e=>e.toLowerCase())),e.extensions||[],e.filename,t,i)}static matchFilename(e,t){for(let i of e)if(i.filename&&i.filename.test(t))return i;let i=/\.([^.]+)$/.exec(t);if(i)for(let t of e)if(t.extensions.indexOf(i[1])>-1)return t;return null}static matchLanguageName(e,t,i=!0){t=t.toLowerCase();for(let i of e)if(i.alias.some((e=>e==t)))return i;if(i)for(let i of e)for(let e of i.alias){let o=t.indexOf(e);if(o>-1&&(e.length>2||!/\w/.test(t[o-1])&&!/\w/.test(t[o+e.length])))return i}return null}}const Ms=L.define(),Es=L.define({combine:e=>{if(!e.length)return" ";let t=e[0];if(!t||/\S/.test(t)||Array.from(t).some((e=>e!=t[0])))throw new Error("Invalid indent unit: "+JSON.stringify(e[0]));return t}});function Fs(e){let t=e.facet(Es);return 9==t.charCodeAt(0)?e.tabSize*t.length:t.length}function Ls(e,t){let i="",o=e.tabSize,n=e.facet(Es)[0];if("\t"==n){for(;t>=o;)i+="\t",t-=o;n=" "}for(let e=0;e=i.from&&o<=i.to?n&&o==e?{text:"",from:e}:(t<0?o-1&&(n+=a-this.countColumn(i,i.search(/\S|$/))),n}countColumn(e,t=e.length){return Ve(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:o}=this.lineAt(e,t),n=this.options.overrideIndentation;if(n){let e=n(o);if(e>-1)return e}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Gs=new er;function $s(e){let t=e.type.prop(Gs);if(t)return t;let i,o=e.firstChild;if(o&&(i=o.type.prop(er.closedBy))){let t=e.lastChild,o=t&&i.indexOf(t.name)>-1;return e=>js(e,!0,1,void 0,o&&!function(e){return e.pos==e.options.simulateBreak&&e.options.simulateDoubleBreak}(e)?t.from:void 0)}return null==e.parent?Vs:null}function zs(e,t,i){for(;e;e=e.parent){let o=$s(e);if(o)return o(Ns.create(i,t,e))}return null}function Vs(){return 0}class Ns extends Is{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 Ns(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let e=this.state.doc.lineAt(this.node.from);for(;;){let t=this.node.resolve(e.from);for(;t.parent&&t.parent.from==t.from;)t=t.parent;if(Ws(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?zs(e,this.pos,this.base):0}}function Ws(e,t){for(let i=t;i;i=i.parent)if(e==i)return!0;return!1}function qs({closing:e,align:t=!0,units:i=1}){return o=>js(o,t,i,e)}function js(e,t,i,o,n){let a=e.textAfter,r=a.match(/^\s*/)[0].length,s=o&&a.slice(r,r+o.length)==o||n==e.pos+r,l=t?function(e){let t=e.node,i=t.childAfter(t.from),o=t.lastChild;if(!i)return null;let n=e.options.simulateBreak,a=e.state.doc.lineAt(i.from),r=null==n||n<=a.from?a.to:Math.min(a.to,n);for(let e=i.to;;){let n=t.childAfter(e);if(!n||n==o)return null;if(!n.type.isSkipped)return n.from{let o=e&&e.test(i.textAfter);return i.baseIndent+(o?0:t*i.unit)}}function Xs(){return xe.transactionFilter.of((e=>{if(!e.docChanged||!e.isUserEvent("input.type")&&!e.isUserEvent("input.complete"))return e;let t=e.startState.languageDataAt("indentOnInput",e.startState.selection.main.head);if(!t.length)return e;let i=e.newDoc,{head:o}=e.newSelection.main,n=i.lineAt(o);if(o>n.from+200)return e;let a=i.sliceString(n.from,o);if(!t.some((e=>e.test(a))))return e;let{state:r}=e,s=-1,l=[];for(let{head:e}of r.selection.ranges){let t=r.doc.lineAt(e);if(t.from==s)continue;s=t.from;let i=Bs(r,t.from);if(null==i)continue;let o=/^\s*/.exec(t.text)[0],n=Ls(r,i);o!=n&&l.push({from:t.from,to:t.from+o.length,insert:n})}return l.length?[e,{changes:l,sequential:!0}]:e}))}const Zs=L.define(),Us=new er;function Hs(e){let t=e.firstChild,i=e.lastChild;return t&&t.toe.prop(ys)==a.data:a?e=>e==a:void 0,this.style=Zr(e.map((e=>({tag:e.tag,class:e.class||o(Object.assign({},e,{tag:null}))}))),{all:n}).style,this.module=i?new je(i):null,this.themeType=t.themeType}static define(e,t){return new Ys(e,t||{})}}const Ks=L.define(),Js=L.define({combine:e=>e.length?[e[0]]:null});function el(e){let t=e.facet(Ks);return t.length?t:e.facet(Js)}function tl(e,t){let i,o=[ol];return e instanceof Ys&&(e.module&&o.push(Fn.styleModule.of(e.module)),i=e.themeType),(null==t?void 0:t.fallback)?o.push(Js.of(e)):i?o.push(Ks.computeN([Fn.darkTheme],(t=>t.facet(Fn.darkTheme)==("dark"==i)?[e]:[]))):o.push(Ks.of(e)),o}class il{constructor(e){this.markCache=Object.create(null),this.tree=ks(e.state),this.decorations=this.buildDeco(e,el(e.state))}update(e){let t=ks(e.state),i=el(e.state),o=i!=el(e.startState);t.length{i.add(e,t,this.markCache[o]||(this.markCache[o]=oi.mark({class:o})))}),o,n);return i.finish()}}const ol=Z.high(Qi.fromClass(il,{decorations:e=>e.decorations})),nl=Ys.define([{tag:hs.meta,color:"#404740"},{tag:hs.link,textDecoration:"underline"},{tag:hs.heading,textDecoration:"underline",fontWeight:"bold"},{tag:hs.emphasis,fontStyle:"italic"},{tag:hs.strong,fontWeight:"bold"},{tag:hs.strikethrough,textDecoration:"line-through"},{tag:hs.keyword,color:"#708"},{tag:[hs.atom,hs.bool,hs.url,hs.contentSeparator,hs.labelName],color:"#219"},{tag:[hs.literal,hs.inserted],color:"#164"},{tag:[hs.string,hs.deleted],color:"#a11"},{tag:[hs.regexp,hs.escape,hs.special(hs.string)],color:"#e40"},{tag:hs.definition(hs.variableName),color:"#00f"},{tag:hs.local(hs.variableName),color:"#30a"},{tag:[hs.typeName,hs.namespace],color:"#085"},{tag:hs.className,color:"#167"},{tag:[hs.special(hs.variableName),hs.macroName],color:"#256"},{tag:hs.definition(hs.propertyName),color:"#00c"},{tag:hs.comment,color:"#940"},{tag:hs.invalid,color:"#f00"}]),al=Fn.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),rl=1e4,sl="()[]{}",ll=L.define({combine:e=>Se(e,{afterCursor:!0,brackets:sl,maxScanDistance:rl,renderMatch:cl})}),pl=oi.mark({class:"cm-matchingBracket"}),dl=oi.mark({class:"cm-nonmatchingBracket"});function cl(e){let t=[],i=e.matched?pl:dl;return t.push(i.range(e.start.from,e.start.to)),e.end&&t.push(i.range(e.end.from,e.end.to)),t}const hl=N.define({create:()=>oi.none,update(e,t){if(!t.docChanged&&!t.selection)return e;let i=[],o=t.state.facet(ll);for(let e of t.state.selection.ranges){if(!e.empty)continue;let n=bl(t.state,e.head,-1,o)||e.head>0&&bl(t.state,e.head-1,1,o)||o.afterCursor&&(bl(t.state,e.head,1,o)||e.headFn.decorations.from(e)}),fl=[hl,al];function yl(e={}){return[ll.of(e),fl]}const ul=new er;function ml(e,t,i){let o=e.prop(t<0?er.openedBy:er.closedBy);if(o)return o;if(1==e.name.length){let o=i.indexOf(e.name);if(o>-1&&o%2==(t<0?1:0))return[i[o+t]]}return null}function gl(e){let t=e.type.prop(ul);return t?t(e.node):e}function bl(e,t,i,o={}){let n=o.maxScanDistance||rl,a=o.brackets||sl,r=ks(e),s=r.resolveInner(t,i);for(let o=s;o;o=o.parent){let n=ml(o.type,i,a);if(n&&o.from0?t>=r.from&&tr.from&&t<=r.to))return wl(e,t,i,o,r,n,a)}}return function(e,t,i,o,n,a,r){let s=i<0?e.sliceDoc(t-1,t):e.sliceDoc(t,t+1),l=r.indexOf(s);if(l<0||l%2==0!=i>0)return null;let p={from:i<0?t-1:t,to:i>0?t+1:t},d=e.doc.iterRange(t,i>0?e.doc.length:0),c=0;for(let e=0;!d.next().done&&e<=a;){let a=d.value;i<0&&(e+=a.length);let s=t+e*i;for(let e=i>0?0:a.length-1,t=i>0?a.length:-1;e!=t;e+=i){let t=r.indexOf(a[e]);if(!(t<0||o.resolveInner(s+e,1).type!=n))if(t%2==0==i>0)c++;else{if(1==c)return{start:p,end:{from:s+e,to:s+e+1},matched:t>>1==l>>1};c--}}i>0&&(e+=a.length)}return d.done?{start:p,matched:!1}:null}(e,t,i,r,s.type,n,a)}function wl(e,t,i,o,n,a,r){let s=o.parent,l={from:n.from,to:n.to},p=0,d=null==s?void 0:s.cursor();if(d&&(i<0?d.childBefore(o.from):d.childAfter(o.to)))do{if(i<0?d.to<=o.from:d.from>=o.to){if(0==p&&a.indexOf(d.type.name)>-1&&d.from=this.string.length}sol(){return 0==this.pos}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.post}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPosi?e.toLowerCase():e;return o(this.string.substr(this.pos,e.length))==o(e)?(!1!==t&&(this.pos+=e.length),!0):null}{let i=this.string.slice(this.pos).match(e);return i&&i.index>0?null:(i&&!1!==t&&(this.pos+=i[0].length),i)}}current(){return this.string.slice(this.start,this.pos)}}function Ol(e){if("object"!=typeof e)return e;let t={};for(let i in e){let o=e[i];t[i]=o instanceof Array?o.slice():o}return t}const xl=new WeakMap;class Sl extends gs{constructor(e){let t,i=us(e.languageData),o={name:(n=e).name||"",token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||Ol,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||Ql};var n;super(i,new class extends Pr{createParse(e,i,o){return new Dl(t,e,i,o)}},[Ms.of(((e,t)=>this.getIndent(e,t)))],e.name),this.topNode=function(e){let t=or.define({id:Rl.length,name:"Document",props:[ys.add((()=>e))]});return Rl.push(t),t}(i),t=this,this.streamParser=o,this.stateAfter=new er({perNode:!0}),this.tokenTable=e.tokenTable?new Fl(o.tokenTable):Ll}static define(e){return new Sl(e)}getIndent(e,t){let i,o=ks(e.state),n=o.resolve(t);for(;n&&n.type!=this.topNode;)n=n.parent;if(!n)return null;let{overrideIndentation:a}=e.options;a&&(i=xl.get(e.state),null!=i&&i1e4)return null;for(;r=o&&i+t.length<=n&&t.prop(e.stateAfter);if(a)return{state:e.streamParser.copyState(a),pos:i+t.length};for(let a=t.children.length-1;a>=0;a--){let r=t.children[a],s=i+t.positions[a],l=r instanceof lr&&s=t.length)return t;n||t.type!=e.topNode||(n=!0);for(let a=t.children.length-1;a>=0;a--){let r,s=t.positions[a],l=t.children[a];if(si&&Cl(e,o.tree,0-o.offset,i,a);if(r&&(t=Pl(e,o.tree,i+o.offset,r.pos+o.offset,!1)))return{state:r.state,tree:t}}return{state:e.streamParser.startState(o?Fs(o):4),tree:lr.empty}}(e,i,a,null==n?void 0:n.state);this.state=r,this.parsedPos=this.chunkStart=a+s.length;for(let e=0;e=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)"\n"==t&&(t="");else{let e=t.indexOf("\n");e>-1&&(t=t.slice(0,e))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let e=this.rangeIndex;;){let o=this.ranges[e].to;if(o>=i)break;if(t=t.slice(0,o-(i-t.length)),e++,e==this.ranges.length)break;let n=this.ranges[e].from,a=this.lineAfter(n);t+=a,i=n+a.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let o=this.ranges[this.rangeIndex].to,n=e+t;if(i>0?o>n:o>=n)break;t+=this.ranges[++this.rangeIndex].from-o}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){t+=n=this.skipGapsTo(t,n,1);let e=this.chunk.length;i+=n=this.skipGapsTo(i,n,-1),o+=this.chunk.length-e}return this.chunk.push(e,t,i,o),n}parseLine(e){let{line:t,end:i}=this.nextLine(),o=0,{streamParser:n}=this.lang,a=new vl(t,e?e.state.tabSize:4,e?Fs(e.state):2);if(a.eol())n.blankLine(this.state,a.indentUnit);else for(;!a.eol();){let e=Tl(n.token,a,this.state);if(e&&(o=this.emitToken(this.lang.tokenTable.resolve(e),this.parsedPos+a.start,this.parsedPos+a.pos,4,o)),a.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPost.start)return o}throw new Error("Stream parser failed to advance stream.")}const Ql=Object.create(null),Rl=[or.none],Al=new nr(Rl),Ml=[],El=Object.create(null);for(let[e,t]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"]])El[e]=Il(Ql,t);class Fl{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),El)}resolve(e){return e?this.table[e]||(this.table[e]=Il(this.extra,e)):0}}const Ll=new Fl(Ql);function Bl(e,t){Ml.indexOf(e)>-1||(Ml.push(e),console.warn(t))}function Il(e,t){let i=null;for(let o of t.split(".")){let t=e[o]||hs[o];t?"function"==typeof t?i?i=t(i):Bl(o,`Modifier ${o} used at start of tag`):i?Bl(o,`Tag ${o} used as modifier`):i=t:Bl(o,`Unknown highlighting tag ${o}`)}if(!i)return 0;let o=t.replace(/ /g,"_"),n=or.define({id:Rl.length,name:o,props:[jr({[o]:i})]});return Rl.push(n),n.id}function Gl(e,t){return({state:i,dispatch:o})=>{if(i.readOnly)return!1;let n=e(t,i);return!!n&&(o(i.update(n)),!0)}}const $l=Gl(jl,0),zl=Gl(ql,0),Vl=Gl(((e,t)=>ql(e,t,function(e){let t=[];for(let i of e.selection.ranges){let o=e.doc.lineAt(i.from),n=i.to<=o.to?o:e.doc.lineAt(i.to),a=t.length-1;a>=0&&t[a].to>o.from?t[a].to=n.to:t.push({from:o.from+/^\s*/.exec(o.text)[0].length,to:n.to})}return t}(t))),0);function Nl(e,t){let i=e.languageDataAt("commentTokens",t);return i.length?i[0]:{}}const Wl=50;function ql(e,t,i=t.selection.ranges){let o=i.map((e=>Nl(t,e.from).block));if(!o.every((e=>e)))return null;let n=i.map(((e,i)=>function(e,{open:t,close:i},o,n){let a,r,s=e.sliceDoc(o-Wl,o),l=e.sliceDoc(n,n+Wl),p=/\s*$/.exec(s)[0].length,d=/^\s*/.exec(l)[0].length,c=s.length-p;if(s.slice(c-t.length,c)==t&&l.slice(d,d+i.length)==i)return{open:{pos:o-p,margin:p&&1},close:{pos:n+d,margin:d&&1}};n-o<=2*Wl?a=r=e.sliceDoc(o,n):(a=e.sliceDoc(o,o+Wl),r=e.sliceDoc(n-Wl,n));let h=/^\s*/.exec(a)[0].length,f=/\s*$/.exec(r)[0].length,y=r.length-f-i.length;return a.slice(h,h+t.length)==t&&r.slice(y,y+i.length)==i?{open:{pos:o+h+t.length,margin:/\s/.test(a.charAt(h+t.length))?1:0},close:{pos:n-f-i.length,margin:/\s/.test(r.charAt(y-1))?1:0}}:null}(t,o[i],e.from,e.to)));if(2!=e&&!n.every((e=>e)))return{changes:t.changes(i.map(((e,t)=>n[t]?[]:[{from:e.from,insert:o[t].open+" "},{from:e.to,insert:" "+o[t].close}])))};if(1!=e&&n.some((e=>e))){let e=[];for(let t,i=0;in&&(e==a||a>l.from)){n=l.from;let e=/^\s*/.exec(l.text)[0].length,t=e==l.length,i=l.text.slice(e,e+s.length)==s?e:-1;ee.comment<0&&(!e.empty||e.single)))){let e=[];for(let{line:t,token:i,indent:n,empty:a,single:r}of o)!r&&a||e.push({from:t.from+n,insert:i+" "});let i=t.changes(e);return{changes:i,selection:t.selection.map(i,1)}}if(1!=e&&o.some((e=>e.comment>=0))){let e=[];for(let{line:t,comment:i,token:n}of o)if(i>=0){let o=t.from+i,a=o+n.length;" "==t.text[a-t.from]&&a++,e.push({from:o,to:a})}return{changes:e}}return null}const _l=le.define(),Xl=le.define(),Zl=L.define(),Ul=L.define({combine:e=>Se(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,o)=>e(i,o)||t(i,o)})});const Hl=N.define({create:()=>fp.empty,update(e,t){let i=t.state.facet(Ul),o=t.annotation(_l);if(o){let n=t.docChanged?M.single(function(e){let t=0;return e.iterChangedRanges(((e,i)=>t=i)),t}(t.changes)):void 0,a=op.fromTransaction(t,n),r=o.side,s=0==r?e.undone:e.done;return s=a?np(s,s.length,i.minDepth,a):lp(s,t.startState.selection),new fp(0==r?o.rest:s,0==r?s:o.rest)}let n=t.annotation(Xl);if("full"!=n&&"before"!=n||(e=e.isolate()),!1===t.annotation(he.addToHistory))return t.changes.empty?e:e.addMapping(t.changes.desc);let a=op.fromTransaction(t),r=t.annotation(he.time),s=t.annotation(he.userEvent);return a?e=e.addChanges(a,r,s,i,t):t.selection&&(e=e.addSelection(t.startState.selection,r,s,i.newGroupDelay)),"full"!=n&&"after"!=n||(e=e.isolate()),e},toJSON:e=>({done:e.done.map((e=>e.toJSON())),undone:e.undone.map((e=>e.toJSON()))}),fromJSON:e=>new fp(e.done.map(op.fromJSON),e.undone.map(op.fromJSON))});function Yl(e={}){return[Hl,Ul.of(e),Fn.domEventHandlers({beforeinput(e,t){let i="historyUndo"==e.inputType?Jl:"historyRedo"==e.inputType?ep:null;return!!i&&(e.preventDefault(),i(t))}})]}function Kl(e,t){return function({state:i,dispatch:o}){if(!t&&i.readOnly)return!1;let n=i.field(Hl,!1);if(!n)return!1;let a=n.pop(e,i,t);return!!a&&(o(a),!0)}}const Jl=Kl(0,!1),ep=Kl(1,!1),tp=Kl(0,!0),ip=Kl(1,!0);class op{constructor(e,t,i,o,n){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=o,this.selectionsAfter=n}setSelAfter(e){return new op(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:null===(e=this.changes)||void 0===e?void 0:e.toJSON(),mapped:null===(t=this.mapped)||void 0===t?void 0:t.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map((e=>e.toJSON()))}}static fromJSON(e){return new op(e.changes&&S.fromJSON(e.changes),[],e.mapped&&x.fromJSON(e.mapped),e.startSelection&&M.fromJSON(e.startSelection),e.selectionsAfter.map(M.fromJSON))}static fromTransaction(e,t){let i=rp;for(let t of e.startState.facet(Zl)){let o=t(e);o.length&&(i=i.concat(o))}return!i.length&&e.changes.empty?null:new op(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,rp)}static selection(e){return new op(void 0,rp,void 0,void 0,e)}}function np(e,t,i,o){let n=t+1>i+20?t-i-1:0,a=e.slice(n,t);return a.push(o),a}function ap(e,t){return e.length?t.length?e.concat(t):e:t}const rp=[],sp=200;function lp(e,t){if(e.length){let i=e[e.length-1],o=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-sp));return o.length&&o[o.length-1].eq(t)?e:(o.push(t),np(e,e.length-1,1e9,i.setSelAfter(o)))}return[op.selection([t])]}function pp(e){let t=e[e.length-1],i=e.slice();return i[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),i}function dp(e,t){if(!e.length)return e;let i=e.length,o=rp;for(;i;){let n=cp(e[i-1],t,o);if(n.changes&&!n.changes.empty||n.effects.length){let t=e.slice(0,i);return t[i-1]=n,t}t=n.mapped,i--,o=n.selectionsAfter}return o.length?[op.selection(o)]:rp}function cp(e,t,i){let o=ap(e.selectionsAfter.length?e.selectionsAfter.map((e=>e.map(t))):rp,i);if(!e.changes)return op.selection(o);let n=e.changes.map(t),a=t.mapDesc(e.changes,!0),r=e.mapped?e.mapped.composeDesc(a):a;return new op(n,ce.mapEffects(e.effects,t),r,e.startSelection.map(a),o)}const hp=/^(input\.type|delete)($|\.)/;class fp{constructor(e,t,i=0,o=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=o}isolate(){return this.prevTime?new fp(this.done,this.undone):this}addChanges(e,t,i,o,n){let a=this.done,r=a[a.length-1];return a=r&&r.changes&&!r.changes.empty&&e.changes&&(!i||hp.test(i))&&(!r.selectionsAfter.length&&t-this.prevTimei.push(e,t))),t.iterChangedRanges(((e,t,n,a)=>{for(let e=0;e=t&&n<=r&&(o=!0)}})),o}(r.changes,e.changes))||"input.type.compose"==i)?np(a,a.length-1,o.minDepth,new op(e.changes.compose(r.changes),ap(e.effects,r.effects),r.mapped,r.startSelection,rp)):np(a,a.length,o.minDepth,e),new fp(a,rp,t,i)}addSelection(e,t,i,o){let n=this.done.length?this.done[this.done.length-1].selectionsAfter:rp;return n.length>0&&t-this.prevTimee.empty!=r.ranges[t].empty)).length)?this:new fp(lp(this.done,e),this.undone,t,i);var a,r}addMapping(e){return new fp(dp(this.done,e),dp(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let o=0==e?this.done:this.undone;if(0==o.length)return null;let n=o[o.length-1];if(i&&n.selectionsAfter.length)return t.update({selection:n.selectionsAfter[n.selectionsAfter.length-1],annotations:_l.of({side:e,rest:pp(o)}),userEvent:0==e?"select.undo":"select.redo",scrollIntoView:!0});if(n.changes){let i=1==o.length?rp:o.slice(0,o.length-1);return n.mapped&&(i=dp(i,n.mapped)),t.update({changes:n.changes,selection:n.startSelection,effects:n.effects,annotations:_l.of({side:e,rest:i}),filter:!1,userEvent:0==e?"undo":"redo",scrollIntoView:!0})}return null}}fp.empty=new fp(rp,rp);const yp=[{key:"Mod-z",run:Jl,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:ep,preventDefault:!0},{linux:"Ctrl-Shift-z",run:ep,preventDefault:!0},{key:"Mod-u",run:tp,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:ip,preventDefault:!0}];function up(e,t){return M.create(e.ranges.map(t),e.mainIndex)}function mp(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function gp({state:e,dispatch:t},i){let o=up(e.selection,i);return!o.eq(e.selection)&&(t(mp(e,o)),!0)}function bp(e,t){return M.cursor(t?e.to:e.from)}function wp(e,t){return gp(e,(i=>i.empty?e.moveByChar(i,t):bp(i,t)))}function kp(e){return e.textDirectionAt(e.state.selection.main.head)==$i.LTR}const vp=e=>wp(e,!kp(e)),Op=e=>wp(e,kp(e));function xp(e,t){return gp(e,(i=>i.empty?e.moveByGroup(i,t):bp(i,t)))}function Sp(e,t,i){if(t.type.prop(i))return!0;let o=t.to-t.from;return o&&(o>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Cp(e,t,i){let o,n,a=ks(e).resolveInner(t.head),r=i?er.closedBy:er.openedBy;for(let o=t.head;;){let t=i?a.childAfter(o):a.childBefore(o);if(!t)break;Sp(e,t,r)?a=t:o=i?t.to:t.from}return n=a.type.prop(r)&&(o=i?bl(e,a.from,1):bl(e,a.to,-1))&&o.matched?i?o.end.to:o.end.from:i?a.to:a.from,M.cursor(n,i?-1:1)}function Pp(e,t){return gp(e,(i=>{if(!i.empty)return bp(i,t);let o=e.moveVertically(i,t);return o.head!=i.head?o:e.moveToLineBoundary(i,t)}))}const Dp=e=>Pp(e,!1),Tp=e=>Pp(e,!0);function Qp(e){let t,i=e.scrollDOM.clientHeighti.empty?e.moveVertically(i,t,o.height):bp(i,t)));if(a.eq(n.selection))return!1;if(o.selfScroll){let t=e.coordsAtPos(n.selection.main.head),r=e.scrollDOM.getBoundingClientRect(),s=r.top+o.marginTop,l=r.bottom-o.marginBottom;t&&t.top>s&&t.bottomRp(e,!1),Mp=e=>Rp(e,!0);function Ep(e,t,i){let o=e.lineBlockAt(t.head),n=e.moveToLineBoundary(t,i);if(n.head==t.head&&n.head!=(i?o.to:o.from)&&(n=e.moveToLineBoundary(t,i,!1)),!i&&n.head==o.from&&o.length){let i=/^\s*/.exec(e.state.sliceDoc(o.from,Math.min(o.from+100,o.to)))[0].length;i&&t.head!=o.from+i&&(n=M.cursor(o.from+i))}return n}function Fp(e,t){let i=up(e.state.selection,(e=>{let i=t(e);return M.range(e.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)}));return!i.eq(e.state.selection)&&(e.dispatch(mp(e.state,i)),!0)}function Lp(e,t){return console.log("Select!"),Fp(e,(i=>e.moveByCharSelected(i,t)))}const Bp=e=>Lp(e,!kp(e)),Ip=e=>Lp(e,kp(e));function Gp(e,t){return Fp(e,(i=>e.moveByGroup(i,t)))}function $p(e,t){return Fp(e,(i=>e.moveVertically(i,t)))}const zp=e=>$p(e,!1),Vp=e=>$p(e,!0);function Np(e,t){return Fp(e,(i=>e.moveVertically(i,t,Qp(e).height)))}const Wp=e=>Np(e,!1),qp=e=>Np(e,!0),jp=({state:e,dispatch:t})=>(t(mp(e,{anchor:0})),!0),_p=({state:e,dispatch:t})=>(t(mp(e,{anchor:e.doc.length})),!0),Xp=({state:e,dispatch:t})=>(t(mp(e,{anchor:e.selection.main.anchor,head:0})),!0),Zp=({state:e,dispatch:t})=>(t(mp(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0);function Up(e,t){if(e.state.readOnly)return!1;let i="delete.selection",{state:o}=e,n=o.changeByRange((o=>{let{from:n,to:a}=o;if(n==a){let o=t(n);on&&(i="delete.forward",o=Hp(e,o,!0)),n=Math.min(n,o),a=Math.max(a,o)}else n=Hp(e,n,!1),a=Hp(e,a,!0);return n==a?{range:o}:{changes:{from:n,to:a},range:M.cursor(n)}}));return!n.changes.empty&&(e.dispatch(o.update(n,{scrollIntoView:!0,userEvent:i,effects:"delete.selection"==i?Fn.announce.of(o.phrase("Selection deleted")):void 0})),!0)}function Hp(e,t,i){if(e instanceof Fn)for(let o of e.state.facet(Fn.atomicRanges).map((t=>t(e))))o.between(t,t,((e,o)=>{et&&(t=i?o:e)}));return t}const Yp=(e,t)=>Up(e,(i=>{let o,n,{state:a}=e,r=a.doc.lineAt(i);if(!t&&i>r.from&&iYp(e,!1),Jp=e=>Yp(e,!0),ed=(e,t)=>Up(e,(i=>{let o=i,{state:n}=e,a=n.doc.lineAt(o),r=n.charCategorizer(o);for(let e=null;;){if(o==(t?a.to:a.from)){o==i&&a.number!=(t?n.doc.lines:1)&&(o+=t?1:-1);break}let s=f(a.text,o-a.from,t)+a.from,l=a.text.slice(Math.min(o,s)-a.from,Math.max(o,s)-a.from),p=r(l);if(null!=e&&p!=e)break;" "==l&&o==i||(e=p),o=s}return o})),td=e=>ed(e,!1),id=e=>Up(e,(t=>{let i=e.lineBlockAt(t).to;return t=n.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(o)}else t.push({from:n.from,to:a.to,ranges:[o]});i=a.number+1}return t}function nd(e,t,i){if(e.readOnly)return!1;let o=[],n=[];for(let t of od(e)){if(i?t.to==e.doc.length:0==t.from)continue;let a=e.doc.lineAt(i?t.to+1:t.from-1),r=a.length+1;if(i){o.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let i of t.ranges)n.push(M.range(Math.min(e.doc.length,i.anchor+r),Math.min(e.doc.length,i.head+r)))}else{o.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)n.push(M.range(e.anchor-r,e.head-r))}}return!!o.length&&(t(e.update({changes:o,scrollIntoView:!0,selection:M.create(n,e.selection.mainIndex),userEvent:"move.line"})),!0)}function ad(e,t,i){if(e.readOnly)return!1;let o=[];for(let t of od(e))i?o.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):o.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});return t(e.update({changes:o,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const rd=sd(!1);function sd(t){return({state:i,dispatch:o})=>{if(i.readOnly)return!1;let n=i.changeByRange((o=>{let{from:n,to:a}=o,r=i.doc.lineAt(n),s=!t&&n==a&&function(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let i,o=ks(e).resolveInner(t),n=o.childBefore(t),a=o.childAfter(t);return n&&a&&n.to<=t&&a.from>=t&&(i=n.type.prop(er.closedBy))&&i.indexOf(a.name)>-1&&e.doc.lineAt(n.to).from==e.doc.lineAt(a.from).from?{from:n.to,to:a.from}:null}(i,n);t&&(n=a=(a<=r.to?r:i.doc.lineAt(a)).to);let l=new Is(i,{simulateBreak:n,simulateDoubleBreak:!!s}),p=Bs(l,n);for(null==p&&(p=/^\s*/.exec(i.doc.lineAt(n).text)[0].length);ar.from&&n{let n=[];for(let a=o.from;a<=o.to;){let r=e.doc.lineAt(a);r.number>i&&(o.empty||o.to>r.from)&&(t(r,n,o),i=r.number),a=r.to+1}let a=e.changes(n);return{changes:n,range:M.range(a.mapPos(o.anchor,1),a.mapPos(o.head,1))}}))}const pd=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(ld(e,((t,i)=>{i.push({from:t.from,insert:e.facet(Es)})})),{userEvent:"input.indent"})),!0),dd=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(ld(e,((t,i)=>{let o=/^\s*/.exec(t.text)[0];if(!o)return;let n=Ve(o,e.tabSize),a=0,r=Ls(e,Math.max(0,n-Fs(e)));for(;agp(e,(t=>Cp(e.state,t,!kp(e)))),shift:e=>Fp(e,(t=>Cp(e.state,t,!kp(e))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:e=>gp(e,(t=>Cp(e.state,t,kp(e)))),shift:e=>Fp(e,(t=>Cp(e.state,t,kp(e))))},{key:"Alt-ArrowUp",run:({state:e,dispatch:t})=>nd(e,t,!1)},{key:"Shift-Alt-ArrowUp",run:({state:e,dispatch:t})=>ad(e,t,!1)},{key:"Alt-ArrowDown",run:({state:e,dispatch:t})=>nd(e,t,!0)},{key:"Shift-Alt-ArrowDown",run:({state:e,dispatch:t})=>ad(e,t,!0)},{key:"Escape",run:({state:e,dispatch:t})=>{let i=e.selection,o=null;return i.ranges.length>1?o=M.create([i.main]):i.main.empty||(o=M.create([M.cursor(i.main.head)])),!!o&&(t(mp(e,o)),!0)}},{key:"Mod-Enter",run:sd(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:e,dispatch:t})=>{let i=od(e).map((({from:t,to:i})=>M.range(t,Math.min(i+1,e.doc.length))));return t(e.update({selection:M.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:e,dispatch:t})=>{let i=up(e.selection,(t=>{var i;let o=ks(e).resolveInner(t.head,1);for(;!(o.from=t.to||o.to>t.to&&o.from<=t.from)&&(null===(i=o.parent)||void 0===i?void 0:i.parent);)o=o.parent;return M.range(o.to,o.from)}));return t(mp(e,i)),!0},preventDefault:!0},{key:"Mod-[",run:dd},{key:"Mod-]",run:pd},{key:"Mod-Alt-\\",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=Object.create(null),o=new Is(e,{overrideIndentation:e=>{let t=i[e];return null==t?-1:t}}),n=ld(e,((t,n,a)=>{let r=Bs(o,t.from);if(null==r)return;/\S/.test(t.text)||(r=0);let s=/^\s*/.exec(t.text)[0],l=Ls(e,r);(s!=l||a.from{if(e.state.readOnly)return!1;let{state:t}=e,i=t.changes(od(t).map((({from:e,to:i})=>(e>0?e--:ie.moveVertically(t,!0))).map(i);return e.dispatch({changes:i,selection:o,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:e,dispatch:t})=>function(e,t,i){let o=!1,n=up(e.selection,(t=>{let n=bl(e,t.head,-1)||bl(e,t.head,1)||t.head>0&&bl(e,t.head-1,1)||t.head{let{state:t}=e,i=t.doc.lineAt(t.selection.main.from),o=Nl(e.state,i.from);return o.line?$l(e):!!o.block&&Vl(e)}},{key:"Alt-A",run:zl}].concat([{key:"ArrowLeft",run:vp,shift:Bp,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:e=>xp(e,!kp(e)),shift:e=>Gp(e,!kp(e)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:e=>gp(e,(t=>Ep(e,t,!kp(e)))),shift:e=>Fp(e,(t=>Ep(e,t,!kp(e)))),preventDefault:!0},{key:"ArrowRight",run:Op,shift:Ip,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:e=>xp(e,kp(e)),shift:e=>Gp(e,kp(e)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:e=>gp(e,(t=>Ep(e,t,kp(e)))),shift:e=>Fp(e,(t=>Ep(e,t,kp(e)))),preventDefault:!0},{key:"ArrowUp",run:Dp,shift:zp,preventDefault:!0},{mac:"Cmd-ArrowUp",run:jp,shift:Xp},{mac:"Ctrl-ArrowUp",run:Ap,shift:Wp},{key:"ArrowDown",run:Tp,shift:Vp,preventDefault:!0},{mac:"Cmd-ArrowDown",run:_p,shift:Zp},{mac:"Ctrl-ArrowDown",run:Mp,shift:qp},{key:"PageUp",run:Ap,shift:Wp},{key:"PageDown",run:Mp,shift:qp},{key:"Home",run:e=>gp(e,(t=>Ep(e,t,!1))),shift:e=>Fp(e,(t=>Ep(e,t,!1))),preventDefault:!0},{key:"Mod-Home",run:jp,shift:Xp},{key:"End",run:e=>gp(e,(t=>Ep(e,t,!0))),shift:e=>Fp(e,(t=>Ep(e,t,!0))),preventDefault:!0},{key:"Mod-End",run:_p,shift:Zp},{key:"Enter",run:rd},{key:"Mod-a",run:({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Kp,shift:Kp},{key:"Delete",run:Jp},{key:"Mod-Backspace",mac:"Alt-Backspace",run:td},{key:"Mod-Delete",mac:"Alt-Delete",run:e=>ed(e,!0)},{mac:"Mod-Backspace",run:e=>Up(e,(t=>{let i=e.lineBlockAt(t).from;return t>i?i:Math.max(0,t-1)}))},{mac:"Mod-Delete",run:id}].concat([{key:"Ctrl-b",run:vp,shift:Bp,preventDefault:!0},{key:"Ctrl-f",run:Op,shift:Ip},{key:"Ctrl-p",run:Dp,shift:zp},{key:"Ctrl-n",run:Tp,shift:Vp},{key:"Ctrl-a",run:e=>gp(e,(t=>M.cursor(e.lineBlockAt(t.head).from,1))),shift:e=>Fp(e,(t=>M.cursor(e.lineBlockAt(t.head).from)))},{key:"Ctrl-e",run:e=>gp(e,(t=>M.cursor(e.lineBlockAt(t.head).to,-1))),shift:e=>Fp(e,(t=>M.cursor(e.lineBlockAt(t.head).to)))},{key:"Ctrl-d",run:Jp},{key:"Ctrl-h",run:Kp},{key:"Ctrl-k",run:id},{key:"Ctrl-Alt-h",run:td},{key:"Ctrl-o",run:({state:t,dispatch:i})=>{if(t.readOnly)return!1;let o=t.changeByRange((t=>({changes:{from:t.from,to:t.to,insert:e.of(["",""])},range:M.cursor(t.from)})));return i(t.update(o,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange((t=>{if(!t.empty||0==t.from||t.from==e.doc.length)return{range:t};let i=t.from,o=e.doc.lineAt(i),n=i==o.from?i-1:f(o.text,i-o.from,!1)+o.from,a=i==o.to?i+1:f(o.text,i-o.from,!0)+o.from;return{changes:{from:n,to:a,insert:e.doc.slice(i,a).append(e.doc.slice(n,i))},range:M.cursor(a)}}));return!i.changes.empty&&(t(e.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Mp}].map((e=>({mac:e.key,run:e.run,shift:e.shift}))))),hd={key:"Tab",run:pd,shift:dd},fd="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class yd{constructor(e,t,i=0,o=e.length,n,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,o),this.bufferStart=i,this.normalize=n?e=>n(fd(e)):fd,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 b(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=w(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=k(e);let o=this.normalize(t);for(let e=0,n=i;;e++){let a=o.charCodeAt(e),r=this.match(a,n);if(r)return this.value=r,this;if(e==o.length-1)break;n==i&&eSe(e,ud,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});function gd(e){let t=[Od,vd];return e&&t.push(md.of(e)),t}const bd=oi.mark({class:"cm-selectionMatch"}),wd=oi.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function kd(e,t,i,o){return!(0!=i&&e(t.sliceDoc(i-1,i))==we.Word||o!=t.doc.length&&e(t.sliceDoc(o,o+1))==we.Word)}const vd=Qi.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(md),{state:i}=e,o=i.selection;if(o.ranges.length>1)return oi.none;let n,a=o.main,r=null;if(a.empty){if(!t.highlightWordAroundCursor)return oi.none;let e=i.wordAt(a.head);if(!e)return oi.none;r=i.charCategorizer(a.head),n=i.sliceDoc(e.from,e.to)}else{let e=a.to-a.from;if(e200)return oi.none;if(t.wholeWords){if(n=i.sliceDoc(a.from,a.to),r=i.charCategorizer(a.head),!kd(r,i,a.from,a.to)||!function(e,t,i,o){return e(t.sliceDoc(i,i+1))==we.Word&&e(t.sliceDoc(o-1,o))==we.Word}(r,i,a.from,a.to))return oi.none}else if(n=i.sliceDoc(a.from,a.to).trim(),!n)return oi.none}let s=[];for(let o of e.visibleRanges){let e=new yd(i.doc,n,o.from,o.to);for(;!e.next().done;){let{from:o,to:n}=e.value;if((!r||kd(r,i,o,n))&&(a.empty&&o<=a.from&&n>=a.to?s.push(wd.range(o,n)):(o>=a.to||n<=a.from)&&s.push(bd.range(o,n)),s.length>t.maxMatches))return oi.none}}return oi.set(s)}},{decorations:e=>e.decorations}),Od=Fn.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});class xd{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=ks(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),o=t.text.slice(i-t.from,this.pos-t.from),n=o.search(Td(e,!1));return n<0?null:{from:i+n,to:this.pos,text:o.slice(n)}}get aborted(){return null==this.abortListeners}addEventListener(e,t){"abort"==e&&this.abortListeners&&this.abortListeners.push(t)}}function Sd(e){let t=Object.keys(e).join(""),i=/\w/.test(t);return i&&(t=t.replace(/\w/g,"")),`[${i?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Cd(e){let t=e.map((e=>"string"==typeof e?{label:e}:e)),[i,o]=t.every((e=>/^\w+$/.test(e.label)))?[/\w*$/,/\w+$/]:function(e){let t=Object.create(null),i=Object.create(null);for(let{label:o}of e){t[o[0]]=!0;for(let e=1;e{let n=e.matchBefore(o);return n||e.explicit?{from:n?n.from:e.pos,options:t,validFor:i}:null}}class Pd{constructor(e,t,i,o){this.completion=e,this.source=t,this.match=i,this.score=o}}function Dd(e){return e.selection.main.from}function Td(e,t){var i;let{source:o}=e,n=t&&"^"!=o[0],a="$"!=o[o.length-1];return n||a?new RegExp(`${n?"^":""}(?:${o})${a?"$":""}`,null!==(i=e.flags)&&void 0!==i?i:e.ignoreCase?"i":""):e}const Qd=le.define();const Rd=new WeakMap;function Ad(e){if(!Array.isArray(e))return e;let t=Rd.get(e);return t||Rd.set(e,t=Cd(e)),t}const Md=ce.define(),Ed=ce.define();class Fd{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[];for(let t=0;t=48&&l<=57||l>=97&&l<=122?2:l>=65&&l<=90?1:0:(v=w(l))!=v.toLowerCase()?1:v!=v.toUpperCase()?2:0;(!o||1==O&&u||0==g&&0!=O)&&(t[d]==l||i[d]==l&&(c=!0)?a[d++]=o:a.length&&(m=!1)),g=O,o+=k(l)}return d==s&&0==a[0]&&m?this.result((c?-200:0)-100,a,e):h==s&&0==f?[-200-e.length+(y==e.length?0:-100),0,y]:r>-1?[-700-e.length,r,r+this.pattern.length]:h==s?[-900-e.length,f,y]:d==s?this.result((c?-200:0)-100-700+(m?0:-1100),a,e):2==t.length?null:this.result((o[0]?-700:0)-200-1100,o,e)}result(e,t,i){let o=[e-i.length],n=1;for(let e of t){let t=e+(this.astral?k(b(i,e)):1);n>1&&o[n-1]==e?o[n-1]=t:(o[n++]=e,o[n++]=t)}return o}}const Ld=L.define({combine:e=>Se(e,{activateOnTyping:!0,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Id,compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>Bd(e(i),t(i)),optionClass:(e,t)=>i=>Bd(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})});function Bd(e,t){return e?t?e+" "+t:e:t}function Id(e,t,i,o,n){let a,r,s=e.textDirection==$i.RTL,l=s,p=!1,d="top",c=t.left-n.left,h=n.right-t.right,f=o.right-o.left,y=o.bottom-o.top;if(l&&c