r.bottom)&&y==r.bottom-h.bottom>h.top-r.top&&(y=!y);let w=(y?h.top-r.top:r.bottom-h.bottom)-d;if(wv&&t.topb&&(b=y?t.top-p-2-d:t.bottom+d+2);"absolute"==this.position?(l.style.top=b-t.parent.top+"px",l.style.left=v-t.parent.left+"px"):(l.style.top=b+"px",l.style.left=v+"px"),u&&(u.style.left=h.left+(g?m.x:-m.x)-(v+14-7)+"px"),!0!==a.overlap&&i.push({left:v,top:b,right:x,bottom:b+p}),l.classList.toggle("cm-tooltip-above",y),l.classList.toggle("cm-tooltip-below",!y),a.positioned&&a.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=ca}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),ga={x:0,y:0},va=ue.define({enables:[ma,fs.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"}}})]}),ya=ue.define();class wa{constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new ua(t,ya,(t=>this.createHostedView(t)))}static create(t){return new wa(t)}createHostedView(t){let e=t.create(this.view);return e.dom.classList.add("cm-tooltip-section"),this.dom.appendChild(e.dom),this.mounted&&e.mount&&e.mount(this.view),e}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)null===(t=e.destroy)||void 0===t||t.call(e)}}const ba=va.compute([ya],(t=>{let e=t.facet(ya).filter((t=>t));return 0===e.length?null:{pos:Math.min(...e.map((t=>t.pos))),end:Math.max(...e.filter((t=>null!=t.end)).map((t=>t.end))),create:wa.create,above:e[0].above,arrow:e.some((t=>t.arrow))}}));class xa{constructor(t,e,n,r,i){this.view=t,this.source=e,this.field=n,this.setHover=r,this.hoverTime=i,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout((()=>this.startHover()),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active)return;let t=Date.now()-this.lastMove.time;tn.bottom||t.xn.right+this.view.defaultCharacterWidth)return;let r=this.view.bidiSpans(this.view.state.doc.lineAt(e)).find((t=>t.from<=e&&t.to>=e)),i=r&&r.dir==gi.RTL?-1:1,o=this.source(this.view,e,t.x{this.pending==t&&(this.pending=null,e&&this.view.dispatch({effects:this.setHover.of(e)}))}),(t=>ei(this.view.state,t,"hover tooltip")))}else o&&this.view.dispatch({effects:this.setHover.of(o)})}mousemove(t){var e;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let n=this.active;if(n&&!ka(this.lastMove.target)||this.pending){let{pos:r}=n||this.pending,i=null!==(e=null==n?void 0:n.end)&&void 0!==e?e:r;(r==i?this.view.posAtCoords(this.lastMove)==r:function(t,e,n,r,i,o){let s=document.createRange(),a=t.domAtPos(e),l=t.domAtPos(n);s.setEnd(l.node,l.offset),s.setStart(a.node,a.offset);let h=s.getClientRects();s.detach();for(let t=0;t-1?n.panels[r]:null}const Ta=oi.fromClass(class{constructor(t){this.input=t.state.facet(Da),this.specs=this.input.filter((t=>t)),this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(Ca);this.top=new Ma(t,!0,e.topContainer),this.bottom=new Ma(t,!1,e.bottomContainer),this.top.sync(this.panels.filter((t=>t.top))),this.bottom.sync(this.panels.filter((t=>!t.top)));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(Ca);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Ma(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ma(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=t.state.facet(Da);if(n!=this.input){let e=n.filter((t=>t)),r=[],i=[],o=[],s=[];for(let n of e){let e,a=this.specs.indexOf(n);a<0?(e=n(t.view),s.push(e)):(e=this.panels[a],e.update&&e.update(t)),r.push(e),(e.top?i:o).push(e)}this.specs=e,this.panels=r,this.top.sync(i),this.bottom.sync(o);for(let t of s)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>fs.scrollMargins.of((e=>{let n=e.plugin(t);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}}))});class Ma{constructor(t,e,n){this.view=t,this.top=e,this.container=n,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=_a(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=_a(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(this.container&&this.classes!=this.view.themeClasses){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function _a(t){let e=t.nextSibling;return t.remove(),e}const Da=ue.define({enables:Ta});class Oa extends en{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Oa.prototype.elementClass="",Oa.prototype.toDOM=void 0,Oa.prototype.mapMode=Qt.TrackBefore,Oa.prototype.startSide=Oa.prototype.endSide=-1,Oa.prototype.point=!0;const Pa=ue.define(),Ia={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>sn.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},Ra=ue.define();function Na(t){return[Ba(),Ra.of(Object.assign(Object.assign({},Ia),t))]}const La=ue.define({combine:t=>t.some((t=>t))});function Ba(t){let e=[Fa];return t&&!1===t.fixed&&e.push(La.of(!0)),e}const Fa=oi.fromClass(class{constructor(t){this.view=t,this.prevViewport=t.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=t.state.facet(Ra).map((e=>new Va(t,e)));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!t.state.facet(La),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}update(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,r=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(r<.8*(n.to-n.from))}t.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight+"px"),this.view.state.facet(La)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&this.dom.remove();let n=sn.iter(this.view.state.facet(Pa),this.view.viewport.from),r=[],i=this.gutters.map((t=>new Wa(t,this.view.viewport,-this.view.documentPadding.top)));for(let t of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(t.type)){let e=!0;for(let o of t.type)if(o.type==Pr.Text&&e){Ha(n,r,o.from);for(let t of i)t.line(this.view,o,r);e=!1}else if(o.widget)for(let t of i)t.widget(this.view,o)}else if(t.type==Pr.Text){Ha(n,r,t.from);for(let e of i)e.line(this.view,t,r)}for(let t of i)t.finish();t&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(t){let e=t.startState.facet(Ra),n=t.state.facet(Ra),r=t.docChanged||t.heightChanged||t.viewportChanged||!sn.eq(t.startState.facet(Pa),t.state.facet(Pa),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let e of this.gutters)e.update(t)&&(r=!0);else{r=!0;let i=[];for(let r of n){let n=e.indexOf(r);n<0?i.push(new Va(this.view,r)):(this.gutters[n].update(t),i.push(this.gutters[n]))}for(let t of this.gutters)t.dom.remove(),i.indexOf(t)<0&&t.destroy();for(let t of i)this.dom.appendChild(t.dom);this.gutters=i}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove()}},{provide:t=>fs.scrollMargins.of((e=>{let n=e.plugin(t);return n&&0!=n.gutters.length&&n.fixed?e.textDirection==gi.LTR?{left:n.dom.offsetWidth}:{right:n.dom.offsetWidth}:null}))});function za(t){return Array.isArray(t)?t:[t]}function Ha(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}class Wa{constructor(t,e,n){this.gutter=t,this.height=n,this.i=0,this.cursor=sn.iter(t.markers,e.from)}addElement(t,e,n){let{gutter:r}=this,i=e.top-this.height;if(this.i==r.elements.length){let o=new Ua(t,e.height,i,n);r.elements.push(o),r.dom.appendChild(o.dom)}else r.elements[this.i].update(t,e.height,i,n);this.height=e.bottom,this.i++}line(t,e,n){let r=[];Ha(this.cursor,r,e.from),n.length&&(r=r.concat(n));let i=this.gutter.config.lineMarker(t,e,r);i&&r.unshift(i);let o=this.gutter;(0!=r.length||o.config.renderEmptyElements)&&this.addElement(t,e,r)}widget(t,e){let n=this.gutter.config.widgetMarker(t,e.widget,e);n&&this.addElement(t,e,[n])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Va{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let n in e.domEventHandlers)this.dom.addEventListener(n,(r=>{let i,o=r.target;if(o!=this.dom&&this.dom.contains(o)){for(;o.parentNode!=this.dom;)o=o.parentNode;let t=o.getBoundingClientRect();i=(t.top+t.bottom)/2}else i=r.clientY;let s=t.lineBlockAtHeight(i-t.documentTop);e.domEventHandlers[n](t,s,r)&&r.preventDefault()}));this.markers=za(e.markers(t)),e.initialSpacer&&(this.spacer=new Ua(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=za(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let n=t.view.viewport;return!sn.eq(this.markers,e,n.from,n.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class Ua{constructor(t,e,n,r){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,n,r)}update(t,e,n,r){this.height!=e&&(this.dom.style.height=(this.height=e)+"px"),this.above!=n&&(this.dom.style.marginTop=(this.above=n)?n+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let n=0;ntn(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let n=Object.assign({},t);for(let t in e){let r=n[t],i=e[t];n[t]=r?(t,e,n)=>r(t,e,n)||i(t,e,n):i}return n}})});class qa extends Oa{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Xa(t,e){return t.state.facet($a).formatNumber(e,t.state)}const Ka=Ra.compute([$a],(t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(ja),lineMarker:(t,e,n)=>n.some((t=>t.toDOM))?null:new qa(Xa(t,t.state.doc.lineAt(e.from).number)),widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet($a)!=t.state.facet($a),initialSpacer:t=>new qa(Xa(t,Ya(t.state.doc.lines))),updateSpacer(t,e){let n=Xa(e.view,Ya(e.view.state.doc.lines));return n==t.number?t:new qa(n)},domEventHandlers:t.facet($a).domEventHandlers})));function Ga(t={}){return[$a.of(t),Ba(),Ka]}function Ya(t){let e=9;for(;e{let e=[],n=-1;for(let r of t.selection.ranges){let i=t.doc.lineAt(r.head).from;i>n&&(n=i,e.push(Ja.range(i)))}return sn.of(e)}));const Za=1024;let tl=0;class el{constructor(t,e){this.from=t,this.to=e}}class nl{constructor(t={}){this.id=tl++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=il.match(t)),e=>{let n=t(e);return void 0===n?null:[this,n]}}}nl.closedBy=new nl({deserialize:t=>t.split(" ")}),nl.openedBy=new nl({deserialize:t=>t.split(" ")}),nl.group=new nl({deserialize:t=>t.split(" ")}),nl.contextHash=new nl({perNode:!0}),nl.lookAhead=new nl({perNode:!0}),nl.mounted=new nl({perNode:!0});const rl=Object.create(null);class il{constructor(t,e,n,r=0){this.name=t,this.props=e,this.id=n,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):rl,n=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),r=new il(t.name||"",e,t.id,n);if(t.props)for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}return r}prop(t){return this.props[t.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(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(nl.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let n in t)for(let r of n.split(" "))e[r]=t[n];return t=>{for(let n=t.prop(nl.group),r=-1;r<(n?n.length:0);r++){let i=e[r<0?t.name:n[r]];if(i)return i}}}}il.none=new il("",Object.create(null),0,8);const ol=new WeakMap,sl=new WeakMap;var al,ll;(ll=al||(al={}))[ll.ExcludeBuffers=1]="ExcludeBuffers",ll[ll.IncludeAnonymous=2]="IncludeAnonymous",ll[ll.IgnoreMounts=4]="IgnoreMounts",ll[ll.IgnoreOverlays=8]="IgnoreOverlays";class hl{constructor(t,e,n,r,i){if(this.type=t,this.children=e,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[t,e]of i)this.props["number"==typeof t?t:t.id]=e}}toString(){let t=this.prop(nl.mounted);if(t&&!t.overlay)return t.tree.toString();let e="";for(let t of this.children){let n=t.toString();n&&(e&&(e+=","),e+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new bl(this.topNode,t)}cursorAt(t,e=0,n=0){let r=ol.get(this)||this.topNode,i=new bl(r);return i.moveTo(t,e),ol.set(this,i._tree),i}get topNode(){return new ml(this,0,0,null)}resolve(t,e=0){let n=pl(ol.get(this)||this.topNode,t,e,!1);return ol.set(this,n),n}resolveInner(t,e=0){let n=pl(sl.get(this)||this.topNode,t,e,!0);return sl.set(this,n),n}iterate(t){let{enter:e,leave:n,from:r=0,to:i=this.length}=t,o=t.mode||0,s=(o&al.IncludeAnonymous)>0;for(let t=this.cursor(o|al.IncludeAnonymous);;){let o=!1;if(t.from<=i&&t.to>=r&&(!s&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;o=!0}for(;o&&n&&(s||!t.type.isAnonymous)&&n(t),!t.nextSibling();){if(!t.parent())return;o=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:El(il.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,n)=>new hl(this.type,t,e,n,this.propValues)),t.makeTree||((t,e,n)=>new hl(il.none,t,e,n)))}static build(t){return function(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:i=Za,reused:o=[],minRepeatType:s=r.types.length}=t,a=Array.isArray(n)?new cl(n,n.length):n,l=r.types,h=0,c=0;function u(t,e,n,v,y){let{id:w,start:b,end:x,size:k}=a,S=c;for(;k<0;){if(a.next(),-1==k){let e=o[w];return n.push(e),void v.push(b-t)}if(-3==k)return void(h=w);if(-4==k)return void(c=w);throw new RangeError(`Unrecognized record size: ${k}`)}let E,C,A=l[w],T=b-t;if(x-b<=i&&(C=m(a.pos-e,y))){let e=new Uint16Array(C.size-C.skip),n=a.pos-C.size,i=e.length;for(;a.pos>n;)i=g(C.start,e,i);E=new ul(e,x-C.start,r),T=C.start-t}else{let t=a.pos-k;a.next();let e=[],n=[],r=w>=s?w:-1,o=0,l=x;for(;a.pos>t;)r>=0&&a.id==r&&a.size>=0?(a.end<=l-i&&(f(e,n,b,o,a.end,l,r,S),o=e.length,l=a.end),a.next()):u(b,t,e,n,r);if(r>=0&&o>0&&o-1&&o>0){let t=d(A);E=El(A,e,n,0,e.length,0,x-b,t,t)}else E=p(A,e,n,x-b,S-x)}n.push(E),v.push(T)}function d(t){return(e,n,r)=>{let i,o,s=0,a=e.length-1;if(a>=0&&(i=e[a])instanceof hl){if(!a&&i.type==t&&i.length==r)return i;(o=i.prop(nl.lookAhead))&&(s=n[a]+i.length+o)}return p(t,e,n,r,s)}}function f(t,e,n,i,o,s,a,l){let h=[],c=[];for(;t.length>i;)h.push(t.pop()),c.push(e.pop()+n-o);t.push(p(r.types[a],h,c,s-o,l-s)),e.push(o-n)}function p(t,e,n,r,i=0,o){if(h){let t=[nl.contextHash,h];o=o?[t].concat(o):[t]}if(i>25){let t=[nl.lookAhead,i];o=o?[t].concat(o):[t]}return new hl(t,e,n,r,o)}function m(t,e){let n=a.fork(),r=0,o=0,l=0,h=n.end-i,c={size:0,start:0,skip:0};t:for(let i=n.pos-t;n.pos>i;){let t=n.size;if(n.id==e&&t>=0){c.size=r,c.start=o,c.skip=l,l+=4,r+=4,n.next();continue}let a=n.pos-t;if(t<0||a=s?4:0,d=n.start;for(n.next();n.pos>a;){if(n.size<0){if(-3!=n.size)break t;u+=4}else n.id>=s&&(u+=4);n.next()}o=d,r+=t,l+=u}return(e<0||r==t)&&(c.size=r,c.start=o,c.skip=l),c.size>4?c:void 0}function g(t,e,n){let{id:r,start:i,end:o,size:l}=a;if(a.next(),l>=0&&r4){let r=a.pos-(l-4);for(;a.pos>r;)n=g(t,e,n)}e[--n]=s,e[--n]=o-t,e[--n]=i-t,e[--n]=r}else-3==l?h=r:-4==l&&(c=r);return n}let v=[],y=[];for(;a.pos>0;)u(t.start||0,t.bufferStart||0,v,y,-1);let w=null!==(e=t.length)&&void 0!==e?e:v.length?y[0]+v[0].length:0;return new hl(l[t.topID],v.reverse(),y.reverse(),w)}(t)}}hl.empty=new hl(il.none,[],[],0);class cl{constructor(t,e){this.buffer=t,this.index=e}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 cl(this.buffer,this.index)}}class ul{constructor(t,e,n){this.buffer=t,this.length=e,this.set=n}get type(){return il.none}toString(){let t=[];for(let e=0;e0));a=o[a+3]);return s}slice(t,e,n){let r=this.buffer,i=new Uint16Array(e-t),o=0;for(let s=t,a=0;s=e&≠case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function fl(t,e){let n=t.childBefore(e);for(;n;){let e=n.lastChild;if(!e||e.to!=n.to)break;e.type.isError&&e.from==e.to?(t=n,n=e.prevSibling):n=e}return t}function pl(t,e,n,r){for(var i;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to0?s.length:-1;t!=l;t+=e){let l=s[t],h=a[t]+o.from;if(dl(r,n,h,h+l.length))if(l instanceof ul){if(i&al.ExcludeBuffers)continue;let s=l.findChild(0,l.buffer.length,e,n-h,r);if(s>-1)return new wl(new yl(o,l,t,h),null,s)}else if(i&al.IncludeAnonymous||!l.type.isAnonymous||xl(l)){let s;if(!(i&al.IgnoreMounts)&&l.props&&(s=l.prop(nl.mounted))&&!s.overlay)return new ml(s.tree,h,t,o);let a=new ml(l,h,t,o);return i&al.IncludeAnonymous||!a.type.isAnonymous?a:a.nextChild(e<0?l.children.length-1:0,e,n,r)}}if(i&al.IncludeAnonymous||!o.type.isAnonymous)return null;if(t=o.index>=0?o.index+e:e<0?-1:o._parent._tree.children.length,o=o._parent,!o)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,n=0){let r;if(!(n&al.IgnoreOverlays)&&(r=this._tree.prop(nl.mounted))&&r.overlay){let n=t-this.from;for(let{from:t,to:i}of r.overlay)if((e>0?t<=n:t=n:i>n))return new ml(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,n)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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(t=0){return new bl(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return pl(this,t,e,!1)}resolveInner(t,e=0){return pl(this,t,e,!0)}enterUnfinishedNodesBefore(t){return fl(this,t)}getChild(t,e=null,n=null){let r=gl(this,t,e,n);return r.length?r[0]:null}getChildren(t,e=null,n=null){return gl(this,t,e,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return vl(this,t)}}function gl(t,e,n,r){let i=t.cursor(),o=[];if(!i.firstChild())return o;if(null!=n)for(;!i.type.is(n);)if(!i.nextSibling())return o;for(;;){if(null!=r&&i.type.is(r))return o;if(i.type.is(e)&&o.push(i.node),!i.nextSibling())return null==r?o:[]}}function vl(t,e,n=e.length-1){for(let r=t.parent;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}class yl{constructor(t,e,n,r){this.parent=t,this.buffer=e,this.index=n,this.start=r}}class wl{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(t,e,n){this.context=t,this._parent=e,this.index=n,this.type=t.buffer.set.types[t.buffer.buffer[n]]}child(t,e,n){let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,n);return i<0?null:new wl(this.context,this,i)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,n=0){if(n&al.ExcludeBuffers)return null;let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return i<0?null:new wl(this.context,this,i)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new wl(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new wl(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new bl(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let o=n.buffer[this.index+1];t.push(n.slice(r,i,o)),e.push(0)}return new hl(this.type,t,e,this.to-this.from)}resolve(t,e=0){return pl(this,t,e,!1)}resolveInner(t,e=0){return pl(this,t,e,!0)}enterUnfinishedNodesBefore(t){return fl(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,n=null){let r=gl(this,t,e,n);return r.length?r[0]:null}getChildren(t,e=null,n=null){return gl(this,t,e,n)}get node(){return this}matchContext(t){return vl(this,t)}}class bl{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof ml)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return!!t&&(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0)}yieldBuf(t,e){this.index=t;let{start:n,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=n+r.buffer[t+1],this.to=n+r.buffer[t+2],!0}yield(t){return!!t&&(t instanceof ml?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,n){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,n);return!(i<0)&&(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,n=this.mode){return this.buffer?!(n&al.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&al.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&al.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode));let{buffer:e}=this.buffer,n=this.stack.length-1;if(t<0){let t=n<0?0:this.stack[n]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(n<0?e.buffer.length:e.buffer[this.stack[n]+3]))return this.yieldBuf(t)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,n,{buffer:r}=this;if(r){if(t>0){if(this.index-1)for(let r=e+t,i=t<0?-1:n._tree.children.length;r!=i;r+=t){let t=n._tree.children[r];if(this.mode&al.IncludeAnonymous||t instanceof ul||!t.type.isAnonymous||xl(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let o=t;o;o=o._parent)if(o.index==r){if(r==this.index)return o;e=o,n=i+1;break t}r=this.stack[--i]}for(let t=n;t=0;i--){if(i<0)return vl(this.node,t,r);let o=n[e.buffer[this.stack[i]]];if(!o.isAnonymous){if(t[r]&&t[r]!=o.name)return!1;r--}}return!0}}function xl(t){return t.children.some((t=>t instanceof ul||!t.type.isAnonymous||xl(t)))}const kl=new WeakMap;function Sl(t,e){if(!t.isAnonymous||e instanceof ul||e.type!=t)return 1;let n=kl.get(e);if(null==n){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof hl)){n=1;break}n+=Sl(t,r)}kl.set(e,n)}return n}function El(t,e,n,r,i,o,s,a,l){let h=0;for(let n=r;n=c)break;p+=e}if(h==i+1){if(p>c){let t=n[i];e(t.children,t.positions,0,t.children.length,r[i]+a);continue}u.push(n[i])}else{let e=r[h-1]+n[h-1].length-f;u.push(El(t,n,r,i,h,f,e,null,l))}d.push(f+a-o)}}(e,n,r,i,0),(a||l)(u,d,s)}class Cl{constructor(t,e,n,r,i=!1,o=!1){this.from=t,this.to=e,this.tree=n,this.offset=r,this.open=(i?1:0)|(o?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],n=!1){let r=[new Cl(0,t.length,t,0,!1,n)];for(let n of e)n.to>t.length&&r.push(n);return r}static applyChanges(t,e,n=128){if(!e.length)return t;let r=[],i=1,o=t.length?t[0]:null;for(let s=0,a=0,l=0;;s++){let h=s=n)for(;o&&o.from=e.from||c<=e.to||l){let t=Math.max(e.from,a)-l,n=Math.min(e.to,c)-l;e=t>=n?null:new Cl(t,n,e.tree,e.offset+l,s>0,!!h)}if(e&&r.push(e),o.to>c)break;o=inew el(t.from,t.to))):[new el(0,0)]:[new el(0,t.length)],this.createParse(t,e||[],n)}parse(t,e,n){let r=this.startParse(t,e,n);for(;;){let t=r.advance();if(t)return t}}}class Tl{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new nl({perNode:!0});const Ml=1024;let _l=0;class Dl{constructor(t={}){this.id=_l++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=Pl.match(t)),e=>{let n=t(e);return void 0===n?null:[this,n]}}}Dl.closedBy=new Dl({deserialize:t=>t.split(" ")}),Dl.openedBy=new Dl({deserialize:t=>t.split(" ")}),Dl.group=new Dl({deserialize:t=>t.split(" ")}),Dl.contextHash=new Dl({perNode:!0}),Dl.lookAhead=new Dl({perNode:!0}),Dl.mounted=new Dl({perNode:!0});const Ol=Object.create(null);class Pl{constructor(t,e,n,r=0){this.name=t,this.props=e,this.id=n,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):Ol,n=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),r=new Pl(t.name||"",e,t.id,n);if(t.props)for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}return r}prop(t){return this.props[t.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(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(Dl.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let n in t)for(let r of n.split(" "))e[r]=t[n];return t=>{for(let n=t.prop(Dl.group),r=-1;r<(n?n.length:0);r++){let i=e[r<0?t.name:n[r]];if(i)return i}}}}Pl.none=new Pl("",Object.create(null),0,8);const Il=new WeakMap,Rl=new WeakMap;var Nl;!function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays"}(Nl||(Nl={}));class Ll{constructor(t,e,n,r,i){if(this.type=t,this.children=e,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[t,e]of i)this.props["number"==typeof t?t:t.id]=e}}toString(){let t=this.prop(Dl.mounted);if(t&&!t.overlay)return t.tree.toString();let e="";for(let t of this.children){let n=t.toString();n&&(e&&(e+=","),e+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new Xl(this.topNode,t)}cursorAt(t,e=0,n=0){let r=Il.get(this)||this.topNode,i=new Xl(r);return i.moveTo(t,e),Il.set(this,i._tree),i}get topNode(){return new Vl(this,0,0,null)}resolve(t,e=0){let n=Wl(Il.get(this)||this.topNode,t,e,!1);return Il.set(this,n),n}resolveInner(t,e=0){let n=Wl(Rl.get(this)||this.topNode,t,e,!0);return Rl.set(this,n),n}iterate(t){let{enter:e,leave:n,from:r=0,to:i=this.length}=t,o=t.mode||0,s=(o&Nl.IncludeAnonymous)>0;for(let t=this.cursor(o|Nl.IncludeAnonymous);;){let o=!1;if(t.from<=i&&t.to>=r&&(!s&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;o=!0}for(;o&&n&&(s||!t.type.isAnonymous)&&n(t),!t.nextSibling();){if(!t.parent())return;o=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Jl(Pl.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,n)=>new Ll(this.type,t,e,n,this.propValues)),t.makeTree||((t,e,n)=>new Ll(Pl.none,t,e,n)))}static build(t){return function(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:i=Ml,reused:o=[],minRepeatType:s=r.types.length}=t,a=Array.isArray(n)?new Bl(n,n.length):n,l=r.types,h=0,c=0;function u(t,e,n,v,y){let{id:w,start:b,end:x,size:k}=a,S=c;for(;k<0;){if(a.next(),-1==k){let e=o[w];return n.push(e),void v.push(b-t)}if(-3==k)return void(h=w);if(-4==k)return void(c=w);throw new RangeError(`Unrecognized record size: ${k}`)}let E,C,A=l[w],T=b-t;if(x-b<=i&&(C=m(a.pos-e,y))){let e=new Uint16Array(C.size-C.skip),n=a.pos-C.size,i=e.length;for(;a.pos>n;)i=g(C.start,e,i);E=new Fl(e,x-C.start,r),T=C.start-t}else{let t=a.pos-k;a.next();let e=[],n=[],r=w>=s?w:-1,o=0,l=x;for(;a.pos>t;)r>=0&&a.id==r&&a.size>=0?(a.end<=l-i&&(f(e,n,b,o,a.end,l,r,S),o=e.length,l=a.end),a.next()):u(b,t,e,n,r);if(r>=0&&o>0&&o-1&&o>0){let t=d(A);E=Jl(A,e,n,0,e.length,0,x-b,t,t)}else E=p(A,e,n,x-b,S-x)}n.push(E),v.push(T)}function d(t){return(e,n,r)=>{let i,o,s=0,a=e.length-1;if(a>=0&&(i=e[a])instanceof Ll){if(!a&&i.type==t&&i.length==r)return i;(o=i.prop(Dl.lookAhead))&&(s=n[a]+i.length+o)}return p(t,e,n,r,s)}}function f(t,e,n,i,o,s,a,l){let h=[],c=[];for(;t.length>i;)h.push(t.pop()),c.push(e.pop()+n-o);t.push(p(r.types[a],h,c,s-o,l-s)),e.push(o-n)}function p(t,e,n,r,i=0,o){if(h){let t=[Dl.contextHash,h];o=o?[t].concat(o):[t]}if(i>25){let t=[Dl.lookAhead,i];o=o?[t].concat(o):[t]}return new Ll(t,e,n,r,o)}function m(t,e){let n=a.fork(),r=0,o=0,l=0,h=n.end-i,c={size:0,start:0,skip:0};t:for(let i=n.pos-t;n.pos>i;){let t=n.size;if(n.id==e&&t>=0){c.size=r,c.start=o,c.skip=l,l+=4,r+=4,n.next();continue}let a=n.pos-t;if(t<0||a=s?4:0,d=n.start;for(n.next();n.pos>a;){if(n.size<0){if(-3!=n.size)break t;u+=4}else n.id>=s&&(u+=4);n.next()}o=d,r+=t,l+=u}return(e<0||r==t)&&(c.size=r,c.start=o,c.skip=l),c.size>4?c:void 0}function g(t,e,n){let{id:r,start:i,end:o,size:l}=a;if(a.next(),l>=0&&r4){let r=a.pos-(l-4);for(;a.pos>r;)n=g(t,e,n)}e[--n]=s,e[--n]=o-t,e[--n]=i-t,e[--n]=r}else-3==l?h=r:-4==l&&(c=r);return n}let v=[],y=[];for(;a.pos>0;)u(t.start||0,t.bufferStart||0,v,y,-1);let w=null!==(e=t.length)&&void 0!==e?e:v.length?y[0]+v[0].length:0;return new Ll(l[t.topID],v.reverse(),y.reverse(),w)}(t)}}Ll.empty=new Ll(Pl.none,[],[],0);class Bl{constructor(t,e){this.buffer=t,this.index=e}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 Bl(this.buffer,this.index)}}class Fl{constructor(t,e,n){this.buffer=t,this.length=e,this.set=n}get type(){return Pl.none}toString(){let t=[];for(let e=0;e0));a=o[a+3]);return s}slice(t,e,n){let r=this.buffer,i=new Uint16Array(e-t),o=0;for(let s=t,a=0;s=e&≠case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function Hl(t,e){let n=t.childBefore(e);for(;n;){let e=n.lastChild;if(!e||e.to!=n.to)break;e.type.isError&&e.from==e.to?(t=n,n=e.prevSibling):n=e}return t}function Wl(t,e,n,r){for(var i;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to0?s.length:-1;t!=l;t+=e){let l=s[t],h=a[t]+o.from;if(zl(r,n,h,h+l.length))if(l instanceof Fl){if(i&Nl.ExcludeBuffers)continue;let s=l.findChild(0,l.buffer.length,e,n-h,r);if(s>-1)return new ql(new $l(o,l,t,h),null,s)}else if(i&Nl.IncludeAnonymous||!l.type.isAnonymous||Kl(l)){let s;if(!(i&Nl.IgnoreMounts)&&l.props&&(s=l.prop(Dl.mounted))&&!s.overlay)return new Vl(s.tree,h,t,o);let a=new Vl(l,h,t,o);return i&Nl.IncludeAnonymous||!a.type.isAnonymous?a:a.nextChild(e<0?l.children.length-1:0,e,n,r)}}if(i&Nl.IncludeAnonymous||!o.type.isAnonymous)return null;if(t=o.index>=0?o.index+e:e<0?-1:o._parent._tree.children.length,o=o._parent,!o)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,n=0){let r;if(!(n&Nl.IgnoreOverlays)&&(r=this._tree.prop(Dl.mounted))&&r.overlay){let n=t-this.from;for(let{from:t,to:i}of r.overlay)if((e>0?t<=n:t=n:i>n))return new Vl(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,n)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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(t=0){return new Xl(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return Wl(this,t,e,!1)}resolveInner(t,e=0){return Wl(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Hl(this,t)}getChild(t,e=null,n=null){let r=Ul(this,t,e,n);return r.length?r[0]:null}getChildren(t,e=null,n=null){return Ul(this,t,e,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return jl(this,t)}}function Ul(t,e,n,r){let i=t.cursor(),o=[];if(!i.firstChild())return o;if(null!=n)for(;!i.type.is(n);)if(!i.nextSibling())return o;for(;;){if(null!=r&&i.type.is(r))return o;if(i.type.is(e)&&o.push(i.node),!i.nextSibling())return null==r?o:[]}}function jl(t,e,n=e.length-1){for(let r=t.parent;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}class $l{constructor(t,e,n,r){this.parent=t,this.buffer=e,this.index=n,this.start=r}}class ql{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(t,e,n){this.context=t,this._parent=e,this.index=n,this.type=t.buffer.set.types[t.buffer.buffer[n]]}child(t,e,n){let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,n);return i<0?null:new ql(this.context,this,i)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,n=0){if(n&Nl.ExcludeBuffers)return null;let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return i<0?null:new ql(this.context,this,i)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new ql(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new ql(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new Xl(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let o=n.buffer[this.index+1];t.push(n.slice(r,i,o)),e.push(0)}return new Ll(this.type,t,e,this.to-this.from)}resolve(t,e=0){return Wl(this,t,e,!1)}resolveInner(t,e=0){return Wl(this,t,e,!0)}enterUnfinishedNodesBefore(t){return Hl(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,n=null){let r=Ul(this,t,e,n);return r.length?r[0]:null}getChildren(t,e=null,n=null){return Ul(this,t,e,n)}get node(){return this}matchContext(t){return jl(this,t)}}class Xl{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof Vl)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return!!t&&(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0)}yieldBuf(t,e){this.index=t;let{start:n,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=n+r.buffer[t+1],this.to=n+r.buffer[t+2],!0}yield(t){return!!t&&(t instanceof Vl?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,n){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,n);return!(i<0)&&(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,n=this.mode){return this.buffer?!(n&Nl.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Nl.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Nl.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode));let{buffer:e}=this.buffer,n=this.stack.length-1;if(t<0){let t=n<0?0:this.stack[n]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(n<0?e.buffer.length:e.buffer[this.stack[n]+3]))return this.yieldBuf(t)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,n,{buffer:r}=this;if(r){if(t>0){if(this.index-1)for(let r=e+t,i=t<0?-1:n._tree.children.length;r!=i;r+=t){let t=n._tree.children[r];if(this.mode&Nl.IncludeAnonymous||t instanceof Fl||!t.type.isAnonymous||Kl(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let o=t;o;o=o._parent)if(o.index==r){if(r==this.index)return o;e=o,n=i+1;break t}r=this.stack[--i]}for(let t=n;t=0;i--){if(i<0)return jl(this.node,t,r);let o=n[e.buffer[this.stack[i]]];if(!o.isAnonymous){if(t[r]&&t[r]!=o.name)return!1;r--}}return!0}}function Kl(t){return t.children.some((t=>t instanceof Fl||!t.type.isAnonymous||Kl(t)))}const Gl=new WeakMap;function Yl(t,e){if(!t.isAnonymous||e instanceof Fl||e.type!=t)return 1;let n=Gl.get(e);if(null==n){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof Ll)){n=1;break}n+=Yl(t,r)}Gl.set(e,n)}return n}function Jl(t,e,n,r,i,o,s,a,l){let h=0;for(let n=r;n=c)break;p+=e}if(h==i+1){if(p>c){let t=n[i];e(t.children,t.positions,0,t.children.length,r[i]+a);continue}u.push(n[i])}else{let e=r[h-1]+n[h-1].length-f;u.push(Jl(t,n,r,i,h,f,e,null,l))}d.push(f+a-o)}}(e,n,r,i,0),(a||l)(u,d,s)}new Dl({perNode:!0});let Ql=0;class Zl{constructor(t,e,n){this.set=t,this.base=e,this.modified=n,this.id=Ql++}static define(t){if(null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let e=new Zl([],null,[]);if(e.set.push(e),t)for(let n of t.set)e.set.push(n);return e}static defineModifier(){let t=new eh;return e=>e.modified.indexOf(t)>-1?e:eh.get(e.base||e,e.modified.concat(t).sort(((t,e)=>t.id-e.id)))}}let th=0;class eh{constructor(){this.instances=[],this.id=th++}static get(t,e){if(!e.length)return t;let n=e[0].instances.find((n=>{return n.base==t&&(r=e,i=n.modified,r.length==i.length&&r.every(((t,e)=>t==i[e])));var r,i}));if(n)return n;let r=[],i=new Zl(r,t,e);for(let t of e)t.instances.push(i);let o=function(t){let e=[[]];for(let n=0;ne.length-t.length))}(e);for(let e of t.set)if(!e.modified.length)for(let t of o)r.push(eh.get(e,t));return i}}function nh(t){let e=Object.create(null);for(let n in t){let r=t[n];Array.isArray(r)||(r=[r]);for(let t of n.split(" "))if(t){let n=[],i=2,o=t;for(let e=0;;){if("..."==o&&e>0&&e+3==t.length){i=1;break}let r=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!r)throw new RangeError("Invalid path: "+t);if(n.push("*"==r[0]?"":'"'==r[0][0]?JSON.parse(r[0]):r[0]),e+=r[0].length,e==t.length)break;let s=t[e++];if(e==t.length&&"!"==s){i=0;break}if("/"!=s)throw new RangeError("Invalid path: "+t);o=t.slice(e)}let s=n.length-1,a=n[s];if(!a)throw new RangeError("Invalid path: "+t);let l=new ih(r,i,s>0?n.slice(0,s):null);e[a]=l.sort(e[a])}}return rh.add(e)}const rh=new Dl;class ih{constructor(t,e,n,r){this.tags=t,this.mode=e,this.context=n,this.next=r}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}sort(t){return!t||t.depth{let e=i;for(let r of t)for(let t of r.set){let r=n[t.id];if(r){e=e?e+" "+r:r;break}}return e},scope:r}}function sh(t,e,n,r=0,i=t.length){let o=new ah(r,Array.isArray(e)?e:[e],n);o.highlightRange(t.cursor(),r,i,"",o.highlighters),o.flush(i)}ih.empty=new ih([],2,null);class ah{constructor(t,e,n){this.at=t,this.highlighters=e,this.span=n,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,n,r,i){let{type:o,from:s,to:a}=t;if(s>=n||a<=e)return;o.isTop&&(i=this.highlighters.filter((t=>!t.scope||t.scope(o))));let l=r,h=function(t){let e=t.type.prop(rh);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||ih.empty,c=function(t,e){let n=null;for(let r of t){let t=r.style(e);t&&(n=n?n+" "+t:t)}return n}(i,h.tags);if(c&&(l&&(l+=" "),l+=c,1==h.mode&&(r+=(r?" ":"")+c)),this.startSpan(Math.max(e,s),l),h.opaque)return;let u=t.tree&&t.tree.prop(Dl.mounted);if(u&&u.overlay){let o=t.node.enter(u.overlay[0].from+s,1),h=this.highlighters.filter((t=>!t.scope||t.scope(u.tree.type))),c=t.firstChild();for(let d=0,f=s;;d++){let p=d=m)&&t.nextSibling()););if(!p||m>n)break;f=p.to+s,f>e&&(this.highlightRange(o.cursor(),Math.max(e,p.from+s),Math.min(n,f),"",h),this.startSpan(Math.min(n,f),l))}c&&t.parent()}else if(t.firstChild()){u&&(r="");do{if(!(t.to<=e)){if(t.from>=n)break;this.highlightRange(t,e,n,r,i),this.startSpan(Math.min(n,t.to),l)}}while(t.nextSibling());t.parent()}}}const lh=Zl.define,hh=lh(),ch=lh(),uh=lh(ch),dh=lh(ch),fh=lh(),ph=lh(fh),mh=lh(fh),gh=lh(),vh=lh(gh),yh=lh(),wh=lh(),bh=lh(),xh=lh(bh),kh=lh(),Sh={comment:hh,lineComment:lh(hh),blockComment:lh(hh),docComment:lh(hh),name:ch,variableName:lh(ch),typeName:uh,tagName:lh(uh),propertyName:dh,attributeName:lh(dh),className:lh(ch),labelName:lh(ch),namespace:lh(ch),macroName:lh(ch),literal:fh,string:ph,docString:lh(ph),character:lh(ph),attributeValue:lh(ph),number:mh,integer:lh(mh),float:lh(mh),bool:lh(fh),regexp:lh(fh),escape:lh(fh),color:lh(fh),url:lh(fh),keyword:yh,self:lh(yh),null:lh(yh),atom:lh(yh),unit:lh(yh),modifier:lh(yh),operatorKeyword:lh(yh),controlKeyword:lh(yh),definitionKeyword:lh(yh),moduleKeyword:lh(yh),operator:wh,derefOperator:lh(wh),arithmeticOperator:lh(wh),logicOperator:lh(wh),bitwiseOperator:lh(wh),compareOperator:lh(wh),updateOperator:lh(wh),definitionOperator:lh(wh),typeOperator:lh(wh),controlOperator:lh(wh),punctuation:bh,separator:lh(bh),bracket:xh,angleBracket:lh(xh),squareBracket:lh(xh),paren:lh(xh),brace:lh(xh),content:gh,heading:vh,heading1:lh(vh),heading2:lh(vh),heading3:lh(vh),heading4:lh(vh),heading5:lh(vh),heading6:lh(vh),contentSeparator:lh(gh),list:lh(gh),quote:lh(gh),emphasis:lh(gh),strong:lh(gh),link:lh(gh),monospace:lh(gh),strikethrough:lh(gh),inserted:lh(),deleted:lh(),changed:lh(),invalid:lh(),meta:kh,documentMeta:lh(kh),annotation:lh(kh),processingInstruction:lh(kh),definition:Zl.defineModifier(),constant:Zl.defineModifier(),function:Zl.defineModifier(),standard:Zl.defineModifier(),local:Zl.defineModifier(),special:Zl.defineModifier()};oh([{tag:Sh.link,class:"tok-link"},{tag:Sh.heading,class:"tok-heading"},{tag:Sh.emphasis,class:"tok-emphasis"},{tag:Sh.strong,class:"tok-strong"},{tag:Sh.keyword,class:"tok-keyword"},{tag:Sh.atom,class:"tok-atom"},{tag:Sh.bool,class:"tok-bool"},{tag:Sh.url,class:"tok-url"},{tag:Sh.labelName,class:"tok-labelName"},{tag:Sh.inserted,class:"tok-inserted"},{tag:Sh.deleted,class:"tok-deleted"},{tag:Sh.literal,class:"tok-literal"},{tag:Sh.string,class:"tok-string"},{tag:Sh.number,class:"tok-number"},{tag:[Sh.regexp,Sh.escape,Sh.special(Sh.string)],class:"tok-string2"},{tag:Sh.variableName,class:"tok-variableName"},{tag:Sh.local(Sh.variableName),class:"tok-variableName tok-local"},{tag:Sh.definition(Sh.variableName),class:"tok-variableName tok-definition"},{tag:Sh.special(Sh.variableName),class:"tok-variableName2"},{tag:Sh.definition(Sh.propertyName),class:"tok-propertyName tok-definition"},{tag:Sh.typeName,class:"tok-typeName"},{tag:Sh.namespace,class:"tok-namespace"},{tag:Sh.className,class:"tok-className"},{tag:Sh.macroName,class:"tok-macroName"},{tag:Sh.propertyName,class:"tok-propertyName"},{tag:Sh.operator,class:"tok-operator"},{tag:Sh.comment,class:"tok-comment"},{tag:Sh.meta,class:"tok-meta"},{tag:Sh.invalid,class:"tok-invalid"},{tag:Sh.punctuation,class:"tok-punctuation"}]);var Eh;const Ch=new nl;const Ah=new nl;class Th{constructor(t,e,n=[],r=""){this.data=t,this.name=r,Ze.prototype.hasOwnProperty("tree")||Object.defineProperty(Ze.prototype,"tree",{get(){return _h(this)}}),this.parser=e,this.extension=[Fh.of(this),Ze.languageData.of(((t,e,n)=>{let r=Mh(t,e,n),i=r.type.prop(Ch);if(!i)return[];let o=t.facet(i),s=r.type.prop(Ah);if(s){let i=r.resolve(e-r.from,n);for(let e of s)if(e.test(i,t)){let n=t.facet(e.facet);return"replace"==e.type?n:n.concat(o)}}return o}))].concat(n)}isActiveAt(t,e,n=-1){return Mh(t,e,n).type.prop(Ch)==this.data}findRegions(t){let e=t.facet(Fh);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let n=[],r=(t,e)=>{if(t.prop(Ch)==this.data)return void n.push({from:e,to:e+t.length});let i=t.prop(nl.mounted);if(i){if(i.tree.prop(Ch)==this.data){if(i.overlay)for(let t of i.overlay)n.push({from:t.from+e,to:t.to+e});else n.push({from:e,to:e+t.length});return}if(i.overlay){let t=n.length;if(r(i.tree,i.overlay[0].from+e),n.length>t)return}}for(let n=0;n=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-n,e-n)}}let Oh=null;class Ph{constructor(t,e,n=[],r,i,o,s,a){this.parser=t,this.state=e,this.fragments=n,this.tree=r,this.treeLen=i,this.viewport=o,this.skipped=s,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(t,e,n){return new Ph(t,e,[],hl.empty,0,n,[],null)}startParse(){return this.parser.startParse(new Dh(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=hl.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var n;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e=this.treeLen&&((null==this.parse.stoppedAt||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext((()=>{for(;!(e=this.parse.advance()););})),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(Cl.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=Oh;Oh=this;try{return t()}finally{Oh=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=Ih(t,e.from,e.to);return t}changes(t,e){let{fragments:n,tree:r,treeLen:i,viewport:o,skipped:s}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges(((t,n,r,i)=>e.push({fromA:t,toA:n,fromB:r,toB:i}))),n=Cl.applyChanges(n,e),r=hl.empty,i=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){s=[];for(let e of this.skipped){let n=t.mapPos(e.from,1),r=t.mapPos(e.to,-1);nt.from&&(this.fragments=Ih(this.fragments,n,r),this.skipped.splice(e--,1))}return!(this.skipped.length>=e)&&(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Al{createParse(e,n,r){let i=r[0].from,o=r[r.length-1].to;return{parsedPos:i,advance(){let e=Oh;if(e){for(let t of r)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=o,new hl(il.none,[],[],o-i)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return Oh}}function Ih(t,e,n){return Cl.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}class Rh{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),n=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,n)||e.takeTree(),new Rh(e)}static init(t){let e=Math.min(3e3,t.doc.length),n=Ph.create(t.facet(Fh).parser,t,{from:0,to:e});return n.work(20,e)||n.takeTree(),new Rh(n)}}Th.state=ye.define({create:Rh.init,update(t,e){for(let t of e.effects)if(t.is(Th.setState))return t.value;return e.startState.facet(Fh)!=e.state.facet(Fh)?Rh.init(e.state):t.apply(e)}});let Nh=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(Nh=t=>{let e=-1,n=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});const Lh="undefined"!=typeof navigator&&(null===(Eh=navigator.scheduling)||void 0===Eh?void 0:Eh.isInputPending)?()=>navigator.scheduling.isInputPending():null,Bh=oi.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Th.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),t.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Th.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=Nh(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEndr+1e3,a=i.context.work((()=>Lh&&Lh()||Date.now()>o),r+(s?0:1e5));this.chunkBudget-=Date.now()-e,(a||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:Th.setState.of(new Rh(i.context))})),this.chunkBudget>0&&(!a||s)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then((()=>this.scheduleWork())).catch((t=>ei(this.view.state,t))).then((()=>this.workScheduled--)),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Fh=ue.define({combine:t=>t.length?t[0]:null,enables:t=>[Th.state,Bh,fs.contentAttributes.compute([t],(e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}}))]});const zh=ue.define(),Hh=ue.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some((t=>t!=e[0])))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function Wh(t){let e=t.facet(Hh);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function Vh(t,e){let n="",r=t.tabSize,i=t.facet(Hh)[0];if("\t"==i){for(;e>=r;)n+="\t",e-=r;i=" "}for(let t=0;t=n.from&&r<=n.to?i&&r==t?{text:"",from:t}:(e<0?r-1&&(i+=o-this.countColumn(n,n.search(/\S|$/))),i}countColumn(t,e=t.length){return yn(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:n,from:r}=this.lineAt(t,e),i=this.options.overrideIndentation;if(i){let t=i(r);if(t>-1)return t}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const $h=new nl;function qh(t){let e=t.type.prop($h);if(e)return e;let n,r=t.firstChild;if(r&&(n=r.type.prop(nl.closedBy))){let e=t.lastChild,r=e&&n.indexOf(e.name)>-1;return t=>Jh(t,!0,1,void 0,r&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?Kh:null}function Xh(t,e,n){for(;t;t=t.parent){let r=qh(t);if(r)return r(Gh.create(n,e,t))}return null}function Kh(){return 0}class Gh extends jh{constructor(t,e,n){super(t.state,t.options),this.base=t,this.pos=e,this.node=n}static create(t,e,n){return new Gh(t,e,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let t=this.state.doc.lineAt(this.node.from);for(;;){let e=this.node.resolve(t.from);for(;e.parent&&e.parent.from==e.from;)e=e.parent;if(Yh(e,this.node))break;t=this.state.doc.lineAt(e.from)}return this.lineIndent(t.from)}continue(){let t=this.node.parent;return t?Xh(t,this.pos,this.base):0}}function Yh(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function Jh(t,e,n,r,i){let o=t.textAfter,s=o.match(/^\s*/)[0].length,a=r&&o.slice(s,s+r.length)==r||i==t.pos+s,l=e?function(t){let e=t.node,n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let i=t.options.simulateBreak,o=t.state.doc.lineAt(n.from),s=null==i||i<=o.from?o.to:Math.min(o.to,i);for(let t=n.to;;){let i=e.childAfter(t);if(!i||i==r)return null;if(!i.type.isSkipped)return i.fromn)continue;if(i&&o.from=e&&r.to>n&&(i=r)}}return i}(t,e,n)}function nc(t,e){let n=e.mapPos(t.from,1),r=e.mapPos(t.to,-1);return n>=r?void 0:{from:n,to:r}}const rc=We.define({map:nc}),ic=We.define({map:nc});function oc(t){let e=[];for(let{head:n}of t.state.selection.ranges)e.some((t=>t.from<=n&&t.to>=n))||e.push(t.lineBlockAt(n));return e}const sc=ye.define({create:()=>Ir.none,update(t,e){t=t.map(e.changes);for(let n of e.effects)n.is(rc)&&!lc(t,n.value.from,n.value.to)?t=t.update({add:[mc.range(n.value.from,n.value.to)]}):n.is(ic)&&(t=t.update({filter:(t,e)=>n.value.from!=t||n.value.to!=e,filterFrom:n.value.from,filterTo:n.value.to}));if(e.selection){let n=!1,{head:r}=e.selection.main;t.between(r,r,((t,e)=>{tr&&(n=!0)})),n&&(t=t.update({filterFrom:r,filterTo:r,filter:(t,e)=>e<=r||t>=r}))}return t},provide:t=>fs.decorations.from(t),toJSON(t,e){let n=[];return t.between(0,e.doc.length,((t,e)=>{n.push(t,e)})),n},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let n=0;n{(!i||i.from>t)&&(i={from:t,to:e})})),i}function lc(t,e,n){let r=!1;return t.between(e,e,((t,i)=>{t==e&&i==n&&(r=!0)})),r}function hc(t,e){return t.field(sc,!1)?e:e.concat(We.appendConfig.of(pc()))}function cc(t,e,n=!0){let r=t.state.doc.lineAt(e.from).number,i=t.state.doc.lineAt(e.to).number;return fs.announce.of(`${t.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${t.state.phrase("to")} ${i}.`)}const uc=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of oc(t)){let n=ec(t.state,e.from,e.to);if(n)return t.dispatch({effects:hc(t.state,[rc.of(n),cc(t,n)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(sc,!1))return!1;let e=[];for(let n of oc(t)){let r=ac(t.state,n.from,n.to);r&&e.push(ic.of(r),cc(t,r,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,n=[];for(let r=0;r{let e=t.state.field(sc,!1);if(!e||!e.size)return!1;let n=[];return e.between(0,t.state.doc.length,((t,e)=>{n.push(ic.of({from:t,to:e}))})),t.dispatch({effects:n}),!0}}],dc={placeholderDOM:null,placeholderText:"…"},fc=ue.define({combine:t=>tn(t,dc)});function pc(t){let e=[sc,wc];return t&&e.push(fc.of(t)),e}const mc=Ir.replace({widget:new class extends Or{toDOM(t){let{state:e}=t,n=e.facet(fc),r=e=>{let n=t.lineBlockAt(t.posAtDOM(e.target)),r=ac(t.state,n.from,n.to);r&&t.dispatch({effects:ic.of(r)}),e.preventDefault()};if(n.placeholderDOM)return n.placeholderDOM(t,r);let i=document.createElement("span");return i.textContent=n.placeholderText,i.setAttribute("aria-label",e.phrase("folded code")),i.title=e.phrase("unfold"),i.className="cm-foldPlaceholder",i.onclick=r,i}}}),gc={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class vc extends Oa{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}function yc(t={}){let e=Object.assign(Object.assign({},gc),t),n=new vc(e,!0),r=new vc(e,!1),i=oi.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(Fh)!=t.state.facet(Fh)||t.startState.field(sc,!1)!=t.state.field(sc,!1)||_h(t.startState)!=_h(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new an;for(let i of t.viewportLineBlocks){let o=ac(t.state,i.from,i.to)?r:ec(t.state,i.from,i.to)?n:null;o&&e.add(i.from,i.from,o)}return e.finish()}}),{domEventHandlers:o}=e;return[i,Na({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(i))||void 0===e?void 0:e.markers)||sn.empty},initialSpacer:()=>new vc(e,!1),domEventHandlers:Object.assign(Object.assign({},o),{click:(t,e,n)=>{if(o.click&&o.click(t,e,n))return!0;let r=ac(t.state,e.from,e.to);if(r)return t.dispatch({effects:ic.of(r)}),!0;let i=ec(t.state,e.from,e.to);return!!i&&(t.dispatch({effects:rc.of(i)}),!0)}})}),pc()]}const wc=fs.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class bc{constructor(t,e){let n;function r(t){let e=Sn.newName();return(n||(n=Object.create(null)))["."+e]=t,e}this.specs=t;const i="string"==typeof e.all?e.all:e.all?r(e.all):void 0,o=e.scope;this.scope=o instanceof Th?t=>t.prop(Ch)==o.data:o?t=>t==o:void 0,this.style=oh(t.map((t=>({tag:t.tag,class:t.class||r(Object.assign({},t,{tag:null}))}))),{all:i}).style,this.module=n?new Sn(n):null,this.themeType=e.themeType}static define(t,e){return new bc(t,e||{})}}const xc=ue.define(),kc=ue.define({combine:t=>t.length?[t[0]]:null});function Sc(t){let e=t.facet(xc);return e.length?e:t.facet(kc)}function Ec(t,e){let n,r=[Ac];return t instanceof bc&&(t.module&&r.push(fs.styleModule.of(t.module)),n=t.themeType),(null==e?void 0:e.fallback)?r.push(kc.of(t)):n?r.push(xc.computeN([fs.darkTheme],(e=>e.facet(fs.darkTheme)==("dark"==n)?[t]:[]))):r.push(xc.of(t)),r}class Cc{constructor(t){this.markCache=Object.create(null),this.tree=_h(t.state),this.decorations=this.buildDeco(t,Sc(t.state))}update(t){let e=_h(t.state),n=Sc(t.state),r=n!=Sc(t.startState);e.length{n.add(t,e,this.markCache[r]||(this.markCache[r]=Ir.mark({class:r})))}),r,i);return n.finish()}}const Ac=Ee.high(oi.fromClass(Cc,{decorations:t=>t.decorations})),Tc=bc.define([{tag:Sh.meta,color:"#404740"},{tag:Sh.link,textDecoration:"underline"},{tag:Sh.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Sh.emphasis,fontStyle:"italic"},{tag:Sh.strong,fontWeight:"bold"},{tag:Sh.strikethrough,textDecoration:"line-through"},{tag:Sh.keyword,color:"#708"},{tag:[Sh.atom,Sh.bool,Sh.url,Sh.contentSeparator,Sh.labelName],color:"#219"},{tag:[Sh.literal,Sh.inserted],color:"#164"},{tag:[Sh.string,Sh.deleted],color:"#a11"},{tag:[Sh.regexp,Sh.escape,Sh.special(Sh.string)],color:"#e40"},{tag:Sh.definition(Sh.variableName),color:"#00f"},{tag:Sh.local(Sh.variableName),color:"#30a"},{tag:[Sh.typeName,Sh.namespace],color:"#085"},{tag:Sh.className,color:"#167"},{tag:[Sh.special(Sh.variableName),Sh.macroName],color:"#256"},{tag:Sh.definition(Sh.propertyName),color:"#00c"},{tag:Sh.comment,color:"#940"},{tag:Sh.invalid,color:"#f00"}]),Mc=fs.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),_c=1e4,Dc="()[]{}",Oc=ue.define({combine:t=>tn(t,{afterCursor:!0,brackets:Dc,maxScanDistance:_c,renderMatch:Rc})}),Pc=Ir.mark({class:"cm-matchingBracket"}),Ic=Ir.mark({class:"cm-nonmatchingBracket"});function Rc(t){let e=[],n=t.matched?Pc:Ic;return e.push(n.range(t.start.from,t.start.to)),t.end&&e.push(n.range(t.end.from,t.end.to)),e}const Nc=[ye.define({create:()=>Ir.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let n=[],r=e.state.facet(Oc);for(let t of e.state.selection.ranges){if(!t.empty)continue;let i=Hc(e.state,t.head,-1,r)||t.head>0&&Hc(e.state,t.head-1,1,r)||r.afterCursor&&(Hc(e.state,t.head,1,r)||t.headfs.decorations.from(t)}),Mc];function Lc(t={}){return[Oc.of(t),Nc]}const Bc=new nl;function Fc(t,e,n){let r=t.prop(e<0?nl.openedBy:nl.closedBy);if(r)return r;if(1==t.name.length){let r=n.indexOf(t.name);if(r>-1&&r%2==(e<0?1:0))return[n[r+e]]}return null}function zc(t){let e=t.type.prop(Bc);return e?e(t.node):t}function Hc(t,e,n,r={}){let i=r.maxScanDistance||_c,o=r.brackets||Dc,s=_h(t),a=s.resolveInner(e,n);for(let r=a;r;r=r.parent){let i=Fc(r.type,n,o);if(i&&r.from0?e>=s.from&&es.from&&e<=s.to))return Wc(t,e,n,r,s,i,o)}}return function(t,e,n,r,i,o,s){let a=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),l=s.indexOf(a);if(l<0||l%2==0!=n>0)return null;let h={from:n<0?e-1:e,to:n>0?e+1:e},c=t.doc.iterRange(e,n>0?t.doc.length:0),u=0;for(let t=0;!c.next().done&&t<=o;){let o=c.value;n<0&&(t+=o.length);let a=e+t*n;for(let t=n>0?0:o.length-1,e=n>0?o.length:-1;t!=e;t+=n){let e=s.indexOf(o[t]);if(!(e<0||r.resolveInner(a+t,1).type!=i))if(e%2==0==n>0)u++;else{if(1==u)return{start:h,end:{from:a+t,to:a+t+1},matched:e>>1==l>>1};u--}}n>0&&(t+=o.length)}return c.done?{start:h,matched:!1}:null}(t,e,n,s,a.type,i,o)}function Wc(t,e,n,r,i,o,s){let a=r.parent,l={from:i.from,to:i.to},h=0,c=null==a?void 0:a.cursor();if(c&&(n<0?c.childBefore(r.from):c.childAfter(r.to)))do{if(n<0?c.to<=r.from:c.from>=r.to){if(0==h&&o.indexOf(c.type.name)>-1&&c.from-1||(jc.push(t),console.warn(e))}function Xc(t,e){let n=null;for(let r of e.split(".")){let e=t[r]||Sh[r];e?"function"==typeof e?n?n=e(n):qc(r,`Modifier ${r} used at start of tag`):n?qc(r,`Tag ${r} used as modifier`):n=e:qc(r,`Unknown highlighting tag ${r}`)}if(!n)return 0;let r=e.replace(/ /g,"_"),i=il.define({id:Uc.length,name:r,props:[nh({[r]:n})]});return Uc.push(i),i.id}const Kc=1024;let Gc=0;class Yc{constructor(t={}){this.id=Gc++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return"function"!=typeof t&&(t=Qc.match(t)),e=>{let n=t(e);return void 0===n?null:[this,n]}}}Yc.closedBy=new Yc({deserialize:t=>t.split(" ")}),Yc.openedBy=new Yc({deserialize:t=>t.split(" ")}),Yc.group=new Yc({deserialize:t=>t.split(" ")}),Yc.contextHash=new Yc({perNode:!0}),Yc.lookAhead=new Yc({perNode:!0}),Yc.mounted=new Yc({perNode:!0});const Jc=Object.create(null);class Qc{constructor(t,e,n,r=0){this.name=t,this.props=e,this.id=n,this.flags=r}static define(t){let e=t.props&&t.props.length?Object.create(null):Jc,n=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),r=new Qc(t.name||"",e,t.id,n);if(t.props)for(let n of t.props)if(Array.isArray(n)||(n=n(r)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[n[0].id]=n[1]}return r}prop(t){return this.props[t.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(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(Yc.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let n in t)for(let r of n.split(" "))e[r]=t[n];return t=>{for(let n=t.prop(Yc.group),r=-1;r<(n?n.length:0);r++){let i=e[r<0?t.name:n[r]];if(i)return i}}}}Qc.none=new Qc("",Object.create(null),0,8);const Zc=new WeakMap,tu=new WeakMap;var eu;!function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays"}(eu||(eu={}));class nu{constructor(t,e,n,r,i){if(this.type=t,this.children=e,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[t,e]of i)this.props["number"==typeof t?t:t.id]=e}}toString(){let t=this.prop(Yc.mounted);if(t&&!t.overlay)return t.tree.toString();let e="";for(let t of this.children){let n=t.toString();n&&(e&&(e+=","),e+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new fu(this.topNode,t)}cursorAt(t,e=0,n=0){let r=Zc.get(this)||this.topNode,i=new fu(r);return i.moveTo(t,e),Zc.set(this,i._tree),i}get topNode(){return new lu(this,0,0,null)}resolve(t,e=0){let n=au(Zc.get(this)||this.topNode,t,e,!1);return Zc.set(this,n),n}resolveInner(t,e=0){let n=au(tu.get(this)||this.topNode,t,e,!0);return tu.set(this,n),n}iterate(t){let{enter:e,leave:n,from:r=0,to:i=this.length}=t,o=t.mode||0,s=(o&eu.IncludeAnonymous)>0;for(let t=this.cursor(o|eu.IncludeAnonymous);;){let o=!1;if(t.from<=i&&t.to>=r&&(!s&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;o=!0}for(;o&&n&&(s||!t.type.isAnonymous)&&n(t),!t.nextSibling();){if(!t.parent())return;o=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:vu(Qc.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,n)=>new nu(this.type,t,e,n,this.propValues)),t.makeTree||((t,e,n)=>new nu(Qc.none,t,e,n)))}static build(t){return function(t){var e;let{buffer:n,nodeSet:r,maxBufferLength:i=Kc,reused:o=[],minRepeatType:s=r.types.length}=t,a=Array.isArray(n)?new ru(n,n.length):n,l=r.types,h=0,c=0;function u(t,e,n,v,y){let{id:w,start:b,end:x,size:k}=a,S=c;for(;k<0;){if(a.next(),-1==k){let e=o[w];return n.push(e),void v.push(b-t)}if(-3==k)return void(h=w);if(-4==k)return void(c=w);throw new RangeError(`Unrecognized record size: ${k}`)}let E,C,A=l[w],T=b-t;if(x-b<=i&&(C=m(a.pos-e,y))){let e=new Uint16Array(C.size-C.skip),n=a.pos-C.size,i=e.length;for(;a.pos>n;)i=g(C.start,e,i);E=new iu(e,x-C.start,r),T=C.start-t}else{let t=a.pos-k;a.next();let e=[],n=[],r=w>=s?w:-1,o=0,l=x;for(;a.pos>t;)r>=0&&a.id==r&&a.size>=0?(a.end<=l-i&&(f(e,n,b,o,a.end,l,r,S),o=e.length,l=a.end),a.next()):u(b,t,e,n,r);if(r>=0&&o>0&&o-1&&o>0){let t=d(A);E=vu(A,e,n,0,e.length,0,x-b,t,t)}else E=p(A,e,n,x-b,S-x)}n.push(E),v.push(T)}function d(t){return(e,n,r)=>{let i,o,s=0,a=e.length-1;if(a>=0&&(i=e[a])instanceof nu){if(!a&&i.type==t&&i.length==r)return i;(o=i.prop(Yc.lookAhead))&&(s=n[a]+i.length+o)}return p(t,e,n,r,s)}}function f(t,e,n,i,o,s,a,l){let h=[],c=[];for(;t.length>i;)h.push(t.pop()),c.push(e.pop()+n-o);t.push(p(r.types[a],h,c,s-o,l-s)),e.push(o-n)}function p(t,e,n,r,i=0,o){if(h){let t=[Yc.contextHash,h];o=o?[t].concat(o):[t]}if(i>25){let t=[Yc.lookAhead,i];o=o?[t].concat(o):[t]}return new nu(t,e,n,r,o)}function m(t,e){let n=a.fork(),r=0,o=0,l=0,h=n.end-i,c={size:0,start:0,skip:0};t:for(let i=n.pos-t;n.pos>i;){let t=n.size;if(n.id==e&&t>=0){c.size=r,c.start=o,c.skip=l,l+=4,r+=4,n.next();continue}let a=n.pos-t;if(t<0||a=s?4:0,d=n.start;for(n.next();n.pos>a;){if(n.size<0){if(-3!=n.size)break t;u+=4}else n.id>=s&&(u+=4);n.next()}o=d,r+=t,l+=u}return(e<0||r==t)&&(c.size=r,c.start=o,c.skip=l),c.size>4?c:void 0}function g(t,e,n){let{id:r,start:i,end:o,size:l}=a;if(a.next(),l>=0&&r4){let r=a.pos-(l-4);for(;a.pos>r;)n=g(t,e,n)}e[--n]=s,e[--n]=o-t,e[--n]=i-t,e[--n]=r}else-3==l?h=r:-4==l&&(c=r);return n}let v=[],y=[];for(;a.pos>0;)u(t.start||0,t.bufferStart||0,v,y,-1);let w=null!==(e=t.length)&&void 0!==e?e:v.length?y[0]+v[0].length:0;return new nu(l[t.topID],v.reverse(),y.reverse(),w)}(t)}}nu.empty=new nu(Qc.none,[],[],0);class ru{constructor(t,e){this.buffer=t,this.index=e}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 ru(this.buffer,this.index)}}class iu{constructor(t,e,n){this.buffer=t,this.length=e,this.set=n}get type(){return Qc.none}toString(){let t=[];for(let e=0;e0));a=o[a+3]);return s}slice(t,e,n){let r=this.buffer,i=new Uint16Array(e-t),o=0;for(let s=t,a=0;s=e&≠case 1:return n<=e&&r>e;case 2:return r>e;case 4:return!0}}function su(t,e){let n=t.childBefore(e);for(;n;){let e=n.lastChild;if(!e||e.to!=n.to)break;e.type.isError&&e.from==e.to?(t=n,n=e.prevSibling):n=e}return t}function au(t,e,n,r){for(var i;t.from==t.to||(n<1?t.from>=e:t.from>e)||(n>-1?t.to<=e:t.to0?s.length:-1;t!=l;t+=e){let l=s[t],h=a[t]+o.from;if(ou(r,n,h,h+l.length))if(l instanceof iu){if(i&eu.ExcludeBuffers)continue;let s=l.findChild(0,l.buffer.length,e,n-h,r);if(s>-1)return new du(new uu(o,l,t,h),null,s)}else if(i&eu.IncludeAnonymous||!l.type.isAnonymous||pu(l)){let s;if(!(i&eu.IgnoreMounts)&&l.props&&(s=l.prop(Yc.mounted))&&!s.overlay)return new lu(s.tree,h,t,o);let a=new lu(l,h,t,o);return i&eu.IncludeAnonymous||!a.type.isAnonymous?a:a.nextChild(e<0?l.children.length-1:0,e,n,r)}}if(i&eu.IncludeAnonymous||!o.type.isAnonymous)return null;if(t=o.index>=0?o.index+e:e<0?-1:o._parent._tree.children.length,o=o._parent,!o)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,n=0){let r;if(!(n&eu.IgnoreOverlays)&&(r=this._tree.prop(Yc.mounted))&&r.overlay){let n=t-this.from;for(let{from:t,to:i}of r.overlay)if((e>0?t<=n:t=n:i>n))return new lu(r.tree,r.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,n)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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(t=0){return new fu(this,t)}get tree(){return this._tree}toTree(){return this._tree}resolve(t,e=0){return au(this,t,e,!1)}resolveInner(t,e=0){return au(this,t,e,!0)}enterUnfinishedNodesBefore(t){return su(this,t)}getChild(t,e=null,n=null){let r=hu(this,t,e,n);return r.length?r[0]:null}getChildren(t,e=null,n=null){return hu(this,t,e,n)}toString(){return this._tree.toString()}get node(){return this}matchContext(t){return cu(this,t)}}function hu(t,e,n,r){let i=t.cursor(),o=[];if(!i.firstChild())return o;if(null!=n)for(;!i.type.is(n);)if(!i.nextSibling())return o;for(;;){if(null!=r&&i.type.is(r))return o;if(i.type.is(e)&&o.push(i.node),!i.nextSibling())return null==r?o:[]}}function cu(t,e,n=e.length-1){for(let r=t.parent;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[n]&&e[n]!=r.name)return!1;n--}}return!0}class uu{constructor(t,e,n,r){this.parent=t,this.buffer=e,this.index=n,this.start=r}}class du{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(t,e,n){this.context=t,this._parent=e,this.index=n,this.type=t.buffer.set.types[t.buffer.buffer[n]]}child(t,e,n){let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.context.start,n);return i<0?null:new du(this.context,this,i)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,n=0){if(n&eu.ExcludeBuffers)return null;let{buffer:r}=this.context,i=r.findChild(this.index+4,r.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return i<0?null:new du(this.context,this,i)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new du(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new du(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}cursor(t=0){return new fu(this,t)}get tree(){return null}toTree(){let t=[],e=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let o=n.buffer[this.index+1];t.push(n.slice(r,i,o)),e.push(0)}return new nu(this.type,t,e,this.to-this.from)}resolve(t,e=0){return au(this,t,e,!1)}resolveInner(t,e=0){return au(this,t,e,!0)}enterUnfinishedNodesBefore(t){return su(this,t)}toString(){return this.context.buffer.childString(this.index)}getChild(t,e=null,n=null){let r=hu(this,t,e,n);return r.length?r[0]:null}getChildren(t,e=null,n=null){return hu(this,t,e,n)}get node(){return this}matchContext(t){return cu(this,t)}}class fu{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof lu)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return!!t&&(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0)}yieldBuf(t,e){this.index=t;let{start:n,buffer:r}=this.buffer;return this.type=e||r.set.types[r.buffer[t]],this.from=n+r.buffer[t+1],this.to=n+r.buffer[t+2],!0}yield(t){return!!t&&(t instanceof lu?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,n){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],t,e-this.buffer.start,n);return!(i<0)&&(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,n=this.mode){return this.buffer?!(n&eu.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&eu.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&eu.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return!!this._tree._parent&&this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode));let{buffer:e}=this.buffer,n=this.stack.length-1;if(t<0){let t=n<0?0:this.stack[n]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(n<0?e.buffer.length:e.buffer[this.stack[n]+3]))return this.yieldBuf(t)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,n,{buffer:r}=this;if(r){if(t>0){if(this.index-1)for(let r=e+t,i=t<0?-1:n._tree.children.length;r!=i;r+=t){let t=n._tree.children[r];if(this.mode&eu.IncludeAnonymous||t instanceof iu||!t.type.isAnonymous||pu(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to=0;){for(let o=t;o;o=o._parent)if(o.index==r){if(r==this.index)return o;e=o,n=i+1;break t}r=this.stack[--i]}for(let t=n;t=0;i--){if(i<0)return cu(this.node,t,r);let o=n[e.buffer[this.stack[i]]];if(!o.isAnonymous){if(t[r]&&t[r]!=o.name)return!1;r--}}return!0}}function pu(t){return t.children.some((t=>t instanceof iu||!t.type.isAnonymous||pu(t)))}const mu=new WeakMap;function gu(t,e){if(!t.isAnonymous||e instanceof iu||e.type!=t)return 1;let n=mu.get(e);if(null==n){n=1;for(let r of e.children){if(r.type!=t||!(r instanceof nu)){n=1;break}n+=gu(t,r)}mu.set(e,n)}return n}function vu(t,e,n,r,i,o,s,a,l){let h=0;for(let n=r;n=c)break;p+=e}if(h==i+1){if(p>c){let t=n[i];e(t.children,t.positions,0,t.children.length,r[i]+a);continue}u.push(n[i])}else{let e=r[h-1]+n[h-1].length-f;u.push(vu(t,n,r,i,h,f,e,null,l))}d.push(f+a-o)}}(e,n,r,i,0),(a||l)(u,d,s)}new Yc({perNode:!0});function yu(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=t(e,n);return!!i&&(r(n.update(i)),!0)}}const wu=yu(Cu,0),bu=yu(Eu,0),xu=yu(((t,e)=>Eu(t,e,function(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),i=n.to<=r.to?r:t.doc.lineAt(n.to),o=e.length-1;o>=0&&e[o].to>r.from?e[o].to=i.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return e}(e))),0);function ku(t,e){let n=t.languageDataAt("commentTokens",e);return n.length?n[0]:{}}const Su=50;function Eu(t,e,n=e.selection.ranges){let r=n.map((t=>ku(e,t.from).block));if(!r.every((t=>t)))return null;let i=n.map(((t,n)=>function(t,{open:e,close:n},r,i){let o,s,a=t.sliceDoc(r-Su,r),l=t.sliceDoc(i,i+Su),h=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(l)[0].length,u=a.length-h;if(a.slice(u-e.length,u)==e&&l.slice(c,c+n.length)==n)return{open:{pos:r-h,margin:h&&1},close:{pos:i+c,margin:c&&1}};i-r<=2*Su?o=s=t.sliceDoc(r,i):(o=t.sliceDoc(r,r+Su),s=t.sliceDoc(i-Su,i));let d=/^\s*/.exec(o)[0].length,f=/\s*$/.exec(s)[0].length,p=s.length-f-n.length;return o.slice(d,d+e.length)==e&&s.slice(p,p+n.length)==n?{open:{pos:r+d+e.length,margin:/\s/.test(o.charAt(d+e.length))?1:0},close:{pos:i-f-n.length,margin:/\s/.test(s.charAt(p-1))?1:0}}:null}(e,r[n],t.from,t.to)));if(2!=t&&!i.every((t=>t)))return{changes:e.changes(n.map(((t,e)=>i[e]?[]:[{from:t.from,insert:r[e].open+" "},{from:t.to,insert:" "+r[e].close}])))};if(1!=t&&i.some((t=>t))){let t=[];for(let e,n=0;ni&&(t==o||o>l.from)){i=l.from;let t=/^\s*/.exec(l.text)[0].length,e=t==l.length,n=l.text.slice(t,t+a.length)==a?t:-1;tt.comment<0&&(!t.empty||t.single)))){let t=[];for(let{line:e,token:n,indent:i,empty:o,single:s}of r)!s&&o||t.push({from:e.from+i,insert:n+" "});let n=e.changes(t);return{changes:n,selection:e.selection.map(n,1)}}if(1!=t&&r.some((t=>t.comment>=0))){let t=[];for(let{line:e,comment:n,token:i}of r)if(n>=0){let r=e.from+n,o=r+i.length;" "==e.text[o-e.from]&&o++,t.push({from:r,to:o})}return{changes:t}}return null}const Au=Fe.define(),Tu=Fe.define(),Mu=ue.define(),_u=ue.define({combine:t=>tn(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(n,r)=>t(n,r)||e(n,r)})});const Du=ye.define({create:()=>Xu.empty,update(t,e){let n=e.state.facet(_u),r=e.annotation(Au);if(r){let i=e.docChanged?le.single(function(t){let e=0;return t.iterChangedRanges(((t,n)=>e=n)),e}(e.changes)):void 0,o=Bu.fromTransaction(e,i),s=r.side,a=0==s?t.undone:t.done;return a=o?Fu(a,a.length,n.minDepth,o):Vu(a,e.startState.selection),new Xu(0==s?r.rest:a,0==s?a:r.rest)}let i=e.annotation(Tu);if("full"!=i&&"before"!=i||(t=t.isolate()),!1===e.annotation(Ve.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let o=Bu.fromTransaction(e),s=e.annotation(Ve.time),a=e.annotation(Ve.userEvent);return o?t=t.addChanges(o,s,a,n,e):e.selection&&(t=t.addSelection(e.startState.selection,s,a,n.newGroupDelay)),"full"!=i&&"after"!=i||(t=t.isolate()),t},toJSON:t=>({done:t.done.map((t=>t.toJSON())),undone:t.undone.map((t=>t.toJSON()))}),fromJSON:t=>new Xu(t.done.map(Bu.fromJSON),t.undone.map(Bu.fromJSON))});function Ou(t={}){return[Du,_u.of(t),fs.domEventHandlers({beforeinput(t,e){let n="historyUndo"==t.inputType?Iu:"historyRedo"==t.inputType?Ru:null;return!!n&&(t.preventDefault(),n(e))}})]}function Pu(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let i=n.field(Du,!1);if(!i)return!1;let o=i.pop(t,n,e);return!!o&&(r(o),!0)}}const Iu=Pu(0,!1),Ru=Pu(1,!1),Nu=Pu(0,!0),Lu=Pu(1,!0);class Bu{constructor(t,e,n,r,i){this.changes=t,this.effects=e,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new Bu(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,n;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(n=this.startSelection)||void 0===n?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map((t=>t.toJSON()))}}static fromJSON(t){return new Bu(t.changes&&te.fromJSON(t.changes),[],t.mapped&&Zt.fromJSON(t.mapped),t.startSelection&&le.fromJSON(t.startSelection),t.selectionsAfter.map(le.fromJSON))}static fromTransaction(t,e){let n=Hu;for(let e of t.startState.facet(Mu)){let r=e(t);r.length&&(n=n.concat(r))}return!n.length&&t.changes.empty?null:new Bu(t.changes.invert(t.startState.doc),n,void 0,e||t.startState.selection,Hu)}static selection(t){return new Bu(void 0,Hu,void 0,void 0,t)}}function Fu(t,e,n,r){let i=e+1>n+20?e-n-1:0,o=t.slice(i,e);return o.push(r),o}function zu(t,e){return t.length?e.length?t.concat(e):t:e}const Hu=[],Wu=200;function Vu(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Wu));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),Fu(t,t.length-1,1e9,n.setSelAfter(r)))}return[Bu.selection([e])]}function Uu(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function ju(t,e){if(!t.length)return t;let n=t.length,r=Hu;for(;n;){let i=$u(t[n-1],e,r);if(i.changes&&!i.changes.empty||i.effects.length){let e=t.slice(0,n);return e[n-1]=i,e}e=i.mapped,n--,r=i.selectionsAfter}return r.length?[Bu.selection(r)]:Hu}function $u(t,e,n){let r=zu(t.selectionsAfter.length?t.selectionsAfter.map((t=>t.map(e))):Hu,n);if(!t.changes)return Bu.selection(r);let i=t.changes.map(e),o=e.mapDesc(t.changes,!0),s=t.mapped?t.mapped.composeDesc(o):o;return new Bu(i,We.mapEffects(t.effects,e),s,t.startSelection.map(o),r)}const qu=/^(input\.type|delete)($|\.)/;class Xu{constructor(t,e,n=0,r){this.done=t,this.undone=e,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new Xu(this.done,this.undone):this}addChanges(t,e,n,r,i){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!n||qu.test(n))&&(!s.selectionsAfter.length&&e-this.prevTimen.push(t,e))),e.iterChangedRanges(((t,e,i,o)=>{for(let t=0;t=e&&i<=s&&(r=!0)}})),r}(s.changes,t.changes))||"input.type.compose"==n)?Fu(o,o.length-1,r.minDepth,new Bu(t.changes.compose(s.changes),zu(t.effects,s.effects),s.mapped,s.startSelection,Hu)):Fu(o,o.length,r.minDepth,t),new Xu(o,Hu,e,n)}addSelection(t,e,n,r){let i=this.done.length?this.done[this.done.length-1].selectionsAfter:Hu;return i.length>0&&e-this.prevTimet.empty!=s.ranges[e].empty)).length)?this:new Xu(Vu(this.done,t),this.undone,e,n);var o,s}addMapping(t){return new Xu(ju(this.done,t),ju(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,n){let r=0==t?this.done:this.undone;if(0==r.length)return null;let i=r[r.length-1];if(n&&i.selectionsAfter.length)return e.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:Au.of({side:t,rest:Uu(r)}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(i.changes){let n=1==r.length?Hu:r.slice(0,r.length-1);return i.mapped&&(n=ju(n,i.mapped)),e.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:Au.of({side:t,rest:n}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}Xu.empty=new Xu(Hu,Hu);const Ku=[{key:"Mod-z",run:Iu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Ru,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Ru,preventDefault:!0},{key:"Mod-u",run:Nu,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Lu,preventDefault:!0}];function Gu(t,e){return le.create(t.ranges.map(e),t.mainIndex)}function Yu(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Ju({state:t,dispatch:e},n){let r=Gu(t.selection,n);return!r.eq(t.selection)&&(e(Yu(t,r)),!0)}function Qu(t,e){return le.cursor(e?t.to:t.from)}function Zu(t,e){return Ju(t,(n=>n.empty?t.moveByChar(n,e):Qu(n,e)))}function td(t){return t.textDirectionAt(t.state.selection.main.head)==gi.LTR}const ed=t=>Zu(t,!td(t)),nd=t=>Zu(t,td(t));function rd(t,e){return Ju(t,(n=>n.empty?t.moveByGroup(n,e):Qu(n,e)))}function id(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function od(t,e,n){let r,i,o=_h(t).resolveInner(e.head),s=n?Yc.closedBy:Yc.openedBy;for(let r=e.head;;){let e=n?o.childAfter(r):o.childBefore(r);if(!e)break;id(t,e,s)?o=e:r=n?e.to:e.from}return i=o.type.prop(s)&&(r=n?Hc(t,o.from,1):Hc(t,o.to,-1))&&r.matched?n?r.end.to:r.end.from:n?o.to:o.from,le.cursor(i,n?-1:1)}function sd(t,e){return Ju(t,(n=>{if(!n.empty)return Qu(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)}))}const ad=t=>sd(t,!1),ld=t=>sd(t,!0);function hd(t){let e,n=t.scrollDOM.clientHeightn.empty?t.moveVertically(n,e,r.height):Qu(n,e)));if(o.eq(i.selection))return!1;if(r.selfScroll){let e=t.coordsAtPos(i.selection.main.head),s=t.scrollDOM.getBoundingClientRect(),a=s.top+r.marginTop,l=s.bottom-r.marginBottom;e&&e.top>a&&e.bottomcd(t,!1),dd=t=>cd(t,!0);function fd(t,e,n){let r=t.lineBlockAt(e.head),i=t.moveToLineBoundary(e,n);if(i.head==e.head&&i.head!=(n?r.to:r.from)&&(i=t.moveToLineBoundary(e,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&e.head!=r.from+n&&(i=le.cursor(r.from+n))}return i}function pd(t,e,n){let r=!1,i=Gu(t.selection,(e=>{let i=Hc(t,e.head,-1)||Hc(t,e.head,1)||e.head>0&&Hc(t,e.head-1,1)||e.head{let n=e(t);return le.range(t.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)}));return!n.eq(t.state.selection)&&(t.dispatch(Yu(t.state,n)),!0)}function gd(t,e){return md(t,(n=>t.moveByChar(n,e)))}const vd=t=>gd(t,!td(t)),yd=t=>gd(t,td(t));function wd(t,e){return md(t,(n=>t.moveByGroup(n,e)))}function bd(t,e){return md(t,(n=>t.moveVertically(n,e)))}const xd=t=>bd(t,!1),kd=t=>bd(t,!0);function Sd(t,e){return md(t,(n=>t.moveVertically(n,e,hd(t).height)))}const Ed=t=>Sd(t,!1),Cd=t=>Sd(t,!0),Ad=({state:t,dispatch:e})=>(e(Yu(t,{anchor:0})),!0),Td=({state:t,dispatch:e})=>(e(Yu(t,{anchor:t.doc.length})),!0),Md=({state:t,dispatch:e})=>(e(Yu(t,{anchor:t.selection.main.anchor,head:0})),!0),_d=({state:t,dispatch:e})=>(e(Yu(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function Dd(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,i=r.changeByRange((r=>{let{from:i,to:o}=r;if(i==o){let r=e(i);ri&&(n="delete.forward",r=Od(t,r,!0)),i=Math.min(i,r),o=Math.max(o,r)}else i=Od(t,i,!1),o=Od(t,o,!0);return i==o?{range:r}:{changes:{from:i,to:o},range:le.cursor(i)}}));return!i.changes.empty&&(t.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:"delete.selection"==n?fs.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function Od(t,e,n){if(t instanceof fs)for(let r of t.state.facet(fs.atomicRanges).map((e=>e(t))))r.between(e,e,((t,r)=>{te&&(e=n?r:t)}));return e}const Pd=(t,e)=>Dd(t,(n=>{let r,i,{state:o}=t,s=o.doc.lineAt(n);if(!e&&n>s.from&&nPd(t,!1),Rd=t=>Pd(t,!0),Nd=(t,e)=>Dd(t,(n=>{let r=n,{state:i}=t,o=i.doc.lineAt(r),s=i.charCategorizer(r);for(let t=null;;){if(r==(e?o.to:o.from)){r==n&&o.number!=(e?i.doc.lines:1)&&(r+=e?1:-1);break}let a=Ut(o.text,r-o.from,e)+o.from,l=o.text.slice(Math.min(r,a)-o.from,Math.max(r,a)-o.from),h=s(l);if(null!=t&&h!=t)break;" "==l&&r==n||(t=h),r=a}return r})),Ld=t=>Nd(t,!1),Bd=t=>Dd(t,(e=>{let n=t.lineBlockAt(e).to;return e=i.number){let t=e[e.length-1];t.to=o.to,t.ranges.push(r)}else e.push({from:i.from,to:o.to,ranges:[r]});n=o.number+1}return e}function zd(t,e,n){if(t.readOnly)return!1;let r=[],i=[];for(let e of Fd(t)){if(n?e.to==t.doc.length:0==e.from)continue;let o=t.doc.lineAt(n?e.to+1:e.from-1),s=o.length+1;if(n){r.push({from:e.to,to:o.to},{from:e.from,insert:o.text+t.lineBreak});for(let n of e.ranges)i.push(le.range(Math.min(t.doc.length,n.anchor+s),Math.min(t.doc.length,n.head+s)))}else{r.push({from:o.from,to:e.from},{from:e.to,insert:t.lineBreak+o.text});for(let t of e.ranges)i.push(le.range(t.anchor-s,t.head-s))}}return!!r.length&&(e(t.update({changes:r,scrollIntoView:!0,selection:le.create(i,t.selection.mainIndex),userEvent:"move.line"})),!0)}function Hd(t,e,n){if(t.readOnly)return!1;let r=[];for(let e of Fd(t))n?r.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):r.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:r,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Wd=Vd(!1);function Vd(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange((n=>{let{from:r,to:i}=n,o=e.doc.lineAt(r),s=!t&&r==i&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n,r=_h(t).resolveInner(e),i=r.childBefore(e),o=r.childAfter(e);return i&&o&&i.to<=e&&o.from>=e&&(n=i.type.prop(Yc.closedBy))&&n.indexOf(o.name)>-1&&t.doc.lineAt(i.to).from==t.doc.lineAt(o.from).from?{from:i.to,to:o.from}:null}(e,r);t&&(r=i=(i<=o.to?o:e.doc.lineAt(i)).to);let a=new jh(e,{simulateBreak:r,simulateDoubleBreak:!!s}),l=Uh(a,r);for(null==l&&(l=/^\s*/.exec(e.doc.lineAt(r).text)[0].length);io.from&&r{let i=[];for(let o=r.from;o<=r.to;){let s=t.doc.lineAt(o);s.number>n&&(r.empty||r.to>s.from)&&(e(s,i,r),n=s.number),o=s.to+1}let o=t.changes(i);return{changes:i,range:le.range(o.mapPos(r.anchor,1),o.mapPos(r.head,1))}}))}const jd=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Ud(t,((e,n)=>{n.push({from:e.from,insert:t.facet(Hh)})})),{userEvent:"input.indent"})),!0),$d=({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(Ud(t,((e,n)=>{let r=/^\s*/.exec(e.text)[0];if(!r)return;let i=yn(r,t.tabSize),o=0,s=Vh(t,Math.max(0,i-Wh(t)));for(;oJu(t,(e=>od(t.state,e,!td(t)))),shift:t=>md(t,(e=>od(t.state,e,!td(t))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>Ju(t,(e=>od(t.state,e,td(t)))),shift:t=>md(t,(e=>od(t.state,e,td(t))))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>zd(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>Hd(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>zd(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>Hd(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=le.create([n.main]):n.main.empty||(r=le.create([le.cursor(n.main.head)])),!!r&&(e(Yu(t,r)),!0)}},{key:"Mod-Enter",run:Vd(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let n=Fd(t).map((({from:e,to:n})=>le.range(e,Math.min(n+1,t.doc.length))));return e(t.update({selection:le.create(n),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let n=Gu(t.selection,(e=>{var n;let r=_h(t).resolveInner(e.head,1);for(;!(r.from=e.to||r.to>e.to&&r.from<=e.from)&&(null===(n=r.parent)||void 0===n?void 0:n.parent);)r=r.parent;return le.range(r.to,r.from)}));return e(Yu(t,n)),!0},preventDefault:!0},{key:"Mod-[",run:$d},{key:"Mod-]",run:jd},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new jh(t,{overrideIndentation:t=>{let e=n[t];return null==e?-1:e}}),i=Ud(t,((e,i,o)=>{let s=Uh(r,e.from);if(null==s)return;/\S/.test(e.text)||(s=0);let a=/^\s*/.exec(e.text)[0],l=Vh(t,s);(a!=l||o.from{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(Fd(e).map((({from:t,to:n})=>(t>0?t--:nt.moveVertically(e,!0))).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>pd(t,e,!1)},{key:"Mod-/",run:t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=ku(t.state,n.from);return r.line?wu(t):!!r.block&&xu(t)}},{key:"Alt-A",run:bu}].concat([{key:"ArrowLeft",run:ed,shift:vd,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>rd(t,!td(t)),shift:t=>wd(t,!td(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>Ju(t,(e=>fd(t,e,!td(t)))),shift:t=>md(t,(e=>fd(t,e,!td(t)))),preventDefault:!0},{key:"ArrowRight",run:nd,shift:yd,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>rd(t,td(t)),shift:t=>wd(t,td(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>Ju(t,(e=>fd(t,e,td(t)))),shift:t=>md(t,(e=>fd(t,e,td(t)))),preventDefault:!0},{key:"ArrowUp",run:ad,shift:xd,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ad,shift:Md},{mac:"Ctrl-ArrowUp",run:ud,shift:Ed},{key:"ArrowDown",run:ld,shift:kd,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Td,shift:_d},{mac:"Ctrl-ArrowDown",run:dd,shift:Cd},{key:"PageUp",run:ud,shift:Ed},{key:"PageDown",run:dd,shift:Cd},{key:"Home",run:t=>Ju(t,(e=>fd(t,e,!1))),shift:t=>md(t,(e=>fd(t,e,!1))),preventDefault:!0},{key:"Mod-Home",run:Ad,shift:Md},{key:"End",run:t=>Ju(t,(e=>fd(t,e,!0))),shift:t=>md(t,(e=>fd(t,e,!0))),preventDefault:!0},{key:"Mod-End",run:Td,shift:_d},{key:"Enter",run:Wd},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Id,shift:Id},{key:"Delete",run:Rd},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Ld},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Nd(t,!0)},{mac:"Mod-Backspace",run:t=>Dd(t,(e=>{let n=t.lineBlockAt(e).from;return e>n?n:Math.max(0,e-1)}))},{mac:"Mod-Delete",run:Bd}].concat([{key:"Ctrl-b",run:ed,shift:vd,preventDefault:!0},{key:"Ctrl-f",run:nd,shift:yd},{key:"Ctrl-p",run:ad,shift:xd},{key:"Ctrl-n",run:ld,shift:kd},{key:"Ctrl-a",run:t=>Ju(t,(e=>le.cursor(t.lineBlockAt(e.head).from,1))),shift:t=>md(t,(e=>le.cursor(t.lineBlockAt(e.head).from)))},{key:"Ctrl-e",run:t=>Ju(t,(e=>le.cursor(t.lineBlockAt(e.head).to,-1))),shift:t=>md(t,(e=>le.cursor(t.lineBlockAt(e.head).to)))},{key:"Ctrl-d",run:Rd},{key:"Ctrl-h",run:Id},{key:"Ctrl-k",run:Bd},{key:"Ctrl-Alt-h",run:Ld},{key:"Ctrl-o",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange((t=>({changes:{from:t.from,to:t.to,insert:Dt.of(["",""])},range:le.cursor(t.from)})));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange((e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let n=e.from,r=t.doc.lineAt(n),i=n==r.from?n-1:Ut(r.text,n-r.from,!1)+r.from,o=n==r.to?n+1:Ut(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:o,insert:t.doc.slice(n,o).append(t.doc.slice(i,n))},range:le.cursor(o)}}));return!n.changes.empty&&(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:dd}].map((t=>({mac:t.key,run:t.run,shift:t.shift}))))),Xd={key:"Tab",run:jd,shift:$d};function Kd(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,n=arguments[1];if(n&&"object"==typeof n&&null==n.nodeType&&!Array.isArray(n)){for(var r in n)if(Object.prototype.hasOwnProperty.call(n,r)){var i=n[r];"string"==typeof i?t.setAttribute(r,i):null!=i&&(t[r]=i)}e++}for(;et.normalize("NFKD"):t=>t;class Jd{constructor(t,e,n=0,r=t.length,i,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(n,r),this.bufferStart=n,this.normalize=i?t=>i(Yd(t)):Yd,this.query=this.normalize(e)}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 Kt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=Gt(t),n=this.bufferStart+this.bufferPos;this.bufferPos+=Yt(t);let r=this.normalize(e);for(let t=0,i=n;;t++){let o=r.charCodeAt(t),s=this.match(o,i);if(s)return this.value=s,this;if(t==r.length-1)break;i==n&&tthis.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let n=this.curLineStart+e.index,r=n+e[0].length;if(this.matchPos=of(this.text,r+(n==r?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(nthis.value.to)&&(!this.test||this.test(n,r,e)))return this.value={from:n,to:r,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length=n||r.to<=e){let r=new nf(e,t.sliceString(e,n));return ef.set(t,r),r}if(r.from==e&&r.to==n)return r;let{text:i,from:o}=r;return o>e&&(i=t.sliceString(e,o)+i,o=e),r.to=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let t=this.flat.from+e.index,n=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,n,e)))return this.value={from:t,to:n,match:e},this.matchPos=of(this.text,n+(t==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=nf.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function of(t,e){if(e>=t.length)return e;let n,r=t.lineAt(e);for(;e=56320&&n<57344;)e++;return e}function sf(t){let e=Kd("input",{class:"cm-textfield",name:"line"});function n(){let n=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!n)return;let{state:r}=t,i=r.doc.lineAt(r.selection.main.head),[,o,s,a,l]=n,h=a?+a.slice(1):0,c=s?+s:i.number;if(s&&l){let t=c/100;o&&(t=t*("-"==o?-1:1)+i.number/r.doc.lines),c=Math.round(r.doc.lines*t)}else s&&o&&(c=c*("-"==o?-1:1)+i.number);let u=r.doc.line(Math.max(1,Math.min(r.doc.lines,c)));t.dispatch({effects:af.of(!1),selection:le.cursor(u.from+Math.max(0,Math.min(h,u.length))),scrollIntoView:!0}),t.focus()}return{dom:Kd("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:af.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),n())},onsubmit:t=>{t.preventDefault(),n()}},Kd("label",t.state.phrase("Go to line"),": ",e)," ",Kd("button",{class:"cm-button",type:"submit"},t.state.phrase("go")))}}"undefined"!=typeof Symbol&&(tf.prototype[Symbol.iterator]=rf.prototype[Symbol.iterator]=function(){return this});const af=We.define(),lf=ye.define({create:()=>!0,update(t,e){for(let n of e.effects)n.is(af)&&(t=n.value);return t},provide:t=>Da.from(t,(t=>t?sf:null))}),hf=fs.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),cf={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},uf=ue.define({combine:t=>tn(t,cf,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});function df(t){let e=[vf,gf];return t&&e.push(uf.of(t)),e}const ff=Ir.mark({class:"cm-selectionMatch"}),pf=Ir.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function mf(t,e,n,r){return!(0!=n&&t(e.sliceDoc(n-1,n))==Ge.Word||r!=e.doc.length&&t(e.sliceDoc(r,r+1))==Ge.Word)}const gf=oi.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(uf),{state:n}=t,r=n.selection;if(r.ranges.length>1)return Ir.none;let i,o=r.main,s=null;if(o.empty){if(!e.highlightWordAroundCursor)return Ir.none;let t=n.wordAt(o.head);if(!t)return Ir.none;s=n.charCategorizer(o.head),i=n.sliceDoc(t.from,t.to)}else{let t=o.to-o.from;if(t200)return Ir.none;if(e.wholeWords){if(i=n.sliceDoc(o.from,o.to),s=n.charCategorizer(o.head),!mf(s,n,o.from,o.to)||!function(t,e,n,r){return t(e.sliceDoc(n,n+1))==Ge.Word&&t(e.sliceDoc(r-1,r))==Ge.Word}(s,n,o.from,o.to))return Ir.none}else if(i=n.sliceDoc(o.from,o.to).trim(),!i)return Ir.none}let a=[];for(let r of t.visibleRanges){let t=new Jd(n.doc,i,r.from,r.to);for(;!t.next().done;){let{from:r,to:i}=t.value;if((!s||mf(s,n,r,i))&&(o.empty&&r<=o.from&&i>=o.to?a.push(pf.range(r,i)):(r>=o.to||i<=o.from)&&a.push(ff.range(r,i)),a.length>e.maxMatches))return Ir.none}}return Ir.set(a)}},{decorations:t=>t.decorations}),vf=fs.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const yf=ue.define({combine:t=>tn(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Xf(t),scrollToMatch:t=>fs.scrollIntoView(t)})});class wf{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,Zd),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,((t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\"))}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new Af(this):new kf(this)}getCursor(t,e=0,n){let r=t.doc?t:Ze.create({doc:t});return null==n&&(n=r.doc.length),this.regexp?Sf(this,r,e,n):xf(this,r,e,n)}}class bf{constructor(t){this.spec=t}}function xf(t,e,n,r){return new Jd(e.doc,t.unquoted,n,r,t.caseSensitive?void 0:t=>t.toLowerCase(),t.wholeWord?(i=e.doc,o=e.charCategorizer(e.selection.main.head),(t,e,n,r)=>((r>t||r+n.length=e)return null;r.push(n.value)}return r}highlight(t,e,n,r){let i=xf(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,t.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}}function Sf(t,e,n,r){return new tf(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(i=e.charCategorizer(e.selection.main.head),(t,e,n)=>!n[0].length||(i(Ef(n.input,n.index))!=Ge.Word||i(Cf(n.input,n.index))!=Ge.Word)&&(i(Cf(n.input,n.index+n[0].length))!=Ge.Word||i(Ef(n.input,n.index+n[0].length))!=Ge.Word)):void 0},n,r);var i}function Ef(t,e){return t.slice(Ut(t,e,!1),e)}function Cf(t,e){return t.slice(e,Ut(t,e))}class Af extends bf{nextMatch(t,e,n){let r=Sf(this.spec,t,n,t.doc.length).next();return r.done&&(r=Sf(this.spec,t,0,e).next()),r.done?null:r.value}prevMatchInRange(t,e,n){for(let r=1;;r++){let i=Math.max(e,n-1e4*r),o=Sf(this.spec,t,i,n),s=null;for(;!o.next().done;)s=o.value;if(s&&(i==e||s.from>i+10))return s;if(i==e)return null}}prevMatch(t,e,n){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,n,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g,((e,n)=>"$"==n?"$":"&"==n?t.match[0]:"0"!=n&&+n=e)return null;r.push(n.value)}return r}highlight(t,e,n,r){let i=Sf(this.spec,t,Math.max(0,e-250),Math.min(n+250,t.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}}const Tf=We.define(),Mf=We.define(),_f=ye.define({create:t=>new Df(Wf(t).create(),null),update(t,e){for(let n of e.effects)n.is(Tf)?t=new Df(n.value.create(),t.panel):n.is(Mf)&&(t=new Df(t.query,n.value?Hf:null));return t},provide:t=>Da.from(t,(t=>t.panel))});class Df{constructor(t,e){this.query=t,this.panel=e}}const Of=Ir.mark({class:"cm-searchMatch"}),Pf=Ir.mark({class:"cm-searchMatch cm-searchMatch-selected"}),If=oi.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(_f))}update(t){let e=t.state.field(_f);(e!=t.startState.field(_f)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Ir.none;let{view:n}=this,r=new an;for(let e=0,i=n.visibleRanges,o=i.length;ei[e+1].from-500;)a=i[++e].to;t.highlight(n.state,s,a,((t,e)=>{let i=n.state.selection.ranges.some((n=>n.from==t&&n.to==e));r.add(t,e,i?Pf:Of)}))}return r.finish()}},{decorations:t=>t.decorations});function Rf(t){return e=>{let n=e.state.field(_f,!1);return n&&n.query.spec.valid?t(e,n):jf(e)}}const Nf=Rf(((t,{query:e})=>{let{to:n}=t.state.selection.main,r=e.nextMatch(t.state,n,n);if(!r)return!1;let i=le.single(r.from,r.to),o=t.state.facet(yf);return t.dispatch({selection:i,effects:[Jf(t,r),o.scrollToMatch(i.main,t)],userEvent:"select.search"}),Uf(t),!0})),Lf=Rf(((t,{query:e})=>{let{state:n}=t,{from:r}=n.selection.main,i=e.prevMatch(n,r,r);if(!i)return!1;let o=le.single(i.from,i.to),s=t.state.facet(yf);return t.dispatch({selection:o,effects:[Jf(t,i),s.scrollToMatch(o.main,t)],userEvent:"select.search"}),Uf(t),!0})),Bf=Rf(((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!(!n||!n.length)&&(t.dispatch({selection:le.create(n.map((t=>le.range(t.from,t.to)))),userEvent:"select.search.matches"}),!0)})),Ff=Rf(((t,{query:e})=>{let{state:n}=t,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let o=e.nextMatch(n,r,r);if(!o)return!1;let s,a,l=[],h=[];if(o.from==r&&o.to==i&&(a=n.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:a}),o=e.nextMatch(n,o.from,o.to),h.push(fs.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+"."))),o){let e=0==l.length||l[0].from>=o.to?0:o.to-o.from-a.length;s=le.single(o.from-e,o.to-e),h.push(Jf(t,o)),h.push(n.facet(yf).scrollToMatch(s.main,t))}return t.dispatch({changes:l,selection:s,effects:h,userEvent:"input.replace"}),!0})),zf=Rf(((t,{query:e})=>{if(t.state.readOnly)return!1;let n=e.matchAll(t.state,1e9).map((t=>{let{from:n,to:r}=t;return{from:n,to:r,insert:e.getReplacement(t)}}));if(!n.length)return!1;let r=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:fs.announce.of(r),userEvent:"input.replace.all"}),!0}));function Hf(t){return t.state.facet(yf).createPanel(t)}function Wf(t,e){var n,r,i,o,s;let a=t.selection.main,l=a.empty||a.to>a.from+100?"":t.sliceDoc(a.from,a.to);if(e&&!l)return e;let h=t.facet(yf);return new wf({search:(null!==(n=null==e?void 0:e.literal)&&void 0!==n?n:h.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:null!==(r=null==e?void 0:e.caseSensitive)&&void 0!==r?r:h.caseSensitive,literal:null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:h.literal,regexp:null!==(o=null==e?void 0:e.regexp)&&void 0!==o?o:h.regexp,wholeWord:null!==(s=null==e?void 0:e.wholeWord)&&void 0!==s?s:h.wholeWord})}function Vf(t){let e=Aa(t,Hf);return e&&e.dom.querySelector("[main-field]")}function Uf(t){let e=Vf(t);e&&e==t.root.activeElement&&e.select()}const jf=t=>{let e=t.state.field(_f,!1);if(e&&e.panel){let n=Vf(t);if(n&&n!=t.root.activeElement){let r=Wf(t.state,e.query.spec);r.valid&&t.dispatch({effects:Tf.of(r)}),n.focus(),n.select()}}else t.dispatch({effects:[Mf.of(!0),e?Tf.of(Wf(t.state,e.query.spec)):We.appendConfig.of(Zf)]});return!0},$f=t=>{let e=t.state.field(_f,!1);if(!e||!e.panel)return!1;let n=Aa(t,Hf);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Mf.of(!1)}),!0},qf=[{key:"Mod-f",run:jf,scope:"editor search-panel"},{key:"F3",run:Nf,shift:Lf,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Nf,shift:Lf,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:$f,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,o=[],s=0;for(let e=new Jd(t.doc,t.sliceDoc(r,i));!e.next().done;){if(o.length>1e3)return!1;e.value.from==r&&(s=o.length),o.push(le.range(e.value.from,e.value.to))}return e(t.update({selection:le.create(o,s),userEvent:"select.search.matches"})),!0}},{key:"Alt-g",run:t=>{let e=Aa(t,sf);if(!e){let n=[af.of(!0)];null==t.state.field(lf,!1)&&n.push(We.appendConfig.of([lf,hf])),t.dispatch({effects:n}),e=Aa(t,sf)}return e&&e.dom.querySelector("input").focus(),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:n}=t.selection;if(n.some((t=>t.from===t.to)))return(({state:t,dispatch:e})=>{let{selection:n}=t,r=le.create(n.ranges.map((e=>t.wordAt(e.head)||le.cursor(e.head))),n.mainIndex);return!r.eq(n)&&(e(t.update({selection:r})),!0)})({state:t,dispatch:e});let r=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=r)))return!1;let i=function(t,e){let{main:n,ranges:r}=t.selection,i=t.wordAt(n.head),o=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new Jd(t.doc,e,r[r.length-1].to);;){if(i.next(),!i.done){if(n&&r.some((t=>t.from==i.value.from)))continue;if(o){let e=t.wordAt(i.value.from);if(!e||e.from!=i.value.from||e.to!=i.value.to)continue}return i.value}if(n)return null;i=new Jd(t.doc,e,0,Math.max(0,r[r.length-1].from-1)),n=!0}}(t,r);return!!i&&(e(t.update({selection:t.selection.addRange(le.range(i.from,i.to),!1),effects:fs.scrollIntoView(i.to)})),!0)},preventDefault:!0}];class Xf{constructor(t){this.view=t;let e=this.query=t.state.field(_f).query.spec;function n(t,e,n){return Kd("button",{class:"cm-button",name:t,onclick:e,type:"button"},n)}this.commit=this.commit.bind(this),this.searchField=Kd("input",{value:e.search,placeholder:Kf(t,"Find"),"aria-label":Kf(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Kd("input",{value:e.replace,placeholder:Kf(t,"Replace"),"aria-label":Kf(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Kd("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=Kd("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=Kd("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=Kd("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,n("next",(()=>Nf(t)),[Kf(t,"next")]),n("prev",(()=>Lf(t)),[Kf(t,"previous")]),n("select",(()=>Bf(t)),[Kf(t,"all")]),Kd("label",null,[this.caseField,Kf(t,"match case")]),Kd("label",null,[this.reField,Kf(t,"regexp")]),Kd("label",null,[this.wordField,Kf(t,"by word")]),...t.state.readOnly?[]:[Kd("br"),this.replaceField,n("replace",(()=>Ff(t)),[Kf(t,"replace")]),n("replaceAll",(()=>zf(t)),[Kf(t,"replace all")])],Kd("button",{name:"close",onclick:()=>$f(t),"aria-label":Kf(t,"close"),type:"button"},["×"])])}commit(){let t=new wf({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Tf.of(t)}))}keydown(t){var e,n,r;e=this.view,n=t,r="search-panel",Cs(ks(e.state),n,e,r)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Lf:Nf)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),Ff(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(Tf)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(yf).top}}function Kf(t,e){return t.state.phrase(e)}const Gf=30,Yf=/[\s\.,:;?!]/;function Jf(t,{from:e,to:n}){let r=t.state.doc.lineAt(e),i=t.state.doc.lineAt(n).to,o=Math.max(r.from,e-Gf),s=Math.min(i,n+Gf),a=t.state.sliceDoc(o,s);if(o!=r.from)for(let t=0;ta.length-Gf;t--)if(!Yf.test(a[t-1])&&Yf.test(a[t])){a=a.slice(0,t);break}return fs.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${r.number}.`)}const Qf=fs.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Zf=[_f,Ee.lowest(If),Qf];class tp{constructor(t,e,n){this.state=t,this.pos=e,this.explicit=n,this.abortListeners=[]}tokenBefore(t){let e=_h(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),n=Math.max(e.from,this.pos-250),r=e.text.slice(n-e.from,this.pos-e.from),i=r.search(op(t,!1));return i<0?null:{from:n+i,to:this.pos,text:r.slice(i)}}get aborted(){return null==this.abortListeners}addEventListener(t,e){"abort"==t&&this.abortListeners&&this.abortListeners.push(e)}}function ep(t){let e=Object.keys(t).join(""),n=/\w/.test(e);return n&&(e=e.replace(/\w/g,"")),`[${n?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function np(t){let e=t.map((t=>"string"==typeof t?{label:t}:t)),[n,r]=e.every((t=>/^\w+$/.test(t.label)))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),n=Object.create(null);for(let{label:r}of t){e[r[0]]=!0;for(let t=1;t{let i=t.matchBefore(r);return i||t.explicit?{from:i?i.from:t.pos,options:e,validFor:n}:null}}class rp{constructor(t,e,n,r){this.completion=t,this.source=e,this.match=n,this.score=r}}function ip(t){return t.selection.main.from}function op(t,e){var n;let{source:r}=t,i=e&&"^"!=r[0],o="$"!=r[r.length-1];return i||o?new RegExp(`${i?"^":""}(?:${r})${o?"$":""}`,null!==(n=t.flags)&&void 0!==n?n:t.ignoreCase?"i":""):t}const sp=Fe.define();const ap=new WeakMap;function lp(t){if(!Array.isArray(t))return t;let e=ap.get(t);return e||ap.set(t,e=np(t)),e}const hp=We.define(),cp=We.define();class up{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[];for(let e=0;e=48&&l<=57||l>=97&&l<=122?2:l>=65&&l<=90?1:0:(y=Gt(l))!=y.toLowerCase()?1:y!=y.toUpperCase()?2:0;(!r||1==w&&m||0==v&&0!=w)&&(e[c]==l||n[c]==l&&(u=!0)?o[c++]=r:o.length&&(g=!1)),v=w,r+=Yt(l)}return c==a&&0==o[0]&&g?this.result((u?-200:0)-100,o,t):d==a&&0==f?[-200-t.length+(p==t.length?0:-100),0,p]:s>-1?[-700-t.length,s,s+this.pattern.length]:d==a?[-900-t.length,f,p]:c==a?this.result((u?-200:0)-100-700+(g?0:-1100),o,t):2==e.length?null:this.result((r[0]?-700:0)-200-1100,r,t)}result(t,e,n){let r=[t-n.length],i=1;for(let t of e){let e=t+(this.astral?Yt(Kt(n,t)):1);i>1&&r[i-1]==t?r[i-1]=e:(r[i++]=t,r[i++]=e)}return r}}const dp=ue.define({combine:t=>tn(t,{activateOnTyping:!0,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:pp,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>n=>fp(t(n),e(n)),optionClass:(t,e)=>n=>fp(t(n),e(n)),addToOptions:(t,e)=>t.concat(e)})});function fp(t,e){return t?e?t+" "+e:t:e}function pp(t,e,n,r,i){let o,s,a=t.textDirection==gi.RTL,l=a,h=!1,c="top",u=e.left-i.left,d=i.right-e.right,f=r.right-r.left,p=r.bottom-r.top;if(l&&u=p||t>e.top?o=n.bottom-e.top:(c="bottom",o=e.bottom-n.top)}return{style:`${c}: ${o}px; max-width: ${s}px`,class:"cm-completionInfo-"+(h?a?"left-narrow":"right-narrow":l?"left":"right")}}function mp(t,e="option"){return n=>{let r=n.state.field(Pp,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp-1?r.open.selected+o*(t?1:-1):t?0:s-1;return a<0?a="page"==e?0:s-1:a>=s&&(a="page"==e?s-1:0),n.dispatch({effects:Op.of(a)}),!0}}class gp{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const vp=oi.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.composing=0;for(let e of t.state.field(Pp).active)1==e.state&&this.startQuery(e)}update(t){let e=t.state.field(Pp);if(!t.selectionSet&&!t.docChanged&&t.startState.field(Pp)==e)return;let n=t.transactions.some((t=>(t.selection||t.docChanged)&&!Tp(t)));for(let e=0;e50&&Date.now()-r.time>1e3){for(let t of r.context.abortListeners)try{t()}catch(t){ei(this.view.state,t)}r.context.abortListeners=null,this.running.splice(e--,1)}else r.updates.push(...t.transactions)}if(this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),this.debounceUpdate=e.active.some((t=>1==t.state&&!this.running.some((e=>e.active.source==t.source))))?setTimeout((()=>this.startUpdate()),50):-1,0!=this.composing)for(let e of t.transactions)"input"==Tp(e)?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1;let{state:t}=this.view,e=t.field(Pp);for(let t of e.active)1!=t.state||this.running.some((e=>e.active.source==t.source))||this.startQuery(t)}startQuery(t){let{state:e}=this.view,n=ip(e),r=new tp(e,n,t.explicitPos==n),i=new gp(t,r);this.running.push(i),Promise.resolve(t.source(r)).then((t=>{i.context.aborted||(i.done=t||null,this.scheduleAccept())}),(t=>{this.view.dispatch({effects:cp.of(null)}),ei(this.view.state,t)}))}scheduleAccept(){this.running.every((t=>void 0!==t.done))?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout((()=>this.accept()),50))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(dp);for(let r=0;rt.source==i.active.source));if(o&&1==o.state)if(null==i.done){let t=new Mp(i.active.source,0);for(let e of i.updates)t=t.update(e,n);1!=t.state&&e.push(t)}else this.startQuery(o)}e.length&&this.view.dispatch({effects:Dp.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(Pp,!1);if(e&&e.tooltip&&this.view.state.facet(dp).closeOnBlur){let n=e.open&&Sa(this.view,e.open.tooltip);n&&n.dom.contains(t.relatedTarget)||this.view.dispatch({effects:cp.of(null)})}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout((()=>this.view.dispatch({effects:hp.of(!1)})),20),this.composing=0}}});function yp(t,e){const n=e.completion.apply||e.completion.label;let r=t.state.field(Pp).active.find((t=>t.source==e.source));return r instanceof _p&&("string"==typeof n?t.dispatch(Object.assign(Object.assign({},function(t,e,n,r){let{main:i}=t.selection,o=n-i.from,s=r-i.from;return Object.assign(Object.assign({},t.changeByRange((a=>a!=i&&n!=r&&t.sliceDoc(a.from+o,a.from+s)!=t.sliceDoc(n,r)?{range:a}:{changes:{from:a.from+o,to:r==i.from?a.to:a.from+s,insert:e},range:le.cursor(a.from+o+e.length)}))),{userEvent:"input.complete"})}(t.state,n,r.from,r.to)),{annotations:sp.of(e.completion)})):n(t,e.completion,r.from,r.to),!0)}function wp(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/n);return{from:t*n,to:(t+1)*n}}let r=Math.floor((t-e)/n);return{from:t-(r+1)*n,to:t-r*n}}class bp{constructor(t,e){this.view=t,this.stateField=e,this.info=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:r,selected:i}=n.open,o=t.state.facet(dp);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map((t=>"cm-completionIcon-"+t))),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,n){let r=document.createElement("span");r.className="cm-completionLabel";let{label:i}=t,o=0;for(let t=1;to&&r.appendChild(document.createTextNode(i.slice(o,e)));let a=r.appendChild(document.createElement("span"));a.appendChild(document.createTextNode(i.slice(e,s))),a.className="cm-completionMatchedText",o=s}return ot.position-e.position)).map((t=>t.render))}(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=wp(r.length,i,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",(e=>{for(let n,i=e.target;i&&i!=this.dom;i=i.parentNode)if("LI"==i.nodeName&&(n=/-(\d+)$/.exec(i.id))&&+n[1]{let n=t.state.field(this.stateField,!1);n&&n.tooltip&&t.state.facet(dp).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:cp.of(null)})})),this.list=this.dom.appendChild(this.createListBox(r,n.id,this.range)),this.list.addEventListener("scroll",(()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)}))}mount(){this.updateSel()}update(t){var e,n,r;let i=t.state.field(this.stateField),o=t.startState.field(this.stateField);this.updateTooltipClass(t.state),i!=o&&(this.updateSel(),(null===(e=i.open)||void 0===e?void 0:e.disabled)!=(null===(n=o.open)||void 0===n?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!(null===(r=i.open)||void 0===r?void 0:r.disabled)))}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected=this.range.to)&&(this.range=wp(e.options.length,e.selected,this.view.state.facet(dp).maxRenderedOptions),this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e.options,t.id,this.range)),this.list.addEventListener("scroll",(()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)}))),this.updateSelectedOption(e.selected)){this.info&&(this.info.remove(),this.info=null);let{completion:n}=e.options[e.selected],{info:r}=n;if(!r)return;let i="string"==typeof r?document.createTextNode(r):r(n);if(!i)return;"then"in i?i.then((e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e)})).catch((t=>ei(this.view.state,t,"completion info"))):this.addInfoPane(i)}}addInfoPane(t){let e=this.info=document.createElement("div");e.className="cm-tooltip cm-completionInfo",e.appendChild(t),this.dom.appendChild(e),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let n=this.list.firstChild,r=this.range.from;n;n=n.nextSibling,r++)"LI"==n.nodeName&&n.id?r==t?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),e=n):n.hasAttribute("aria-selected")&&n.removeAttribute("aria-selected"):r--;return e&&function(t,e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();r.topn.bottom&&(t.scrollTop+=r.bottom-n.bottom)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),r=t.getBoundingClientRect(),i=this.space;if(!i){let t=this.dom.ownerDocument.defaultView||window;i={left:0,top:0,right:t.innerWidth,bottom:t.innerHeight}}return r.top>Math.min(i.bottom,e.bottom)-10||r.bottomn.from||0==n.from))if(i=t,"string"!=typeof l&&l.header)r.appendChild(l.header(l));else{r.appendChild(document.createElement("completion-section")).textContent=t}}const h=r.appendChild(document.createElement("li"));h.id=e+"-"+o,h.setAttribute("role","option");let c=this.optionClass(s);c&&(h.className=c);for(let t of this.optionContent){let e=t(s,this.view.state,a);e&&h.appendChild(e)}}return n.from&&r.classList.add("cm-completionListIncompleteTop"),n.to=this.options.length?this:new kp(this.options,Cp(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,n,r,i){let o=function(t,e){let n=[],r=null,i=t=>{n.push(t);let{section:e}=t.completion;if(e){r||(r=[]);let t="string"==typeof e?e:e.name;r.some((e=>e.name==t))||r.push("string"==typeof e?{name:t}:e)}};for(let r of t)if(r.hasResult())if(!1===r.result.filter){let t=r.result.getMatch;for(let e of r.result.options){let o=[1e9-n.length];if(t)for(let n of t(e))o.push(n);i(new rp(e,r.source,o,o[0]))}}else{let t,n=new up(e.sliceDoc(r.from,r.to));for(let e of r.result.options)(t=n.match(e.label))&&i(new rp(e,r.source,t,t[0]+(e.boost||0)))}if(r){let t=Object.create(null),e=0,i=(t,e)=>{var n,r;return(null!==(n=t.rank)&&void 0!==n?n:1e9)-(null!==(r=e.rank)&&void 0!==r?r:1e9)||(t.namee.score-t.score||a(t.completion,e.completion))))!s||s.label!=t.completion.label||s.detail!=t.completion.detail||null!=s.type&&null!=t.completion.type&&s.type!=t.completion.type||s.apply!=t.completion.apply?o.push(t):xp(t.completion)>xp(s)&&(o[o.length-1]=t),s=t.completion;return o}(t,e);if(!o.length)return r&&t.some((t=>1==t.state))?new kp(r.options,r.attrs,r.tooltip,r.timestamp,r.selected,!0):null;let s=e.facet(dp).selectOnOpen?0:-1;if(r&&r.selected!=s&&-1!=r.selected){let t=r.options[r.selected].completion;for(let e=0;ee.hasResult()?Math.min(t,e.from):t),1e8),create:(a=Pp,t=>new bp(t,a)),above:i.aboveCursor},r?r.timestamp:Date.now(),s,!1);var a}map(t){return new kp(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Sp{constructor(t,e,n){this.active=t,this.id=e,this.open=n}static start(){return new Sp(Ap,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,n=e.facet(dp),r=(n.override||e.languageDataAt("autocomplete",ip(e)).map(lp)).map((e=>(this.active.find((t=>t.source==e))||new Mp(e,this.active.some((t=>0!=t.state))?1:0)).update(t,n)));r.length==this.active.length&&r.every(((t,e)=>t==this.active[e]))&&(r=this.active);let i=this.open;i&&t.docChanged&&(i=i.map(t.changes)),t.selection||r.some((e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to)))||!function(t,e){if(t==e)return!0;for(let n=0,r=0;;){for(;n1==t.state))&&(i=null),!i&&r.every((t=>1!=t.state))&&r.some((t=>t.hasResult()))&&(r=r.map((t=>t.hasResult()?new Mp(t.source,0):t)));for(let e of t.effects)e.is(Op)&&(i=i&&i.setSelected(e.value,this.id));return r==this.active&&i==this.open?this:new Sp(r,this.id,i)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Ep}}const Ep={"aria-autocomplete":"list"};function Cp(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const Ap=[];function Tp(t){return t.isUserEvent("input.type")?"input":t.isUserEvent("delete.backward")?"delete":null}class Mp{constructor(t,e,n=-1){this.source=t,this.state=e,this.explicitPos=n}hasResult(){return!1}update(t,e){let n=Tp(t),r=this;n?r=r.handleUserEvent(t,n,e):t.docChanged?r=r.handleChange(t):t.selection&&0!=r.state&&(r=new Mp(r.source,0));for(let e of t.effects)if(e.is(hp))r=new Mp(r.source,1,e.value?ip(t.state):-1);else if(e.is(cp))r=new Mp(r.source,0);else if(e.is(Dp))for(let t of e.value)t.source==r.source&&(r=t);return r}handleUserEvent(t,e,n){return"delete"!=e&&n.activateOnTyping?new Mp(this.source,1):this.map(t.changes)}handleChange(t){return t.changes.touchesRange(ip(t.startState))?new Mp(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new Mp(this.source,this.state,t.mapPos(this.explicitPos))}}class _p extends Mp{constructor(t,e,n,r,i){super(t,2,e),this.result=n,this.from=r,this.to=i}hasResult(){return!0}handleUserEvent(t,e,n){var r;let i=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),s=ip(t.state);if((this.explicitPos<0?s<=i:so||"delete"==e&&ip(t.startState)==this.from)return new Mp(this.source,"input"==e&&n.activateOnTyping?1:0);let a,l=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos);return function(t,e,n,r){if(!t)return!1;let i=e.sliceDoc(n,r);return"function"==typeof t?t(i,n,r,e):op(t,!0).test(i)}(this.result.validFor,t.state,i,o)?new _p(this.source,l,this.result,i,o):this.result.update&&(a=this.result.update(this.result,i,o,new tp(t.state,s,l>=0)))?new _p(this.source,l,a,a.from,null!==(r=a.to)&&void 0!==r?r:ip(t.state)):new Mp(this.source,1,l)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new Mp(this.source,0):this.map(t.changes)}map(t){return t.empty?this:new _p(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1))}}const Dp=We.define({map:(t,e)=>t.map((t=>t.map(e)))}),Op=We.define(),Pp=ye.define({create:()=>Sp.start(),update:(t,e)=>t.update(e),provide:t=>[va.from(t,(t=>t.tooltip)),fs.contentAttributes.from(t,(t=>t.attrs))]}),Ip=fs.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});const Rp={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Np=We.define({map(t,e){let n=e.mapPos(t,-1,Qt.TrackAfter);return null==n?void 0:n}}),Lp=new class extends en{};Lp.startSide=1,Lp.endSide=-1;const Bp=ye.define({create:()=>sn.empty,update(t,e){if(e.selection){let n=e.state.doc.lineAt(e.selection.main.head).from,r=e.startState.doc.lineAt(e.startState.selection.main.head).from;n!=e.changes.mapPos(r,-1)&&(t=sn.empty)}t=t.map(e.changes);for(let n of e.effects)n.is(Np)&&(t=t.update({add:[Lp.range(n.value,n.value+1)]}));return t}});const Fp="()[]{}<>";function zp(t){for(let e=0;e{if((Wp?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let i=t.state.selection.main;if(r.length>2||2==r.length&&1==Yt(Kt(r,0))||e!=i.from||n!=i.to)return!1;let o=function(t,e){let n=Hp(t,t.selection.main.head),r=n.brackets||Rp.brackets;for(let i of r){let o=zp(Kt(i,0));if(e==i)return o==i?Kp(t,i,r.indexOf(i+i+i)>-1,n):qp(t,i,o,n.before||Rp.before);if(e==o&&jp(t,t.selection.main.from))return Xp(t,i,o)}return null}(t.state,r);return!!o&&(t.dispatch(o),!0)})),Up=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Hp(t,t.selection.main.head).brackets||Rp.brackets,r=null,i=t.changeByRange((e=>{if(e.empty){let r=function(t,e){let n=t.sliceString(e-2,e);return Yt(Kt(n,0))==n.length?n:n.slice(1)}(t.doc,e.head);for(let i of n)if(i==r&&$p(t.doc,e.head)==zp(Kt(i,0)))return{changes:{from:e.head-i.length,to:e.head+i.length},range:le.cursor(e.head-i.length)}}return{range:r=e}}));return r||e(t.update(i,{scrollIntoView:!0,userEvent:"delete.backward"})),!r}}];function jp(t,e){let n=!1;return t.field(Bp).between(0,t.doc.length,(t=>{t==e&&(n=!0)})),n}function $p(t,e){let n=t.sliceString(e,e+2);return n.slice(0,Yt(Kt(n,0)))}function qp(t,e,n,r){let i=null,o=t.changeByRange((o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:n,from:o.to}],effects:Np.of(o.to+e.length),range:le.range(o.anchor+e.length,o.head+e.length)};let s=$p(t.doc,o.head);return!s||/\s/.test(s)||r.indexOf(s)>-1?{changes:{insert:e+n,from:o.head},effects:Np.of(o.head+e.length),range:le.cursor(o.head+e.length)}:{range:i=o}}));return i?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Xp(t,e,n){let r=null,i=t.changeByRange((e=>e.empty&&$p(t.doc,e.head)==n?{changes:{from:e.head,to:e.head+n.length,insert:n},range:le.cursor(e.head+n.length)}:r={range:e}));return r?null:t.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function Kp(t,e,n,r){let i=r.stringPrefixes||Rp.stringPrefixes,o=null,s=t.changeByRange((r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:e,from:r.to}],effects:Np.of(r.to+e.length),range:le.range(r.anchor+e.length,r.head+e.length)};let s,a=r.head,l=$p(t.doc,a);if(l==e){if(Gp(t,a))return{changes:{insert:e+e,from:a},effects:Np.of(a+e.length),range:le.cursor(a+e.length)};if(jp(t,a)){let r=n&&t.sliceDoc(a,a+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+r.length,insert:r},range:le.cursor(a+r.length)}}}else{if(n&&t.sliceDoc(a-2*e.length,a)==e+e&&(s=Yp(t,a-2*e.length,i))>-1&&Gp(t,s))return{changes:{insert:e+e+e+e,from:a},effects:Np.of(a+e.length),range:le.cursor(a+e.length)};if(t.charCategorizer(a)(l)!=Ge.Word&&Yp(t,a,i)>-1&&!function(t,e,n,r){let i=_h(t).resolveInner(e,-1),o=r.reduce(((t,e)=>Math.max(t,e.length)),0);for(let s=0;s<5;s++){let s=t.sliceDoc(i.from,Math.min(i.to,i.from+n.length+o)),a=s.indexOf(n);if(!a||a>-1&&r.indexOf(s.slice(0,a))>-1){let e=i.firstChild;for(;e&&e.from==i.from&&e.to-e.from>n.length+a;){if(t.sliceDoc(e.to-n.length,e.to)==n)return!1;e=e.firstChild}return!0}let l=i.to==e&&i.parent;if(!l)break;i=l}return!1}(t,a,e,i))return{changes:{insert:e+e,from:a},effects:Np.of(a+e.length),range:le.cursor(a+e.length)}}return{range:o=r}}));return o?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Gp(t,e){let n=_h(t).resolveInner(e+1);return n.parent&&n.from==e}function Yp(t,e,n){let r=t.charCategorizer(e);if(r(t.sliceDoc(e-1,e))!=Ge.Word)return e;for(let i of n){let n=e-i.length;if(t.sliceDoc(n,e)==i&&r(t.sliceDoc(n-1,n))!=Ge.Word)return n}return-1}function Jp(t={}){return[Pp,dp.of(t),vp,Zp,Ip]}const Qp=[{key:"Ctrl-Space",run:t=>!!t.state.field(Pp,!1)&&(t.dispatch({effects:hp.of(!0)}),!0)},{key:"Escape",run:t=>{let e=t.state.field(Pp,!1);return!(!e||!e.active.some((t=>0!=t.state)))&&(t.dispatch({effects:cp.of(null)}),!0)}},{key:"ArrowDown",run:mp(!0)},{key:"ArrowUp",run:mp(!1)},{key:"PageDown",run:mp(!0,"page")},{key:"PageUp",run:mp(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(Pp,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||Date.now()-e.open.timestampt.facet(dp).defaultKeymap?[Qp]:[])));class tm{constructor(t,e,n){this.from=t,this.to=e,this.diagnostic=n}}class em{constructor(t,e,n){this.diagnostics=t,this.panel=e,this.selected=n}static init(t,e,n){let r=t,i=n.facet(pm).markerFilter;i&&(r=i(r));let o=Ir.set(r.map((t=>t.from==t.to||t.from==t.to-1&&n.doc.lineAt(t.from).to==t.from?Ir.widget({widget:new vm(t),diagnostic:t}).range(t.from):Ir.mark({attributes:{class:"cm-lintRange cm-lintRange-"+t.severity},diagnostic:t}).range(t.from,t.to))),!0);return new em(o,e,nm(o))}}function nm(t,e=null,n=0){let r=null;return t.between(n,1e9,((t,n,{spec:i})=>{if(!e||i.diagnostic==e)return r=new tm(t,n,i.diagnostic),!1})),r}function rm(t,e){let n=t.startState.doc.lineAt(e.pos);return!(!t.effects.some((t=>t.is(om)))&&!t.changes.touchesRange(n.from,n.to))}function im(t,e){return t.field(lm,!1)?e:e.concat(We.appendConfig.of(Sm))}const om=We.define(),sm=We.define(),am=We.define(),lm=ye.define({create:()=>new em(Ir.none,null,null),update(t,e){if(e.docChanged){let n=t.diagnostics.map(e.changes),r=null;if(t.selected){let i=e.changes.mapPos(t.selected.from,1);r=nm(n,t.selected.diagnostic,i)||nm(n,null,i)}t=new em(n,t.panel,r)}for(let n of e.effects)n.is(om)?t=em.init(n.value,t.panel,e.state):n.is(sm)?t=new em(t.diagnostics,n.value?wm.open:null,t.selected):n.is(am)&&(t=new em(t.diagnostics,t.panel,n.value));return t},provide:t=>[Da.from(t,(t=>t.panel)),fs.decorations.from(t,(t=>t.diagnostics))]});const hm=Ir.mark({class:"cm-lintRange cm-lintRange-active"});function cm(t,e,n){let{diagnostics:r}=t.state.field(lm),i=[],o=2e8,s=0;r.between(e-(n<0?1:0),e+(n>0?1:0),((t,r,{spec:a})=>{e>=t&&e<=r&&(t==r||(e>t||n>0)&&(e({dom:um(t,i)})}:null}function um(t,e){return Kd("ul",{class:"cm-tooltip-lint"},e.map((e=>gm(t,e,!1))))}const dm=t=>{let e=t.state.field(lm,!1);return!(!e||!e.panel)&&(t.dispatch({effects:sm.of(!1)}),!0)},fm=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(lm,!1);e&&e.panel||t.dispatch({effects:im(t.state,[sm.of(!0)])});let n=Aa(t,wm.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(lm,!1);if(!e)return!1;let n=t.state.selection.main,r=e.diagnostics.iter(n.to+1);return!(!r.value&&(r=e.diagnostics.iter(0),!r.value||r.from==n.from&&r.to==n.to))&&(t.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],pm=ue.define({combine:t=>Object.assign({sources:t.map((t=>t.source))},tn(t.map((t=>t.config)),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null},{needsRefresh:(t,e)=>t?e?n=>t(n)||e(n):t:e}))});function mm(t){let e=[];if(t)t:for(let{name:n}of t){for(let t=0;tt.toLowerCase()==r.toLowerCase()))){e.push(r);continue t}}e.push("")}return e}function gm(t,e,n){var r;let i=n?mm(e.actions):[];return Kd("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Kd("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage():e.message),null===(r=e.actions)||void 0===r?void 0:r.map(((n,r)=>{let o=!1,s=r=>{if(r.preventDefault(),o)return;o=!0;let i=nm(t.state.field(lm).diagnostics,e);i&&n.apply(t,i.from,i.to)},{name:a}=n,l=i[r]?a.indexOf(i[r]):-1,h=l<0?a:[a.slice(0,l),Kd("u",a.slice(l,l+1)),a.slice(l+1)];return Kd("button",{type:"button",class:"cm-diagnosticAction",onclick:s,onmousedown:s,"aria-label":` Action: ${a}${l<0?"":` (access key "${i[r]})"`}.`},h)})),e.source&&Kd("div",{class:"cm-diagnosticSource"},e.source))}class vm extends Or{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return Kd("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class ym{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=gm(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class wm{constructor(t){this.view=t,this.items=[];this.list=Kd("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)dm(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:n}=this.items[this.selectedIndex],r=mm(n.actions);for(let i=0;i{for(let e=0;edm(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(lm).selected;if(!t)return-1;for(let e=0;e{let a,l=-1;for(let t=n;tn&&(this.items.splice(n,l-n),r=!0)),e&&a.diagnostic==e.diagnostic?a.dom.hasAttribute("aria-selected")||(a.dom.setAttribute("aria-selected","true"),i=a):a.dom.hasAttribute("aria-selected")&&a.dom.removeAttribute("aria-selected"),n++}));n({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:t,panel:e})=>{t.tope.bottom&&(this.list.scrollTop+=t.bottom-e.bottom)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),r&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;t!=n.dom;)e();t=n.dom.nextSibling}else this.list.insertBefore(n.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=nm(this.view.state.field(lm).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:am.of(e)})}static open(t){return new wm(t)}}function bm(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,')`}function xm(t){return bm(``,'width="6" height="3"')}const km=fs.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:xm("#d11")},".cm-lintRange-warning":{backgroundImage:xm("orange")},".cm-lintRange-info":{backgroundImage:xm("#999")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});const Sm=[lm,fs.decorations.compute([lm],(t=>{let{selected:e,panel:n}=t.field(lm);return e&&n&&e.from!=e.to?Ir.set([hm.range(e.from,e.to)]):Ir.none})),function(t,e={}){let n=We.define(),r=ye.define({create:()=>null,update(t,r){if(t&&(e.hideOnChange&&(r.docChanged||r.selection)||e.hideOn&&e.hideOn(r,t)))return null;if(t&&r.docChanged){let e=r.changes.mapPos(t.pos,-1,Qt.TrackDel);if(null==e)return null;let n=Object.assign(Object.create(null),t);n.pos=e,null!=t.end&&(n.end=r.changes.mapPos(t.end)),t=n}for(let e of r.effects)e.is(n)&&(t=e.value),e.is(Ea)&&(t=null);return t},provide:t=>ya.from(t)});return[r,oi.define((i=>new xa(i,t,r,n,e.hoverTime||300))),ba]}(cm,{hideOn:rm}),km];const Em=(()=>[Ga(),Qa,Js(),Ou(),yc(),Rs(),[Vs,Us],Ze.allowMultipleSelections.of(!0),Ze.transactionFilter.of((t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let n=t.newDoc,{head:r}=t.newSelection.main,i=n.lineAt(r);if(r>i.from+200)return t;let o=n.sliceString(i.from,r);if(!e.some((t=>t.test(o))))return t;let{state:s}=t,a=-1,l=[];for(let{head:t}of s.selection.ranges){let e=s.doc.lineAt(t);if(e.from==a)continue;a=e.from;let n=Uh(s,e.from);if(null==n)continue;let r=/^\s*/.exec(e.text)[0],i=Vh(s,n);r!=i&&l.push({from:e.from,to:e.from+r.length,insert:i})}return l.length?[t,{changes:l,sequential:!0}]:t})),Ec(Tc,{fallback:!0}),Lc(),[Vp,Bp],Jp(),sa(),ha(),na,df(),bs.of([...Up,...qd,...qf,...Ku,...uc,...Qp,...fm])])(),Cm=document.getElementById("settings"),Am=document.getElementById("code-wrapper");let Tm=()=>{};const Mm=localStorage.getItem("source")||"",_m=new fs({doc:Mm,extensions:[Em,bs.of([Xd]),fs.updateListener.of((t=>{Tm(t)}))],parent:Am}),Dm=document.getElementById("toggle-config"),Om=document.getElementById("compile"),Pm=document.getElementById("run-all"),Im=document.getElementById("run-statement"),Rm=document.getElementById("run-instruction"),Nm=document.getElementById("undo-statement"),Lm=document.getElementById("undo-instruction"),Bm=document.getElementById("reset"),Fm=document.getElementById("log"),zm=document.getElementById("current-line"),Hm=document.getElementById("mem-table"),Wm=document.getElementById("instruction-table"),Vm=document.getElementById("register-table"),Um=document.getElementById("variables-table"),jm=document.getElementById("reset-modal"),$m=document.getElementById("no-reset"),qm=document.getElementById("reset2"),Xm=document.getElementById("close-reset-modal");let Km=()=>{};const Gm=document.getElementById("input"),Ym=document.getElementById("input-btn"),Jm=document.getElementById("output"),Qm=document.getElementById("compile-resets"),Zm=document.getElementById("kw-if"),tg=document.getElementById("kw-else"),eg=document.getElementById("kw-while"),ng=document.getElementById("kw-goto"),rg=document.getElementById("kw-write"),ig=document.getElementById("kw-read"),og=document.getElementById("kw-true"),sg=document.getElementById("kw-false"),ag=new class extends T{constructor(t){super(),this.size=t,this.data=new Uint8Array(t)}reset(){for(var t=0;t>=8n,this.data[r]=Number(t),this.emit("writeByte",r,t)}this.emit("write",t,n)}read(t){let e=0n;for(var n=0;n<8;++n){e=BigInt(this.data[t+n])<=this.program.instructions.length}checkForProgram(t){if(!t)throw new Error("Attempted to run program but no program set.")}reset(){for(;!this.stack.isEmpty();)this.stack.pop()}async runProgram(){for(this.checkForProgram(this.program);!this.isDone();)await this.runOneInstruction()}async runOneInstruction(){this.checkForProgram(this.program);const{instructions:t}=this.program;if(!this.isDone()){const e=t[Number(this.pc)];await this.runInstruction(e)}}async runInstruction(t){this.checkForProgram(this.program);const e=t.op();let n=this.instructionMap[e];n||(console.log("Handler not defined for instruction ",t.mnemonic()),n=I);const r=new n(this,t.operands());await this.stack.push(r)}async runOneStatement(){this.checkForProgram(this.program);do{await this.runOneInstruction()}while(!this.instructionIsBoundary[Number(this.pc)]&&!this.isDone())}undoOneInstruction(){this.checkForProgram(this.program),this.stack.isEmpty()||this.stack.pop()}undoOneStatement(){this.checkForProgram(this.program);do{this.undoOneInstruction()}while(!this.instructionIsBoundary[Number(this.pc)])}wrapExecution(t){return e=>new t(this,e)}setPc(t){this.pc=t,this.emit("updatePc",t)}getPc(){return this.pc}setX(t){this.x=t,this.emit("updateX",t)}getX(){return this.x}incPc(){this.setPc(this.pc+1n)}decPc(){this.setPc(this.pc-1n)}}(ag,lg,hg);window.mem=ag,window.cpu=cg,window.input=lg,window.output=hg,new class{constructor(t,e){this.el=e,this.sourceLines=[],this.header=document.createElement("SPAN"),this.header.textContent="Nenhum programa.",this.el.append(this.header),t.on("loadedProgram",this.loadProgram.bind(this)),t.on("updatePc",this.updateLine.bind(this))}formatLine(t){return`Linha da próxima instrução: ${t}`}loadProgram(t){this.sourceLines=t.metadata.sourceLines;const e=this.sourceLines[0];this.header.textContent=this.formatLine(e)}updateLine(t){if(t>=this.sourceLines.length)return void(this.header.textContent="Finalizado.");const e=this.sourceLines[Number(t)];this.header.textContent=this.formatLine(e)}}(cg,zm),new class{constructor(t,e){this.el=e,this.rows=new Map;const n=t.getMemory();this.maxAddr=n.getSize(),this.variableBytes=new Map,this.init(),n.on("reset",this.clear.bind(this)),n.on("writeByte",this.write.bind(this)),t.on("loadedProgram",this.addVariables.bind(this))}init(){const t=document.createElement("TR"),e=document.createElement("TH");e.textContent="Variável";const n=document.createElement("TH");n.textContent="Endereço";const r=document.createElement("TH");r.textContent="Conteúdo",t.append(e,n,r),this.el.append(t)}clear(){for(const[t,e]of this.rows)this.el.removeChild(e);this.rows.clear()}write(t,e){this.updateRow(t,e)}updateRow(t,e){let n=this.rows.get(t);const r=document.createElement("TR"),i=document.createElement("TD");if(this.variableBytes.has(t)){const e=this.variableBytes.get(t);i.textContent=String(e.name)}const o=document.createElement("TD");o.textContent=String(t);const s=document.createElement("TD");s.textContent=String(e),r.append(i,o,s),n?n.replaceWith(r):this.positionRow(t,r),this.rows.set(t,r)}positionRow(t,e){if(0===this.rows.size)return void this.el.append(e);let n=t;for(;n>=0&&!this.rows.has(n);)--n;let r=t;for(;r<=this.maxAddr&&!this.rows.has(r);)++r;(n<0?1/0:t-n)<(r>this.maxAddr?1/0:r-t)?this.rows.get(n).after(e):this.rows.get(r).before(e)}addVariables(t){this.variableBytes.clear();const e=t.metadata.variables.values();for(const t of e){const e=Number(t.address);for(var n=e;n{const{parser:e,compiler:n,tokiwen:r}=t;function i(){const t=_m.state.doc.toString(),r=e.parse(t),i=n.compile(r.get()),o=cg.getProgram();o&&o.delete(),cg.setProgram(i),Fm.textContent="",r.delete()}function o(){cg.getProgram()||i()}function s(){cg.reset(),ag.reset()}async function a(t){Om.disabled=!0,Pm.disabled=!0,Im.disabled=!0,Rm.disabled=!0,Nm.disabled=!0,Lm.disabled=!0,Bm.disabled=!0;try{await t()}finally{Om.disabled=!1,Pm.disabled=!1,Im.disabled=!1,Rm.disabled=!1,Nm.disabled=!1,Lm.disabled=!1,Bm.disabled=!1}}function l(){const t=new Promise((t=>{Km=t}));return jm.style.display="block",t}function h(){ug&&(Cm.style.display="block"),setTimeout((()=>{Cm.style.height=ug?"83vh":"0"}),0),setTimeout((()=>{ug||(Cm.style.display="none")}),300)}function c(){jm.style.display="none"}window.parser=e,window.compiler=n,window.tokiwen=r,Tm=t=>{t.docChanged&&(cg.getProgram()&&(Fm.textContent="O código foi alterado desde a última compilação."),localStorage.setItem("source",t.state.doc.toString()))},Om.addEventListener("click",(()=>{try{Qm.checked&&s(),i()}catch(t){const e=t;throw Fm.textContent=e.message,t}})),Pm.addEventListener("click",(async()=>{try{if(o(),cg.isDone()){if(null===await l())return}await a((async()=>{await cg.runProgram()}))}catch(t){const e=t;throw Fm.textContent=e.message,t}})),Im.addEventListener("click",(async()=>{try{if(o(),cg.isDone()){if(null===await l())return}await a((async()=>{await cg.runOneStatement()}))}catch(t){const e=t;throw Fm.textContent=e.message,t}})),Rm.addEventListener("click",(async()=>{try{if(o(),cg.isDone()){if(null===await l())return}await a((async()=>{await cg.runOneInstruction()}))}catch(t){const e=t;throw Fm.textContent=e.message,t}})),Nm.addEventListener("click",(()=>{cg.getProgram()&&cg.undoOneStatement()})),Lm.addEventListener("click",(()=>{cg.getProgram()&&cg.undoOneInstruction()})),Bm.addEventListener("click",(()=>{try{s()}catch(t){const e=t;throw Fm.textContent=e.message,t}})),lg.on("waiting",(()=>{Ym.disabled=!1,Fm.textContent="Aguardando input."})),Ym.addEventListener("click",(()=>{Fm.textContent="";const t=parseInt(Gm.value);if(Number.isNaN(t)){const t="Há algo que não é um número no campo de input. Somente números inteiros são suportados no momento.";throw Fm.textContent=t,new Error(t)}const e=BigInt(t);lg.write(e),Ym.disabled=!0})),hg.on("buffered",(async()=>{Jm.value=String(await hg.read())})),e.setKeywordIf(Zm.value),e.setKeywordElse(tg.value),e.setKeywordWhile(eg.value),e.setKeywordGoto(ng.value),e.setKeywordWrite(rg.value),e.setKeywordRead(ig.value),e.setKeywordTrue(og.value),e.setKeywordFalse(sg.value),Zm.addEventListener("change",(()=>{e.setKeywordIf(Zm.value)})),tg.addEventListener("change",(()=>{e.setKeywordElse(tg.value)})),eg.addEventListener("change",(()=>{e.setKeywordWhile(eg.value)})),ng.addEventListener("change",(()=>{e.setKeywordGoto(ng.value)})),rg.addEventListener("change",(()=>{e.setKeywordWrite(rg.value)})),ig.addEventListener("change",(()=>{e.setKeywordRead(ig.value)})),og.addEventListener("change",(()=>{e.setKeywordTrue(og.value)})),sg.addEventListener("change",(()=>{e.setKeywordFalse(sg.value)})),h(),Dm.addEventListener("click",(()=>{ug=!ug,h()})),$m.addEventListener("click",(()=>{c(),Km(!1)})),qm.addEventListener("click",(()=>{try{s(),c(),Km(!0)}catch(t){const e=t;throw Fm.textContent=e.message,t}})),Xm.addEventListener("click",(()=>{Km(null),c()}))}));