texlite 0.9.3 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/OPERATIONS.md +9 -7
  2. package/README.md +64 -40
  3. package/README.zh-CN.md +56 -34
  4. package/dist/client/assets/{AdminUsers-huwQK7Ly.js → AdminUsers-C7oU_1Y_.js} +1 -1
  5. package/dist/client/assets/{CitationLibraryDialog-C5C3sPdw.js → CitationLibraryDialog-CU2b0xtm.js} +1 -1
  6. package/dist/client/assets/Dashboard-BB4RO4x2.js +2 -0
  7. package/dist/client/assets/{GitDialog-BI7QIMsh.js → GitDialog-C2Np1i8v.js} +1 -1
  8. package/dist/client/assets/{HistoryDialog-DA7O9aF2.js → HistoryDialog-CdoYeLyX.js} +1 -1
  9. package/dist/client/assets/LatexEditor-Dmy6_gqt.js +138 -0
  10. package/dist/client/assets/{PdfPreview-mO9WS01q.js → PdfPreview-fDxKh6hP.js} +1 -1
  11. package/dist/client/assets/{ProjectIconPickerDialog-B0q_r5dX.js → ProjectIconPickerDialog-CsjMKq7h.js} +1 -1
  12. package/dist/client/assets/{ProjectNavigationDialogs-DwWYbB1A.js → ProjectNavigationDialogs-_JY0yVob.js} +1 -1
  13. package/dist/client/assets/{ProjectSettings-BpPFgdoj.js → ProjectSettings-DXGA-lmB.js} +1 -1
  14. package/dist/client/assets/ProjectWorkspace-mCYjyc6e.js +32 -0
  15. package/dist/client/assets/{SelectionHistoryDialog-pWMI5izu.js → SelectionHistoryDialog-D8CeqjLD.js} +1 -1
  16. package/dist/client/assets/{SystemMetricsDialog-BmlO7oNg.js → SystemMetricsDialog-BZx7ZMQt.js} +1 -1
  17. package/dist/client/assets/{TagManagementDialog-h4Ves4FR.js → TagManagementDialog-4R1Gs43j.js} +1 -1
  18. package/dist/client/assets/{WordCountDialog-DlBSP4y7.js → WordCountDialog-C-MCscAu.js} +1 -1
  19. package/dist/client/assets/check-Jf8WBxDX.js +1 -0
  20. package/dist/client/assets/{editor-DZS7-wrd.js → editor-B9HNwtsd.js} +1 -1
  21. package/dist/client/assets/hard-drive-Bsk-RETn.js +1 -0
  22. package/dist/client/assets/{index-teah8iB2.js → index-B6rP7QsM.js} +4 -4
  23. package/dist/client/assets/{index-i5IY_PMw.js → index-Csp5J5aI.js} +1 -1
  24. package/dist/client/assets/index-DGZNAyxW.css +1 -0
  25. package/dist/client/assets/{key-round-D8sCqL2b.js → key-round-DqptHHKC.js} +1 -1
  26. package/dist/client/assets/{minimize-2-6tf519Ts.js → minimize-2-92UqFWI9.js} +1 -1
  27. package/dist/client/assets/{minus-CqvESp9M.js → minus-bx4ZLZnb.js} +1 -1
  28. package/dist/client/assets/{plus-DIrweesj.js → plus-DQg_bV50.js} +1 -1
  29. package/dist/client/assets/{refresh-cw-BDcwKu_d.js → refresh-cw-BoMEkk5J.js} +1 -1
  30. package/dist/client/assets/{search-C9_Jyrnx.js → search-UZspmceH.js} +1 -1
  31. package/dist/client/assets/{sigma-p9-fBP0d.js → sigma-C0IvFdKV.js} +1 -1
  32. package/dist/client/assets/{spellCheck-Y0RlmXbl.js → spellCheck-DyKIHf5C.js} +1 -1
  33. package/dist/client/assets/{tags-DjF3z21M.js → tags-BTUtvaAc.js} +1 -1
  34. package/dist/client/assets/{type-CNrDJnzR.js → type-XvvfEJRs.js} +1 -1
  35. package/dist/client/assets/{user-plus-C7exNawX.js → user-plus-Chr9T97G.js} +1 -1
  36. package/dist/client/assets/x-DlFXD9Vl.js +1 -0
  37. package/dist/client/index.html +2 -2
  38. package/dist/client/pdf-download.svg +2 -0
  39. package/dist/client/pdf-file.svg +19 -0
  40. package/dist/client/tex-file.svg +7 -0
  41. package/dist/server/cli.js +5 -2
  42. package/dist/server/routes/projectFiles.js +6 -1
  43. package/package.json +4 -3
  44. package/dist/client/assets/Dashboard-DtHSc55D.js +0 -2
  45. package/dist/client/assets/LatexEditor-BYWWx5Km.js +0 -138
  46. package/dist/client/assets/ProjectWorkspace-CI2zKon5.js +0 -32
  47. package/dist/client/assets/check-BAdi_Lxq.js +0 -1
  48. package/dist/client/assets/hard-drive-DP2OHKMC.js +0 -1
  49. package/dist/client/assets/index-CBrIrzgg.css +0 -1
  50. package/dist/client/assets/x-BEVz0wdw.js +0 -1
@@ -11,4 +11,4 @@ let Zs=[],Ma=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,
11
11
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Br),Kd={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Ls=null;function Ud(){var s;if(Ls==null&&typeof document<"u"&&document.body){let e=document.body.style;Ls=((s=e.tabSize)!==null&&s!==void 0?s:e.MozTabSize)!=null}return Ls||!1}const On=T.define({combine(s){let e=ft(s,{render:null,specialChars:qd,addSpecialChars:null});return(e.replaceTabs=!Ud())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Br)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Br)),e}});function vb(s={}){return[On.of(s),jd()]}let Tl=null;function jd(){return Tl||(Tl=te.fromClass(class{constructor(s){this.view=s,this.decorations=R.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(s.state.facet(On)),this.decorations=this.decorator.createDeco(s)}makeDecorator(s){return new $d({regexp:s.specialChars,decoration:(e,t,i)=>{let{doc:n}=t.state,r=xe(e[0],0);if(r==9){let o=n.lineAt(i),l=t.state.tabSize,a=Ki(o.text,l,i-o.from);return R.replace({widget:new Jd((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=R.replace({widget:new Yd(s,r)}))},boundary:s.replaceTabs?void 0:/[^]/})}update(s){let e=s.state.facet(On);s.startState.facet(On)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(s.view)):this.decorations=this.decorator.updateDeco(s,this.decorations)}},{decorations:s=>s.decorations}))}const Gd="•";function _d(s){return s>=32?Gd:s==10?"␤":String.fromCharCode(9216+s)}class Yd extends nt{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=_d(this.code),i=e.state.phrase("Control character")+" "+(Kd[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,t);if(n)return n;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Jd extends nt{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function Sb(){return Qd}const Xd=R.line({class:"cm-activeLine"}),Qd=te.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.docChanged||s.selectionSet)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let e=-1,t=[];for(let i of s.state.selection.ranges){let n=s.lineBlockAt(i.head);n.from>e&&(t.push(Xd.range(n.from)),e=n.from)}return R.set(t)}},{decorations:s=>s.decorations}),fn="-10000px";class $h{constructor(e,t,i,n){this.facet=t,this.createTooltipView=i,this.removeTooltipView=n,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(e,t){var i;let n=e.state.facet(this.facet),r=n.filter(a=>a);if(n===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let h=r[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==h.create&&(c=f)}if(c<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let f=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function Zd(s){let e=s.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Es=T.define({combine:s=>{var e,t,i;return{position:A.ios?"absolute":((e=s.find(n=>n.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=s.find(n=>n.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Zd}}}),Dl=new WeakMap,ao=te.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=s.state.facet(Es);this.position=e.position,this.parent=e.parent,this.classes=s.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new $h(s,ho,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),s.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let s of this.manager.tooltipViews)this.intersectionObserver.observe(s.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(s){s.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(s,this.above);e&&this.observeIntersection();let t=e||s.geometryChanged,i=s.state.facet(Es);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(s,e){let t=s.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),s.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let n=document.createElement("div");n.className="cm-tooltip-arrow",t.dom.appendChild(n)}return t.dom.style.position=this.position,t.dom.style.top=fn,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var s,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(s=i.destroy)===null||s===void 0||s.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:r}=this.manager.tooltipViews[0];if(A.safari){let o=r.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else t=!!r.offsetParent&&r.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let r=this.parent.getBoundingClientRect();r.width&&r.height&&(s=r.width/this.parent.offsetWidth,e=r.height/this.parent.offsetHeight)}else({scaleX:s,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),n=no(this.view);return{visible:{left:i.left+n.left,top:i.top+n.top,right:i.right-n.right,bottom:i.bottom-n.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((r,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(r.pos):this.view.coordsAtPos(r.pos)}),size:this.manager.tooltipViews.map(({dom:r})=>r.getBoundingClientRect()),space:this.view.state.facet(Es).tooltipSpace(this.view),scaleX:s,scaleY:e,makeAbsolute:t}}writeMeasure(s){var e;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:n,scaleY:r}=s,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=s.pos[l],u=s.size[l];if(!f||a.clip!==!1&&(f.bottom<=Math.max(t.top,i.top)||f.top>=Math.min(t.bottom,i.bottom)||f.right<Math.max(t.left,i.left)-.1||f.left>Math.min(t.right,i.right)+.1)){c.style.top=fn;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=Dl.get(h))!==null&&e!==void 0?e:u.bottom-u.top,b=h.offset||tp,x=this.view.textDirection==j.LTR,k=u.width>i.right-i.left?x?i.left:i.right-u.width:x?Math.max(i.left,Math.min(f.left-(d?14:0)+b.x,i.right-m)):Math.min(Math.max(i.left,f.left-m+(d?14:0)-b.x),i.right-m),D=this.above[l];!a.strictSide&&(D?f.top-g-p-b.y<i.top:f.bottom+g+p+b.y>i.bottom)&&D==i.bottom-f.bottom>f.top-i.top&&(D=this.above[l]=!D);let w=(D?f.top-i.top:i.bottom-f.bottom)-p;if(w<g&&h.resize!==!1){if(w<this.view.defaultLineHeight){c.style.top=fn;continue}Dl.set(h,g),c.style.height=(g=w)/r+"px"}else c.style.height&&(c.style.height="");let v=D?f.top-g-p-b.y:f.bottom+p+b.y,S=k+m;if(h.overlap!==!0)for(let L of o)L.left<S&&L.right>k&&L.top<v+g&&L.bottom>v&&(v=D?L.top-g-2-p:L.bottom+p+2);if(this.position=="absolute"?(c.style.top=(v-s.parent.top)/r+"px",Ol(c,(k-s.parent.left)/n)):(c.style.top=v/r+"px",Ol(c,k/n)),d){let L=f.left+(x?b.x:-b.x)-(k+14-7);d.style.left=L/n+"px"}h.overlap!==!0&&o.push({left:k,top:v,right:S,bottom:v+g}),c.classList.toggle("cm-tooltip-above",D),c.classList.toggle("cm-tooltip-below",!D),h.positioned&&h.positioned(s.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 s of this.manager.tooltipViews)s.dom.style.top=fn}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Ol(s,e){let t=parseInt(s.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(s.style.left=e+"px")}const ep=O.baseTheme({".cm-tooltip":{zIndex:500,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"}}}),tp={x:0,y:0},ho=T.define({enables:[ao,ep]}),qn=T.define({combine:s=>s.reduce((e,t)=>e.concat(t),[])});class fs{static create(e){return new fs(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new $h(e,qn,(t,i)=>this.createHostedView(t,i),t=>t.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let n=i[e];if(n!==void 0){if(t===void 0)t=n;else if(t!==n)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const ip=ho.compute([qn],s=>{let e=s.facet(qn);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var i;return(i=t.end)!==null&&i!==void 0?i:t.pos})),create:fs.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),np=T.define();class sp{constructor(e,t,i,n,r,o){this.view=e,this.source=t,this.field=i,this.locked=n,this.setHover=r,this.hoverTime=o,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(e){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.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,i=e.docView.tile.nearest(t.target);if(!i)return;let n,r=1;if(i.isWidget())n=i.posAtStart;else{if(n=e.posAtCoords(t),n==null)return;let o=e.coordsAtPos(n);if(!o||t.y<o.top||t.y>o.bottom||t.x<o.left-e.defaultCharacterWidth||t.x>o.right+e.defaultCharacterWidth)return;let l=e.bidiSpans(e.state.doc.lineAt(n)).find(h=>h.from<=n&&h.to>=n),a=l&&l.dir==j.RTL?-1:1;r=t.x<o.left?-a:a}this.activateHover(e,n,r)}activateHover(e,t,i,n){let r=this.source(e,t,i),o=l=>{if(l&&!(Array.isArray(l)&&!l.length)){let a=Array.isArray(l)?l:[l];n&&this.locked.set(a,n),e.dispatch({effects:this.setHover.of(a)})}};if(r&&"then"in r){let l=this.pending={pos:t};r.then(a=>{this.pending==l&&(this.pending=null,o(a))},a=>me(e.state,a,"hover tooltip"))}else o(r)}get tooltip(){let e=this.view.plugin(ao),t=e?e.manager.tooltips.findIndex(i=>i.create==fs.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&!this.locked.has(n)&&r&&!rp(r.dom,e)||this.pending){let{pos:o}=n[0]||this.pending,l=(i=(t=n[0])===null||t===void 0?void 0:t.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!op(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length&&!this.locked.has(t)){let{tooltip:i}=this;i&&i.dom.contains(e.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t);let{active:n}=this;n.length&&!this.locked.has(n)&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const un=4;function rp(s,e){let{left:t,right:i,top:n,bottom:r}=s.getBoundingClientRect(),o;if(o=s.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();n=Math.min(l.top,n),r=Math.max(l.bottom,r)}return e.clientX>=t-un&&e.clientX<=i+un&&e.clientY>=n-un&&e.clientY<=r+un}function op(s,e,t,i,n,r){let o=s.scrollDOM.getBoundingClientRect(),l=s.documentTop+s.documentPadding.top+s.contentHeight;if(o.left>i||o.right<i||o.top>n||Math.min(o.bottom,l)<n)return!1;let a=s.posAtCoords({x:i,y:n},!1);return a>=e&&a<=t}function lp(s,e={}){let t=P.define(),i=new WeakMap,n=fe.define({create(){return[]},update(o,l){let a=i.get(o);if(o.length&&(e.hideOnChange&&(l.docChanged||l.selection)?o=[]:a&&a(l)?o=[]:e.hideOn&&(o=o.filter(h=>!e.hideOn(l,h)))),l.docChanged&&o.length){let h=[];for(let c of o){let f=l.changes.mapPos(c.pos,-1,le.TrackDel);if(f!=null){let u=Object.assign(Object.create(null),c);u.pos=f,u.end!=null&&(u.end=l.changes.mapPos(u.end)),h.push(u)}}o=h}for(let h of l.effects)h.is(t)&&(o=h.value,a=void 0),(h.is(ap)&&!h.value||h.value==n)&&(o=[]);return o.length&&a&&i.set(o,a),o},provide:o=>qn.from(o)});const r=te.define(o=>new sp(o,s,n,i,t,e.hoverTime||300));return{active:n,extension:[n,r,np.of(r),ip]}}function qh(s,e){let t=s.plugin(ao);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const ap=P.define(),Bl=T.define({combine(s){let e,t;for(let i of s)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Kh(s,e){let t=s.plugin(Uh),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Uh=te.fromClass(class{constructor(s){this.input=s.state.facet(Ei),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(s));let e=s.state.facet(Bl);this.top=new dn(s,!0,e.topContainer),this.bottom=new dn(s,!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(s){let e=s.state.facet(Bl);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new dn(s.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new dn(s.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=s.state.facet(Ei);if(t!=this.input){let i=t.filter(a=>a),n=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(s.view),l.push(c)):(c=this.panels[h],c.update&&c.update(s)),n.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>O.scrollMargins.of(e=>{let t=e.plugin(s);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class dn{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Pl(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Pl(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Pl(s){let e=s.nextSibling;return s.remove(),e}const Ei=T.define({enables:Uh});function hp(s,e){let t,i=new Promise(o=>t=o),n=o=>cp(o,e,t);s.state.field(Is,!1)?s.dispatch({effects:jh.of(n)}):s.dispatch({effects:P.appendConfig.of(Is.init(()=>[n]))});let r=Gh.of(n);return{close:r,result:i.then(o=>((s.win.queueMicrotask||(a=>s.win.setTimeout(a,10)))(()=>{s.state.field(Is).indexOf(n)>-1&&s.dispatch({effects:r})}),o))}}const Is=fe.define({create(){return[]},update(s,e){for(let t of e.effects)t.is(jh)?s=[t.value].concat(s):t.is(Gh)&&(s=s.filter(i=>i!=t.value));return s},provide:s=>Ei.computeN([s],e=>e.field(s))}),jh=P.define(),Gh=P.define();function cp(s,e,t){let i=e.content?e.content(s,()=>o(null)):null;if(!i){if(i=$("form"),e.input){let l=$("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild($("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild($("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let n=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<n.length;l++){let a=n[l];a.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=$("div",i,$("button",{onclick:()=>o(null),"aria-label":s.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(r.className=e.class),r.classList.add("cm-dialog");function o(l){r.contains(r.ownerDocument.activeElement)&&s.focus(),t(l)}return{dom:r,top:e.top,mount:()=>{if(e.focus){let l;typeof e.focus=="string"?l=i.querySelector(e.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class vt extends yt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}vt.prototype.elementClass="";vt.prototype.toDOM=void 0;vt.prototype.mapMode=le.TrackBefore;vt.prototype.startSide=vt.prototype.endSide=-1;vt.prototype.point=!0;const Ns=T.define(),fp=T.define(),up={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>N.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Mi=T.define();function dp(s){return[_h(),Mi.of({...up,...s})]}const Rl=T.define({combine:s=>s.some(e=>e)});function _h(s){return[pp]}const pp=te.fromClass(class{constructor(s){this.view=s,this.domAfter=null,this.prevViewport=s.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=s.state.facet(Mi).map(e=>new El(s,e)),this.fixed=!s.state.facet(Rl);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),s.scrollDOM.insertBefore(this.dom,s.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(s){if(this.updateGutters(s)){let e=this.prevViewport,t=s.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(s.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(Rl)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=s.view.viewport}syncGutters(s){let e=this.dom.nextSibling;s&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=N.iter(this.view.state.facet(Ns),this.view.viewport.from),i=[],n=this.gutters.map(r=>new mp(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==ae.Text&&o){Pr(t,i,l.from);for(let a of n)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of n)a.widget(this.view,l)}else if(r.type==ae.Text){Pr(t,i,r.from);for(let o of n)o.line(this.view,r,i)}else if(r.widget)for(let o of n)o.widget(this.view,r);for(let r of n)r.finish();s&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(s){let e=s.startState.facet(Mi),t=s.state.facet(Mi),i=s.docChanged||s.heightChanged||s.viewportChanged||!N.eq(s.startState.facet(Ns),s.state.facet(Ns),s.view.viewport.from,s.view.viewport.to);if(e==t)for(let n of this.gutters)n.update(s)&&(i=!0);else{i=!0;let n=[];for(let r of t){let o=e.indexOf(r);o<0?n.push(new El(this.view,r)):(this.gutters[o].update(s),n.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),n.indexOf(r)<0&&r.destroy();for(let r of n)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=n}return i}destroy(){for(let s of this.gutters)s.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:s=>O.scrollMargins.of(e=>{let t=e.plugin(s);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,n=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==j.LTR?{left:i,right:n}:{right:i,left:n}})});function Ll(s){return Array.isArray(s)?s:[s]}function Pr(s,e,t){for(;s.value&&s.from<=t;)s.from==t&&e.push(s.value),s.next()}class mp{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=N.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:n}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==n.elements.length){let l=new Yh(e,o,r,i);n.elements.push(l),n.dom.appendChild(l.dom)}else n.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let n=[];Pr(this.cursor,n,t.from),i.length&&(n=n.concat(i));let r=this.gutter.config.lineMarker(e,t,n);r&&n.unshift(r);let o=this.gutter;n.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,n)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),n=i?[i]:null;for(let r of e.state.facet(fp)){let o=r(e,t.widget,t);o&&(n||(n=[])).push(o)}n&&this.addElement(e,t,n)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class El{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,n=>{let r=n.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=n.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,n)&&n.preventDefault()});this.markers=Ll(t.markers(e)),t.initialSpacer&&(this.spacer=new Yh(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=Ll(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let n=this.config.updateSpacer(this.spacer.markers[0],e);n!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[n])}let i=e.view.viewport;return!N.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Yh{constructor(e,t,i,n){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,n)}update(e,t,i,n){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),gp(this.markers,n)||this.setMarkers(e,n)}setMarkers(e,t){let i="cm-gutterElement",n=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(n);let f=n.nextSibling;n.remove(),n=f}}if(!a)break;a.toDOM&&(h?n=n.nextSibling:this.dom.insertBefore(a.toDOM(e),n)),h&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function gp(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(!s[t].compare(e[t]))return!1;return!0}const bp=T.define(),yp=T.define(),Jt=T.define({combine(s){return ft(s,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let n in t){let r=i[n],o=t[n];i[n]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}});class Fs extends vt{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Ws(s,e){return s.state.facet(Jt).formatNumber(e,s.state)}const xp=Mi.compute([Jt],s=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(bp)},lineMarker(e,t,i){return i.some(n=>n.toDOM)?null:new Fs(Ws(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let n of e.state.facet(yp)){let r=n(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Jt)!=e.state.facet(Jt),initialSpacer(e){return new Fs(Ws(e,Il(e.state.doc.lines)))},updateSpacer(e,t){let i=Ws(t.view,Il(t.view.state.doc.lines));return i==e.number?e:new Fs(i)},domEventHandlers:s.facet(Jt).domEventHandlers,side:"before"}));function Cb(s={}){return[Jt.of(s),_h(),xp]}function Il(s){let e=9;for(;e<s;)e=e*10+9;return e}const Jh=1024;let kp=0;class Hs{constructor(e,t){this.from=e,this.to=t}}class E{constructor(e={}){this.id=kp++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=ye.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}E.closedBy=new E({deserialize:s=>s.split(" ")});E.openedBy=new E({deserialize:s=>s.split(" ")});E.group=new E({deserialize:s=>s.split(" ")});E.isolate=new E({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});E.contextHash=new E({perNode:!0});E.lookAhead=new E({perNode:!0});E.mounted=new E({perNode:!0});class Ti{constructor(e,t,i,n=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=n}static get(e){return e&&e.props&&e.props[E.mounted.id]}}const wp=Object.create(null);class ye{constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):wp,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new ye(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(n)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return n}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(E.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return i=>{for(let n=i.prop(E.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}ye.none=new ye("",Object.create(null),0,8);class us{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let r of e){let o=r(i);if(o){n||(n=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in n&&(l=a.combine(n[a.id],l)),n[a.id]=l}}t.push(n?new ye(i.name,n,i.id,i.flags):i)}return new us(t)}}const pn=new WeakMap,Nl=new WeakMap;var Y;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays",s[s.EnterBracketed=16]="EnterBracketed"})(Y||(Y={}));class q{constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=Ti.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let n=i.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new Lr(this.topNode,e)}cursorAt(e,t=0,i=0){let n=pn.get(this)||this.topNode,r=new Lr(n);return r.moveTo(e,t),pn.set(this,r._tree),r}get topNode(){return new Ee(this,0,0,null)}resolve(e,t=0){let i=Ii(pn.get(this)||this.topNode,e,t,!1);return pn.set(this,i),i}resolveInner(e,t=0){let i=Ii(Nl.get(this)||this.topNode,e,t,!0);return Nl.set(this,i),i}resolveStack(e,t=0){return Cp(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,o=e.mode||0,l=(o&Y.IncludeAnonymous)>0;for(let a=this.cursor(o|Y.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=n&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:uo(ye.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new q(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new q(ye.none,t,i,n)))}static build(e){return Ap(e)}}q.empty=new q(ye.none,[],[],0);class co{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new co(this.buffer,this.index)}}class St{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ye.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,n,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Xh(r,n,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let n=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=n[l++],r[a++]=n[l++]-i;let h=r[a++]=n[l++]-i;r[a++]=n[l++]-e,o=Math.max(o,h)}return new St(r,o,this.set)}}function Xh(s,e,t,i){switch(s){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Ii(s,e,t,i){for(var n;s.from==s.to||(t<1?s.from>=e:s.from>e)||(t>-1?s.to<=e:s.to<e);){let o=!i&&s instanceof Ee&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:Y.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof Ee&&o.index<0&&((n=l.enter(e,t,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(e,t,r);if(!o)return s;s=o}}class Qh{cursor(e=0){return new Lr(this,e)}getChild(e,t=null,i=null){let n=Fl(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Fl(this,e,t,i)}resolve(e,t=0){return Ii(this,e,t,!1)}resolveInner(e,t=0){return Ii(this,e,t,!0)}matchContext(e){return Rr(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(i=t,t=n.prevSibling):t=n}return i}get node(){return this}get next(){return this.parent}}class Ee extends Qh{constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],f=a[e]+o.from,u;if(!(!(r&Y.EnterBracketed&&c instanceof q&&(u=Ti.get(c))&&!u.overlay&&u.bracketed&&i>=f&&i<=f+c.length)&&!Xh(n,i,f,f+c.length))){if(c instanceof St){if(r&Y.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,i-f,n);if(d>-1)return new bt(new vp(o,c,e,f),null,d)}else if(r&Y.IncludeAnonymous||!c.type.isAnonymous||fo(c)){let d;if(!(r&Y.IgnoreMounts)&&(d=Ti.get(c))&&!d.overlay)return new Ee(d.tree,f,e,o);let p=new Ee(c,f,e,o);return r&Y.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,i,n,r)}}}if(r&Y.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let n;if(!(i&Y.IgnoreOverlays)&&(n=Ti.get(this._tree))&&n.overlay){let r=e-this.from,o=i&Y.EnterBracketed&&n.bracketed;for(let{from:l,to:a}of n.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?a>=r:a>r))return new Ee(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Fl(s,e,t,i){let n=s.cursor(),r=[];if(!n.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=n.type.is(t),!n.nextSibling())return r}for(;;){if(i!=null&&n.type.is(i))return r;if(n.type.is(e)&&r.push(n.node),!n.nextSibling())return i==null?r:[]}}function Rr(s,e,t=e.length-1){for(let i=s;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class vp{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class bt extends Qh{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new bt(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&Y.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new bt(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new bt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new bt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let o=i.buffer[this.index+1];e.push(i.slice(n,r,o)),t.push(0)}return new q(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Zh(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof Ee&&t.index<0?null:t.parent,n=s.slice();return i?n[e]=i:n.splice(e,1),new Sp(n,t)}class Sp{constructor(e,t){this.heads=e,this.node=t}get next(){return Zh(this.heads)}}function Cp(s,e,t){let i=s.resolveInner(e,t),n=null;for(let r=i instanceof Ee?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(e,t)),r=o}else{let o=Ti.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new Ee(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(Ii(l,e,t,!1))}}return n?Zh(n):i}class Lr{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~Y.EnterBracketed,e instanceof Ee)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return e?e instanceof Ee?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&Y.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Y.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&Y.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(n.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&Y.IncludeAnonymous||l instanceof St||!l.type.isAnonymous||fo(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new bt(this.buffer,t,this.stack[n]);return this.bufferNode=new bt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&t&&t(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return Rr(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return Rr(this._tree,e,n);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[n]&&e[n]!=o.name)return!1;n--}}return!0}}function fo(s){return s.children.some(e=>e instanceof St||!e.type.isAnonymous||fo(e))}function Ap(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Jh,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new co(t,t.length):t,a=i.types,h=0,c=0;function f(w,v,S,L,F,K){let{id:I,start:B,end:z,size:H}=l,G=c,de=h;if(H<0)if(l.next(),H==-1){let st=r[I];S.push(st),L.push(B-w);return}else if(H==-3){h=I;return}else if(H==-4){c=I;return}else throw new RangeError(`Unrecognized record size: ${H}`);let Se=a[I],$e,se,De=B-w;if(z-B<=n&&(se=g(l.pos-v,F))){let st=new Uint16Array(se.size-se.skip),Oe=l.pos-se.size,qe=st.length;for(;l.pos>Oe;)qe=b(se.start,st,qe);$e=new St(st,z-se.start,i),De=se.start-w}else{let st=l.pos-H;l.next();let Oe=[],qe=[],Tt=I>=o?I:-1,Ut=0,Qi=z;for(;l.pos>st;)Tt>=0&&l.id==Tt&&l.size>=0?(l.end<=Qi-n&&(p(Oe,qe,B,Ut,l.end,Qi,Tt,G,de),Ut=Oe.length,Qi=l.end),l.next()):K>2500?u(B,st,Oe,qe):f(B,st,Oe,qe,Tt,K+1);if(Tt>=0&&Ut>0&&Ut<Oe.length&&p(Oe,qe,B,Ut,B,Qi,Tt,G,de),Oe.reverse(),qe.reverse(),Tt>-1&&Ut>0){let No=d(Se,de);$e=uo(Se,Oe,qe,0,Oe.length,0,z-B,No,No)}else $e=m(Se,Oe,qe,z-B,G-z,de)}S.push($e),L.push(De)}function u(w,v,S,L){let F=[],K=0,I=-1;for(;l.pos>v;){let{id:B,start:z,end:H,size:G}=l;if(G>4)l.next();else{if(I>-1&&z<I)break;I<0&&(I=H-n),F.push(B,z,H),K++,l.next()}}if(K){let B=new Uint16Array(K*4),z=F[F.length-2];for(let H=F.length-3,G=0;H>=0;H-=3)B[G++]=F[H],B[G++]=F[H+1]-z,B[G++]=F[H+2]-z,B[G++]=G;S.push(new St(B,F[2]-z,i)),L.push(z-w)}}function d(w,v){return(S,L,F)=>{let K=0,I=S.length-1,B,z;if(I>=0&&(B=S[I])instanceof q){if(!I&&B.type==w&&B.length==F)return B;(z=B.prop(E.lookAhead))&&(K=L[I]+B.length+z)}return m(w,S,L,F,K,v)}}function p(w,v,S,L,F,K,I,B,z){let H=[],G=[];for(;w.length>L;)H.push(w.pop()),G.push(v.pop()+S-F);w.push(m(i.types[I],H,G,K-F,B-K,z)),v.push(F-S)}function m(w,v,S,L,F,K,I){if(K){let B=[E.contextHash,K];I=I?[B].concat(I):[B]}if(F>25){let B=[E.lookAhead,F];I=I?[B].concat(I):[B]}return new q(w,v,S,L,I)}function g(w,v){let S=l.fork(),L=0,F=0,K=0,I=S.end-n,B={size:0,start:0,skip:0};e:for(let z=S.pos-w;S.pos>z;){let H=S.size;if(S.id==v&&H>=0){B.size=L,B.start=F,B.skip=K,K+=4,L+=4,S.next();continue}let G=S.pos-H;if(H<0||G<z||S.start<I)break;let de=S.id>=o?4:0,Se=S.start;for(S.next();S.pos>G;){if(S.size<0)if(S.size==-3||S.size==-4)de+=4;else break e;else S.id>=o&&(de+=4);S.next()}F=Se,L+=H,K+=de}return(v<0||L==w)&&(B.size=L,B.start=F,B.skip=K),B.size>4?B:void 0}function b(w,v,S){let{id:L,start:F,end:K,size:I}=l;if(l.next(),I>=0&&L<o){let B=S;if(I>4){let z=l.pos-(I-4);for(;l.pos>z;)S=b(w,v,S)}v[--S]=B,v[--S]=K-w,v[--S]=F-w,v[--S]=L}else I==-3?h=L:I==-4&&(c=L);return S}let x=[],k=[];for(;l.pos>0;)f(s.start||0,s.bufferStart||0,x,k,-1,0);let D=(e=s.length)!==null&&e!==void 0?e:x.length?k[0]+x[0].length:0;return new q(a[s.topID],x.reverse(),k.reverse(),D)}const Wl=new WeakMap;function Bn(s,e){if(!s.isAnonymous||e instanceof St||e.type!=s)return 1;let t=Wl.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof q)){t=1;break}t+=Bn(s,i)}Wl.set(e,t)}return t}function uo(s,e,t,i,n,r,o,l,a){let h=0;for(let p=i;p<n;p++)h+=Bn(s,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,m,g,b,x){for(let k=g;k<b;){let D=k,w=m[k],v=Bn(s,p[k]);for(k++;k<b;k++){let S=Bn(s,p[k]);if(v+S>=c)break;v+=S}if(k==D+1){if(v>c){let S=p[D];d(S.children,S.positions,0,S.children.length,m[D]+x);continue}f.push(p[D])}else{let S=m[k-1]+p[k-1].length-w;f.push(uo(s,p,m,D,k,w,S,null,a))}u.push(w+x-r)}}return d(e,t,i,n,0),(l||a)(f,u,o)}class Nt{constructor(e,t,i,n,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let n=[new Nt(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&n.push(r);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=i)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new Nt(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&n.push(u),o.to>f)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return n}}class po{startParse(e,t,i){return typeof e=="string"&&(e=new Mp(e)),i=i?i.length?i.map(n=>new Hs(n.from,n.to)):[new Hs(0,0)]:[new Hs(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let r=n.advance();if(r)return r}}}class Mp{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new E({perNode:!0});let Tp=0;class Be{constructor(e,t,i,n){this.name=e,this.set=t,this.base=i,this.modified=n,this.id=Tp++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof Be&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let n=new Be(i,[],null,[]);if(n.set.push(n),t)for(let r of t.set)n.set.push(r);return n}static defineModifier(e){let t=new Kn(e);return i=>i.modified.indexOf(t)>-1?i:Kn.get(i.base||i,i.modified.concat(t).sort((n,r)=>n.id-r.id))}}let Dp=0;class Kn{constructor(e){this.name=e,this.instances=[],this.id=Dp++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Op(t,l.modified));if(i)return i;let n=[],r=new Be(e.name,n,e,t);for(let l of t)l.instances.push(r);let o=Bp(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(Kn.get(l,a));return r}}function Op(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function Bp(s){let e=[[]];for(let t=0;t<s.length;t++)for(let i=0,n=e.length;i<n;i++)e.push(e[i].concat(s[t]));return e.sort((t,i)=>i.length-t.length)}function Pp(s){let e=Object.create(null);for(let t in s){let i=s[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let r=[],o=2,l=n;for(let f=0;;){if(l=="..."&&f>0&&f+3==n.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+n);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==n.length)break;let d=n[f++];if(f==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(f)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+n);let c=new Ni(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return ec.add(e)}const ec=new E({combine(s,e){let t,i,n;for(;s||e;){if(!s||e&&s.depth>=e.depth?(n=e,e=e.next):(n=s,s=s.next),t&&t.mode==n.mode&&!n.context&&!t.context)continue;let r=new Ni(n.tags,n.mode,n.context);t?t.next=r:i=r,t=r}return i}});class Ni{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Ni.empty=new Ni([],2,null);function tc(s,e){let t=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:n=null}=e||{};return{style:r=>{let o=n;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function Rp(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function Lp(s,e,t,i=0,n=s.length){let r=new Ep(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class Ep{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,n,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=n,c=Ip(e)||Ni.empty,f=Rp(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(n+=(n?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop(E.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(u.tree.type)),m=e.firstChild();for(let g=0,b=l;;g++){let x=g<u.overlay.length?u.overlay[g]:null,k=x?x.from+l:a,D=Math.max(t,b),w=Math.min(i,k);if(D<w&&m)for(;e.from<w&&(this.highlightRange(e,D,w,n,r),this.startSpan(Math.min(w,e.to),h),!(e.to>=k||!e.nextSibling())););if(!x||k>i)break;b=x.to+l,b>t&&(this.highlightRange(d.cursor(),Math.max(t,x.from+l),Math.min(i,b),"",p),this.startSpan(Math.min(i,b),h))}m&&e.parent()}else if(e.firstChild()){u&&(n="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,n,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}}function Ip(s){let e=s.type.prop(ec);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const C=Be.define,mn=C(),ut=C(),Hl=C(ut),Vl=C(ut),dt=C(),gn=C(dt),Vs=C(dt),Ge=C(),Dt=C(Ge),Ue=C(),je=C(),Er=C(),gi=C(Er),bn=C(),M={comment:mn,lineComment:C(mn),blockComment:C(mn),docComment:C(mn),name:ut,variableName:C(ut),typeName:Hl,tagName:C(Hl),propertyName:Vl,attributeName:C(Vl),className:C(ut),labelName:C(ut),namespace:C(ut),macroName:C(ut),literal:dt,string:gn,docString:C(gn),character:C(gn),attributeValue:C(gn),number:Vs,integer:C(Vs),float:C(Vs),bool:C(dt),regexp:C(dt),escape:C(dt),color:C(dt),url:C(dt),keyword:Ue,self:C(Ue),null:C(Ue),atom:C(Ue),unit:C(Ue),modifier:C(Ue),operatorKeyword:C(Ue),controlKeyword:C(Ue),definitionKeyword:C(Ue),moduleKeyword:C(Ue),operator:je,derefOperator:C(je),arithmeticOperator:C(je),logicOperator:C(je),bitwiseOperator:C(je),compareOperator:C(je),updateOperator:C(je),definitionOperator:C(je),typeOperator:C(je),controlOperator:C(je),punctuation:Er,separator:C(Er),bracket:gi,angleBracket:C(gi),squareBracket:C(gi),paren:C(gi),brace:C(gi),content:Ge,heading:Dt,heading1:C(Dt),heading2:C(Dt),heading3:C(Dt),heading4:C(Dt),heading5:C(Dt),heading6:C(Dt),contentSeparator:C(Ge),list:C(Ge),quote:C(Ge),emphasis:C(Ge),strong:C(Ge),link:C(Ge),monospace:C(Ge),strikethrough:C(Ge),inserted:C(),deleted:C(),changed:C(),invalid:C(),meta:bn,documentMeta:C(bn),annotation:C(bn),processingInstruction:C(bn),definition:Be.defineModifier("definition"),constant:Be.defineModifier("constant"),function:Be.defineModifier("function"),standard:Be.defineModifier("standard"),local:Be.defineModifier("local"),special:Be.defineModifier("special")};for(let s in M){let e=M[s];e instanceof Be&&(e.name=s)}tc([{tag:M.link,class:"tok-link"},{tag:M.heading,class:"tok-heading"},{tag:M.emphasis,class:"tok-emphasis"},{tag:M.strong,class:"tok-strong"},{tag:M.keyword,class:"tok-keyword"},{tag:M.atom,class:"tok-atom"},{tag:M.bool,class:"tok-bool"},{tag:M.url,class:"tok-url"},{tag:M.labelName,class:"tok-labelName"},{tag:M.inserted,class:"tok-inserted"},{tag:M.deleted,class:"tok-deleted"},{tag:M.literal,class:"tok-literal"},{tag:M.string,class:"tok-string"},{tag:M.number,class:"tok-number"},{tag:[M.regexp,M.escape,M.special(M.string)],class:"tok-string2"},{tag:M.variableName,class:"tok-variableName"},{tag:M.local(M.variableName),class:"tok-variableName tok-local"},{tag:M.definition(M.variableName),class:"tok-variableName tok-definition"},{tag:M.special(M.variableName),class:"tok-variableName2"},{tag:M.definition(M.propertyName),class:"tok-propertyName tok-definition"},{tag:M.typeName,class:"tok-typeName"},{tag:M.namespace,class:"tok-namespace"},{tag:M.className,class:"tok-className"},{tag:M.macroName,class:"tok-macroName"},{tag:M.propertyName,class:"tok-propertyName"},{tag:M.operator,class:"tok-operator"},{tag:M.comment,class:"tok-comment"},{tag:M.meta,class:"tok-meta"},{tag:M.invalid,class:"tok-invalid"},{tag:M.punctuation,class:"tok-punctuation"}]);var zs;const Lt=new E;function ic(s){return T.define({combine:s?e=>e.concat(s):void 0})}const Np=new E;class Te{constructor(e,t,i=[],n=""){this.data=e,this.name=n,V.prototype.hasOwnProperty("tree")||Object.defineProperty(V.prototype,"tree",{get(){return ce(this)}}),this.parser=t,this.extension=[Ct.of(this),V.languageData.of((r,o,l)=>{let a=zl(r,o,l),h=a.type.prop(Lt);if(!h)return[];let c=r.facet(h),f=a.type.prop(Np);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return zl(e,t,i).type.prop(Lt)==this.data}findRegions(e){let t=e.facet(Ct);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(Lt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(E.mounted);if(l){if(l.tree.prop(Lt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let h=r.children[a];h instanceof q&&n(h,r.positions[a]+o)}};return n(ce(e),0),i}get allowsNesting(){return!0}}Te.setState=P.define();function zl(s,e,t){let i=s.facet(Ct),n=ce(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(e,t,Y.ExcludeBuffers|Y.EnterBracketed))r.type.isTop&&(n=r);return n}class Ir extends Te{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=ic(e.languageData);return new Ir(t,e.parser.configure({props:[Lt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Ir(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ce(s){let e=s.field(Te.state,!1);return e?e.tree:q.empty}function Ab(s,e,t=50){var i;let n=(i=s.field(Te.state,!1))===null||i===void 0?void 0:i.context;if(!n)return null;let r=n.viewport;n.updateViewport({from:0,to:e});let o=n.isDone(e)||n.work(t,e)?n.tree:null;return n.updateViewport(r),o}class Fp{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let bi=null;class hi{constructor(e,t,i=[],n,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new hi(e,t,[],q.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Fp(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=q.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(Nt.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=n,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Nt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=bi;bi=this;try{return e()}finally{bi=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=$l(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=Nt.applyChanges(i,a),n=q.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new hi(this.parser,t,i,n,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<e.to&&r>e.from&&(this.fragments=$l(this.fragments,n,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends po{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=bi;if(a){for(let h of n)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new q(ye.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return bi}}function $l(s,e,t){return Nt.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class ci{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new ci(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=hi.create(e.facet(Ct).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new ci(i)}}Te.state=fe.define({create:ci.init,update(s,e){for(let t of e.effects)if(t.is(Te.setState))return t.value;return e.startState.facet(Ct)!=e.state.facet(Ct)?ci.init(e.state):s.apply(e)}});let nc=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(nc=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const $s=typeof navigator<"u"&&(!((zs=navigator.scheduling)===null||zs===void 0)&&zs.isInputPending)?()=>navigator.scheduling.isInputPending():null,Wp=te.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Te.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Te.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=nc(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(Te.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!$s?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,a=r.context.work(()=>$s&&$s()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Te.setState.of(new ci(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>me(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ct=T.define({combine(s){return s.length?s[0]:null},enables:s=>[Te.state,Wp,O.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]}),Hp=T.define(),ds=T.define({combine:s=>{if(!s.length)return" ";let e=s[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(s[0]));return e}});function $t(s){let e=s.facet(ds);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function Fi(s,e){let t="",i=s.tabSize,n=s.facet(ds)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r<e;r++)t+=n;return t}function mo(s,e){s instanceof V&&(s=new ps(s));for(let i of s.state.facet(Hp)){let n=i(s,e);if(n!==void 0)return n}let t=ce(s.state);return t.length>=e?Vp(s,t,e):null}class ps{constructor(e,t={}){this.state=e,this.options=t,this.unit=$t(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return Ki(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(n);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const sc=new E;function Vp(s,e,t){let i=e.resolveStack(t),n=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(n!=i.node){let r=[];for(let o=n;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return rc(i,s,t)}function rc(s,e,t){for(let i=s;i;i=i.next){let n=$p(i.node);if(n)return n(go.create(e,t,i))}return 0}function zp(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function $p(s){let e=s.type.prop(sc);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(E.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>jp(o,!0,1,void 0,r&&!zp(o)?n.from:void 0)}return s.parent==null?qp:null}function qp(){return 0}class go extends ps{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new go(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(Kp(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return rc(this.context.next,this.base,this.pos)}}function Kp(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function Up(s){let e=s.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let n=s.options.simulateBreak,r=s.state.doc.lineAt(t.from),o=n==null||n<=r.from?r.to:Math.min(r.to,n);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let h=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function jp(s,e,t,i,n){let r=s.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||n==s.pos+o,a=Up(s);return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*t)}const Gp=200;function Tb(){return V.transactionFilter.of(s=>{if(!s.docChanged||!s.isUserEvent("input.type")&&!s.isUserEvent("input.complete"))return s;let e=s.startState.languageDataAt("indentOnInput",s.startState.selection.main.head);if(!e.length)return s;let t=s.newDoc,{head:i}=s.newSelection.main,n=t.lineAt(i);if(i>n.from+Gp)return s;let r=t.sliceString(n.from,i);if(!e.some(h=>h.test(r)))return s;let{state:o}=s,l=-1,a=[];for(let{head:h}of o.selection.ranges){let c=o.doc.lineAt(h);if(c.from==l)continue;l=c.from;let f=mo(o,c.from);if(f==null)continue;let u=/^\s*/.exec(c.text)[0],d=Fi(o,f);u!=d&&a.push({from:c.from,to:c.from+u.length,insert:d})}return a.length?[s,{changes:a,sequential:!0}]:s})}const _p=T.define(),Yp=new E;function Db(s){let e=s.firstChild,t=s.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?s.to:t.from}:null}function Jp(s,e,t){let i=ce(s);if(i.length<t)return null;let n=i.resolveStack(t,1),r=null;for(let o=n;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(r&&l.from<e)break;let a=l.type.prop(Yp);if(a&&(l.to<i.length-50||i.length==s.doc.length||!Xp(l))){let h=a(l,s);h&&h.from<=t&&h.from>=e&&h.to>t&&(r=h)}}return r}function Xp(s){let e=s.lastChild;return e&&e.to==s.to&&e.type.isError}function Un(s,e,t){for(let i of s.facet(_p)){let n=i(s,e,t);if(n)return n}return Jp(s,e,t)}function oc(s,e){let t=e.mapPos(s.from,1),i=e.mapPos(s.to,-1);return t>=i?void 0:{from:t,to:i}}const ms=P.define({map:oc}),_i=P.define({map:oc});function lc(s){let e=[];for(let{head:t}of s.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(s.lineBlockAt(t));return e}const qt=fe.define({create(){return R.none},update(s,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((i,n)=>s=ql(s,i,n)),s=s.map(e.changes);let t=[];for(let i of e.effects)i.is(ms)&&!Qp(s,i.value.from,i.value.to)?t.push(i.value):i.is(_i)&&(s=s.update({filter:(n,r)=>i.value.from!=n||i.value.to!=r,filterFrom:i.value.from,filterTo:i.value.to}));if(t.length){let{preparePlaceholder:i}=e.state.facet(cc),n=t.map(r=>(i?R.replace({widget:new sm(i(e.state,r))}):Kl).range(r.from,r.to));s=s.update({add:n})}return e.selection&&(s=ql(s,e.selection.main.head)),s},provide:s=>O.decorations.from(s),toJSON(s,e){let t=[];return s.between(0,e.doc.length,(i,n)=>{t.push(i,n)}),t},fromJSON(s){if(!Array.isArray(s)||s.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<s.length;){let i=s[t++],n=s[t++];if(typeof i!="number"||typeof n!="number")throw new RangeError("Invalid JSON for fold state");e.push(Kl.range(i,n))}return R.set(e,!0)}});function ql(s,e,t=e){let i=!1;return s.between(e,t,(n,r)=>{n<t&&r>e&&(i=!0)}),i?s.update({filterFrom:e,filterTo:t,filter:(n,r)=>n>=t||r<=e}):s}function jn(s,e,t){var i;let n=null;return(i=s.field(qt,!1))===null||i===void 0||i.between(e,t,(r,o)=>{(!n||n.from>r)&&(n={from:r,to:o})}),n}function Qp(s,e,t){let i=!1;return s.between(e,e,(n,r)=>{n==e&&r==t&&(i=!0)}),i}function ac(s,e){return s.field(qt,!1)?e:e.concat(P.appendConfig.of(fc()))}const Zp=s=>{for(let e of lc(s)){let t=Un(s.state,e.from,e.to);if(t)return s.dispatch({effects:ac(s.state,[ms.of(t),hc(s,t)])}),!0}return!1},em=s=>{if(!s.state.field(qt,!1))return!1;let e=[];for(let t of lc(s)){let i=jn(s.state,t.from,t.to);i&&e.push(_i.of(i),hc(s,i,!1))}return e.length&&s.dispatch({effects:e}),e.length>0};function hc(s,e,t=!0){let i=s.state.doc.lineAt(e.from).number,n=s.state.doc.lineAt(e.to).number;return O.announce.of(`${s.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${s.state.phrase("to")} ${n}.`)}const tm=s=>{let{state:e}=s,t=[];for(let i=0;i<e.doc.length;){let n=s.lineBlockAt(i),r=Un(e,n.from,n.to);r&&t.push(ms.of(r)),i=(r?s.lineBlockAt(r.to):n).to+1}return t.length&&s.dispatch({effects:ac(s.state,t)}),!!t.length},im=s=>{let e=s.state.field(qt,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,s.state.doc.length,(i,n)=>{t.push(_i.of({from:i,to:n}))}),s.dispatch({effects:t}),!0},Ob=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:Zp},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:em},{key:"Ctrl-Alt-[",run:tm},{key:"Ctrl-Alt-]",run:im}],nm={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},cc=T.define({combine(s){return ft(s,nm)}});function fc(s){return[qt,om]}function uc(s,e){let{state:t}=s,i=t.facet(cc),n=o=>{let l=s.lineBlockAt(s.posAtDOM(o.target)),a=jn(s.state,l.from,l.to);a&&s.dispatch({effects:_i.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(s,n,e);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=n,r}const Kl=R.replace({widget:new class extends nt{toDOM(s){return uc(s,null)}}});class sm extends nt{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return uc(e,this.value)}}const rm={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class qs extends vt{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function Bb(s={}){let e={...rm,...s},t=new qs(e,!0),i=new qs(e,!1),n=te.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Ct)!=o.state.facet(Ct)||o.startState.field(qt,!1)!=o.state.field(qt,!1)||ce(o.startState)!=ce(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new at;for(let a of o.viewportLineBlocks){let h=jn(o.state,a.from,a.to)?i:Un(o.state,a.from,a.to)?t:null;h&&l.add(a.from,a.from,h)}return l.finish()}}),{domEventHandlers:r}=e;return[n,dp({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(n))===null||l===void 0?void 0:l.markers)||N.empty},initialSpacer(){return new qs(e,!1)},domEventHandlers:{...r,click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let h=jn(o.state,l.from,l.to);if(h)return o.dispatch({effects:_i.of(h)}),!0;let c=Un(o.state,l.from,l.to);return c?(o.dispatch({effects:ms.of(c)}),!0):!1}}}),fc()]}const om=O.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 gs{constructor(e,t){this.specs=e;let i;function n(l){let a=xt.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?n(t.all):void 0,o=t.scope;this.scope=o instanceof Te?l=>l.prop(Lt)==o.data:o?l=>l==o:void 0,this.style=tc(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new xt(i):null,this.themeType=t.themeType}static define(e,t){return new gs(e,t||{})}}const Nr=T.define(),lm=T.define({combine(s){return s.length?[s[0]]:null}});function Ks(s){let e=s.facet(Nr);return e.length?e:s.facet(lm)}function Pb(s,e){let t=[hm],i;return s instanceof gs&&(s.module&&t.push(O.styleModule.of(s.module)),i=s.themeType),i?t.push(Nr.computeN([O.darkTheme],n=>n.facet(O.darkTheme)==(i=="dark")?[s]:[])):t.push(Nr.of(s)),t}class am{constructor(e){this.markCache=Object.create(null),this.tree=ce(e.state),this.decorations=this.buildDeco(e,Ks(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=ce(e.state),i=Ks(e.state),n=i!=Ks(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return R.none;let i=new at;for(let{from:n,to:r}of e.visibleRanges)Lp(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=R.mark({class:a})))},n,r);return i.finish()}}const hm=At.high(te.fromClass(am,{decorations:s=>s.decorations})),Rb=gs.define([{tag:M.meta,color:"#404740"},{tag:M.link,textDecoration:"underline"},{tag:M.heading,textDecoration:"underline",fontWeight:"bold"},{tag:M.emphasis,fontStyle:"italic"},{tag:M.strong,fontWeight:"bold"},{tag:M.strikethrough,textDecoration:"line-through"},{tag:M.keyword,color:"#708"},{tag:[M.atom,M.bool,M.url,M.contentSeparator,M.labelName],color:"#219"},{tag:[M.literal,M.inserted],color:"#164"},{tag:[M.string,M.deleted],color:"#a11"},{tag:[M.regexp,M.escape,M.special(M.string)],color:"#e40"},{tag:M.definition(M.variableName),color:"#00f"},{tag:M.local(M.variableName),color:"#30a"},{tag:[M.typeName,M.namespace],color:"#085"},{tag:M.className,color:"#167"},{tag:[M.special(M.variableName),M.macroName],color:"#256"},{tag:M.definition(M.propertyName),color:"#00c"},{tag:M.comment,color:"#940"},{tag:M.invalid,color:"#f00"}]),cm=O.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),dc=1e4,pc="()[]{}",mc=T.define({combine(s){return ft(s,{afterCursor:!0,brackets:pc,maxScanDistance:dc,renderMatch:dm})}}),fm=R.mark({class:"cm-matchingBracket"}),um=R.mark({class:"cm-nonmatchingBracket"});function dm(s){let e=[],t=s.matched?fm:um;return e.push(t.range(s.start.from,s.start.to)),s.end&&e.push(t.range(s.end.from,s.end.to)),e}function Ul(s){let e=[],t=s.facet(mc);for(let i of s.selection.ranges){if(!i.empty)continue;let n=Qe(s,i.head,-1,t)||i.head>0&&Qe(s,i.head-1,1,t)||t.afterCursor&&(Qe(s,i.head,1,t)||i.head<s.doc.length&&Qe(s,i.head+1,-1,t));n&&(e=e.concat(t.renderMatch(n,s)))}return R.set(e,!0)}const pm=te.fromClass(class{constructor(s){this.paused=!1,this.decorations=Ul(s.state)}update(s){(s.docChanged||s.selectionSet||this.paused)&&(s.view.composing?(this.decorations=this.decorations.map(s.changes),this.paused=!0):(this.decorations=Ul(s.state),this.paused=!1))}},{decorations:s=>s.decorations}),mm=[pm,cm];function Lb(s={}){return[mc.of(s),mm]}const gm=new E;function Fr(s,e,t){let i=s.prop(e<0?E.openedBy:E.closedBy);if(i)return i;if(s.name.length==1){let n=t.indexOf(s.name);if(n>-1&&n%2==(e<0?1:0))return[t[n+e]]}return null}function Wr(s){let e=s.type.prop(gm);return e?e(s.node):s}function Qe(s,e,t,i={}){let n=i.maxScanDistance||dc,r=i.brackets||pc,o=ce(s),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Fr(a.type,t,r);if(h&&a.from<a.to){let c=Wr(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return bm(s,e,t,a,c,h,r)}}return ym(s,e,t,o,l.type,n,r)}function bm(s,e,t,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},h=0,c=l?.cursor();if(c&&(t<0?c.childBefore(i.from):c.childAfter(i.to)))do if(t<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let f=Wr(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(Fr(c.type,t,o))h++;else if(Fr(c.type,-t,o)){if(h==0){let f=Wr(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function ym(s,e,t,i,n,r,o){if(t<0?!e:e==s.doc.length)return null;let l=t<0?s.sliceDoc(e-1,e):s.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=s.doc.iterRange(e,t>0?s.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=r;){let d=c.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let b=o.indexOf(d[m]);if(!(b<0||i.resolveInner(p+m,1).type!=n))if(b%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+m,to:p+m+1},matched:b>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}function jl(s,e,t,i=0,n=0){e==null&&(e=s.search(/[^\s\u00a0]/),e==-1&&(e=s.length));let r=n;for(let o=i;o<e;o++)s.charCodeAt(o)==9?r+=t-r%t:r++;return r}class gc{constructor(e,t,i,n){this.string=e,this.tabSize=t,this.indentUnit=i,this.overrideIndent=n,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),i;if(typeof e=="string"?i=t==e:i=t&&(e instanceof RegExp?e.test(t):e(t)),i)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=jl(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:jl(this.string,null,this.tabSize)}match(e,t,i){if(typeof e=="string"){let n=o=>i?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return n(r)==n(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}}current(){return this.string.slice(this.start,this.pos)}}function xm(s){return{name:s.name||"",token:s.token,blankLine:s.blankLine||(()=>{}),startState:s.startState||(()=>!0),copyState:s.copyState||km,indent:s.indent||(()=>null),languageData:s.languageData||{},tokenTable:s.tokenTable||yo,mergeTokens:s.mergeTokens!==!1}}function km(s){if(typeof s!="object")return s;let e={};for(let t in s){let i=s[t];e[t]=i instanceof Array?i.slice():i}return e}const Gl=new WeakMap;class bc extends Te{constructor(e){let t=ic(e.languageData),i=xm(e),n,r=new class extends po{createParse(o,l,a){return new vm(n,o,l,a)}};super(t,r,[],e.name),this.topNode=Am(t,this),n=this,this.streamParser=i,this.stateAfter=new E({perNode:!0}),this.tokenTable=e.tokenTable?new wc(i.tokenTable):Cm}static define(e){return new bc(e)}getIndent(e){let t,{overrideIndentation:i}=e.options;i&&(t=Gl.get(e.state),t!=null&&t<e.pos-1e4&&(t=void 0));let n=bo(this,e.node.tree,e.node.from,e.node.from,t??e.pos),r,o;if(n?(o=n.state,r=n.pos+1):(o=this.streamParser.startState(e.unit),r=e.node.from),e.pos-r>1e4)return null;for(;r<e.pos;){let a=e.state.doc.lineAt(r),h=Math.min(e.pos,a.to);if(a.length){let c=i?i(a.from):-1,f=new gc(a.text,e.state.tabSize,e.unit,c<0?void 0:c);for(;f.pos<h-a.from;)xc(this.streamParser.token,f,o)}else this.streamParser.blankLine(o,e.unit);if(h==e.pos)break;r=a.to+1}let l=e.lineAt(e.pos);return i&&t==null&&Gl.set(e.state,l.from),this.streamParser.indent(o,/^\s*(.*)/.exec(l.text)[1],e)}get allowsNesting(){return!1}}function bo(s,e,t,i,n){let r=t>=i&&t+e.length<=n&&e.prop(s.stateAfter);if(r)return{state:s.streamParser.copyState(r),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof q&&a<n&&bo(s,l,a,i,n);if(h)return h}return null}function yc(s,e,t,i,n){if(n&&t<=0&&i>=e.length)return e;!n&&t==0&&e.type==s.topNode&&(n=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],a;if(o<i&&l instanceof q){if(!(a=yc(s,l,t-o,i-o,n)))break;return n?new q(e.type,e.children.slice(0,r).concat(a),e.positions.slice(0,r+1),o+a.length):a}}return null}function wm(s,e,t,i,n){for(let r of e){let o=r.from+(r.openStart?25:0),l=r.to-(r.openEnd?25:0),a=o<=t&&l>t&&bo(s,r.tree,0-r.offset,t,l),h;if(a&&a.pos<=i&&(h=yc(s,r.tree,t+r.offset,a.pos+r.offset,!1)))return{state:a.state,tree:h}}return{state:s.streamParser.startState(n?$t(n):4),tree:q.empty}}let vm=class{constructor(e,t,i,n){this.lang=e,this.input=t,this.fragments=i,this.ranges=n,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=n[n.length-1].to;let r=hi.get(),o=n[0].from,{state:l,tree:a}=wm(e,i,o,this.to,r?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);r&&this.parsedPos<r.viewport.from-1e5&&n.some(h=>h.from<=r.viewport.from&&h.to>=r.viewport.from)&&(this.state=this.lang.streamParser.startState($t(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=hi.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(t,this.chunkStart+512);for(e&&(i=Math.min(i,e.viewport.to));this.parsedPos<i;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
12
12
  `&&(t="");else{let i=t.indexOf(`
13
13
  `);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let n=this.rangeIndex;;){let r=this.ranges[n].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),n++,n==this.ranges.length))break;let o=this.ranges[n].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let n=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?n>r:n>=r)break;let o=this.ranges[++this.rangeIndex].from;t+=o-n}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,i,n){let r=4;if(this.ranges.length>1){n=this.skipGapsTo(t,n,1),t+=n;let l=this.chunk.length;n=this.skipGapsTo(i,n,-1),i+=n,r+=this.chunk.length-l}let o=this.chunk.length-4;return this.lang.streamParser.mergeTokens&&r==4&&o>=0&&this.chunk[o]==e&&this.chunk[o+2]==t?this.chunk[o+2]=i:this.chunk.push(e,t,i,r),n}parseLine(e){let{line:t,end:i}=this.nextLine(),n=0,{streamParser:r}=this.lang,o=new gc(t,e?e.state.tabSize:4,e?$t(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=xc(r.token,o,this.state);if(l&&(n=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,n)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=q.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Sm,topID:0,maxBufferLength:512,reused:this.chunkReused});e=new q(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new q(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}};function xc(s,e,t){e.start=e.pos;for(let i=0;i<10;i++){let n=s(e,t);if(e.pos>e.start)return n}throw new Error("Stream parser failed to advance stream.")}const yo=Object.create(null),Wi=[ye.none],Sm=new us(Wi),_l=[],Yl=Object.create(null),kc=Object.create(null);for(let[s,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])kc[s]=vc(yo,e);class wc{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),kc)}resolve(e){return e?this.table[e]||(this.table[e]=vc(this.extra,e)):0}}const Cm=new wc(yo);function Us(s,e){_l.indexOf(s)>-1||(_l.push(s),console.warn(e))}function vc(s,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=s[h]||M[h];c?typeof c=="function"?a.length?a=a.map(c):Us(h,`Modifier ${h} used at start of tag`):a.length?Us(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:Us(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),n=i+" "+t.map(l=>l.id),r=Yl[n];if(r)return r.id;let o=Yl[n]=ye.define({id:Wi.length,name:i,props:[Pp({[i]:t})]});return Wi.push(o),o.id}function Am(s,e){let t=ye.define({id:Wi.length,name:"Document",props:[Lt.add(()=>s),sc.add(()=>i=>e.getIndent(i))],top:!0});return Wi.push(t),t}j.RTL,j.LTR;const Mm=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=ko(s.state,t.from);return i.line?Tm(s):i.block?Om(s):!1};function xo(s,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=s(e,t);return n?(i(t.update(n)),!0):!1}}const Tm=xo(Rm,0),Dm=xo(Sc,0),Om=xo((s,e)=>Sc(s,e,Pm(e)),0);function ko(s,e){let t=s.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const yi=50;function Bm(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-yi,i),o=s.sliceDoc(n,n+yi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+a,margin:a&&1}};let c,f;n-i<=2*yi?c=f=s.sliceDoc(i,n):(c=s.sliceDoc(i,i+yi),f=s.sliceDoc(n-yi,n));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function Pm(s){let e=[];for(let t of s.selection.ranges){let i=s.doc.lineAt(t.from),n=t.to<=i.to?i:s.doc.lineAt(t.to);n.from>i.from&&n.from==t.to&&(n=t.to==i.to+1?i:s.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=n.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return e}function Sc(s,e,t=e.selection.ranges){let i=t.map(r=>ko(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>Bm(e,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:e.changes(t.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let a=i[o],{open:h,close:c}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function Rm(s,e,t=e.selection.ranges){let i=[],n=-1;e:for(let{from:r,to:o}of t){let l=i.length,a=1e9,h;for(let c=r;c<=o;){let f=e.doc.lineAt(c);if(h==null&&(h=ko(e,f.from).line,!h))continue e;if(f.from>n&&(r==o||o>f.from)){n=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+h.length)==h?u:-1;u<f.text.length&&u<a&&(a=u),i.push({line:f,comment:p,token:h,indent:u,empty:d,single:!1})}c=f.to+1}if(a<1e9)for(let c=l;c<i.length;c++)i[c].indent<i[c].line.text.length&&(i[c].indent=a);i.length==l+1&&(i[l].single=!0)}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of i)(f||!c)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(s!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,r.push({from:h,to:c})}return{changes:r}}return null}const Hr=ct.define(),Lm=ct.define(),Em=T.define(),Cc=T.define({combine(s){return ft(s,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,n)=>e(i,n)||t(i,n)})}}),Ac=fe.define({create(){return Ze.empty},update(s,e){let t=e.state.facet(Cc),i=e.annotation(Hr);if(i){let a=ve.fromTransaction(e,i.selection),h=i.side,c=h==0?s.undone:s.done;return a?c=Gn(c,c.length,t.minDepth,a):c=Dc(c,e.startState.selection),new Ze(h==0?i.rest:c,h==0?c:i.rest)}let n=e.annotation(Lm);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(Q.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=ve.fromTransaction(e),o=e.annotation(Q.time),l=e.annotation(Q.userEvent);return r?s=s.addChanges(r,o,l,t,e):e.selection&&(s=s.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(e=>e.toJSON()),undone:s.undone.map(e=>e.toJSON())}},fromJSON(s){return new Ze(s.done.map(ve.fromJSON),s.undone.map(ve.fromJSON))}});function Ib(s={}){return[Ac,Cc.of(s),O.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?Mc:e.inputType=="historyRedo"?Vr:null;return i?(e.preventDefault(),i(t)):!1}})]}function bs(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(Ac,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const Mc=bs(0,!1),Vr=bs(1,!1),Im=bs(0,!0),Nm=bs(1,!0);class ve{constructor(e,t,i,n,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(e){return new ve(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(e){return new ve(e.changes&&ee.fromJSON(e.changes),[],e.mapped&&tt.fromJSON(e.mapped),e.startSelection&&y.fromJSON(e.startSelection),e.selectionsAfter.map(y.fromJSON))}static fromTransaction(e,t){let i=Re;for(let n of e.startState.facet(Em)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new ve(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Re)}static selection(e){return new ve(void 0,Re,void 0,void 0,e)}}function Gn(s,e,t,i){let n=e+1>t+20?e-t-1:0,r=s.slice(n,e);return r.push(i),r}function Fm(s,e){let t=[],i=!1;return s.iterChangedRanges((n,r)=>t.push(n,r)),e.iterChangedRanges((n,r,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(i=!0)}}),i}function Wm(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function Tc(s,e){return s.length?e.length?s.concat(e):s:e}const Re=[],Hm=200;function Dc(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Hm));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),Gn(s,s.length-1,1e9,t.setSelAfter(i)))}else return[ve.selection([e])]}function Vm(s){let e=s[s.length-1],t=s.slice();return t[s.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function js(s,e){if(!s.length)return s;let t=s.length,i=Re;for(;t;){let n=zm(s[t-1],e,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,t);return r[t-1]=n,r}else e=n.mapped,t--,i=n.selectionsAfter}return i.length?[ve.selection(i)]:Re}function zm(s,e,t){let i=Tc(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):Re,t);if(!s.changes)return ve.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new ve(n,P.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const $m=/^(input\.type|delete)($|\.)/;class Ze{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Ze(this.done,this.undone):this}addChanges(e,t,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||$m.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,Fm(l.changes,e.changes))||i=="input.type.compose")?o=Gn(o,o.length-1,n.minDepth,new ve(e.changes.compose(l.changes),Tc(P.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Re)):o=Gn(o,o.length,n.minDepth,e),new Ze(o,Re,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Re;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Wm(r[r.length-1],e)?this:new Ze(Dc(this.done,e),this.undone,t,i)}addMapping(e){return new Ze(js(this.done,e),js(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=e==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Hr.of({side:e,rest:Vm(n),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?Re:n.slice(0,n.length-1);return r.mapped&&(l=js(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Hr.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Ze.empty=new Ze(Re,Re);const Nb=[{key:"Mod-z",run:Mc,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Vr,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Vr,preventDefault:!0},{key:"Mod-u",run:Im,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Nm,preventDefault:!0}];function ui(s,e){return y.create(s.ranges.map(e),s.mainIndex)}function Ve(s,e){return s.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ze({state:s,dispatch:e},t){let i=ui(s.selection,t);return i.eq(s.selection,!0)?!1:(e(Ve(s,i)),!0)}function ys(s,e){return y.cursor(e?s.to:s.from)}function wo(s,e){return ze(s,t=>t.empty?s.moveByChar(t,e):ys(t,e))}function ue(s){return s.textDirectionAt(s.state.selection.main.head)==j.LTR}const Oc=s=>wo(s,!ue(s)),Bc=s=>wo(s,ue(s)),Fb=s=>wo(s,!1);function Pc(s,e){return ze(s,t=>t.empty?s.moveByGroup(t,e):ys(t,e))}const qm=s=>Pc(s,!ue(s)),Km=s=>Pc(s,ue(s));function Um(s,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(e.from,e.to)))||e.firstChild}function xs(s,e,t){let i=ce(s).resolveInner(e.head),n=t?E.closedBy:E.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Um(s,h,n)?i=h:a=t?h.to:h.from}let r=i.type.prop(n),o,l;return r&&(o=t?Qe(s,i.from,1):Qe(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,y.cursor(l,t?-1:1)}const jm=s=>ze(s,e=>xs(s.state,e,!ue(s))),Gm=s=>ze(s,e=>xs(s.state,e,ue(s)));function Rc(s,e){return ze(s,t=>{if(!t.empty)return ys(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const Lc=s=>Rc(s,!1),Ec=s=>Rc(s,!0);function Ic(s){let e=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,t=0,i=0,n;if(e){for(let r of s.state.facet(O.scrollMargins)){let o=r(s);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(i=Math.max(o?.bottom,i))}n=s.scrollDOM.clientHeight-t-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(s.defaultLineHeight,n-5)}}function Nc(s,e){let t=Ic(s),{state:i}=s,n=ui(i.selection,o=>o.empty?s.moveVertically(o,e,t.height):ys(o,e));if(n.eq(i.selection))return!1;let r;if(t.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=O.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-a}))}return s.dispatch(Ve(i,n),{effects:r}),!0}const Jl=s=>Nc(s,!1),zr=s=>Nc(s,!0);function Mt(s,e,t){let i=s.lineBlockAt(e.head),n=s.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=s.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(n=y.cursor(i.from+r))}return n}const _m=s=>ze(s,e=>Mt(s,e,!0)),Ym=s=>ze(s,e=>Mt(s,e,!1)),Jm=s=>ze(s,e=>Mt(s,e,!ue(s))),Xm=s=>ze(s,e=>Mt(s,e,ue(s))),Qm=s=>ze(s,e=>y.cursor(s.lineBlockAt(e.head).from,1)),Zm=s=>ze(s,e=>y.cursor(s.lineBlockAt(e.head).to,-1));function eg(s,e,t){let i=!1,n=ui(s.selection,r=>{let o=Qe(s,r.head,-1)||Qe(s,r.head,1)||r.head>0&&Qe(s,r.head-1,1)||r.head<s.doc.length&&Qe(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return y.cursor(l)});return i?(e(Ve(s,n)),!0):!1}const tg=({state:s,dispatch:e})=>eg(s,e);function Ie(s,e,t){let i=ui(s.state.selection,n=>{n.undirectional&&n.head>=n.anchor!=e&&(n=y.range(n.head,n.anchor));let r=t(n);return y.range(n.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return i.eq(s.state.selection)?!1:(s.dispatch(Ve(s.state,i)),!0)}function Fc(s,e){return Ie(s,e,t=>s.moveByChar(t,e))}const Wc=s=>Fc(s,!ue(s)),Hc=s=>Fc(s,ue(s));function Vc(s,e){return Ie(s,e,t=>s.moveByGroup(t,e))}const ig=s=>Vc(s,!ue(s)),ng=s=>Vc(s,ue(s)),sg=s=>{let e=!ue(s);return Ie(s,e,t=>xs(s.state,t,e))},rg=s=>{let e=ue(s);return Ie(s,e,t=>xs(s.state,t,e))};function zc(s,e){return Ie(s,e,t=>s.moveVertically(t,e))}const $c=s=>zc(s,!1),qc=s=>zc(s,!0);function Kc(s,e){return Ie(s,e,t=>s.moveVertically(t,e,Ic(s).height))}const Xl=s=>Kc(s,!1),Ql=s=>Kc(s,!0),og=s=>Ie(s,!0,e=>Mt(s,e,!0)),lg=s=>Ie(s,!1,e=>Mt(s,e,!1)),ag=s=>{let e=!ue(s);return Ie(s,e,t=>Mt(s,t,e))},hg=s=>{let e=ue(s);return Ie(s,e,t=>Mt(s,t,e))},cg=s=>Ie(s,!1,e=>y.cursor(s.lineBlockAt(e.head).from)),fg=s=>Ie(s,!0,e=>y.cursor(s.lineBlockAt(e.head).to)),Zl=({state:s,dispatch:e})=>(e(Ve(s,{anchor:0})),!0),ea=({state:s,dispatch:e})=>(e(Ve(s,{anchor:s.doc.length})),!0),ta=({state:s,dispatch:e})=>(e(Ve(s,{anchor:s.selection.main.anchor,head:0})),!0),ia=({state:s,dispatch:e})=>(e(Ve(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),ug=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),dg=({state:s,dispatch:e})=>{let t=ks(s).map(({from:i,to:n})=>y.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:y.create(t),userEvent:"select"})),!0},pg=({state:s,dispatch:e})=>{let t=ui(s.selection,i=>{let n=ce(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return y.range(l.to,l.from)}return i});return t.eq(s.selection)?!1:(e(Ve(s,t)),!0)};function Uc(s,e){let{state:t}=s,i=t.selection,n=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<s.state.doc.length:o.from>0)for(let l=r;;){let a=s.moveVertically(l,e);if(a.head<o.from||a.head>o.to){n.some(h=>h.head==a.head)||n.push(a);break}else{if(a.head==l.head)break;l=a}}}return n.length==i.ranges.length?!1:(s.dispatch(Ve(t,y.create(n,n.length-1))),!0)}const mg=s=>Uc(s,!1),gg=s=>Uc(s,!0),bg=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=y.create([t.main]):t.main.empty||(i=y.create([y.cursor(t.main.head)])),i?(e(Ve(s,i)),!0):!1};function Yi(s,e){if(s.state.readOnly)return!1;let t="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=yn(s,a,!1)):a>o&&(t="delete.forward",a=yn(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=yn(s,o,!1),l=yn(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:y.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?O.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function yn(s,e,t){if(s instanceof O)for(let i of s.state.facet(O.atomicRanges).map(n=>n(s)))i.between(e,e,(n,r)=>{n<e&&r>e&&(e=t?r:n)});return e}const jc=(s,e,t)=>Yi(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,a;if(t&&!e&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let h=Ki(l,r.tabSize),c=h%$t(r)||$t(r);for(let f=0;f<c&&l[l.length-1-f]==" ";f++)n--;a=n}else a=ne(o.text,n-o.from,e,e)+o.from,a==n&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,n-o.from))&&(a=ne(o.text,a-o.from,!1,!1)+o.from);return a}),$r=s=>jc(s,!1,!0),Gc=s=>jc(s,!0,!1),_c=(s,e)=>Yi(s,t=>{let i=t.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?n.doc.lines:1)&&(i+=e?1:-1);break}let a=ne(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t.head)&&(l=c),i=a}return i}),Yc=s=>_c(s,!1),yg=s=>_c(s,!0),xg=s=>Yi(s,e=>{let t=s.lineBlockAt(e.head).to;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),kg=s=>Yi(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),wg=s=>Yi(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),vg=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:W.of(["",""])},range:y.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},Sg=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>{if(!i.empty||i.from==0||i.from==s.doc.length)return{range:i};let n=i.from,r=s.doc.lineAt(n),o=n==r.from?n-1:ne(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:ne(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:y.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function ks(s){let e=[],t=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.from),r=s.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=s.doc.lineAt(i.to-1)),t>=n.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:n.from,to:r.to,ranges:[i]});t=r.number+1}return e}function Jc(s,e,t){if(s.readOnly)return!1;let i=[],n=[];for(let r of ks(s)){if(t?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let a of r.ranges)n.push(y.range(Math.min(s.doc.length,a.anchor+l),Math.min(s.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let a of r.ranges)n.push(y.range(a.anchor-l,a.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:y.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Cg=({state:s,dispatch:e})=>Jc(s,e,!1),Ag=({state:s,dispatch:e})=>Jc(s,e,!0);function Xc(s,e,t){if(s.readOnly)return!1;let i=[];for(let r of ks(s))t?i.push({from:r.from,insert:s.doc.slice(r.from,r.to)+s.lineBreak}):i.push({from:r.to,insert:s.lineBreak+s.doc.slice(r.from,r.to)});let n=s.changes(i);return e(s.update({changes:n,selection:s.selection.map(n,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Mg=({state:s,dispatch:e})=>Xc(s,e,!1),Tg=({state:s,dispatch:e})=>Xc(s,e,!0),Dg=s=>{if(s.state.readOnly)return!1;let{state:e}=s,t=e.changes(ks(e).map(({from:n,to:r})=>(n>0?n--:r<e.doc.length&&r++,{from:n,to:r}))),i=ui(e.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(t);return s.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Og(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ce(s).resolveInner(e),i=t.childBefore(e),n=t.childAfter(e),r;return i&&n&&i.to<=e&&n.from>=e&&(r=i.type.prop(E.closedBy))&&r.indexOf(n.name)>-1&&s.doc.lineAt(i.to).from==s.doc.lineAt(n.from).from&&!/\S/.test(s.sliceDoc(i.to,n.from))?{from:i.to,to:n.from}:null}const na=Qc(!1),Bg=Qc(!0);function Qc(s){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(n=>{let{from:r,to:o}=n,l=e.doc.lineAt(r),a=!s&&r==o&&Og(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new ps(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=mo(h,r);for(c==null&&(c=Ki(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",Fi(e,c)];return a&&f.push(Fi(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:W.of(f)},range:y.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function vo(s,e){let t=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:y.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Pg=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new ps(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=vo(s,(r,o,l)=>{let a=mo(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=Fi(s,a);(h!=c||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return n.changes.empty||e(s.update(n,{userEvent:"indent"})),!0},Rg=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(vo(s,(t,i)=>{i.push({from:t.from,insert:s.facet(ds)})}),{userEvent:"input.indent"})),!0),Lg=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(vo(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=Ki(n,s.tabSize),o=0,l=Fi(s,Math.max(0,r-$t(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Eg=s=>(s.setTabFocusMode(),!0),Ig=[{key:"Ctrl-b",run:Oc,shift:Wc,preventDefault:!0},{key:"Ctrl-f",run:Bc,shift:Hc},{key:"Ctrl-p",run:Lc,shift:$c},{key:"Ctrl-n",run:Ec,shift:qc},{key:"Ctrl-a",run:Qm,shift:cg},{key:"Ctrl-e",run:Zm,shift:fg},{key:"Ctrl-d",run:Gc},{key:"Ctrl-h",run:$r},{key:"Ctrl-k",run:xg},{key:"Ctrl-Alt-h",run:Yc},{key:"Ctrl-o",run:vg},{key:"Ctrl-t",run:Sg},{key:"Ctrl-v",run:zr}],Ng=[{key:"ArrowLeft",run:Oc,shift:Wc,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:qm,shift:ig,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Jm,shift:ag,preventDefault:!0},{key:"ArrowRight",run:Bc,shift:Hc,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Km,shift:ng,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Xm,shift:hg,preventDefault:!0},{key:"ArrowUp",run:Lc,shift:$c,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Zl,shift:ta},{mac:"Ctrl-ArrowUp",run:Jl,shift:Xl},{key:"ArrowDown",run:Ec,shift:qc,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ea,shift:ia},{mac:"Ctrl-ArrowDown",run:zr,shift:Ql},{key:"PageUp",run:Jl,shift:Xl},{key:"PageDown",run:zr,shift:Ql},{key:"Home",run:Ym,shift:lg,preventDefault:!0},{key:"Mod-Home",run:Zl,shift:ta},{key:"End",run:_m,shift:og,preventDefault:!0},{key:"Mod-End",run:ea,shift:ia},{key:"Enter",run:na,shift:na},{key:"Mod-a",run:ug},{key:"Backspace",run:$r,shift:$r,preventDefault:!0},{key:"Delete",run:Gc,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Yc,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:yg,preventDefault:!0},{mac:"Mod-Backspace",run:kg,preventDefault:!0},{mac:"Mod-Delete",run:wg,preventDefault:!0}].concat(Ig.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),Wb=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:jm,shift:sg},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Gm,shift:rg},{key:"Alt-ArrowUp",run:Cg},{key:"Shift-Alt-ArrowUp",run:Mg},{key:"Alt-ArrowDown",run:Ag},{key:"Shift-Alt-ArrowDown",run:Tg},{key:"Mod-Alt-ArrowUp",run:mg},{key:"Mod-Alt-ArrowDown",run:gg},{key:"Escape",run:bg},{key:"Mod-Enter",run:Bg},{key:"Alt-l",mac:"Ctrl-l",run:dg},{key:"Mod-i",run:pg,preventDefault:!0},{key:"Mod-[",run:Lg},{key:"Mod-]",run:Rg},{key:"Mod-Alt-\\",run:Pg},{key:"Shift-Mod-k",run:Dg},{key:"Shift-Mod-\\",run:tg},{key:"Mod-/",run:Mm},{key:"Alt-A",run:Dm},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Eg}].concat(Ng);class Zc{constructor(e,t,i,n){this.state=e,this.pos=t,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ce(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),n=t.text.slice(i-t.from,this.pos-t.from),r=n.search(ef(e,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function sa(s){let e=Object.keys(s).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Fg(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;r<n.length;r++)t[n[r]]=!0}let i=sa(e)+sa(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Wg(s){let e=s.map(n=>typeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:Fg(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}class ra{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function Ft(s){return s.selection.main.from}function ef(s,e){var t;let{source:i}=s,n=e&&i[0]!="^",r=i[i.length-1]!="$";return!n&&!r?s:new RegExp(`${n?"^":""}(?:${i})${r?"$":""}`,(t=s.flags)!==null&&t!==void 0?t:s.ignoreCase?"i":"")}const So=ct.define();function Hg(s,e,t,i){let{main:n}=s.selection,r=t-n.from,o=i-n.from;return{...s.changeByRange(l=>{if(l!=n&&t!=i&&s.sliceDoc(l.from+r,l.from+o)!=s.sliceDoc(t,i))return{range:l};let a=s.toText(e);return{changes:{from:l.from+r,to:i==n.from?l.to:l.from+o,insert:a},range:y.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const oa=new WeakMap;function Vg(s){if(!Array.isArray(s))return s;let e=oa.get(s);return e||oa.set(s,e=Wg(s)),e}const _n=P.define(),Hi=P.define();class zg{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=xe(e,t),n=Ye(i);this.chars.push(i);let r=e.slice(t,t+n),o=r.toUpperCase();this.folded.push(xe(o==r?r.toLowerCase():o,0)),t+=n}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:n,precise:r,byWord:o}=this;if(t.length==1){let x=xe(e,0),k=Ye(x),D=k==e.length?0:-100;if(x!=t[0])if(x==i[0])D+=-200;else return null;return this.ret(D,[0,k])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let x=0,k=Math.min(e.length,200);x<k&&h<a;){let D=xe(e,x);(D==t[h]||D==i[h])&&(n[h++]=x),x+=Ye(D)}if(h<a)return null}let c=0,f=0,u=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),b=!0;for(let x=0,k=Math.min(e.length,200),D=0;x<k&&f<a;){let w=xe(e,x);l<0&&(c<a&&w==t[c]&&(r[c++]=x),d<a&&(w==t[d]||w==i[d]?(d==0&&(p=x),m=x+1,d++):d=0));let v,S=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(v=Ur(w))!=v.toLowerCase()?1:v!=v.toUpperCase()?2:0;(!x||S==1&&g||D==0&&S!=0)&&(t[f]==w||i[f]==w&&(u=!0)?o[f++]=x:o.length&&(b=!1)),D=S,x+=Ye(w)}return f==a&&o[0]==0&&b?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):f==a?this.result(-100+(u?-200:0)+-700+(b?0:-1100),o,e):t.length==2?null:this.result((n[0]?-700:0)+-200+-1100,n,e)}result(e,t,i){let n=[],r=0;for(let o of t){let l=o+(this.astral?Ye(xe(i,o)):1);r&&n[r-1]==o?n[r-1]=l:(n[r++]=o,n[r++]=l)}return this.ret(e-i.length,n)}}class $g{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const ie=T.define({combine(s){return ft(s,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:qg,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>la(e(i),t(i)),optionClass:(e,t)=>i=>la(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function la(s,e){return s?e?s+" "+e:s:e}function qg(s,e,t,i,n,r){let o=s.textDirection==j.RTL,l=o,a=!1,h="top",c,f,u=e.left-n.left,d=n.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))c=Math.max(n.top,Math.min(t.top,n.bottom-m))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:n.right-e.left)-30);let x=n.bottom-e.bottom;x>=m||x>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,b=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${c/g}px; max-width: ${f/b}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const Co=P.define();function Kg(s){let e=s.addToOptions.slice();return s.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(n=>"cm-completionIcon-"+n)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,n,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;h<r.length;){let c=r[h++],f=r[h++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(c,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function Gs(s,e,t){if(s<=t)return{from:0,to:s};if(e<0&&(e=0),e<=s>>1){let n=Math.floor(e/t);return{from:n*t,to:(n+1)*t}}let i=Math.ceil((s-e)/t);return{from:s-i*t,to:s-(i-1)*t}}class Ug{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let n=e.state.field(t),{options:r,selected:o}=n.open,l=e.state.facet(ie);this.optionContent=Kg(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Gs(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=e.state.field(t).open;for(let c=a.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]<h.length){this.applyCompletion(e,h[+f[1]]),a.preventDefault();return}if(a.target==this.list){let c=this.list.classList.contains("cm-completionListIncompleteTop")&&a.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&a.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;c!=null&&(e.dispatch({effects:Co.of(c)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ie).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Hi.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=n){let{options:r,selected:o,disabled:l}=i.open;(!n.open||n.open.options!=r)&&(this.range=Gs(r.length,o,e.state.facet(ie).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=n.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Gs(t.options.length,t.selected,this.view.state.facet(ie).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:n}=t.options[t.selected],{info:r}=n;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(n);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,n)}).catch(l=>me(this.view.state,l,"completion info")):(this.addInfoPane(o,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:n,destroy:r}=e;i.appendChild(n),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)i.nodeName!="LI"||!i.id?n--:n==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&Gg(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return n.top>Math.min(r.bottom,t.bottom)-10||n.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(ie).positionInfo(this.view,t,n,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const n=document.createElement("ul");n.id=t,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",o=>{o.target==n&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof h!="string"&&h.header)n.appendChild(h.header(h));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=n.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function jg(s,e){return t=>new Ug(t,s,e)}function Gg(s,e){let t=s.getBoundingClientRect(),i=e.getBoundingClientRect(),n=t.height/s.offsetHeight;i.top<t.top?s.scrollTop-=(t.top-i.top)/n:i.bottom>t.bottom&&(s.scrollTop+=(i.bottom-t.bottom)/n)}function aa(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function _g(s,e){let t=[],i=null,n=null,r=c=>{t.push(c);let{section:f}=c.completion;if(f){i||(i=[]);let u=typeof f=="string"?f:f.name;i.some(d=>d.name==u)||i.push(typeof f=="string"?{name:u}:f)}},o=e.facet(ie);for(let c of s)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let u of c.result.options)r(new ra(u,c.source,f?f(u):[],1e9-t.length));else{let u=e.sliceDoc(c.from,c.to),d,p=o.filterStrict?new $g(u):new zg(u);for(let m of c.result.options)if(d=p.match(m.label)){let g=m.displayLabel?f?f(m,d.matched):[]:d.matched,b=d.score+(m.boost||0);if(r(new ra(m,c.source,g,b)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:x}=m.section;n||(n=Object.create(null)),n[x]=Math.max(b,n[x]||-1e9)}}}}if(i){let c=Object.create(null),f=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?n[p.name]-n[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(u))f-=1e5,c[d.name]=f;for(let d of t){let{section:p}=d.completion;p&&(d.score+=c[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let c of t.sort((f,u)=>u.score-f.score||h(f.completion,u.completion))){let f=c.completion;!a||a.label!=f.label||a.detail!=f.detail||a.type!=null&&f.type!=null&&a.type!=f.type||a.apply!=f.apply||a.boost!=f.boost?l.push(c):aa(c.completion)>aa(a)&&(l[l.length-1]=c),a=c.completion}return l}class Xt{constructor(e,t,i,n,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Xt(this.options,ha(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,n,r,o){if(n&&!o&&e.some(h=>h.isPending))return n.setDisabled();let l=_g(e,t);if(!l.length)return n&&e.some(h=>h.isPending)?n.setDisabled():null;let a=t.facet(ie).selectOnOpen?0:-1;if(n&&n.selected!=a&&n.selected!=-1){let h=n.options[n.selected].completion;for(let c=0;c<l.length;c++)if(l[c].completion==h){a=c;break}}return new Xt(l,ha(i,a),{pos:e.reduce((h,c)=>c.hasResult()?Math.min(h,c.from):h,1e8),create:e0,above:r.aboveCursor},n?n.timestamp:Date.now(),a,!1)}map(e){return new Xt(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Xt(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class Yn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new Yn(Qg,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(ie),r=(i.override||t.languageDataAt("autocomplete",Ft(t)).map(Vg)).map(a=>(this.active.find(c=>c.source==a)||new Le(a,this.active.some(c=>c.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((a,h)=>a==this.active[h])&&(r=this.active);let o=this.open,l=e.effects.some(a=>a.is(Ao));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!Yg(r,this.active)||l?o=Xt.build(r,t,this.id,o,i,l):o&&o.disabled&&!r.some(a=>a.isPending)&&(o=null),!o&&r.every(a=>!a.isPending)&&r.some(a=>a.hasResult())&&(r=r.map(a=>a.hasResult()?new Le(a.source,0):a));for(let a of e.effects)a.is(Co)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new Yn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Jg:Xg}}function Yg(s,e){if(s==e)return!0;for(let t=0,i=0;;){for(;t<s.length&&!s[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let n=t==s.length,r=i==e.length;if(n||r)return n==r;if(s[t++].result!=e[i++].result)return!1}}const Jg={"aria-autocomplete":"list"},Xg={};function ha(s,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return e>-1&&(t["aria-activedescendant"]=s+"-"+e),t}const Qg=[];function tf(s,e){if(s.isUserEvent("input.complete")){let i=s.annotation(So);if(i&&e.activateOnCompletion(i))return 12}let t=s.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:s.isUserEvent("delete.backward")?2:s.selection?8:s.docChanged?16:0}class Le{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=tf(e,t),n=this;(i&8||i&16&&this.touches(e))&&(n=new Le(n.source,0)),i&4&&n.state==0&&(n=new Le(this.source,1)),n=n.updateFor(e,i);for(let r of e.effects)if(r.is(_n))n=new Le(n.source,1,r.value);else if(r.is(Hi))n=new Le(n.source,0);else if(r.is(Ao))for(let o of r.value)o.source==n.source&&(n=o);return n}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Ft(e.state))}}class ii extends Le{constructor(e,t,i,n,r,o){super(e,3,t),this.limit=i,this.result=n,this.from=r,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let n=this.result;n.map&&!e.changes.empty&&(n=n.map(n,e.changes));let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=Ft(e.state);if(l>o||!n||t&2&&(Ft(e.startState)==this.from||l<this.limit))return new Le(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return Zg(n.validFor,e.state,r,o)?new ii(this.source,this.explicit,a,n,r,o):n.update&&(n=n.update(n,r,o,new Zc(e.state,l,!1)))?new ii(this.source,this.explicit,a,n,n.from,(i=n.to)!==null&&i!==void 0?i:Ft(e.state)):new Le(this.source,1,this.explicit)}map(e){if(e.empty)return this;let t=this.result.map?this.result.map(this.result,e):this.result;return t?new ii(this.source,this.explicit,e.mapPos(this.limit),t,e.mapPos(this.from),e.mapPos(this.to,1)):new Le(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function Zg(s,e,t,i){if(!s)return!1;let n=e.sliceDoc(t,i);return typeof s=="function"?s(n,t,i,e):ef(s,!0).test(n)}const Ao=P.define({map(s,e){return s.map(t=>t.map(e))}}),ke=fe.define({create(){return Yn.start()},update(s,e){return s.update(e)},provide:s=>[ho.from(s,e=>e.tooltip),O.contentAttributes.from(s,e=>e.attrs)]});function Mo(s,e){const t=e.completion.apply||e.completion.label;let i=s.state.field(ke).active.find(n=>n.source==e.source);return i instanceof ii?(typeof t=="string"?s.dispatch({...Hg(s.state,t,i.from,i.to),annotations:So.of(e.completion)}):t(s,e.completion,i.from,i.to),!0):!1}const e0=jg(ke,Mo);function xn(s,e="option"){return t=>{let i=t.state.field(ke,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(ie).interactionDelay)return!1;let n=1,r;e=="page"&&(r=qh(t,i.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+n*(s?1:-1):s?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Co.of(l)}),!0}}const t0=s=>{let e=s.state.field(ke,!1);return s.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<s.state.facet(ie).interactionDelay?!1:Mo(s,e.open.options[e.open.selected])},_s=s=>s.state.field(ke,!1)?(s.dispatch({effects:_n.of(!0)}),!0):!1,i0=s=>{let e=s.state.field(ke,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(s.dispatch({effects:Hi.of(null)}),!0)};class n0{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const s0=50,r0=1e3,o0=te.fromClass(class{constructor(s){this.view=s,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of s.state.field(ke).active)e.isPending&&this.startQuery(e)}update(s){let e=s.state.field(ke),t=s.state.facet(ie);if(!s.selectionSet&&!s.docChanged&&s.startState.field(ke)==e)return;let i=s.transactions.some(r=>{let o=tf(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&s.docChanged||o.updates.length+s.transactions.length>s0&&Date.now()-o.time>r0){for(let l of o.context.abortListeners)try{l()}catch(a){me(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...s.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),s.transactions.some(r=>r.effects.some(o=>o.is(_n)))&&(this.pendingStart=!0);let n=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(r=>r.isPending&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),n):-1,this.composing!=0)for(let r of s.transactions)r.isUserEvent("input.type")?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:s}=this.view,e=s.field(ke);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ie).updateSyncTime))}startQuery(s){let{state:e}=this.view,t=Ft(e),i=new Zc(e,t,s.explicit,this.view),n=new n0(s,i);this.running.push(n),Promise.resolve(s.source(i)).then(r=>{n.context.aborted||(n.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Hi.of(null)}),me(this.view.state,r)})}scheduleAccept(){this.running.every(s=>s.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(ie).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ie),i=this.view.state.field(ke);for(let n=0;n<this.running.length;n++){let r=this.running[n];if(r.done===void 0)continue;if(this.running.splice(n--,1),r.done){let l=Ft(r.updates.length?r.updates[0].startState:this.view.state),a=Math.min(l,r.done.from+(r.active.explicit?0:1)),h=new ii(r.active.source,r.active.explicit,a,r.done,r.done.from,(s=r.done.to)!==null&&s!==void 0?s:l);for(let c of r.updates)h=h.update(c,t);if(h.hasResult()){e.push(h);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Le(r.active.source,0);for(let a of r.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:Ao.of(e)})}},{eventHandlers:{blur(s){let e=this.view.state.field(ke,!1);if(e&&e.tooltip&&this.view.state.facet(ie).closeOnBlur){let t=e.open&&qh(this.view,e.open.tooltip);(!t||!t.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Hi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:_n.of(!1)}),20),this.composing=0}}}),l0=typeof navigator=="object"&&/Win/.test(navigator.platform),a0=At.highest(O.domEventHandlers({keydown(s,e){let t=e.state.field(ke,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||s.key.length>1||s.ctrlKey&&!(l0&&s.altKey)||s.metaKey)return!1;let i=t.open.options[t.open.selected],n=t.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||n.result.commitCharacters;return r&&r.indexOf(s.key)>-1&&Mo(e,i),!1}})),nf=O.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",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".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"}}});class h0{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class To{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,le.TrackDel),i=e.mapPos(this.to,1,le.TrackDel);return t==null||i==null?null:new To(this.field,t,i)}}class Do{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let h=o,c=/^\t*/.exec(a)[0].length;for(let f=0;f<c;f++)h+=e.facet(ds);n.push(t+h.length-c),a=h+a.slice(c)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new To(a.field,n[a.line]+a.from,n[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],n=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",h=-1;l===0&&(l=1e9);let c=a.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<t.length;f++)(l!=null?t[f].seq==l:c&&t[f].name==c)&&(h=f);if(h<0){let f=0;for(;f<t.length&&(l==null||t[f].seq!=null&&t[f].seq<l);)f++;t.splice(f,0,{seq:l,name:c}),h=f;for(let u of n)u.field>=h&&u.field++}for(let f of n)if(f.line==i.length&&f.from>r.index){let u=r[2]?3+(r[1]||"").length:2;f.from-=u,f.to-=u}n.push(new h0(h,i.length,r.index,r.index+c.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,h)=>{for(let c of n)c.line==i.length&&c.from>h&&(c.from--,c.to--);return a}),i.push(o)}return new Do(i,n)}}let c0=R.widget({widget:new class extends nt{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),f0=R.mark({class:"cm-snippetField"});class di{constructor(e,t){this.ranges=e,this.active=t,this.deco=R.set(e.map(i=>(i.from==i.to?c0:f0).range(i.from,i.to)),!0)}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new di(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const Ji=P.define({map(s,e){return s&&s.map(e)}}),u0=P.define(),Vi=fe.define({create(){return null},update(s,e){for(let t of e.effects){if(t.is(Ji))return t.value;if(t.is(u0)&&s)return new di(s.ranges,t.value)}return s&&e.docChanged&&(s=s.map(e.changes)),s&&e.selection&&!s.selectionInsideField(e.selection)&&(s=null),s},provide:s=>O.decorations.from(s,e=>e?e.deco:R.none)});function Oo(s,e){return y.create(s.filter(t=>t.field==e).map(t=>y.range(t.from,t.to)))}function d0(s){let e=Do.parse(s);return(t,i,n,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,n),{main:a}=t.state.selection,h={changes:{from:n,to:r==a.from?a.to:r,insert:W.of(o)},scrollIntoView:!0,annotations:i?[So.of(i),Q.userEvent.of("input.complete")]:void 0};if(l.length&&(h.selection=Oo(l,0)),l.some(c=>c.field>0)){let c=new di(l,0),f=h.effects=[Ji.of(c)];t.state.field(Vi,!1)===void 0&&f.push(P.appendConfig.of([Vi,y0,x0,nf]))}t.dispatch(t.state.update(h))}}function sf(s){return({state:e,dispatch:t})=>{let i=e.field(Vi,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return t(e.update({selection:Oo(i.ranges,n),effects:Ji.of(r?null:new di(i.ranges,n)),scrollIntoView:!0})),!0}}const p0=({state:s,dispatch:e})=>s.field(Vi,!1)?(e(s.update({effects:Ji.of(null)})),!0):!1,m0=sf(1),g0=sf(-1),b0=[{key:"Tab",run:m0,shift:g0},{key:"Escape",run:p0}],ca=T.define({combine(s){return s.length?s[0]:b0}}),y0=At.highest(lo.compute([ca],s=>s.facet(ca)));function Hb(s,e){return{...e,apply:d0(s)}}const x0=O.domEventHandlers({mousedown(s,e){let t=e.state.field(Vi,!1),i;if(!t||(i=e.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=t.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==t.active?!1:(e.dispatch({selection:Oo(t.ranges,n.field),effects:Ji.of(t.ranges.some(r=>r.field>n.field)?new di(t.ranges,n.field):null),scrollIntoView:!0}),!0)}}),zi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Et=P.define({map(s,e){let t=e.mapPos(s,-1,le.TrackAfter);return t??void 0}}),Bo=new class extends yt{};Bo.startSide=1;Bo.endSide=-1;const rf=fe.define({create(){return N.empty},update(s,e){if(s=s.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);s=s.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(Et)&&(s=s.update({add:[Bo.range(t.value,t.value+1)]}));return s}});function Vb(){return[w0,rf]}const Ys="()[]{}<>«»»«[]{}";function of(s){for(let e=0;e<Ys.length;e+=2)if(Ys.charCodeAt(e)==s)return Ys.charAt(e+1);return Ur(s<128?s:s+1)}function lf(s,e){return s.languageDataAt("closeBrackets",e)[0]||zi}const k0=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),w0=O.inputHandler.of((s,e,t,i)=>{if((k0?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&Ye(xe(i,0))==1||e!=n.from||t!=n.to)return!1;let r=S0(s.state,i);return r?(s.dispatch(r),!0):!1}),v0=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let i=lf(s,s.selection.main.head).brackets||zi.brackets,n=null,r=s.changeByRange(o=>{if(o.empty){let l=C0(s.doc,o.head);for(let a of i)if(a==l&&ws(s.doc,o.head)==of(xe(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:y.cursor(o.head-a.length)}}return{range:n=o}});return n||e(s.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!n},zb=[{key:"Backspace",run:v0}];function S0(s,e){let t=lf(s,s.selection.main.head),i=t.brackets||zi.brackets;for(let n of i){let r=of(xe(n,0));if(e==n)return r==n?T0(s,n,i.indexOf(n+n+n)>-1,t):A0(s,n,r,t.before||zi.before);if(e==r&&af(s,s.selection.main.from))return M0(s,n,r)}return null}function af(s,e){let t=!1;return s.field(rf).between(0,s.doc.length,i=>{i==e&&(t=!0)}),t}function ws(s,e){let t=s.sliceString(e,e+2);return t.slice(0,Ye(xe(t,0)))}function C0(s,e){let t=s.sliceString(e-2,e);return Ye(xe(t,0))==t.length?t:t.slice(1)}function A0(s,e,t,i){let n=null,r=s.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:Et.of(o.to+e.length),range:y.range(o.anchor+e.length,o.head+e.length)};let l=ws(s.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:Et.of(o.head+e.length),range:y.cursor(o.head+e.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function M0(s,e,t){let i=null,n=s.changeByRange(r=>r.empty&&ws(s.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:y.cursor(r.head+t.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function T0(s,e,t,i){let n=i.stringPrefixes||zi.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:Et.of(l.to+e.length),range:y.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=ws(s.doc,a),c;if(h==e){if(fa(s,a))return{changes:{insert:e+e,from:a},effects:Et.of(a+e.length),range:y.cursor(a+e.length)};if(af(s,a)){let u=t&&s.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:y.cursor(a+u.length)}}}else{if(t&&s.sliceDoc(a-2*e.length,a)==e+e&&(c=ua(s,a-2*e.length,n))>-1&&fa(s,c))return{changes:{insert:e+e+e+e,from:a},effects:Et.of(a+e.length),range:y.cursor(a+e.length)};if(s.charCategorizer(a)(h)!=Z.Word&&ua(s,a,n)>-1&&!D0(s,a,e,n))return{changes:{insert:e+e,from:a},effects:Et.of(a+e.length),range:y.cursor(a+e.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function fa(s,e){let t=ce(s).resolveInner(e+1);return t.parent&&t.from==e}function D0(s,e,t,i){let n=ce(s).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=s.sliceDoc(n.from,Math.min(n.to,n.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let c=n.firstChild;for(;c&&c.from==n.from&&c.to-c.from>t.length+a;){if(s.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=n.to==e&&n.parent;if(!h)break;n=h}return!1}function ua(s,e,t){let i=s.charCategorizer(e);if(i(s.sliceDoc(e-1,e))!=Z.Word)return e;for(let n of t){let r=e-n.length;if(s.sliceDoc(r,e)==n&&i(s.sliceDoc(r-1,r))!=Z.Word)return r}return-1}function $b(s={}){return[a0,ke,ie.of(s),o0,B0,nf]}const O0=[{key:"Ctrl-Space",run:_s},{mac:"Alt-`",run:_s},{mac:"Alt-i",run:_s},{key:"Escape",run:i0},{key:"ArrowDown",run:xn(!0)},{key:"ArrowUp",run:xn(!1)},{key:"PageDown",run:xn(!0,"page")},{key:"PageUp",run:xn(!1,"page")},{key:"Enter",run:t0}],B0=At.highest(lo.computeN([ie],s=>s.facet(ie).defaultKeymap?[O0]:[])),da=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class $i{constructor(e,t,i=0,n=e.length,r,o){this.test=o,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(da(l)):da,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return xe(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Ur(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=Ye(e);let n=this.normalize(t);if(n.length)for(let r=0,o=i,l=!0;;r++){let a=n.charCodeAt(r),h=this.match(a,o,l,this.bufferPos+this.bufferStart,r==n.length-1);if(h)return this.value=h,this;if(r==n.length-1)break;l&&r<t.length&&t.charCodeAt(r)==a?o++:l=!1}}}match(e,t,i,n,r){let o=null;for(let l=0;l<this.matches.length;){let a=this.matches[l],h=!1;this.query.charCodeAt(a.index)==e&&(a.index==this.query.length-1?o={from:a.from,to:n,precise:r&&a.precise}:(a.index++,h=!0)),h?l++:this.matches.splice(l,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?o={from:t,to:n,precise:i&&r}:this.matches.push({from:t,index:1,precise:i})),o&&this.test&&!this.test(o.from,o.to,this.buffer,this.bufferStart)&&(o=null),o}}typeof Symbol<"u"&&($i.prototype[Symbol.iterator]=function(){return this});const hf={from:-1,to:-1,match:/.*/.exec(""),precise:!0},Po="gm"+(/x/.unicode==null?"":"u");class cf{constructor(e,t,i,n=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=hf,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new ff(e,t,i,n,r);this.re=new RegExp(t,Po+(i?.ignoreCase?"i":"")),this.test=i?.test,this.iter=e.iter();let o=e.lineAt(n);this.curLineStart=o.from,this.matchPos=Jn(e,n),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,n=i+t[0].length;if(this.matchPos=Jn(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Js=new WeakMap;class ni{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let n=Js.get(e);if(!n||n.from>=i||n.to<=t){let l=new ni(t,e.sliceString(t,i));return Js.set(e,l),l}if(n.from==t&&n.to==i)return n;let{text:r,from:o}=n;return o>t&&(r=e.sliceString(t,o)+r,o=t),n.to<i&&(r+=e.sliceString(n.to,i)),Js.set(e,new ni(o,r)),new ni(t,r.slice(t-o,i-o))}}class ff{constructor(e,t,i,n,r){this.text=e,this.to=r,this.done=!1,this.value=hf,this.matchPos=Jn(e,n),this.re=new RegExp(t,Po+(i?.ignoreCase?"i":"")),this.test=i?.test,this.flat=ni.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,n=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,precise:!0,match:t},this.matchPos=Jn(this.text,n+(i==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=ni.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(cf.prototype[Symbol.iterator]=ff.prototype[Symbol.iterator]=function(){return this});function P0(s){try{return new RegExp(s,Po),!0}catch{return!1}}function Jn(s,e){if(e>=s.length)return e;let t=s.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}const R0=s=>{let{state:e}=s,t=String(e.doc.lineAt(s.state.selection.main.head).number),{close:i,result:n}=hp(s,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return n.then(r=>{let o=r&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(r.elements.line.value);if(!o){s.dispatch({effects:i});return}let l=e.doc.lineAt(e.selection.main.head),[,a,h,c,f]=o,u=c?+c.slice(1):0,d=h?+h:l.number;if(h&&f){let g=d/100;a&&(g=g*(a=="-"?-1:1)+l.number/e.doc.lines),d=Math.round(e.doc.lines*g)}else h&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=e.doc.line(Math.max(1,Math.min(e.doc.lines,d))),m=y.cursor(p.from+Math.max(0,Math.min(u,p.length)));s.dispatch({effects:[i,O.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},L0=({state:s,dispatch:e})=>{let{selection:t}=s,i=y.create(t.ranges.map(n=>s.wordAt(n.head)||y.cursor(n.head)),t.mainIndex);return i.eq(t)?!1:(e(s.update({selection:i})),!0)};function E0(s,e){let{main:t,ranges:i}=s.selection,n=s.wordAt(t.head),r=n&&n.from==t.from&&n.to==t.to;for(let o=!1,l=new $i(s.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new $i(s.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=s.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const I0=({state:s,dispatch:e})=>{let{ranges:t}=s.selection;if(t.some(r=>r.from===r.to))return L0({state:s,dispatch:e});let i=s.sliceDoc(t[0].from,t[0].to);if(s.selection.ranges.some(r=>s.sliceDoc(r.from,r.to)!=i))return!1;let n=E0(s,i);return n?(e(s.update({selection:s.selection.addRange(y.range(n.from,n.to),!1),effects:O.scrollIntoView(n.to)})),!0):!1},Kt=T.define({combine(s){return ft(s,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new _0(e),scrollToMatch:e=>O.scrollIntoView(e)})}});function qb(s){return s?[Kt.of(s),qr]:qr}class uf{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||P0(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
14
- `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new z0(this):new W0(this)}getCursor(e,t=0,i){let n=e.doc?e:V.create({doc:e});return i==null&&(i=n.doc.length),this.regexp?_t(this,n,t,i):Gt(this,n,t,i)}}class df{constructor(e){this.spec=e}}function N0(s,e,t){return(i,n,r,o)=>{if(t&&!t(i,n,r,o))return!1;let l=i>=o&&n<=o+r.length?r.slice(i-o,n-o):e.doc.sliceString(i,n);return s(l,e,i,n)}}function Gt(s,e,t,i){let n;return s.wholeWord&&(n=F0(e.doc,e.charCategorizer(e.selection.main.head))),s.test&&(n=N0(s.test,e,n)),new $i(e.doc,s.unquoted,t,i,s.caseSensitive?void 0:r=>r.toLowerCase(),n)}function F0(s,e){return(t,i,n,r)=>((r>t||r+n.length<i)&&(r=Math.max(0,t-2),n=s.sliceString(r,Math.min(s.length,i+2))),(e(Xn(n,t-r))!=Z.Word||e(Qn(n,t-r))!=Z.Word)&&(e(Qn(n,i-r))!=Z.Word||e(Xn(n,i-r))!=Z.Word))}class W0 extends df{constructor(e){super(e)}nextMatch(e,t,i){let n=Gt(this.spec,e,i,e.doc.length).nextOverlapping();if(n.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);n=Gt(this.spec,e,0,r).nextOverlapping()}return n.done||n.value.from==t&&n.value.to==i?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let r=Math.max(t,n-1e4-this.spec.unquoted.length),o=Gt(this.spec,e,r,n),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;n-=1e4}}prevMatch(e,t,i){let n=this.prevMatchInRange(e,0,t);return n||(n=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),n&&(n.from!=t||n.to!=i)?n:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Gt(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Gt(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function H0(s,e,t){return(i,n,r)=>(!t||t(i,n,r))&&s(r[0],e,i,n)}function _t(s,e,t,i){let n;return s.wholeWord&&(n=V0(e.charCategorizer(e.selection.main.head))),s.test&&(n=H0(s.test,e,n)),new cf(e.doc,s.search,{ignoreCase:!s.caseSensitive,test:n},t,i)}function Xn(s,e){return s.slice(ne(s,e,!1),e)}function Qn(s,e){return s.slice(e,ne(s,e))}function V0(s){return(e,t,i)=>!i[0].length||(s(Xn(i.input,i.index))!=Z.Word||s(Qn(i.input,i.index))!=Z.Word)&&(s(Qn(i.input,i.index+i[0].length))!=Z.Word||s(Xn(i.input,i.index+i[0].length))!=Z.Word)}class z0 extends df{nextMatch(e,t,i){let n=_t(this.spec,e,i,e.doc.length).next();return n.done&&(n=_t(this.spec,e,0,t).next()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=1;;n++){let r=Math.max(t,i-n*1e4),o=_t(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let n=i.length;n>0;n--){let r=+i.slice(0,n);if(r>0&&r<e.match.length)return e.match[r]+i.slice(n)}return t})}matchAll(e,t){let i=_t(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=_t(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const qi=P.define(),Ro=P.define(),it=fe.define({create(s){return new Xs(ts(s).create(),null)},update(s,e){for(let t of e.effects)t.is(qi)?s=new Xs(t.value.create(),s.panel):t.is(Ro)&&(s=new Xs(s.query,t.value?Lo:null));return s},provide:s=>Ei.from(s,e=>e.panel)});function Kb(s){let e=s.field(it,!1);return e?e.query.spec:ts(s)}function Ub(s){var e;return((e=s.field(it,!1))===null||e===void 0?void 0:e.panel)!=null}class Xs{constructor(e,t){this.query=e,this.panel=t}}const $0=R.mark({class:"cm-searchMatch"}),q0=R.mark({class:"cm-searchMatch cm-searchMatch-selected"}),K0=te.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(it))}update(s){let e=s.state.field(it);(e!=s.startState.field(it)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:s,panel:e}){if(!e||!s.spec.valid)return R.none;let{view:t}=this,i=new at;for(let n=0,r=t.visibleRanges,o=r.length;n<o;n++){let{from:l,to:a}=r[n];for(;n<o-1&&a>r[n+1].from-500;)a=r[++n].to;s.highlight(t.state,l,a,(h,c)=>{let f=t.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?q0:$0)})}return i.finish()}},{decorations:s=>s.decorations});function Xi(s){return e=>{let t=e.state.field(it,!1);return t&&t.query.spec.valid?s(e,t):gf(e)}}const Zn=Xi((s,{query:e})=>{let{to:t}=s.state.selection.main,i=e.nextMatch(s.state,t,t);if(!i)return!1;let n=y.single(i.from,i.to),r=s.state.facet(Kt);return s.dispatch({selection:n,effects:[Eo(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),mf(s),!0}),es=Xi((s,{query:e})=>{let{state:t}=s,{from:i}=t.selection.main,n=e.prevMatch(t,i,i);if(!n)return!1;let r=y.single(n.from,n.to),o=s.state.facet(Kt);return s.dispatch({selection:r,effects:[Eo(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),mf(s),!0}),U0=Xi((s,{query:e})=>{let t=e.matchAll(s.state,1e3);return!t||!t.length?!1:(s.dispatch({selection:y.create(t.map(i=>y.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),j0=({state:s,dispatch:e})=>{let t=s.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:n}=t.main,r=[],o=0;for(let l=new $i(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(y.range(l.value.from,l.value.to))}return e(s.update({selection:y.create(r,o),userEvent:"select.search.matches"})),!0},pa=Xi((s,{query:e})=>{let{state:t}=s,{from:i,to:n}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=r,l=[],a,h,c=[];o.precise?o.from==i&&o.to==n&&(h=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),o=e.nextMatch(t,o.from,o.to),c.push(O.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))):o=e.nextMatch(t,o.from,o.to);let f=s.state.changes(l);return o&&(a=y.single(o.from,o.to).map(f),c.push(Eo(s,o)),c.push(t.facet(Kt).scrollToMatch(a.main,s))),s.dispatch({changes:f,selection:a,effects:c,userEvent:"input.replace"}),!0}),G0=Xi((s,{query:e})=>{if(s.state.readOnly)return!1;let t=[];for(let n of e.matchAll(s.state,1e9)){let{from:r,to:o,precise:l}=n;l&&t.push({from:r,to:o,insert:e.getReplacement(n)})}if(!t.length)return!1;let i=s.state.phrase("replaced $ matches",t.length)+".";return s.dispatch({changes:t,effects:O.announce.of(i),userEvent:"input.replace.all"}),!0});function Lo(s){return s.state.facet(Kt).createPanel(s)}function ts(s,e){var t,i,n,r,o;let l=s.selection.main,a=l.empty||l.to>l.from+100?"":s.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=s.facet(Kt);return new uf({search:((t=e?.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(n=e?.literal)!==null&&n!==void 0?n:h.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function pf(s){let e=Kh(s,Lo);return e&&e.dom.querySelector("[main-field]")}function mf(s){let e=pf(s);e&&e==s.root.activeElement&&e.select()}const gf=s=>{let e=s.state.field(it,!1);if(e&&e.panel){let t=pf(s);if(t&&t!=s.root.activeElement){let i=ts(s.state,e.query.spec);i.valid&&s.dispatch({effects:qi.of(i)}),t.focus(),t.select()}}else s.dispatch({effects:[Ro.of(!0),e?qi.of(ts(s.state,e.query.spec)):P.appendConfig.of(qr)]});return!0},bf=s=>{let e=s.state.field(it,!1);if(!e||!e.panel)return!1;let t=Kh(s,Lo);return t&&t.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:Ro.of(!1)}),!0},jb=[{key:"Mod-f",run:gf,scope:"editor search-panel"},{key:"F3",run:Zn,shift:es,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Zn,shift:es,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:bf,scope:"editor search-panel"},{key:"Mod-Shift-l",run:j0},{key:"Mod-Alt-g",run:R0},{key:"Mod-d",run:I0,preventDefault:!0}];class _0{constructor(e){this.view=e;let t=this.query=e.state.field(it).query.spec;this.commit=this.commit.bind(this),this.searchField=$("input",{value:t.search,placeholder:Ce(e,"Find"),"aria-label":Ce(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=$("input",{value:t.replace,placeholder:Ce(e,"Replace"),"aria-label":Ce(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=$("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=$("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=$("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(n,r,o){return $("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=$("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>Zn(e),[Ce(e,"next")]),i("prev",()=>es(e),[Ce(e,"previous")]),i("select",()=>U0(e),[Ce(e,"all")]),$("label",null,[this.caseField,Ce(e,"match case")]),$("label",null,[this.reField,Ce(e,"regexp")]),$("label",null,[this.wordField,Ce(e,"by word")]),...e.state.readOnly?[]:[$("br"),this.replaceField,i("replace",()=>pa(e),[Ce(e,"replace")]),i("replaceAll",()=>G0(e),[Ce(e,"replace all")])],$("button",{name:"close",onclick:()=>bf(e),"aria-label":Ce(e,"close"),type:"button"},["×"])])}commit(){let e=new uf({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:qi.of(e)}))}keydown(e){Pd(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?es:Zn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),pa(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(qi)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Kt).top}}function Ce(s,e){return s.state.phrase(e)}const kn=30,wn=/[\s\.,:;?!]/;function Eo(s,{from:e,to:t}){let i=s.state.doc.lineAt(e),n=s.state.doc.lineAt(t).to,r=Math.max(i.from,e-kn),o=Math.min(n,t+kn),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<kn;a++)if(!wn.test(l[a+1])&&wn.test(l[a])){l=l.slice(a);break}}if(o!=n){for(let a=l.length-1;a>l.length-kn;a--)if(!wn.test(l[a-1])&&wn.test(l[a])){l=l.slice(0,a);break}}return O.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const Y0=O.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"}}),qr=[it,At.low(K0),Y0];function yf(s){function e(f,u){f.cmdState.push(u)}function t(f){return f.cmdState.length>0?f.cmdState[f.cmdState.length-1]:null}function i(f){var u=f.cmdState.pop();u&&u.closeBracket()}function n(f){for(var u=f.cmdState,d=u.length-1;d>=0;d--){var p=u[d];if(p.name!="DEFAULT")return p}return{styleIdentifier:function(){return null}}}function r(f,u,d){return function(){this.name=f,this.bracketNo=0,this.style=u,this.styles=d,this.argument=null,this.styleIdentifier=function(){return this.styles[this.bracketNo-1]||null},this.openBracket=function(){return this.bracketNo++,"bracket"},this.closeBracket=function(){}}}var o={};o.importmodule=r("importmodule","tag",["string","builtin"]),o.documentclass=r("documentclass","tag",["","atom"]),o.usepackage=r("usepackage","tag",["atom"]),o.begin=r("begin","tag",["atom"]),o.end=r("end","tag",["atom"]),o.label=r("label","tag",["atom"]),o.ref=r("ref","tag",["atom"]),o.eqref=r("eqref","tag",["atom"]),o.cite=r("cite","tag",["atom"]),o.bibitem=r("bibitem","tag",["atom"]),o.Bibitem=r("Bibitem","tag",["atom"]),o.RBibitem=r("RBibitem","tag",["atom"]),o.DEFAULT=function(){this.name="DEFAULT",this.style="tag",this.styleIdentifier=this.openBracket=this.closeBracket=function(){}};function l(f,u){f.f=u}function a(f,u){var d;if(f.match(/^\\[a-zA-Z@\xc0-\u1fff\u2060-\uffff]+/)){var p=f.current().slice(1);return d=o.hasOwnProperty(p)?o[p]:o.DEFAULT,d=new d,e(u,d),l(u,c),d.style}if(f.match(/^\\[$&%#{}_]/)||f.match(/^\\[,;!\/\\]/))return"tag";if(f.match("\\["))return l(u,function(g,b){return h(g,b,"\\]")}),"keyword";if(f.match("\\("))return l(u,function(g,b){return h(g,b,"\\)")}),"keyword";if(f.match("$$"))return l(u,function(g,b){return h(g,b,"$$")}),"keyword";if(f.match("$"))return l(u,function(g,b){return h(g,b,"$")}),"keyword";var m=f.next();if(m=="%")return f.skipToEnd(),"comment";if(m=="}"||m=="]"){if(d=t(u),d)d.closeBracket(m),l(u,c);else return"error";return"bracket"}else return m=="{"||m=="["?(d=o.DEFAULT,d=new d,e(u,d),"bracket"):/\d/.test(m)?(f.eatWhile(/[\w.%]/),"atom"):(f.eatWhile(/[\w\-_]/),d=n(u),d.name=="begin"&&(d.argument=f.current()),d.styleIdentifier())}function h(f,u,d){if(f.eatSpace())return null;if(d&&f.match(d))return l(u,a),"keyword";if(f.match(/^\\[a-zA-Z@]+/))return"tag";if(f.match(/^[a-zA-Z]+/))return"variableName.special";if(f.match(/^\\[$&%#{}_]/)||f.match(/^\\[,;!\/]/)||f.match(/^[\^_&]/))return"tag";if(f.match(/^[+\-<>|=,\/@!*:;'"`~#?]/))return null;if(f.match(/^(\d+\.\d*|\d*\.\d+|\d+)/))return"number";var p=f.next();return p=="{"||p=="}"||p=="["||p=="]"||p=="("||p==")"?"bracket":p=="%"?(f.skipToEnd(),"comment"):"error"}function c(f,u){var d=f.peek(),p;return d=="{"||d=="["?(p=t(u),p.openBracket(d),f.eat(d),l(u,a),"bracket"):/[ \t\r]/.test(d)?(f.eat(d),null):(l(u,a),i(u),a(f,u))}return{name:"stex",startState:function(){var f=s?function(u,d){return h(u,d)}:a;return{cmdState:[],f}},copyState:function(f){return{cmdState:f.cmdState.slice(),f:f.f}},token:function(f,u){return u.f(f,u)},blankLine:function(f){f.f=a,f.cmdState.length=0},languageData:{commentTokens:{line:"%"}}}}const Gb=yf(!1);yf(!0);class ma{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class Pt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(et).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((d,p)=>d.from-p.from||d.to-p.to),o=new at,l=[],a=0,h=i.doc.iter(),c=0,f=i.doc.length;for(let d=0;;){let p=d==r.length?null:r[d];if(!p&&!l.length)break;let m,g;if(l.length)m=a,g=l.reduce((k,D)=>Math.min(k,D.to),p&&p.from>m?p.from:1e8);else{if(m=p.from,m>f)break;g=p.to,l.push(p),d++}for(;d<r.length;){let k=r[d];if(k.from==m&&(k.to>k.from||k.to==m))l.push(k),d++,g=Math.min(k.to,g);else{g=Math.min(k.from,g);break}}g=Math.min(g,f);let b=!1;if(l.some(k=>k.from==m&&(k.to==g||g==f))&&(b=m==g,!b&&g-m<10)){let k=m-(c+h.value.length);k>0&&(h.next(k),c=m);for(let D=m;;){if(D>=g){b=!0;break}if(!h.lineBreak&&c+h.value.length>D)break;D=c+h.value.length,c+=h.value.length,h.next()}}let x=ab(l);if(b)o.add(m,m,R.widget({widget:new sb(x),diagnostics:l.slice()}));else{let k=l.reduce((D,w)=>w.markClass?D+" "+w.markClass:D,"");o.add(m,g,R.mark({class:"cm-lintRange cm-lintRange-"+x+k,diagnostics:l.slice(),inclusiveEnd:l.some(D=>D.to>g)}))}if(a=g,a==f)break;for(let k=0;k<l.length;k++)l[k].to<=a&&l.splice(k--,1)}let u=o.finish();return new Pt(u,t,fi(u))}}function fi(s,e=null,t=0){let i=null;return s.between(t,1e9,(n,r,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!i)i=new ma(n,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new ma(i.from,r,i.diagnostic)}}),i}function J0(s,e){let t=e.pos,i=e.end||t,n=s.state.facet(et).hideOn(s,t,i);if(n!=null)return n;let r=s.startState.doc.lineAt(e.pos);return!!(s.effects.some(o=>o.is(Io))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function X0(s,e){return s.field(We,!1)?e:e.concat(P.appendConfig.of(Sf))}function Q0(s,e){return{effects:X0(s,[Io.of(e)])}}const Io=P.define(),xf=P.define(),kf=P.define(),We=fe.define({create(){return new Pt(R.none,null,null)},update(s,e){if(e.docChanged&&s.diagnostics.size){let t=s.diagnostics.map(e.changes),i=null,n=s.panel;if(s.selected){let r=e.changes.mapPos(s.selected.from,1);i=fi(t,s.selected.diagnostic,r)||fi(t,null,r)}!t.size&&n&&e.state.facet(et).autoPanel&&(n=null),s=new Pt(t,n,i)}for(let t of e.effects)if(t.is(Io)){let i=e.state.facet(et).autoPanel?t.value.length?is.open:null:s.panel;s=Pt.init(t.value,i,e.state)}else t.is(xf)?s=new Pt(s.diagnostics,t.value?is.open:null,s.selected):t.is(kf)&&(s=new Pt(s.diagnostics,s.panel,t.value));return s},provide:s=>[Ei.from(s,e=>e.panel),O.decorations.from(s,e=>e.diagnostics)]}),Z0=R.mark({class:"cm-lintRange cm-lintRange-active"});function eb(s,e,t){let{diagnostics:i}=s.state.field(We),n,r=-1,o=-1;i.between(e-(t<0?1:0),e+(t>0?1:0),(a,h,{spec:c})=>{if(e>=a&&e<=h&&(a==h||(e>a||t>0)&&(e<h||t<0)))return n=c.diagnostics,r=a,o=h,!1});let l=s.state.facet(et).tooltipFilter;return n&&l&&(n=l(n,s.state)),n?{pos:r,end:o,above:!0,create(){return{dom:tb(s,n)}}}:null}function tb(s,e){return $("ul",{class:"cm-tooltip-lint"},e.map(t=>vf(s,t,!1)))}const ga=s=>{let e=s.state.field(We,!1);return!e||!e.panel?!1:(s.dispatch({effects:xf.of(!1)}),!0)},ib=te.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:e}=s.state.facet(et);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(et);t.length&&nb(t.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==e.doc&&this.view.dispatch(Q0(this.view.state,i.reduce((n,r)=>n.concat(r))))},i=>{me(this.view.state,i)})}}update(s){let e=s.state.facet(et);(s.docChanged||e!=s.startState.facet(et)||e.needsRefresh&&e.needsRefresh(s))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function nb(s,e,t){let i=[],n=-1;for(let r of s)r.then(o=>{i.push(o),clearTimeout(n),i.length==s.length?e(i):n=setTimeout(()=>e(i),200)},t)}const et=T.define({combine(s){return{sources:s.map(e=>e.source).filter(e=>e!=null),...ft(s.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ba,tooltipFilter:ba,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})}}});function ba(s,e){return s?e?(t,i)=>e(s(t,i),i):s:e}function _b(s,e={}){return[et.of({source:s,config:e}),ib,Sf]}function wf(s){let e=[];if(s)e:for(let{name:t}of s){for(let i=0;i<t.length;i++){let n=t[i];if(/[a-zA-Z]/.test(n)&&!e.some(r=>r.toLowerCase()==n.toLowerCase())){e.push(n);continue e}}e.push("")}return e}function vf(s,e,t){var i;let n=t?wf(e.actions):[];return $("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},$("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(s):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=d=>{if(d.preventDefault(),l)return;l=!0;let p=fi(s.state.field(We).diagnostics,e);p&&r.apply(s,p.from,p.to)},{name:h}=r,c=n[o]?h.indexOf(n[o]):-1,f=c<0?h:[h.slice(0,c),$("u",h.slice(c,c+1)),h.slice(c+1)],u=r.markClass?" "+r.markClass:"";return $("button",{type:"button",class:"cm-diagnosticAction"+u,onclick:a,onmousedown:a,"aria-label":` Action: ${h}${c<0?"":` (access key "${n[o]})"`}.`},f)}),e.source&&$("div",{class:"cm-diagnosticSource"},e.source))}class sb extends nt{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return $("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ya{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=vf(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class is{constructor(e){this.view=e,this.items=[];let t=n=>{if(!(n.ctrlKey||n.altKey||n.metaKey)){if(n.keyCode==27)ga(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=wf(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==n.keyCode){let a=fi(this.view.state.field(We).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;n.preventDefault()}},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=$("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=$("div",{class:"cm-panel-lint"},this.list,$("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>ga(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(We).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(We),i=0,n=!1,r=null,o=new Set;for(e.between(0,this.view.state.doc.length,(l,a,{spec:h})=>{for(let c of h.diagnostics){if(o.has(c))continue;o.add(c);let f=-1,u;for(let d=i;d<this.items.length;d++)if(this.items[d].diagnostic==c){f=d;break}f<0?(u=new ya(this.view,c),this.items.splice(i,0,u),n=!0):(u=this.items[f],f>i&&(this.items.splice(i,f-i),n=!0)),t&&u.diagnostic==t.diagnostic?u.dom.hasAttribute("aria-selected")||(u.dom.setAttribute("aria-selected","true"),r=u):u.dom.hasAttribute("aria-selected")&&u.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new ya(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:a})=>{let h=a.height/this.list.offsetHeight;l.top<a.top?this.list.scrollTop-=(a.top-l.top)/h:l.bottom>a.bottom&&(this.list.scrollTop+=(l.bottom-a.bottom)/h)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(We),i=fi(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:kf.of(i)})}static open(e){return new is(e)}}function rb(s,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(s)}</svg>')`}function vn(s){return rb(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const ob=O.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-diagnostic-hint":{borderLeft:"5px solid #66d"},".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:vn("#f11")},".cm-lintRange-warning":{backgroundImage:vn("orange")},".cm-lintRange-info":{backgroundImage:vn("#999")},".cm-lintRange-hint":{backgroundImage:vn("#66d")},".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-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".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}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function lb(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function ab(s){let e="hint",t=1;for(let i of s){let n=lb(i.severity);n>t&&(t=n,e=i.severity)}return e}const hb=lp(eb,{hideOn:J0}),Sf=[We,O.decorations.compute([We],s=>{let{selected:e,panel:t}=s.field(We);return!e||!t||e.from==e.to?R.none:R.set([Z0.range(e.from,e.to)])}),hb,ob];var xa={};class ns{constructor(e,t,i,n,r,o,l,a,h,c=0,f){this.p=e,this.stack=t,this.state=i,this.reducePos=n,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=a,this.curContext=h,this.lookAhead=c,this.parent=f}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let n=e.parser.context;return new ns(e,[],t,i,i,0,[],0,n?new ka(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,n=e&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(n);if(l&&(this.score+=l),i==0){n<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(n,this.reducePos);return}let a=this.stack.length-(i-1)*3-(e&262144?6:0),h=a?this.stack[a-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&h==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let c=this.reducePos-h;c>=2e3&&!(!((t=this.p.parser.nodeSet.types[n])===null||t===void 0)&&t.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=c));let f=a?this.stack[a-1]:0,u=this.bufferBase+this.buffer.length-f;if(n<r.minRepeatTerm||e&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,h,d,u+4,!0)}if(e&262144)this.state=this.stack[a];else{let d=this.stack[a-3];this.state=r.getGoto(d,n,!0)}for(;this.stack.length>a;)this.stack.pop();this.reduceContext(n,h)}storeNode(e,t,i,n=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this.buffer.length;if(o>0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(t==i)return;if(this.buffer[o-2]>=t){this.buffer[o-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,n);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let a=o;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,n>4&&(n-=4)}this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=n}}shift(e,t,i,n){if(e&131072)this.pushState(e&65535,this.pos);else if((e&262144)==0){let r=e,{parser:o}=this.p;this.pos=n;let l=o.stateFlag(r,1);!l&&(n>i||t<=o.maxNode)&&(this.reducePos=n),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,n,4)}else this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4)}apply(e,t,i,n){e&65536?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(t&&e.buffer[t-4]==0&&(t-=4);t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new ns(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new cb(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if((i&65536)==0)return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&n.push(t[r],o);if(this.stack.length<120)for(let r=0;n.length<8&&r<t.length;r+=2){let o=t[r+1];n.some((l,a)=>a&1&&l==o)||n.push(t[r],o)}t=n}let i=[];for(let n=0;n<t.length&&i.length<4;n+=2){let r=t[n+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[n],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if((t&65536)==0)return!1;if(!e.validAction(this.state,t)){let i=t>>19,n=t&65535,r=this.stack.length-i*3;if(r<0||e.getGoto(this.stack[r],n,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(n,r)=>{if(!t.includes(n))return t.push(n),e.allActions(n,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let a=o&65535,h=this.stack.length-l*3;if(h>=0&&e.getGoto(this.stack[h],a,!1)>=0)return l<<19|65536|a}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new ka(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class ka{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class cb{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let n=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=n}}class ss{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new ss(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}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]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new ss(this.stack,this.pos,this.index)}}function Sn(s,e=Uint16Array){if(typeof s!="string")return s;let t=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let o=s.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),r+=a,l)break;r*=46}t?t[n++]=r:t=new e(r)}return t}class Pn{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const wa=new Pn;class fb{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=wa,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,n=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!n)return null;let o=this.ranges[--n];r-=i.from-o.to,i=o}for(;t<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let o=this.ranges[++n];r+=o.from-i.to,i=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,n;if(t>=0&&t<this.chunk.length)i=this.pos+e,n=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)n=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),n=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),n}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=wa,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let n of this.ranges){if(n.from>=t)break;n.to>e&&(i+=this.input.read(Math.max(n.from,e),Math.min(n.to,t)))}return i}}class si{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;ub(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}si.prototype.contextual=si.prototype.fallback=si.prototype.extend=!1;si.prototype.fallback=si.prototype.extend=!1;function ub(s,e,t,i,n,r){let o=0,l=1<<i,{dialect:a}=t.p.parser;e:for(;(l&s[o])!=0;){let h=s[o+1];for(let d=o+3;d<h;d+=2)if((s[d+1]&l)>0){let p=s[d];if(a.allows(p)&&(e.token.value==-1||e.token.value==p||db(p,e.token.value,n,r))){e.acceptToken(p);break}}let c=e.next,f=0,u=s[o+2];if(e.next<0&&u>f&&s[h+u*3-3]==65535){o=s[h+u*3-1];continue e}for(;f<u;){let d=f+u>>1,p=h+d+(d<<1),m=s[p],g=s[p+1]||65536;if(c<m)u=d;else if(c>=g)f=d+1;else{o=s[p+2],e.advance();continue e}}break}}function va(s,e,t){for(let i=e,n;(n=s[i])!=65535;i++)if(n==t)return i-e;return-1}function db(s,e,t,i){let n=va(t,i,e);return n<0||va(t,i,s)<n}const Ae=typeof process<"u"&&xa&&/\bparse\b/.test(xa.LOG);let Qs=null;function Sa(s,e,t){let i=s.cursor(Y.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(s.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:s.length}}class pb{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?Sa(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Sa(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],n=this.index[t];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],o=this.start[t]+i.positions[n];if(o>e)return this.nextStart=o,null;if(r instanceof q){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let a=r.prop(E.lookAhead);if(!a||l+a<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}}class mb{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new Pn)}getActions(e){let t=0,i=null,{parser:n}=e.p,{tokenizers:r}=n,o=n.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let h=0;h<r.length;h++){if((1<<h&o)==0)continue;let c=r[h],f=this.tokens[h];if(!(i&&!c.fallback)&&((c.contextual||f.start!=e.pos||f.mask!=o||f.context!=l)&&(this.updateCachedToken(f,c,e),f.mask=o,f.context=l),f.lookAhead>f.end+25&&(a=Math.max(f.lookAhead,a)),f.value!=0)){let u=t;if(f.extended>-1&&(t=this.addActions(e,f.extended,f.end,t)),t=this.addActions(e,f.value,f.end,t),!c.extend&&(i=f,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new Pn,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new Pn,{pos:i,p:n}=e;return t.start=i,t.end=Math.min(i+1,n.stream.end),t.value=i==n.stream.end?n.parser.eofTerm:0,t}updateCachedToken(e,t,i){let n=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(n,e),i),e.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?e.value=l>>1:e.extended=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(n+1)}putAction(e,t,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==e)return n;return this.actions[n++]=e,this.actions[n++]=t,this.actions[n++]=i,n}addActions(e,t,i,n){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let h=o.stateSlot(r,a?2:1);;h+=3){if(l[h]==65535)if(l[h+1]==1)h=rt(l,h+2);else{n==0&&l[h+1]==2&&(n=this.putAction(rt(l,h+2),t,i,n));break}l[h]==t&&(n=this.putAction(rt(l,h+1),t,i,n))}return n}}class gb{constructor(e,t,i,n){this.parser=e,this.input=t,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new fb(t,n),this.tokens=new mb(e,this.stream),this.topTerm=e.top[1];let{from:r}=n[0];this.stacks=[ns.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>e.bufferLength*4?new pb(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],n,r;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{n||(n=[],r=[]),n.push(l);let a=this.tokens.getMainToken(l);r.push(a.value,a.end)}}break}}if(!i.length){let o=n&&yb(n);if(o)return Ae&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw Ae&&n&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&n){let o=this.stoppedAt!=null&&n[0].pos>this.stoppedAt?n[0]:this.runRecovery(n,r,i);if(o)return Ae&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,a)=>a.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let a=o+1;a<i.length;a++){let h=i[a];if(l.sameState(h)||l.buffer.length>500&&h.buffer.length>500)if((l.score-h.score||l.buffer.length-h.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let n=e.pos,{parser:r}=this,o=Ae?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let h=e.curContext&&e.curContext.tracker.strict,c=h?e.curContext.hash:0;for(let f=this.fragments.nodeAt(n);f;){let u=this.parser.nodeSet.types[f.type.id]==f.type?r.getGoto(e.state,f.type.id):-1;if(u>-1&&f.length&&(!h||(f.prop(E.contextHash)||0)==c))return e.useNode(f,u),Ae&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(f.type.id)})`),!0;if(!(f instanceof q)||f.children.length==0||f.positions[0]>0)break;let d=f.children[0];if(d instanceof q&&f.positions[0]==0)f=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),Ae&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let h=0;h<a.length;){let c=a[h++],f=a[h++],u=a[h++],d=h==a.length||!i,p=d?e:e.split(),m=this.tokens.mainToken;if(p.apply(c,f,m?m.start:p.pos,u),Ae&&console.log(o+this.stackID(p)+` (via ${(c&65536)==0?"shift":`reduce of ${r.getName(c&65535)}`} for ${r.getName(f)} @ ${n}${p==e?"":", split"})`),d)return!0;p.pos>n?t.push(p):i.push(p)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return Ca(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],h=t[(o<<1)+1],c=Ae?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),Ae&&console.log(c+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let f=l.split(),u=c;for(let d=0;d<10&&f.forceReduce()&&(Ae&&console.log(u+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,i));d++)Ae&&(u=this.stackID(f)+" -> ");for(let d of l.recoverByInsert(a))Ae&&console.log(c+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(h==l.pos&&(h++,a=0),l.recoverByDelete(a,h),Ae&&console.log(c+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),Ca(l,i)):(!n||n.score<f.score)&&(n=f)}return n}stackToTree(e){return e.close(),q.build({buffer:ss.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(Qs||(Qs=new WeakMap)).get(e);return t||Qs.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function Ca(s,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==s.pos&&i.sameState(s)){e[t].score<s.score&&(e[t]=s);return}}e.push(s)}class bb{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}}class Kr extends po{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),n=[];for(let l=0;l<t.length;l++)n.push([]);function r(l,a,h){n[l].push([a,a.deserialize(String(h))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=E[a]);for(let h=1;h<l.length;){let c=l[h++];if(c>=0)r(c,a,l[h++]);else{let f=l[h+-c];for(let u=-c;u>0;u--)r(l[h++],a,f);h++}}}this.nodeSet=new us(t.map((l,a)=>ye.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:n[a],top:i.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Jh;let o=Sn(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Aa),this.states=Sn(e.states,Uint32Array),this.data=Sn(e.stateData),this.goto=Sn(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new si(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let n=new gb(this,e,t,i);for(let r of this.wrappers)n=r(n,e,t,i);return n}getGoto(e,t,i=!1){let n=this.goto;if(t>=n[0])return-1;for(let r=n[t+1];;){let o=n[r++],l=o&1,a=n[r++];if(l&&i)return a;for(let h=r+(o>>1);r<h;r++)if(n[r]==e)return a;if(l)return-1}}hasAction(e,t){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(e,n?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=rt(i,r+2)];else{if(i[r+1]==2)return rt(i,r+2);break}if(o==t||o==0)return rt(i,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),n=i?t(i):void 0;for(let r=this.stateSlot(e,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=rt(this.data,r+2);else break;n=t(rt(this.data,r+1))}return n}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=rt(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];t.some((r,o)=>o&1&&r==n)||t.push(this.data[i],n)}}return t}configure(e){let t=Object.assign(Object.create(Kr.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let n=e.tokenizers.find(r=>r.from==i);return n?n.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=e.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[n]=Aa(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(i[o]=!0)}let n=null;for(let r=0;r<t.length;r++)if(!i[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[l]=1;return new bb(e,i,n)}static deserialize(e){return new Kr(e)}}function rt(s,e){return s[e]|s[e+1]<<16}function yb(s){let e=null;for(let t of s){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function Aa(s){if(s.external){let e=s.extend?1:0;return(t,i)=>s.external(t,i)<<1|e}return s.get}export{W as $,ct as A,bc as B,Ir as C,R as D,O as E,T as F,sc as G,Yp as H,Db as I,Pp as J,M as K,Kr as L,le as M,ce as N,lp as O,At as P,Hb as Q,at as R,fe as S,_b as T,Lb as U,te as V,nt as W,Gb as X,_p as Y,V as Z,Q as _,qi as a,So as a0,rs as a1,Bb as a2,Ib as a3,kb as a4,Sb as a5,vb as a6,Pb as a7,Vb as a8,Tb as a9,qb as aa,$b as ab,lo as ac,zb as ad,O0 as ae,jb as af,Ob as ag,Wb as ah,Nb as ai,gf as aj,bp as ak,Cb as al,Ub as am,Rb as an,vt as ao,Kb as ap,y as b,Lg as c,Ym as d,_m as e,Zp as f,Fb as g,uf as h,Rg as i,ds as j,Ab as k,P as l,Qe as m,wb as n,cf as o,j as p,gc as q,Pg as r,Ei as s,na as t,Oc as u,Tm as v,Mc as w,Vr as x,Pd as y,N as z};
14
+ `:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new z0(this):new W0(this)}getCursor(e,t=0,i){let n=e.doc?e:V.create({doc:e});return i==null&&(i=n.doc.length),this.regexp?_t(this,n,t,i):Gt(this,n,t,i)}}class df{constructor(e){this.spec=e}}function N0(s,e,t){return(i,n,r,o)=>{if(t&&!t(i,n,r,o))return!1;let l=i>=o&&n<=o+r.length?r.slice(i-o,n-o):e.doc.sliceString(i,n);return s(l,e,i,n)}}function Gt(s,e,t,i){let n;return s.wholeWord&&(n=F0(e.doc,e.charCategorizer(e.selection.main.head))),s.test&&(n=N0(s.test,e,n)),new $i(e.doc,s.unquoted,t,i,s.caseSensitive?void 0:r=>r.toLowerCase(),n)}function F0(s,e){return(t,i,n,r)=>((r>t||r+n.length<i)&&(r=Math.max(0,t-2),n=s.sliceString(r,Math.min(s.length,i+2))),(e(Xn(n,t-r))!=Z.Word||e(Qn(n,t-r))!=Z.Word)&&(e(Qn(n,i-r))!=Z.Word||e(Xn(n,i-r))!=Z.Word))}class W0 extends df{constructor(e){super(e)}nextMatch(e,t,i){let n=Gt(this.spec,e,i,e.doc.length).nextOverlapping();if(n.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);n=Gt(this.spec,e,0,r).nextOverlapping()}return n.done||n.value.from==t&&n.value.to==i?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let r=Math.max(t,n-1e4-this.spec.unquoted.length),o=Gt(this.spec,e,r,n),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;n-=1e4}}prevMatch(e,t,i){let n=this.prevMatchInRange(e,0,t);return n||(n=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),n&&(n.from!=t||n.to!=i)?n:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Gt(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Gt(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function H0(s,e,t){return(i,n,r)=>(!t||t(i,n,r))&&s(r[0],e,i,n)}function _t(s,e,t,i){let n;return s.wholeWord&&(n=V0(e.charCategorizer(e.selection.main.head))),s.test&&(n=H0(s.test,e,n)),new cf(e.doc,s.search,{ignoreCase:!s.caseSensitive,test:n},t,i)}function Xn(s,e){return s.slice(ne(s,e,!1),e)}function Qn(s,e){return s.slice(e,ne(s,e))}function V0(s){return(e,t,i)=>!i[0].length||(s(Xn(i.input,i.index))!=Z.Word||s(Qn(i.input,i.index))!=Z.Word)&&(s(Qn(i.input,i.index+i[0].length))!=Z.Word||s(Xn(i.input,i.index+i[0].length))!=Z.Word)}class z0 extends df{nextMatch(e,t,i){let n=_t(this.spec,e,i,e.doc.length).next();return n.done&&(n=_t(this.spec,e,0,t).next()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=1;;n++){let r=Math.max(t,i-n*1e4),o=_t(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let n=i.length;n>0;n--){let r=+i.slice(0,n);if(r>0&&r<e.match.length)return e.match[r]+i.slice(n)}return t})}matchAll(e,t){let i=_t(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=_t(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const qi=P.define(),Ro=P.define(),it=fe.define({create(s){return new Xs(ts(s).create(),null)},update(s,e){for(let t of e.effects)t.is(qi)?s=new Xs(t.value.create(),s.panel):t.is(Ro)&&(s=new Xs(s.query,t.value?Lo:null));return s},provide:s=>Ei.from(s,e=>e.panel)});function Kb(s){let e=s.field(it,!1);return e?e.query.spec:ts(s)}function Ub(s){var e;return((e=s.field(it,!1))===null||e===void 0?void 0:e.panel)!=null}class Xs{constructor(e,t){this.query=e,this.panel=t}}const $0=R.mark({class:"cm-searchMatch"}),q0=R.mark({class:"cm-searchMatch cm-searchMatch-selected"}),K0=te.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(it))}update(s){let e=s.state.field(it);(e!=s.startState.field(it)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:s,panel:e}){if(!e||!s.spec.valid)return R.none;let{view:t}=this,i=new at;for(let n=0,r=t.visibleRanges,o=r.length;n<o;n++){let{from:l,to:a}=r[n];for(;n<o-1&&a>r[n+1].from-500;)a=r[++n].to;s.highlight(t.state,l,a,(h,c)=>{let f=t.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?q0:$0)})}return i.finish()}},{decorations:s=>s.decorations});function Xi(s){return e=>{let t=e.state.field(it,!1);return t&&t.query.spec.valid?s(e,t):gf(e)}}const Zn=Xi((s,{query:e})=>{let{to:t}=s.state.selection.main,i=e.nextMatch(s.state,t,t);if(!i)return!1;let n=y.single(i.from,i.to),r=s.state.facet(Kt);return s.dispatch({selection:n,effects:[Eo(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),mf(s),!0}),es=Xi((s,{query:e})=>{let{state:t}=s,{from:i}=t.selection.main,n=e.prevMatch(t,i,i);if(!n)return!1;let r=y.single(n.from,n.to),o=s.state.facet(Kt);return s.dispatch({selection:r,effects:[Eo(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),mf(s),!0}),U0=Xi((s,{query:e})=>{let t=e.matchAll(s.state,1e3);return!t||!t.length?!1:(s.dispatch({selection:y.create(t.map(i=>y.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),j0=({state:s,dispatch:e})=>{let t=s.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:n}=t.main,r=[],o=0;for(let l=new $i(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(y.range(l.value.from,l.value.to))}return e(s.update({selection:y.create(r,o),userEvent:"select.search.matches"})),!0},pa=Xi((s,{query:e})=>{let{state:t}=s,{from:i,to:n}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=r,l=[],a,h,c=[];o.precise?o.from==i&&o.to==n&&(h=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),o=e.nextMatch(t,o.from,o.to),c.push(O.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))):o=e.nextMatch(t,o.from,o.to);let f=s.state.changes(l);return o&&(a=y.single(o.from,o.to).map(f),c.push(Eo(s,o)),c.push(t.facet(Kt).scrollToMatch(a.main,s))),s.dispatch({changes:f,selection:a,effects:c,userEvent:"input.replace"}),!0}),G0=Xi((s,{query:e})=>{if(s.state.readOnly)return!1;let t=[];for(let n of e.matchAll(s.state,1e9)){let{from:r,to:o,precise:l}=n;l&&t.push({from:r,to:o,insert:e.getReplacement(n)})}if(!t.length)return!1;let i=s.state.phrase("replaced $ matches",t.length)+".";return s.dispatch({changes:t,effects:O.announce.of(i),userEvent:"input.replace.all"}),!0});function Lo(s){return s.state.facet(Kt).createPanel(s)}function ts(s,e){var t,i,n,r,o;let l=s.selection.main,a=l.empty||l.to>l.from+100?"":s.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=s.facet(Kt);return new uf({search:((t=e?.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(n=e?.literal)!==null&&n!==void 0?n:h.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function pf(s){let e=Kh(s,Lo);return e&&e.dom.querySelector("[main-field]")}function mf(s){let e=pf(s);e&&e==s.root.activeElement&&e.select()}const gf=s=>{let e=s.state.field(it,!1);if(e&&e.panel){let t=pf(s);if(t&&t!=s.root.activeElement){let i=ts(s.state,e.query.spec);i.valid&&s.dispatch({effects:qi.of(i)}),t.focus(),t.select()}}else s.dispatch({effects:[Ro.of(!0),e?qi.of(ts(s.state,e.query.spec)):P.appendConfig.of(qr)]});return!0},bf=s=>{let e=s.state.field(it,!1);if(!e||!e.panel)return!1;let t=Kh(s,Lo);return t&&t.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:Ro.of(!1)}),!0},jb=[{key:"Mod-f",run:gf,scope:"editor search-panel"},{key:"F3",run:Zn,shift:es,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Zn,shift:es,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:bf,scope:"editor search-panel"},{key:"Mod-Shift-l",run:j0},{key:"Mod-Alt-g",run:R0},{key:"Mod-d",run:I0,preventDefault:!0}];class _0{constructor(e){this.view=e;let t=this.query=e.state.field(it).query.spec;this.commit=this.commit.bind(this),this.searchField=$("input",{value:t.search,placeholder:Ce(e,"Find"),"aria-label":Ce(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=$("input",{value:t.replace,placeholder:Ce(e,"Replace"),"aria-label":Ce(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=$("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=$("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=$("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(n,r,o){return $("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=$("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>Zn(e),[Ce(e,"next")]),i("prev",()=>es(e),[Ce(e,"previous")]),i("select",()=>U0(e),[Ce(e,"all")]),$("label",null,[this.caseField,Ce(e,"match case")]),$("label",null,[this.reField,Ce(e,"regexp")]),$("label",null,[this.wordField,Ce(e,"by word")]),...e.state.readOnly?[]:[$("br"),this.replaceField,i("replace",()=>pa(e),[Ce(e,"replace")]),i("replaceAll",()=>G0(e),[Ce(e,"replace all")])],$("button",{name:"close",onclick:()=>bf(e),"aria-label":Ce(e,"close"),type:"button"},["×"])])}commit(){let e=new uf({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:qi.of(e)}))}keydown(e){Pd(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?es:Zn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),pa(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(qi)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Kt).top}}function Ce(s,e){return s.state.phrase(e)}const kn=30,wn=/[\s\.,:;?!]/;function Eo(s,{from:e,to:t}){let i=s.state.doc.lineAt(e),n=s.state.doc.lineAt(t).to,r=Math.max(i.from,e-kn),o=Math.min(n,t+kn),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<kn;a++)if(!wn.test(l[a+1])&&wn.test(l[a])){l=l.slice(a);break}}if(o!=n){for(let a=l.length-1;a>l.length-kn;a--)if(!wn.test(l[a-1])&&wn.test(l[a])){l=l.slice(0,a);break}}return O.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const Y0=O.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"}}),qr=[it,At.low(K0),Y0];function yf(s){function e(f,u){f.cmdState.push(u)}function t(f){return f.cmdState.length>0?f.cmdState[f.cmdState.length-1]:null}function i(f){var u=f.cmdState.pop();u&&u.closeBracket()}function n(f){for(var u=f.cmdState,d=u.length-1;d>=0;d--){var p=u[d];if(p.name!="DEFAULT")return p}return{styleIdentifier:function(){return null}}}function r(f,u,d){return function(){this.name=f,this.bracketNo=0,this.style=u,this.styles=d,this.argument=null,this.styleIdentifier=function(){return this.styles[this.bracketNo-1]||null},this.openBracket=function(){return this.bracketNo++,"bracket"},this.closeBracket=function(){}}}var o={};o.importmodule=r("importmodule","tag",["string","builtin"]),o.documentclass=r("documentclass","tag",["","atom"]),o.usepackage=r("usepackage","tag",["atom"]),o.begin=r("begin","tag",["atom"]),o.end=r("end","tag",["atom"]),o.label=r("label","tag",["atom"]),o.ref=r("ref","tag",["atom"]),o.eqref=r("eqref","tag",["atom"]),o.cite=r("cite","tag",["atom"]),o.bibitem=r("bibitem","tag",["atom"]),o.Bibitem=r("Bibitem","tag",["atom"]),o.RBibitem=r("RBibitem","tag",["atom"]),o.DEFAULT=function(){this.name="DEFAULT",this.style="tag",this.styleIdentifier=this.openBracket=this.closeBracket=function(){}};function l(f,u){f.f=u}function a(f,u){var d;if(f.match(/^\\[a-zA-Z@\xc0-\u1fff\u2060-\uffff]+/)){var p=f.current().slice(1);return d=o.hasOwnProperty(p)?o[p]:o.DEFAULT,d=new d,e(u,d),l(u,c),d.style}if(f.match(/^\\[$&%#{}_]/)||f.match(/^\\[,;!\/\\]/))return"tag";if(f.match("\\["))return l(u,function(g,b){return h(g,b,"\\]")}),"keyword";if(f.match("\\("))return l(u,function(g,b){return h(g,b,"\\)")}),"keyword";if(f.match("$$"))return l(u,function(g,b){return h(g,b,"$$")}),"keyword";if(f.match("$"))return l(u,function(g,b){return h(g,b,"$")}),"keyword";var m=f.next();if(m=="%")return f.skipToEnd(),"comment";if(m=="}"||m=="]"){if(d=t(u),d)d.closeBracket(m),l(u,c);else return"error";return"bracket"}else return m=="{"||m=="["?(d=o.DEFAULT,d=new d,e(u,d),"bracket"):/\d/.test(m)?(f.eatWhile(/[\w.%]/),"atom"):(f.eatWhile(/[\w\-_]/),d=n(u),d.name=="begin"&&(d.argument=f.current()),d.styleIdentifier())}function h(f,u,d){if(f.eatSpace())return null;if(d&&f.match(d))return l(u,a),"keyword";if(f.match(/^\\[a-zA-Z@]+/))return"tag";if(f.match(/^[a-zA-Z]+/))return"variableName.special";if(f.match(/^\\[$&%#{}_]/)||f.match(/^\\[,;!\/]/)||f.match(/^[\^_&]/))return"tag";if(f.match(/^[+\-<>|=,\/@!*:;'"`~#?]/))return null;if(f.match(/^(\d+\.\d*|\d*\.\d+|\d+)/))return"number";var p=f.next();return p=="{"||p=="}"||p=="["||p=="]"||p=="("||p==")"?"bracket":p=="%"?(f.skipToEnd(),"comment"):"error"}function c(f,u){var d=f.peek(),p;return d=="{"||d=="["?(p=t(u),p.openBracket(d),f.eat(d),l(u,a),"bracket"):/[ \t\r]/.test(d)?(f.eat(d),null):(l(u,a),i(u),a(f,u))}return{name:"stex",startState:function(){var f=s?function(u,d){return h(u,d)}:a;return{cmdState:[],f}},copyState:function(f){return{cmdState:f.cmdState.slice(),f:f.f}},token:function(f,u){return u.f(f,u)},blankLine:function(f){f.f=a,f.cmdState.length=0},languageData:{commentTokens:{line:"%"}}}}const Gb=yf(!1);yf(!0);class ma{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class Pt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(et).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((d,p)=>d.from-p.from||d.to-p.to),o=new at,l=[],a=0,h=i.doc.iter(),c=0,f=i.doc.length;for(let d=0;;){let p=d==r.length?null:r[d];if(!p&&!l.length)break;let m,g;if(l.length)m=a,g=l.reduce((k,D)=>Math.min(k,D.to),p&&p.from>m?p.from:1e8);else{if(m=p.from,m>f)break;g=p.to,l.push(p),d++}for(;d<r.length;){let k=r[d];if(k.from==m&&(k.to>k.from||k.to==m))l.push(k),d++,g=Math.min(k.to,g);else{g=Math.min(k.from,g);break}}g=Math.min(g,f);let b=!1;if(l.some(k=>k.from==m&&(k.to==g||g==f))&&(b=m==g,!b&&g-m<10)){let k=m-(c+h.value.length);k>0&&(h.next(k),c=m);for(let D=m;;){if(D>=g){b=!0;break}if(!h.lineBreak&&c+h.value.length>D)break;D=c+h.value.length,c+=h.value.length,h.next()}}let x=ab(l);if(b)o.add(m,m,R.widget({widget:new sb(x),diagnostics:l.slice()}));else{let k=l.reduce((D,w)=>w.markClass?D+" "+w.markClass:D,"");o.add(m,g,R.mark({class:"cm-lintRange cm-lintRange-"+x+k,diagnostics:l.slice(),inclusiveEnd:l.some(D=>D.to>g)}))}if(a=g,a==f)break;for(let k=0;k<l.length;k++)l[k].to<=a&&l.splice(k--,1)}let u=o.finish();return new Pt(u,t,fi(u))}}function fi(s,e=null,t=0){let i=null;return s.between(t,1e9,(n,r,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!i)i=new ma(n,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new ma(i.from,r,i.diagnostic)}}),i}function J0(s,e){let t=e.pos,i=e.end||t,n=s.state.facet(et).hideOn(s,t,i);if(n!=null)return n;let r=s.startState.doc.lineAt(e.pos);return!!(s.effects.some(o=>o.is(Io))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function X0(s,e){return s.field(We,!1)?e:e.concat(P.appendConfig.of(Sf))}function Q0(s,e){return{effects:X0(s,[Io.of(e)])}}const Io=P.define(),xf=P.define(),kf=P.define(),We=fe.define({create(){return new Pt(R.none,null,null)},update(s,e){if(e.docChanged&&s.diagnostics.size){let t=s.diagnostics.map(e.changes),i=null,n=s.panel;if(s.selected){let r=e.changes.mapPos(s.selected.from,1);i=fi(t,s.selected.diagnostic,r)||fi(t,null,r)}!t.size&&n&&e.state.facet(et).autoPanel&&(n=null),s=new Pt(t,n,i)}for(let t of e.effects)if(t.is(Io)){let i=e.state.facet(et).autoPanel?t.value.length?is.open:null:s.panel;s=Pt.init(t.value,i,e.state)}else t.is(xf)?s=new Pt(s.diagnostics,t.value?is.open:null,s.selected):t.is(kf)&&(s=new Pt(s.diagnostics,s.panel,t.value));return s},provide:s=>[Ei.from(s,e=>e.panel),O.decorations.from(s,e=>e.diagnostics)]}),Z0=R.mark({class:"cm-lintRange cm-lintRange-active"});function eb(s,e,t){let{diagnostics:i}=s.state.field(We),n,r=-1,o=-1;i.between(e-(t<0?1:0),e+(t>0?1:0),(a,h,{spec:c})=>{if(e>=a&&e<=h&&(a==h||(e>a||t>0)&&(e<h||t<0)))return n=c.diagnostics,r=a,o=h,!1});let l=s.state.facet(et).tooltipFilter;return n&&l&&(n=l(n,s.state)),n?{pos:r,end:o,above:!0,create(){return{dom:tb(s,n)}}}:null}function tb(s,e){return $("ul",{class:"cm-tooltip-lint"},e.map(t=>vf(s,t,!1)))}const ga=s=>{let e=s.state.field(We,!1);return!e||!e.panel?!1:(s.dispatch({effects:xf.of(!1)}),!0)},ib=te.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:e}=s.state.facet(et);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(et);t.length&&nb(t.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==e.doc&&this.view.dispatch(Q0(this.view.state,i.reduce((n,r)=>n.concat(r))))},i=>{me(this.view.state,i)})}}update(s){let e=s.state.facet(et);(s.docChanged||e!=s.startState.facet(et)||e.needsRefresh&&e.needsRefresh(s))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function nb(s,e,t){let i=[],n=-1;for(let r of s)r.then(o=>{i.push(o),clearTimeout(n),i.length==s.length?e(i):n=setTimeout(()=>e(i),200)},t)}const et=T.define({combine(s){return{sources:s.map(e=>e.source).filter(e=>e!=null),...ft(s.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ba,tooltipFilter:ba,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})}}});function ba(s,e){return s?e?(t,i)=>e(s(t,i),i):s:e}function _b(s,e={}){return[et.of({source:s,config:e}),ib,Sf]}function wf(s){let e=[];if(s)e:for(let{name:t}of s){for(let i=0;i<t.length;i++){let n=t[i];if(/[a-zA-Z]/.test(n)&&!e.some(r=>r.toLowerCase()==n.toLowerCase())){e.push(n);continue e}}e.push("")}return e}function vf(s,e,t){var i;let n=t?wf(e.actions):[];return $("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},$("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(s):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=d=>{if(d.preventDefault(),l)return;l=!0;let p=fi(s.state.field(We).diagnostics,e);p&&r.apply(s,p.from,p.to)},{name:h}=r,c=n[o]?h.indexOf(n[o]):-1,f=c<0?h:[h.slice(0,c),$("u",h.slice(c,c+1)),h.slice(c+1)],u=r.markClass?" "+r.markClass:"";return $("button",{type:"button",class:"cm-diagnosticAction"+u,onclick:a,onmousedown:a,"aria-label":` Action: ${h}${c<0?"":` (access key "${n[o]})"`}.`},f)}),e.source&&$("div",{class:"cm-diagnosticSource"},e.source))}class sb extends nt{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return $("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ya{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=vf(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class is{constructor(e){this.view=e,this.items=[];let t=n=>{if(!(n.ctrlKey||n.altKey||n.metaKey)){if(n.keyCode==27)ga(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=wf(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==n.keyCode){let a=fi(this.view.state.field(We).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;n.preventDefault()}},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=$("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=$("div",{class:"cm-panel-lint"},this.list,$("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>ga(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(We).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(We),i=0,n=!1,r=null,o=new Set;for(e.between(0,this.view.state.doc.length,(l,a,{spec:h})=>{for(let c of h.diagnostics){if(o.has(c))continue;o.add(c);let f=-1,u;for(let d=i;d<this.items.length;d++)if(this.items[d].diagnostic==c){f=d;break}f<0?(u=new ya(this.view,c),this.items.splice(i,0,u),n=!0):(u=this.items[f],f>i&&(this.items.splice(i,f-i),n=!0)),t&&u.diagnostic==t.diagnostic?u.dom.hasAttribute("aria-selected")||(u.dom.setAttribute("aria-selected","true"),r=u):u.dom.hasAttribute("aria-selected")&&u.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new ya(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:a})=>{let h=a.height/this.list.offsetHeight;l.top<a.top?this.list.scrollTop-=(a.top-l.top)/h:l.bottom>a.bottom&&(this.list.scrollTop+=(l.bottom-a.bottom)/h)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(We),i=fi(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:kf.of(i)})}static open(e){return new is(e)}}function rb(s,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(s)}</svg>')`}function vn(s){return rb(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const ob=O.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-diagnostic-hint":{borderLeft:"5px solid #66d"},".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:vn("#f11")},".cm-lintRange-warning":{backgroundImage:vn("orange")},".cm-lintRange-info":{backgroundImage:vn("#999")},".cm-lintRange-hint":{backgroundImage:vn("#66d")},".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-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".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}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function lb(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function ab(s){let e="hint",t=1;for(let i of s){let n=lb(i.severity);n>t&&(t=n,e=i.severity)}return e}const hb=lp(eb,{hideOn:J0}),Sf=[We,O.decorations.compute([We],s=>{let{selected:e,panel:t}=s.field(We);return!e||!t||e.from==e.to?R.none:R.set([Z0.range(e.from,e.to)])}),hb,ob];var xa={};class ns{constructor(e,t,i,n,r,o,l,a,h,c=0,f){this.p=e,this.stack=t,this.state=i,this.reducePos=n,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=a,this.curContext=h,this.lookAhead=c,this.parent=f}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let n=e.parser.context;return new ns(e,[],t,i,i,0,[],0,n?new ka(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,n=e&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(n);if(l&&(this.score+=l),i==0){n<r.minRepeatTerm&&this.reducePos<this.pos&&(this.reducePos=this.pos),this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(n,this.reducePos);return}let a=this.stack.length-(i-1)*3-(e&262144?6:0),h=a?this.stack[a-2]:this.p.ranges[0].from;n<r.minRepeatTerm&&h==this.reducePos&&this.reducePos<this.pos&&(this.reducePos=this.pos);let c=this.reducePos-h;c>=2e3&&!(!((t=this.p.parser.nodeSet.types[n])===null||t===void 0)&&t.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=c));let f=a?this.stack[a-1]:0,u=this.bufferBase+this.buffer.length-f;if(n<r.minRepeatTerm||e&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,h,d,u+4,!0)}if(e&262144)this.state=this.stack[a];else{let d=this.stack[a-3];this.state=r.getGoto(d,n,!0)}for(;this.stack.length>a;)this.stack.pop();this.reduceContext(n,h)}storeNode(e,t,i,n=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this.buffer.length;if(o>0&&this.buffer[o-4]==0&&this.buffer[o-1]>-1){if(t==i)return;if(this.buffer[o-2]>=t){this.buffer[o-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,n);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let a=o;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,n>4&&(n-=4)}this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=n}}shift(e,t,i,n){if(e&131072)this.pushState(e&65535,this.pos);else if((e&262144)==0){let r=e,{parser:o}=this.p;this.pos=n;let l=o.stateFlag(r,1);!l&&(n>i||t<=o.maxNode)&&(this.reducePos=n),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,n,4)}else this.pos=n,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,n,4)}apply(e,t,i,n){e&65536?this.reduce(e):this.shift(e,t,i,n)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let n=this.pos;this.reducePos=this.pos=n+e.length,this.pushState(t,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(t&&e.buffer[t-4]==0&&(t-=4);t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),n=e.bufferBase+t;for(;e&&n==e.bufferBase;)e=e.parent;return new ns(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new cb(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if((i&65536)==0)return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let n=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&n.push(t[r],o);if(this.stack.length<120)for(let r=0;n.length<8&&r<t.length;r+=2){let o=t[r+1];n.some((l,a)=>a&1&&l==o)||n.push(t[r],o)}t=n}let i=[];for(let n=0;n<t.length&&i.length<4;n+=2){let r=t[n+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[n],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if((t&65536)==0)return!1;if(!e.validAction(this.state,t)){let i=t>>19,n=t&65535,r=this.stack.length-i*3;if(r<0||e.getGoto(this.stack[r],n,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(n,r)=>{if(!t.includes(n))return t.push(n),e.allActions(n,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let a=o&65535,h=this.stack.length-l*3;if(h>=0&&e.getGoto(this.stack[h],a,!1)>=0)return l<<19|65536|a}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new ka(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class ka{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class cb{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let n=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=n}}class ss{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new ss(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}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]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new ss(this.stack,this.pos,this.index)}}function Sn(s,e=Uint16Array){if(typeof s!="string")return s;let t=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let o=s.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),r+=a,l)break;r*=46}t?t[n++]=r:t=new e(r)}return t}class Pn{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const wa=new Pn;class fb{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=wa,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,n=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!n)return null;let o=this.ranges[--n];r-=i.from-o.to,i=o}for(;t<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let o=this.ranges[++n];r+=o.from-i.to,i=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,n;if(t>=0&&t<this.chunk.length)i=this.pos+e,n=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)n=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),n=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),n}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=wa,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let n of this.ranges){if(n.from>=t)break;n.to>e&&(i+=this.input.read(Math.max(n.from,e),Math.min(n.to,t)))}return i}}class si{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;ub(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}si.prototype.contextual=si.prototype.fallback=si.prototype.extend=!1;si.prototype.fallback=si.prototype.extend=!1;function ub(s,e,t,i,n,r){let o=0,l=1<<i,{dialect:a}=t.p.parser;e:for(;(l&s[o])!=0;){let h=s[o+1];for(let d=o+3;d<h;d+=2)if((s[d+1]&l)>0){let p=s[d];if(a.allows(p)&&(e.token.value==-1||e.token.value==p||db(p,e.token.value,n,r))){e.acceptToken(p);break}}let c=e.next,f=0,u=s[o+2];if(e.next<0&&u>f&&s[h+u*3-3]==65535){o=s[h+u*3-1];continue e}for(;f<u;){let d=f+u>>1,p=h+d+(d<<1),m=s[p],g=s[p+1]||65536;if(c<m)u=d;else if(c>=g)f=d+1;else{o=s[p+2],e.advance();continue e}}break}}function va(s,e,t){for(let i=e,n;(n=s[i])!=65535;i++)if(n==t)return i-e;return-1}function db(s,e,t,i){let n=va(t,i,e);return n<0||va(t,i,s)<n}const Ae=typeof process<"u"&&xa&&/\bparse\b/.test(xa.LOG);let Qs=null;function Sa(s,e,t){let i=s.cursor(Y.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(s.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:s.length}}class pb{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?Sa(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?Sa(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],n=this.index[t];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],o=this.start[t]+i.positions[n];if(o>e)return this.nextStart=o,null;if(r instanceof q){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let a=r.prop(E.lookAhead);if(!a||l+a<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}}class mb{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new Pn)}getActions(e){let t=0,i=null,{parser:n}=e.p,{tokenizers:r}=n,o=n.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let h=0;h<r.length;h++){if((1<<h&o)==0)continue;let c=r[h],f=this.tokens[h];if(!(i&&!c.fallback)&&((c.contextual||f.start!=e.pos||f.mask!=o||f.context!=l)&&(this.updateCachedToken(f,c,e),f.mask=o,f.context=l),f.lookAhead>f.end+25&&(a=Math.max(f.lookAhead,a)),f.value!=0)){let u=t;if(f.extended>-1&&(t=this.addActions(e,f.extended,f.end,t)),t=this.addActions(e,f.value,f.end,t),!c.extend&&(i=f,t>u))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new Pn,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new Pn,{pos:i,p:n}=e;return t.start=i,t.end=Math.min(i+1,n.stream.end),t.value=i==n.stream.end?n.parser.eofTerm:0,t}updateCachedToken(e,t,i){let n=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(n,e),i),e.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?e.value=l>>1:e.extended=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(n+1)}putAction(e,t,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==e)return n;return this.actions[n++]=e,this.actions[n++]=t,this.actions[n++]=i,n}addActions(e,t,i,n){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let h=o.stateSlot(r,a?2:1);;h+=3){if(l[h]==65535)if(l[h+1]==1)h=rt(l,h+2);else{n==0&&l[h+1]==2&&(n=this.putAction(rt(l,h+2),t,i,n));break}l[h]==t&&(n=this.putAction(rt(l,h+1),t,i,n))}return n}}class gb{constructor(e,t,i,n){this.parser=e,this.input=t,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new fb(t,n),this.tokens=new mb(e,this.stream),this.topTerm=e.top[1];let{from:r}=n[0];this.stacks=[ns.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>e.bufferLength*4?new pb(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],n,r;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{n||(n=[],r=[]),n.push(l);let a=this.tokens.getMainToken(l);r.push(a.value,a.end)}}break}}if(!i.length){let o=n&&yb(n);if(o)return Ae&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw Ae&&n&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&n){let o=this.stoppedAt!=null&&n[0].pos>this.stoppedAt?n[0]:this.runRecovery(n,r,i);if(o)return Ae&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,a)=>a.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let a=o+1;a<i.length;a++){let h=i[a];if(l.sameState(h)||l.buffer.length>500&&h.buffer.length>500)if((l.score-h.score||l.buffer.length-h.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let n=e.pos,{parser:r}=this,o=Ae?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let h=e.curContext&&e.curContext.tracker.strict,c=h?e.curContext.hash:0;for(let f=this.fragments.nodeAt(n);f;){let u=this.parser.nodeSet.types[f.type.id]==f.type?r.getGoto(e.state,f.type.id):-1;if(u>-1&&f.length&&(!h||(f.prop(E.contextHash)||0)==c))return e.useNode(f,u),Ae&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(f.type.id)})`),!0;if(!(f instanceof q)||f.children.length==0||f.positions[0]>0)break;let d=f.children[0];if(d instanceof q&&f.positions[0]==0)f=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),Ae&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let h=0;h<a.length;){let c=a[h++],f=a[h++],u=a[h++],d=h==a.length||!i,p=d?e:e.split(),m=this.tokens.mainToken;if(p.apply(c,f,m?m.start:p.pos,u),Ae&&console.log(o+this.stackID(p)+` (via ${(c&65536)==0?"shift":`reduce of ${r.getName(c&65535)}`} for ${r.getName(f)} @ ${n}${p==e?"":", split"})`),d)return!0;p.pos>n?t.push(p):i.push(p)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return Ca(e,t),!0}}runRecovery(e,t,i){let n=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],h=t[(o<<1)+1],c=Ae?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),Ae&&console.log(c+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let f=l.split(),u=c;for(let d=0;d<10&&f.forceReduce()&&(Ae&&console.log(u+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,i));d++)Ae&&(u=this.stackID(f)+" -> ");for(let d of l.recoverByInsert(a))Ae&&console.log(c+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(h==l.pos&&(h++,a=0),l.recoverByDelete(a,h),Ae&&console.log(c+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),Ca(l,i)):(!n||n.score<f.score)&&(n=f)}return n}stackToTree(e){return e.close(),q.build({buffer:ss.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(Qs||(Qs=new WeakMap)).get(e);return t||Qs.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function Ca(s,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==s.pos&&i.sameState(s)){e[t].score<s.score&&(e[t]=s);return}}e.push(s)}class bb{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}}class Kr extends po{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),n=[];for(let l=0;l<t.length;l++)n.push([]);function r(l,a,h){n[l].push([a,a.deserialize(String(h))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=E[a]);for(let h=1;h<l.length;){let c=l[h++];if(c>=0)r(c,a,l[h++]);else{let f=l[h+-c];for(let u=-c;u>0;u--)r(l[h++],a,f);h++}}}this.nodeSet=new us(t.map((l,a)=>ye.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:n[a],top:i.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Jh;let o=Sn(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Aa),this.states=Sn(e.states,Uint32Array),this.data=Sn(e.stateData),this.goto=Sn(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new si(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let n=new gb(this,e,t,i);for(let r of this.wrappers)n=r(n,e,t,i);return n}getGoto(e,t,i=!1){let n=this.goto;if(t>=n[0])return-1;for(let r=n[t+1];;){let o=n[r++],l=o&1,a=n[r++];if(l&&i)return a;for(let h=r+(o>>1);r<h;r++)if(n[r]==e)return a;if(l)return-1}}hasAction(e,t){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(e,n?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=rt(i,r+2)];else{if(i[r+1]==2)return rt(i,r+2);break}if(o==t||o==0)return rt(i,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),n=i?t(i):void 0;for(let r=this.stateSlot(e,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=rt(this.data,r+2);else break;n=t(rt(this.data,r+1))}return n}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=rt(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];t.some((r,o)=>o&1&&r==n)||t.push(this.data[i],n)}}return t}configure(e){let t=Object.assign(Object.create(Kr.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let n=e.tokenizers.find(r=>r.from==i);return n?n.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=e.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[n]=Aa(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(i[o]=!0)}let n=null;for(let r=0;r<t.length;r++)if(!i[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[l]=1;return new bb(e,i,n)}static deserialize(e){return new Kr(e)}}function rt(s,e){return s[e]|s[e+1]<<16}function yb(s){let e=null;for(let t of s){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function Aa(s){if(s.external){let e=s.extend?1:0;return(t,i)=>s.external(t,i)<<1|e}return s.get}export{Q as $,ct as A,bc as B,Ir as C,R as D,O as E,T as F,sc as G,Yp as H,Db as I,Pp as J,M as K,Kr as L,le as M,gs as N,ce as O,At as P,lp as Q,at as R,fe as S,Hb as T,_b as U,te as V,nt as W,Lb as X,Gb as Y,_p as Z,V as _,qi as a,W as a0,So as a1,rs as a2,Bb as a3,Ib as a4,kb as a5,Sb as a6,vb as a7,Pb as a8,Vb as a9,Tb as aa,qb as ab,$b as ac,lo as ad,zb as ae,O0 as af,jb as ag,Ob as ah,Wb as ai,Nb as aj,gf as ak,bp as al,Cb as am,Ub as an,Rb as ao,vt as ap,Kb as aq,y as b,Lg as c,Ym as d,_m as e,Zp as f,Fb as g,uf as h,Rg as i,ds as j,Ab as k,P as l,Qe as m,wb as n,cf as o,j as p,gc as q,Pg as r,Ei as s,na as t,Oc as u,Tm as v,Mc as w,Vr as x,Pd as y,N as z};