diff --git a/l4d2web/l4d2web/static/css/editor.css b/l4d2web/l4d2web/static/css/editor.css index 0017e98..a752cfd 100644 --- a/l4d2web/l4d2web/static/css/editor.css +++ b/l4d2web/l4d2web/static/css/editor.css @@ -9,10 +9,17 @@ * in _editor_assets.html un-hides for JS-disabled users. */ textarea[data-editor-language] { display: none; } +/* Pre-reserves the slot cm6 will mount into. The min-height formula + * matches the height EditorView.theme applies inside editor-entry.js, + * keyed off the textarea's `rows` attribute via the inline --editor-rows + * custom property. Same expression on both sides = zero layout shift. */ +.editor-mount { + min-height: calc(var(--editor-rows, 8) * 1.84rem + 1.125rem); +} + .cm-editor { border: var(--line); border-radius: var(--radius-s); - min-height: 8em; } .cm-editor.cm-focused { diff --git a/l4d2web/l4d2web/static/js/editor.js b/l4d2web/l4d2web/static/js/editor.js index d751977..df1742f 100644 --- a/l4d2web/l4d2web/static/js/editor.js +++ b/l4d2web/l4d2web/static/js/editor.js @@ -52,7 +52,8 @@ } const vocab = (lang === "srccfg") ? await loadSrccfgVocab() : null; - const controller = window.__editor.mount(textarea, { language: lang, vocab }); + const rows = parseInt(textarea.getAttribute("rows") || "0", 10) || 0; + const controller = window.__editor.mount(textarea, { language: lang, vocab, rows }); // Submit-time copy bridge const form = textarea.closest("form"); diff --git a/l4d2web/l4d2web/static/vendor/editor.bundle.js b/l4d2web/l4d2web/static/vendor/editor.bundle.js index eec2607..ff4c05e 100644 --- a/l4d2web/l4d2web/static/vendor/editor.bundle.js +++ b/l4d2web/l4d2web/static/vendor/editor.bundle.js @@ -9,4 +9,4 @@ var __editor_pkg=(()=>{var ns=[],Ro=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,2 `&&n.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:L.of([" "])}),t)return Or(n,t,i,o);if(i&&!vn(i,r)){let l=!1,a="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),a=n.inputState.lastSelectionOrigin,a=="select.pointer"&&(i=ha(s.facet(Ai).map(h=>h(n)),i))),n.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function Or(n,e,t,i=-1){if(S.ios&&n.inputState.flushIOSKey(e))return!0;let s=n.state.selection.main;if(S.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&n.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Ut(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||i==8&&e.insert.lengths.head)&&Ut(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&Ut(n.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=Bc(n,e,t));return n.state.facet(Ql).some(a=>a(n,e.from,e.to,r,l))||n.dispatch(l()),!0}function Bc(n,e,t){let i,s=n.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.fromr.to){let a=e.fromc(n)),h,a);e.from==f&&(o=f)}if(o>-1)i={changes:e,selection:w.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let a=r.frome.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(a+e.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(e),h=t&&t.main.to<=a.newLength?t.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let f=n.state.sliceDoc(e.from,e.to),c,u=t&&aa(n,t.main.head);if(u){let p=e.insert.length-(e.to-e.from);c={from:u.from,to:u.to-p}}else c=n.state.doc.lineAt(r.head);let d=r.to-e.to;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,g=m-f.length;if(n.state.sliceDoc(g,m)!=f||m>=c.from&&g<=c.to)return{range:p};let y=s.changes({from:g,to:m,insert:e.insert}),b=p.to-r.to;return{changes:y,range:h?w.range(Math.max(0,h.anchor+b),Math.max(0,h.head+b)):p.map(y)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function ua(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Ec(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new xn(t,i)),(s!=t||r!=i)&&e.push(new xn(s,r))),e}function Lc(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?w.single(t+e,i+e):null}function vn(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}var tr=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,S.safari&&e.contentDOM.addEventListener("input",()=>null),S.gecko&&Uc(e.contentDOM.ownerDocument)}handleEvent(e){!Wc(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let s of i.observers)s(this.view,t);for(let s of i.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Rc(e),i=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&pa.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),S.android&&S.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return S.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=da.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||Pc.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from0?!0:S.safari&&!S.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function pl(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(s){oe(t.state,s)}}}function Rc(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,r=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&t(l).handlers.push(pl(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(pl(i.value,a))}}for(let i in Ee)t(i).handlers.push(Ee[i]);for(let i in pe)t(i).observers.push(pe[i]);return e}var da=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Pc="dthko",pa=[16,17,18,20,91,92,224,225],nn=6;function sn(n){return Math.max(0,n)*.7+8}function Ic(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}var ir=class{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Fl(e.contentDOM),this.atoms=e.state.facet(Ai).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(q.allowMultipleSelections)&&Nc(e,t),this.dragging=Fc(e,t)&&ya(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Ic(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=Dr(this.view);e.clientX-a.left<=s+nn?t=-sn(s-e.clientX):e.clientX+a.right>=o-nn&&(t=sn(e.clientX-o)),e.clientY-a.top<=r+nn?i=-sn(r-e.clientY):e.clientY+a.bottom>=l-nn&&(i=sn(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=ha(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Nc(n,e){let t=n.state.facet(_l);return t.length?t[0](e):S.mac?e.metaKey:e.ctrlKey}function Hc(n,e){let t=n.state.facet(Yl);return t.length?t[0](e):S.mac?!e.altKey:!e.ctrlKey}function Fc(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=Si(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Wc(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=$.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}var Ee=Object.create(null),pe=Object.create(null),ma=S.ie&&S.ie_version<15||S.ios&&S.webkit_version<604;function Vc(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),ga(n,t.value)},50)}function Bn(n,e,t){for(let i of n.facet(e))t=i(t,n);return t}function ga(n,e){e=Bn(n.state,Cr,e);let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(nr!=null&&t.selection.ranges.every(a=>a.empty)&&nr==r.toString()){let a=-1;i=t.changeByRange(h=>{let f=t.doc.lineAt(h.from);if(f.from==a)return{range:h};a=f.from;let c=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:c},range:w.cursor(h.from+c.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:w.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}pe.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};pe.wheel=pe.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};Ee.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);pe.touchstart=(n,e)=>{let t=n.inputState,i=e.targetTouches[0];t.lastTouchTime=Date.now(),i&&(t.lastTouchX=i.clientX,t.lastTouchY=i.clientY),t.setSelectionOrigin("select.pointer")};pe.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ee.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(Jl))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=qc(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new ir(n,e,t,i)),i&&n.observer.ignore(()=>{Wl(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function ml(n,e,t,i){if(i==1)return w.cursor(e,t);if(i==2)return kc(n.state,e,t);{let s=n.docView.lineAt(e,t),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return lDate.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(yl+1)%3:1}function qc(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=ya(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=n.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,f=ml(n,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let c=ml(n,t.pos,t.assoc,i),u=Math.min(c.from,f.from),d=Math.max(c.to,f.to);f=u1&&(h=Kc(s,a.pos))?h:l?s.addRange(f):w.create([f])}}}function Kc(n,e){for(let t=0;t=e)return w.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}Ee.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let s=n.docView.tile.nearest(e.target);if(s&&s.isWidget()){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=w.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",Bn(n.state,Ar,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Ee.dragend=n=>(n.inputState.draggedContent=null,!1);function wl(n,e,t,i){if(t=Bn(n.state,Cr,t),!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&Hc(n,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ee.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),s=0,r=()=>{++s==t.length&&wl(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return wl(n,e,i,!0),!0}return!1};Ee.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=ma?null:e.clipboardData;return t?(ga(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Vc(n),!1)};function $c(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function jc(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:Bn(n,Ar,e.join(n.lineBreak)),ranges:t,linewise:i}}var nr=null;Ee.copy=Ee.cut=(n,e)=>{if(!di(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:s}=jc(n.state);if(!t&&!s)return!1;nr=s?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=ma?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):($c(n,t),!1)};var ba=fe.define();function wa(n,e){let t=[];for(let i of n.facet(Zl)){let s=i(n,e);s&&t.push(s)}return t.length?n.update({effects:t,annotations:ba.of(!0)}):null}function xa(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=wa(n.state,e);t?n.dispatch(t):n.update([])}},10)}pe.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),xa(n)};pe.blur=n=>{n.observer.clearSelectionRange(),xa(n)};pe.compositionstart=pe.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};pe.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,S.chrome&&S.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};pe.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ee.beforeinput=(n,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return Or(n,{from:a,to:h,insert:n.state.toText(r)},null),!0}}let s;if(S.chrome&&S.android&&(s=da.find(r=>r.inputType==e.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return S.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),S.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>pe.compositionend(n,e),20),!1};var xl=new Set;function Uc(n){xl.has(n)||(xl.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}var vl=["pre-wrap","normal","pre-line","break-spaces"],Xt=!1;function kl(){Xt=!1}var sr=class{constructor(e){this.lineWrapping=e,this.doc=L.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return vl.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>cn&&(Xt=!0),this.height=e)}replace(e,t,i){return n.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:f,toB:c}=s[l],u=r.lineAt(a,V.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,V.ByPosNoHeight,i,0,0);for(c+=d.to-h,h=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,f=s[l-1].fromB,l--,ar*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s=r&&o(this.lineAt(0,V.ByPos,i,s,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}},Se=class n extends Sn{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new Oe(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof n||s instanceof st&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof st?s=new n(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):ye.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}},st=class n extends ye{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let h=s+(e0){let r=i[i.length-1];r instanceof n?i[i.length-1]=new n(r.length+s):i.push(null,new n(s-1))}if(e>0){let r=i[0];r instanceof n?i[0]=new n(e+r.length):i.unshift(new n(e-1),null)}return ye.of(i)}decomposeLeft(e,t){t.push(new n(e-1),null)}decomposeRight(e,t){t.push(null,new n(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new n(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let c=s.heights[s.index++],u=0;c<0&&(u=-c,c=s.heights[s.index++]),a==-1?a=c:Math.abs(c-a)>=cn&&(a=-2);let d=new Se(f,c,u);d.outdated=!1,o.push(d),l+=f+1}l<=r&&o.push(null,new n(r-l).updateHeight(e,l));let h=ye.of(o);return(a<0||Math.abs(h.height-this.height)>=cn||Math.abs(a-this.heightMetrics(e,t).perLine)>=cn)&&(Xt=!0),kn(this,h)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}},or=class extends ye{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return el))return h;let f=t==V.ByPosNoHeight?V.ByPosNoHeight:V.ByPos;return a?h.join(this.right.lineAt(l,f,i,o,l)):this.left.lineAt(l,f,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,V.ByPos,i,s,r);e=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(tthis.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Sl(r,o-1),t=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e2*t.size||t.size>2*e.size?ye.of(this.break?[e,null,t]:[e,t]):(this.left=kn(this.left,e),this.right=kn(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}};function Sl(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof st&&(i=n[e+1])instanceof st&&n.splice(e-1,3,new st(t.length+1+i.length))}var _c=5,lr=class n{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Se?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Se(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e=_c)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenToe&&this.nodes.push(new Se(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new st(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Se)return e;let t=new Se(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Se)&&!this.isCovered?this.nodes.push(new Se(0,-1,0)):(this.writtenTof.clientHeight||f.scrollWidth>f.clientWidth)&&c.overflow!="visible"){let u=f.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=Math.min(h==n.parentNode?s.innerHeight:a,u.bottom)}h=c.position=="absolute"||c.position=="fixed"?f.offsetParent:f.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function Xc(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left0&&e.top0}function Qc(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}var wi=class{constructor(e,t,i,s){this.from=e,this.to=t,this.size=i,this.displaySize=s}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;itypeof s!="function"&&s.class=="cm-lineWrapping");this.heightOracle=new sr(i),this.stateDeco=Al(t),this.heightMap=ye.empty().applyChanges(this.stateDeco,L.empty,this.heightOracle.setDoc(t.doc),[new Be(0,0,0,t.doc.length)]);for(let s=0;s<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());s++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=H.set(this.lineGaps.map(s=>s.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new Kt(r,o))}}return this.viewports=e.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Cl:new fr(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(ui(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=Al(this.state);let s=e.changedRanges,r=Be.extendWithRanges(s,Yc(i,this.stateDeco,e?e.changes:se.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);kl(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||Xt)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.heada.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(oc)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?z.RTL:z.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,f=0;if(l.width&&l.height){let{scaleX:C,scaleY:T}=Hl(t,l);(C>.005&&Math.abs(this.scaleX-C)>.005||T>.005&&Math.abs(this.scaleY-T)>.005)&&(this.scaleX=C,this.scaleY=T,h|=16,o=a=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=Fl(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=Vl(this.scrollParent||e.win);let m=(this.printing?Qc:Jc)(t,this.paddingTop),g=m.top-this.pixelViewport.top,y=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(a=!0)),!this.inView&&!this.scrollTarget&&!Xc(e.dom))return 0;let k=l.width;if((this.contentDOMWidth!=k||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let C=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(C)&&(o=!0),o||s.lineWrapping&&Math.abs(k-this.contentDOMWidth)>s.charWidth){let{lineHeight:T,charWidth:A,textHeight:P}=e.docView.measureTextSize();o=T>0&&s.refresh(r,T,A,P,Math.max(5,k/A),C),o&&(e.docView.minWidth=0,h|=16)}g>0&&y>0?f=Math.max(g,y):g<0&&y<0&&(f=Math.min(g,y)),kl();for(let T of this.viewports){let A=T.from==this.viewport.from?C:e.docView.measureVisibleLineHeights(T);this.heightMap=(o?ye.empty().applyChanges(this.stateDeco,L.empty,this.heightOracle,[new Be(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new rr(T.from,A))}Xt&&(h|=2)}let O=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.headthis.viewport.to);return O&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),h|=this.updateForViewport()),(h&2||O)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Kt(s.lineAt(o-i*1e3,V.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,V.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(ha.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=s.lineAt(h,V.ByPos,r,0,0),u;t.y=="center"?u=(c.top+c.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&h=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r>1,o=s<<1;if(this.defaultTextDirection!=z.LTR&&!i)return[];let l=[],a=(f,c,u,d)=>{if(c-ff&&yy.from>=u.from&&y.to<=u.to&&Math.abs(y.from-f)y.fromb));if(!g){if(ck.from<=c&&k.to>=c)){let k=t.moveToLineBoundary(w.cursor(c),!1,!0).head;k>f&&(c=k)}let y=this.gapSize(u,f,c,d),b=i||y<2e6?y:2e6;g=new wi(f,c,y,b)}l.push(g)},h=f=>{if(f.length2e6)for(let T of e)T.from>=f.from&&T.fromf.from&&a(f.from,d,f,c),pt.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];N.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let r=0;r=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||ui(this.heightMap.lineAt(e,V.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||ui(this.heightMap.lineAt(this.scaler.fromDOM(e),V.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return ui(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},Kt=class{constructor(e,t){this.from=e,this.to=t}};function Zc(n,e,t){let i=[],s=n,r=0;return N.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function on(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function eu(n,e){for(let t of n)if(e(t))return t}var Cl={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Al(n){let e=n.facet(On).filter(i=>typeof i!="function"),t=n.facet(Tr).filter(i=>typeof i!="function");return t.length&&e.push(N.join(t)),e}var fr=class n{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,V.ByPos,e,0,0).top,f=t.lineAt(a,V.ByPos,e,0,0).bottom;return s+=f-h,{from:l,to:a,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=tt.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}};function ui(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new Oe(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>ui(s,e)):n._content)}var ln=M.define({combine:n=>n.join(" ")}),cr=M.define({combine:n=>n.indexOf(!0)>-1}),ur=ke.newName(),va=ke.newName(),ka=ke.newName(),Sa={"&light":"."+va,"&dark":"."+ka};function dr(n,e,t){return new ke(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}var tu=dr("."+ur,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Sa),iu={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Os=S.ie&&S.ie_version<=11,pr=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Fs,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(S.ie&&S.ie_version<=11||S.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&S.android&&e.constructor.EDIT_CONTEXT!==!1&&!(S.chrome&&S.chrome_version<126)&&(this.editContext=new mr(e),e.state.facet(_e)&&(e.contentDOM.editContext=this.editContext.editContext)),Os&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate){this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(_e)?i.root.activeElement!=this.dom:!di(this.dom,s))return;let r=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(S.ie&&S.ie_version<=11||S.android&&S.chrome)&&!i.state.selection.main.empty&&s.focusNode&&pi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=Si(e.root);if(!t)return!1;let i=S.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&nu(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let s=di(this.dom,i);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Ut(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&di(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new er(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,s=ca(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!vn(this.view.state.selection,t.newSel.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=Ml(t,e.previousSibling||e.target.previousSibling,-1),s=Ml(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(_e)!=e.state.facet(_e)&&(e.view.contentDOM.editContext=e.state.facet(_e)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function Ml(n,e,t){for(;e;){let i=$.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function Tl(n,e){let t=e.startContainer,i=e.startOffset,s=e.endContainer,r=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return pi(o.node,o.offset,s,r)&&([t,i,s,r]=[s,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}}function nu(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return Tl(n,s)}let t=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?Tl(n,t):null}var mr=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let s=e.state.selection.main,{anchor:r,head:o}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&rthis.to&&(a=r);let f=ua(e.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!f){let u=w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));vn(u,s)||e.dispatch({selection:u,userEvent:"select"});return}let c={from:f.from+l,to:f.toA+l,insert:L.of(i.text.slice(f.from,f.toB).split(` `))};if((S.mac||S.android)&&c.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(c={from:l,to:a,insert:L.of([i.text.replace("."," ")])}),this.pendingContextChange=c,!e.state.readOnly){let u=this.to-this.from+(c.to-c.from+c.insert.length);Or(e,c,w.single(this.toEditorPos(i.selectionStart,u),this.toEditorPos(i.selectionEnd,u)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),c.from=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=Si(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let f=h.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(h)){s=this.pendingContextChange=null,t+=f,this.to+=f;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=f,this.to+=f;else if(rthis.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=f}t+=f}),s&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},D=class n{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(s=>s.forEach(r=>i(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Yf(e.parent)||document,this.viewState=new Cn(this,e.state||q.create(e)),e.scrollTo&&e.scrollTo.is(tn)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(qt).map(s=>new gi(s));for(let s of this.plugins)s.update(this);this.observer=new pr(this),this.inputState=new tr(this),this.inputState.ensureHandlers(this.plugins),this.docView=new wn(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof J?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(ba))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=wa(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(f=null)):this.observer.clear(),r.facet(q.phrases)!=this.state.facet(q.phrases))return this.setState(r);s=yn.create(this,r,e),s.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection,{x:p,y:m}=this.state.facet(n.cursorScrollMargin);c=new mi(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of u.effects)d.is(tn)&&(c=d.value.clip(this.state))}this.viewState.update(s,c),this.bidiCache=An.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(ci)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(ln)!=s.state.facet(ln)&&(this.viewState.mustMeasureContent=!0),(t||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(qs))try{u(s)}catch(d){oe(this.state,d,"update listener")}(a||f)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),f&&!ca(this,f)&&h.force&&Ut(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Cn(this,e),this.plugins=e.facet(qt).map(i=>new gi(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new wn(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(qt),i=e.state.facet(qt);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new gi(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,s=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Vl(i||this.win))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure();if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let f=h.map(d=>{try{return d.read(this)}catch(p){return oe(this.state,p),Dl}}),c=yn.create(this,this.state,[]),u=!1;c.flags|=a,t?t.flags|=a:t=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d1||p<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){s=s+p,i?i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(qs))l(t)}get themeClasses(){return ur+" "+(this.state.facet(cr)?ka:va)+" "+this.state.facet(ln)}updateAttrs(){let e=Ol(this,na,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(_e)?"true":"false",class:"cm-content",style:`${S.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Ol(this,Mr,t);let i=this.observer.ignore(()=>{let s=ll(this.contentDOM,this.contentAttrs,t),r=ll(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(n.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(ci);let e=this.state.facet(n.cspNonce);ke.mount(this.root,this.styleModules.concat(tu).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;ti.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Ds(this,e,dl(this,e,t,i))}moveByGroup(e,t){return Ds(this,e,dl(this,e,t,i=>Mc(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return w.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,i=!0){return Ac(this,e,t,i)}moveVertically(e,t,i){return Ds(this,e,Tc(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=Xs(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),Xs(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[Ae.find(r,e-s.from,-1,t)];return gn(i,o.dir==z.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(ea)||ethis.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>su)return Ul(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||jl(r.isolates,i=fl(this,e))))return r.order;i||(i=fl(this,e));let s=nc(e.text,t,i);return this.bidiCache.push(new An(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||S.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Wl(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var i,s,r,o;return tn.of(new mi(typeof e=="number"?w.cursor(e):e,(i=t.y)!==null&&i!==void 0?i:"nearest",(s=t.x)!==null&&s!==void 0?s:"nearest",(r=t.yMargin)!==null&&r!==void 0?r:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return tn.of(new mi(w.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return be.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return be.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ke.newName(),s=[ln.of(i),ci.of(dr(`.${i}`,e))];return t&&t.dark&&s.push(cr.of(!0)),s}static baseTheme(e){return tt.lowest(ci.of(dr("."+ur,e,Sa)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&$.get(i)||$.get(e);return((t=s?.root)===null||t===void 0?void 0:t.view)||null}};D.styleModule=ci;D.inputHandler=Ql;D.clipboardInputFilter=Cr;D.clipboardOutputFilter=Ar;D.scrollHandler=ta;D.focusChangeEffect=Zl;D.perLineTextDirection=ea;D.exceptionSink=Xl;D.updateListener=qs;D.editable=_e;D.mouseSelectionStyle=Jl;D.dragMovesSelection=Yl;D.clickAddsSelectionRange=_l;D.decorations=On;D.blockWrappers=sa;D.outerDecorations=Tr;D.atomicRanges=Ai;D.bidiIsolatedRanges=ra;D.cursorScrollMargin=M.define({combine:n=>{let e=5,t=5;for(let i of n)typeof i=="number"?e=t=i:{x:e,y:t}=i;return{x:e,y:t}}});D.scrollMargins=oa;D.darkTheme=cr;D.cspNonce=M.define({combine:n=>n.length?n[0]:""});D.contentAttributes=Mr;D.editorAttributes=na;D.lineWrapping=D.contentAttributes.of({class:"cm-lineWrapping"});D.announce=I.define();var su=4096,Dl={},An=class n{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:z.LTR;for(let r=Math.max(0,e.length-10);r=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&vr(o,t)}return t}var ru=S.mac?"mac":S.windows?"win":S.linux?"linux":"key";function ou(n,e){let t=n.split(/-(?!$)/),i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;ai.concat(s),[]))),t}var nt=null,hu=4e3;function fu(n,e=ru){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,f)=>{var c,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>ou(y,e));for(let y=1;y{let O=nt={view:k,prefix:b,scope:o};return setTimeout(()=>{nt==O&&(nt=null)},hu),!0}]})}let m=p.join(" ");s(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),f&&(g.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let f=t[h]||(t[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in f)f[u].run.push(d=>c(d,gr))}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}var gr=null;function cu(n,e,t,i){gr=e;let s=nl(e),r=ce(s,0),o=De(r)==s.length&&s!=" ",l="",a=!1,h=!1,f=!1;nt&&nt.view==t&&nt.scope==i&&(l=nt.prefix+" ",pa.indexOf(e.keyCode)<0&&(h=!0,nt=null));let c=new Set,u=g=>{if(g){for(let y of g.run)if(!c.has(y)&&(c.add(y),y(t)))return g.stopPropagation&&(f=!0),!0;g.preventDefault&&(g.stopPropagation&&(f=!0),h=!0)}return!1},d=n[i],p,m;return d&&(u(d[l+an(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(S.windows&&e.ctrlKey&&e.altKey)&&!(S.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=Ge[e.keyCode])&&p!=s?(u(d[l+an(p,e,!0)])||e.shiftKey&&(m=Vt[e.keyCode])!=s&&m!=p&&u(d[l+an(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+an(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&f&&e.stopPropagation(),gr=null,a}var gm=/x/.unicode!=null?"gu":"g";function Ca(){return du}var uu=H.line({class:"cm-activeLine"}),du=be.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>e&&(t.push(uu.range(s.from)),e=s.from)}return H.set(t)}},{decorations:n=>n.decorations});var hn="-10000px",yr=class{constructor(e,t,i,s){this.facet=t,this.createTooltipView=i,this.removeTooltipView=s,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 s=e.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;at[h]=a),t.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}};function pu(n){let e=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}var Bs=M.define({combine:n=>{var e,t,i;return{position:S.ios?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||pu}}}),El=new WeakMap,Aa=be.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Bs);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new yr(n,Br,(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(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Bs);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",t.dom.appendChild(s)}return t.dom.style.position=this.position,t.dom.style.top=hn,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 n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.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 n=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:r}=this.manager.tooltipViews[0];if(S.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&&(n=r.width/this.parent.offsetWidth,e=r.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),s=Dr(this.view);return{visible:{left:i.left+s.left,top:i.top+s.top,right:i.right-s.right,bottom:i.bottom-s.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(Bs).tooltipSpace(this.view),scaleX:n,scaleY:e,makeAbsolute:t}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l=Math.min(t.bottom,i.bottom)||c.rightMath.min(t.right,i.right)+.1)){f.style.top=hn;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=El.get(h))!==null&&e!==void 0?e:u.bottom-u.top,y=h.offset||gu,b=this.view.textDirection==z.LTR,k=u.width>i.right-i.left?b?i.left:i.right-u.width:b?Math.max(i.left,Math.min(c.left-(d?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,c.left-m+(d?14:0)-y.x),i.right-m),O=this.above[l];!a.strictSide&&(O?c.top-g-p-y.yi.bottom)&&O==i.bottom-c.bottom>c.top-i.top&&(O=this.above[l]=!O);let C=(O?c.top-i.top:i.bottom-c.bottom)-p;if(Ck&&P.topT&&(T=O?P.top-g-2-p:P.bottom+p+2);if(this.position=="absolute"?(f.style.top=(T-n.parent.top)/r+"px",Ll(f,(k-n.parent.left)/s)):(f.style.top=T/r+"px",Ll(f,k/s)),d){let P=c.left+(b?y.x:-y.x)-(k+14-7);d.style.left=P/s+"px"}h.overlap!==!0&&o.push({left:k,top:T,right:A,bottom:T+g}),f.classList.toggle("cm-tooltip-above",O),f.classList.toggle("cm-tooltip-below",!O),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=hn}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Ll(n,e){let t=parseInt(n.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(n.style.left=e+"px")}var mu=D.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:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),gu={x:0,y:0},Br=M.define({enables:[Aa,mu]});function Er(n,e){let t=n.plugin(Aa);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}var Ve=class extends ve{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};Ve.prototype.elementClass="";Ve.prototype.toDOM=void 0;Ve.prototype.mapMode=te.TrackBefore;Ve.prototype.startSide=Ve.prototype.endSide=-1;Ve.prototype.point=!0;var Es=M.define(),yu=M.define();var un=M.define();var br=M.define({combine:n=>n.some(e=>e)});function bu(n){let e=[wu];return n&&n.fixed===!1&&e.push(br.of(!0)),e}var wu=be.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.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=n.state.facet(un).map(e=>new Mn(n,e)),this.fixed=!n.state.facet(br);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),n.scrollDOM.insertBefore(this.dom,n.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(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(n.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(br)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=N.iter(this.view.state.facet(Es),this.view.viewport.from),i=[],s=this.gutters.map(r=>new xr(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==de.Text&&o){wr(t,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==de.Text){wr(t,i,r.from);for(let o of s)o.line(this.view,r,i)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(un),t=n.state.facet(un),i=n.docChanged||n.heightChanged||n.viewportChanged||!N.eq(n.startState.facet(Es),n.state.facet(Es),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new Mn(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>D.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,s=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==z.LTR?{left:i,right:s}:{right:i,left:s}})});function Rl(n){return Array.isArray(n)?n:[n]}function wr(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}var xr=class{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:s}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==s.elements.length){let l=new Tn(e,o,r,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let s=[];wr(this.cursor,s,t.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),s=i?[i]:null;for(let r of e.state.facet(yu)){let o=r(e,t.widget,t);o&&(s||(s=[])).push(o)}s&&this.addElement(e,t,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}},Mn=class{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,s)&&s.preventDefault()});this.markers=Rl(t.markers(e)),t.initialSpacer&&(this.spacer=new Tn(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=Rl(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!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()}},Tn=class{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),xu(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=rr(l,a,h)||o(l,a,h):o}return i}})}}),xi=class extends Ve{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}};function Ls(n,e){return n.state.facet($t).formatNumber(e,n.state)}var Su=un.compute([$t],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(vu)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new xi(Ls(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let s of e.state.facet(ku)){let r=s(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet($t)!=e.state.facet($t),initialSpacer(e){return new xi(Ls(e,Pl(e.state.doc.lines)))},updateSpacer(e,t){let i=Ls(t.view,Pl(t.view.state.doc.lines));return i==e.number?e:new xi(i)},domEventHandlers:n.facet($t).domEventHandlers,side:"before"}));function Ma(n={}){return[$t.of(n),bu(),Su]}function Pl(n){let e=9;for(;e{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=le.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}};E.closedBy=new E({deserialize:n=>n.split(" ")});E.openedBy=new E({deserialize:n=>n.split(" ")});E.group=new E({deserialize:n=>n.split(" ")});E.isolate=new E({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});E.contextHash=new E({perNode:!0});E.lookAhead=new E({perNode:!0});E.mounted=new E({perNode:!0});var Mt=class{constructor(e,t,i,s=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=s}static get(e){return e&&e.props&&e.props[E.mounted.id]}},Au=Object.create(null),le=class n{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Au,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new n(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(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 s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(E.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}};le.none=new le("",Object.create(null),0,8);var Rn=class n{constructor(e){this.types=e;for(let t=0;t0;for(let a=this.cursor(o|_.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Fr(le.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new n(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new n(le.none,t,i,s)))}static build(e){return Tu(e)}};j.empty=new j(le.none,[],[],0);var Lr=class n{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new n(this.buffer,this.index)}},at=class n{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return le.none}toString(){let e=[];for(let t=0;t0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l=e&&te;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Di(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to0?l.length:-1;e!=h;e+=t){let f=l[e],c=a[e]+o.from,u;if(!(!(r&_.EnterBracketed&&f instanceof j&&(u=Mt.get(f))&&!u.overlay&&u.bracketed&&i>=c&&i<=c+f.length)&&!Ba(s,i,c,c+f.length))){if(f instanceof at){if(r&_.ExcludeBuffers)continue;let d=f.findChild(0,f.buffer.length,t,i-c,s);if(d>-1)return new Oi(new Pr(o,f,e,c),null,d)}else if(r&_.IncludeAnonymous||!f.type.isAnonymous||Hr(f)){let d;if(!(r&_.IgnoreMounts)&&(d=Mt.get(f))&&!d.overlay)return new n(d.tree,c,e,o);let p=new n(f,c,e,o);return r&_.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?f.children.length-1:0,t,i,s,r)}}}if(r&_.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 s;if(!(i&_.IgnoreOverlays)&&(s=Mt.get(this._tree))&&s.overlay){let r=e-this.from,o=i&_.EnterBracketed&&s.bracketed;for(let{from:l,to:a}of s.overlay)if((t>0||o?l<=r:l=r:a>r))return new n(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function Da(n,e,t,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=s.type.is(t),!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function Rr(n,e,t=e.length-1){for(let i=n;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}var Pr=class{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}},Oi=class n extends Pn{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:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new n(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&_.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new n(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new n(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new n(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1];e.push(i.slice(s,r,o)),t.push(0)}return new j(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Ea(n){if(!n.length)return null;let e=0,t=n[0];for(let r=1;rt.from||o.to=e){let l=new ze(o.tree,o.overlay[0].from+r.from,-1,r);(s||(s=[i])).push(Di(l,e,t,!1))}}return s?Ea(s):i}var Bi=class{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&~_.EnterBracketed,e instanceof ze)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof ze?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&_.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&_.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&_.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&_.IncludeAnonymous||l instanceof at||!l.type.isAnonymous||Hr(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}for(let s=i;s=0;r--){if(r<0)return Rr(this._tree,e,s);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}};function Hr(n){return n.children.some(e=>e instanceof at||!e.type.isAnonymous||Hr(e))}function Tu(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=1024,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new Lr(t,t.length):t,a=i.types,h=0,f=0;function c(C,T,A,P,W,G){let{id:R,start:B,end:K,size:U}=l,Z=f,Qe=h;if(U<0)if(l.next(),U==-1){let je=r[R];A.push(je),P.push(B-C);return}else if(U==-3){h=R;return}else if(U==-4){f=R;return}else throw new RangeError(`Unrecognized record size: ${U}`);let ri=a[R],qi,dt,Do=B-C;if(K-B<=s&&(dt=g(l.pos-T,W))){let je=new Uint16Array(dt.size-dt.skip),xe=l.pos-dt.size,He=je.length;for(;l.pos>xe;)He=y(dt.start,je,He);qi=new at(je,K-dt.start,i),Do=dt.start-C}else{let je=l.pos-U;l.next();let xe=[],He=[],pt=R>=o?R:-1,Pt=0,Ki=K;for(;l.pos>je;)pt>=0&&l.id==pt&&l.size>=0?(l.end<=Ki-s&&(p(xe,He,B,Pt,l.end,Ki,pt,Z,Qe),Pt=xe.length,Ki=l.end),l.next()):G>2500?u(B,je,xe,He):c(B,je,xe,He,pt,G+1);if(pt>=0&&Pt>0&&Pt-1&&Pt>0){let Oo=d(ri,Qe);qi=Fr(ri,xe,He,0,xe.length,0,K-B,Oo,Oo)}else qi=m(ri,xe,He,K-B,Z-K,Qe)}A.push(qi),P.push(Do)}function u(C,T,A,P){let W=[],G=0,R=-1;for(;l.pos>T;){let{id:B,start:K,end:U,size:Z}=l;if(Z>4)l.next();else{if(R>-1&&K=0;U-=3)B[Z++]=W[U],B[Z++]=W[U+1]-K,B[Z++]=W[U+2]-K,B[Z++]=Z;A.push(new at(B,W[2]-K,i)),P.push(K-C)}}function d(C,T){return(A,P,W)=>{let G=0,R=A.length-1,B,K;if(R>=0&&(B=A[R])instanceof j){if(!R&&B.type==C&&B.length==W)return B;(K=B.prop(E.lookAhead))&&(G=P[R]+B.length+K)}return m(C,A,P,W,G,T)}}function p(C,T,A,P,W,G,R,B,K){let U=[],Z=[];for(;C.length>P;)U.push(C.pop()),Z.push(T.pop()+A-W);C.push(m(i.types[R],U,Z,G-W,B-G,K)),T.push(W-A)}function m(C,T,A,P,W,G,R){if(G){let B=[E.contextHash,G];R=R?[B].concat(R):[B]}if(W>25){let B=[E.lookAhead,W];R=R?[B].concat(R):[B]}return new j(C,T,A,P,R)}function g(C,T){let A=l.fork(),P=0,W=0,G=0,R=A.end-s,B={size:0,start:0,skip:0};e:for(let K=A.pos-C;A.pos>K;){let U=A.size;if(A.id==T&&U>=0){B.size=P,B.start=W,B.skip=G,G+=4,P+=4,A.next();continue}let Z=A.pos-U;if(U<0||Z=o?4:0,ri=A.start;for(A.next();A.pos>Z;){if(A.size<0)if(A.size==-3||A.size==-4)Qe+=4;else break e;else A.id>=o&&(Qe+=4);A.next()}W=ri,P+=U,G+=Qe}return(T<0||P==C)&&(B.size=P,B.start=W,B.skip=G),B.size>4?B:void 0}function y(C,T,A){let{id:P,start:W,end:G,size:R}=l;if(l.next(),R>=0&&P4){let K=l.pos-(R-4);for(;l.pos>K;)A=y(C,T,A)}T[--A]=B,T[--A]=G-C,T[--A]=W-C,T[--A]=P}else R==-3?h=P:R==-4&&(f=P);return A}let b=[],k=[];for(;l.pos>0;)c(n.start||0,n.bufferStart||0,b,k,-1,0);let O=(e=n.length)!==null&&e!==void 0?e:b.length?k[0]+b[0].length:0;return new j(a[n.topID],b.reverse(),k.reverse(),O)}var Oa=new WeakMap;function Ln(n,e){if(!n.isAnonymous||e instanceof at||e.type!=n)return 1;let t=Oa.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof j)){t=1;break}t+=Ln(n,i)}Oa.set(e,t)}return t}function Fr(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p=f)break;T+=A}if(k==O+1){if(T>f){let A=p[O];d(A.children,A.positions,0,A.children.length,m[O]+b);continue}c.push(p[O])}else{let A=m[k-1]+p[k-1].length-C;c.push(Fr(n,p,m,O,k,C,A,null,a))}u.push(C+b-r)}}return d(e,t,i,s,0),(l||a)(c,u,o)}var Tt=class n{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new n(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let f=l=i)for(;o&&o.from=u.from||c<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,c)-h;u=d>=p?null:new n(d,p,u.tree,u.offset+h,l>0,!!f)}if(u&&s.push(u),o.to>c)break;o=rnew Ti(s.from,s.to)):[new Ti(0,0)]:[new Ti(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}},Nr=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var km=new E({perNode:!0});var Du=0,Le=class n{constructor(e,t,i,s){this.name=e,this.set=t,this.base=i,this.modified=s,this.id=Du++}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 n&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let s=new n(i,[],null,[]);if(s.set.push(s),t)for(let r of t.set)s.set.push(r);return s}static defineModifier(e){let t=new Fn(e);return i=>i.modified.indexOf(t)>-1?i:Fn.get(i.base||i,i.modified.concat(t).sort((s,r)=>s.id-r.id))}},Ou=0,Fn=class n{constructor(e){this.name=e,this.instances=[],this.id=Ou++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Bu(t,l.modified));if(i)return i;let s=[],r=new Le(e.name,s,e,t);for(let l of t)l.instances.push(r);let o=Eu(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(n.get(l,a));return r}};function Bu(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function Eu(n){let e=[[]];for(let t=0;ti.length-t.length)}function Pa(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let c=0;;){if(l=="..."&&c>0&&c+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),c+=u[0].length,c==s.length)break;let d=s[c++];if(c==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(c)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let f=new Ot(i,o,a>0?r.slice(0,a):null);e[h]=f.sort(e[h])}}return Ia.add(e)}var Ia=new E({combine(n,e){let t,i,s;for(;n||e;){if(!n||e&&n.depth>=e.depth?(s=e,e=e.next):(s=n,n=n.next),t&&t.mode==s.mode&&!s.context&&!t.context)continue;let r=new Ot(s.tags,s.mode,s.context);t?t.next=r:i=r,t=r}return i}}),Ot=class{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth{let o=s;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function Lu(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function Na(n,e,t,i=0,s=n.length){let r=new Vr(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}var Vr=class{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,s,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,f=Ru(e)||Ot.empty,c=Lu(r,f.tags);if(c&&(h&&(h+=" "),h+=c,f.mode==1&&(s+=(s?" ":"")+c)),this.startSpan(Math.max(t,l),h),f.opaque)return;let u=e.tree&&e.tree.prop(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,y=l;;g++){let b=g=k||!e.nextSibling())););if(!b||k>i)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),h))}m&&e.parent()}else if(e.firstChild()){u&&(s="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}};function Ru(n){let e=n.type.prop(Ia);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}var v=Le.define,In=v(),ht=v(),La=v(ht),Ra=v(ht),ft=v(),Nn=v(ft),Wr=v(ft),$e=v(),Dt=v($e),qe=v(),Ke=v(),zr=v(),Li=v(zr),Hn=v(),x={comment:In,lineComment:v(In),blockComment:v(In),docComment:v(In),name:ht,variableName:v(ht),typeName:La,tagName:v(La),propertyName:Ra,attributeName:v(Ra),className:v(ht),labelName:v(ht),namespace:v(ht),macroName:v(ht),literal:ft,string:Nn,docString:v(Nn),character:v(Nn),attributeValue:v(Nn),number:Wr,integer:v(Wr),float:v(Wr),bool:v(ft),regexp:v(ft),escape:v(ft),color:v(ft),url:v(ft),keyword:qe,self:v(qe),null:v(qe),atom:v(qe),unit:v(qe),modifier:v(qe),operatorKeyword:v(qe),controlKeyword:v(qe),definitionKeyword:v(qe),moduleKeyword:v(qe),operator:Ke,derefOperator:v(Ke),arithmeticOperator:v(Ke),logicOperator:v(Ke),bitwiseOperator:v(Ke),compareOperator:v(Ke),updateOperator:v(Ke),definitionOperator:v(Ke),typeOperator:v(Ke),controlOperator:v(Ke),punctuation:zr,separator:v(zr),bracket:Li,angleBracket:v(Li),squareBracket:v(Li),paren:v(Li),brace:v(Li),content:$e,heading:Dt,heading1:v(Dt),heading2:v(Dt),heading3:v(Dt),heading4:v(Dt),heading5:v(Dt),heading6:v(Dt),contentSeparator:v($e),list:v($e),quote:v($e),emphasis:v($e),strong:v($e),link:v($e),monospace:v($e),strikethrough:v($e),inserted:v(),deleted:v(),changed:v(),invalid:v(),meta:Hn,documentMeta:v(Hn),annotation:v(Hn),processingInstruction:v(Hn),definition:Le.defineModifier("definition"),constant:Le.defineModifier("constant"),function:Le.defineModifier("function"),standard:Le.defineModifier("standard"),local:Le.defineModifier("local"),special:Le.defineModifier("special")};for(let n in x){let e=x[n];e instanceof Le&&(e.name=n)}var Am=qr([{tag:x.link,class:"tok-link"},{tag:x.heading,class:"tok-heading"},{tag:x.emphasis,class:"tok-emphasis"},{tag:x.strong,class:"tok-strong"},{tag:x.keyword,class:"tok-keyword"},{tag:x.atom,class:"tok-atom"},{tag:x.bool,class:"tok-bool"},{tag:x.url,class:"tok-url"},{tag:x.labelName,class:"tok-labelName"},{tag:x.inserted,class:"tok-inserted"},{tag:x.deleted,class:"tok-deleted"},{tag:x.literal,class:"tok-literal"},{tag:x.string,class:"tok-string"},{tag:x.number,class:"tok-number"},{tag:[x.regexp,x.escape,x.special(x.string)],class:"tok-string2"},{tag:x.variableName,class:"tok-variableName"},{tag:x.local(x.variableName),class:"tok-variableName tok-local"},{tag:x.definition(x.variableName),class:"tok-variableName tok-definition"},{tag:x.special(x.variableName),class:"tok-variableName2"},{tag:x.definition(x.propertyName),class:"tok-propertyName tok-definition"},{tag:x.typeName,class:"tok-typeName"},{tag:x.namespace,class:"tok-namespace"},{tag:x.className,class:"tok-className"},{tag:x.macroName,class:"tok-macroName"},{tag:x.propertyName,class:"tok-propertyName"},{tag:x.operator,class:"tok-operator"},{tag:x.comment,class:"tok-comment"},{tag:x.meta,class:"tok-meta"},{tag:x.invalid,class:"tok-invalid"},{tag:x.punctuation,class:"tok-punctuation"}]);var Kr,Qt=new E;function Pu(n){return M.define({combine:n?e=>e.concat(n):void 0})}var Iu=new E,we=class{constructor(e,t,i=[],s=""){this.data=e,this.name=s,q.prototype.hasOwnProperty("tree")||Object.defineProperty(q.prototype,"tree",{get(){return ae(this)}}),this.parser=t,this.extension=[Zt.of(this),q.languageData.of((r,o,l)=>{let a=Ha(r,o,l),h=a.type.prop(Qt);if(!h)return[];let f=r.facet(h),c=a.type.prop(Iu);if(c){let u=a.resolve(o-a.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(f)}}return f})].concat(i)}isActiveAt(e,t,i=-1){return Ha(e,t,i).type.prop(Qt)==this.data}findRegions(e){let t=e.facet(Zt);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(Qt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(E.mounted);if(l){if(l.tree.prop(Qt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}},Ri=null,Pi=class n{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new n(e,t,[],j.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Gr(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=j.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Tt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Ri;Ri=this;try{return e()}finally{Ri=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Fa(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,f,c,u)=>a.push({fromA:h,toA:f,fromB:c,toB:u})),i=Tt.applyChanges(i,a),s=j.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let f=e.mapPos(h.from,1),c=e.mapPos(h.to,-1);fe.from&&(this.fragments=Fa(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends Ei{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=Ri;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new j(le.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 Ri}};function Fa(n,e,t){return Tt.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}var Ii=class n{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new n(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Pi.create(e.facet(Zt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new n(i)}};we.state=he.define({create:Ii.init,update(n,e){for(let t of e.effects)if(t.is(we.setState))return t.value;return e.startState.facet(Zt)!=e.state.facet(Zt)?Ii.init(e.state):n.apply(e)}});var $a=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&($a=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});var $r=typeof navigator<"u"&&(!((Kr=navigator.scheduling)===null||Kr===void 0)&&Kr.isInputPending)?()=>navigator.scheduling.isInputPending():null,Nu=be.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(we.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(we.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=$a(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnds+1e3,a=r.context.work(()=>$r&&$r()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:we.setState.of(new Ii(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=>oe(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()}}}),Zt=M.define({combine(n){return n.length?n[0]:null},enables:n=>[we.state,Nu,D.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});var Hu=M.define(),Hi=M.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function ct(n){let e=n.facet(Hi);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function ii(n,e){let t="",i=n.tabSize,s=n.facet(Hi)[0];if(s==" "){for(;e>=i;)t+=" ",e-=i;s=" "}for(let r=0;r=e?Fu(n,t,e):null}var Bt=class{constructor(e,t={}){this.state=e,this.options=t,this.unit=ct(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return xt(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}},ja=new E;function Fu(n,e,t){let i=e.resolveStack(t),s=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(s!=i.node){let r=[];for(let o=s;o&&!(o.fromi.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 Ua(i,n,t)}function Ua(n,e,t){for(let i=n;i;i=i.next){let s=Vu(i.node);if(s)return s(_r.create(e,t,i))}return 0}function Wu(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Vu(n){let e=n.type.prop(ja);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(E.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>$u(o,!0,1,void 0,r&&!Wu(o)?s.from:void 0)}return n.parent==null?zu:null}function zu(){return 0}var _r=class n extends Bt{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 n(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(qu(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return Ua(this.context.next,this.base,this.pos)}};function qu(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function Ku(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){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 $u(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=e?Ku(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}var ju=200;function Ga(){return q.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,s=t.lineAt(i);if(i>s.from+ju)return n;let r=t.sliceString(s.from,i);if(!e.some(h=>h.test(r)))return n;let{state:o}=n,l=-1,a=[];for(let{head:h}of o.selection.ranges){let f=o.doc.lineAt(h);if(f.from==l)continue;l=f.from;let c=zn(o,f.from);if(c==null)continue;let u=/^\s*/.exec(f.text)[0],d=ii(o,c);u!=d&&a.push({from:f.from,to:f.from+u.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}var ei=class n{constructor(e,t){this.specs=e;let i;function s(l){let a=ke.newName();return(i||(i=Object.create(null)))["."+a]=l,a}let r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof we?l=>l.prop(Qt)==o.data:o?l=>l==o:void 0,this.style=qr(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ke(i):null,this.themeType=t.themeType}static define(e,t){return new n(e,t||{})}},Yr=M.define(),_a=M.define({combine(n){return n.length?[n[0]]:null}});function jr(n){let e=n.facet(Yr);return e.length?e:n.facet(_a)}function qn(n,e){let t=[Uu],i;return n instanceof ei&&(n.module&&t.push(D.styleModule.of(n.module)),i=n.themeType),e?.fallback?t.push(_a.of(n)):i?t.push(Yr.computeN([D.darkTheme],s=>s.facet(D.darkTheme)==(i=="dark")?[n]:[])):t.push(Yr.of(n)),t}var Jr=class{constructor(e){this.markCache=Object.create(null),this.tree=ae(e.state),this.decorations=this.buildDeco(e,jr(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=ae(e.state),i=jr(e.state),s=i!=jr(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return H.none;let i=new wt;for(let{from:s,to:r}of e.visibleRanges)Na(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=H.mark({class:a})))},s,r);return i.finish()}},Uu=tt.high(be.fromClass(Jr,{decorations:n=>n.decorations})),Ya=ei.define([{tag:x.meta,color:"#404740"},{tag:x.link,textDecoration:"underline"},{tag:x.heading,textDecoration:"underline",fontWeight:"bold"},{tag:x.emphasis,fontStyle:"italic"},{tag:x.strong,fontWeight:"bold"},{tag:x.strikethrough,textDecoration:"line-through"},{tag:x.keyword,color:"#708"},{tag:[x.atom,x.bool,x.url,x.contentSeparator,x.labelName],color:"#219"},{tag:[x.literal,x.inserted],color:"#164"},{tag:[x.string,x.deleted],color:"#a11"},{tag:[x.regexp,x.escape,x.special(x.string)],color:"#e40"},{tag:x.definition(x.variableName),color:"#00f"},{tag:x.local(x.variableName),color:"#30a"},{tag:[x.typeName,x.namespace],color:"#085"},{tag:x.className,color:"#167"},{tag:[x.special(x.variableName),x.macroName],color:"#256"},{tag:x.definition(x.propertyName),color:"#00c"},{tag:x.comment,color:"#940"},{tag:x.invalid,color:"#f00"}]),Gu=D.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ja=1e4,Xa="()[]{}",Qa=M.define({combine(n){return it(n,{afterCursor:!0,brackets:Xa,maxScanDistance:Ja,renderMatch:Ju})}}),_u=H.mark({class:"cm-matchingBracket"}),Yu=H.mark({class:"cm-nonmatchingBracket"});function Ju(n){let e=[],t=n.matched?_u:Yu;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}function Wa(n){let e=[],t=n.facet(Qa);for(let i of n.selection.ranges){if(!i.empty)continue;let s=Re(n,i.head,-1,t)||i.head>0&&Re(n,i.head-1,1,t)||t.afterCursor&&(Re(n,i.head,1,t)||i.headn.decorations}),Qu=[Xu,Gu];function Za(n={}){return[Qa.of(n),Qu]}var Zu=new E;function Xr(n,e,t){let i=n.prop(e<0?E.openedBy:E.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function Qr(n){let e=n.type.prop(Zu);return e?e(n.node):n}function Re(n,e,t,i={}){let s=i.maxScanDistance||Ja,r=i.brackets||Xa,o=ae(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Xr(a.type,t,r);if(h&&a.from0?e>=f.from&&ef.from&&e<=f.to))return ed(n,e,t,a,f,h,r)}}return td(n,e,t,o,l.type,s,r)}function ed(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},h=0,f=l?.cursor();if(f&&(t<0?f.childBefore(i.from):f.childAfter(i.to)))do if(t<0?f.to<=i.from:f.from>=i.to){if(h==0&&r.indexOf(f.type.name)>-1&&f.from0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},f=n.doc.iterRange(e,t>0?n.doc.length:0),c=0;for(let u=0;!f.next().done&&u<=r;){let d=f.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||i.resolveInner(p+m,1).type!=s))if(y%2==0==t>0)c++;else{if(c==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};c--}}t>0&&(u+=d.length)}return f.done?{start:h,matched:!1}:null}function Va(n,e,t,i=0,s=0){e==null&&(e=n.search(/[^\s\u00a0]/),e==-1&&(e=n.length));let r=s;for(let o=i;o=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.post}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPosi?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return s(r)==s(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let s=this.string.slice(this.pos).match(e);return s&&s.index>0?null:(s&&t!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}};function id(n){return{name:n.name||"",token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||nd,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||to,mergeTokens:n.mergeTokens!==!1}}function nd(n){if(typeof n!="object")return n;let e={};for(let t in n){let i=n[t];e[t]=i instanceof Array?i.slice():i}return e}var za=new WeakMap,ti=class n extends we{constructor(e){let t=Pu(e.languageData),i=id(e),s,r=new class extends Ei{createParse(o,l,a){return new Zr(s,o,l,a)}};super(t,r,[],e.name),this.topNode=ld(t,this),s=this,this.streamParser=i,this.stateAfter=new E({perNode:!0}),this.tokenTable=e.tokenTable?new Vn(i.tokenTable):od}static define(e){return new n(e)}getIndent(e){let t,{overrideIndentation:i}=e.options;i&&(t=za.get(e.state),t!=null&&t1e4)return null;for(;r=i&&t+e.length<=s&&e.prop(n.stateAfter);if(r)return{state:n.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 j&&a=e.length)return e;!s&&t==0&&e.type==n.topNode&&(s=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],a;if(ot&&eo(n,r.tree,0-r.offset,t,l),h;if(a&&a.pos<=i&&(h=eh(n,r.tree,t+r.offset,a.pos+r.offset,!1)))return{state:a.state,tree:h}}return{state:n.streamParser.startState(s?ct(s):4),tree:j.empty}}var Zr=class{constructor(e,t,i,s){this.lang=e,this.input=t,this.fragments=i,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let r=Pi.get(),o=s[0].from,{state:l,tree:a}=sd(e,i,o,this.to,r?.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;hh.from<=r.viewport.from&&h.to>=r.viewport.from)&&(this.state=this.lang.streamParser.startState(ct(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=Pi.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=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==` `&&(t="");else{let i=t.indexOf(` -`);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 s=this.rangeIndex;;){let r=this.ranges[s].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let s=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?s>r:s>=r)break;let o=this.ranges[++this.rangeIndex].from;t+=o-s}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){s=this.skipGapsTo(t,s,1),t+=s;let l=this.chunk.length;s=this.skipGapsTo(i,s,-1),i+=s,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),s}parseLine(e){let{line:t,end:i}=this.nextLine(),s=0,{streamParser:r}=this.lang,o=new Wn(t,e?e.state.tabSize:4,e?ct(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=th(r.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPose.start)return s}throw new Error("Stream parser failed to advance stream.")}var to=Object.create(null),Ni=[le.none],rd=new Rn(Ni),qa=[],Ka=Object.create(null),ih=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])ih[n]=nh(to,e);var Vn=class{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),ih)}resolve(e){return e?this.table[e]||(this.table[e]=nh(this.extra,e)):0}},od=new Vn(to);function Ur(n,e){qa.indexOf(n)>-1||(qa.push(n),console.warn(e))}function nh(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let f=n[h]||x[h];f?typeof f=="function"?a.length?a=a.map(f):Ur(h,`Modifier ${h} used at start of tag`):a.length?Ur(h,`Tag ${h} used as modifier`):a=Array.isArray(f)?f:[f]:Ur(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=Ka[s];if(r)return r.id;let o=Ka[s]=le.define({id:Ni.length,name:i,props:[Pa({[i]:t})]});return Ni.push(o),o.id}function ld(n,e){let t=le.define({id:Ni.length,name:"Document",props:[Qt.add(()=>n),ja.add(()=>i=>e.getIndent(i))],top:!0});return Ni.push(t),t}var Pm={rtl:H.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:z.RTL}),ltr:H.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:z.LTR}),auto:H.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var ad=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=ao(n.state,t.from);return i.line?hd(n):i.block?cd(n):!1};function lo(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}var hd=lo(pd,0);var fd=lo(uh,0);var cd=lo((n,e)=>uh(n,e,dd(e)),0);function ao(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}var Fi=50;function ud(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-Fi,i),o=n.sliceDoc(s,s+Fi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let f,c;s-i<=2*Fi?f=c=n.sliceDoc(i,s):(f=n.sliceDoc(i,i+Fi),c=n.sliceDoc(s-Fi,s));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function dd(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to);s.from>i.from&&s.from==t.to&&(s=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function uh(n,e,t=e.selection.ranges){let i=t.map(r=>ao(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>ud(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;os&&(r==o||o>c.from)){s=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+h.length)==h?u:-1;ur.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:f,single:c}of i)(c||!f)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,f=h+a.length;o.text[f-o.from]==" "&&f++,r.push({from:h,to:f})}return{changes:r}}return null}var no=fe.define(),md=fe.define(),gd=M.define(),dh=M.define({combine(n){return it(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}}),ph=he.define({create(){return Et.empty},update(n,e){let t=e.state.facet(dh),i=e.annotation(no);if(i){let a=Pe.fromTransaction(e,i.selection),h=i.side,f=h==0?n.undone:n.done;return a?f=$n(f,f.length,t.minDepth,a):f=bh(f,e.startState.selection),new Et(h==0?i.rest:f,h==0?f:i.rest)}let s=e.annotation(md);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(J.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=Pe.fromTransaction(e),o=e.annotation(J.time),l=e.annotation(J.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new Et(n.done.map(Pe.fromJSON),n.undone.map(Pe.fromJSON))}});function mh(n={}){return[ph,dh.of(n),D.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?gh:e.inputType=="historyRedo"?so:null;return i?(e.preventDefault(),i(t)):!1}})]}function jn(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(ph,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}var gh=jn(0,!1),so=jn(1,!1),yd=jn(0,!0),bd=jn(1,!0);var Pe=class n{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new n(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new n(e.changes&&se.fromJSON(e.changes),[],e.mapped&&Ue.fromJSON(e.mapped),e.startSelection&&w.fromJSON(e.startSelection),e.selectionsAfter.map(w.fromJSON))}static fromTransaction(e,t){let i=Me;for(let s of e.startState.facet(gd)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new n(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Me)}static selection(e){return new n(void 0,Me,void 0,void 0,e)}};function $n(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function wd(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a=h&&o<=f&&(i=!0)}}),i}function xd(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function yh(n,e){return n.length?e.length?n.concat(e):n:e}var Me=[],vd=200;function bh(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-vd));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),$n(n,n.length-1,1e9,t.setSelAfter(i)))}else return[Pe.selection([e])]}function kd(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function io(n,e){if(!n.length)return n;let t=n.length,i=Me;for(;t;){let s=Sd(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[Pe.selection(i)]:Me}function Sd(n,e,t){let i=yh(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Me,t);if(!n.changes)return Pe.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new Pe(s,I.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}var Cd=/^(input\.type|delete)($|\.)/,Et=class n{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new n(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Cd.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?n.moveByChar(t,e):Un(t,e))}function ie(n){return n.textDirectionAt(n.state.selection.main.head)==z.LTR}var vh=n=>xh(n,!ie(n)),kh=n=>xh(n,ie(n));function Sh(n,e){return Ne(n,t=>t.empty?n.moveByGroup(t,e):Un(t,e))}var Ad=n=>Sh(n,!ie(n)),Md=n=>Sh(n,ie(n));var Km=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Td(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function Gn(n,e,t){let i=ae(n).resolveInner(e.head),s=t?E.closedBy:E.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Td(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?Re(n,i.from,1):Re(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,w.cursor(l,t?-1:1)}var Dd=n=>Ne(n,e=>Gn(n.state,e,!ie(n))),Od=n=>Ne(n,e=>Gn(n.state,e,ie(n)));function Ch(n,e){return Ne(n,t=>{if(!t.empty)return Un(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}var Ah=n=>Ch(n,!1),Mh=n=>Ch(n,!0);function Th(n){let e=n.scrollDOM.clientHeighto.empty?n.moveVertically(o,e,t.height):Un(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottomDh(n,!1),ro=n=>Dh(n,!0);function ut(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=w.cursor(i.from+r))}return s}var Bd=n=>Ne(n,e=>ut(n,e,!0)),Ed=n=>Ne(n,e=>ut(n,e,!1)),Ld=n=>Ne(n,e=>ut(n,e,!ie(n))),Rd=n=>Ne(n,e=>ut(n,e,ie(n))),Pd=n=>Ne(n,e=>w.cursor(n.lineBlockAt(e.head).from,1)),Id=n=>Ne(n,e=>w.cursor(n.lineBlockAt(e.head).to,-1));function Nd(n,e,t){let i=!1,s=ni(n.selection,r=>{let o=Re(n,r.head,-1)||Re(n,r.head,1)||r.head>0&&Re(n,r.head-1,1)||r.headNd(n,e,!1);function Te(n,e){let t=ni(n.state.selection,i=>{let s=e(i);return w.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return t.eq(n.state.selection)?!1:(n.dispatch(Ie(n.state,t)),!0)}function Oh(n,e){return Te(n,t=>n.moveByChar(t,e))}var Bh=n=>Oh(n,!ie(n)),Eh=n=>Oh(n,ie(n));function Lh(n,e){return Te(n,t=>n.moveByGroup(t,e))}var Fd=n=>Lh(n,!ie(n)),Wd=n=>Lh(n,ie(n));var Vd=n=>Te(n,e=>Gn(n.state,e,!ie(n))),zd=n=>Te(n,e=>Gn(n.state,e,ie(n)));function Rh(n,e){return Te(n,t=>n.moveVertically(t,e))}var Ph=n=>Rh(n,!1),Ih=n=>Rh(n,!0);function Nh(n,e){return Te(n,t=>n.moveVertically(t,e,Th(n).height))}var rh=n=>Nh(n,!1),oh=n=>Nh(n,!0),qd=n=>Te(n,e=>ut(n,e,!0)),Kd=n=>Te(n,e=>ut(n,e,!1)),$d=n=>Te(n,e=>ut(n,e,!ie(n))),jd=n=>Te(n,e=>ut(n,e,ie(n))),Ud=n=>Te(n,e=>w.cursor(n.lineBlockAt(e.head).from)),Gd=n=>Te(n,e=>w.cursor(n.lineBlockAt(e.head).to)),lh=({state:n,dispatch:e})=>(e(Ie(n,{anchor:0})),!0),ah=({state:n,dispatch:e})=>(e(Ie(n,{anchor:n.doc.length})),!0),hh=({state:n,dispatch:e})=>(e(Ie(n,{anchor:n.selection.main.anchor,head:0})),!0),fh=({state:n,dispatch:e})=>(e(Ie(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),_d=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Yd=({state:n,dispatch:e})=>{let t=_n(n).map(({from:i,to:s})=>w.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:w.create(t),userEvent:"select"})),!0},Jd=({state:n,dispatch:e})=>{let t=ni(n.selection,i=>{let s=ae(n),r=s.resolveStack(i.from,1);if(i.empty){let o=s.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.to||l.to>i.to&&l.from<=i.from)&&o.next)return w.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ie(n,t)),!0)};function Hh(n,e){let{state:t}=n,i=t.selection,s=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to0)for(let l=r;;){let a=n.moveVertically(l,e);if(a.heado.to){s.some(h=>h.head==a.head)||s.push(a);break}else{if(a.head==l.head)break;l=a}}}return s.length==i.ranges.length?!1:(n.dispatch(Ie(t,w.create(s,s.length-1))),!0)}var Xd=n=>Hh(n,!1),Qd=n=>Hh(n,!0),Zd=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=w.create([t.main]):t.main.empty||(i=w.create([w.cursor(t.main.head)])),i?(e(Ie(n,i)),!0):!1};function Wi(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);ao&&(t="delete.forward",a=Kn(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Kn(n,o,!1),l=Kn(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:w.cursor(o,os(n)))i.between(e,e,(s,r)=>{se&&(e=t?r:s)});return e}var Fh=(n,e,t)=>Wi(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&sFh(n,!1,!0);var Wh=n=>Fh(n,!0,!1),Vh=(n,e)=>Wi(n,t=>{let i=t.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=X(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),f=o(h);if(l!=null&&f!=l)break;(h!=" "||i!=t.head)&&(l=f),i=a}return i}),zh=n=>Vh(n,!1),ep=n=>Vh(n,!0);var tp=n=>Wi(n,e=>{let t=n.lineBlockAt(e.head).to;return e.headWi(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),np=n=>Wi(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:L.of(["",""])},range:w.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},rp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:X(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:X(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:w.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function _n(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function qh(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of _n(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(w.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(w.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:w.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var op=({state:n,dispatch:e})=>qh(n,e,!1),lp=({state:n,dispatch:e})=>qh(n,e,!0);function Kh(n,e,t){if(n.readOnly)return!1;let i=[];for(let r of _n(n))t?i.push({from:r.from,insert:n.doc.slice(r.from,r.to)+n.lineBreak}):i.push({from:r.to,insert:n.lineBreak+n.doc.slice(r.from,r.to)});let s=n.changes(i);return e(n.update({changes:s,selection:n.selection.map(s,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var ap=({state:n,dispatch:e})=>Kh(n,e,!1),hp=({state:n,dispatch:e})=>Kh(n,e,!0),fp=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(_n(e).map(({from:s,to:r})=>(s>0?s--:r{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function cp(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ae(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(E.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}var ch=$h(!1),up=$h(!0);function $h(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&cp(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Bt(e,{simulateBreak:r,simulateDoubleBreak:!!a}),f=zn(h,r);for(f==null&&(f=xt(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));ol.from&&r{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:w.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}var dp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Bt(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=ho(n,(r,o,l)=>{let a=zn(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],f=ii(n,a);(h!=f||l.fromn.readOnly?!1:(e(n.update(ho(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Hi)})}),{userEvent:"input.indent"})),!0),Uh=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(ho(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=xt(s,n.tabSize),o=0,l=ii(n,Math.max(0,r-ct(n)));for(;o(n.setTabFocusMode(),!0);var mp=[{key:"Ctrl-b",run:vh,shift:Bh,preventDefault:!0},{key:"Ctrl-f",run:kh,shift:Eh},{key:"Ctrl-p",run:Ah,shift:Ph},{key:"Ctrl-n",run:Mh,shift:Ih},{key:"Ctrl-a",run:Pd,shift:Ud},{key:"Ctrl-e",run:Id,shift:Gd},{key:"Ctrl-d",run:Wh},{key:"Ctrl-h",run:oo},{key:"Ctrl-k",run:tp},{key:"Ctrl-Alt-h",run:zh},{key:"Ctrl-o",run:sp},{key:"Ctrl-t",run:rp},{key:"Ctrl-v",run:ro}],gp=[{key:"ArrowLeft",run:vh,shift:Bh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Ad,shift:Fd,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Ld,shift:$d,preventDefault:!0},{key:"ArrowRight",run:kh,shift:Eh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Md,shift:Wd,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Rd,shift:jd,preventDefault:!0},{key:"ArrowUp",run:Ah,shift:Ph,preventDefault:!0},{mac:"Cmd-ArrowUp",run:lh,shift:hh},{mac:"Ctrl-ArrowUp",run:sh,shift:rh},{key:"ArrowDown",run:Mh,shift:Ih,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ah,shift:fh},{mac:"Ctrl-ArrowDown",run:ro,shift:oh},{key:"PageUp",run:sh,shift:rh},{key:"PageDown",run:ro,shift:oh},{key:"Home",run:Ed,shift:Kd,preventDefault:!0},{key:"Mod-Home",run:lh,shift:hh},{key:"End",run:Bd,shift:qd,preventDefault:!0},{key:"Mod-End",run:ah,shift:fh},{key:"Enter",run:ch,shift:ch},{key:"Mod-a",run:_d},{key:"Backspace",run:oo,shift:oo,preventDefault:!0},{key:"Delete",run:Wh,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:zh,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:ep,preventDefault:!0},{mac:"Mod-Backspace",run:ip,preventDefault:!0},{mac:"Mod-Delete",run:np,preventDefault:!0}].concat(mp.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Gh=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Dd,shift:Vd},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Od,shift:zd},{key:"Alt-ArrowUp",run:op},{key:"Shift-Alt-ArrowUp",run:ap},{key:"Alt-ArrowDown",run:lp},{key:"Shift-Alt-ArrowDown",run:hp},{key:"Mod-Alt-ArrowUp",run:Xd},{key:"Mod-Alt-ArrowDown",run:Qd},{key:"Escape",run:Zd},{key:"Mod-Enter",run:up},{key:"Alt-l",mac:"Ctrl-l",run:Yd},{key:"Mod-i",run:Jd,preventDefault:!0},{key:"Mod-[",run:Uh},{key:"Mod-]",run:jh},{key:"Mod-Alt-\\",run:dp},{key:"Shift-Mod-k",run:fp},{key:"Shift-Mod-\\",run:Hd},{key:"Mod-/",run:ad},{key:"Alt-A",run:fd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:pp}].concat(gp),_h={key:"Tab",run:jh,shift:Uh};var Jn=class{constructor(e,t,i,s){this.state=e,this.pos=t,this.explicit=i,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ae(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),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(nf(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.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 Yh(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function yp(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;rtypeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:yp(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}var Xn=class{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}};function Rt(n){return n.selection.main.from}function nf(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}var sf=fe.define();function wp(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return{...n.changeByRange(l=>{if(l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:a},range:w.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}var Jh=new WeakMap;function xp(n){if(!Array.isArray(n))return n;let e=Jh.get(n);return e||Jh.set(n,e=bp(n)),e}var Qn=I.define(),Vi=I.define(),po=class{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=48&&C<=57||C>=97&&C<=122?2:C>=65&&C<=90?1:0:(T=bs(C))!=T.toLowerCase()?1:T!=T.toUpperCase()?2:0;(!b||A==1&&g||O==0&&A!=0)&&(t[c]==C||i[c]==C&&(u=!0)?o[c++]=b:o.length&&(y=!1)),O=A,b+=De(C)}return c==a&&o[0]==0&&y?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]):c==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?De(ce(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}},mo=class{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:vp,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=>Xh(e(i),t(i)),optionClass:(e,t)=>i=>Xh(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Xh(n,e){return n?e?n+" "+e:n:e}function vp(n,e,t,i,s,r){let o=n.textDirection==z.RTL,l=o,a=!1,h="top",f,c,u=e.left-s.left,d=s.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u=m||b>e.top?f=t.bottom-e.top:(h="bottom",f=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${f/g}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}var xo=I.define();function kp(n){let e=n.addToOptions.slice();return n.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(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;ha&&o.appendChild(document.createTextNode(l.slice(a,f)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(f,c))),u.className="cm-completionMatchedText",a=c}return at.position-i.position).map(t=>t.render)}function fo(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.ceil((n-e)/t);return{from:n-i*t,to:n-(i-1)*t}}var go=class{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 s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(Q);this.optionContent=kp(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=fo(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 f=a.target,c;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(c=/-(\d+)$/.exec(f.id))&&+c[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;f!=null&&(e.dispatch({effects:xo.of(f)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(Q).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Vi.of(null)})}),this.showOptions(r,s.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),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=fo(r.length,o,e.state.facet(Q).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=s.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.to)&&(this.range=fo(t.options.length,t.selected,this.view.state.facet(Q).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:s}=t.options[t.selected],{info:r}=s;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(s);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,s)}).catch(l=>oe(this.view.state,l,"completion info")):(this.addInfoPane(o,s),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:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==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&&Cp(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(),s=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 s.top>Math.min(r.bottom,t.bottom)-10||s.bottom{o.target==s&&o.preventDefault()});let r=null;for(let o=i.from;oi.from||i.from==0))if(r=u,typeof h!="string"&&h.header)s.appendChild(h.header(h));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=u}}let f=s.appendChild(document.createElement("li"));f.id=t+"-"+o,f.setAttribute("role","option");let c=this.optionClass(l);c&&(f.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&f.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.tonew go(t,n,e)}function Cp(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),s=t.height/n.offsetHeight;i.topt.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/s)}function Qh(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function Ap(n,e){let t=[],i=null,s=null,r=f=>{t.push(f);let{section:c}=f.completion;if(c){i||(i=[]);let u=typeof c=="string"?c:c.name;i.some(d=>d.name==u)||i.push(typeof c=="string"?{name:u}:c)}},o=e.facet(Q);for(let f of n)if(f.hasResult()){let c=f.result.getMatch;if(f.result.filter===!1)for(let u of f.result.options)r(new Xn(u,f.source,c?c(u):[],1e9-t.length));else{let u=e.sliceDoc(f.from,f.to),d,p=o.filterStrict?new mo(u):new po(u);for(let m of f.result.options)if(d=p.match(m.label)){let g=m.displayLabel?c?c(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(r(new Xn(m,f.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:b}=m.section;s||(s=Object.create(null)),s[b]=Math.max(y,s[b]||-1e9)}}}}if(i){let f=Object.create(null),c=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?s[p.name]-s[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.nameu.score-c.score||h(c.completion,u.completion))){let c=f.completion;!a||a.label!=c.label||a.detail!=c.detail||a.type!=null&&c.type!=null&&a.type!=c.type||a.apply!=c.apply||a.boost!=c.boost?l.push(f):Qh(f.completion)>Qh(a)&&(l[l.length-1]=f),a=f.completion}return l}var yo=class n{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new n(this.options,Zh(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r,o){if(s&&!o&&e.some(h=>h.isPending))return s.setDisabled();let l=Ap(e,t);if(!l.length)return s&&e.some(h=>h.isPending)?s.setDisabled():null;let a=t.facet(Q).selectOnOpen?0:-1;if(s&&s.selected!=a&&s.selected!=-1){let h=s.options[s.selected].completion;for(let f=0;ff.hasResult()?Math.min(h,f.from):h,1e8),create:Ep,above:r.aboveCursor},s?s.timestamp:Date.now(),a,!1)}map(e){return new n(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new n(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}},bo=class n{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new n(Op,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Q),r=(i.override||t.languageDataAt("autocomplete",Rt(t)).map(xp)).map(a=>(this.active.find(f=>f.source==a)||new Xe(a,this.active.some(f=>f.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(vo));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!Mp(r,this.active)||l?o=yo.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 Xe(a.source,0):a));for(let a of e.effects)a.is(xo)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new n(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Tp:Dp}};function Mp(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t-1&&(t["aria-activedescendant"]=n+"-"+e),t}var Op=[];function rf(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(sf);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}var Xe=class n{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=rf(e,t),s=this;(i&8||i&16&&this.touches(e))&&(s=new n(s.source,0)),i&4&&s.state==0&&(s=new n(this.source,1)),s=s.updateFor(e,i);for(let r of e.effects)if(r.is(Qn))s=new n(s.source,1,r.value);else if(r.is(Vi))s=new n(s.source,0);else if(r.is(vo))for(let o of r.value)o.source==s.source&&(s=o);return s}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Rt(e.state))}},Zn=class n extends Xe{constructor(e,t,i,s,r,o){super(e,3,t),this.limit=i,this.result=s,this.from=r,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=Rt(e.state);if(l>o||!s||t&2&&(Rt(e.startState)==this.from||lt.map(e))}}),me=he.define({create(){return bo.start()},update(n,e){return n.update(e)},provide:n=>[Br.from(n,e=>e.tooltip),D.contentAttributes.from(n,e=>e.attrs)]});function ko(n,e){let t=e.completion.apply||e.completion.label,i=n.state.field(me).active.find(s=>s.source==e.source);return i instanceof Zn?(typeof t=="string"?n.dispatch({...wp(n.state,t,i.from,i.to),annotations:sf.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}var Ep=Sp(me,ko);function Yn(n,e="option"){return t=>{let i=t.state.field(me,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp-1?i.open.selected+s*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:xo.of(l)}),!0}}var So=n=>{let e=n.state.field(me,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampn.state.field(me,!1)?(n.dispatch({effects:Qn.of(!0)}),!0):!1,Lp=n=>{let e=n.state.field(me,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Vi.of(null)}),!0)},wo=class{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}},Rp=50,Pp=1e3,Ip=be.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(me).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(me),t=n.state.facet(Q);if(!n.selectionSet&&!n.docChanged&&n.startState.field(me)==e)return;let i=n.transactions.some(r=>{let o=rf(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;rRp&&Date.now()-o.time>Pp){for(let l of o.context.abortListeners)try{l()}catch(a){oe(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(r=>r.effects.some(o=>o.is(Qn)))&&(this.pendingStart=!0);let s=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(),s):-1,this.composing!=0)for(let r of n.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:n}=this.view,e=n.field(me);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(Q).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=Rt(e),i=new Jn(e,t,n.explicit,this.view),s=new wo(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Vi.of(null)}),oe(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Q).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Q),i=this.view.state.field(me);for(let s=0;sl.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Xe(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:vo.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(me,!1);if(e&&e.tooltip&&this.view.state.facet(Q).closeOnBlur){let t=e.open&&Er(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Vi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Qn.of(!1)}),20),this.composing=0}}}),Np=typeof navigator=="object"&&/Win/.test(navigator.platform),Hp=tt.highest(D.domEventHandlers({keydown(n,e){let t=e.state.field(me,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(Np&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],s=t.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(n.key)>-1&&ko(e,i),!1}})),Fp=D.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:'"\xB7\xB7\xB7"',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:"'\u0192'"}},".cm-completionIcon-class":{"&:after":{content:"'\u25CB'"}},".cm-completionIcon-interface":{"&:after":{content:"'\u25CC'"}},".cm-completionIcon-variable":{"&:after":{content:"'\u{1D465}'"}},".cm-completionIcon-constant":{"&:after":{content:"'\u{1D436}'"}},".cm-completionIcon-type":{"&:after":{content:"'\u{1D461}'"}},".cm-completionIcon-enum":{"&:after":{content:"'\u222A'"}},".cm-completionIcon-property":{"&:after":{content:"'\u25A1'"}},".cm-completionIcon-keyword":{"&:after":{content:"'\u{1F511}\uFE0E'"}},".cm-completionIcon-namespace":{"&:after":{content:"'\u25A2'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});var zi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Lt=I.define({map(n,e){let t=e.mapPos(n,-1,te.TrackAfter);return t??void 0}}),Co=new class extends ve{};Co.startSide=1;Co.endSide=-1;var of=he.define({create(){return N.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(Lt)&&(n=n.update({add:[Co.range(t.value,t.value+1)]}));return n}});function lf(){return[Vp,of]}var uo="()[]{}<>\xAB\xBB\xBB\xAB\uFF3B\uFF3D\uFF5B\uFF5D";function af(n){for(let e=0;e{if((Wp?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&De(ce(i,0))==1||e!=s.from||t!=s.to)return!1;let r=qp(n.state,i);return r?(n.dispatch(r),!0):!1}),zp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=hf(n,n.selection.main.head).brackets||zi.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=Kp(n.doc,o.head);for(let a of i)if(a==l&&es(n.doc,o.head)==af(ce(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:w.cursor(o.head-a.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},ff=[{key:"Backspace",run:zp}];function qp(n,e){let t=hf(n,n.selection.main.head),i=t.brackets||zi.brackets;for(let s of i){let r=af(ce(s,0));if(e==s)return r==s?Up(n,s,i.indexOf(s+s+s)>-1,t):$p(n,s,r,t.before||zi.before);if(e==r&&cf(n,n.selection.main.from))return jp(n,s,r)}return null}function cf(n,e){let t=!1;return n.field(of).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function es(n,e){let t=n.sliceString(e,e+2);return t.slice(0,De(ce(t,0)))}function Kp(n,e){let t=n.sliceString(e-2,e);return De(ce(t,0))==t.length?t:t.slice(1)}function $p(n,e,t,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:Lt.of(o.to+e.length),range:w.range(o.anchor+e.length,o.head+e.length)};let l=es(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:Lt.of(o.head+e.length),range:w.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function jp(n,e,t){let i=null,s=n.changeByRange(r=>r.empty&&es(n.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:w.cursor(r.head+t.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Up(n,e,t,i){let s=i.stringPrefixes||zi.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:Lt.of(l.to+e.length),range:w.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=es(n.doc,a),f;if(h==e){if(ef(n,a))return{changes:{insert:e+e,from:a},effects:Lt.of(a+e.length),range:w.cursor(a+e.length)};if(cf(n,a)){let u=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:w.cursor(a+u.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(f=tf(n,a-2*e.length,s))>-1&&ef(n,f))return{changes:{insert:e+e+e+e,from:a},effects:Lt.of(a+e.length),range:w.cursor(a+e.length)};if(n.charCategorizer(a)(h)!=ne.Word&&tf(n,a,s)>-1&&!Gp(n,a,e,s))return{changes:{insert:e+e,from:a},effects:Lt.of(a+e.length),range:w.cursor(a+e.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function ef(n,e){let t=ae(n).resolveInner(e+1);return t.parent&&t.from==e}function Gp(n,e,t,i){let s=ae(n).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let f=s.firstChild;for(;f&&f.from==s.from&&f.to-f.from>t.length+a;){if(n.sliceDoc(f.to-t.length,f.to)==t)return!1;f=f.firstChild}return!0}let h=s.to==e&&s.parent;if(!h)break;s=h}return!1}function tf(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=ne.Word)return e;for(let s of t){let r=e-s.length;if(n.sliceDoc(r,e)==s&&i(n.sliceDoc(r-1,r))!=ne.Word)return r}return-1}function uf(n={}){return[Hp,me,Q.of(n),Ip,_p,Fp]}var Ao=[{key:"Ctrl-Space",run:co},{mac:"Alt-`",run:co},{mac:"Alt-i",run:co},{key:"Escape",run:Lp},{key:"ArrowDown",run:Yn(!0)},{key:"ArrowUp",run:Yn(!1)},{key:"PageDown",run:Yn(!0,"page")},{key:"PageUp",run:Yn(!1,"page")},{key:"Enter",run:So}],_p=tt.highest(Mi.computeN([Q],n=>n.facet(Q).defaultKeymap?[Ao]:[]));var Mo={};function To(n,e){for(var t=0;t1&&n.eat("$");var t=n.next();return/['"({]/.test(t)?(e.tokens[0]=ts(t,t=="("?"quote":t=="{"?"def":"string"),si(n,e)):(/\d/.test(t)||n.eatWhile(/\w/),e.tokens.shift(),"def")};function Xp(n){return function(e,t){return e.sol()&&e.string==n&&t.tokens.shift(),e.skipToEnd(),"string.special"}}function si(n,e){return(e.tokens[0]||Yp)(n,e)}var yf={name:"shell",startState:function(){return{tokens:[]}},token:function(n,e){return si(n,e)},languageData:{autocomplete:df.concat(pf,mf),closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"#"}}};var Qp=new Set(["exec","alias","bind","unbindall","wait"]),bf=ti.define({name:"srccfg",startState:()=>({}),token(n){if(n.eatSpace())return null;if(n.match("//"))return n.skipToEnd(),"comment";if(n.match(/^"(?:[^"\\]|\\.)*"?/))return"string";if(n.match(/^-?\d+(?:\.\d+)?/))return"number";if(n.match(/^[A-Za-z_][A-Za-z0-9_]*/)){let e=n.current();return Qp.has(e)?"keyword":"variableName"}return n.next(),null},languageData:{commentTokens:{line:"//"}}});var wf={"&":{backgroundColor:"var(--cm-bg)",color:"var(--cm-fg)",fontFamily:"var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)",fontSize:"14px"},".cm-content":{caretColor:"var(--cm-fg)",padding:"8px"},".cm-cursor":{borderLeftColor:"var(--cm-fg)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:"var(--cm-selection)"},".cm-gutters":{backgroundColor:"var(--cm-bg)",color:"var(--fg-muted, #888)",border:"none"},".cm-tooltip":{backgroundColor:"var(--cm-bg)",border:"1px solid var(--border-strong, #444)",color:"var(--cm-fg)"},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:"var(--cm-selection)"}},xf=D.theme(wf,{dark:!1}),vf=D.theme(wf,{dark:!0}),Zp=ei.define([{tag:x.comment,color:"var(--cm-comment)"},{tag:x.string,color:"var(--cm-string)"},{tag:x.number,color:"var(--cm-number)"},{tag:x.keyword,color:"var(--cm-keyword)"},{tag:x.variableName,color:"var(--cm-fg)"}]),kf=qn(Zp);var Sf=/[A-Za-z0-9_]{2,}/;function em(n,e){let t=n.toLowerCase(),i=e.toLowerCase();if(i===t)return 0;if(i.startsWith(t))return 1+i.length;let s=i.indexOf(t);return s!==-1?1e4+s:-1}function tm(n){let e=[...n.cvars.map(t=>({...t,kind:"cvar"})),...n.commands.map(t=>({...t,kind:"command"}))];return t=>{let i=t.matchBefore(Sf);if(!i||i.from===i.to&&!t.explicit)return null;let s=i.text,r=[];for(let l of e){let a=em(s,l.name);if(a!==-1&&(r.push([a,l]),r.length>200))break}r.sort((l,a)=>l[0]-a[0]);let o=r.slice(0,50).map(([,l])=>({label:l.name,info:l.desc||l.kind,type:l.kind==="command"?"function":"variable"}));return{from:i.from,options:o,validFor:Sf}}}function Cf(n){return uf({override:[tm(n)],activateOnTyping:!0,maxRenderedOptions:8})}var im=ti.define(yf);function Af(n){return n==="srccfg"?bf:n==="bash"?im:null}function Mf(n){return n.matches?vf:xf}function nm(n,{language:e="plain",vocab:t=null}={}){let i=new et,s=new et,r=new et,o=Af(e),l=window.matchMedia("(prefers-color-scheme: dark)"),a=[mh(),Ma(),Ca(),Za(),lf(),Ga(),qn(Ya,{fallback:!0}),kf,s.of(Mf(l)),i.of(o?[o]:[]),r.of(t?[Cf(t)]:[]),Mi.of([{key:"Tab",run:So},...ff,...Gh,...wh,...Ao,_h])],h=q.create({doc:n.value,extensions:a}),f=new D({state:h,parent:n.parentElement});n.parentElement.insertBefore(f.dom,n),n.style.display="none";let c=()=>f.dispatch({effects:s.reconfigure(Mf(l))});return l.addEventListener("change",c),{getValue:()=>f.state.doc.toString(),setContent:d=>{f.dispatch({changes:{from:0,to:f.state.doc.length,insert:d}})},setLanguage:d=>{let p=Af(d);f.dispatch({effects:i.reconfigure(p?[p]:[])})},destroy:()=>{l.removeEventListener("change",c),f.destroy(),n.style.display=""}}}window.__editor={mount:nm};})(); +`);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 s=this.rangeIndex;;){let r=this.ranges[s].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let s=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?s>r:s>=r)break;let o=this.ranges[++this.rangeIndex].from;t+=o-s}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to1){s=this.skipGapsTo(t,s,1),t+=s;let l=this.chunk.length;s=this.skipGapsTo(i,s,-1),i+=s,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),s}parseLine(e){let{line:t,end:i}=this.nextLine(),s=0,{streamParser:r}=this.lang,o=new Wn(t,e?e.state.tabSize:4,e?ct(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=th(r.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,s)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPose.start)return s}throw new Error("Stream parser failed to advance stream.")}var to=Object.create(null),Ni=[le.none],rd=new Rn(Ni),qa=[],Ka=Object.create(null),ih=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])ih[n]=nh(to,e);var Vn=class{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),ih)}resolve(e){return e?this.table[e]||(this.table[e]=nh(this.extra,e)):0}},od=new Vn(to);function Ur(n,e){qa.indexOf(n)>-1||(qa.push(n),console.warn(e))}function nh(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let f=n[h]||x[h];f?typeof f=="function"?a.length?a=a.map(f):Ur(h,`Modifier ${h} used at start of tag`):a.length?Ur(h,`Tag ${h} used as modifier`):a=Array.isArray(f)?f:[f]:Ur(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=Ka[s];if(r)return r.id;let o=Ka[s]=le.define({id:Ni.length,name:i,props:[Pa({[i]:t})]});return Ni.push(o),o.id}function ld(n,e){let t=le.define({id:Ni.length,name:"Document",props:[Qt.add(()=>n),ja.add(()=>i=>e.getIndent(i))],top:!0});return Ni.push(t),t}var Pm={rtl:H.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"rtl"},bidiIsolate:z.RTL}),ltr:H.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"ltr"},bidiIsolate:z.LTR}),auto:H.mark({class:"cm-iso",inclusive:!0,attributes:{dir:"auto"},bidiIsolate:null})};var ad=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=ao(n.state,t.from);return i.line?hd(n):i.block?cd(n):!1};function lo(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}var hd=lo(pd,0);var fd=lo(uh,0);var cd=lo((n,e)=>uh(n,e,dd(e)),0);function ao(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}var Fi=50;function ud(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-Fi,i),o=n.sliceDoc(s,s+Fi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let f,c;s-i<=2*Fi?f=c=n.sliceDoc(i,s):(f=n.sliceDoc(i,i+Fi),c=n.sliceDoc(s-Fi,s));let u=/^\s*/.exec(f)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-t.length;return f.slice(u,u+e.length)==e&&c.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(f.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function dd(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to);s.from>i.from&&s.from==t.to&&(s=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function uh(n,e,t=e.selection.ranges){let i=t.map(r=>ao(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>ud(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;os&&(r==o||o>c.from)){s=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+h.length)==h?u:-1;ur.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:f,single:c}of i)(c||!f)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,f=h+a.length;o.text[f-o.from]==" "&&f++,r.push({from:h,to:f})}return{changes:r}}return null}var no=fe.define(),md=fe.define(),gd=M.define(),dh=M.define({combine(n){return it(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}}),ph=he.define({create(){return Et.empty},update(n,e){let t=e.state.facet(dh),i=e.annotation(no);if(i){let a=Pe.fromTransaction(e,i.selection),h=i.side,f=h==0?n.undone:n.done;return a?f=$n(f,f.length,t.minDepth,a):f=bh(f,e.startState.selection),new Et(h==0?i.rest:f,h==0?f:i.rest)}let s=e.annotation(md);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(J.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=Pe.fromTransaction(e),o=e.annotation(J.time),l=e.annotation(J.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new Et(n.done.map(Pe.fromJSON),n.undone.map(Pe.fromJSON))}});function mh(n={}){return[ph,dh.of(n),D.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?gh:e.inputType=="historyRedo"?so:null;return i?(e.preventDefault(),i(t)):!1}})]}function jn(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(ph,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}var gh=jn(0,!1),so=jn(1,!1),yd=jn(0,!0),bd=jn(1,!0);var Pe=class n{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new n(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new n(e.changes&&se.fromJSON(e.changes),[],e.mapped&&Ue.fromJSON(e.mapped),e.startSelection&&w.fromJSON(e.startSelection),e.selectionsAfter.map(w.fromJSON))}static fromTransaction(e,t){let i=Me;for(let s of e.startState.facet(gd)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new n(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Me)}static selection(e){return new n(void 0,Me,void 0,void 0,e)}};function $n(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function wd(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a=h&&o<=f&&(i=!0)}}),i}function xd(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function yh(n,e){return n.length?e.length?n.concat(e):n:e}var Me=[],vd=200;function bh(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-vd));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),$n(n,n.length-1,1e9,t.setSelAfter(i)))}else return[Pe.selection([e])]}function kd(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function io(n,e){if(!n.length)return n;let t=n.length,i=Me;for(;t;){let s=Sd(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[Pe.selection(i)]:Me}function Sd(n,e,t){let i=yh(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Me,t);if(!n.changes)return Pe.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new Pe(s,I.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}var Cd=/^(input\.type|delete)($|\.)/,Et=class n{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new n(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Cd.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime0&&t-this.prevTimet.empty?n.moveByChar(t,e):Un(t,e))}function ie(n){return n.textDirectionAt(n.state.selection.main.head)==z.LTR}var vh=n=>xh(n,!ie(n)),kh=n=>xh(n,ie(n));function Sh(n,e){return Ne(n,t=>t.empty?n.moveByGroup(t,e):Un(t,e))}var Ad=n=>Sh(n,!ie(n)),Md=n=>Sh(n,ie(n));var Km=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Td(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function Gn(n,e,t){let i=ae(n).resolveInner(e.head),s=t?E.closedBy:E.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Td(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?Re(n,i.from,1):Re(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,w.cursor(l,t?-1:1)}var Dd=n=>Ne(n,e=>Gn(n.state,e,!ie(n))),Od=n=>Ne(n,e=>Gn(n.state,e,ie(n)));function Ch(n,e){return Ne(n,t=>{if(!t.empty)return Un(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}var Ah=n=>Ch(n,!1),Mh=n=>Ch(n,!0);function Th(n){let e=n.scrollDOM.clientHeighto.empty?n.moveVertically(o,e,t.height):Un(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottomDh(n,!1),ro=n=>Dh(n,!0);function ut(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=w.cursor(i.from+r))}return s}var Bd=n=>Ne(n,e=>ut(n,e,!0)),Ed=n=>Ne(n,e=>ut(n,e,!1)),Ld=n=>Ne(n,e=>ut(n,e,!ie(n))),Rd=n=>Ne(n,e=>ut(n,e,ie(n))),Pd=n=>Ne(n,e=>w.cursor(n.lineBlockAt(e.head).from,1)),Id=n=>Ne(n,e=>w.cursor(n.lineBlockAt(e.head).to,-1));function Nd(n,e,t){let i=!1,s=ni(n.selection,r=>{let o=Re(n,r.head,-1)||Re(n,r.head,1)||r.head>0&&Re(n,r.head-1,1)||r.headNd(n,e,!1);function Te(n,e){let t=ni(n.state.selection,i=>{let s=e(i);return w.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return t.eq(n.state.selection)?!1:(n.dispatch(Ie(n.state,t)),!0)}function Oh(n,e){return Te(n,t=>n.moveByChar(t,e))}var Bh=n=>Oh(n,!ie(n)),Eh=n=>Oh(n,ie(n));function Lh(n,e){return Te(n,t=>n.moveByGroup(t,e))}var Fd=n=>Lh(n,!ie(n)),Wd=n=>Lh(n,ie(n));var Vd=n=>Te(n,e=>Gn(n.state,e,!ie(n))),zd=n=>Te(n,e=>Gn(n.state,e,ie(n)));function Rh(n,e){return Te(n,t=>n.moveVertically(t,e))}var Ph=n=>Rh(n,!1),Ih=n=>Rh(n,!0);function Nh(n,e){return Te(n,t=>n.moveVertically(t,e,Th(n).height))}var rh=n=>Nh(n,!1),oh=n=>Nh(n,!0),qd=n=>Te(n,e=>ut(n,e,!0)),Kd=n=>Te(n,e=>ut(n,e,!1)),$d=n=>Te(n,e=>ut(n,e,!ie(n))),jd=n=>Te(n,e=>ut(n,e,ie(n))),Ud=n=>Te(n,e=>w.cursor(n.lineBlockAt(e.head).from)),Gd=n=>Te(n,e=>w.cursor(n.lineBlockAt(e.head).to)),lh=({state:n,dispatch:e})=>(e(Ie(n,{anchor:0})),!0),ah=({state:n,dispatch:e})=>(e(Ie(n,{anchor:n.doc.length})),!0),hh=({state:n,dispatch:e})=>(e(Ie(n,{anchor:n.selection.main.anchor,head:0})),!0),fh=({state:n,dispatch:e})=>(e(Ie(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),_d=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Yd=({state:n,dispatch:e})=>{let t=_n(n).map(({from:i,to:s})=>w.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:w.create(t),userEvent:"select"})),!0},Jd=({state:n,dispatch:e})=>{let t=ni(n.selection,i=>{let s=ae(n),r=s.resolveStack(i.from,1);if(i.empty){let o=s.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.to||l.to>i.to&&l.from<=i.from)&&o.next)return w.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ie(n,t)),!0)};function Hh(n,e){let{state:t}=n,i=t.selection,s=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to0)for(let l=r;;){let a=n.moveVertically(l,e);if(a.heado.to){s.some(h=>h.head==a.head)||s.push(a);break}else{if(a.head==l.head)break;l=a}}}return s.length==i.ranges.length?!1:(n.dispatch(Ie(t,w.create(s,s.length-1))),!0)}var Xd=n=>Hh(n,!1),Qd=n=>Hh(n,!0),Zd=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=w.create([t.main]):t.main.empty||(i=w.create([w.cursor(t.main.head)])),i?(e(Ie(n,i)),!0):!1};function Wi(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);ao&&(t="delete.forward",a=Kn(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Kn(n,o,!1),l=Kn(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:w.cursor(o,os(n)))i.between(e,e,(s,r)=>{se&&(e=t?r:s)});return e}var Fh=(n,e,t)=>Wi(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&sFh(n,!1,!0);var Wh=n=>Fh(n,!0,!1),Vh=(n,e)=>Wi(n,t=>{let i=t.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=X(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),f=o(h);if(l!=null&&f!=l)break;(h!=" "||i!=t.head)&&(l=f),i=a}return i}),zh=n=>Vh(n,!1),ep=n=>Vh(n,!0);var tp=n=>Wi(n,e=>{let t=n.lineBlockAt(e.head).to;return e.headWi(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),np=n=>Wi(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:L.of(["",""])},range:w.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},rp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:X(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:X(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:w.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function _n(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function qh(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of _n(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(w.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(w.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:w.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}var op=({state:n,dispatch:e})=>qh(n,e,!1),lp=({state:n,dispatch:e})=>qh(n,e,!0);function Kh(n,e,t){if(n.readOnly)return!1;let i=[];for(let r of _n(n))t?i.push({from:r.from,insert:n.doc.slice(r.from,r.to)+n.lineBreak}):i.push({from:r.to,insert:n.lineBreak+n.doc.slice(r.from,r.to)});let s=n.changes(i);return e(n.update({changes:s,selection:n.selection.map(s,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var ap=({state:n,dispatch:e})=>Kh(n,e,!1),hp=({state:n,dispatch:e})=>Kh(n,e,!0),fp=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(_n(e).map(({from:s,to:r})=>(s>0?s--:r{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function cp(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ae(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(E.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}var ch=$h(!1),up=$h(!0);function $h(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&cp(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Bt(e,{simulateBreak:r,simulateDoubleBreak:!!a}),f=zn(h,r);for(f==null&&(f=xt(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));ol.from&&r{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:w.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}var dp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Bt(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=ho(n,(r,o,l)=>{let a=zn(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],f=ii(n,a);(h!=f||l.fromn.readOnly?!1:(e(n.update(ho(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Hi)})}),{userEvent:"input.indent"})),!0),Uh=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(ho(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=xt(s,n.tabSize),o=0,l=ii(n,Math.max(0,r-ct(n)));for(;o(n.setTabFocusMode(),!0);var mp=[{key:"Ctrl-b",run:vh,shift:Bh,preventDefault:!0},{key:"Ctrl-f",run:kh,shift:Eh},{key:"Ctrl-p",run:Ah,shift:Ph},{key:"Ctrl-n",run:Mh,shift:Ih},{key:"Ctrl-a",run:Pd,shift:Ud},{key:"Ctrl-e",run:Id,shift:Gd},{key:"Ctrl-d",run:Wh},{key:"Ctrl-h",run:oo},{key:"Ctrl-k",run:tp},{key:"Ctrl-Alt-h",run:zh},{key:"Ctrl-o",run:sp},{key:"Ctrl-t",run:rp},{key:"Ctrl-v",run:ro}],gp=[{key:"ArrowLeft",run:vh,shift:Bh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Ad,shift:Fd,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Ld,shift:$d,preventDefault:!0},{key:"ArrowRight",run:kh,shift:Eh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Md,shift:Wd,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Rd,shift:jd,preventDefault:!0},{key:"ArrowUp",run:Ah,shift:Ph,preventDefault:!0},{mac:"Cmd-ArrowUp",run:lh,shift:hh},{mac:"Ctrl-ArrowUp",run:sh,shift:rh},{key:"ArrowDown",run:Mh,shift:Ih,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ah,shift:fh},{mac:"Ctrl-ArrowDown",run:ro,shift:oh},{key:"PageUp",run:sh,shift:rh},{key:"PageDown",run:ro,shift:oh},{key:"Home",run:Ed,shift:Kd,preventDefault:!0},{key:"Mod-Home",run:lh,shift:hh},{key:"End",run:Bd,shift:qd,preventDefault:!0},{key:"Mod-End",run:ah,shift:fh},{key:"Enter",run:ch,shift:ch},{key:"Mod-a",run:_d},{key:"Backspace",run:oo,shift:oo,preventDefault:!0},{key:"Delete",run:Wh,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:zh,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:ep,preventDefault:!0},{mac:"Mod-Backspace",run:ip,preventDefault:!0},{mac:"Mod-Delete",run:np,preventDefault:!0}].concat(mp.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Gh=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Dd,shift:Vd},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Od,shift:zd},{key:"Alt-ArrowUp",run:op},{key:"Shift-Alt-ArrowUp",run:ap},{key:"Alt-ArrowDown",run:lp},{key:"Shift-Alt-ArrowDown",run:hp},{key:"Mod-Alt-ArrowUp",run:Xd},{key:"Mod-Alt-ArrowDown",run:Qd},{key:"Escape",run:Zd},{key:"Mod-Enter",run:up},{key:"Alt-l",mac:"Ctrl-l",run:Yd},{key:"Mod-i",run:Jd,preventDefault:!0},{key:"Mod-[",run:Uh},{key:"Mod-]",run:jh},{key:"Mod-Alt-\\",run:dp},{key:"Shift-Mod-k",run:fp},{key:"Shift-Mod-\\",run:Hd},{key:"Mod-/",run:ad},{key:"Alt-A",run:fd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:pp}].concat(gp),_h={key:"Tab",run:jh,shift:Uh};var Jn=class{constructor(e,t,i,s){this.state=e,this.pos=t,this.explicit=i,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=ae(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),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(nf(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.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 Yh(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function yp(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;rtypeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:yp(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}var Xn=class{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}};function Rt(n){return n.selection.main.from}function nf(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}var sf=fe.define();function wp(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return{...n.changeByRange(l=>{if(l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:a},range:w.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}var Jh=new WeakMap;function xp(n){if(!Array.isArray(n))return n;let e=Jh.get(n);return e||Jh.set(n,e=bp(n)),e}var Qn=I.define(),Vi=I.define(),po=class{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=48&&C<=57||C>=97&&C<=122?2:C>=65&&C<=90?1:0:(T=bs(C))!=T.toLowerCase()?1:T!=T.toUpperCase()?2:0;(!b||A==1&&g||O==0&&A!=0)&&(t[c]==C||i[c]==C&&(u=!0)?o[c++]=b:o.length&&(y=!1)),O=A,b+=De(C)}return c==a&&o[0]==0&&y?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]):c==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?De(ce(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}},mo=class{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:vp,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=>Xh(e(i),t(i)),optionClass:(e,t)=>i=>Xh(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Xh(n,e){return n?e?n+" "+e:n:e}function vp(n,e,t,i,s,r){let o=n.textDirection==z.RTL,l=o,a=!1,h="top",f,c,u=e.left-s.left,d=s.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&u=m||b>e.top?f=t.bottom-e.top:(h="bottom",f=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${f/g}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}var xo=I.define();function kp(n){let e=n.addToOptions.slice();return n.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(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;ha&&o.appendChild(document.createTextNode(l.slice(a,f)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(f,c))),u.className="cm-completionMatchedText",a=c}return at.position-i.position).map(t=>t.render)}function fo(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.ceil((n-e)/t);return{from:n-i*t,to:n-(i-1)*t}}var go=class{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 s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(Q);this.optionContent=kp(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=fo(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 f=a.target,c;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(c=/-(\d+)$/.exec(f.id))&&+c[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;f!=null&&(e.dispatch({effects:xo.of(f)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(Q).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Vi.of(null)})}),this.showOptions(r,s.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),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=fo(r.length,o,e.state.facet(Q).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=s.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.to)&&(this.range=fo(t.options.length,t.selected,this.view.state.facet(Q).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();let{completion:s}=t.options[t.selected],{info:r}=s;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(s);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,s)}).catch(l=>oe(this.view.state,l,"completion info")):(this.addInfoPane(o,s),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:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==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&&Cp(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(),s=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 s.top>Math.min(r.bottom,t.bottom)-10||s.bottom{o.target==s&&o.preventDefault()});let r=null;for(let o=i.from;oi.from||i.from==0))if(r=u,typeof h!="string"&&h.header)s.appendChild(h.header(h));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=u}}let f=s.appendChild(document.createElement("li"));f.id=t+"-"+o,f.setAttribute("role","option");let c=this.optionClass(l);c&&(f.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&f.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.tonew go(t,n,e)}function Cp(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),s=t.height/n.offsetHeight;i.topt.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/s)}function Qh(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function Ap(n,e){let t=[],i=null,s=null,r=f=>{t.push(f);let{section:c}=f.completion;if(c){i||(i=[]);let u=typeof c=="string"?c:c.name;i.some(d=>d.name==u)||i.push(typeof c=="string"?{name:u}:c)}},o=e.facet(Q);for(let f of n)if(f.hasResult()){let c=f.result.getMatch;if(f.result.filter===!1)for(let u of f.result.options)r(new Xn(u,f.source,c?c(u):[],1e9-t.length));else{let u=e.sliceDoc(f.from,f.to),d,p=o.filterStrict?new mo(u):new po(u);for(let m of f.result.options)if(d=p.match(m.label)){let g=m.displayLabel?c?c(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(r(new Xn(m,f.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:b}=m.section;s||(s=Object.create(null)),s[b]=Math.max(y,s[b]||-1e9)}}}}if(i){let f=Object.create(null),c=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?s[p.name]-s[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.nameu.score-c.score||h(c.completion,u.completion))){let c=f.completion;!a||a.label!=c.label||a.detail!=c.detail||a.type!=null&&c.type!=null&&a.type!=c.type||a.apply!=c.apply||a.boost!=c.boost?l.push(f):Qh(f.completion)>Qh(a)&&(l[l.length-1]=f),a=f.completion}return l}var yo=class n{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new n(this.options,Zh(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r,o){if(s&&!o&&e.some(h=>h.isPending))return s.setDisabled();let l=Ap(e,t);if(!l.length)return s&&e.some(h=>h.isPending)?s.setDisabled():null;let a=t.facet(Q).selectOnOpen?0:-1;if(s&&s.selected!=a&&s.selected!=-1){let h=s.options[s.selected].completion;for(let f=0;ff.hasResult()?Math.min(h,f.from):h,1e8),create:Ep,above:r.aboveCursor},s?s.timestamp:Date.now(),a,!1)}map(e){return new n(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new n(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}},bo=class n{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new n(Op,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Q),r=(i.override||t.languageDataAt("autocomplete",Rt(t)).map(xp)).map(a=>(this.active.find(f=>f.source==a)||new Xe(a,this.active.some(f=>f.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(vo));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!Mp(r,this.active)||l?o=yo.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 Xe(a.source,0):a));for(let a of e.effects)a.is(xo)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new n(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Tp:Dp}};function Mp(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t-1&&(t["aria-activedescendant"]=n+"-"+e),t}var Op=[];function rf(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(sf);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}var Xe=class n{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=rf(e,t),s=this;(i&8||i&16&&this.touches(e))&&(s=new n(s.source,0)),i&4&&s.state==0&&(s=new n(this.source,1)),s=s.updateFor(e,i);for(let r of e.effects)if(r.is(Qn))s=new n(s.source,1,r.value);else if(r.is(Vi))s=new n(s.source,0);else if(r.is(vo))for(let o of r.value)o.source==s.source&&(s=o);return s}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Rt(e.state))}},Zn=class n extends Xe{constructor(e,t,i,s,r,o){super(e,3,t),this.limit=i,this.result=s,this.from=r,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=Rt(e.state);if(l>o||!s||t&2&&(Rt(e.startState)==this.from||lt.map(e))}}),me=he.define({create(){return bo.start()},update(n,e){return n.update(e)},provide:n=>[Br.from(n,e=>e.tooltip),D.contentAttributes.from(n,e=>e.attrs)]});function ko(n,e){let t=e.completion.apply||e.completion.label,i=n.state.field(me).active.find(s=>s.source==e.source);return i instanceof Zn?(typeof t=="string"?n.dispatch({...wp(n.state,t,i.from,i.to),annotations:sf.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}var Ep=Sp(me,ko);function Yn(n,e="option"){return t=>{let i=t.state.field(me,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp-1?i.open.selected+s*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:xo.of(l)}),!0}}var So=n=>{let e=n.state.field(me,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampn.state.field(me,!1)?(n.dispatch({effects:Qn.of(!0)}),!0):!1,Lp=n=>{let e=n.state.field(me,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Vi.of(null)}),!0)},wo=class{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}},Rp=50,Pp=1e3,Ip=be.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(me).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(me),t=n.state.facet(Q);if(!n.selectionSet&&!n.docChanged&&n.startState.field(me)==e)return;let i=n.transactions.some(r=>{let o=rf(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;rRp&&Date.now()-o.time>Pp){for(let l of o.context.abortListeners)try{l()}catch(a){oe(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(r=>r.effects.some(o=>o.is(Qn)))&&(this.pendingStart=!0);let s=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(),s):-1,this.composing!=0)for(let r of n.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:n}=this.view,e=n.field(me);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(Q).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=Rt(e),i=new Jn(e,t,n.explicit,this.view),s=new wo(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Vi.of(null)}),oe(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Q).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Q),i=this.view.state.field(me);for(let s=0;sl.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Xe(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:vo.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(me,!1);if(e&&e.tooltip&&this.view.state.facet(Q).closeOnBlur){let t=e.open&&Er(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Vi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Qn.of(!1)}),20),this.composing=0}}}),Np=typeof navigator=="object"&&/Win/.test(navigator.platform),Hp=tt.highest(D.domEventHandlers({keydown(n,e){let t=e.state.field(me,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(Np&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],s=t.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(n.key)>-1&&ko(e,i),!1}})),Fp=D.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:'"\xB7\xB7\xB7"',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:"'\u0192'"}},".cm-completionIcon-class":{"&:after":{content:"'\u25CB'"}},".cm-completionIcon-interface":{"&:after":{content:"'\u25CC'"}},".cm-completionIcon-variable":{"&:after":{content:"'\u{1D465}'"}},".cm-completionIcon-constant":{"&:after":{content:"'\u{1D436}'"}},".cm-completionIcon-type":{"&:after":{content:"'\u{1D461}'"}},".cm-completionIcon-enum":{"&:after":{content:"'\u222A'"}},".cm-completionIcon-property":{"&:after":{content:"'\u25A1'"}},".cm-completionIcon-keyword":{"&:after":{content:"'\u{1F511}\uFE0E'"}},".cm-completionIcon-namespace":{"&:after":{content:"'\u25A2'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});var zi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Lt=I.define({map(n,e){let t=e.mapPos(n,-1,te.TrackAfter);return t??void 0}}),Co=new class extends ve{};Co.startSide=1;Co.endSide=-1;var of=he.define({create(){return N.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(Lt)&&(n=n.update({add:[Co.range(t.value,t.value+1)]}));return n}});function lf(){return[Vp,of]}var uo="()[]{}<>\xAB\xBB\xBB\xAB\uFF3B\uFF3D\uFF5B\uFF5D";function af(n){for(let e=0;e{if((Wp?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&De(ce(i,0))==1||e!=s.from||t!=s.to)return!1;let r=qp(n.state,i);return r?(n.dispatch(r),!0):!1}),zp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=hf(n,n.selection.main.head).brackets||zi.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=Kp(n.doc,o.head);for(let a of i)if(a==l&&es(n.doc,o.head)==af(ce(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:w.cursor(o.head-a.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},ff=[{key:"Backspace",run:zp}];function qp(n,e){let t=hf(n,n.selection.main.head),i=t.brackets||zi.brackets;for(let s of i){let r=af(ce(s,0));if(e==s)return r==s?Up(n,s,i.indexOf(s+s+s)>-1,t):$p(n,s,r,t.before||zi.before);if(e==r&&cf(n,n.selection.main.from))return jp(n,s,r)}return null}function cf(n,e){let t=!1;return n.field(of).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function es(n,e){let t=n.sliceString(e,e+2);return t.slice(0,De(ce(t,0)))}function Kp(n,e){let t=n.sliceString(e-2,e);return De(ce(t,0))==t.length?t:t.slice(1)}function $p(n,e,t,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:Lt.of(o.to+e.length),range:w.range(o.anchor+e.length,o.head+e.length)};let l=es(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:Lt.of(o.head+e.length),range:w.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function jp(n,e,t){let i=null,s=n.changeByRange(r=>r.empty&&es(n.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:w.cursor(r.head+t.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Up(n,e,t,i){let s=i.stringPrefixes||zi.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:Lt.of(l.to+e.length),range:w.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=es(n.doc,a),f;if(h==e){if(ef(n,a))return{changes:{insert:e+e,from:a},effects:Lt.of(a+e.length),range:w.cursor(a+e.length)};if(cf(n,a)){let u=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:w.cursor(a+u.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(f=tf(n,a-2*e.length,s))>-1&&ef(n,f))return{changes:{insert:e+e+e+e,from:a},effects:Lt.of(a+e.length),range:w.cursor(a+e.length)};if(n.charCategorizer(a)(h)!=ne.Word&&tf(n,a,s)>-1&&!Gp(n,a,e,s))return{changes:{insert:e+e,from:a},effects:Lt.of(a+e.length),range:w.cursor(a+e.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function ef(n,e){let t=ae(n).resolveInner(e+1);return t.parent&&t.from==e}function Gp(n,e,t,i){let s=ae(n).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let f=s.firstChild;for(;f&&f.from==s.from&&f.to-f.from>t.length+a;){if(n.sliceDoc(f.to-t.length,f.to)==t)return!1;f=f.firstChild}return!0}let h=s.to==e&&s.parent;if(!h)break;s=h}return!1}function tf(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=ne.Word)return e;for(let s of t){let r=e-s.length;if(n.sliceDoc(r,e)==s&&i(n.sliceDoc(r-1,r))!=ne.Word)return r}return-1}function uf(n={}){return[Hp,me,Q.of(n),Ip,_p,Fp]}var Ao=[{key:"Ctrl-Space",run:co},{mac:"Alt-`",run:co},{mac:"Alt-i",run:co},{key:"Escape",run:Lp},{key:"ArrowDown",run:Yn(!0)},{key:"ArrowUp",run:Yn(!1)},{key:"PageDown",run:Yn(!0,"page")},{key:"PageUp",run:Yn(!1,"page")},{key:"Enter",run:So}],_p=tt.highest(Mi.computeN([Q],n=>n.facet(Q).defaultKeymap?[Ao]:[]));var Mo={};function To(n,e){for(var t=0;t1&&n.eat("$");var t=n.next();return/['"({]/.test(t)?(e.tokens[0]=ts(t,t=="("?"quote":t=="{"?"def":"string"),si(n,e)):(/\d/.test(t)||n.eatWhile(/\w/),e.tokens.shift(),"def")};function Xp(n){return function(e,t){return e.sol()&&e.string==n&&t.tokens.shift(),e.skipToEnd(),"string.special"}}function si(n,e){return(e.tokens[0]||Yp)(n,e)}var yf={name:"shell",startState:function(){return{tokens:[]}},token:function(n,e){return si(n,e)},languageData:{autocomplete:df.concat(pf,mf),closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"#"}}};var Qp=new Set(["exec","alias","bind","unbindall","wait"]),bf=ti.define({name:"srccfg",startState:()=>({}),token(n){if(n.eatSpace())return null;if(n.match("//"))return n.skipToEnd(),"comment";if(n.match(/^"(?:[^"\\]|\\.)*"?/))return"string";if(n.match(/^-?\d+(?:\.\d+)?/))return"number";if(n.match(/^[A-Za-z_][A-Za-z0-9_]*/)){let e=n.current();return Qp.has(e)?"keyword":"variableName"}return n.next(),null},languageData:{commentTokens:{line:"//"}}});var wf={"&":{backgroundColor:"var(--cm-bg)",color:"var(--cm-fg)",fontFamily:"var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace)",fontSize:"14px"},".cm-content":{caretColor:"var(--cm-fg)",padding:"8px"},".cm-cursor":{borderLeftColor:"var(--cm-fg)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:"var(--cm-selection)"},".cm-gutters":{backgroundColor:"var(--cm-bg)",color:"var(--fg-muted, #888)",border:"none"},".cm-tooltip":{backgroundColor:"var(--cm-bg)",border:"1px solid var(--border-strong, #444)",color:"var(--cm-fg)"},".cm-tooltip-autocomplete > ul > li[aria-selected]":{backgroundColor:"var(--cm-selection)"}},xf=D.theme(wf,{dark:!1}),vf=D.theme(wf,{dark:!0}),Zp=ei.define([{tag:x.comment,color:"var(--cm-comment)"},{tag:x.string,color:"var(--cm-string)"},{tag:x.number,color:"var(--cm-number)"},{tag:x.keyword,color:"var(--cm-keyword)"},{tag:x.variableName,color:"var(--cm-fg)"}]),kf=qn(Zp);var Sf=/[A-Za-z0-9_]{2,}/;function em(n,e){let t=n.toLowerCase(),i=e.toLowerCase();if(i===t)return 0;if(i.startsWith(t))return 1+i.length;let s=i.indexOf(t);return s!==-1?1e4+s:-1}function tm(n){let e=[...n.cvars.map(t=>({...t,kind:"cvar"})),...n.commands.map(t=>({...t,kind:"command"}))];return t=>{let i=t.matchBefore(Sf);if(!i||i.from===i.to&&!t.explicit)return null;let s=i.text,r=[];for(let l of e){let a=em(s,l.name);if(a!==-1&&(r.push([a,l]),r.length>200))break}r.sort((l,a)=>l[0]-a[0]);let o=r.slice(0,50).map(([,l])=>({label:l.name,info:l.desc||l.kind,type:l.kind==="command"?"function":"variable"}));return{from:i.from,options:o,validFor:Sf}}}function Cf(n){return uf({override:[tm(n)],activateOnTyping:!0,maxRenderedOptions:8})}var im=ti.define(yf);function Af(n){return n==="srccfg"?bf:n==="bash"?im:null}function Mf(n){return n.matches?vf:xf}function nm(n,{language:e="plain",vocab:t=null,rows:i=0}={}){let s=new et,r=new et,o=new et,l=Af(e),a=window.matchMedia("(prefers-color-scheme: dark)"),f=[...i>0?[D.theme({"&":{height:`calc(${i} * 1.84rem + 1.125rem)`},".cm-scroller":{overflow:"auto"}})]:[],mh(),Ma(),Ca(),Za(),lf(),Ga(),qn(Ya,{fallback:!0}),kf,r.of(Mf(a)),s.of(l?[l]:[]),o.of(t?[Cf(t)]:[]),Mi.of([{key:"Tab",run:So},...ff,...Gh,...wh,...Ao,_h])],c=q.create({doc:n.value,extensions:f}),u=new D({state:c,parent:n.parentElement});n.parentElement.insertBefore(u.dom,n),n.style.display="none";let d=()=>u.dispatch({effects:r.reconfigure(Mf(a))});return a.addEventListener("change",d),{getValue:()=>u.state.doc.toString(),setContent:m=>{u.dispatch({changes:{from:0,to:u.state.doc.length,insert:m}})},setLanguage:m=>{let g=Af(m);u.dispatch({effects:s.reconfigure(g?[g]:[])})},destroy:()=>{a.removeEventListener("change",d),u.destroy(),n.style.display=""}}}window.__editor={mount:nm};})(); diff --git a/l4d2web/l4d2web/static/vendor/editor.bundle.sha256 b/l4d2web/l4d2web/static/vendor/editor.bundle.sha256 index f9370d3..eb788f8 100644 --- a/l4d2web/l4d2web/static/vendor/editor.bundle.sha256 +++ b/l4d2web/l4d2web/static/vendor/editor.bundle.sha256 @@ -1,2 +1,2 @@ -6700b694fe25837f52e77c780d88f3eb5aef2a1591dc461c26efa3fa9724290b editor.bundle.js +910031cfc346106af240df71b9ef8069f1b38f1a4c63128392c2aa074e7e57b2 editor.bundle.js e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 editor.bundle.css diff --git a/l4d2web/l4d2web/templates/blueprint_detail.html b/l4d2web/l4d2web/templates/blueprint_detail.html index 0fae77b..ee3c366 100644 --- a/l4d2web/l4d2web/templates/blueprint_detail.html +++ b/l4d2web/l4d2web/templates/blueprint_detail.html @@ -51,7 +51,7 @@
{% for o in exposed %}exec {{ o.name }}.cfg
 {% endfor %}
{% endif %} - +
diff --git a/l4d2web/l4d2web/templates/overlay_detail.html b/l4d2web/l4d2web/templates/overlay_detail.html index 597e11a..17576cb 100644 --- a/l4d2web/l4d2web/templates/overlay_detail.html +++ b/l4d2web/l4d2web/templates/overlay_detail.html @@ -24,7 +24,7 @@

Runs sandboxed against the overlay directory mounted at /overlay.

{% if not latest_build_is_running %} @@ -186,7 +186,7 @@
UTF-8 · 0 bytes diff --git a/l4d2web/scripts/editor-src/editor-entry.js b/l4d2web/scripts/editor-src/editor-entry.js index 1e1ac94..1fc58e3 100644 --- a/l4d2web/scripts/editor-src/editor-entry.js +++ b/l4d2web/scripts/editor-src/editor-entry.js @@ -21,7 +21,7 @@ function pickThemeForMatchMedia(mm) { return mm.matches ? editorDarkTheme : editorLightTheme; } -function mount(textarea, { language = "plain", vocab = null } = {}) { +function mount(textarea, { language = "plain", vocab = null, rows = 0 } = {}) { const langCompartment = new Compartment(); const themeCompartment = new Compartment(); const autocompleteCompartment = new Compartment(); @@ -29,7 +29,21 @@ function mount(textarea, { language = "plain", vocab = null } = {}) { const lang = pickLanguage(language); const mm = window.matchMedia("(prefers-color-scheme: dark)"); + // Fix the editor's rendered height to match the textarea's `rows` + // attribute via a small EditorView.theme — keeps the wrapper's + // pre-reserved space (editor.css `.editor-mount`) and the actual + // cm6 height in lockstep, eliminating the mount-time layout shift. + // Empirical per-row metric on this build: 1.84rem content + 1.125rem + // chrome (8px top + 8px bottom padding + 1px×2 border). + const heightThemes = rows > 0 ? [ + EditorView.theme({ + "&": { height: `calc(${rows} * 1.84rem + 1.125rem)` }, + ".cm-scroller": { overflow: "auto" }, + }), + ] : []; + const extensions = [ + ...heightThemes, history(), lineNumbers(), highlightActiveLine(),