claudekit-cli 3.41.4-dev.40 → 3.41.4-dev.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -267,7 +267,7 @@ Please change the parent <Route path="${w}"> to <Route path="${w==="/"?"*":`${w}
267
267
  `&&t.lineWrapping&&(r&&(r=q.single(r.main.anchor-1,r.main.head-1)),n={from:s.from,to:s.to,insert:We.of([" "])}),n)return og(t,n,r,i);if(r&&!r.main.eq(s)){let o=!1,a="select";return t.inputState.lastSelectionTime>Date.now()-50&&(t.inputState.lastSelectionOrigin=="select"&&(o=!0),a=t.inputState.lastSelectionOrigin,a=="select.pointer"&&(r=s2(t.state.facet(Kl).map(l=>l(t)),r))),t.dispatch({selection:r,scrollIntoView:o,userEvent:a}),!0}else return!1}function og(t,e,n,r=-1){if(pe.ios&&t.inputState.flushIOSKey(e))return!0;let s=t.state.selection.main;if(pe.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&t.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&zi(t.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&zi(t.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&zi(t.contentDOM,"Delete",46)))return!0;let i=e.insert.toString();t.inputState.composing>=0&&t.inputState.composing++;let o,a=()=>o||(o=ZA(t,e,n));return t.state.facet(Uk).some(l=>l(t,e.from,e.to,i,a))||t.dispatch(a()),!0}function ZA(t,e,n){let r,s=t.state,i=s.selection.main,o=-1;if(e.from==e.to&&e.from<i.from||e.from>i.to){let l=e.from<i.from?-1:1,d=l<0?i.from:i.to,u=da(s.facet(Kl).map(h=>h(t)),d,l);e.from==u&&(o=u)}if(o>-1)r={changes:e,selection:q.cursor(e.from+e.insert.length,-1)};else if(e.from>=i.from&&e.to<=i.to&&e.to-e.from>=(i.to-i.from)/3&&(!n||n.main.empty&&n.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let l=i.from<e.from?s.sliceDoc(i.from,e.from):"",d=i.to>e.to?s.sliceDoc(e.to,i.to):"";r=s.replaceSelection(t.state.toText(l+e.insert.sliceString(0,void 0,t.state.lineBreak)+d))}else{let l=s.changes(e),d=n&&n.main.to<=l.newLength?n.main:void 0;if(s.selection.ranges.length>1&&(t.inputState.composing>=0||t.inputState.compositionPendingChange)&&e.to<=i.to+10&&e.to>=i.to-10){let u=t.state.sliceDoc(e.from,e.to),h,f=n&&r2(t,n.main.head);if(f){let m=e.insert.length-(e.to-e.from);h={from:f.from,to:f.to-m}}else h=t.state.doc.lineAt(i.head);let p=i.to-e.to;r=s.changeByRange(m=>{if(m.from==i.from&&m.to==i.to)return{changes:l,range:d||m.map(l)};let x=m.to-p,b=x-u.length;if(t.state.sliceDoc(b,x)!=u||x>=h.from&&b<=h.to)return{range:m};let y=s.changes({from:b,to:x,insert:e.insert}),w=m.to-i.to;return{changes:y,range:d?q.range(Math.max(0,d.anchor+w),Math.max(0,d.head+w)):m.map(y)}})}else r={changes:l,selection:d&&s.selection.replaceRange(d)}}let a="input.type";return(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,a+=".compose",t.inputState.compositionFirstChange&&(a+=".start",t.inputState.compositionFirstChange=!1)),s.update(r,{userEvent:a,scrollIntoView:!0})}function l2(t,e,n,r){let s=Math.min(t.length,e.length),i=0;for(;i<s&&t.charCodeAt(i)==e.charCodeAt(i);)i++;if(i==s&&t.length==e.length)return null;let o=t.length,a=e.length;for(;o>0&&a>0&&t.charCodeAt(o-1)==e.charCodeAt(a-1);)o--,a--;if(r=="end"){let l=Math.max(0,i-Math.min(o,a));n-=o+l-i}if(o<i&&t.length<e.length){let l=n<=i&&n>=o?i-n:0;i-=l,a=i+(a-o),o=i}else if(a<i){let l=n<=i&&n>=a?i-n:0;i-=l,o=i+(o-a),a=i}return{from:i,toA:o,toB:a}}function QA(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:n,anchorOffset:r,focusNode:s,focusOffset:i}=t.observer.selectionRange;return n&&(e.push(new Wx(n,r)),(s!=n||i!=r)&&e.push(new Wx(s,i))),e}function JA(t,e){if(t.length==0)return null;let n=t[0].pos,r=t.length==2?t[1].pos:n;return n>-1&&r>-1?q.single(n+e,r+e):null}class eM{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=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,pe.safari&&e.contentDOM.addEventListener("input",()=>null),pe.gecko&&mM(e.contentDOM.ownerDocument)}handleEvent(e){!lM(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,n){let r=this.handlers[e];if(r){for(let s of r.observers)s(this.view,n);for(let s of r.handlers){if(n.defaultPrevented)break;if(s(this.view,n)){n.preventDefault();break}}}}ensureHandlers(e){let n=tM(e),r=this.handlers,s=this.view.contentDOM;for(let i in n)if(i!="scroll"){let o=!n[i].handlers.length,a=r[i];a&&o!=!a.handlers.length&&(s.removeEventListener(i,this.handleEvent),a=null),a||s.addEventListener(i,this.handleEvent,{passive:o})}for(let i in r)i!="scroll"&&!n[i]&&s.removeEventListener(i,this.handleEvent);this.handlers=n}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&&d2.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),pe.android&&pe.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let n;return pe.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((n=c2.find(r=>r.keyCode==e.keyCode))&&!e.ctrlKey||nM.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=n||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let n=this.pendingIOSKey;return!n||n.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,zi(this.view.contentDOM,n.key,n.keyCode,n instanceof KeyboardEvent?n:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:pe.safari&&!pe.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 Ux(t,e){return(n,r)=>{try{return e.call(t,r,n)}catch(s){sn(n.state,s)}}}function tM(t){let e=Object.create(null);function n(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of t){let s=r.spec,i=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(i)for(let a in i){let l=i[a];l&&n(a).handlers.push(Ux(r.value,l))}if(o)for(let a in o){let l=o[a];l&&n(a).observers.push(Ux(r.value,l))}}for(let r in Jn)n(r).handlers.push(Jn[r]);for(let r in In)n(r).observers.push(In[r]);return e}const c2=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],nM="dthko",d2=[16,17,18,20,91,92,224,225],Pc=6;function Oc(t){return Math.max(0,t)*.7+8}function rM(t,e){return Math.max(Math.abs(t.clientX-e.clientX),Math.abs(t.clientY-e.clientY))}class sM{constructor(e,n,r,s){this.view=e,this.startEvent=n,this.style=r,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=n,this.scrollParents=aA(e.contentDOM),this.atoms=e.state.facet(Kl).map(o=>o(e));let i=e.contentDOM.ownerDocument;i.addEventListener("mousemove",this.move=this.move.bind(this)),i.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=n.shiftKey,this.multiple=e.state.facet(Ie.allowMultipleSelections)&&iM(e,n),this.dragging=aM(e,n)&&f2(n)==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&&rM(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let n=0,r=0,s=0,i=0,o=this.view.win.innerWidth,a=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:i,bottom:a}=this.scrollParents.y.getBoundingClientRect());let l=ig(this.view);e.clientX-l.left<=s+Pc?n=-Oc(s-e.clientX):e.clientX+l.right>=o-Pc&&(n=Oc(e.clientX-o)),e.clientY-l.top<=i+Pc?r=-Oc(i-e.clientY):e.clientY+l.bottom>=a-Pc&&(r=Oc(e.clientY-a)),this.setScrollSpeed(n,r)}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,n){this.scrollSpeed={x:e,y:n},e||n?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:n}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),n&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=n,n=0),(e||n)&&this.view.win.scrollBy(e,n),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:n}=this,r=s2(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(n.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(n=>n.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function iM(t,e){let n=t.state.facet(zk);return n.length?n[0](e):pe.mac?e.metaKey:e.ctrlKey}function oM(t,e){let n=t.state.facet(Vk);return n.length?n[0](e):pe.mac?!e.altKey:!e.ctrlKey}function aM(t,e){let{main:n}=t.state.selection;if(n.empty)return!1;let r=Da(t.root);if(!r||r.rangeCount==0)return!0;let s=r.getRangeAt(0).getClientRects();for(let i=0;i<s.length;i++){let o=s[i];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function lM(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let n=e.target,r;n!=t.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=mt.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}const Jn=Object.create(null),In=Object.create(null),u2=pe.ie&&pe.ie_version<15||pe.ios&&pe.webkit_version<604;function cM(t){let e=t.dom.parentNode;if(!e)return;let n=e.appendChild(document.createElement("textarea"));n.style.cssText="position: fixed; left: -10000px; top: 10px",n.focus(),setTimeout(()=>{t.focus(),n.remove(),h2(t,n.value)},50)}function zu(t,e,n){for(let r of t.facet(e))n=r(n,t);return n}function h2(t,e){e=zu(t.state,ng,e);let{state:n}=t,r,s=1,i=n.toText(e),o=i.lines==n.selection.ranges.length;if(Ip!=null&&n.selection.ranges.every(l=>l.empty)&&Ip==i.toString()){let l=-1;r=n.changeByRange(d=>{let u=n.doc.lineAt(d.from);if(u.from==l)return{range:d};l=u.from;let h=n.toText((o?i.line(s++).text:e)+n.lineBreak);return{changes:{from:u.from,insert:h},range:q.cursor(d.from+h.length)}})}else o?r=n.changeByRange(l=>{let d=i.line(s++);return{changes:{from:l.from,to:l.to,insert:d.text},range:q.cursor(l.from+d.length)}}):r=n.replaceSelection(i);t.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}In.scroll=t=>{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft};Jn.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),e.keyCode==27&&t.inputState.tabFocusMode!=0&&(t.inputState.tabFocusMode=Date.now()+2e3),!1);In.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")};In.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")};Jn.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of t.state.facet(Hk))if(n=r(t,e),n)break;if(!n&&e.button==0&&(n=uM(t,e)),n){let r=!t.hasFocus;t.inputState.startMouseSelection(new sM(t,e,n,r)),r&&t.observer.ignore(()=>{Mk(t.contentDOM);let i=t.root.activeElement;i&&!i.contains(t.contentDOM)&&i.blur()});let s=t.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}else t.inputState.setSelectionOrigin("select.pointer");return!1};function Kx(t,e,n,r){if(r==1)return q.cursor(e,n);if(r==2)return VA(t.state,e,n);{let s=t.docView.lineAt(e,n),i=t.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:i.from,a=s?s.posAtEnd:i.to;return a<t.state.doc.length&&a==i.to&&a++,q.range(o,a)}}const dM=pe.ie&&pe.ie_version<=11;let Gx=null,qx=0,Yx=0;function f2(t){if(!dM)return t.detail;let e=Gx,n=Yx;return Gx=t,Yx=Date.now(),qx=!e||n>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(qx+1)%3:1}function uM(t,e){let n=t.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=f2(e),s=t.state.selection;return{update(i){i.docChanged&&(n.pos=i.changes.mapPos(n.pos),s=s.map(i.changes))},get(i,o,a){let l=t.posAndSideAtCoords({x:i.clientX,y:i.clientY},!1),d,u=Kx(t,l.pos,l.assoc,r);if(n.pos!=l.pos&&!o){let h=Kx(t,n.pos,n.assoc,r),f=Math.min(h.from,u.from),p=Math.max(h.to,u.to);u=f<u.from?q.range(f,p):q.range(p,f)}return o?s.replaceRange(s.main.extend(u.from,u.to)):a&&r==1&&s.ranges.length>1&&(d=hM(s,l.pos))?d:a?s.addRange(u):q.create([u])}}}function hM(t,e){for(let n=0;n<t.ranges.length;n++){let{from:r,to:s}=t.ranges[n];if(r<=e&&s>=e)return q.create(t.ranges.slice(0,n).concat(t.ranges.slice(n+1)),t.mainIndex==n?0:t.mainIndex-(t.mainIndex>n?1:0))}return null}Jn.dragstart=(t,e)=>{let{selection:{main:n}}=t.state;if(e.target.draggable){let s=t.docView.tile.nearest(e.target);if(s&&s.isWidget()){let i=s.posAtStart,o=i+s.length;(i>=n.to||o<=n.from)&&(n=q.range(i,o))}}let{inputState:r}=t;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,e.dataTransfer&&(e.dataTransfer.setData("Text",zu(t.state,rg,t.state.sliceDoc(n.from,n.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Jn.dragend=t=>(t.inputState.draggedContent=null,!1);function Xx(t,e,n,r){if(n=zu(t.state,ng,n),!n)return;let s=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:i}=t.inputState,o=r&&i&&oM(t,e)?{from:i.from,to:i.to}:null,a={from:s,insert:n},l=t.state.changes(o?[o,a]:a);t.focus(),t.dispatch({changes:l,selection:{anchor:l.mapPos(s,-1),head:l.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Jn.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let n=e.dataTransfer.files;if(n&&n.length){let r=Array(n.length),s=0,i=()=>{++s==n.length&&Xx(t,e,r.filter(o=>o!=null).join(t.state.lineBreak),!1)};for(let o=0;o<n.length;o++){let a=new FileReader;a.onerror=i,a.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(a.result)||(r[o]=a.result),i()},a.readAsText(n[o])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Xx(t,e,r,!0),!0}return!1};Jn.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let n=u2?null:e.clipboardData;return n?(h2(t,n.getData("text/plain")||n.getData("text/uri-list")),!0):(cM(t),!1)};function fM(t,e){let n=t.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),t.focus()},50)}function pM(t){let e=[],n=[],r=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),n.push(s));if(!e.length){let s=-1;for(let{from:i}of t.selection.ranges){let o=t.doc.lineAt(i);o.number>s&&(e.push(o.text),n.push({from:o.from,to:Math.min(t.doc.length,o.to+1)})),s=o.number}r=!0}return{text:zu(t,rg,e.join(t.lineBreak)),ranges:n,linewise:r}}let Ip=null;Jn.copy=Jn.cut=(t,e)=>{let{text:n,ranges:r,linewise:s}=pM(t.state);if(!n&&!s)return!1;Ip=s?n:null,e.type=="cut"&&!t.state.readOnly&&t.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let i=u2?null:e.clipboardData;return i?(i.clearData(),i.setData("text/plain",n),!0):(fM(t,n),!1)};const p2=Pr.define();function m2(t,e){let n=[];for(let r of t.facet(Kk)){let s=r(t,e);s&&n.push(s)}return n.length?t.update({effects:n,annotations:p2.of(!0)}):null}function g2(t){setTimeout(()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let n=m2(t.state,e);n?t.dispatch(n):t.update([])}},10)}In.focus=t=>{t.inputState.lastFocusTime=Date.now(),!t.scrollDOM.scrollTop&&(t.inputState.lastScrollTop||t.inputState.lastScrollLeft)&&(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),g2(t)};In.blur=t=>{t.observer.clearSelectionRange(),g2(t)};In.compositionstart=In.compositionupdate=t=>{t.observer.editContext||(t.inputState.compositionFirstChange==null&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0))};In.compositionend=t=>{t.observer.editContext||(t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,pe.chrome&&pe.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then(()=>t.observer.flush()):setTimeout(()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])},50))};In.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()};Jn.beforeinput=(t,e)=>{var n,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(t.inputState.insertingText=e.data,t.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&t.observer.editContext){let i=(n=e.dataTransfer)===null||n===void 0?void 0:n.getData("text/plain"),o=e.getTargetRanges();if(i&&o.length){let a=o[0],l=t.posAtDOM(a.startContainer,a.startOffset),d=t.posAtDOM(a.endContainer,a.endOffset);return og(t,{from:l,to:d,insert:t.state.toText(i)},null),!0}}let s;if(pe.chrome&&pe.android&&(s=c2.find(i=>i.inputType==e.inputType))&&(t.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let i=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>i+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())},100)}return pe.ios&&e.inputType=="deleteContentForward"&&t.observer.flushSoon(),pe.safari&&e.inputType=="insertText"&&t.inputState.composing>=0&&setTimeout(()=>In.compositionend(t,e),20),!1};const Zx=new Set;function mM(t){Zx.has(t)||(Zx.add(t),t.addEventListener("copy",()=>{}),t.addEventListener("cut",()=>{}))}const Qx=["pre-wrap","normal","pre-line","break-spaces"];let so=!1;function Jx(){so=!1}class gM{constructor(e){this.lineWrapping=e,this.doc=We.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,n){let r=this.doc.lineAt(n).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((n-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}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 Qx.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let n=!1;for(let r=0;r<e.length;r++){let s=e[r];s<0?r++:this.heightSamples[Math.floor(s*10)]||(n=!0,this.heightSamples[Math.floor(s*10)]=!0)}return n}refresh(e,n,r,s,i,o){let a=Qx.indexOf(e)>-1,l=Math.round(n)!=Math.round(this.lineHeight)||this.lineWrapping!=a;if(this.lineWrapping=a,this.lineHeight=n,this.charWidth=r,this.textHeight=s,this.lineLength=i,l){this.heightSamples={};for(let d=0;d<o.length;d++){let u=o[d];u<0?d++:this.heightSamples[Math.floor(u*10)]=!0}}return l}}class xM{constructor(e,n){this.from=e,this.heights=n,this.index=0}get more(){return this.index<this.heights.length}}class Kn{constructor(e,n,r,s,i){this.from=e,this.length=n,this.top=r,this.height=s,this._content=i}get type(){return typeof this._content=="number"?It.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ni?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Kn(this.from,this.length+e.length,this.top,this.height+e.height,n)}}var Xe=function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t}(Xe||(Xe={}));const fd=.001;class qt{constructor(e,n,r=2){this.length=e,this.height=n,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>fd&&(so=!0),this.height=e)}replace(e,n,r){return qt.of(r)}decomposeLeft(e,n){n.push(this)}decomposeRight(e,n){n.push(this)}applyChanges(e,n,r,s){let i=this,o=r.doc;for(let a=s.length-1;a>=0;a--){let{fromA:l,toA:d,fromB:u,toB:h}=s[a],f=i.lineAt(l,Xe.ByPosNoHeight,r.setDoc(n),0,0),p=f.to>=d?f:i.lineAt(d,Xe.ByPosNoHeight,r,0,0);for(h+=p.to-d,d=p.to;a>0&&f.from<=s[a-1].toA;)l=s[a-1].fromA,u=s[a-1].fromB,a--,l<f.from&&(f=i.lineAt(l,Xe.ByPosNoHeight,r,0,0));u+=f.from-l,l=f.from;let m=ag.build(r.setDoc(o),e,u,h);i=Kd(i,i.replace(l,d,m))}return i.updateHeight(r,0)}static empty(){return new fn(0,0,0)}static of(e){if(e.length==1)return e[0];let n=0,r=e.length,s=0,i=0;for(;;)if(n==r)if(s>i*2){let a=e[n-1];a.break?e.splice(--n,1,a.left,null,a.right):e.splice(--n,1,a.left,a.right),r+=1+a.break,s-=a.size}else if(i>s*2){let a=e[r];a.break?e.splice(r,1,a.left,null,a.right):e.splice(r,1,a.left,a.right),r+=2+a.break,i-=a.size}else break;else if(s<i){let a=e[n++];a&&(s+=a.size)}else{let a=e[--r];a&&(i+=a.size)}let o=0;return e[n-1]==null?(o=1,n--):e[n]==null&&(o=1,r++),new yM(qt.of(e.slice(0,n)),o,qt.of(e.slice(r)))}}function Kd(t,e){return t==e?t:(t.constructor!=e.constructor&&(so=!0),e)}qt.prototype.size=1;const bM=Ce.replace({});class x2 extends qt{constructor(e,n,r){super(e,n),this.deco=r,this.spaceAbove=0}mainBlock(e,n){return new Kn(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,n,r,s){return this.spaceAbove&&e<r+this.spaceAbove?new Kn(s,0,r,this.spaceAbove,bM):this.mainBlock(r,s)}lineAt(e,n,r,s,i){let o=this.mainBlock(s,i);return this.spaceAbove?this.blockAt(0,r,s,i).join(o):o}forEachLine(e,n,r,s,i,o){e<=i+this.length&&n>=i&&o(this.lineAt(0,Xe.ByPos,r,s,i))}setMeasuredHeight(e){let n=e.heights[e.index++];n<0?(this.spaceAbove=-n,n=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(n)}updateHeight(e,n=0,r=!1,s){return s&&s.from<=n&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class fn extends x2{constructor(e,n,r){super(e,n,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,n){return new Kn(n,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,n,r){let s=r[0];return r.length==1&&(s instanceof fn||s instanceof Lt&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof Lt?s=new fn(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):qt.of(r)}updateHeight(e,n=0,r=!1,s){return s&&s.from<=n&&s.more?this.setMeasuredHeight(s):(r||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:""})`}}class Lt extends qt{constructor(e){super(e,0)}heightMetrics(e,n){let r=e.doc.lineAt(n).number,s=e.doc.lineAt(n+this.length).number,i=s-r+1,o,a=0;if(e.lineWrapping){let l=Math.min(this.height,e.lineHeight*i);o=l/i,this.length>i+1&&(a=(this.height-l)/(this.length-i-1))}else o=this.height/i;return{firstLine:r,lastLine:s,perLine:o,perChar:a}}blockAt(e,n,r,s){let{firstLine:i,lastLine:o,perLine:a,perChar:l}=this.heightMetrics(n,s);if(n.lineWrapping){let d=s+(e<n.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),u=n.doc.lineAt(d),h=a+u.length*l,f=Math.max(r,e-h/2);return new Kn(u.from,u.length,f,h,0)}else{let d=Math.max(0,Math.min(o-i,Math.floor((e-r)/a))),{from:u,length:h}=n.doc.line(i+d);return new Kn(u,h,r+a*d,a,0)}}lineAt(e,n,r,s,i){if(n==Xe.ByHeight)return this.blockAt(e,r,s,i);if(n==Xe.ByPosNoHeight){let{from:p,to:m}=r.doc.lineAt(e);return new Kn(p,m-p,0,0,0)}let{firstLine:o,perLine:a,perChar:l}=this.heightMetrics(r,i),d=r.doc.lineAt(e),u=a+d.length*l,h=d.number-o,f=s+a*h+l*(d.from-i-h);return new Kn(d.from,d.length,Math.max(s,Math.min(f,s+this.height-u)),u,0)}forEachLine(e,n,r,s,i,o){e=Math.max(e,i),n=Math.min(n,i+this.length);let{firstLine:a,perLine:l,perChar:d}=this.heightMetrics(r,i);for(let u=e,h=s;u<=n;){let f=r.doc.lineAt(u);if(u==e){let m=f.number-a;h+=l*m+d*(e-i-m)}let p=l+d*f.length;o(new Kn(f.from,f.length,h,p,0)),h+=p,u=f.to+1}}replace(e,n,r){let s=this.length-n;if(s>0){let i=r[r.length-1];i instanceof Lt?r[r.length-1]=new Lt(i.length+s):r.push(null,new Lt(s-1))}if(e>0){let i=r[0];i instanceof Lt?r[0]=new Lt(e+i.length):r.unshift(new Lt(e-1),null)}return qt.of(r)}decomposeLeft(e,n){n.push(new Lt(e-1),null)}decomposeRight(e,n){n.push(null,new Lt(this.length-e-1))}updateHeight(e,n=0,r=!1,s){let i=n+this.length;if(s&&s.from<=n+this.length&&s.more){let o=[],a=Math.max(n,s.from),l=-1;for(s.from>n&&o.push(new Lt(s.from-n-1).updateHeight(e,n));a<=i&&s.more;){let u=e.doc.lineAt(a).length;o.length&&o.push(null);let h=s.heights[s.index++],f=0;h<0&&(f=-h,h=s.heights[s.index++]),l==-1?l=h:Math.abs(h-l)>=fd&&(l=-2);let p=new fn(u,h,f);p.outdated=!1,o.push(p),a+=u+1}a<=i&&o.push(null,new Lt(i-a).updateHeight(e,a));let d=qt.of(o);return(l<0||Math.abs(d.height-this.height)>=fd||Math.abs(l-this.heightMetrics(e,n).perLine)>=fd)&&(so=!0),Kd(this,d)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(n,n+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class yM extends qt{constructor(e,n,r){super(e.length+n+r.length,e.height+r.height,n|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,n,r,s){let i=r+this.left.height;return e<i?this.left.blockAt(e,n,r,s):this.right.blockAt(e,n,i,s+this.left.length+this.break)}lineAt(e,n,r,s,i){let o=s+this.left.height,a=i+this.left.length+this.break,l=n==Xe.ByHeight?e<o:e<a,d=l?this.left.lineAt(e,n,r,s,i):this.right.lineAt(e,n,r,o,a);if(this.break||(l?d.to<a:d.from>a))return d;let u=n==Xe.ByPosNoHeight?Xe.ByPosNoHeight:Xe.ByPos;return l?d.join(this.right.lineAt(a,u,r,o,a)):this.left.lineAt(a,u,r,s,i).join(d)}forEachLine(e,n,r,s,i,o){let a=s+this.left.height,l=i+this.left.length+this.break;if(this.break)e<l&&this.left.forEachLine(e,n,r,s,i,o),n>=l&&this.right.forEachLine(e,n,r,a,l,o);else{let d=this.lineAt(l,Xe.ByPos,r,s,i);e<d.from&&this.left.forEachLine(e,d.from-1,r,s,i,o),d.to>=e&&d.from<=n&&o(d),n>d.to&&this.right.forEachLine(d.to+1,n,r,a,l,o)}}replace(e,n,r){let s=this.left.length+this.break;if(n<s)return this.balanced(this.left.replace(e,n,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,n-s,r));let i=[];e>0&&this.decomposeLeft(e,i);let o=i.length;for(let a of r)i.push(a);if(e>0&&eb(i,o-1),n<this.length){let a=i.length;this.decomposeRight(n,i),eb(i,a)}return qt.of(i)}decomposeLeft(e,n){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,n);n.push(this.left),this.break&&(r++,e>=r&&n.push(null)),e>r&&this.right.decomposeLeft(e-r,n)}decomposeRight(e,n){let r=this.left.length,s=r+this.break;if(e>=s)return this.right.decomposeRight(e-s,n);e<r&&this.left.decomposeRight(e,n),this.break&&e<s&&n.push(null),n.push(this.right)}balanced(e,n){return e.size>2*n.size||n.size>2*e.size?qt.of(this.break?[e,null,n]:[e,n]):(this.left=Kd(this.left,e),this.right=Kd(this.right,n),this.setHeight(e.height+n.height),this.outdated=e.outdated||n.outdated,this.size=e.size+n.size,this.length=e.length+this.break+n.length,this)}updateHeight(e,n=0,r=!1,s){let{left:i,right:o}=this,a=n+i.length+this.break,l=null;return s&&s.from<=n+i.length&&s.more?l=i=i.updateHeight(e,n,r,s):i.updateHeight(e,n,r),s&&s.from<=a+o.length&&s.more?l=o=o.updateHeight(e,a,r,s):o.updateHeight(e,a,r),l?this.balanced(i,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function eb(t,e){let n,r;t[e]==null&&(n=t[e-1])instanceof Lt&&(r=t[e+1])instanceof Lt&&t.splice(e-1,3,new Lt(n.length+1+r.length))}const vM=5;class ag{constructor(e,n){this.pos=e,this.oracle=n,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,n){if(this.lineStart>-1){let r=Math.min(n,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof fn?s.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new fn(r-this.pos,-1,0)),this.writtenTo=r,n>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=n}point(e,n,r){if(e<n||r.heightRelevant){let s=r.widget?r.widget.estimatedHeight:0,i=r.widget?r.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=n-e;r.block?this.addBlock(new x2(o,s,r)):(o||i||s>=vM)&&this.addLineDeco(s,i,o)}else n>e&&this.span(e,n);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:n}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=n,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new fn(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,n){let r=new Lt(n-e);return this.oracle.doc.lineAt(e).to==n&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof fn)return e;let n=new fn(0,-1,0);return this.nodes.push(n),n}addBlock(e){this.enterLine();let n=e.deco;n&&n.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,n&&n.endSide>0&&(this.covering=e)}addLineDeco(e,n,r){let s=this.ensureLine();s.length+=r,s.collapsed+=r,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=n,this.writtenTo=this.pos=this.pos+r}finish(e){let n=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(n instanceof fn)&&!this.isCovered?this.nodes.push(new fn(0,-1,0)):(this.writtenTo<this.pos||n==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let s of this.nodes)s instanceof fn&&s.updateHeight(this.oracle,r),r+=s?s.length:1;return this.nodes}static build(e,n,r,s){let i=new ag(r,e);return Le.spans(n,r,s,i,0),i.finish(r)}}function wM(t,e,n){let r=new kM;return Le.compare(t,e,n,r,0),r.changes}class kM{constructor(){this.changes=[]}compareRange(){}comparePoint(e,n,r,s){(e<n||r&&r.heightRelevant||s&&s.heightRelevant)&&Fi(e,n,this.changes,5)}}function SM(t,e){let n=t.getBoundingClientRect(),r=t.ownerDocument,s=r.defaultView||window,i=Math.max(0,n.left),o=Math.min(s.innerWidth,n.right),a=Math.max(0,n.top),l=Math.min(s.innerHeight,n.bottom);for(let d=t.parentNode;d&&d!=r.body;)if(d.nodeType==1){let u=d,h=window.getComputedStyle(u);if((u.scrollHeight>u.clientHeight||u.scrollWidth>u.clientWidth)&&h.overflow!="visible"){let f=u.getBoundingClientRect();i=Math.max(i,f.left),o=Math.min(o,f.right),a=Math.max(a,f.top),l=Math.min(d==t.parentNode?s.innerHeight:l,f.bottom)}d=h.position=="absolute"||h.position=="fixed"?u.offsetParent:u.parentNode}else if(d.nodeType==11)d=d.host;else break;return{left:i-n.left,right:Math.max(i,o)-n.left,top:a-(n.top+e),bottom:Math.max(a,l)-(n.top+e)}}function CM(t){let e=t.getBoundingClientRect(),n=t.ownerDocument.defaultView||window;return e.left<n.innerWidth&&e.right>0&&e.top<n.innerHeight&&e.bottom>0}function jM(t,e){let n=t.getBoundingClientRect();return{left:0,right:n.right-n.left,top:e,bottom:n.bottom-(n.top+e)}}class Fh{constructor(e,n,r,s){this.from=e,this.to=n,this.size=r,this.displaySize=s}static same(e,n){if(e.length!=n.length)return!1;for(let r=0;r<e.length;r++){let s=e[r],i=n[r];if(s.from!=i.from||s.to!=i.to||s.size!=i.size)return!1}return!0}draw(e,n){return Ce.replace({widget:new NM(this.displaySize*(n?e.scaleY:e.scaleX),n)}).range(this.from,this.to)}}class NM extends Er{constructor(e,n){super(),this.size=e,this.vertical=n}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class tb{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=nb,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Ye.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let n=e.facet(sg).some(r=>typeof r!="function"&&r.class=="cm-lineWrapping");this.heightOracle=new gM(n),this.stateDeco=e.facet(Ta).filter(r=>typeof r!="function"),this.heightMap=qt.empty().applyChanges(this.stateDeco,We.empty,this.heightOracle.setDoc(e.doc),[new An(0,0,0,e.doc.length)]);for(let r=0;r<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());r++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=Ce.set(this.lineGaps.map(r=>r.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:n}=this.state.selection;for(let r=0;r<=1;r++){let s=r?n.head:n.anchor;if(!e.some(({from:i,to:o})=>s>=i&&s<=o)){let{from:i,to:o}=this.lineBlockAt(s);e.push(new Ec(i,o))}}return this.viewports=e.sort((r,s)=>r.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?nb:new lg(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(ea(e,this.scaler))})}update(e,n=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=this.state.facet(Ta).filter(u=>typeof u!="function");let s=e.changedRanges,i=An.extendWithRanges(s,wM(r,this.stateDeco,e?e.changes:yt.empty(this.state.doc.length))),o=this.heightMap.height,a=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);Jx(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),i),(this.heightMap.height!=o||so)&&(e.flags|=2),a?(this.scrollAnchorPos=e.changes.mapPos(a.from,-1),this.scrollAnchorHeight=a.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let l=i.length?this.mapViewport(this.viewport,e.changes):this.viewport;(n&&(n.range.head<l.from||n.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,n));let d=l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,e.flags|=this.updateForViewport(),(d||!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),n&&(this.scrollTarget=n),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(qk)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let n=e.contentDOM,r=window.getComputedStyle(n),s=this.heightOracle,i=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?Ye.RTL:Ye.LTR;let o=this.heightOracle.mustRefreshForWrapping(i),a=n.getBoundingClientRect(),l=o||this.mustMeasureContent||this.contentDOMHeight!=a.height;this.contentDOMHeight=a.height,this.mustMeasureContent=!1;let d=0,u=0;if(a.width&&a.height){let{scaleX:k,scaleY:C}=Ak(n,a);(k>.005&&Math.abs(this.scaleX-k)>.005||C>.005&&Math.abs(this.scaleY-C)>.005)&&(this.scaleX=k,this.scaleY=C,d|=16,o=l=!0)}let h=(parseInt(r.paddingTop)||0)*this.scaleY,f=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=h||this.paddingBottom!=f)&&(this.paddingTop=h,this.paddingBottom=f,d|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,d|=16);let p=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=p&&(this.scrollAnchorHeight=-1,this.scrollTop=p),this.scrolledToBottom=Tk(e.scrollDOM);let m=(this.printing?jM:SM)(n,this.paddingTop),x=m.top-this.pixelViewport.top,b=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(l=!0)),!this.inView&&!this.scrollTarget&&!CM(e.dom))return 0;let w=a.width;if((this.contentDOMWidth!=w||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=a.width,this.editorHeight=e.scrollDOM.clientHeight,d|=16),l){let k=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(k)&&(o=!0),o||s.lineWrapping&&Math.abs(w-this.contentDOMWidth)>s.charWidth){let{lineHeight:C,charWidth:j,textHeight:S}=e.docView.measureTextSize();o=C>0&&s.refresh(i,C,j,S,Math.max(5,w/j),k),o&&(e.docView.minWidth=0,d|=16)}x>0&&b>0?u=Math.max(x,b):x<0&&b<0&&(u=Math.min(x,b)),Jx();for(let C of this.viewports){let j=C.from==this.viewport.from?k:e.docView.measureVisibleLineHeights(C);this.heightMap=(o?qt.empty().applyChanges(this.stateDeco,We.empty,this.heightOracle,[new An(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new xM(C.from,j))}so&&(d|=2)}let v=!this.viewportIsAppropriate(this.viewport,u)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return v&&(d&2&&(d|=this.updateScaler()),this.viewport=this.getViewport(u,this.scrollTarget),d|=this.updateForViewport()),(d&2||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),d|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),d}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,n){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,i=this.heightOracle,{visibleTop:o,visibleBottom:a}=this,l=new Ec(s.lineAt(o-r*1e3,Xe.ByHeight,i,0,0).from,s.lineAt(a+(1-r)*1e3,Xe.ByHeight,i,0,0).to);if(n){let{head:d}=n.range;if(d<l.from||d>l.to){let u=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),h=s.lineAt(d,Xe.ByPos,i,0,0),f;n.y=="center"?f=(h.top+h.bottom)/2-u/2:n.y=="start"||n.y=="nearest"&&d<l.from?f=h.top:f=h.bottom-u,l=new Ec(s.lineAt(f-1e3/2,Xe.ByHeight,i,0,0).from,s.lineAt(f+u+1e3/2,Xe.ByHeight,i,0,0).to)}}return l}mapViewport(e,n){let r=n.mapPos(e.from,-1),s=n.mapPos(e.to,1);return new Ec(this.heightMap.lineAt(r,Xe.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,Xe.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:n},r=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,Xe.ByPos,this.heightOracle,0,0),{bottom:i}=this.heightMap.lineAt(n,Xe.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:a}=this;return(e==0||s<=o-Math.max(10,Math.min(-r,250)))&&(n==this.state.doc.length||i>=a+Math.max(10,Math.min(r,250)))&&s>o-2*1e3&&i<a+2*1e3}mapLineGaps(e,n){if(!e.length||n.empty)return e;let r=[];for(let s of e)n.touchesRange(s.from,s.to)||r.push(new Fh(n.mapPos(s.from),n.mapPos(s.to),s.size,s.displaySize));return r}ensureLineGaps(e,n){let r=this.heightOracle.lineWrapping,s=r?1e4:2e3,i=s>>1,o=s<<1;if(this.defaultTextDirection!=Ye.LTR&&!r)return[];let a=[],l=(u,h,f,p)=>{if(h-u<i)return;let m=this.state.selection.main,x=[m.from];m.empty||x.push(m.to);for(let y of x)if(y>u&&y<h){l(u,y-10,f,p),l(y+10,h,f,p);return}let b=OM(e,y=>y.from>=f.from&&y.to<=f.to&&Math.abs(y.from-u)<i&&Math.abs(y.to-h)<i&&!x.some(w=>y.from<w&&y.to>w));if(!b){if(h<f.to&&n&&r&&n.visibleRanges.some(v=>v.from<=h&&v.to>=h)){let v=n.moveToLineBoundary(q.cursor(h),!1,!0).head;v>u&&(h=v)}let y=this.gapSize(f,u,h,p),w=r||y<2e6?y:2e6;b=new Fh(u,h,y,w)}a.push(b)},d=u=>{if(u.length<o||u.type!=It.Text)return;let h=PM(u.from,u.to,this.stateDeco);if(h.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,p,m;if(r){let x=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,b,y;if(f!=null){let w=Ac(h,f),v=((this.visibleBottom-this.visibleTop)/2+x)/u.height;b=w-v,y=w+v}else b=(this.visibleTop-u.top-x)/u.height,y=(this.visibleBottom-u.top+x)/u.height;p=Dc(h,b),m=Dc(h,y)}else{let x=h.total*this.heightOracle.charWidth,b=s*this.heightOracle.charWidth,y=0;if(x>2e6)for(let j of e)j.from>=u.from&&j.from<u.to&&j.size!=j.displaySize&&j.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=j.size-j.displaySize);let w=this.pixelViewport.left+y,v=this.pixelViewport.right+y,k,C;if(f!=null){let j=Ac(h,f),S=((v-w)/2+b)/x;k=j-S,C=j+S}else k=(w-b)/x,C=(v+b)/x;p=Dc(h,k),m=Dc(h,C)}p>u.from&&l(u.from,p,u,h),m<u.to&&l(m,u.to,u,h)};for(let u of this.viewportLines)Array.isArray(u.type)?u.type.forEach(d):d(u);return a}gapSize(e,n,r,s){let i=Ac(s,r)-Ac(s,n);return this.heightOracle.lineWrapping?e.height*i:s.total*this.heightOracle.charWidth*i}updateLineGaps(e){Fh.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=Ce.set(e.map(n=>n.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let n=this.stateDeco;this.lineGaps.length&&(n=n.concat(this.lineGapDeco));let r=[];Le.spans(n,this.viewport.from,this.viewport.to,{span(i,o){r.push({from:i,to:o})},point(){}},20);let s=0;if(r.length!=this.visibleRanges.length)s=12;else for(let i=0;i<r.length&&!(s&8);i++){let o=this.visibleRanges[i],a=r[i];(o.from!=a.from||o.to!=a.to)&&(s|=4,e&&e.mapPos(o.from,-1)==a.from&&e.mapPos(o.to,1)==a.to||(s|=8))}return this.visibleRanges=r,s}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(n=>n.from<=e&&n.to>=e)||ea(this.heightMap.lineAt(e,Xe.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(n=>n.top<=e&&n.bottom>=e)||ea(this.heightMap.lineAt(this.scaler.fromDOM(e),Xe.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let n=this.lineBlockAtHeight(e+8);return n.from>=this.viewport.from||this.viewportLines[0].top-e>200?n:this.viewportLines[0]}elementAtHeight(e){return ea(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}}let Ec=class{constructor(e,n){this.from=e,this.to=n}};function PM(t,e,n){let r=[],s=t,i=0;return Le.spans(n,t,e,{span(){},point(o,a){o>s&&(r.push({from:s,to:o}),i+=o-s),s=a}},20),s<e&&(r.push({from:s,to:e}),i+=e-s),{total:i,ranges:r}}function Dc({total:t,ranges:e},n){if(n<=0)return e[0].from;if(n>=1)return e[e.length-1].to;let r=Math.floor(t*n);for(let s=0;;s++){let{from:i,to:o}=e[s],a=o-i;if(r<=a)return i+r;r-=a}}function Ac(t,e){let n=0;for(let{from:r,to:s}of t.ranges){if(e<=s){n+=e-r;break}n+=s-r}return n/t.total}function OM(t,e){for(let n of t)if(e(n))return n}const nb={toDOM(t){return t},fromDOM(t){return t},scale:1,eq(t){return t==this}};class lg{constructor(e,n,r){let s=0,i=0,o=0;this.viewports=r.map(({from:a,to:l})=>{let d=n.lineAt(a,Xe.ByPos,e,0,0).top,u=n.lineAt(l,Xe.ByPos,e,0,0).bottom;return s+=u-d,{from:a,to:l,top:d,bottom:u,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(n.height-s);for(let a of this.viewports)a.domTop=o+(a.top-i)*this.scale,o=a.domBottom=a.domTop+(a.bottom-a.top),i=a.bottom}toDOM(e){for(let n=0,r=0,s=0;;n++){let i=n<this.viewports.length?this.viewports[n]:null;if(!i||e<i.top)return s+(e-r)*this.scale;if(e<=i.bottom)return i.domTop+(e-i.top);r=i.bottom,s=i.domBottom}}fromDOM(e){for(let n=0,r=0,s=0;;n++){let i=n<this.viewports.length?this.viewports[n]:null;if(!i||e<i.domTop)return r+(e-s)/this.scale;if(e<=i.domBottom)return i.top+(e-i.domTop);r=i.bottom,s=i.domBottom}}eq(e){return e instanceof lg?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((n,r)=>n.from==e.viewports[r].from&&n.to==e.viewports[r].to):!1}}function ea(t,e){if(e.scale==1)return t;let n=e.toDOM(t.top),r=e.toDOM(t.bottom);return new Kn(t.from,t.length,n,r-n,Array.isArray(t._content)?t._content.map(s=>ea(s,e)):t._content)}const Mc=me.define({combine:t=>t.join(" ")}),$p=me.define({combine:t=>t.indexOf(!0)>-1}),Bp=Ss.newName(),b2=Ss.newName(),y2=Ss.newName(),v2={"&light":"."+b2,"&dark":"."+y2};function Fp(t,e,n){return new Ss(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,s=>{if(s=="&")return t;if(!n||!n[s])throw new RangeError(`Unsupported selector: ${s}`);return n[s]}):t+" "+r}})}const EM=Fp("."+Bp,{"&":{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-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,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,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"}},v2),DM={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},zh=pe.ie&&pe.ie_version<=11;class AM{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new lA,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(n=>{for(let r of n)this.queue.push(r);(pe.ie&&pe.ie_version<=11||pe.ios&&e.composing)&&n.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&pe.android&&e.constructor.EDIT_CONTEXT!==!1&&!(pe.chrome&&pe.chrome_version<126)&&(this.editContext=new TM(e),e.state.facet(Fr)&&(e.contentDOM.editContext=this.editContext.editContext)),zh&&(this.onCharData=n=>{this.queue.push({target:n.target,type:"characterData",oldValue:n.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 n;((n=this.view.docView)===null||n===void 0?void 0:n.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(n=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),n.length>0&&n[n.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(n=>{n.length>0&&n[n.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((n,r)=>n!=e[r]))){this.gapIntersection.disconnect();for(let n of e)this.gapIntersection.observe(n);this.gaps=e}}onSelectionChange(e){let n=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:r}=this,s=this.selectionRange;if(r.state.facet(Fr)?r.root.activeElement!=this.dom:!hd(this.dom,s))return;let i=s.anchorNode&&r.docView.tile.nearest(s.anchorNode);if(i&&i.isWidget()&&i.widget.ignoreEvent(e)){n||(this.selectionChanged=!1);return}(pe.ie&&pe.ie_version<=11||pe.android&&pe.chrome)&&!r.state.selection.main.empty&&s.focusNode&&ca(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,n=Da(e.root);if(!n)return!1;let r=pe.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&MM(this.view,n)||n;if(!r||this.selectionRange.eq(r))return!1;let s=hd(this.dom,r);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&dA(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,n){this.selectionRange.set(e.node,e.offset,n.node,n.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,n=null;for(let r=this.dom;r;)if(r.nodeType==1)!n&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:n||(n=this.scrollTargets.slice(0,e)),n&&n.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!n&&(n=this.scrollTargets.slice(0,e)),n){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=n)r.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,DM),zh&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),zh&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,n){var r;if(!this.delayedAndroidKey){let s=()=>{let i=this.delayedAndroidKey;i&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=i.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&i.force&&zi(this.dom,i.key,i.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:n,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{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 n=-1,r=-1,s=!1;for(let i of e){let o=this.readMutation(i);o&&(o.typeOver&&(s=!0),n==-1?{from:n,to:r}=o:(n=Math.min(o.from,n),r=Math.max(o.to,r)))}return{from:n,to:r,typeOver:s}}readChange(){let{from:e,to:n,typeOver:r}=this.processRecords(),s=this.selectionChanged&&hd(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 i=new XA(this.view,e,n,r);return this.view.docView.domChanged={newSel:i.newSel?i.newSel.main:null},i}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,s=a2(this.view,n);return this.view.state==r&&(n.domChanged||n.newSel&&!n.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(e){let n=this.view.docView.tile.nearest(e.target);if(!n||n.isWidget())return null;if(n.markDirty(e.type=="attributes"),e.type=="childList"){let r=rb(n,e.previousSibling||e.target.previousSibling,-1),s=rb(n,e.nextSibling||e.target.nextSibling,1);return{from:r?n.posAfter(r):n.posAtStart,to:s?n.posBefore(s):n.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:n.posAtStart,to:n.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(Fr)!=e.state.facet(Fr)&&(e.view.contentDOM.editContext=e.state.facet(Fr)?this.editContext.editContext:null))}destroy(){var e,n,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(n=this.gapIntersection)===null||n===void 0||n.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.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 rb(t,e,n){for(;e;){let r=mt.get(e);if(r&&r.parent==t)return r;let s=e.parentNode;e=s!=t.dom?s:n>0?e.nextSibling:e.previousSibling}return null}function sb(t,e){let n=e.startContainer,r=e.startOffset,s=e.endContainer,i=e.endOffset,o=t.docView.domAtPos(t.state.selection.main.anchor,1);return ca(o.node,o.offset,s,i)&&([n,r,s,i]=[s,i,n,r]),{anchorNode:n,anchorOffset:r,focusNode:s,focusOffset:i}}function MM(t,e){if(e.getComposedRanges){let s=e.getComposedRanges(t.root)[0];if(s)return sb(t,s)}let n=null;function r(s){s.preventDefault(),s.stopImmediatePropagation(),n=s.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",r,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",r,!0),n?sb(t,n):null}class TM{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let n=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=r=>{let s=e.state.selection.main,{anchor:i,head:o}=s,a=this.toEditorPos(r.updateRangeStart),l=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:a,drifted:!1});let d=l-a>r.text.length;a==this.from&&i<this.from?a=i:l==this.to&&i>this.to&&(l=i);let u=l2(e.state.sliceDoc(a,l),r.text,(d?s.from:s.to)-a,d?"end":null);if(!u){let f=q.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));f.main.eq(s)||e.dispatch({selection:f,userEvent:"select"});return}let h={from:u.from+a,to:u.toA+a,insert:We.of(r.text.slice(u.from,u.toB).split(`
268
268
  `))};if((pe.mac||pe.android)&&h.from==o-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(h={from:a,to:l,insert:We.of([r.text.replace("."," ")])}),this.pendingContextChange=h,!e.state.readOnly){let f=this.to-this.from+(h.to-h.from+h.insert.length);og(e,h,q.single(this.toEditorPos(r.selectionStart,f),this.toEditorPos(r.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),h.from<h.to&&!h.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(n.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(n.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let s=[],i=null;for(let o=this.toEditorPos(r.rangeStart),a=this.toEditorPos(r.rangeEnd);o<a;o++){let l=e.coordsForChar(o);i=l&&new DOMRect(l.left,l.top,l.right-l.left,l.bottom-l.top)||i||new DOMRect,s.push(i)}n.updateCharacterBounds(r.rangeStart,s)},this.handlers.textformatupdate=r=>{let s=[];for(let i of r.getTextFormats()){let o=i.underlineStyle,a=i.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(a)){let l=this.toEditorPos(i.rangeStart),d=this.toEditorPos(i.rangeEnd);if(l<d){let u=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(a)?1:2}px`;s.push(Ce.mark({attributes:{style:u}}).range(l,d))}}}e.dispatch({effects:Xk.of(Ce.set(s))})},this.handlers.compositionstart=()=>{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:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)n.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let s=Da(r.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let n=0,r=!1,s=this.pendingContextChange;return e.changes.iterChanges((i,o,a,l,d)=>{if(r)return;let u=d.length-(o-i);if(s&&o>=s.to)if(s.from==i&&s.to==o&&s.insert.eq(d)){s=this.pendingContextChange=null,n+=u,this.to+=u;return}else s=null,this.revertPending(e.state);if(i+=n,o+=n,o<=this.from)this.from+=u,this.to+=u;else if(i<this.to){if(i<this.from||o>this.to||this.to-this.from+d.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(i),this.toContextPos(o),d.toString()),this.to+=u}n+=u}),s&&!r&&this.revertPending(e.state),!r}update(e){let n=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.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||n)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:n}=e.selection.main;this.from=Math.max(0,n-1e4),this.to=Math.min(e.doc.length,n+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 n=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(n.from),this.toContextPos(n.from+n.insert.length),e.doc.sliceString(n.from,n.to))}setSelection(e){let{main:n}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,n.anchor))),s=this.toContextPos(n.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(r,s)}rangeIsValid(e){let{head:n}=e.selection.main;return!(this.from>0&&n-this.from<500||this.to<e.doc.length&&this.to-n<500||this.to-this.from>1e4*3)}toEditorPos(e,n=this.to-this.from){e=Math.min(e,n);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let n=this.composing;return n&&n.drifted?n.contextBase+(e-n.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class ae{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 n;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:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(s=>s.forEach(i=>r(i,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||cA(e.parent)||document,this.viewState=new tb(e.state||Ie.create(e)),e.scrollTo&&e.scrollTo.is(Nc)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ei).map(s=>new Rh(s));for(let s of this.plugins)s.update(this);this.observer=new AM(this),this.inputState=new eM(this),this.inputState.ensureHandlers(this.plugins),this.docView=new zx(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((n=document.fonts)===null||n===void 0)&&n.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...e){let n=e.length==1&&e[0]instanceof kt?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(n,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let n=!1,r=!1,s,i=this.state;for(let f of e){if(f.startState!=i)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");i=f.state}if(this.destroyed){this.viewState.state=i;return}let o=this.hasFocus,a=0,l=null;e.some(f=>f.annotation(p2))?(this.inputState.notifiedFocused=o,a=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,l=m2(i,o),l||(a=1));let d=this.observer.delayedAndroidKey,u=null;if(d?(this.observer.clearDelayedAndroidKey(),u=this.observer.readChange(),(u&&!this.state.doc.eq(i.doc)||!this.state.selection.eq(i.selection))&&(u=null)):this.observer.clear(),i.facet(Ie.phrases)!=this.state.facet(Ie.phrases))return this.setState(i);s=Hd.create(this,i,e),s.flags|=a;let h=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(h&&(h=h.map(f.changes)),f.scrollIntoView){let{main:p}=f.state.selection;h=new Vi(p.empty?p:q.cursor(p.head,p.head>p.anchor?-1:1))}for(let p of f.effects)p.is(Nc)&&(h=p.value.clip(this.state))}this.viewState.update(s,h),this.bidiCache=Gd.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),n=this.docView.update(s),this.state.facet(Qo)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(n,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Mc)!=s.state.facet(Mc)&&(this.viewState.mustMeasureContent=!0),(n||r||h||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!s.empty)for(let f of this.state.facet(Tp))try{f(s)}catch(p){sn(this.state,p,"update listener")}(l||u)&&Promise.resolve().then(()=>{l&&this.state==l.startState&&this.dispatch(l),u&&!a2(this,u)&&d.force&&zi(this.contentDOM,d.key,d.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 n=this.hasFocus;try{for(let r of this.plugins)r.destroy(this);this.viewState=new tb(e),this.plugins=e.facet(Ei).map(r=>new Rh(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new zx(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}n&&this.focus(),this.requestMeasure()}updatePlugins(e){let n=e.startState.facet(Ei),r=e.state.facet(Ei);if(n!=r){let s=[];for(let i of r){let o=n.indexOf(i);if(o<0)s.push(new Rh(i));else{let a=this.plugins[o];a.mustUpdate=e,s.push(a)}}for(let i of this.plugins)i.mustUpdate!=e&&i.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);n!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let n=e.value;if(n&&n.docViewUpdate)try{n.docViewUpdate(this)}catch(r){sn(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let n=null,r=this.scrollDOM,s=r.scrollTop*this.scaleY,{scrollAnchorPos:i,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let a=0;;a++){if(o<0)if(Tk(r))i=-1,o=this.viewState.heightMap.height;else{let p=this.viewState.scrollAnchorAt(s);i=p.from,o=p.top}this.updateState=1;let l=this.viewState.measure(this);if(!l&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(a>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let d=[];l&4||([this.measureRequests,d]=[d,this.measureRequests]);let u=d.map(p=>{try{return p.read(this)}catch(m){return sn(this.state,m),ib}}),h=Hd.create(this,this.state,[]),f=!1;h.flags|=l,n?n.flags|=l:n=h,this.updateState=2,h.empty||(this.updatePlugins(h),this.inputState.update(h),this.updateAttrs(),f=this.docView.update(h),f&&this.docViewUpdate());for(let p=0;p<d.length;p++)if(u[p]!=ib)try{let m=d[p];m.write&&m.write(u[p],this)}catch(m){sn(this.state,m)}if(f&&this.docView.updateSelection(!0),!h.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let m=(i<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(i).top)-o;if(m>1||m<-1){s=s+m,r.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(n&&!n.empty)for(let a of this.state.facet(Tp))a(n)}get themeClasses(){return Bp+" "+(this.state.facet($p)?y2:b2)+" "+this.state.facet(Mc)}updateAttrs(){let e=ob(this,Zk,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),n={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Fr)?"true":"false",class:"cm-content",style:`${pe.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(n["aria-readonly"]="true"),ob(this,sg,n);let r=this.observer.ignore(()=>{let s=Rx(this.contentDOM,this.contentAttrs,n),i=Rx(this.dom,this.editorAttrs,e);return s||i});return this.editorAttrs=e,this.contentAttrs=n,r}showAnnouncements(e){let n=!0;for(let r of e)for(let s of r.effects)if(s.is(ae.announce)){n&&(this.announceDOM.textContent=""),n=!1;let i=this.announceDOM.appendChild(document.createElement("div"));i.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Qo);let e=this.state.facet(ae.cspNonce);Ss.mount(this.root,this.styleModules.concat(EM).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 n=0;n<this.measureRequests.length;n++)if(this.measureRequests[n].key===e.key){this.measureRequests[n]=e;return}}this.measureRequests.push(e)}}plugin(e){let n=this.pluginMap.get(e);return(n===void 0||n&&n.plugin!=e)&&this.pluginMap.set(e,n=this.plugins.find(r=>r.plugin==e)||null),n&&n.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,n,r){return Bh(this,e,Vx(this,e,n,r))}moveByGroup(e,n){return Bh(this,e,Vx(this,e,n,r=>UA(this,e.head,r)))}visualLineSide(e,n){let r=this.bidiSpans(e),s=this.textDirectionAt(e.from),i=r[n?r.length-1:0];return q.cursor(i.side(n,s)+e.from,i.forward(!n,s)?1:-1)}moveToLineBoundary(e,n,r=!0){return WA(this,e,n,r)}moveVertically(e,n,r){return Bh(this,e,KA(this,e,n,r))}domAtPos(e,n=1){return this.docView.domAtPos(e,n)}posAtDOM(e,n=0){return this.docView.posFromDOM(e,n)}posAtCoords(e,n=!0){this.readMeasured();let r=_p(this,e,n);return r&&r.pos}posAndSideAtCoords(e,n=!0){return this.readMeasured(),_p(this,e,n)}coordsAtPos(e,n=1){this.readMeasured();let r=this.docView.coordsAt(e,n);if(!r||r.left==r.right)return r;let s=this.state.doc.lineAt(e),i=this.bidiSpans(s),o=i[Vr.find(i,e-s.from,-1,n)];return Aa(r,o.dir==Ye.LTR==n>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(Gk)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>LM)return Bk(e.length);let n=this.textDirectionAt(e.from),r;for(let i of this.bidiCache)if(i.from==e.from&&i.dir==n&&(i.fresh||$k(i.isolates,r=$x(this,e))))return i.order;r||(r=$x(this,e));let s=xA(e.text,n,r);return this.bidiCache.push(new Gd(e.from,e.to,n,r,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||pe.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Mk(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,n={}){return Nc.of(new Vi(typeof e=="number"?q.cursor(e):e,n.y,n.x,n.yMargin,n.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:n}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return Nc.of(new Vi(q.cursor(r.from),"start","start",r.top-e,n,!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 ut.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return ut.define(()=>({}),{eventObservers:e})}static theme(e,n){let r=Ss.newName(),s=[Mc.of(r),Qo.of(Fp(`.${r}`,e))];return n&&n.dark&&s.push($p.of(!0)),s}static baseTheme(e){return hi.lowest(Qo.of(Fp("."+Bp,e,v2)))}static findFromDOM(e){var n;let r=e.querySelector(".cm-content"),s=r&&mt.get(r)||mt.get(e);return((n=s?.root)===null||n===void 0?void 0:n.view)||null}}ae.styleModule=Qo;ae.inputHandler=Uk;ae.clipboardInputFilter=ng;ae.clipboardOutputFilter=rg;ae.scrollHandler=Yk;ae.focusChangeEffect=Kk;ae.perLineTextDirection=Gk;ae.exceptionSink=Wk;ae.updateListener=Tp;ae.editable=Fr;ae.mouseSelectionStyle=Hk;ae.dragMovesSelection=Vk;ae.clickAddsSelectionRange=zk;ae.decorations=Ta;ae.blockWrappers=Qk;ae.outerDecorations=Jk;ae.atomicRanges=Kl;ae.bidiIsolatedRanges=e2;ae.scrollMargins=t2;ae.darkTheme=$p;ae.cspNonce=me.define({combine:t=>t.length?t[0]:""});ae.contentAttributes=sg;ae.editorAttributes=Zk;ae.lineWrapping=ae.contentAttributes.of({class:"cm-lineWrapping"});ae.announce=Ee.define();const LM=4096,ib={};class Gd{constructor(e,n,r,s,i,o){this.from=e,this.to=n,this.dir=r,this.isolates=s,this.fresh=i,this.order=o}static update(e,n){if(n.empty&&!e.some(i=>i.fresh))return e;let r=[],s=e.length?e[e.length-1].dir:Ye.LTR;for(let i=Math.max(0,e.length-10);i<e.length;i++){let o=e[i];o.dir==s&&!n.touchesRange(o.from,o.to)&&r.push(new Gd(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}}function ob(t,e,n){for(let r=t.state.facet(e),s=r.length-1;s>=0;s--){let i=r[s],o=typeof i=="function"?i(t):i;o&&Jm(o,n)}return n}const RM=pe.mac?"mac":pe.windows?"win":pe.linux?"linux":"key";function _M(t,e){const n=t.split(/-(?!$)/);let r=n[n.length-1];r=="Space"&&(r=" ");let s,i,o,a;for(let l=0;l<n.length-1;++l){const d=n[l];if(/^(cmd|meta|m)$/i.test(d))a=!0;else if(/^a(lt)?$/i.test(d))s=!0;else if(/^(c|ctrl|control)$/i.test(d))i=!0;else if(/^s(hift)?$/i.test(d))o=!0;else if(/^mod$/i.test(d))e=="mac"?a=!0:i=!0;else throw new Error("Unrecognized modifier name: "+d)}return s&&(r="Alt-"+r),i&&(r="Ctrl-"+r),a&&(r="Meta-"+r),o&&(r="Shift-"+r),r}function Tc(t,e,n){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),n!==!1&&e.shiftKey&&(t="Shift-"+t),t}const IM=hi.default(ae.domEventHandlers({keydown(t,e){return k2(w2(e.state),t,e,"editor")}})),Vu=me.define({enables:IM}),ab=new WeakMap;function w2(t){let e=t.facet(Vu),n=ab.get(e);return n||ab.set(e,n=FM(e.reduce((r,s)=>r.concat(s),[]))),n}function $M(t,e,n){return k2(w2(t.state),e,t,n)}let ds=null;const BM=4e3;function FM(t,e=RM){let n=Object.create(null),r=Object.create(null),s=(o,a)=>{let l=r[o];if(l==null)r[o]=a;else if(l!=a)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},i=(o,a,l,d,u)=>{var h,f;let p=n[o]||(n[o]=Object.create(null)),m=a.split(/ (?!$)/).map(y=>_M(y,e));for(let y=1;y<m.length;y++){let w=m.slice(0,y).join(" ");s(w,!0),p[w]||(p[w]={preventDefault:!0,stopPropagation:!1,run:[v=>{let k=ds={view:v,prefix:w,scope:o};return setTimeout(()=>{ds==k&&(ds=null)},BM),!0}]})}let x=m.join(" ");s(x,!1);let b=p[x]||(p[x]={preventDefault:!1,stopPropagation:!1,run:((f=(h=p._any)===null||h===void 0?void 0:h.run)===null||f===void 0?void 0:f.slice())||[]});l&&b.run.push(l),d&&(b.preventDefault=!0),u&&(b.stopPropagation=!0)};for(let o of t){let a=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let d of a){let u=n[d]||(n[d]=Object.create(null));u._any||(u._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:h}=o;for(let f in u)u[f].run.push(p=>h(p,zp))}let l=o[e]||o.key;if(l)for(let d of a)i(d,l,o.run,o.preventDefault,o.stopPropagation),o.shift&&i(d,"Shift-"+l,o.shift,o.preventDefault,o.stopPropagation)}return n}let zp=null;function k2(t,e,n,r){zp=e;let s=eA(e),i=tn(s,0),o=gr(i)==s.length&&s!=" ",a="",l=!1,d=!1,u=!1;ds&&ds.view==n&&ds.scope==r&&(a=ds.prefix+" ",d2.indexOf(e.keyCode)<0&&(d=!0,ds=null));let h=new Set,f=b=>{if(b){for(let y of b.run)if(!h.has(y)&&(h.add(y),y(n)))return b.stopPropagation&&(u=!0),!0;b.preventDefault&&(b.stopPropagation&&(u=!0),d=!0)}return!1},p=t[r],m,x;return p&&(f(p[a+Tc(s,e,!o)])?l=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(pe.windows&&e.ctrlKey&&e.altKey)&&!(pe.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(m=Cs[e.keyCode])&&m!=s?(f(p[a+Tc(m,e,!0)])||e.shiftKey&&(x=Oa[e.keyCode])!=s&&x!=m&&f(p[a+Tc(x,e,!1)]))&&(l=!0):o&&e.shiftKey&&f(p[a+Tc(s,e,!0)])&&(l=!0),!l&&f(p._any)&&(l=!0)),d&&(l=!0),l&&u&&e.stopPropagation(),zp=null,l}class Gl{constructor(e,n,r,s,i){this.className=e,this.left=n,this.top=r,this.width=s,this.height=i}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,n){return n.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,n,r){if(r.empty){let s=e.coordsAtPos(r.head,r.assoc||1);if(!s)return[];let i=S2(e);return[new Gl(n,s.left-i.left,s.top-i.top,null,s.bottom-s.top)]}else return zM(e,n,r)}}function S2(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==Ye.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function lb(t,e,n,r){let s=t.coordsAtPos(e,n*2);if(!s)return r;let i=t.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,a=t.posAtCoords({x:i.left+1,y:o}),l=t.posAtCoords({x:i.right-1,y:o});return a==null||l==null?r:{from:Math.max(r.from,Math.min(a,l)),to:Math.min(r.to,Math.max(a,l))}}function zM(t,e,n){if(n.to<=t.viewport.from||n.from>=t.viewport.to)return[];let r=Math.max(n.from,t.viewport.from),s=Math.min(n.to,t.viewport.to),i=t.textDirection==Ye.LTR,o=t.contentDOM,a=o.getBoundingClientRect(),l=S2(t),d=o.querySelector(".cm-line"),u=d&&window.getComputedStyle(d),h=a.left+(u?parseInt(u.paddingLeft)+Math.min(0,parseInt(u.textIndent)):0),f=a.right-(u?parseInt(u.paddingRight):0),p=Rp(t,r,1),m=Rp(t,s,-1),x=p.type==It.Text?p:null,b=m.type==It.Text?m:null;if(x&&(t.lineWrapping||p.widgetLineBreaks)&&(x=lb(t,r,1,x)),b&&(t.lineWrapping||m.widgetLineBreaks)&&(b=lb(t,s,-1,b)),x&&b&&x.from==b.from&&x.to==b.to)return w(v(n.from,n.to,x));{let C=x?v(n.from,null,x):k(p,!1),j=b?v(null,n.to,b):k(m,!0),S=[];return(x||p).to<(b||m).from-(x&&b?1:0)||p.widgetLineBreaks>1&&C.bottom+t.defaultLineHeight/2<j.top?S.push(y(h,C.bottom,f,j.top)):C.bottom<j.top&&t.elementAtHeight((C.bottom+j.top)/2).type==It.Text&&(C.bottom=j.top=(C.bottom+j.top)/2),w(C).concat(S).concat(w(j))}function y(C,j,S,O){return new Gl(e,C-l.left,j-l.top,S-C,O-j)}function w({top:C,bottom:j,horizontal:S}){let O=[];for(let D=0;D<S.length;D+=2)O.push(y(S[D],C,S[D+1],j));return O}function v(C,j,S){let O=1e9,D=-1e9,M=[];function P(N,E,A,R,_){let I=t.coordsAtPos(N,N==S.to?-2:2),F=t.coordsAtPos(A,A==S.from?2:-2);!I||!F||(O=Math.min(I.top,F.top,O),D=Math.max(I.bottom,F.bottom,D),_==Ye.LTR?M.push(i&&E?h:I.left,i&&R?f:F.right):M.push(!i&&R?h:F.left,!i&&E?f:I.right))}let T=C??S.from,$=j??S.to;for(let N of t.visibleRanges)if(N.to>T&&N.from<$)for(let E=Math.max(N.from,T),A=Math.min(N.to,$);;){let R=t.state.doc.lineAt(E);for(let _ of t.bidiSpans(R)){let I=_.from+R.from,F=_.to+R.from;if(I>=A)break;F>E&&P(Math.max(I,E),C==null&&I<=T,Math.min(F,A),j==null&&F>=$,_.dir)}if(E=R.to+1,E>=A)break}return M.length==0&&P(T,C==null,$,j==null,t.textDirection),{top:O,bottom:D,horizontal:M}}function k(C,j){let S=a.top+(j?C.top:C.bottom);return{top:S,bottom:S,horizontal:[]}}}function VM(t,e){return t.constructor==e.constructor&&t.eq(e)}class HM{constructor(e,n){this.view=e,this.layer=n,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),n.above&&this.dom.classList.add("cm-layer-above"),n.class&&this.dom.classList.add(n.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),n.mount&&n.mount(this.dom,e)}update(e){e.startState.facet(pd)!=e.state.facet(pd)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let n=0,r=e.facet(pd);for(;n<r.length&&r[n]!=this.layer;)n++;this.dom.style.zIndex=String((this.layer.above?150:-1)-n)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:n}=this.view;(e!=this.scaleX||n!=this.scaleY)&&(this.scaleX=e,this.scaleY=n,this.dom.style.transform=`scale(${1/e}, ${1/n})`)}draw(e){if(e.length!=this.drawn.length||e.some((n,r)=>!VM(n,this.drawn[r]))){let n=this.dom.firstChild,r=0;for(let s of e)s.update&&n&&s.constructor&&this.drawn[r].constructor&&s.update(n,this.drawn[r])?(n=n.nextSibling,r++):this.dom.insertBefore(s.draw(),n);for(;n;){let s=n.nextSibling;n.remove(),n=s}this.drawn=e,pe.safari&&pe.safari_version>=26&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const pd=me.define();function C2(t){return[ut.define(e=>new HM(e,t)),pd.of(t)]}const La=me.define({combine(t){return Or(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,n)=>Math.min(e,n),drawRangeCursor:(e,n)=>e||n})}});function WM(t={}){return[La.of(t),UM,KM,GM,qk.of(!0)]}function j2(t){return t.startState.facet(La)!=t.state.facet(La)}const UM=C2({above:!0,markers(t){let{state:e}=t,n=e.facet(La),r=[];for(let s of e.selection.ranges){let i=s==e.selection.main;if(s.empty||n.drawRangeCursor){let o=i?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",a=s.empty?s:q.cursor(s.head,s.head>s.anchor?-1:1);for(let l of Gl.forRange(t,o,a))r.push(l)}}return r},update(t,e){t.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let n=j2(t);return n&&cb(t.state,e),t.docChanged||t.selectionSet||n},mount(t,e){cb(e.state,t)},class:"cm-cursorLayer"});function cb(t,e){e.style.animationDuration=t.facet(La).cursorBlinkRate+"ms"}const KM=C2({above:!1,markers(t){return t.state.selection.ranges.map(e=>e.empty?[]:Gl.forRange(t,"cm-selectionBackground",e)).reduce((e,n)=>e.concat(n))},update(t,e){return t.docChanged||t.selectionSet||t.viewportChanged||j2(t)},class:"cm-selectionLayer"}),GM=hi.highest(ae.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),N2=Ee.define({map(t,e){return t==null?null:e.mapPos(t)}}),ta=Bt.define({create(){return null},update(t,e){return t!=null&&(t=e.changes.mapPos(t)),e.effects.reduce((n,r)=>r.is(N2)?r.value:n,t)}}),qM=ut.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let n=t.state.field(ta);n==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(ta)!=n||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(ta),n=e!=null&&t.coordsAtPos(e);if(!n)return null;let r=t.scrollDOM.getBoundingClientRect();return{left:n.left-r.left+t.scrollDOM.scrollLeft*t.scaleX,top:n.top-r.top+t.scrollDOM.scrollTop*t.scaleY,height:n.bottom-n.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:n}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/n+"px",this.cursor.style.height=t.height/n+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(ta)!=t&&this.view.dispatch({effects:N2.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){(t.target==this.view.contentDOM||!this.view.contentDOM.contains(t.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function YM(){return[ta,qM]}function db(t,e,n,r,s){e.lastIndex=0;for(let i=t.iterRange(n,r),o=n,a;!i.next().done;o+=i.value.length)if(!i.lineBreak)for(;a=e.exec(i.value);)s(o+a.index,a)}function XM(t,e){let n=t.visibleRanges;if(n.length==1&&n[0].from==t.viewport.from&&n[0].to==t.viewport.to)return n;let r=[];for(let{from:s,to:i}of n)s=Math.max(t.state.doc.lineAt(s).from,s-e),i=Math.min(t.state.doc.lineAt(i).to,i+e),r.length&&r[r.length-1].to>=s?r[r.length-1].to=i:r.push({from:s,to:i});return r}class ZM{constructor(e){const{regexp:n,decoration:r,decorate:s,boundary:i,maxLength:o=1e3}=e;if(!n.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=n,s)this.addMatch=(a,l,d,u)=>s(u,d,d+a[0].length,a,l);else if(typeof r=="function")this.addMatch=(a,l,d,u)=>{let h=r(a,l,d);h&&u(d,d+a[0].length,h)};else if(r)this.addMatch=(a,l,d,u)=>u(d,d+a[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=i,this.maxLength=o}createDeco(e){let n=new Ur,r=n.add.bind(n);for(let{from:s,to:i}of XM(e,this.maxLength))db(e.state.doc,this.regexp,s,i,(o,a)=>this.addMatch(a,e,o,r));return n.finish()}updateDeco(e,n){let r=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((i,o,a,l)=>{l>=e.view.viewport.from&&a<=e.view.viewport.to&&(r=Math.min(a,r),s=Math.max(l,s))}),e.viewportMoved||s-r>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,n.map(e.changes),r,s):n}updateRange(e,n,r,s){for(let i of e.visibleRanges){let o=Math.max(i.from,r),a=Math.min(i.to,s);if(a>=o){let l=e.state.doc.lineAt(o),d=l.to<a?e.state.doc.lineAt(a):l,u=Math.max(i.from,l.from),h=Math.min(i.to,d.to);if(this.boundary){for(;o>l.from;o--)if(this.boundary.test(l.text[o-1-l.from])){u=o;break}for(;a<d.to;a++)if(this.boundary.test(d.text[a-d.from])){h=a;break}}let f=[],p,m=(x,b,y)=>f.push(y.range(x,b));if(l==d)for(this.regexp.lastIndex=u-l.from;(p=this.regexp.exec(l.text))&&p.index<h-l.from;)this.addMatch(p,e,p.index+l.from,m);else db(e.state.doc,this.regexp,u,h,(x,b)=>this.addMatch(b,e,x,m));n=n.update({filterFrom:u,filterTo:h,filter:(x,b)=>x<u||b>h,add:f})}}return n}}const Vp=/x/.unicode!=null?"gu":"g",QM=new RegExp(`[\0-\b
269
269
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Vp),JM={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Vh=null;function eT(){var t;if(Vh==null&&typeof document<"u"&&document.body){let e=document.body.style;Vh=((t=e.tabSize)!==null&&t!==void 0?t:e.MozTabSize)!=null}return Vh||!1}const md=me.define({combine(t){let e=Or(t,{render:null,specialChars:QM,addSpecialChars:null});return(e.replaceTabs=!eT())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Vp)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Vp)),e}});function tT(t={}){return[md.of(t),nT()]}let ub=null;function nT(){return ub||(ub=ut.fromClass(class{constructor(t){this.view=t,this.decorations=Ce.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(md)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new ZM({regexp:t.specialChars,decoration:(e,n,r)=>{let{doc:s}=n.state,i=tn(e[0],0);if(i==9){let o=s.lineAt(r),a=n.state.tabSize,l=vo(o.text,a,r-o.from);return Ce.replace({widget:new oT((a-l%a)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[i]||(this.decorationCache[i]=Ce.replace({widget:new iT(t,i)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(md);t.startState.facet(md)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))}const rT="•";function sT(t){return t>=32?rT:t==10?"␤":String.fromCharCode(9216+t)}class iT extends Er{constructor(e,n){super(),this.options=e,this.code=n}eq(e){return e.code==this.code}toDOM(e){let n=sT(this.code),r=e.state.phrase("Control character")+" "+(JM[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,r,n);if(s)return s;let i=document.createElement("span");return i.textContent=n,i.title=r,i.setAttribute("aria-label",r),i.className="cm-specialChar",i}ignoreEvent(){return!1}}class oT extends Er{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function aT(){return cT}const lT=Ce.line({class:"cm-activeLine"}),cT=ut.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,n=[];for(let r of t.state.selection.ranges){let s=t.lineBlockAt(r.head);s.from>e&&(n.push(lT.range(s.from)),e=s.from)}return Ce.set(n)}},{decorations:t=>t.decorations});class dT extends Er{constructor(e){super(),this.content=e}toDOM(e){let n=document.createElement("span");return n.className="cm-placeholder",n.style.pointerEvents="none",n.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),n.setAttribute("aria-hidden","true"),n}coordsAt(e){let n=e.firstChild?la(e.firstChild):[];if(!n.length)return null;let r=window.getComputedStyle(e.parentNode),s=Aa(n[0],r.direction!="rtl"),i=parseInt(r.lineHeight);return s.bottom-s.top>i*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+i}:s}ignoreEvent(){return!1}}function uT(t){let e=ut.fromClass(class{constructor(n){this.view=n,this.placeholder=t?Ce.set([Ce.widget({widget:new dT(t),side:1}).range(0)]):Ce.none}get decorations(){return this.view.state.doc.length?Ce.none:this.placeholder}},{decorations:n=>n.decorations});return typeof t=="string"?[e,ae.contentAttributes.of({"aria-placeholder":t})]:e}const Hp=2e3;function hT(t,e,n){let r=Math.min(e.line,n.line),s=Math.max(e.line,n.line),i=[];if(e.off>Hp||n.off>Hp||e.col<0||n.col<0){let o=Math.min(e.off,n.off),a=Math.max(e.off,n.off);for(let l=r;l<=s;l++){let d=t.doc.line(l);d.length<=a&&i.push(q.range(d.from+o,d.to+a))}}else{let o=Math.min(e.col,n.col),a=Math.max(e.col,n.col);for(let l=r;l<=s;l++){let d=t.doc.line(l),u=kp(d.text,o,t.tabSize,!0);if(u<0)i.push(q.cursor(d.to));else{let h=kp(d.text,a,t.tabSize);i.push(q.range(d.from+u,d.from+h))}}}return i}function fT(t,e){let n=t.coordsAtPos(t.viewport.from);return n?Math.round(Math.abs((n.left-e)/t.defaultCharacterWidth)):-1}function hb(t,e){let n=t.posAtCoords({x:e.clientX,y:e.clientY},!1),r=t.state.doc.lineAt(n),s=n-r.from,i=s>Hp?-1:s==r.length?fT(t,e.clientX):vo(r.text,t.state.tabSize,n-r.from);return{line:r.number,col:i,off:s}}function pT(t,e){let n=hb(t,e),r=t.state.selection;return n?{update(s){if(s.docChanged){let i=s.changes.mapPos(s.startState.doc.line(n.line).from),o=s.state.doc.lineAt(i);n={line:o.number,col:n.col,off:Math.min(n.off,o.length)},r=r.map(s.changes)}},get(s,i,o){let a=hb(t,s);if(!a)return r;let l=hT(t.state,n,a);return l.length?o?q.create(l.concat(r.ranges)):q.create(l):r}}:null}function mT(t){let e=n=>n.altKey&&n.button==0;return ae.mouseSelectionStyle.of((n,r)=>e(r)?pT(n,r):null)}const gT={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},xT={style:"cursor: crosshair"};function bT(t={}){let[e,n]=gT[t.key||"Alt"],r=ut.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==e||n(s))},keyup(s){(s.keyCode==e||!n(s))&&this.set(!1)},mousemove(s){this.set(n(s))}}});return[r,ae.contentAttributes.of(s=>{var i;return!((i=s.plugin(r))===null||i===void 0)&&i.isDown?xT:null})]}const Lc="-10000px";class P2{constructor(e,n,r,s){this.facet=n,this.createTooltipView=r,this.removeTooltipView=s,this.input=e.state.facet(n),this.tooltips=this.input.filter(o=>o);let i=null;this.tooltipViews=this.tooltips.map(o=>i=r(o,i))}update(e,n){var r;let s=e.state.facet(this.facet),i=s.filter(l=>l);if(s===this.input){for(let l of this.tooltipViews)l.update&&l.update(e);return!1}let o=[],a=n?[]:null;for(let l=0;l<i.length;l++){let d=i[l],u=-1;if(d){for(let h=0;h<this.tooltips.length;h++){let f=this.tooltips[h];f&&f.create==d.create&&(u=h)}if(u<0)o[l]=this.createTooltipView(d,l?o[l-1]:null),a&&(a[l]=!!d.above);else{let h=o[l]=this.tooltipViews[u];a&&(a[l]=n[u]),h.update&&h.update(e)}}}for(let l of this.tooltipViews)o.indexOf(l)<0&&(this.removeTooltipView(l),(r=l.destroy)===null||r===void 0||r.call(l));return n&&(a.forEach((l,d)=>n[d]=l),n.length=a.length),this.input=s,this.tooltips=i,this.tooltipViews=o,!0}}function yT(t){let e=t.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Hh=me.define({combine:t=>{var e,n,r;return{position:pe.ios?"absolute":((e=t.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((n=t.find(s=>s.parent))===null||n===void 0?void 0:n.parent)||null,tooltipSpace:((r=t.find(s=>s.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||yT}}}),fb=new WeakMap,cg=ut.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(Hh);this.position=e.position,this.parent=e.parent,this.classes=t.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 P2(t,dg,(n,r)=>this.createTooltip(n,r),n=>{this.resizeObserver&&this.resizeObserver.unobserve(n.dom),n.dom.remove()}),this.above=this.manager.tooltips.map(n=>!!n.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(n=>{Date.now()>this.lastTransaction-50&&n.length>0&&n[n.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),t.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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let n=e||t.geometryChanged,r=t.state.facet(Hh);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;n=!0}if(r.parent!=this.parent){this.parent&&this.container.remove(),this.parent=r.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);n=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);n&&this.maybeMeasure()}createTooltip(t,e){let n=t.create(this.view),r=e?e.dom:null;if(n.dom.classList.add("cm-tooltip"),t.arrow&&!n.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",n.dom.appendChild(s)}return n.dom.style.position=this.position,n.dom.style.top=Lc,n.dom.style.left="0px",this.container.insertBefore(n.dom,r),n.mount&&n.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(n.dom),n}destroy(){var t,e,n;this.view.win.removeEventListener("resize",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(t=r.destroy)===null||t===void 0||t.call(r);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(n=this.intersectionObserver)===null||n===void 0||n.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=1,e=1,n=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:i}=this.manager.tooltipViews[0];if(pe.safari){let o=i.getBoundingClientRect();n=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else n=!!i.offsetParent&&i.offsetParent!=this.container.ownerDocument.body}if(n||this.position=="absolute")if(this.parent){let i=this.parent.getBoundingClientRect();i.width&&i.height&&(t=i.width/this.parent.offsetWidth,e=i.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);let r=this.view.scrollDOM.getBoundingClientRect(),s=ig(this.view);return{visible:{left:r.left+s.left,top:r.top+s.top,right:r.right-s.right,bottom:r.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((i,o)=>{let a=this.manager.tooltipViews[o];return a.getCoords?a.getCoords(i.pos):this.view.coordsAtPos(i.pos)}),size:this.manager.tooltipViews.map(({dom:i})=>i.getBoundingClientRect()),space:this.view.state.facet(Hh).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:n}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let a of this.manager.tooltipViews)a.dom.style.position="absolute"}let{visible:n,space:r,scaleX:s,scaleY:i}=t,o=[];for(let a=0;a<this.manager.tooltips.length;a++){let l=this.manager.tooltips[a],d=this.manager.tooltipViews[a],{dom:u}=d,h=t.pos[a],f=t.size[a];if(!h||l.clip!==!1&&(h.bottom<=Math.max(n.top,r.top)||h.top>=Math.min(n.bottom,r.bottom)||h.right<Math.max(n.left,r.left)-.1||h.left>Math.min(n.right,r.right)+.1)){u.style.top=Lc;continue}let p=l.arrow?d.dom.querySelector(".cm-tooltip-arrow"):null,m=p?7:0,x=f.right-f.left,b=(e=fb.get(d))!==null&&e!==void 0?e:f.bottom-f.top,y=d.offset||wT,w=this.view.textDirection==Ye.LTR,v=f.width>r.right-r.left?w?r.left:r.right-f.width:w?Math.max(r.left,Math.min(h.left-(p?14:0)+y.x,r.right-x)):Math.min(Math.max(r.left,h.left-x+(p?14:0)-y.x),r.right-x),k=this.above[a];!l.strictSide&&(k?h.top-b-m-y.y<r.top:h.bottom+b+m+y.y>r.bottom)&&k==r.bottom-h.bottom>h.top-r.top&&(k=this.above[a]=!k);let C=(k?h.top-r.top:r.bottom-h.bottom)-m;if(C<b&&d.resize!==!1){if(C<this.view.defaultLineHeight){u.style.top=Lc;continue}fb.set(d,b),u.style.height=(b=C)/i+"px"}else u.style.height&&(u.style.height="");let j=k?h.top-b-m-y.y:h.bottom+m+y.y,S=v+x;if(d.overlap!==!0)for(let O of o)O.left<S&&O.right>v&&O.top<j+b&&O.bottom>j&&(j=k?O.top-b-2-m:O.bottom+m+2);if(this.position=="absolute"?(u.style.top=(j-t.parent.top)/i+"px",pb(u,(v-t.parent.left)/s)):(u.style.top=j/i+"px",pb(u,v/s)),p){let O=h.left+(w?y.x:-y.x)-(v+14-7);p.style.left=O/s+"px"}d.overlap!==!0&&o.push({left:v,top:j,right:S,bottom:j+b}),u.classList.toggle("cm-tooltip-above",k),u.classList.toggle("cm-tooltip-below",!k),d.positioned&&d.positioned(t.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let t of this.manager.tooltipViews)t.dom.style.top=Lc}},{eventObservers:{scroll(){this.maybeMeasure()}}});function pb(t,e){let n=parseInt(t.style.left,10);(isNaN(n)||Math.abs(e-n)>1)&&(t.style.left=e+"px")}const vT=ae.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"}}}),wT={x:0,y:0},dg=me.define({enables:[cg,vT]}),qd=me.define({combine:t=>t.reduce((e,n)=>e.concat(n),[])});class Hu{static create(e){return new Hu(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new P2(e,qd,(n,r)=>this.createHostedView(n,r),n=>n.dom.remove())}createHostedView(e,n){let r=e.create(this.view);return r.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(r.dom,n?n.dom.nextSibling:this.dom.firstChild),this.mounted&&r.mount&&r.mount(this.view),r}mount(e){for(let n of this.manager.tooltipViews)n.mount&&n.mount(e);this.mounted=!0}positioned(e){for(let n of this.manager.tooltipViews)n.positioned&&n.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let n of this.manager.tooltipViews)(e=n.destroy)===null||e===void 0||e.call(n)}passProp(e){let n;for(let r of this.manager.tooltipViews){let s=r[e];if(s!==void 0){if(n===void 0)n=s;else if(n!==s)return}}return n}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const kT=dg.compute([qd],t=>{let e=t.facet(qd);return e.length===0?null:{pos:Math.min(...e.map(n=>n.pos)),end:Math.max(...e.map(n=>{var r;return(r=n.end)!==null&&r!==void 0?r:n.pos})),create:Hu.create,above:e[0].above,arrow:e.some(n=>n.arrow)}});class ST{constructor(e,n,r,s,i){this.view=e,this.source=n,this.field=r,this.setHover=s,this.hoverTime=i,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:n}=this,r=e.docView.tile.nearest(n.target);if(!r)return;let s,i=1;if(r.isWidget())s=r.posAtStart;else{if(s=e.posAtCoords(n),s==null)return;let a=e.coordsAtPos(s);if(!a||n.y<a.top||n.y>a.bottom||n.x<a.left-e.defaultCharacterWidth||n.x>a.right+e.defaultCharacterWidth)return;let l=e.bidiSpans(e.state.doc.lineAt(s)).find(u=>u.from<=s&&u.to>=s),d=l&&l.dir==Ye.RTL?-1:1;i=n.x<a.left?-d:d}let o=this.source(e,s,i);if(o?.then){let a=this.pending={pos:s};o.then(l=>{this.pending==a&&(this.pending=null,l&&!(Array.isArray(l)&&!l.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(l)?l:[l])}))},l=>sn(e.state,l,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let e=this.view.plugin(cg),n=e?e.manager.tooltips.findIndex(r=>r.create==Hu.create):-1;return n>-1?e.manager.tooltipViews[n]:null}mousemove(e){var n,r;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:i}=this;if(s.length&&i&&!CT(i.dom,e)||this.pending){let{pos:o}=s[0]||this.pending,a=(r=(n=s[0])===null||n===void 0?void 0:n.end)!==null&&r!==void 0?r:o;(o==a?this.view.posAtCoords(this.lastMove)!=o:!jT(this.view,o,a,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:n}=this;if(n.length){let{tooltip:r}=this;r&&r.dom.contains(e.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let n=r=>{e.removeEventListener("mouseleave",n),this.active.length&&!this.view.dom.contains(r.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",n)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Rc=4;function CT(t,e){let{left:n,right:r,top:s,bottom:i}=t.getBoundingClientRect(),o;if(o=t.querySelector(".cm-tooltip-arrow")){let a=o.getBoundingClientRect();s=Math.min(a.top,s),i=Math.max(a.bottom,i)}return e.clientX>=n-Rc&&e.clientX<=r+Rc&&e.clientY>=s-Rc&&e.clientY<=i+Rc}function jT(t,e,n,r,s,i){let o=t.scrollDOM.getBoundingClientRect(),a=t.documentTop+t.documentPadding.top+t.contentHeight;if(o.left>r||o.right<r||o.top>s||Math.min(o.bottom,a)<s)return!1;let l=t.posAtCoords({x:r,y:s},!1);return l>=e&&l<=n}function NT(t,e={}){let n=Ee.define(),r=Bt.define({create(){return[]},update(s,i){if(s.length&&(e.hideOnChange&&(i.docChanged||i.selection)?s=[]:e.hideOn&&(s=s.filter(o=>!e.hideOn(i,o))),i.docChanged)){let o=[];for(let a of s){let l=i.changes.mapPos(a.pos,-1,Gt.TrackDel);if(l!=null){let d=Object.assign(Object.create(null),a);d.pos=l,d.end!=null&&(d.end=i.changes.mapPos(d.end)),o.push(d)}}s=o}for(let o of i.effects)o.is(n)&&(s=o.value),o.is(PT)&&(s=[]);return s},provide:s=>qd.from(s)});return{active:r,extension:[r,ut.define(s=>new ST(s,t,r,n,e.hoverTime||300)),kT]}}function O2(t,e){let n=t.plugin(cg);if(!n)return null;let r=n.manager.tooltips.indexOf(e);return r<0?null:n.manager.tooltipViews[r]}const PT=Ee.define(),mb=me.define({combine(t){let e,n;for(let r of t)e=e||r.topContainer,n=n||r.bottomContainer;return{topContainer:e,bottomContainer:n}}});function Ra(t,e){let n=t.plugin(E2),r=n?n.specs.indexOf(e):-1;return r>-1?n.panels[r]:null}const E2=ut.fromClass(class{constructor(t){this.input=t.state.facet(_a),this.specs=this.input.filter(n=>n),this.panels=this.specs.map(n=>n(t));let e=t.state.facet(mb);this.top=new _c(t,!0,e.topContainer),this.bottom=new _c(t,!1,e.bottomContainer),this.top.sync(this.panels.filter(n=>n.top)),this.bottom.sync(this.panels.filter(n=>!n.top));for(let n of this.panels)n.dom.classList.add("cm-panel"),n.mount&&n.mount()}update(t){let e=t.state.facet(mb);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new _c(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new _c(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let n=t.state.facet(_a);if(n!=this.input){let r=n.filter(l=>l),s=[],i=[],o=[],a=[];for(let l of r){let d=this.specs.indexOf(l),u;d<0?(u=l(t.view),a.push(u)):(u=this.panels[d],u.update&&u.update(t)),s.push(u),(u.top?i:o).push(u)}this.specs=r,this.panels=s,this.top.sync(i),this.bottom.sync(o);for(let l of a)l.dom.classList.add("cm-panel"),l.mount&&l.mount()}else for(let r of this.panels)r.update&&r.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>ae.scrollMargins.of(e=>{let n=e.plugin(t);return n&&{top:n.top.scrollMargin(),bottom:n.bottom.scrollMargin()}})});class _c{constructor(e,n,r){this.view=e,this.top=n,this.container=r,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let n of this.panels)n.destroy&&e.indexOf(n)<0&&n.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let n=this.container||this.view.dom;n.insertBefore(this.dom,this.top?n.firstChild:null)}let e=this.dom.firstChild;for(let n of this.panels)if(n.dom.parentNode==this.dom){for(;e!=n.dom;)e=gb(e);e=e.nextSibling}else this.dom.insertBefore(n.dom,e);for(;e;)e=gb(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function gb(t){let e=t.nextSibling;return t.remove(),e}const _a=me.define({enables:E2});class Gr extends ks{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Gr.prototype.elementClass="";Gr.prototype.toDOM=void 0;Gr.prototype.mapMode=Gt.TrackBefore;Gr.prototype.startSide=Gr.prototype.endSide=-1;Gr.prototype.point=!0;const gd=me.define(),OT=me.define(),ET={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>Le.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},ua=me.define();function DT(t){return[D2(),ua.of({...ET,...t})]}const xb=me.define({combine:t=>t.some(e=>e)});function D2(t){return[AT]}const AT=ut.fromClass(class{constructor(t){this.view=t,this.domAfter=null,this.prevViewport=t.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=t.state.facet(ua).map(e=>new yb(t,e)),this.fixed=!t.state.facet(xb);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),t.scrollDOM.insertBefore(this.dom,t.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(t){if(this.updateGutters(t)){let e=this.prevViewport,n=t.view.viewport,r=Math.min(e.to,n.to)-Math.max(e.from,n.from);this.syncGutters(r<(n.to-n.from)*.8)}if(t.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(xb)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let n=Le.iter(this.view.state.facet(gd),this.view.viewport.from),r=[],s=this.gutters.map(i=>new MT(i,this.view.viewport,-this.view.documentPadding.top));for(let i of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(i.type)){let o=!0;for(let a of i.type)if(a.type==It.Text&&o){Wp(n,r,a.from);for(let l of s)l.line(this.view,a,r);o=!1}else if(a.widget)for(let l of s)l.widget(this.view,a)}else if(i.type==It.Text){Wp(n,r,i.from);for(let o of s)o.line(this.view,i,r)}else if(i.widget)for(let o of s)o.widget(this.view,i);for(let i of s)i.finish();t&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(t){let e=t.startState.facet(ua),n=t.state.facet(ua),r=t.docChanged||t.heightChanged||t.viewportChanged||!Le.eq(t.startState.facet(gd),t.state.facet(gd),t.view.viewport.from,t.view.viewport.to);if(e==n)for(let s of this.gutters)s.update(t)&&(r=!0);else{r=!0;let s=[];for(let i of n){let o=e.indexOf(i);o<0?s.push(new yb(this.view,i)):(this.gutters[o].update(t),s.push(this.gutters[o]))}for(let i of this.gutters)i.dom.remove(),s.indexOf(i)<0&&i.destroy();for(let i of s)i.config.side=="after"?this.getDOMAfter().appendChild(i.dom):this.dom.appendChild(i.dom);this.gutters=s}return r}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:t=>ae.scrollMargins.of(e=>{let n=e.plugin(t);if(!n||n.gutters.length==0||!n.fixed)return null;let r=n.dom.offsetWidth*e.scaleX,s=n.domAfter?n.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==Ye.LTR?{left:r,right:s}:{right:r,left:s}})});function bb(t){return Array.isArray(t)?t:[t]}function Wp(t,e,n){for(;t.value&&t.from<=n;)t.from==n&&e.push(t.value),t.next()}class MT{constructor(e,n,r){this.gutter=e,this.height=r,this.i=0,this.cursor=Le.iter(e.markers,n.from)}addElement(e,n,r){let{gutter:s}=this,i=(n.top-this.height)/e.scaleY,o=n.height/e.scaleY;if(this.i==s.elements.length){let a=new A2(e,o,i,r);s.elements.push(a),s.dom.appendChild(a.dom)}else s.elements[this.i].update(e,o,i,r);this.height=n.bottom,this.i++}line(e,n,r){let s=[];Wp(this.cursor,s,n.from),r.length&&(s=s.concat(r));let i=this.gutter.config.lineMarker(e,n,s);i&&s.unshift(i);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,n,s)}widget(e,n){let r=this.gutter.config.widgetMarker(e,n.widget,n),s=r?[r]:null;for(let i of e.state.facet(OT)){let o=i(e,n.widget,n);o&&(s||(s=[])).push(o)}s&&this.addElement(e,n,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let n=e.elements.pop();e.dom.removeChild(n.dom),n.destroy()}}}class yb{constructor(e,n){this.view=e,this.config=n,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in n.domEventHandlers)this.dom.addEventListener(r,s=>{let i=s.target,o;if(i!=this.dom&&this.dom.contains(i)){for(;i.parentNode!=this.dom;)i=i.parentNode;let l=i.getBoundingClientRect();o=(l.top+l.bottom)/2}else o=s.clientY;let a=e.lineBlockAtHeight(o-e.documentTop);n.domEventHandlers[r](e,a,s)&&s.preventDefault()});this.markers=bb(n.markers(e)),n.initialSpacer&&(this.spacer=new A2(e,0,0,[n.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let n=this.markers;if(this.markers=bb(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 r=e.view.viewport;return!Le.eq(this.markers,n,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class A2{constructor(e,n,r,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,n,r,s)}update(e,n,r,s){this.height!=n&&(this.height=n,this.dom.style.height=n+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),TT(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,n){let r="cm-gutterElement",s=this.dom.firstChild;for(let i=0,o=0;;){let a=o,l=i<n.length?n[i++]:null,d=!1;if(l){let u=l.elementClass;u&&(r+=" "+u);for(let h=o;h<this.markers.length;h++)if(this.markers[h].compare(l)){a=h,d=!0;break}}else a=this.markers.length;for(;o<a;){let u=this.markers[o++];if(u.toDOM){u.destroy(s);let h=s.nextSibling;s.remove(),s=h}}if(!l)break;l.toDOM&&(d?s=s.nextSibling:this.dom.insertBefore(l.toDOM(e),s)),d&&o++}this.dom.className=r,this.markers=n}destroy(){this.setMarkers(null,[])}}function TT(t,e){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].compare(e[n]))return!1;return!0}const LT=me.define(),RT=me.define(),Di=me.define({combine(t){return Or(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,n){let r=Object.assign({},e);for(let s in n){let i=r[s],o=n[s];r[s]=i?(a,l,d)=>i(a,l,d)||o(a,l,d):o}return r}})}});class Wh extends Gr{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Uh(t,e){return t.state.facet(Di).formatNumber(e,t.state)}const _T=ua.compute([Di],t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(LT)},lineMarker(e,n,r){return r.some(s=>s.toDOM)?null:new Wh(Uh(e,e.state.doc.lineAt(n.from).number))},widgetMarker:(e,n,r)=>{for(let s of e.state.facet(RT)){let i=s(e,n,r);if(i)return i}return null},lineMarkerChange:e=>e.startState.facet(Di)!=e.state.facet(Di),initialSpacer(e){return new Wh(Uh(e,vb(e.state.doc.lines)))},updateSpacer(e,n){let r=Uh(n.view,vb(n.view.state.doc.lines));return r==e.number?e:new Wh(r)},domEventHandlers:t.facet(Di).domEventHandlers,side:"before"}));function IT(t={}){return[Di.of(t),D2(),_T]}function vb(t){let e=9;for(;e<t;)e=e*10+9;return e}const $T=new class extends Gr{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},BT=gd.compute(["selection"],t=>{let e=[],n=-1;for(let r of t.selection.ranges){let s=t.doc.lineAt(r.head).from;s>n&&(n=s,e.push($T.range(s)))}return Le.of(e)});function FT(){return BT}var Kh;const Ai=new Te;function zT(t){return me.define({combine:t?e=>e.concat(t):void 0})}const VT=new Te;class Yn{constructor(e,n,r=[],s=""){this.data=e,this.name=s,Ie.prototype.hasOwnProperty("tree")||Object.defineProperty(Ie.prototype,"tree",{get(){return Ht(this)}}),this.parser=n,this.extension=[Ns.of(this),Ie.languageData.of((i,o,a)=>{let l=wb(i,o,a),d=l.type.prop(Ai);if(!d)return[];let u=i.facet(d),h=l.type.prop(VT);if(h){let f=l.resolve(o-l.from,a);for(let p of h)if(p.test(f,i)){let m=i.facet(p.facet);return p.type=="replace"?m:m.concat(u)}}return u})].concat(r)}isActiveAt(e,n,r=-1){return wb(e,n,r).type.prop(Ai)==this.data}findRegions(e){let n=e.facet(Ns);if(n?.data==this.data)return[{from:0,to:e.doc.length}];if(!n||!n.allowsNesting)return[];let r=[],s=(i,o)=>{if(i.prop(Ai)==this.data){r.push({from:o,to:o+i.length});return}let a=i.prop(Te.mounted);if(a){if(a.tree.prop(Ai)==this.data){if(a.overlay)for(let l of a.overlay)r.push({from:l.from+o,to:l.to+o});else r.push({from:o,to:o+i.length});return}else if(a.overlay){let l=r.length;if(s(a.tree,a.overlay[0].from+o),r.length>l)return}}for(let l=0;l<i.children.length;l++){let d=i.children[l];d instanceof dt&&s(d,i.positions[l]+o)}};return s(Ht(e),0),r}get allowsNesting(){return!0}}Yn.setState=Ee.define();function wb(t,e,n){let r=t.facet(Ns),s=Ht(t).topNode;if(!r||r.allowsNesting)for(let i=s;i;i=i.enter(e,n,at.ExcludeBuffers|at.EnterBracketed))i.type.isTop&&(s=i);return s}class Yd extends Yn{constructor(e,n,r){super(e,n,[],r),this.parser=n}static define(e){let n=zT(e.languageData);return new Yd(n,e.parser.configure({props:[Ai.add(r=>r.isTop?n:void 0)]}),e.name)}configure(e,n){return new Yd(this.data,this.parser.configure(e),n||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Ht(t){let e=t.field(Yn.state,!1);return e?e.tree:dt.empty}class HT{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,n){let r=this.cursorPos-this.string.length;return e<r||n>=this.cursorPos?this.doc.sliceString(e,n):this.string.slice(e-r,n-r)}}let Vo=null;class Xd{constructor(e,n,r=[],s,i,o,a,l){this.parser=e,this.state=n,this.fragments=r,this.tree=s,this.treeLen=i,this.viewport=o,this.skipped=a,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,n,r){return new Xd(e,n,[],dt.empty,0,r,[],null)}startParse(){return this.parser.startParse(new HT(this.state.doc),this.fragments)}work(e,n){return n!=null&&n>=this.state.doc.length&&(n=void 0),this.tree!=dt.empty&&this.isDone(n??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),n!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>n)&&n<this.state.doc.length&&this.parse.stopAt(n);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Zs.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(n??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,n;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(n=this.parse.advance()););}),this.treeLen=e,this.tree=n,this.fragments=this.withoutTempSkipped(Zs.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let n=Vo;Vo=this;try{return e()}finally{Vo=n}}withoutTempSkipped(e){for(let n;n=this.tempSkipped.pop();)e=kb(e,n.from,n.to);return e}changes(e,n){let{fragments:r,tree:s,treeLen:i,viewport:o,skipped:a}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((d,u,h,f)=>l.push({fromA:d,toA:u,fromB:h,toB:f})),r=Zs.applyChanges(r,l),s=dt.empty,i=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){a=[];for(let d of this.skipped){let u=e.mapPos(d.from,1),h=e.mapPos(d.to,-1);u<h&&a.push({from:u,to:h})}}}return new Xd(this.parser,n,r,s,i,o,a,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let n=this.skipped.length;for(let r=0;r<this.skipped.length;r++){let{from:s,to:i}=this.skipped[r];s<e.to&&i>e.from&&(this.fragments=kb(this.fragments,s,i),this.skipped.splice(r--,1))}return this.skipped.length>=n?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,n){this.skipped.push({from:e,to:n})}static getSkippingParser(e){return new class extends ok{createParse(n,r,s){let i=s[0].from,o=s[s.length-1].to;return{parsedPos:i,advance(){let l=Vo;if(l){for(let d of s)l.tempSkipped.push(d);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=o,new dt(ln.none,[],[],o-i)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let n=this.fragments;return this.treeLen>=e&&n.length&&n[0].from==0&&n[0].to>=e}static get(){return Vo}}function kb(t,e,n){return Zs.applyChanges(t,[{fromA:e,toA:n,fromB:e,toB:n}])}class io{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let n=this.context.changes(e.changes,e.state),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),n.viewport.to);return n.work(20,r)||n.takeTree(),new io(n)}static init(e){let n=Math.min(3e3,e.doc.length),r=Xd.create(e.facet(Ns).parser,e,{from:0,to:n});return r.work(20,n)||r.takeTree(),new io(r)}}Yn.state=Bt.define({create:io.init,update(t,e){for(let n of e.effects)if(n.is(Yn.setState))return n.value;return e.startState.facet(Ns)!=e.state.facet(Ns)?io.init(e.state):t.apply(e)}});let M2=t=>{let e=setTimeout(()=>t(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(M2=t=>{let e=-1,n=setTimeout(()=>{e=requestIdleCallback(t,{timeout:400})},100);return()=>e<0?clearTimeout(n):cancelIdleCallback(e)});const Gh=typeof navigator<"u"&&(!((Kh=navigator.scheduling)===null||Kh===void 0)&&Kh.isInputPending)?()=>navigator.scheduling.isInputPending():null,WT=ut.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 n=this.view.state.field(Yn.state).context;(n.updateViewport(e.view.viewport)||this.view.viewport.to>n.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(n)}scheduleWork(){if(this.working)return;let{state:e}=this.view,n=e.field(Yn.state);(n.tree!=n.context.tree||!n.context.isDone(e.doc.length))&&(this.working=M2(this.work))}work(e){this.working=null;let n=Date.now();if(this.chunkEnd<n&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=n+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:r,viewport:{to:s}}=this.view,i=r.field(Yn.state);if(i.tree==i.context.tree&&i.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Gh?Math.max(25,e.timeRemaining()-5):1e9),a=i.context.treeLen<s&&r.doc.length>s+1e3,l=i.context.work(()=>Gh&&Gh()||Date.now()>o,s+(a?0:1e5));this.chunkBudget-=Date.now()-n,(l||this.chunkBudget<=0)&&(i.context.takeTree(),this.view.dispatch({effects:Yn.setState.of(new io(i.context))})),this.chunkBudget>0&&!(l&&!a)&&this.scheduleWork(),this.checkAsyncSchedule(i.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(n=>sn(this.view.state,n)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ns=me.define({combine(t){return t.length?t[0]:null},enables:t=>[Yn.state,WT,ae.contentAttributes.compute([t],e=>{let n=e.facet(t);return n&&n.name?{"data-language":n.name}:{}})]});class UT{constructor(e,n=[]){this.language=e,this.support=n,this.extension=[e,n]}}const KT=me.define(),Wu=me.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some(n=>n!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function Zd(t){let e=t.facet(Wu);return e.charCodeAt(0)==9?t.tabSize*e.length:e.length}function Ia(t,e){let n="",r=t.tabSize,s=t.facet(Wu)[0];if(s==" "){for(;e>=r;)n+=" ",e-=r;s=" "}for(let i=0;i<e;i++)n+=s;return n}function ug(t,e){t instanceof Ie&&(t=new Uu(t));for(let r of t.state.facet(KT)){let s=r(t,e);if(s!==void 0)return s}let n=Ht(t.state);return n.length>=e?GT(t,n,e):null}class Uu{constructor(e,n={}){this.state=e,this.options=n,this.unit=Zd(e)}lineAt(e,n=1){let r=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:i}=this.options;return s!=null&&s>=r.from&&s<=r.to?i&&s==e?{text:"",from:e}:(n<0?s<e:s<=e)?{text:r.text.slice(s-r.from),from:s}:{text:r.text.slice(0,s-r.from),from:r.from}:r}textAfterPos(e,n=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:s}=this.lineAt(e,n);return r.slice(e-s,Math.min(r.length,e+100-s))}column(e,n=1){let{text:r,from:s}=this.lineAt(e,n),i=this.countColumn(r,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(i+=o-this.countColumn(r,r.search(/\S|$/))),i}countColumn(e,n=e.length){return vo(e,this.state.tabSize,n)}lineIndent(e,n=1){let{text:r,from:s}=this.lineAt(e,n),i=this.options.overrideIndentation;if(i){let o=i(s);if(o>-1)return o}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const T2=new Te;function GT(t,e,n){let r=e.resolveStack(n),s=e.resolveInner(n,-1).resolve(n,0).enterUnfinishedNodesBefore(n);if(s!=r.node){let i=[];for(let o=s;o&&!(o.from<r.node.from||o.to>r.node.to||o.from==r.node.from&&o.type==r.node.type);o=o.parent)i.push(o);for(let o=i.length-1;o>=0;o--)r={node:i[o],next:r}}return L2(r,t,n)}function L2(t,e,n){for(let r=t;r;r=r.next){let s=YT(r.node);if(s)return s(hg.create(e,n,r))}return 0}function qT(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}function YT(t){let e=t.type.prop(T2);if(e)return e;let n=t.firstChild,r;if(n&&(r=n.type.prop(Te.closedBy))){let s=t.lastChild,i=s&&r.indexOf(s.name)>-1;return o=>JT(o,!0,1,void 0,i&&!qT(o)?s.from:void 0)}return t.parent==null?XT:null}function XT(){return 0}class hg extends Uu{constructor(e,n,r){super(e.state,e.options),this.base=e,this.pos=n,this.context=r}get node(){return this.context.node}static create(e,n,r){return new hg(e,n,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let n=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(n.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(ZT(r,e))break;n=this.state.doc.lineAt(r.from)}return this.lineIndent(n.from)}continue(){return L2(this.context.next,this.base,this.pos)}}function ZT(t,e){for(let n=e;n;n=n.parent)if(t==n)return!0;return!1}function QT(t){let e=t.node,n=e.childAfter(e.from),r=e.lastChild;if(!n)return null;let s=t.options.simulateBreak,i=t.state.doc.lineAt(n.from),o=s==null||s<=i.from?i.to:Math.min(i.to,s);for(let a=n.to;;){let l=e.childAfter(a);if(!l||l==r)return null;if(!l.type.isSkipped){if(l.from>=o)return null;let d=/^ */.exec(i.text.slice(n.to-i.from))[0].length;return{from:n.from,to:n.to+d}}a=l.to}}function JT(t,e,n,r,s){let i=t.textAfter,o=i.match(/^\s*/)[0].length,a=r&&i.slice(o,o+r.length)==r||s==t.pos+o,l=QT(t);return l?a?t.column(l.from):t.column(l.to):t.baseIndent+(a?0:t.unit*n)}function Sb({except:t,units:e=1}={}){return n=>{let r=t&&t.test(n.textAfter);return n.baseIndent+(r?0:e*n.unit)}}const e6=200;function t6(){return Ie.transactionFilter.of(t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let n=t.newDoc,{head:r}=t.newSelection.main,s=n.lineAt(r);if(r>s.from+e6)return t;let i=n.sliceString(s.from,r);if(!e.some(d=>d.test(i)))return t;let{state:o}=t,a=-1,l=[];for(let{head:d}of o.selection.ranges){let u=o.doc.lineAt(d);if(u.from==a)continue;a=u.from;let h=ug(o,u.from);if(h==null)continue;let f=/^\s*/.exec(u.text)[0],p=Ia(o,h);f!=p&&l.push({from:u.from,to:u.from+f.length,insert:p})}return l.length?[t,{changes:l,sequential:!0}]:t})}const n6=me.define(),R2=new Te;function r6(t){let e=t.firstChild,n=t.lastChild;return e&&e.to<n.from?{from:e.to,to:n.type.isError?t.to:n.from}:null}function s6(t,e,n){let r=Ht(t);if(r.length<n)return null;let s=r.resolveStack(n,1),i=null;for(let o=s;o;o=o.next){let a=o.node;if(a.to<=n||a.from>n)continue;if(i&&a.from<e)break;let l=a.type.prop(R2);if(l&&(a.to<r.length-50||r.length==t.doc.length||!i6(a))){let d=l(a,t);d&&d.from<=n&&d.from>=e&&d.to>n&&(i=d)}}return i}function i6(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function Qd(t,e,n){for(let r of t.facet(n6)){let s=r(t,e,n);if(s)return s}return s6(t,e,n)}function _2(t,e){let n=e.mapPos(t.from,1),r=e.mapPos(t.to,-1);return n>=r?void 0:{from:n,to:r}}const Ku=Ee.define({map:_2}),ql=Ee.define({map:_2});function I2(t){let e=[];for(let{head:n}of t.state.selection.ranges)e.some(r=>r.from<=n&&r.to>=n)||e.push(t.lineBlockAt(n));return e}const si=Bt.define({create(){return Ce.none},update(t,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((n,r)=>t=Cb(t,n,r)),t=t.map(e.changes);for(let n of e.effects)if(n.is(Ku)&&!o6(t,n.value.from,n.value.to)){let{preparePlaceholder:r}=e.state.facet(F2),s=r?Ce.replace({widget:new f6(r(e.state,n.value))}):jb;t=t.update({add:[s.range(n.value.from,n.value.to)]})}else n.is(ql)&&(t=t.update({filter:(r,s)=>n.value.from!=r||n.value.to!=s,filterFrom:n.value.from,filterTo:n.value.to}));return e.selection&&(t=Cb(t,e.selection.main.head)),t},provide:t=>ae.decorations.from(t),toJSON(t,e){let n=[];return t.between(0,e.doc.length,(r,s)=>{n.push(r,s)}),n},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let n=0;n<t.length;){let r=t[n++],s=t[n++];if(typeof r!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(jb.range(r,s))}return Ce.set(e,!0)}});function Cb(t,e,n=e){let r=!1;return t.between(e,n,(s,i)=>{s<n&&i>e&&(r=!0)}),r?t.update({filterFrom:e,filterTo:n,filter:(s,i)=>s>=n||i<=e}):t}function Jd(t,e,n){var r;let s=null;return(r=t.field(si,!1))===null||r===void 0||r.between(e,n,(i,o)=>{(!s||s.from>i)&&(s={from:i,to:o})}),s}function o6(t,e,n){let r=!1;return t.between(e,e,(s,i)=>{s==e&&i==n&&(r=!0)}),r}function $2(t,e){return t.field(si,!1)?e:e.concat(Ee.appendConfig.of(z2()))}const a6=t=>{for(let e of I2(t)){let n=Qd(t.state,e.from,e.to);if(n)return t.dispatch({effects:$2(t.state,[Ku.of(n),B2(t,n)])}),!0}return!1},l6=t=>{if(!t.state.field(si,!1))return!1;let e=[];for(let n of I2(t)){let r=Jd(t.state,n.from,n.to);r&&e.push(ql.of(r),B2(t,r,!1))}return e.length&&t.dispatch({effects:e}),e.length>0};function B2(t,e,n=!0){let r=t.state.doc.lineAt(e.from).number,s=t.state.doc.lineAt(e.to).number;return ae.announce.of(`${t.state.phrase(n?"Folded lines":"Unfolded lines")} ${r} ${t.state.phrase("to")} ${s}.`)}const c6=t=>{let{state:e}=t,n=[];for(let r=0;r<e.doc.length;){let s=t.lineBlockAt(r),i=Qd(e,s.from,s.to);i&&n.push(Ku.of(i)),r=(i?t.lineBlockAt(i.to):s).to+1}return n.length&&t.dispatch({effects:$2(t.state,n)}),!!n.length},d6=t=>{let e=t.state.field(si,!1);if(!e||!e.size)return!1;let n=[];return e.between(0,t.state.doc.length,(r,s)=>{n.push(ql.of({from:r,to:s}))}),t.dispatch({effects:n}),!0},u6=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:a6},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:l6},{key:"Ctrl-Alt-[",run:c6},{key:"Ctrl-Alt-]",run:d6}],h6={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},F2=me.define({combine(t){return Or(t,h6)}});function z2(t){return[si,g6]}function V2(t,e){let{state:n}=t,r=n.facet(F2),s=o=>{let a=t.lineBlockAt(t.posAtDOM(o.target)),l=Jd(t.state,a.from,a.to);l&&t.dispatch({effects:ql.of(l)}),o.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(t,s,e);let i=document.createElement("span");return i.textContent=r.placeholderText,i.setAttribute("aria-label",n.phrase("folded code")),i.title=n.phrase("unfold"),i.className="cm-foldPlaceholder",i.onclick=s,i}const jb=Ce.replace({widget:new class extends Er{toDOM(t){return V2(t,null)}}});class f6 extends Er{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return V2(e,this.value)}}const p6={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class qh extends Gr{constructor(e,n){super(),this.config=e,this.open=n}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let n=document.createElement("span");return n.textContent=this.open?this.config.openText:this.config.closedText,n.title=e.state.phrase(this.open?"Fold line":"Unfold line"),n}}function m6(t={}){let e={...p6,...t},n=new qh(e,!0),r=new qh(e,!1),s=ut.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(Ns)!=o.state.facet(Ns)||o.startState.field(si,!1)!=o.state.field(si,!1)||Ht(o.startState)!=Ht(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let a=new Ur;for(let l of o.viewportLineBlocks){let d=Jd(o.state,l.from,l.to)?r:Qd(o.state,l.from,l.to)?n:null;d&&a.add(l.from,l.from,d)}return a.finish()}}),{domEventHandlers:i}=e;return[s,DT({class:"cm-foldGutter",markers(o){var a;return((a=o.plugin(s))===null||a===void 0?void 0:a.markers)||Le.empty},initialSpacer(){return new qh(e,!1)},domEventHandlers:{...i,click:(o,a,l)=>{if(i.click&&i.click(o,a,l))return!0;let d=Jd(o.state,a.from,a.to);if(d)return o.dispatch({effects:ql.of(d)}),!0;let u=Qd(o.state,a.from,a.to);return u?(o.dispatch({effects:Ku.of(u)}),!0):!1}}}),z2()]}const g6=ae.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class wo{constructor(e,n){this.specs=e;let r;function s(a){let l=Ss.newName();return(r||(r=Object.create(null)))["."+l]=a,l}const i=typeof n.all=="string"?n.all:n.all?s(n.all):void 0,o=n.scope;this.scope=o instanceof Yn?a=>a.prop(Ai)==o.data:o?a=>a==o:void 0,this.style=ck(e.map(a=>({tag:a.tag,class:a.class||s(Object.assign({},a,{tag:null}))})),{all:i}).style,this.module=r?new Ss(r):null,this.themeType=n.themeType}static define(e,n){return new wo(e,n||{})}}const Up=me.define(),H2=me.define({combine(t){return t.length?[t[0]]:null}});function Yh(t){let e=t.facet(Up);return e.length?e:t.facet(H2)}function fg(t,e){let n=[b6],r;return t instanceof wo&&(t.module&&n.push(ae.styleModule.of(t.module)),r=t.themeType),e?.fallback?n.push(H2.of(t)):r?n.push(Up.computeN([ae.darkTheme],s=>s.facet(ae.darkTheme)==(r=="dark")?[t]:[])):n.push(Up.of(t)),n}class x6{constructor(e){this.markCache=Object.create(null),this.tree=Ht(e.state),this.decorations=this.buildDeco(e,Yh(e.state)),this.decoratedTo=e.viewport.to}update(e){let n=Ht(e.state),r=Yh(e.state),s=r!=Yh(e.startState),{viewport:i}=e.view,o=e.changes.mapPos(this.decoratedTo,1);n.length<i.to&&!s&&n.type==this.tree.type&&o>=i.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(n!=this.tree||e.viewportChanged||s)&&(this.tree=n,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=i.to)}buildDeco(e,n){if(!n||!this.tree.length)return Ce.none;let r=new Ur;for(let{from:s,to:i}of e.visibleRanges)PD(this.tree,n,(o,a,l)=>{r.add(o,a,this.markCache[l]||(this.markCache[l]=Ce.mark({class:l})))},s,i);return r.finish()}}const b6=hi.high(ut.fromClass(x6,{decorations:t=>t.decorations})),y6=wo.define([{tag:W.meta,color:"#404740"},{tag:W.link,textDecoration:"underline"},{tag:W.heading,textDecoration:"underline",fontWeight:"bold"},{tag:W.emphasis,fontStyle:"italic"},{tag:W.strong,fontWeight:"bold"},{tag:W.strikethrough,textDecoration:"line-through"},{tag:W.keyword,color:"#708"},{tag:[W.atom,W.bool,W.url,W.contentSeparator,W.labelName],color:"#219"},{tag:[W.literal,W.inserted],color:"#164"},{tag:[W.string,W.deleted],color:"#a11"},{tag:[W.regexp,W.escape,W.special(W.string)],color:"#e40"},{tag:W.definition(W.variableName),color:"#00f"},{tag:W.local(W.variableName),color:"#30a"},{tag:[W.typeName,W.namespace],color:"#085"},{tag:W.className,color:"#167"},{tag:[W.special(W.variableName),W.macroName],color:"#256"},{tag:W.definition(W.propertyName),color:"#00c"},{tag:W.comment,color:"#940"},{tag:W.invalid,color:"#f00"}]),v6=ae.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),W2=1e4,U2="()[]{}",K2=me.define({combine(t){return Or(t,{afterCursor:!0,brackets:U2,maxScanDistance:W2,renderMatch:S6})}}),w6=Ce.mark({class:"cm-matchingBracket"}),k6=Ce.mark({class:"cm-nonmatchingBracket"});function S6(t){let e=[],n=t.matched?w6:k6;return e.push(n.range(t.start.from,t.start.to)),t.end&&e.push(n.range(t.end.from,t.end.to)),e}const C6=Bt.define({create(){return Ce.none},update(t,e){if(!e.docChanged&&!e.selection)return t;let n=[],r=e.state.facet(K2);for(let s of e.state.selection.ranges){if(!s.empty)continue;let i=br(e.state,s.head,-1,r)||s.head>0&&br(e.state,s.head-1,1,r)||r.afterCursor&&(br(e.state,s.head,1,r)||s.head<e.state.doc.length&&br(e.state,s.head+1,-1,r));i&&(n=n.concat(r.renderMatch(i,e.state)))}return Ce.set(n,!0)},provide:t=>ae.decorations.from(t)}),j6=[C6,v6];function N6(t={}){return[K2.of(t),j6]}const P6=new Te;function Kp(t,e,n){let r=t.prop(e<0?Te.openedBy:Te.closedBy);if(r)return r;if(t.name.length==1){let s=n.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[n[s+e]]}return null}function Gp(t){let e=t.type.prop(P6);return e?e(t.node):t}function br(t,e,n,r={}){let s=r.maxScanDistance||W2,i=r.brackets||U2,o=Ht(t),a=o.resolveInner(e,n);for(let l=a;l;l=l.parent){let d=Kp(l.type,n,i);if(d&&l.from<l.to){let u=Gp(l);if(u&&(n>0?e>=u.from&&e<u.to:e>u.from&&e<=u.to))return O6(t,e,n,l,u,d,i)}}return E6(t,e,n,o,a.type,s,i)}function O6(t,e,n,r,s,i,o){let a=r.parent,l={from:s.from,to:s.to},d=0,u=a?.cursor();if(u&&(n<0?u.childBefore(r.from):u.childAfter(r.to)))do if(n<0?u.to<=r.from:u.from>=r.to){if(d==0&&i.indexOf(u.type.name)>-1&&u.from<u.to){let h=Gp(u);return{start:l,end:h?{from:h.from,to:h.to}:void 0,matched:!0}}else if(Kp(u.type,n,o))d++;else if(Kp(u.type,-n,o)){if(d==0){let h=Gp(u);return{start:l,end:h&&h.from<h.to?{from:h.from,to:h.to}:void 0,matched:!1}}d--}}while(n<0?u.prevSibling():u.nextSibling());return{start:l,matched:!1}}function E6(t,e,n,r,s,i,o){let a=n<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),l=o.indexOf(a);if(l<0||l%2==0!=n>0)return null;let d={from:n<0?e-1:e,to:n>0?e+1:e},u=t.doc.iterRange(e,n>0?t.doc.length:0),h=0;for(let f=0;!u.next().done&&f<=i;){let p=u.value;n<0&&(f+=p.length);let m=e+f*n;for(let x=n>0?0:p.length-1,b=n>0?p.length:-1;x!=b;x+=n){let y=o.indexOf(p[x]);if(!(y<0||r.resolveInner(m+x,1).type!=s))if(y%2==0==n>0)h++;else{if(h==1)return{start:d,end:{from:m+x,to:m+x+1},matched:y>>1==l>>1};h--}}n>0&&(f+=p.length)}return u.done?{start:d,matched:!1}:null}const D6=Object.create(null),Nb=[ln.none],Pb=[],Ob=Object.create(null),A6=Object.create(null);for(let[t,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"]])A6[t]=M6(D6,e);function Xh(t,e){Pb.indexOf(t)>-1||(Pb.push(t),console.warn(e))}function M6(t,e){let n=[];for(let a of e.split(" ")){let l=[];for(let d of a.split(".")){let u=t[d]||W[d];u?typeof u=="function"?l.length?l=l.map(u):Xh(d,`Modifier ${d} used at start of tag`):l.length?Xh(d,`Tag ${d} used as modifier`):l=Array.isArray(u)?u:[u]:Xh(d,`Unknown highlighting tag ${d}`)}for(let d of l)n.push(d)}if(!n.length)return 0;let r=e.replace(/ /g,"_"),s=r+" "+n.map(a=>a.id),i=Ob[s];if(i)return i.id;let o=Ob[s]=ln.define({id:Nb.length,name:r,props:[ak({[r]:n})]});return Nb.push(o),o.id}Ye.RTL,Ye.LTR;const T6=Yd.define({name:"json",parser:AD.configure({props:[T2.add({Object:Sb({except:/^\s*\}/}),Array:Sb({except:/^\s*\]/})}),R2.add({"Object Array":r6})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function L6(){return new UT(T6)}function qp(){return qp=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},qp.apply(null,arguments)}function R6(t,e){if(t==null)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(e.indexOf(r)!==-1)continue;n[r]=t[r]}return n}const _6=t=>{let{state:e}=t,n=e.doc.lineAt(e.selection.main.from),r=mg(t.state,n.from);return r.line?I6(t):r.block?B6(t):!1};function pg(t,e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let s=t(e,n);return s?(r(n.update(s)),!0):!1}}const I6=pg(V6,0),$6=pg(G2,0),B6=pg((t,e)=>G2(t,e,z6(e)),0);function mg(t,e){let n=t.languageDataAt("commentTokens",e,1);return n.length?n[0]:{}}const Ho=50;function F6(t,{open:e,close:n},r,s){let i=t.sliceDoc(r-Ho,r),o=t.sliceDoc(s,s+Ho),a=/\s*$/.exec(i)[0].length,l=/^\s*/.exec(o)[0].length,d=i.length-a;if(i.slice(d-e.length,d)==e&&o.slice(l,l+n.length)==n)return{open:{pos:r-a,margin:a&&1},close:{pos:s+l,margin:l&&1}};let u,h;s-r<=2*Ho?u=h=t.sliceDoc(r,s):(u=t.sliceDoc(r,r+Ho),h=t.sliceDoc(s-Ho,s));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(h)[0].length,m=h.length-p-n.length;return u.slice(f,f+e.length)==e&&h.slice(m,m+n.length)==n?{open:{pos:r+f+e.length,margin:/\s/.test(u.charAt(f+e.length))?1:0},close:{pos:s-p-n.length,margin:/\s/.test(h.charAt(m-1))?1:0}}:null}function z6(t){let e=[];for(let n of t.selection.ranges){let r=t.doc.lineAt(n.from),s=n.to<=r.to?r:t.doc.lineAt(n.to);s.from>r.from&&s.from==n.to&&(s=n.to==r.to+1?r:t.doc.lineAt(n.to-1));let i=e.length-1;i>=0&&e[i].to>r.from?e[i].to=s.to:e.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:s.to})}return e}function G2(t,e,n=e.selection.ranges){let r=n.map(i=>mg(e,i.from).block);if(!r.every(i=>i))return null;let s=n.map((i,o)=>F6(e,r[o],i.from,i.to));if(t!=2&&!s.every(i=>i))return{changes:e.changes(n.map((i,o)=>s[o]?[]:[{from:i.from,insert:r[o].open+" "},{from:i.to,insert:" "+r[o].close}]))};if(t!=1&&s.some(i=>i)){let i=[];for(let o=0,a;o<s.length;o++)if(a=s[o]){let l=r[o],{open:d,close:u}=a;i.push({from:d.pos-l.open.length,to:d.pos+d.margin},{from:u.pos-u.margin,to:u.pos+l.close.length})}return{changes:i}}return null}function V6(t,e,n=e.selection.ranges){let r=[],s=-1;for(let{from:i,to:o}of n){let a=r.length,l=1e9,d=mg(e,i).line;if(d){for(let u=i;u<=o;){let h=e.doc.lineAt(u);if(h.from>s&&(i==o||o>h.from)){s=h.from;let f=/^\s*/.exec(h.text)[0].length,p=f==h.length,m=h.text.slice(f,f+d.length)==d?f:-1;f<h.text.length&&f<l&&(l=f),r.push({line:h,comment:m,token:d,indent:f,empty:p,single:!1})}u=h.to+1}if(l<1e9)for(let u=a;u<r.length;u++)r[u].indent<r[u].line.text.length&&(r[u].indent=l);r.length==a+1&&(r[a].single=!0)}}if(t!=2&&r.some(i=>i.comment<0&&(!i.empty||i.single))){let i=[];for(let{line:a,token:l,indent:d,empty:u,single:h}of r)(h||!u)&&i.push({from:a.from+d,insert:l+" "});let o=e.changes(i);return{changes:o,selection:e.selection.map(o,1)}}else if(t!=1&&r.some(i=>i.comment>=0)){let i=[];for(let{line:o,comment:a,token:l}of r)if(a>=0){let d=o.from+a,u=d+l.length;o.text[u-o.from]==" "&&u++,i.push({from:d,to:u})}return{changes:i}}return null}const Yp=Pr.define(),H6=Pr.define(),W6=me.define(),q2=me.define({combine(t){return Or(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,n)=>(r,s)=>e(r,s)||n(r,s)})}}),Y2=Bt.define({create(){return yr.empty},update(t,e){let n=e.state.facet(q2),r=e.annotation(Yp);if(r){let l=on.fromTransaction(e,r.selection),d=r.side,u=d==0?t.undone:t.done;return l?u=eu(u,u.length,n.minDepth,l):u=Q2(u,e.startState.selection),new yr(d==0?r.rest:u,d==0?u:r.rest)}let s=e.annotation(H6);if((s=="full"||s=="before")&&(t=t.isolate()),e.annotation(kt.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let i=on.fromTransaction(e),o=e.annotation(kt.time),a=e.annotation(kt.userEvent);return i?t=t.addChanges(i,o,a,n,e):e.selection&&(t=t.addSelection(e.startState.selection,o,a,n.newGroupDelay)),(s=="full"||s=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new yr(t.done.map(on.fromJSON),t.undone.map(on.fromJSON))}});function U6(t={}){return[Y2,q2.of(t),ae.domEventHandlers({beforeinput(e,n){let r=e.inputType=="historyUndo"?X2:e.inputType=="historyRedo"?Xp:null;return r?(e.preventDefault(),r(n)):!1}})]}function Gu(t,e){return function({state:n,dispatch:r}){if(!e&&n.readOnly)return!1;let s=n.field(Y2,!1);if(!s)return!1;let i=s.pop(t,n,e);return i?(r(i),!0):!1}}const X2=Gu(0,!1),Xp=Gu(1,!1),K6=Gu(0,!0),G6=Gu(1,!0);class on{constructor(e,n,r,s,i){this.changes=e,this.effects=n,this.mapped=r,this.startSelection=s,this.selectionsAfter=i}setSelAfter(e){return new on(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,n,r;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(r=this.startSelection)===null||r===void 0?void 0:r.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new on(e.changes&&yt.fromJSON(e.changes),[],e.mapped&&kr.fromJSON(e.mapped),e.startSelection&&q.fromJSON(e.startSelection),e.selectionsAfter.map(q.fromJSON))}static fromTransaction(e,n){let r=Mn;for(let s of e.startState.facet(W6)){let i=s(e);i.length&&(r=r.concat(i))}return!r.length&&e.changes.empty?null:new on(e.changes.invert(e.startState.doc),r,void 0,n||e.startState.selection,Mn)}static selection(e){return new on(void 0,Mn,void 0,void 0,e)}}function eu(t,e,n,r){let s=e+1>n+20?e-n-1:0,i=t.slice(s,e);return i.push(r),i}function q6(t,e){let n=[],r=!1;return t.iterChangedRanges((s,i)=>n.push(s,i)),e.iterChangedRanges((s,i,o,a)=>{for(let l=0;l<n.length;){let d=n[l++],u=n[l++];a>=d&&o<=u&&(r=!0)}}),r}function Y6(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((n,r)=>n.empty!=e.ranges[r].empty).length===0}function Z2(t,e){return t.length?e.length?t.concat(e):t:e}const Mn=[],X6=200;function Q2(t,e){if(t.length){let n=t[t.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-X6));return r.length&&r[r.length-1].eq(e)?t:(r.push(e),eu(t,t.length-1,1e9,n.setSelAfter(r)))}else return[on.selection([e])]}function Z6(t){let e=t[t.length-1],n=t.slice();return n[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),n}function Zh(t,e){if(!t.length)return t;let n=t.length,r=Mn;for(;n;){let s=Q6(t[n-1],e,r);if(s.changes&&!s.changes.empty||s.effects.length){let i=t.slice(0,n);return i[n-1]=s,i}else e=s.mapped,n--,r=s.selectionsAfter}return r.length?[on.selection(r)]:Mn}function Q6(t,e,n){let r=Z2(t.selectionsAfter.length?t.selectionsAfter.map(a=>a.map(e)):Mn,n);if(!t.changes)return on.selection(r);let s=t.changes.map(e),i=e.mapDesc(t.changes,!0),o=t.mapped?t.mapped.composeDesc(i):i;return new on(s,Ee.mapEffects(t.effects,e),o,t.startSelection.map(i),r)}const J6=/^(input\.type|delete)($|\.)/;class yr{constructor(e,n,r=0,s=void 0){this.done=e,this.undone=n,this.prevTime=r,this.prevUserEvent=s}isolate(){return this.prevTime?new yr(this.done,this.undone):this}addChanges(e,n,r,s,i){let o=this.done,a=o[o.length-1];return a&&a.changes&&!a.changes.empty&&e.changes&&(!r||J6.test(r))&&(!a.selectionsAfter.length&&n-this.prevTime<s.newGroupDelay&&s.joinToEvent(i,q6(a.changes,e.changes))||r=="input.type.compose")?o=eu(o,o.length-1,s.minDepth,new on(e.changes.compose(a.changes),Z2(Ee.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,Mn)):o=eu(o,o.length,s.minDepth,e),new yr(o,Mn,n,r)}addSelection(e,n,r,s){let i=this.done.length?this.done[this.done.length-1].selectionsAfter:Mn;return i.length>0&&n-this.prevTime<s&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Y6(i[i.length-1],e)?this:new yr(Q2(this.done,e),this.undone,n,r)}addMapping(e){return new yr(Zh(this.done,e),Zh(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,n,r){let s=e==0?this.done:this.undone;if(s.length==0)return null;let i=s[s.length-1],o=i.selectionsAfter[0]||n.selection;if(r&&i.selectionsAfter.length)return n.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:Yp.of({side:e,rest:Z6(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(i.changes){let a=s.length==1?Mn:s.slice(0,s.length-1);return i.mapped&&(a=Zh(a,i.mapped)),n.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:Yp.of({side:e,rest:a,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}yr.empty=new yr(Mn,Mn);const eL=[{key:"Mod-z",run:X2,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Xp,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Xp,preventDefault:!0},{key:"Mod-u",run:K6,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:G6,preventDefault:!0}];function ko(t,e){return q.create(t.ranges.map(e),t.mainIndex)}function rr(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function sr({state:t,dispatch:e},n){let r=ko(t.selection,n);return r.eq(t.selection,!0)?!1:(e(rr(t,r)),!0)}function qu(t,e){return q.cursor(e?t.to:t.from)}function J2(t,e){return sr(t,n=>n.empty?t.moveByChar(n,e):qu(n,e))}function Wt(t){return t.textDirectionAt(t.state.selection.main.head)==Ye.LTR}const eS=t=>J2(t,!Wt(t)),tS=t=>J2(t,Wt(t));function nS(t,e){return sr(t,n=>n.empty?t.moveByGroup(n,e):qu(n,e))}const tL=t=>nS(t,!Wt(t)),nL=t=>nS(t,Wt(t));function rL(t,e,n){if(e.type.prop(n))return!0;let r=e.to-e.from;return r&&(r>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function Yu(t,e,n){let r=Ht(t).resolveInner(e.head),s=n?Te.closedBy:Te.openedBy;for(let l=e.head;;){let d=n?r.childAfter(l):r.childBefore(l);if(!d)break;rL(t,d,s)?r=d:l=n?d.to:d.from}let i=r.type.prop(s),o,a;return i&&(o=n?br(t,r.from,1):br(t,r.to,-1))&&o.matched?a=n?o.end.to:o.end.from:a=n?r.to:r.from,q.cursor(a,n?-1:1)}const sL=t=>sr(t,e=>Yu(t.state,e,!Wt(t))),iL=t=>sr(t,e=>Yu(t.state,e,Wt(t)));function rS(t,e){return sr(t,n=>{if(!n.empty)return qu(n,e);let r=t.moveVertically(n,e);return r.head!=n.head?r:t.moveToLineBoundary(n,e)})}const sS=t=>rS(t,!1),iS=t=>rS(t,!0);function oS(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,n=0,r=0,s;if(e){for(let i of t.state.facet(ae.scrollMargins)){let o=i(t);o?.top&&(n=Math.max(o?.top,n)),o?.bottom&&(r=Math.max(o?.bottom,r))}s=t.scrollDOM.clientHeight-n-r}else s=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:e,height:Math.max(t.defaultLineHeight,s-5)}}function aS(t,e){let n=oS(t),{state:r}=t,s=ko(r.selection,o=>o.empty?t.moveVertically(o,e,n.height):qu(o,e));if(s.eq(r.selection))return!1;let i;if(n.selfScroll){let o=t.coordsAtPos(r.selection.main.head),a=t.scrollDOM.getBoundingClientRect(),l=a.top+n.marginTop,d=a.bottom-n.marginBottom;o&&o.top>l&&o.bottom<d&&(i=ae.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-l}))}return t.dispatch(rr(r,s),{effects:i}),!0}const Eb=t=>aS(t,!1),Zp=t=>aS(t,!0);function Ds(t,e,n){let r=t.lineBlockAt(e.head),s=t.moveToLineBoundary(e,n);if(s.head==e.head&&s.head!=(n?r.to:r.from)&&(s=t.moveToLineBoundary(e,n,!1)),!n&&s.head==r.from&&r.length){let i=/^\s*/.exec(t.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;i&&e.head!=r.from+i&&(s=q.cursor(r.from+i))}return s}const oL=t=>sr(t,e=>Ds(t,e,!0)),aL=t=>sr(t,e=>Ds(t,e,!1)),lL=t=>sr(t,e=>Ds(t,e,!Wt(t))),cL=t=>sr(t,e=>Ds(t,e,Wt(t))),dL=t=>sr(t,e=>q.cursor(t.lineBlockAt(e.head).from,1)),uL=t=>sr(t,e=>q.cursor(t.lineBlockAt(e.head).to,-1));function hL(t,e,n){let r=!1,s=ko(t.selection,i=>{let o=br(t,i.head,-1)||br(t,i.head,1)||i.head>0&&br(t,i.head-1,1)||i.head<t.doc.length&&br(t,i.head+1,-1);if(!o||!o.end)return i;r=!0;let a=o.start.from==i.head?o.end.to:o.end.from;return q.cursor(a)});return r?(e(rr(t,s)),!0):!1}const fL=({state:t,dispatch:e})=>hL(t,e);function zn(t,e){let n=ko(t.state.selection,r=>{let s=e(r);return q.range(r.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return n.eq(t.state.selection)?!1:(t.dispatch(rr(t.state,n)),!0)}function lS(t,e){return zn(t,n=>t.moveByChar(n,e))}const cS=t=>lS(t,!Wt(t)),dS=t=>lS(t,Wt(t));function uS(t,e){return zn(t,n=>t.moveByGroup(n,e))}const pL=t=>uS(t,!Wt(t)),mL=t=>uS(t,Wt(t)),gL=t=>zn(t,e=>Yu(t.state,e,!Wt(t))),xL=t=>zn(t,e=>Yu(t.state,e,Wt(t)));function hS(t,e){return zn(t,n=>t.moveVertically(n,e))}const fS=t=>hS(t,!1),pS=t=>hS(t,!0);function mS(t,e){return zn(t,n=>t.moveVertically(n,e,oS(t).height))}const Db=t=>mS(t,!1),Ab=t=>mS(t,!0),bL=t=>zn(t,e=>Ds(t,e,!0)),yL=t=>zn(t,e=>Ds(t,e,!1)),vL=t=>zn(t,e=>Ds(t,e,!Wt(t))),wL=t=>zn(t,e=>Ds(t,e,Wt(t))),kL=t=>zn(t,e=>q.cursor(t.lineBlockAt(e.head).from)),SL=t=>zn(t,e=>q.cursor(t.lineBlockAt(e.head).to)),Mb=({state:t,dispatch:e})=>(e(rr(t,{anchor:0})),!0),Tb=({state:t,dispatch:e})=>(e(rr(t,{anchor:t.doc.length})),!0),Lb=({state:t,dispatch:e})=>(e(rr(t,{anchor:t.selection.main.anchor,head:0})),!0),Rb=({state:t,dispatch:e})=>(e(rr(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),CL=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),jL=({state:t,dispatch:e})=>{let n=Xu(t).map(({from:r,to:s})=>q.range(r,Math.min(s+1,t.doc.length)));return e(t.update({selection:q.create(n),userEvent:"select"})),!0},NL=({state:t,dispatch:e})=>{let n=ko(t.selection,r=>{let s=Ht(t),i=s.resolveStack(r.from,1);if(r.empty){let o=s.resolveStack(r.from,-1);o.node.from>=i.node.from&&o.node.to<=i.node.to&&(i=o)}for(let o=i;o;o=o.next){let{node:a}=o;if((a.from<r.from&&a.to>=r.to||a.to>r.to&&a.from<=r.from)&&o.next)return q.range(a.to,a.from)}return r});return n.eq(t.selection)?!1:(e(rr(t,n)),!0)};function gS(t,e){let{state:n}=t,r=n.selection,s=n.selection.ranges.slice();for(let i of n.selection.ranges){let o=n.doc.lineAt(i.head);if(e?o.to<t.state.doc.length:o.from>0)for(let a=i;;){let l=t.moveVertically(a,e);if(l.head<o.from||l.head>o.to){s.some(d=>d.head==l.head)||s.push(l);break}else{if(l.head==a.head)break;a=l}}}return s.length==r.ranges.length?!1:(t.dispatch(rr(n,q.create(s,s.length-1))),!0)}const PL=t=>gS(t,!1),OL=t=>gS(t,!0),EL=({state:t,dispatch:e})=>{let n=t.selection,r=null;return n.ranges.length>1?r=q.create([n.main]):n.main.empty||(r=q.create([q.cursor(n.main.head)])),r?(e(rr(t,r)),!0):!1};function Yl(t,e){if(t.state.readOnly)return!1;let n="delete.selection",{state:r}=t,s=r.changeByRange(i=>{let{from:o,to:a}=i;if(o==a){let l=e(i);l<o?(n="delete.backward",l=Ic(t,l,!1)):l>o&&(n="delete.forward",l=Ic(t,l,!0)),o=Math.min(o,l),a=Math.max(a,l)}else o=Ic(t,o,!1),a=Ic(t,a,!0);return o==a?{range:i}:{changes:{from:o,to:a},range:q.cursor(o,o<i.head?-1:1)}});return s.changes.empty?!1:(t.dispatch(r.update(s,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?ae.announce.of(r.phrase("Selection deleted")):void 0})),!0)}function Ic(t,e,n){if(t instanceof ae)for(let r of t.state.facet(ae.atomicRanges).map(s=>s(t)))r.between(e,e,(s,i)=>{s<e&&i>e&&(e=n?i:s)});return e}const xS=(t,e,n)=>Yl(t,r=>{let s=r.from,{state:i}=t,o=i.doc.lineAt(s),a,l;if(n&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(a=o.text.slice(0,s-o.from))){if(a[a.length-1]==" ")return s-1;let d=vo(a,i.tabSize),u=d%Zd(i)||Zd(i);for(let h=0;h<u&&a[a.length-1-h]==" ";h++)s--;l=s}else l=wt(o.text,s-o.from,e,e)+o.from,l==s&&o.number!=(e?i.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(l-o.from,s-o.from))&&(l=wt(o.text,l-o.from,!1,!1)+o.from);return l}),Qp=t=>xS(t,!1,!0),bS=t=>xS(t,!0,!1),yS=(t,e)=>Yl(t,n=>{let r=n.head,{state:s}=t,i=s.doc.lineAt(r),o=s.charCategorizer(r);for(let a=null;;){if(r==(e?i.to:i.from)){r==n.head&&i.number!=(e?s.doc.lines:1)&&(r+=e?1:-1);break}let l=wt(i.text,r-i.from,e)+i.from,d=i.text.slice(Math.min(r,l)-i.from,Math.max(r,l)-i.from),u=o(d);if(a!=null&&u!=a)break;(d!=" "||r!=n.head)&&(a=u),r=l}return r}),vS=t=>yS(t,!1),DL=t=>yS(t,!0),AL=t=>Yl(t,e=>{let n=t.lineBlockAt(e.head).to;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),ML=t=>Yl(t,e=>{let n=t.moveToLineBoundary(e,!1).head;return e.head>n?n:Math.max(0,e.head-1)}),TL=t=>Yl(t,e=>{let n=t.moveToLineBoundary(e,!0).head;return e.head<n?n:Math.min(t.state.doc.length,e.head+1)}),LL=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>({changes:{from:r.from,to:r.to,insert:We.of(["",""])},range:q.cursor(r.from)}));return e(t.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},RL=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=t.changeByRange(r=>{if(!r.empty||r.from==0||r.from==t.doc.length)return{range:r};let s=r.from,i=t.doc.lineAt(s),o=s==i.from?s-1:wt(i.text,s-i.from,!1)+i.from,a=s==i.to?s+1:wt(i.text,s-i.from,!0)+i.from;return{changes:{from:o,to:a,insert:t.doc.slice(s,a).append(t.doc.slice(o,s))},range:q.cursor(a)}});return n.changes.empty?!1:(e(t.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Xu(t){let e=[],n=-1;for(let r of t.selection.ranges){let s=t.doc.lineAt(r.from),i=t.doc.lineAt(r.to);if(!r.empty&&r.to==i.from&&(i=t.doc.lineAt(r.to-1)),n>=s.number){let o=e[e.length-1];o.to=i.to,o.ranges.push(r)}else e.push({from:s.from,to:i.to,ranges:[r]});n=i.number+1}return e}function wS(t,e,n){if(t.readOnly)return!1;let r=[],s=[];for(let i of Xu(t)){if(n?i.to==t.doc.length:i.from==0)continue;let o=t.doc.lineAt(n?i.to+1:i.from-1),a=o.length+1;if(n){r.push({from:i.to,to:o.to},{from:i.from,insert:o.text+t.lineBreak});for(let l of i.ranges)s.push(q.range(Math.min(t.doc.length,l.anchor+a),Math.min(t.doc.length,l.head+a)))}else{r.push({from:o.from,to:i.from},{from:i.to,insert:t.lineBreak+o.text});for(let l of i.ranges)s.push(q.range(l.anchor-a,l.head-a))}}return r.length?(e(t.update({changes:r,scrollIntoView:!0,selection:q.create(s,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const _L=({state:t,dispatch:e})=>wS(t,e,!1),IL=({state:t,dispatch:e})=>wS(t,e,!0);function kS(t,e,n){if(t.readOnly)return!1;let r=[];for(let i of Xu(t))n?r.push({from:i.from,insert:t.doc.slice(i.from,i.to)+t.lineBreak}):r.push({from:i.to,insert:t.lineBreak+t.doc.slice(i.from,i.to)});let s=t.changes(r);return e(t.update({changes:s,selection:t.selection.map(s,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const $L=({state:t,dispatch:e})=>kS(t,e,!1),BL=({state:t,dispatch:e})=>kS(t,e,!0),FL=t=>{if(t.state.readOnly)return!1;let{state:e}=t,n=e.changes(Xu(e).map(({from:s,to:i})=>(s>0?s--:i<e.doc.length&&i++,{from:s,to:i}))),r=ko(e.selection,s=>{let i;if(t.lineWrapping){let o=t.lineBlockAt(s.head),a=t.coordsAtPos(s.head,s.assoc||1);a&&(i=o.bottom+t.documentTop-a.bottom+t.defaultLineHeight/2)}return t.moveVertically(s,!0,i)}).map(n);return t.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:"delete.line"}),!0};function zL(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let n=Ht(t).resolveInner(e),r=n.childBefore(e),s=n.childAfter(e),i;return r&&s&&r.to<=e&&s.from>=e&&(i=r.type.prop(Te.closedBy))&&i.indexOf(s.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(s.from).from&&!/\S/.test(t.sliceDoc(r.to,s.from))?{from:r.to,to:s.from}:null}const _b=SS(!1),VL=SS(!0);function SS(t){return({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(s=>{let{from:i,to:o}=s,a=e.doc.lineAt(i),l=!t&&i==o&&zL(e,i);t&&(i=o=(o<=a.to?a:e.doc.lineAt(o)).to);let d=new Uu(e,{simulateBreak:i,simulateDoubleBreak:!!l}),u=ug(d,i);for(u==null&&(u=vo(/^\s*/.exec(e.doc.lineAt(i).text)[0],e.tabSize));o<a.to&&/\s/.test(a.text[o-a.from]);)o++;l?{from:i,to:o}=l:i>a.from&&i<a.from+100&&!/\S/.test(a.text.slice(0,i))&&(i=a.from);let h=["",Ia(e,u)];return l&&h.push(Ia(e,d.lineIndent(a.from,-1))),{changes:{from:i,to:o,insert:We.of(h)},range:q.cursor(i+1+h[1].length)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function gg(t,e){let n=-1;return t.changeByRange(r=>{let s=[];for(let o=r.from;o<=r.to;){let a=t.doc.lineAt(o);a.number>n&&(r.empty||r.to>a.from)&&(e(a,s,r),n=a.number),o=a.to+1}let i=t.changes(s);return{changes:s,range:q.range(i.mapPos(r.anchor,1),i.mapPos(r.head,1))}})}const HL=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let n=Object.create(null),r=new Uu(t,{overrideIndentation:i=>{let o=n[i];return o??-1}}),s=gg(t,(i,o,a)=>{let l=ug(r,i.from);if(l==null)return;/\S/.test(i.text)||(l=0);let d=/^\s*/.exec(i.text)[0],u=Ia(t,l);(d!=u||a.from<i.from+d.length)&&(n[i.from]=l,o.push({from:i.from,to:i.from+d.length,insert:u}))});return s.changes.empty||e(t.update(s,{userEvent:"indent"})),!0},CS=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(gg(t,(n,r)=>{r.push({from:n.from,insert:t.facet(Wu)})}),{userEvent:"input.indent"})),!0),jS=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(gg(t,(n,r)=>{let s=/^\s*/.exec(n.text)[0];if(!s)return;let i=vo(s,t.tabSize),o=0,a=Ia(t,Math.max(0,i-Zd(t)));for(;o<s.length&&o<a.length&&s.charCodeAt(o)==a.charCodeAt(o);)o++;r.push({from:n.from+o,to:n.from+s.length,insert:a.slice(o)})}),{userEvent:"delete.dedent"})),!0),WL=t=>(t.setTabFocusMode(),!0),UL=[{key:"Ctrl-b",run:eS,shift:cS,preventDefault:!0},{key:"Ctrl-f",run:tS,shift:dS},{key:"Ctrl-p",run:sS,shift:fS},{key:"Ctrl-n",run:iS,shift:pS},{key:"Ctrl-a",run:dL,shift:kL},{key:"Ctrl-e",run:uL,shift:SL},{key:"Ctrl-d",run:bS},{key:"Ctrl-h",run:Qp},{key:"Ctrl-k",run:AL},{key:"Ctrl-Alt-h",run:vS},{key:"Ctrl-o",run:LL},{key:"Ctrl-t",run:RL},{key:"Ctrl-v",run:Zp}],KL=[{key:"ArrowLeft",run:eS,shift:cS,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:tL,shift:pL,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:lL,shift:vL,preventDefault:!0},{key:"ArrowRight",run:tS,shift:dS,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:nL,shift:mL,preventDefault:!0},{mac:"Cmd-ArrowRight",run:cL,shift:wL,preventDefault:!0},{key:"ArrowUp",run:sS,shift:fS,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Mb,shift:Lb},{mac:"Ctrl-ArrowUp",run:Eb,shift:Db},{key:"ArrowDown",run:iS,shift:pS,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Tb,shift:Rb},{mac:"Ctrl-ArrowDown",run:Zp,shift:Ab},{key:"PageUp",run:Eb,shift:Db},{key:"PageDown",run:Zp,shift:Ab},{key:"Home",run:aL,shift:yL,preventDefault:!0},{key:"Mod-Home",run:Mb,shift:Lb},{key:"End",run:oL,shift:bL,preventDefault:!0},{key:"Mod-End",run:Tb,shift:Rb},{key:"Enter",run:_b,shift:_b},{key:"Mod-a",run:CL},{key:"Backspace",run:Qp,shift:Qp,preventDefault:!0},{key:"Delete",run:bS,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:vS,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:DL,preventDefault:!0},{mac:"Mod-Backspace",run:ML,preventDefault:!0},{mac:"Mod-Delete",run:TL,preventDefault:!0}].concat(UL.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),GL=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:sL,shift:gL},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:iL,shift:xL},{key:"Alt-ArrowUp",run:_L},{key:"Shift-Alt-ArrowUp",run:$L},{key:"Alt-ArrowDown",run:IL},{key:"Shift-Alt-ArrowDown",run:BL},{key:"Mod-Alt-ArrowUp",run:PL},{key:"Mod-Alt-ArrowDown",run:OL},{key:"Escape",run:EL},{key:"Mod-Enter",run:VL},{key:"Alt-l",mac:"Ctrl-l",run:jL},{key:"Mod-i",run:NL,preventDefault:!0},{key:"Mod-[",run:jS},{key:"Mod-]",run:CS},{key:"Mod-Alt-\\",run:HL},{key:"Shift-Mod-k",run:FL},{key:"Shift-Mod-\\",run:fL},{key:"Mod-/",run:_6},{key:"Alt-A",run:$6},{key:"Ctrl-m",mac:"Shift-Alt-m",run:WL}].concat(KL),qL={key:"Tab",run:CS,shift:jS},Ib=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class oo{constructor(e,n,r=0,s=e.length,i,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(r,s),this.bufferStart=r,this.normalize=i?a=>i(Ib(a)):Ib,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return tn(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let n=qm(e),r=this.bufferStart+this.bufferPos;this.bufferPos+=gr(e);let s=this.normalize(n);if(s.length)for(let i=0,o=r;;i++){let a=s.charCodeAt(i),l=this.match(a,o,this.bufferPos+this.bufferStart);if(i==s.length-1){if(l)return this.value=l,this;break}o==r&&i<n.length&&n.charCodeAt(i)==a&&o++}}}match(e,n,r){let s=null;for(let i=0;i<this.matches.length;i+=2){let o=this.matches[i],a=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[i+1],to:r}:(this.matches[i]++,a=!0)),a||(this.matches.splice(i,2),i-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:n,to:r}:this.matches.push(1,n)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(oo.prototype[Symbol.iterator]=function(){return this});const NS={from:-1,to:-1,match:/.*/.exec("")},xg="gm"+(/x/.unicode==null?"":"u");class PS{constructor(e,n,r,s=0,i=e.length){if(this.text=e,this.to=i,this.curLine="",this.done=!1,this.value=NS,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new OS(e,n,r,s,i);this.re=new RegExp(n,xg+(r?.ignoreCase?"i":"")),this.test=r?.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=tu(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let r=this.curLineStart+n.index,s=r+n[0].length;if(this.matchPos=tu(this.text,s+(r==s?1:0)),r==this.curLineStart+this.curLine.length&&this.nextLine(),(r<s||r>this.value.to)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Qh=new WeakMap;class Hi{constructor(e,n){this.from=e,this.text=n}get to(){return this.from+this.text.length}static get(e,n,r){let s=Qh.get(e);if(!s||s.from>=r||s.to<=n){let a=new Hi(n,e.sliceString(n,r));return Qh.set(e,a),a}if(s.from==n&&s.to==r)return s;let{text:i,from:o}=s;return o>n&&(i=e.sliceString(n,o)+i,o=n),s.to<r&&(i+=e.sliceString(s.to,r)),Qh.set(e,new Hi(o,i)),new Hi(n,i.slice(n-o,r-o))}}class OS{constructor(e,n,r,s,i){this.text=e,this.to=i,this.done=!1,this.value=NS,this.matchPos=tu(e,s),this.re=new RegExp(n,xg+(r?.ignoreCase?"i":"")),this.test=r?.test,this.flat=Hi.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==e&&(this.re.lastIndex=e+1,n=this.re.exec(this.flat.text)),n){let r=this.flat.from+n.index,s=r+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(r,s,n)))return this.value={from:r,to:s,match:n},this.matchPos=tu(this.text,s+(r==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Hi.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(PS.prototype[Symbol.iterator]=OS.prototype[Symbol.iterator]=function(){return this});function YL(t){try{return new RegExp(t,xg),!0}catch{return!1}}function tu(t,e){if(e>=t.length)return e;let n=t.lineAt(e),r;for(;e<n.to&&(r=n.text.charCodeAt(e-n.from))>=56320&&r<57344;)e++;return e}function Jp(t){let e=String(t.state.doc.lineAt(t.state.selection.main.head).number),n=Ke("input",{class:"cm-textfield",name:"line",value:e}),r=Ke("form",{class:"cm-gotoLine",onkeydown:i=>{i.keyCode==27?(i.preventDefault(),t.dispatch({effects:ha.of(!1)}),t.focus()):i.keyCode==13&&(i.preventDefault(),s())},onsubmit:i=>{i.preventDefault(),s()}},Ke("label",t.state.phrase("Go to line"),": ",n)," ",Ke("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),Ke("button",{name:"close",onclick:()=>{t.dispatch({effects:ha.of(!1)}),t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["×"]));function s(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.value);if(!i)return;let{state:o}=t,a=o.doc.lineAt(o.selection.main.head),[,l,d,u,h]=i,f=u?+u.slice(1):0,p=d?+d:a.number;if(d&&h){let b=p/100;l&&(b=b*(l=="-"?-1:1)+a.number/o.doc.lines),p=Math.round(o.doc.lines*b)}else d&&l&&(p=p*(l=="-"?-1:1)+a.number);let m=o.doc.line(Math.max(1,Math.min(o.doc.lines,p))),x=q.cursor(m.from+Math.max(0,Math.min(f,m.length)));t.dispatch({effects:[ha.of(!1),ae.scrollIntoView(x.from,{y:"center"})],selection:x}),t.focus()}return{dom:r}}const ha=Ee.define(),$b=Bt.define({create(){return!0},update(t,e){for(let n of e.effects)n.is(ha)&&(t=n.value);return t},provide:t=>_a.from(t,e=>e?Jp:null)}),XL=t=>{let e=Ra(t,Jp);if(!e){let n=[ha.of(!0)];t.state.field($b,!1)==null&&n.push(Ee.appendConfig.of([$b,ZL])),t.dispatch({effects:n}),e=Ra(t,Jp)}return e&&e.dom.querySelector("input").select(),!0},ZL=ae.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),QL={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},JL=me.define({combine(t){return Or(t,QL,{highlightWordAroundCursor:(e,n)=>e||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function e7(t){return[i7,s7]}const t7=Ce.mark({class:"cm-selectionMatch"}),n7=Ce.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Bb(t,e,n,r){return(n==0||t(e.sliceDoc(n-1,n))!=Je.Word)&&(r==e.doc.length||t(e.sliceDoc(r,r+1))!=Je.Word)}function r7(t,e,n,r){return t(e.sliceDoc(n,n+1))==Je.Word&&t(e.sliceDoc(r-1,r))==Je.Word}const s7=ut.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(JL),{state:n}=t,r=n.selection;if(r.ranges.length>1)return Ce.none;let s=r.main,i,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return Ce.none;let l=n.wordAt(s.head);if(!l)return Ce.none;o=n.charCategorizer(s.head),i=n.sliceDoc(l.from,l.to)}else{let l=s.to-s.from;if(l<e.minSelectionLength||l>200)return Ce.none;if(e.wholeWords){if(i=n.sliceDoc(s.from,s.to),o=n.charCategorizer(s.head),!(Bb(o,n,s.from,s.to)&&r7(o,n,s.from,s.to)))return Ce.none}else if(i=n.sliceDoc(s.from,s.to),!i)return Ce.none}let a=[];for(let l of t.visibleRanges){let d=new oo(n.doc,i,l.from,l.to);for(;!d.next().done;){let{from:u,to:h}=d.value;if((!o||Bb(o,n,u,h))&&(s.empty&&u<=s.from&&h>=s.to?a.push(n7.range(u,h)):(u>=s.to||h<=s.from)&&a.push(t7.range(u,h)),a.length>e.maxMatches))return Ce.none}}return Ce.set(a)}},{decorations:t=>t.decorations}),i7=ae.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),o7=({state:t,dispatch:e})=>{let{selection:n}=t,r=q.create(n.ranges.map(s=>t.wordAt(s.head)||q.cursor(s.head)),n.mainIndex);return r.eq(n)?!1:(e(t.update({selection:r})),!0)};function a7(t,e){let{main:n,ranges:r}=t.selection,s=t.wordAt(n.head),i=s&&s.from==n.from&&s.to==n.to;for(let o=!1,a=new oo(t.doc,e,r[r.length-1].to);;)if(a.next(),a.done){if(o)return null;a=new oo(t.doc,e,0,Math.max(0,r[r.length-1].from-1)),o=!0}else{if(o&&r.some(l=>l.from==a.value.from))continue;if(i){let l=t.wordAt(a.value.from);if(!l||l.from!=a.value.from||l.to!=a.value.to)continue}return a.value}}const l7=({state:t,dispatch:e})=>{let{ranges:n}=t.selection;if(n.some(i=>i.from===i.to))return o7({state:t,dispatch:e});let r=t.sliceDoc(n[0].from,n[0].to);if(t.selection.ranges.some(i=>t.sliceDoc(i.from,i.to)!=r))return!1;let s=a7(t,r);return s?(e(t.update({selection:t.selection.addRange(q.range(s.from,s.to),!1),effects:ae.scrollIntoView(s.to)})),!0):!1},So=me.define({combine(t){return Or(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new v7(e),scrollToMatch:e=>ae.scrollIntoView(e)})}});class ES{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||YL(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(n,r)=>r=="n"?`
270
- `:r=="r"?"\r":r=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new h7(this):new d7(this)}getCursor(e,n=0,r){let s=e.doc?e:Ie.create({doc:e});return r==null&&(r=s.doc.length),this.regexp?Pi(this,s,n,r):Ni(this,s,n,r)}}class DS{constructor(e){this.spec=e}}function Ni(t,e,n,r){return new oo(e.doc,t.unquoted,n,r,t.caseSensitive?void 0:s=>s.toLowerCase(),t.wholeWord?c7(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function c7(t,e){return(n,r,s,i)=>((i>n||i+s.length<r)&&(i=Math.max(0,n-2),s=t.sliceString(i,Math.min(t.length,r+2))),(e(nu(s,n-i))!=Je.Word||e(ru(s,n-i))!=Je.Word)&&(e(ru(s,r-i))!=Je.Word||e(nu(s,r-i))!=Je.Word))}class d7 extends DS{constructor(e){super(e)}nextMatch(e,n,r){let s=Ni(this.spec,e,r,e.doc.length).nextOverlapping();if(s.done){let i=Math.min(e.doc.length,n+this.spec.unquoted.length);s=Ni(this.spec,e,0,i).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==r?null:s.value}prevMatchInRange(e,n,r){for(let s=r;;){let i=Math.max(n,s-1e4-this.spec.unquoted.length),o=Ni(this.spec,e,i,s),a=null;for(;!o.nextOverlapping().done;)a=o.value;if(a)return a;if(i==n)return null;s-=1e4}}prevMatch(e,n,r){let s=this.prevMatchInRange(e,0,n);return s||(s=this.prevMatchInRange(e,Math.max(0,r-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=n||s.to!=r)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let r=Ni(this.spec,e,0,e.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(e,n,r,s){let i=Ni(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)s(i.value.from,i.value.to)}}function Pi(t,e,n,r){return new PS(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?u7(e.charCategorizer(e.selection.main.head)):void 0},n,r)}function nu(t,e){return t.slice(wt(t,e,!1),e)}function ru(t,e){return t.slice(e,wt(t,e))}function u7(t){return(e,n,r)=>!r[0].length||(t(nu(r.input,r.index))!=Je.Word||t(ru(r.input,r.index))!=Je.Word)&&(t(ru(r.input,r.index+r[0].length))!=Je.Word||t(nu(r.input,r.index+r[0].length))!=Je.Word)}class h7 extends DS{nextMatch(e,n,r){let s=Pi(this.spec,e,r,e.doc.length).next();return s.done&&(s=Pi(this.spec,e,0,n).next()),s.done?null:s.value}prevMatchInRange(e,n,r){for(let s=1;;s++){let i=Math.max(n,r-s*1e4),o=Pi(this.spec,e,i,r),a=null;for(;!o.next().done;)a=o.value;if(a&&(i==n||a.from>i+10))return a;if(i==n)return null}}prevMatch(e,n,r){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return e.match[0];if(r=="$")return"$";for(let s=r.length;s>0;s--){let i=+r.slice(0,s);if(i>0&&i<e.match.length)return e.match[i]+r.slice(s)}return n})}matchAll(e,n){let r=Pi(this.spec,e,0,e.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(e,n,r,s){let i=Pi(this.spec,e,Math.max(0,n-250),Math.min(r+250,e.doc.length));for(;!i.next().done;)s(i.value.from,i.value.to)}}const $a=Ee.define(),bg=Ee.define(),xs=Bt.define({create(t){return new Jh(em(t).create(),null)},update(t,e){for(let n of e.effects)n.is($a)?t=new Jh(n.value.create(),t.panel):n.is(bg)&&(t=new Jh(t.query,n.value?yg:null));return t},provide:t=>_a.from(t,e=>e.panel)});class Jh{constructor(e,n){this.query=e,this.panel=n}}const f7=Ce.mark({class:"cm-searchMatch"}),p7=Ce.mark({class:"cm-searchMatch cm-searchMatch-selected"}),m7=ut.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(xs))}update(t){let e=t.state.field(xs);(e!=t.startState.field(xs)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Ce.none;let{view:n}=this,r=new Ur;for(let s=0,i=n.visibleRanges,o=i.length;s<o;s++){let{from:a,to:l}=i[s];for(;s<o-1&&l>i[s+1].from-2*250;)l=i[++s].to;t.highlight(n.state,a,l,(d,u)=>{let h=n.state.selection.ranges.some(f=>f.from==d&&f.to==u);r.add(d,u,h?p7:f7)})}return r.finish()}},{decorations:t=>t.decorations});function Xl(t){return e=>{let n=e.state.field(xs,!1);return n&&n.query.spec.valid?t(e,n):TS(e)}}const su=Xl((t,{query:e})=>{let{to:n}=t.state.selection.main,r=e.nextMatch(t.state,n,n);if(!r)return!1;let s=q.single(r.from,r.to),i=t.state.facet(So);return t.dispatch({selection:s,effects:[vg(t,r),i.scrollToMatch(s.main,t)],userEvent:"select.search"}),MS(t),!0}),iu=Xl((t,{query:e})=>{let{state:n}=t,{from:r}=n.selection.main,s=e.prevMatch(n,r,r);if(!s)return!1;let i=q.single(s.from,s.to),o=t.state.facet(So);return t.dispatch({selection:i,effects:[vg(t,s),o.scrollToMatch(i.main,t)],userEvent:"select.search"}),MS(t),!0}),g7=Xl((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:q.create(n.map(r=>q.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),x7=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:s}=n.main,i=[],o=0;for(let a=new oo(t.doc,t.sliceDoc(r,s));!a.next().done;){if(i.length>1e3)return!1;a.value.from==r&&(o=i.length),i.push(q.range(a.value.from,a.value.to))}return e(t.update({selection:q.create(i,o),userEvent:"select.search.matches"})),!0},Fb=Xl((t,{query:e})=>{let{state:n}=t,{from:r,to:s}=n.selection.main;if(n.readOnly)return!1;let i=e.nextMatch(n,r,r);if(!i)return!1;let o=i,a=[],l,d,u=[];o.from==r&&o.to==s&&(d=n.toText(e.getReplacement(o)),a.push({from:o.from,to:o.to,insert:d}),o=e.nextMatch(n,o.from,o.to),u.push(ae.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+".")));let h=t.state.changes(a);return o&&(l=q.single(o.from,o.to).map(h),u.push(vg(t,o)),u.push(n.facet(So).scrollToMatch(l.main,t))),t.dispatch({changes:h,selection:l,effects:u,userEvent:"input.replace"}),!0}),b7=Xl((t,{query:e})=>{if(t.state.readOnly)return!1;let n=e.matchAll(t.state,1e9).map(s=>{let{from:i,to:o}=s;return{from:i,to:o,insert:e.getReplacement(s)}});if(!n.length)return!1;let r=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:ae.announce.of(r),userEvent:"input.replace.all"}),!0});function yg(t){return t.state.facet(So).createPanel(t)}function em(t,e){var n,r,s,i,o;let a=t.selection.main,l=a.empty||a.to>a.from+100?"":t.sliceDoc(a.from,a.to);if(e&&!l)return e;let d=t.facet(So);return new ES({search:((n=e?.literal)!==null&&n!==void 0?n:d.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:(r=e?.caseSensitive)!==null&&r!==void 0?r:d.caseSensitive,literal:(s=e?.literal)!==null&&s!==void 0?s:d.literal,regexp:(i=e?.regexp)!==null&&i!==void 0?i:d.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:d.wholeWord})}function AS(t){let e=Ra(t,yg);return e&&e.dom.querySelector("[main-field]")}function MS(t){let e=AS(t);e&&e==t.root.activeElement&&e.select()}const TS=t=>{let e=t.state.field(xs,!1);if(e&&e.panel){let n=AS(t);if(n&&n!=t.root.activeElement){let r=em(t.state,e.query.spec);r.valid&&t.dispatch({effects:$a.of(r)}),n.focus(),n.select()}}else t.dispatch({effects:[bg.of(!0),e?$a.of(em(t.state,e.query.spec)):Ee.appendConfig.of(k7)]});return!0},LS=t=>{let e=t.state.field(xs,!1);if(!e||!e.panel)return!1;let n=Ra(t,yg);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:bg.of(!1)}),!0},y7=[{key:"Mod-f",run:TS,scope:"editor search-panel"},{key:"F3",run:su,shift:iu,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:su,shift:iu,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:LS,scope:"editor search-panel"},{key:"Mod-Shift-l",run:x7},{key:"Mod-Alt-g",run:XL},{key:"Mod-d",run:l7,preventDefault:!0}];class v7{constructor(e){this.view=e;let n=this.query=e.state.field(xs).query.spec;this.commit=this.commit.bind(this),this.searchField=Ke("input",{value:n.search,placeholder:un(e,"Find"),"aria-label":un(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ke("input",{value:n.replace,placeholder:un(e,"Replace"),"aria-label":un(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Ke("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Ke("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Ke("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(s,i,o){return Ke("button",{class:"cm-button",name:s,onclick:i,type:"button"},o)}this.dom=Ke("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,r("next",()=>su(e),[un(e,"next")]),r("prev",()=>iu(e),[un(e,"previous")]),r("select",()=>g7(e),[un(e,"all")]),Ke("label",null,[this.caseField,un(e,"match case")]),Ke("label",null,[this.reField,un(e,"regexp")]),Ke("label",null,[this.wordField,un(e,"by word")]),...e.state.readOnly?[]:[Ke("br"),this.replaceField,r("replace",()=>Fb(e),[un(e,"replace")]),r("replaceAll",()=>b7(e),[un(e,"replace all")])],Ke("button",{name:"close",onclick:()=>LS(e),"aria-label":un(e,"close"),type:"button"},["×"])])}commit(){let e=new ES({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:$a.of(e)}))}keydown(e){$M(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?iu:su)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Fb(this.view))}update(e){for(let n of e.transactions)for(let r of n.effects)r.is($a)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(So).top}}function un(t,e){return t.state.phrase(e)}const $c=30,Bc=/[\s\.,:;?!]/;function vg(t,{from:e,to:n}){let r=t.state.doc.lineAt(e),s=t.state.doc.lineAt(n).to,i=Math.max(r.from,e-$c),o=Math.min(s,n+$c),a=t.state.sliceDoc(i,o);if(i!=r.from){for(let l=0;l<$c;l++)if(!Bc.test(a[l+1])&&Bc.test(a[l])){a=a.slice(l);break}}if(o!=s){for(let l=a.length-1;l>a.length-$c;l--)if(!Bc.test(a[l-1])&&Bc.test(a[l])){a=a.slice(0,l);break}}return ae.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${r.number}.`)}const w7=ae.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),k7=[xs,hi.low(m7),w7];class RS{constructor(e,n,r,s){this.state=e,this.pos=n,this.explicit=r,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let n=Ht(this.state).resolveInner(this.pos,-1);for(;n&&e.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(e){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),s=n.text.slice(r-n.from,this.pos-n.from),i=s.search(_S(e,!1));return i<0?null:{from:r+i,to:this.pos,text:s.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,n,r){e=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function zb(t){let e=Object.keys(t).join(""),n=/\w/.test(e);return n&&(e=e.replace(/\w/g,"")),`[${n?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function S7(t){let e=Object.create(null),n=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let i=1;i<s.length;i++)n[s[i]]=!0}let r=zb(e)+zb(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function C7(t){let e=t.map(s=>typeof s=="string"?{label:s}:s),[n,r]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:S7(e);return s=>{let i=s.matchBefore(r);return i||s.explicit?{from:i?i.from:s.pos,options:e,validFor:n}:null}}class Vb{constructor(e,n,r,s){this.completion=e,this.source=n,this.match=r,this.score=s}}function Qs(t){return t.selection.main.from}function _S(t,e){var n;let{source:r}=t,s=e&&r[0]!="^",i=r[r.length-1]!="$";return!s&&!i?t:new RegExp(`${s?"^":""}(?:${r})${i?"$":""}`,(n=t.flags)!==null&&n!==void 0?n:t.ignoreCase?"i":"")}const IS=Pr.define();function j7(t,e,n,r){let{main:s}=t.selection,i=n-s.from,o=r-s.from;return{...t.changeByRange(a=>{if(a!=s&&n!=r&&t.sliceDoc(a.from+i,a.from+o)!=t.sliceDoc(n,r))return{range:a};let l=t.toText(e);return{changes:{from:a.from+i,to:r==s.from?a.to:a.from+o,insert:l},range:q.cursor(a.from+i+l.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Hb=new WeakMap;function N7(t){if(!Array.isArray(t))return t;let e=Hb.get(t);return e||Hb.set(t,e=C7(t)),e}const ou=Ee.define(),Ba=Ee.define();class P7{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<e.length;){let r=tn(e,n),s=gr(r);this.chars.push(r);let i=e.slice(n,n+s),o=i.toUpperCase();this.folded.push(tn(o==i?i.toLowerCase():o,0)),n+=s}this.astral=e.length!=this.chars.length}ret(e,n){return this.score=e,this.matched=n,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:n,folded:r,any:s,precise:i,byWord:o}=this;if(n.length==1){let w=tn(e,0),v=gr(w),k=v==e.length?0:-100;if(w!=n[0])if(w==r[0])k+=-200;else return null;return this.ret(k,[0,v])}let a=e.indexOf(this.pattern);if(a==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let l=n.length,d=0;if(a<0){for(let w=0,v=Math.min(e.length,200);w<v&&d<l;){let k=tn(e,w);(k==n[d]||k==r[d])&&(s[d++]=w),w+=gr(k)}if(d<l)return null}let u=0,h=0,f=!1,p=0,m=-1,x=-1,b=/[a-z]/.test(e),y=!0;for(let w=0,v=Math.min(e.length,200),k=0;w<v&&h<l;){let C=tn(e,w);a<0&&(u<l&&C==n[u]&&(i[u++]=w),p<l&&(C==n[p]||C==r[p]?(p==0&&(m=w),x=w+1,p++):p=0));let j,S=C<255?C>=48&&C<=57||C>=97&&C<=122?2:C>=65&&C<=90?1:0:(j=qm(C))!=j.toLowerCase()?1:j!=j.toUpperCase()?2:0;(!w||S==1&&b||k==0&&S!=0)&&(n[h]==C||r[h]==C&&(f=!0)?o[h++]=w:o.length&&(y=!1)),k=S,w+=gr(C)}return h==l&&o[0]==0&&y?this.result(-100+(f?-200:0),o,e):p==l&&m==0?this.ret(-200-e.length+(x==e.length?0:-100),[0,x]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):p==l?this.ret(-900-e.length,[m,x]):h==l?this.result(-100+(f?-200:0)+-700+(y?0:-1100),o,e):n.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,n,r){let s=[],i=0;for(let o of n){let a=o+(this.astral?gr(tn(r,o)):1);i&&s[i-1]==o?s[i-1]=a:(s[i++]=o,s[i++]=a)}return this.ret(e-r.length,s)}}class O7{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let n=e.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(e.length==this.pattern.length?0:-100),this)}}const Pt=me.define({combine(t){return Or(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:E7,filterStrict:!1,compareCompletions:(e,n)=>(e.sortText||e.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,n)=>e&&n,closeOnBlur:(e,n)=>e&&n,icons:(e,n)=>e&&n,tooltipClass:(e,n)=>r=>Wb(e(r),n(r)),optionClass:(e,n)=>r=>Wb(e(r),n(r)),addToOptions:(e,n)=>e.concat(n),filterStrict:(e,n)=>e||n})}});function Wb(t,e){return t?e?t+" "+e:t:e}function E7(t,e,n,r,s,i){let o=t.textDirection==Ye.RTL,a=o,l=!1,d="top",u,h,f=e.left-s.left,p=s.right-e.right,m=r.right-r.left,x=r.bottom-r.top;if(a&&f<Math.min(m,p)?a=!1:!a&&p<Math.min(m,f)&&(a=!0),m<=(a?f:p))u=Math.max(s.top,Math.min(n.top,s.bottom-x))-e.top,h=Math.min(400,a?f:p);else{l=!0,h=Math.min(400,(o?e.right:s.right-e.left)-30);let w=s.bottom-e.bottom;w>=x||w>e.top?u=n.bottom-e.top:(d="bottom",u=e.bottom-n.top)}let b=(e.bottom-e.top)/i.offsetHeight,y=(e.right-e.left)/i.offsetWidth;return{style:`${d}: ${u/b}px; max-width: ${h/y}px`,class:"cm-completionInfo-"+(l?o?"left-narrow":"right-narrow":a?"left":"right")}}function D7(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),r.setAttribute("aria-hidden","true"),r},position:20}),e.push({render(n,r,s,i){let o=document.createElement("span");o.className="cm-completionLabel";let a=n.displayLabel||n.label,l=0;for(let d=0;d<i.length;){let u=i[d++],h=i[d++];u>l&&o.appendChild(document.createTextNode(a.slice(l,u)));let f=o.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(a.slice(u,h))),f.className="cm-completionMatchedText",l=h}return l<a.length&&o.appendChild(document.createTextNode(a.slice(l))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),e.sort((n,r)=>n.position-r.position).map(n=>n.render)}function ef(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let s=Math.floor(e/n);return{from:s*n,to:(s+1)*n}}let r=Math.floor((t-e)/n);return{from:t-(r+1)*n,to:t-r*n}}class A7{constructor(e,n,r){this.view=e,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:l=>this.placeInfo(l),key:this},this.space=null,this.currentClass="";let s=e.state.field(n),{options:i,selected:o}=s.open,a=e.state.facet(Pt);this.optionContent=D7(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=ef(i.length,o,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",l=>{let{options:d}=e.state.field(n).open;for(let u=l.target,h;u&&u!=this.dom;u=u.parentNode)if(u.nodeName=="LI"&&(h=/-(\d+)$/.exec(u.id))&&+h[1]<d.length){this.applyCompletion(e,d[+h[1]]),l.preventDefault();return}}),this.dom.addEventListener("focusout",l=>{let d=e.state.field(this.stateField,!1);d&&d.tooltip&&e.state.facet(Pt).closeOnBlur&&l.relatedTarget!=e.contentDOM&&e.dispatch({effects:Ba.of(null)})}),this.showOptions(i,s.id)}mount(){this.updateSel()}showOptions(e,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var n;let r=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),r!=s){let{options:i,selected:o,disabled:a}=r.open;(!s.open||s.open.options!=i)&&(this.range=ef(i.length,o,e.state.facet(Pt).maxRenderedOptions),this.showOptions(i,r.id)),this.updateSel(),a!=((n=s.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let n=this.tooltipClass(e);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),n=e.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=ef(n.options.length,n.selected,this.view.state.facet(Pt).maxRenderedOptions),this.showOptions(n.options,e.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:s}=n.options[n.selected],{info:i}=s;if(!i)return;let o=typeof i=="string"?document.createTextNode(i):i(s);if(!o)return;"then"in o?o.then(a=>{a&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(a,s)}).catch(a=>sn(this.view.state,a,"completion info")):(this.addInfoPane(o,s),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)r.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:i}=e;r.appendChild(s),this.infoDestroy=i||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let n=null;for(let r=this.list.firstChild,s=this.range.from;r;r=r.nextSibling,s++)r.nodeName!="LI"||!r.id?s--:s==e?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&T7(this.list,n),n}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),i=this.space;if(!i){let o=this.dom.ownerDocument.documentElement;i={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(i.bottom,n.bottom)-10||s.bottom<Math.max(i.top,n.top)+10?null:this.view.state.facet(Pt).positionInfo(this.view,n,s,r,i,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,n,r){const s=document.createElement("ul");s.id=n,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let i=null;for(let o=r.from;o<r.to;o++){let{completion:a,match:l}=e[o],{section:d}=a;if(d){let f=typeof d=="string"?d:d.name;if(f!=i&&(o>r.from||r.from==0))if(i=f,typeof d!="string"&&d.header)s.appendChild(d.header(d));else{let p=s.appendChild(document.createElement("completion-section"));p.textContent=f}}const u=s.appendChild(document.createElement("li"));u.id=n+"-"+o,u.setAttribute("role","option");let h=this.optionClass(a);h&&(u.className=h);for(let f of this.optionContent){let p=f(a,this.view.state,this.view,l);p&&u.appendChild(p)}}return r.from&&s.classList.add("cm-completionListIncompleteTop"),r.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function M7(t,e){return n=>new A7(n,t,e)}function T7(t,e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),s=n.height/t.offsetHeight;r.top<n.top?t.scrollTop-=(n.top-r.top)/s:r.bottom>n.bottom&&(t.scrollTop+=(r.bottom-n.bottom)/s)}function Ub(t){return(t.boost||0)*100+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}function L7(t,e){let n=[],r=null,s=null,i=u=>{n.push(u);let{section:h}=u.completion;if(h){r||(r=[]);let f=typeof h=="string"?h:h.name;r.some(p=>p.name==f)||r.push(typeof h=="string"?{name:f}:h)}},o=e.facet(Pt);for(let u of t)if(u.hasResult()){let h=u.result.getMatch;if(u.result.filter===!1)for(let f of u.result.options)i(new Vb(f,u.source,h?h(f):[],1e9-n.length));else{let f=e.sliceDoc(u.from,u.to),p,m=o.filterStrict?new O7(f):new P7(f);for(let x of u.result.options)if(p=m.match(x.label)){let b=x.displayLabel?h?h(x,p.matched):[]:p.matched,y=p.score+(x.boost||0);if(i(new Vb(x,u.source,b,y)),typeof x.section=="object"&&x.section.rank==="dynamic"){let{name:w}=x.section;s||(s=Object.create(null)),s[w]=Math.max(y,s[w]||-1e9)}}}}if(r){let u=Object.create(null),h=0,f=(p,m)=>(p.rank==="dynamic"&&m.rank==="dynamic"?s[m.name]-s[p.name]:0)||(typeof p.rank=="number"?p.rank:1e9)-(typeof m.rank=="number"?m.rank:1e9)||(p.name<m.name?-1:1);for(let p of r.sort(f))h-=1e5,u[p.name]=h;for(let p of n){let{section:m}=p.completion;m&&(p.score+=u[typeof m=="string"?m:m.name])}}let a=[],l=null,d=o.compareCompletions;for(let u of n.sort((h,f)=>f.score-h.score||d(h.completion,f.completion))){let h=u.completion;!l||l.label!=h.label||l.detail!=h.detail||l.type!=null&&h.type!=null&&l.type!=h.type||l.apply!=h.apply||l.boost!=h.boost?a.push(u):Ub(u.completion)>Ub(l)&&(a[a.length-1]=u),l=u.completion}return a}class Mi{constructor(e,n,r,s,i,o){this.options=e,this.attrs=n,this.tooltip=r,this.timestamp=s,this.selected=i,this.disabled=o}setSelected(e,n){return e==this.selected||e>=this.options.length?this:new Mi(this.options,Kb(n,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,n,r,s,i,o){if(s&&!o&&e.some(d=>d.isPending))return s.setDisabled();let a=L7(e,n);if(!a.length)return s&&e.some(d=>d.isPending)?s.setDisabled():null;let l=n.facet(Pt).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let d=s.options[s.selected].completion;for(let u=0;u<a.length;u++)if(a[u].completion==d){l=u;break}}return new Mi(a,Kb(r,l),{pos:e.reduce((d,u)=>u.hasResult()?Math.min(d,u.from):d,1e8),create:F7,above:i.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(e){return new Mi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Mi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class au{constructor(e,n,r){this.active=e,this.id=n,this.open=r}static start(){return new au($7,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:n}=e,r=n.facet(Pt),i=(r.override||n.languageDataAt("autocomplete",Qs(n)).map(N7)).map(l=>(this.active.find(u=>u.source==l)||new Tn(l,this.active.some(u=>u.state!=0)?1:0)).update(e,r));i.length==this.active.length&&i.every((l,d)=>l==this.active[d])&&(i=this.active);let o=this.open,a=e.effects.some(l=>l.is(wg));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||i.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!R7(i,this.active)||a?o=Mi.build(i,n,this.id,o,r,a):o&&o.disabled&&!i.some(l=>l.isPending)&&(o=null),!o&&i.every(l=>!l.isPending)&&i.some(l=>l.hasResult())&&(i=i.map(l=>l.hasResult()?new Tn(l.source,0):l));for(let l of e.effects)l.is(BS)&&(o=o&&o.setSelected(l.value,this.id));return i==this.active&&o==this.open?this:new au(i,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?_7:I7}}function R7(t,e){if(t==e)return!0;for(let n=0,r=0;;){for(;n<t.length&&!t[n].hasResult();)n++;for(;r<e.length&&!e[r].hasResult();)r++;let s=n==t.length,i=r==e.length;if(s||i)return s==i;if(t[n++].result!=e[r++].result)return!1}}const _7={"aria-autocomplete":"list"},I7={};function Kb(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const $7=[];function $S(t,e){if(t.isUserEvent("input.complete")){let r=t.annotation(IS);if(r&&e.activateOnCompletion(r))return 12}let n=t.isUserEvent("input.type");return n&&e.activateOnTyping?5:n?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class Tn{constructor(e,n,r=!1){this.source=e,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(e,n){let r=$S(e,n),s=this;(r&8||r&16&&this.touches(e))&&(s=new Tn(s.source,0)),r&4&&s.state==0&&(s=new Tn(this.source,1)),s=s.updateFor(e,r);for(let i of e.effects)if(i.is(ou))s=new Tn(s.source,1,i.value);else if(i.is(Ba))s=new Tn(s.source,0);else if(i.is(wg))for(let o of i.value)o.source==s.source&&(s=o);return s}updateFor(e,n){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Qs(e.state))}}class Wi extends Tn{constructor(e,n,r,s,i,o){super(e,3,n),this.limit=r,this.result=s,this.from=i,this.to=o}hasResult(){return!0}updateFor(e,n){var r;if(!(n&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let i=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),a=Qs(e.state);if(a>o||!s||n&2&&(Qs(e.startState)==this.from||a<this.limit))return new Tn(this.source,n&4?1:0);let l=e.changes.mapPos(this.limit);return B7(s.validFor,e.state,i,o)?new Wi(this.source,this.explicit,l,s,i,o):s.update&&(s=s.update(s,i,o,new RS(e.state,a,!1)))?new Wi(this.source,this.explicit,l,s,s.from,(r=s.to)!==null&&r!==void 0?r:Qs(e.state)):new Tn(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new Wi(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Tn(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function B7(t,e,n,r){if(!t)return!1;let s=e.sliceDoc(n,r);return typeof t=="function"?t(s,n,r,e):_S(t,!0).test(s)}const wg=Ee.define({map(t,e){return t.map(n=>n.map(e))}}),BS=Ee.define(),nn=Bt.define({create(){return au.start()},update(t,e){return t.update(e)},provide:t=>[dg.from(t,e=>e.tooltip),ae.contentAttributes.from(t,e=>e.attrs)]});function kg(t,e){const n=e.completion.apply||e.completion.label;let r=t.state.field(nn).active.find(s=>s.source==e.source);return r instanceof Wi?(typeof n=="string"?t.dispatch({...j7(t.state,n,r.from,r.to),annotations:IS.of(e.completion)}):n(t,e.completion,r.from,r.to),!0):!1}const F7=M7(nn,kg);function Fc(t,e="option"){return n=>{let r=n.state.field(nn,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(Pt).interactionDelay)return!1;let s=1,i;e=="page"&&(i=O2(n,r.open.tooltip))&&(s=Math.max(2,Math.floor(i.dom.offsetHeight/i.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,a=r.open.selected>-1?r.open.selected+s*(t?1:-1):t?0:o-1;return a<0?a=e=="page"?0:o-1:a>=o&&(a=e=="page"?o-1:0),n.dispatch({effects:BS.of(a)}),!0}}const z7=t=>{let e=t.state.field(nn,!1);return t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(Pt).interactionDelay?!1:kg(t,e.open.options[e.open.selected])},tf=t=>t.state.field(nn,!1)?(t.dispatch({effects:ou.of(!0)}),!0):!1,V7=t=>{let e=t.state.field(nn,!1);return!e||!e.active.some(n=>n.state!=0)?!1:(t.dispatch({effects:Ba.of(null)}),!0)};class H7{constructor(e,n){this.active=e,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const W7=50,U7=1e3,K7=ut.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(nn).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(nn),n=t.state.facet(Pt);if(!t.selectionSet&&!t.docChanged&&t.startState.field(nn)==e)return;let r=t.transactions.some(i=>{let o=$S(i,n);return o&8||(i.selection||i.docChanged)&&!(o&3)});for(let i=0;i<this.running.length;i++){let o=this.running[i];if(r||o.context.abortOnDocChange&&t.docChanged||o.updates.length+t.transactions.length>W7&&Date.now()-o.time>U7){for(let a of o.context.abortListeners)try{a()}catch(l){sn(this.view.state,l)}o.context.abortListeners=null,this.running.splice(i--,1)}else o.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(i=>i.effects.some(o=>o.is(ou)))&&(this.pendingStart=!0);let s=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(i=>i.isPending&&!this.running.some(o=>o.active.source==i.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let i of t.transactions)i.isUserEvent("input.type")?this.composing=2:this.composing==2&&i.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(nn);for(let n of e.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pt).updateSyncTime))}startQuery(t){let{state:e}=this.view,n=Qs(e),r=new RS(e,n,t.explicit,this.view),s=new H7(t,r);this.running.push(s),Promise.resolve(t.source(r)).then(i=>{s.context.aborted||(s.done=i||null,this.scheduleAccept())},i=>{this.view.dispatch({effects:Ba.of(null)}),sn(this.view.state,i)})}scheduleAccept(){this.running.every(t=>t.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pt).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(Pt),r=this.view.state.field(nn);for(let s=0;s<this.running.length;s++){let i=this.running[s];if(i.done===void 0)continue;if(this.running.splice(s--,1),i.done){let a=Qs(i.updates.length?i.updates[0].startState:this.view.state),l=Math.min(a,i.done.from+(i.active.explicit?0:1)),d=new Wi(i.active.source,i.active.explicit,l,i.done,i.done.from,(t=i.done.to)!==null&&t!==void 0?t:a);for(let u of i.updates)d=d.update(u,n);if(d.hasResult()){e.push(d);continue}}let o=r.active.find(a=>a.source==i.active.source);if(o&&o.isPending)if(i.done==null){let a=new Tn(i.active.source,0);for(let l of i.updates)a=a.update(l,n);a.isPending||e.push(a)}else this.startQuery(o)}(e.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:wg.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(nn,!1);if(e&&e.tooltip&&this.view.state.facet(Pt).closeOnBlur){let n=e.open&&O2(this.view,e.open.tooltip);(!n||!n.dom.contains(t.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Ba.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:ou.of(!1)}),20),this.composing=0}}}),G7=typeof navigator=="object"&&/Win/.test(navigator.platform),q7=hi.highest(ae.domEventHandlers({keydown(t,e){let n=e.state.field(nn,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||t.key.length>1||t.ctrlKey&&!(G7&&t.altKey)||t.metaKey)return!1;let r=n.open.options[n.open.selected],s=n.active.find(o=>o.source==r.source),i=r.completion.commitCharacters||s.result.commitCharacters;return i&&i.indexOf(t.key)>-1&&kg(e,r),!1}})),Y7=ae.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),Fa={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Ys=Ee.define({map(t,e){let n=e.mapPos(t,-1,Gt.TrackAfter);return n??void 0}}),Sg=new class extends ks{};Sg.startSide=1;Sg.endSide=-1;const FS=Bt.define({create(){return Le.empty},update(t,e){if(t=t.map(e.changes),e.selection){let n=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of e.effects)n.is(Ys)&&(t=t.update({add:[Sg.range(n.value,n.value+1)]}));return t}});function X7(){return[Q7,FS]}const nf="()[]{}<>«»»«[]{}";function zS(t){for(let e=0;e<nf.length;e+=2)if(nf.charCodeAt(e)==t)return nf.charAt(e+1);return qm(t<128?t:t+1)}function VS(t,e){return t.languageDataAt("closeBrackets",e)[0]||Fa}const Z7=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Q7=ae.inputHandler.of((t,e,n,r)=>{if((Z7?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(r.length>2||r.length==2&&gr(tn(r,0))==1||e!=s.from||n!=s.to)return!1;let i=t8(t.state,r);return i?(t.dispatch(i),!0):!1}),J7=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=VS(t,t.selection.main.head).brackets||Fa.brackets,s=null,i=t.changeByRange(o=>{if(o.empty){let a=n8(t.doc,o.head);for(let l of r)if(l==a&&Zu(t.doc,o.head)==zS(tn(l,0)))return{changes:{from:o.head-l.length,to:o.head+l.length},range:q.cursor(o.head-l.length)}}return{range:s=o}});return s||e(t.update(i,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},e8=[{key:"Backspace",run:J7}];function t8(t,e){let n=VS(t,t.selection.main.head),r=n.brackets||Fa.brackets;for(let s of r){let i=zS(tn(s,0));if(e==s)return i==s?i8(t,s,r.indexOf(s+s+s)>-1,n):r8(t,s,i,n.before||Fa.before);if(e==i&&HS(t,t.selection.main.from))return s8(t,s,i)}return null}function HS(t,e){let n=!1;return t.field(FS).between(0,t.doc.length,r=>{r==e&&(n=!0)}),n}function Zu(t,e){let n=t.sliceString(e,e+2);return n.slice(0,gr(tn(n,0)))}function n8(t,e){let n=t.sliceString(e-2,e);return gr(tn(n,0))==n.length?n:n.slice(1)}function r8(t,e,n,r){let s=null,i=t.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:n,from:o.to}],effects:Ys.of(o.to+e.length),range:q.range(o.anchor+e.length,o.head+e.length)};let a=Zu(t.doc,o.head);return!a||/\s/.test(a)||r.indexOf(a)>-1?{changes:{insert:e+n,from:o.head},effects:Ys.of(o.head+e.length),range:q.cursor(o.head+e.length)}:{range:s=o}});return s?null:t.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function s8(t,e,n){let r=null,s=t.changeByRange(i=>i.empty&&Zu(t.doc,i.head)==n?{changes:{from:i.head,to:i.head+n.length,insert:n},range:q.cursor(i.head+n.length)}:r={range:i});return r?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function i8(t,e,n,r){let s=r.stringPrefixes||Fa.stringPrefixes,i=null,o=t.changeByRange(a=>{if(!a.empty)return{changes:[{insert:e,from:a.from},{insert:e,from:a.to}],effects:Ys.of(a.to+e.length),range:q.range(a.anchor+e.length,a.head+e.length)};let l=a.head,d=Zu(t.doc,l),u;if(d==e){if(Gb(t,l))return{changes:{insert:e+e,from:l},effects:Ys.of(l+e.length),range:q.cursor(l+e.length)};if(HS(t,l)){let f=n&&t.sliceDoc(l,l+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+f.length,insert:f},range:q.cursor(l+f.length)}}}else{if(n&&t.sliceDoc(l-2*e.length,l)==e+e&&(u=qb(t,l-2*e.length,s))>-1&&Gb(t,u))return{changes:{insert:e+e+e+e,from:l},effects:Ys.of(l+e.length),range:q.cursor(l+e.length)};if(t.charCategorizer(l)(d)!=Je.Word&&qb(t,l,s)>-1&&!o8(t,l,e,s))return{changes:{insert:e+e,from:l},effects:Ys.of(l+e.length),range:q.cursor(l+e.length)}}return{range:i=a}});return i?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Gb(t,e){let n=Ht(t).resolveInner(e+1);return n.parent&&n.from==e}function o8(t,e,n,r){let s=Ht(t).resolveInner(e,-1),i=r.reduce((o,a)=>Math.max(o,a.length),0);for(let o=0;o<5;o++){let a=t.sliceDoc(s.from,Math.min(s.to,s.from+n.length+i)),l=a.indexOf(n);if(!l||l>-1&&r.indexOf(a.slice(0,l))>-1){let u=s.firstChild;for(;u&&u.from==s.from&&u.to-u.from>n.length+l;){if(t.sliceDoc(u.to-n.length,u.to)==n)return!1;u=u.firstChild}return!0}let d=s.to==e&&s.parent;if(!d)break;s=d}return!1}function qb(t,e,n){let r=t.charCategorizer(e);if(r(t.sliceDoc(e-1,e))!=Je.Word)return e;for(let s of n){let i=e-s.length;if(t.sliceDoc(i,e)==s&&r(t.sliceDoc(i-1,i))!=Je.Word)return i}return-1}function a8(t={}){return[q7,nn,Pt.of(t),K7,l8,Y7]}const WS=[{key:"Ctrl-Space",run:tf},{mac:"Alt-`",run:tf},{mac:"Alt-i",run:tf},{key:"Escape",run:V7},{key:"ArrowDown",run:Fc(!0)},{key:"ArrowUp",run:Fc(!1)},{key:"PageDown",run:Fc(!0,"page")},{key:"PageUp",run:Fc(!1,"page")},{key:"Enter",run:z7}],l8=hi.highest(Vu.computeN([Pt],t=>t.facet(Pt).defaultKeymap?[WS]:[]));class Yb{constructor(e,n,r){this.from=e,this.to=n,this.diagnostic=r}}class Vs{constructor(e,n,r){this.diagnostics=e,this.panel=n,this.selected=r}static init(e,n,r){let s=r.facet(za).markerFilter;s&&(e=s(e,r));let i=e.slice().sort((p,m)=>p.from-m.from||p.to-m.to),o=new Ur,a=[],l=0,d=r.doc.iter(),u=0,h=r.doc.length;for(let p=0;;){let m=p==i.length?null:i[p];if(!m&&!a.length)break;let x,b;if(a.length)x=l,b=a.reduce((v,k)=>Math.min(v,k.to),m&&m.from>x?m.from:1e8);else{if(x=m.from,x>h)break;b=m.to,a.push(m),p++}for(;p<i.length;){let v=i[p];if(v.from==x&&(v.to>v.from||v.to==x))a.push(v),p++,b=Math.min(v.to,b);else{b=Math.min(v.from,b);break}}b=Math.min(b,h);let y=!1;if(a.some(v=>v.from==x&&(v.to==b||b==h))&&(y=x==b,!y&&b-x<10)){let v=x-(u+d.value.length);v>0&&(d.next(v),u=x);for(let k=x;;){if(k>=b){y=!0;break}if(!d.lineBreak&&u+d.value.length>k)break;k=u+d.value.length,u+=d.value.length,d.next()}}let w=w8(a);if(y)o.add(x,x,Ce.widget({widget:new x8(w),diagnostics:a.slice()}));else{let v=a.reduce((k,C)=>C.markClass?k+" "+C.markClass:k,"");o.add(x,b,Ce.mark({class:"cm-lintRange cm-lintRange-"+w+v,diagnostics:a.slice(),inclusiveEnd:a.some(k=>k.to>b)}))}if(l=b,l==h)break;for(let v=0;v<a.length;v++)a[v].to<=l&&a.splice(v--,1)}let f=o.finish();return new Vs(f,n,ao(f))}}function ao(t,e=null,n=0){let r=null;return t.between(n,1e9,(s,i,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!r)r=new Yb(s,i,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new Yb(r.from,i,r.diagnostic)}}),r}function c8(t,e){let n=e.pos,r=e.end||n,s=t.state.facet(za).hideOn(t,n,r);if(s!=null)return s;let i=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(o=>o.is(US))||t.changes.touchesRange(i.from,Math.max(i.to,r)))}function d8(t,e){return t.field(gn,!1)?e:e.concat(Ee.appendConfig.of(k8))}const US=Ee.define(),Cg=Ee.define(),KS=Ee.define(),gn=Bt.define({create(){return new Vs(Ce.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let n=t.diagnostics.map(e.changes),r=null,s=t.panel;if(t.selected){let i=e.changes.mapPos(t.selected.from,1);r=ao(n,t.selected.diagnostic,i)||ao(n,null,i)}!n.size&&s&&e.state.facet(za).autoPanel&&(s=null),t=new Vs(n,s,r)}for(let n of e.effects)if(n.is(US)){let r=e.state.facet(za).autoPanel?n.value.length?Va.open:null:t.panel;t=Vs.init(n.value,r,e.state)}else n.is(Cg)?t=new Vs(t.diagnostics,n.value?Va.open:null,t.selected):n.is(KS)&&(t=new Vs(t.diagnostics,t.panel,n.value));return t},provide:t=>[_a.from(t,e=>e.panel),ae.decorations.from(t,e=>e.diagnostics)]}),u8=Ce.mark({class:"cm-lintRange cm-lintRange-active"});function h8(t,e,n){let{diagnostics:r}=t.state.field(gn),s,i=-1,o=-1;r.between(e-(n<0?1:0),e+(n>0?1:0),(l,d,{spec:u})=>{if(e>=l&&e<=d&&(l==d||(e>l||n>0)&&(e<d||n<0)))return s=u.diagnostics,i=l,o=d,!1});let a=t.state.facet(za).tooltipFilter;return s&&a&&(s=a(s,t.state)),s?{pos:i,end:o,above:t.state.doc.lineAt(i).to<o,create(){return{dom:f8(t,s)}}}:null}function f8(t,e){return Ke("ul",{class:"cm-tooltip-lint"},e.map(n=>qS(t,n,!1)))}const p8=t=>{let e=t.state.field(gn,!1);(!e||!e.panel)&&t.dispatch({effects:d8(t.state,[Cg.of(!0)])});let n=Ra(t,Va.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},Xb=t=>{let e=t.state.field(gn,!1);return!e||!e.panel?!1:(t.dispatch({effects:Cg.of(!1)}),!0)},m8=t=>{let e=t.state.field(gn,!1);if(!e)return!1;let n=t.state.selection.main,r=e.diagnostics.iter(n.to+1);return!r.value&&(r=e.diagnostics.iter(0),!r.value||r.from==n.from&&r.to==n.to)?!1:(t.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},g8=[{key:"Mod-Shift-m",run:p8,preventDefault:!0},{key:"F8",run:m8}],za=me.define({combine(t){return{sources:t.map(e=>e.source).filter(e=>e!=null),...Or(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Zb,tooltipFilter:Zb,needsRefresh:(e,n)=>e?n?r=>e(r)||n(r):e:n,hideOn:(e,n)=>e?n?(r,s,i)=>e(r,s,i)||n(r,s,i):e:n,autoPanel:(e,n)=>e||n})}}});function Zb(t,e){return t?e?(n,r)=>e(t(n,r),r):t:e}function GS(t){let e=[];if(t)e:for(let{name:n}of t){for(let r=0;r<n.length;r++){let s=n[r];if(/[a-zA-Z]/.test(s)&&!e.some(i=>i.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function qS(t,e,n){var r;let s=n?GS(e.actions):[];return Ke("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Ke("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(r=e.actions)===null||r===void 0?void 0:r.map((i,o)=>{let a=!1,l=p=>{if(p.preventDefault(),a)return;a=!0;let m=ao(t.state.field(gn).diagnostics,e);m&&i.apply(t,m.from,m.to)},{name:d}=i,u=s[o]?d.indexOf(s[o]):-1,h=u<0?d:[d.slice(0,u),Ke("u",d.slice(u,u+1)),d.slice(u+1)],f=i.markClass?" "+i.markClass:"";return Ke("button",{type:"button",class:"cm-diagnosticAction"+f,onclick:l,onmousedown:l,"aria-label":` Action: ${d}${u<0?"":` (access key "${s[o]})"`}.`},h)}),e.source&&Ke("div",{class:"cm-diagnosticSource"},e.source))}class x8 extends Er{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Ke("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Qb{constructor(e,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=qS(e,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Va{constructor(e){this.view=e,this.items=[];let n=s=>{if(s.keyCode==27)Xb(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:i}=this.items[this.selectedIndex],o=GS(i.actions);for(let a=0;a<o.length;a++)if(o[a].toUpperCase().charCodeAt(0)==s.keyCode){let l=ao(this.view.state.field(gn).diagnostics,i);l&&i.actions[a].apply(e,l.from,l.to)}}else return;s.preventDefault()},r=s=>{for(let i=0;i<this.items.length;i++)this.items[i].dom.contains(s.target)&&this.moveSelection(i)};this.list=Ke("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=Ke("div",{class:"cm-panel-lint"},this.list,Ke("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Xb(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(gn).selected;if(!e)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==e.diagnostic)return n;return-1}update(){let{diagnostics:e,selected:n}=this.view.state.field(gn),r=0,s=!1,i=null,o=new Set;for(e.between(0,this.view.state.doc.length,(a,l,{spec:d})=>{for(let u of d.diagnostics){if(o.has(u))continue;o.add(u);let h=-1,f;for(let p=r;p<this.items.length;p++)if(this.items[p].diagnostic==u){h=p;break}h<0?(f=new Qb(this.view,u),this.items.splice(r,0,f),s=!0):(f=this.items[h],h>r&&(this.items.splice(r,h-r),s=!0)),n&&f.diagnostic==n.diagnostic?f.dom.hasAttribute("aria-selected")||(f.dom.setAttribute("aria-selected","true"),i=f):f.dom.hasAttribute("aria-selected")&&f.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new Qb(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),i?(this.list.setAttribute("aria-activedescendant",i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:l})=>{let d=l.height/this.list.offsetHeight;a.top<l.top?this.list.scrollTop-=(l.top-a.top)/d:a.bottom>l.bottom&&(this.list.scrollTop+=(a.bottom-l.bottom)/d)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function n(){let r=e;e=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;e!=r.dom;)n();e=r.dom.nextSibling}else this.list.insertBefore(r.dom,e);for(;e;)n()}moveSelection(e){if(this.selectedIndex<0)return;let n=this.view.state.field(gn),r=ao(n.diagnostics,this.items[e].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:KS.of(r)})}static open(e){return new Va(e)}}function b8(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}function zc(t){return b8(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const y8=ae.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:zc("#d11")},".cm-lintRange-warning":{backgroundImage:zc("orange")},".cm-lintRange-info":{backgroundImage:zc("#999")},".cm-lintRange-hint":{backgroundImage:zc("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function v8(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function w8(t){let e="hint",n=1;for(let r of t){let s=v8(r.severity);s>n&&(n=s,e=r.severity)}return e}const k8=[gn,ae.decorations.compute([gn],t=>{let{selected:e,panel:n}=t.field(gn);return!e||!n||e.from==e.to?Ce.none:Ce.set([u8.range(e.from,e.to)])}),NT(h8,{hideOn:c8}),y8];var Jb=function(e){e===void 0&&(e={});var{crosshairCursor:n=!1}=e,r=[];e.closeBracketsKeymap!==!1&&(r=r.concat(e8)),e.defaultKeymap!==!1&&(r=r.concat(GL)),e.searchKeymap!==!1&&(r=r.concat(y7)),e.historyKeymap!==!1&&(r=r.concat(eL)),e.foldKeymap!==!1&&(r=r.concat(u6)),e.completionKeymap!==!1&&(r=r.concat(WS)),e.lintKeymap!==!1&&(r=r.concat(g8));var s=[];return e.lineNumbers!==!1&&s.push(IT()),e.highlightActiveLineGutter!==!1&&s.push(FT()),e.highlightSpecialChars!==!1&&s.push(tT()),e.history!==!1&&s.push(U6()),e.foldGutter!==!1&&s.push(m6()),e.drawSelection!==!1&&s.push(WM()),e.dropCursor!==!1&&s.push(YM()),e.allowMultipleSelections!==!1&&s.push(Ie.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&s.push(t6()),e.syntaxHighlighting!==!1&&s.push(fg(y6,{fallback:!0})),e.bracketMatching!==!1&&s.push(N6()),e.closeBrackets!==!1&&s.push(X7()),e.autocompletion!==!1&&s.push(a8()),e.rectangularSelection!==!1&&s.push(mT()),n!==!1&&s.push(bT()),e.highlightActiveLine!==!1&&s.push(aT()),e.highlightSelectionMatches!==!1&&s.push(e7()),e.tabSize&&typeof e.tabSize=="number"&&s.push(Wu.of(" ".repeat(e.tabSize))),s.concat([Vu.of(r.flat())]).filter(Boolean)};const S8="#e5c07b",ey="#e06c75",C8="#56b6c2",j8="#ffffff",xd="#abb2bf",tm="#7d8799",N8="#61afef",P8="#98c379",ty="#d19a66",O8="#c678dd",E8="#21252b",ny="#2c313a",ry="#282c34",rf="#353a42",D8="#3E4451",sy="#528bff",A8=ae.theme({"&":{color:xd,backgroundColor:ry},".cm-content":{caretColor:sy},".cm-cursor, .cm-dropCursor":{borderLeftColor:sy},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:D8},".cm-panels":{backgroundColor:E8,color:xd},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:ry,color:tm,border:"none"},".cm-activeLineGutter":{backgroundColor:ny},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:rf},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:rf,borderBottomColor:rf},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:ny,color:xd}}},{dark:!0}),M8=wo.define([{tag:W.keyword,color:O8},{tag:[W.name,W.deleted,W.character,W.propertyName,W.macroName],color:ey},{tag:[W.function(W.variableName),W.labelName],color:N8},{tag:[W.color,W.constant(W.name),W.standard(W.name)],color:ty},{tag:[W.definition(W.name),W.separator],color:xd},{tag:[W.typeName,W.className,W.number,W.changed,W.annotation,W.modifier,W.self,W.namespace],color:S8},{tag:[W.operator,W.operatorKeyword,W.url,W.escape,W.regexp,W.link,W.special(W.string)],color:C8},{tag:[W.meta,W.comment],color:tm},{tag:W.strong,fontWeight:"bold"},{tag:W.emphasis,fontStyle:"italic"},{tag:W.strikethrough,textDecoration:"line-through"},{tag:W.link,color:tm,textDecoration:"underline"},{tag:W.heading,fontWeight:"bold",color:ey},{tag:[W.atom,W.bool,W.special(W.variableName)],color:ty},{tag:[W.processingInstruction,W.string,W.inserted],color:P8},{tag:W.invalid,color:j8}]),T8=[A8,fg(M8)];var L8=ae.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),R8=function(e){e===void 0&&(e={});var{indentWithTab:n=!0,editable:r=!0,readOnly:s=!1,theme:i="light",placeholder:o="",basicSetup:a=!0}=e,l=[];switch(n&&l.unshift(Vu.of([qL])),a&&(typeof a=="boolean"?l.unshift(Jb()):l.unshift(Jb(a))),o&&l.unshift(uT(o)),i){case"light":l.push(L8);break;case"dark":l.push(T8);break;case"none":break;default:l.push(i);break}return r===!1&&l.push(ae.editable.of(!1)),s&&l.push(Ie.readOnly.of(!0)),[...l]},_8=t=>({line:t.state.doc.lineAt(t.state.selection.main.from),lineCount:t.state.doc.lines,lineBreak:t.state.lineBreak,length:t.state.doc.length,readOnly:t.state.readOnly,tabSize:t.state.tabSize,selection:t.state.selection,selectionAsSingle:t.state.selection.asSingle().main,ranges:t.state.selection.ranges,selectionCode:t.state.sliceDoc(t.state.selection.main.from,t.state.selection.main.to),selections:t.state.selection.ranges.map(e=>t.state.sliceDoc(e.from,e.to)),selectedText:t.state.selection.ranges.some(e=>!e.empty)});class I8{constructor(e,n){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=n,this.timeoutMS=n,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(n=>{try{n()}catch(r){console.error("TimeoutLatch callback error:",r)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class iy{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var sf=null,$8=()=>typeof window>"u"?new iy:(sf||(sf=new iy),sf),oy=Pr.define(),B8=200,F8=[];function z8(t){var{value:e,selection:n,onChange:r,onStatistics:s,onCreateEditor:i,onUpdate:o,extensions:a=F8,autoFocus:l,theme:d="light",height:u=null,minHeight:h=null,maxHeight:f=null,width:p=null,minWidth:m=null,maxWidth:x=null,placeholder:b="",editable:y=!0,readOnly:w=!1,indentWithTab:v=!0,basicSetup:k=!0,root:C,initialState:j}=t,[S,O]=g.useState(),[D,M]=g.useState(),[P,T]=g.useState(),$=g.useState(()=>({current:null}))[0],N=g.useState(()=>({current:null}))[0],E=ae.theme({"&":{height:u,minHeight:h,maxHeight:f,width:p,minWidth:m,maxWidth:x},"& .cm-scroller":{height:"100% !important"}}),A=ae.updateListener.of(I=>{if(I.docChanged&&typeof r=="function"&&!I.transactions.some(V=>V.annotation(oy))){$.current?$.current.reset():($.current=new I8(()=>{if(N.current){var V=N.current;N.current=null,V()}$.current=null},B8),$8().add($.current));var F=I.state.doc,H=F.toString();r(H,I)}s&&s(_8(I))}),R=R8({theme:d,editable:y,readOnly:w,placeholder:b,indentWithTab:v,basicSetup:k}),_=[A,E,...R];return o&&typeof o=="function"&&_.push(ae.updateListener.of(o)),_=_.concat(a),g.useLayoutEffect(()=>{if(S&&!P){var I={doc:e,selection:n,extensions:_},F=j?Ie.fromJSON(j.json,I,j.fields):Ie.create(I);if(T(F),!D){var H=new ae({state:F,parent:S,root:C});M(H),i&&i(H,F)}}return()=>{D&&(T(void 0),M(void 0))}},[S,P]),g.useEffect(()=>{t.container&&O(t.container)},[t.container]),g.useEffect(()=>()=>{D&&(D.destroy(),M(void 0)),$.current&&($.current.cancel(),$.current=null)},[D]),g.useEffect(()=>{l&&D&&D.focus()},[l,D]),g.useEffect(()=>{D&&D.dispatch({effects:Ee.reconfigure.of(_)})},[d,a,u,h,f,p,m,x,b,y,w,v,k,r,o]),g.useEffect(()=>{if(e!==void 0){var I=D?D.state.doc.toString():"";if(D&&e!==I){var F=$.current&&!$.current.isDone,H=()=>{D&&e!==D.state.doc.toString()&&D.dispatch({changes:{from:0,to:D.state.doc.toString().length,insert:e||""},annotations:[oy.of(!0)]})};F?N.current=H:H()}}},[e,D]),{state:P,setState:T,view:D,setView:M,container:S,setContainer:O}}var V8=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],YS=g.forwardRef((t,e)=>{var{className:n,value:r="",selection:s,extensions:i=[],onChange:o,onStatistics:a,onCreateEditor:l,onUpdate:d,autoFocus:u,theme:h="light",height:f,minHeight:p,maxHeight:m,width:x,minWidth:b,maxWidth:y,basicSetup:w,placeholder:v,indentWithTab:k,editable:C,readOnly:j,root:S,initialState:O}=t,D=R6(t,V8),M=g.useRef(null),{state:P,view:T,container:$,setContainer:N}=z8({root:S,value:r,autoFocus:u,theme:h,height:f,minHeight:p,maxHeight:m,width:x,minWidth:b,maxWidth:y,basicSetup:w,placeholder:v,indentWithTab:k,editable:C,readOnly:j,selection:s,onChange:o,onStatistics:a,onCreateEditor:l,onUpdate:d,extensions:i,initialState:O});g.useImperativeHandle(e,()=>({editor:M.current,state:P,view:T}),[M,$,P,T]);var E=g.useCallback(R=>{M.current=R,N(R)},[N]);if(typeof r!="string")throw new Error("value must be typeof string but got "+typeof r);var A=typeof h=="string"?"cm-theme-"+h:"cm-theme";return c.jsx("div",qp({ref:E,className:""+A+(n?" "+n:"")},D))});YS.displayName="CodeMirror";const H8=()=>{const t=ae.theme({"&":{backgroundColor:"var(--dash-surface)",color:"var(--dash-text)",height:"100%"},".cm-editor":{height:"100% !important"},".cm-content":{caretColor:"var(--dash-accent)",fontFamily:"'JetBrains Mono', Menlo, monospace",padding:"1rem"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--dash-accent)"},"& ::selection":{backgroundColor:"var(--dash-accent-selection) !important",color:"inherit !important"},".cm-gutters":{backgroundColor:"var(--dash-surface)",color:"var(--dash-text-muted)",border:"none",borderRight:"1px solid var(--dash-border)",paddingRight:"0.5rem"},".cm-lineNumbers .cm-gutterElement":{padding:"0 0.5rem 0 1rem",minWidth:"3rem"},".cm-activeLineGutter":{backgroundColor:"var(--dash-accent-subtle)",color:"var(--dash-accent)",fontWeight:"600"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--dash-accent) 8%, transparent)"},".cm-matchingBracket":{backgroundColor:"var(--dash-accent-subtle)",outline:"1px solid var(--dash-accent)"},".cm-scroller":{overflow:"auto !important",height:"100%",maxHeight:"100%"}}),e=wo.define([{tag:W.propertyName,color:"var(--dash-accent)"},{tag:W.string,color:"color-mix(in srgb, var(--dash-accent) 70%, var(--dash-text))"},{tag:W.number,color:"var(--dash-accent-hover)"},{tag:W.bool,color:"var(--dash-accent-hover)"},{tag:W.null,color:"var(--dash-text-muted)"},{tag:W.punctuation,color:"var(--dash-text-secondary)"},{tag:W.brace,color:"var(--dash-text-secondary)"},{tag:W.bracket,color:"var(--dash-text-secondary)"}]);return[t,fg(e)]},W8=({value:t,onChange:e,onCursorLineChange:n,onEditorFocus:r,height:s="100%",readOnly:i=!1,className:o})=>{const a=g.useMemo(()=>[L6(),ae.lineWrapping,...H8()],[]),l=g.useMemo(()=>{if(n)return d=>{const u=d.state.selection.main.head,h=d.view.state.doc.lineAt(u).number-1;n(h)}},[n]);return c.jsx("div",{className:`h-full [&_.cm-editor]:h-full [&_.cm-editor]:outline-none [&_.cm-focused]:outline-none ${o??""}`.trim(),children:c.jsx(YS,{value:t,height:s,extensions:a,onChange:e,onFocus:r,onUpdate:l,theme:"none",readOnly:i,basicSetup:{lineNumbers:!0,highlightActiveLineGutter:!0,highlightActiveLine:!0,foldGutter:!1,dropCursor:!0,drawSelection:!1,allowMultipleSelections:!1,indentOnInput:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!1,rectangularSelection:!1,crosshairCursor:!1,highlightSelectionMatches:!0}})})},jg=({width:t,isLoading:e,jsonText:n,cursorLine:r,syntaxError:s,onChange:i,onEditorFocus:o,onCursorLineChange:a,readOnly:l=!1,headerTitle:d,headerPath:u,headerActions:h})=>{const{t:f}=se(),p=m=>{if(l||!m.target.closest(".cm-editor"))return;const b=m.currentTarget;b.scrollHeight<=b.clientHeight||(b.scrollTop+=m.deltaY)};return c.jsxs("div",{style:{width:`${t}%`},className:"bg-dash-surface border border-dash-border rounded-xl overflow-hidden flex flex-col shadow-sm min-w-0 h-full",children:[c.jsx("div",{className:"p-3 border-b border-dash-border bg-dash-surface-hover/50 shrink-0",children:c.jsxs("div",{className:"flex items-end justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h3",{className:"text-xs font-bold text-dash-text-secondary uppercase tracking-widest",children:d??f("jsonTab")}),u&&c.jsx("p",{className:"mt-1 mono text-[11px] text-dash-text-muted truncate",children:u})]}),h&&c.jsx("div",{className:"flex items-center gap-2 shrink-0",children:h})]})}),c.jsx("div",{className:"flex-1 min-h-0 overflow-auto",onWheelCapture:p,children:e?c.jsx("div",{className:"h-full flex items-center justify-center",children:c.jsx("div",{className:"animate-pulse text-dash-text-muted text-sm",children:f("loading")})}):l?c.jsx("pre",{className:"h-full overflow-auto p-4 font-mono text-xs leading-4 text-dash-text whitespace-pre m-0",children:n}):c.jsx(W8,{value:n,onChange:i,onEditorFocus:o,onCursorLineChange:a,readOnly:l,className:"[&_.cm-content]:text-xs [&_.cm-content]:leading-4 [&_.cm-gutters]:text-xs [&_.cm-gutters]:leading-4"})}),c.jsxs("div",{className:"px-4 py-2 bg-dash-surface-hover/30 border-t border-dash-border text-[10px] text-dash-text-muted flex justify-between uppercase tracking-widest font-bold",children:[c.jsxs("div",{className:"flex gap-4",children:[c.jsx("span",{children:"UTF-8"}),c.jsx("span",{children:"JSON"}),c.jsxs("span",{children:["L:",r+1]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[l&&c.jsx("span",{children:f("readOnly")}),s?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-red-500"}),c.jsx("span",{className:"text-red-500 normal-case",children:s})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-dash-accent"}),f("syntaxValid")]})]})]})]})},ay=({label:t,value:e})=>c.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-dash-bg border border-dash-border rounded-md",children:[c.jsxs("span",{className:"text-[9px] font-bold text-dash-text-muted uppercase",children:[t,":"]}),c.jsx("span",{className:"text-[10px] mono font-bold text-dash-text-secondary",children:e})]}),XS=({width:t,fieldDoc:e,activeFieldPath:n,extraContent:r,overrideBadge:s})=>{const{t:i,lang:o}=se(),a=e??(n?Fw[n]??{path:n,type:"unknown",default:"n/a",description:"Help is being resolved for this field. Try editing the value or switching to the JSON view for schema-based details.",descriptionVi:"Đang tải trợ giúp cho trường này. Hãy thử chỉnh sửa giá trị hoặc chuyển sang chế độ JSON để xem mô tả suy ra từ schema."}:null);return c.jsxs("div",{style:{width:`${t}%`},className:"bg-dash-surface border border-dash-border rounded-xl flex flex-col shadow-sm overflow-hidden min-w-0",children:[c.jsx("div",{className:"p-3 border-b border-dash-border bg-dash-surface-hover/50 shrink-0",children:c.jsx("h3",{className:"text-xs font-bold text-dash-text-secondary uppercase tracking-widest",children:i("configurationHelp")})}),c.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:a?c.jsxs("div",{className:"space-y-5 animate-in fade-in duration-500",children:[c.jsxs("header",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[c.jsx("span",{className:"text-[10px] bg-dash-accent-subtle text-dash-accent px-1.5 py-0.5 rounded font-mono uppercase font-bold",children:i("field")}),c.jsx("h2",{className:"text-base font-bold text-dash-text mono break-all",children:a.path}),s]}),c.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[c.jsx(ay,{label:i("type"),value:a.type}),c.jsx(ay,{label:i("default"),value:a.default})]})]}),c.jsxs("section",{children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-text-muted uppercase tracking-widest mb-2",children:i("description")}),c.jsx("p",{className:"text-sm text-dash-text-secondary leading-relaxed italic",children:o==="vi"?a.descriptionVi:a.description})]}),a.validValues&&c.jsxs("section",{children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-text-muted uppercase tracking-widest mb-2",children:i("validValues")}),c.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.validValues.map(l=>c.jsx("span",{className:"px-2 py-0.5 bg-dash-bg border border-dash-border rounded text-[11px] mono text-dash-text",children:l},l))})]}),a.effect&&c.jsxs("section",{className:"bg-dash-accent-subtle/30 p-3 rounded-lg border border-dash-accent/10",children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-accent uppercase tracking-widest mb-1",children:i("systemEffect")}),c.jsx("p",{className:"text-[12px] text-dash-text-secondary leading-normal",children:o==="vi"&&a.effectVi?a.effectVi:a.effect})]}),a.example&&c.jsxs("section",{children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-text-muted uppercase tracking-widest mb-2",children:i("exampleUsage")}),c.jsx("div",{className:"bg-dash-bg p-3 rounded-lg border border-dash-border overflow-hidden",children:c.jsx("pre",{className:"text-[11px] mono text-dash-text-secondary whitespace-pre overflow-x-auto",children:a.example})})]}),r]}):c.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center opacity-40 space-y-4",children:[c.jsx("div",{className:"w-10 h-10 rounded-full bg-dash-bg border border-dash-border flex items-center justify-center text-lg",children:"?"}),c.jsxs("div",{className:"max-w-[180px]",children:[c.jsx("p",{className:"text-sm font-bold text-dash-text mb-1 italic",children:i("knowledgeBase")}),c.jsx("p",{className:"text-xs text-dash-text-secondary",children:i("clickToSeeHelp")})]})]})}),a&&c.jsx("div",{className:"p-3 bg-dash-surface-hover/20 border-t border-dash-border shrink-0",children:c.jsxs("p",{className:"text-[10px] text-dash-text-muted font-medium flex items-center gap-1.5 italic",children:[c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),i("extractedFrom")]})})]})},U8=({variant:t="development"})=>{const{t:e}=se(),n={development:e("developmentFeature"),beta:e("betaFeature"),experimental:e("experimentalFeature")};return c.jsx("span",{className:"text-[9px] bg-orange-500/10 text-orange-500 px-2 py-0.5 rounded-full font-bold border border-orange-500/30 uppercase tracking-wider",children:n[t]})},ly={codex:{heavy:{model:"gpt-5.4",effort:"xhigh"},balanced:{model:"gpt-5.4",effort:"high"},light:{model:"gpt-5.4-mini",effort:"medium"}},"gemini-cli":{heavy:{model:"gemini-3.1-pro-preview"},balanced:{model:"gemini-3.1-pro-preview"},light:{model:"gemini-3-flash-preview"}}},K8={codex:"Codex","gemini-cli":"Gemini CLI"},cy=["heavy","balanced","light"];function dy(t,e){return e.split(".").reduce((n,r)=>{if(n!=null&&typeof n=="object"&&r in n)return n[r]},t)}const uy="bg-transparent border border-dash-border rounded px-2 py-1 text-sm text-dash-text placeholder:text-dash-text-muted focus:border-dash-accent focus:outline-none w-full",G8=({config:t,onChange:e})=>{const{t:n}=se(),[r,s]=g.useState(!1),i=(l,d,u,h)=>{const f=`modelTaxonomy.${l}.${d}.${u}`;e(f,h===""?void 0:h)},o=l=>{for(const d of cy)e(`modelTaxonomy.${l}.${d}.model`,void 0),ly[l]?.[d]?.effort!==void 0&&e(`modelTaxonomy.${l}.${d}.effort`,void 0)},a=l=>n(l==="heavy"?"taxonomyTierHeavy":l==="balanced"?"taxonomyTierBalanced":"taxonomyTierLight");return c.jsxs("div",{className:"bg-dash-surface border border-dash-border rounded-lg overflow-hidden flex flex-col h-full",children:[c.jsxs("button",{type:"button",onClick:()=>s(!r),className:"w-full flex items-center justify-between px-4 py-3 bg-dash-surface-hover/30 hover:bg-dash-surface-hover/50 transition-colors","aria-expanded":!r,"aria-controls":"section-model-taxonomy",children:[c.jsx("h3",{className:"text-sm font-bold text-dash-text uppercase tracking-wider",children:n("sectionModelTaxonomy")}),c.jsx("svg",{className:`w-4 h-4 text-dash-text-muted transition-transform duration-200 ${r?"":"rotate-180"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),!r&&c.jsx("div",{id:"section-model-taxonomy",className:"flex-1 overflow-y-auto min-h-0",children:c.jsxs("div",{className:"px-4 py-3 space-y-4",children:[c.jsx("p",{className:"text-xs text-dash-text-secondary",children:n("taxonomyDescription")}),Object.entries(ly).map(([l,d])=>{const u=Object.values(d).some(h=>h.effort!==void 0);return c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-xs font-semibold text-dash-text uppercase tracking-wider",children:K8[l]??l}),c.jsx("button",{type:"button",onClick:()=>o(l),className:"text-xs text-dash-text-muted hover:text-dash-text px-2 py-0.5 rounded border border-dash-border hover:border-dash-accent transition-colors",children:n("taxonomyResetProvider")})]}),c.jsx("div",{className:"overflow-hidden rounded border border-dash-border",children:c.jsxs("table",{className:"w-full text-xs",children:[c.jsx("thead",{children:c.jsxs("tr",{className:"bg-dash-surface-hover/40 border-b border-dash-border",children:[c.jsx("th",{className:"text-left px-3 py-2 text-dash-text-secondary font-medium w-1/4",children:n("taxonomyTier")}),c.jsx("th",{className:"text-left px-3 py-2 text-dash-text-secondary font-medium",children:n("taxonomyModel")}),u&&c.jsx("th",{className:"text-left px-3 py-2 text-dash-text-secondary font-medium w-1/4",children:n("taxonomyEffort")})]})}),c.jsx("tbody",{children:cy.map(h=>{const f=d[h],p=dy(t,`modelTaxonomy.${l}.${h}.model`),m=dy(t,`modelTaxonomy.${l}.${h}.effort`);return c.jsxs("tr",{className:"border-b border-dash-border last:border-0",children:[c.jsx("td",{className:"px-3 py-2 text-dash-text-secondary",children:a(h)}),c.jsx("td",{className:"px-3 py-2",children:c.jsx("input",{type:"text",className:uy,placeholder:f?.model??"",value:p??"",onChange:x=>i(l,h,"model",x.target.value)})}),u&&c.jsx("td",{className:"px-3 py-2",children:f?.effort!==void 0?c.jsx("input",{type:"text",className:uy,placeholder:f.effort,value:m??"",onChange:x=>i(l,h,"effort",x.target.value)}):null})]},h)})})]})})]},l)})]})})]})},q8=(t,e)=>{const[n,r]=g.useState(null);return g.useEffect(()=>{const s=t.split(`
270
+ `:r=="r"?"\r":r=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new h7(this):new d7(this)}getCursor(e,n=0,r){let s=e.doc?e:Ie.create({doc:e});return r==null&&(r=s.doc.length),this.regexp?Pi(this,s,n,r):Ni(this,s,n,r)}}class DS{constructor(e){this.spec=e}}function Ni(t,e,n,r){return new oo(e.doc,t.unquoted,n,r,t.caseSensitive?void 0:s=>s.toLowerCase(),t.wholeWord?c7(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function c7(t,e){return(n,r,s,i)=>((i>n||i+s.length<r)&&(i=Math.max(0,n-2),s=t.sliceString(i,Math.min(t.length,r+2))),(e(nu(s,n-i))!=Je.Word||e(ru(s,n-i))!=Je.Word)&&(e(ru(s,r-i))!=Je.Word||e(nu(s,r-i))!=Je.Word))}class d7 extends DS{constructor(e){super(e)}nextMatch(e,n,r){let s=Ni(this.spec,e,r,e.doc.length).nextOverlapping();if(s.done){let i=Math.min(e.doc.length,n+this.spec.unquoted.length);s=Ni(this.spec,e,0,i).nextOverlapping()}return s.done||s.value.from==n&&s.value.to==r?null:s.value}prevMatchInRange(e,n,r){for(let s=r;;){let i=Math.max(n,s-1e4-this.spec.unquoted.length),o=Ni(this.spec,e,i,s),a=null;for(;!o.nextOverlapping().done;)a=o.value;if(a)return a;if(i==n)return null;s-=1e4}}prevMatch(e,n,r){let s=this.prevMatchInRange(e,0,n);return s||(s=this.prevMatchInRange(e,Math.max(0,r-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=n||s.to!=r)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,n){let r=Ni(this.spec,e,0,e.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(e,n,r,s){let i=Ni(this.spec,e,Math.max(0,n-this.spec.unquoted.length),Math.min(r+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)s(i.value.from,i.value.to)}}function Pi(t,e,n,r){return new PS(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?u7(e.charCategorizer(e.selection.main.head)):void 0},n,r)}function nu(t,e){return t.slice(wt(t,e,!1),e)}function ru(t,e){return t.slice(e,wt(t,e))}function u7(t){return(e,n,r)=>!r[0].length||(t(nu(r.input,r.index))!=Je.Word||t(ru(r.input,r.index))!=Je.Word)&&(t(ru(r.input,r.index+r[0].length))!=Je.Word||t(nu(r.input,r.index+r[0].length))!=Je.Word)}class h7 extends DS{nextMatch(e,n,r){let s=Pi(this.spec,e,r,e.doc.length).next();return s.done&&(s=Pi(this.spec,e,0,n).next()),s.done?null:s.value}prevMatchInRange(e,n,r){for(let s=1;;s++){let i=Math.max(n,r-s*1e4),o=Pi(this.spec,e,i,r),a=null;for(;!o.next().done;)a=o.value;if(a&&(i==n||a.from>i+10))return a;if(i==n)return null}}prevMatch(e,n,r){return this.prevMatchInRange(e,0,n)||this.prevMatchInRange(e,r,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,r)=>{if(r=="&")return e.match[0];if(r=="$")return"$";for(let s=r.length;s>0;s--){let i=+r.slice(0,s);if(i>0&&i<e.match.length)return e.match[i]+r.slice(s)}return n})}matchAll(e,n){let r=Pi(this.spec,e,0,e.doc.length),s=[];for(;!r.next().done;){if(s.length>=n)return null;s.push(r.value)}return s}highlight(e,n,r,s){let i=Pi(this.spec,e,Math.max(0,n-250),Math.min(r+250,e.doc.length));for(;!i.next().done;)s(i.value.from,i.value.to)}}const $a=Ee.define(),bg=Ee.define(),xs=Bt.define({create(t){return new Jh(em(t).create(),null)},update(t,e){for(let n of e.effects)n.is($a)?t=new Jh(n.value.create(),t.panel):n.is(bg)&&(t=new Jh(t.query,n.value?yg:null));return t},provide:t=>_a.from(t,e=>e.panel)});class Jh{constructor(e,n){this.query=e,this.panel=n}}const f7=Ce.mark({class:"cm-searchMatch"}),p7=Ce.mark({class:"cm-searchMatch cm-searchMatch-selected"}),m7=ut.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(xs))}update(t){let e=t.state.field(xs);(e!=t.startState.field(xs)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return Ce.none;let{view:n}=this,r=new Ur;for(let s=0,i=n.visibleRanges,o=i.length;s<o;s++){let{from:a,to:l}=i[s];for(;s<o-1&&l>i[s+1].from-2*250;)l=i[++s].to;t.highlight(n.state,a,l,(d,u)=>{let h=n.state.selection.ranges.some(f=>f.from==d&&f.to==u);r.add(d,u,h?p7:f7)})}return r.finish()}},{decorations:t=>t.decorations});function Xl(t){return e=>{let n=e.state.field(xs,!1);return n&&n.query.spec.valid?t(e,n):TS(e)}}const su=Xl((t,{query:e})=>{let{to:n}=t.state.selection.main,r=e.nextMatch(t.state,n,n);if(!r)return!1;let s=q.single(r.from,r.to),i=t.state.facet(So);return t.dispatch({selection:s,effects:[vg(t,r),i.scrollToMatch(s.main,t)],userEvent:"select.search"}),MS(t),!0}),iu=Xl((t,{query:e})=>{let{state:n}=t,{from:r}=n.selection.main,s=e.prevMatch(n,r,r);if(!s)return!1;let i=q.single(s.from,s.to),o=t.state.facet(So);return t.dispatch({selection:i,effects:[vg(t,s),o.scrollToMatch(i.main,t)],userEvent:"select.search"}),MS(t),!0}),g7=Xl((t,{query:e})=>{let n=e.matchAll(t.state,1e3);return!n||!n.length?!1:(t.dispatch({selection:q.create(n.map(r=>q.range(r.from,r.to))),userEvent:"select.search.matches"}),!0)}),x7=({state:t,dispatch:e})=>{let n=t.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:s}=n.main,i=[],o=0;for(let a=new oo(t.doc,t.sliceDoc(r,s));!a.next().done;){if(i.length>1e3)return!1;a.value.from==r&&(o=i.length),i.push(q.range(a.value.from,a.value.to))}return e(t.update({selection:q.create(i,o),userEvent:"select.search.matches"})),!0},Fb=Xl((t,{query:e})=>{let{state:n}=t,{from:r,to:s}=n.selection.main;if(n.readOnly)return!1;let i=e.nextMatch(n,r,r);if(!i)return!1;let o=i,a=[],l,d,u=[];o.from==r&&o.to==s&&(d=n.toText(e.getReplacement(o)),a.push({from:o.from,to:o.to,insert:d}),o=e.nextMatch(n,o.from,o.to),u.push(ae.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(r).number)+".")));let h=t.state.changes(a);return o&&(l=q.single(o.from,o.to).map(h),u.push(vg(t,o)),u.push(n.facet(So).scrollToMatch(l.main,t))),t.dispatch({changes:h,selection:l,effects:u,userEvent:"input.replace"}),!0}),b7=Xl((t,{query:e})=>{if(t.state.readOnly)return!1;let n=e.matchAll(t.state,1e9).map(s=>{let{from:i,to:o}=s;return{from:i,to:o,insert:e.getReplacement(s)}});if(!n.length)return!1;let r=t.state.phrase("replaced $ matches",n.length)+".";return t.dispatch({changes:n,effects:ae.announce.of(r),userEvent:"input.replace.all"}),!0});function yg(t){return t.state.facet(So).createPanel(t)}function em(t,e){var n,r,s,i,o;let a=t.selection.main,l=a.empty||a.to>a.from+100?"":t.sliceDoc(a.from,a.to);if(e&&!l)return e;let d=t.facet(So);return new ES({search:((n=e?.literal)!==null&&n!==void 0?n:d.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:(r=e?.caseSensitive)!==null&&r!==void 0?r:d.caseSensitive,literal:(s=e?.literal)!==null&&s!==void 0?s:d.literal,regexp:(i=e?.regexp)!==null&&i!==void 0?i:d.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:d.wholeWord})}function AS(t){let e=Ra(t,yg);return e&&e.dom.querySelector("[main-field]")}function MS(t){let e=AS(t);e&&e==t.root.activeElement&&e.select()}const TS=t=>{let e=t.state.field(xs,!1);if(e&&e.panel){let n=AS(t);if(n&&n!=t.root.activeElement){let r=em(t.state,e.query.spec);r.valid&&t.dispatch({effects:$a.of(r)}),n.focus(),n.select()}}else t.dispatch({effects:[bg.of(!0),e?$a.of(em(t.state,e.query.spec)):Ee.appendConfig.of(k7)]});return!0},LS=t=>{let e=t.state.field(xs,!1);if(!e||!e.panel)return!1;let n=Ra(t,yg);return n&&n.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:bg.of(!1)}),!0},y7=[{key:"Mod-f",run:TS,scope:"editor search-panel"},{key:"F3",run:su,shift:iu,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:su,shift:iu,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:LS,scope:"editor search-panel"},{key:"Mod-Shift-l",run:x7},{key:"Mod-Alt-g",run:XL},{key:"Mod-d",run:l7,preventDefault:!0}];class v7{constructor(e){this.view=e;let n=this.query=e.state.field(xs).query.spec;this.commit=this.commit.bind(this),this.searchField=Ke("input",{value:n.search,placeholder:un(e,"Find"),"aria-label":un(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=Ke("input",{value:n.replace,placeholder:un(e,"Replace"),"aria-label":un(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=Ke("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=Ke("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=Ke("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function r(s,i,o){return Ke("button",{class:"cm-button",name:s,onclick:i,type:"button"},o)}this.dom=Ke("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,r("next",()=>su(e),[un(e,"next")]),r("prev",()=>iu(e),[un(e,"previous")]),r("select",()=>g7(e),[un(e,"all")]),Ke("label",null,[this.caseField,un(e,"match case")]),Ke("label",null,[this.reField,un(e,"regexp")]),Ke("label",null,[this.wordField,un(e,"by word")]),...e.state.readOnly?[]:[Ke("br"),this.replaceField,r("replace",()=>Fb(e),[un(e,"replace")]),r("replaceAll",()=>b7(e),[un(e,"replace all")])],Ke("button",{name:"close",onclick:()=>LS(e),"aria-label":un(e,"close"),type:"button"},["×"])])}commit(){let e=new ES({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:$a.of(e)}))}keydown(e){$M(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?iu:su)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Fb(this.view))}update(e){for(let n of e.transactions)for(let r of n.effects)r.is($a)&&!r.value.eq(this.query)&&this.setQuery(r.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(So).top}}function un(t,e){return t.state.phrase(e)}const $c=30,Bc=/[\s\.,:;?!]/;function vg(t,{from:e,to:n}){let r=t.state.doc.lineAt(e),s=t.state.doc.lineAt(n).to,i=Math.max(r.from,e-$c),o=Math.min(s,n+$c),a=t.state.sliceDoc(i,o);if(i!=r.from){for(let l=0;l<$c;l++)if(!Bc.test(a[l+1])&&Bc.test(a[l])){a=a.slice(l);break}}if(o!=s){for(let l=a.length-1;l>a.length-$c;l--)if(!Bc.test(a[l-1])&&Bc.test(a[l])){a=a.slice(0,l);break}}return ae.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${r.number}.`)}const w7=ae.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),k7=[xs,hi.low(m7),w7];class RS{constructor(e,n,r,s){this.state=e,this.pos=n,this.explicit=r,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let n=Ht(this.state).resolveInner(this.pos,-1);for(;n&&e.indexOf(n.name)<0;)n=n.parent;return n?{from:n.from,to:this.pos,text:this.state.sliceDoc(n.from,this.pos),type:n.type}:null}matchBefore(e){let n=this.state.doc.lineAt(this.pos),r=Math.max(n.from,this.pos-250),s=n.text.slice(r-n.from,this.pos-n.from),i=s.search(_S(e,!1));return i<0?null:{from:r+i,to:this.pos,text:s.slice(i)}}get aborted(){return this.abortListeners==null}addEventListener(e,n,r){e=="abort"&&this.abortListeners&&(this.abortListeners.push(n),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function zb(t){let e=Object.keys(t).join(""),n=/\w/.test(e);return n&&(e=e.replace(/\w/g,"")),`[${n?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function S7(t){let e=Object.create(null),n=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let i=1;i<s.length;i++)n[s[i]]=!0}let r=zb(e)+zb(n)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function C7(t){let e=t.map(s=>typeof s=="string"?{label:s}:s),[n,r]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:S7(e);return s=>{let i=s.matchBefore(r);return i||s.explicit?{from:i?i.from:s.pos,options:e,validFor:n}:null}}class Vb{constructor(e,n,r,s){this.completion=e,this.source=n,this.match=r,this.score=s}}function Qs(t){return t.selection.main.from}function _S(t,e){var n;let{source:r}=t,s=e&&r[0]!="^",i=r[r.length-1]!="$";return!s&&!i?t:new RegExp(`${s?"^":""}(?:${r})${i?"$":""}`,(n=t.flags)!==null&&n!==void 0?n:t.ignoreCase?"i":"")}const IS=Pr.define();function j7(t,e,n,r){let{main:s}=t.selection,i=n-s.from,o=r-s.from;return{...t.changeByRange(a=>{if(a!=s&&n!=r&&t.sliceDoc(a.from+i,a.from+o)!=t.sliceDoc(n,r))return{range:a};let l=t.toText(e);return{changes:{from:a.from+i,to:r==s.from?a.to:a.from+o,insert:l},range:q.cursor(a.from+i+l.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Hb=new WeakMap;function N7(t){if(!Array.isArray(t))return t;let e=Hb.get(t);return e||Hb.set(t,e=C7(t)),e}const ou=Ee.define(),Ba=Ee.define();class P7{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let n=0;n<e.length;){let r=tn(e,n),s=gr(r);this.chars.push(r);let i=e.slice(n,n+s),o=i.toUpperCase();this.folded.push(tn(o==i?i.toLowerCase():o,0)),n+=s}this.astral=e.length!=this.chars.length}ret(e,n){return this.score=e,this.matched=n,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:n,folded:r,any:s,precise:i,byWord:o}=this;if(n.length==1){let w=tn(e,0),v=gr(w),k=v==e.length?0:-100;if(w!=n[0])if(w==r[0])k+=-200;else return null;return this.ret(k,[0,v])}let a=e.indexOf(this.pattern);if(a==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let l=n.length,d=0;if(a<0){for(let w=0,v=Math.min(e.length,200);w<v&&d<l;){let k=tn(e,w);(k==n[d]||k==r[d])&&(s[d++]=w),w+=gr(k)}if(d<l)return null}let u=0,h=0,f=!1,p=0,m=-1,x=-1,b=/[a-z]/.test(e),y=!0;for(let w=0,v=Math.min(e.length,200),k=0;w<v&&h<l;){let C=tn(e,w);a<0&&(u<l&&C==n[u]&&(i[u++]=w),p<l&&(C==n[p]||C==r[p]?(p==0&&(m=w),x=w+1,p++):p=0));let j,S=C<255?C>=48&&C<=57||C>=97&&C<=122?2:C>=65&&C<=90?1:0:(j=qm(C))!=j.toLowerCase()?1:j!=j.toUpperCase()?2:0;(!w||S==1&&b||k==0&&S!=0)&&(n[h]==C||r[h]==C&&(f=!0)?o[h++]=w:o.length&&(y=!1)),k=S,w+=gr(C)}return h==l&&o[0]==0&&y?this.result(-100+(f?-200:0),o,e):p==l&&m==0?this.ret(-200-e.length+(x==e.length?0:-100),[0,x]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):p==l?this.ret(-900-e.length,[m,x]):h==l?this.result(-100+(f?-200:0)+-700+(y?0:-1100),o,e):n.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,n,r){let s=[],i=0;for(let o of n){let a=o+(this.astral?gr(tn(r,o)):1);i&&s[i-1]==o?s[i-1]=a:(s[i++]=o,s[i++]=a)}return this.ret(e-r.length,s)}}class O7{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let n=e.slice(0,this.pattern.length),r=n==this.pattern?0:n.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,n.length],this.score=r+(e.length==this.pattern.length?0:-100),this)}}const Pt=me.define({combine(t){return Or(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:E7,filterStrict:!1,compareCompletions:(e,n)=>(e.sortText||e.label).localeCompare(n.sortText||n.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,n)=>e&&n,closeOnBlur:(e,n)=>e&&n,icons:(e,n)=>e&&n,tooltipClass:(e,n)=>r=>Wb(e(r),n(r)),optionClass:(e,n)=>r=>Wb(e(r),n(r)),addToOptions:(e,n)=>e.concat(n),filterStrict:(e,n)=>e||n})}});function Wb(t,e){return t?e?t+" "+e:t:e}function E7(t,e,n,r,s,i){let o=t.textDirection==Ye.RTL,a=o,l=!1,d="top",u,h,f=e.left-s.left,p=s.right-e.right,m=r.right-r.left,x=r.bottom-r.top;if(a&&f<Math.min(m,p)?a=!1:!a&&p<Math.min(m,f)&&(a=!0),m<=(a?f:p))u=Math.max(s.top,Math.min(n.top,s.bottom-x))-e.top,h=Math.min(400,a?f:p);else{l=!0,h=Math.min(400,(o?e.right:s.right-e.left)-30);let w=s.bottom-e.bottom;w>=x||w>e.top?u=n.bottom-e.top:(d="bottom",u=e.bottom-n.top)}let b=(e.bottom-e.top)/i.offsetHeight,y=(e.right-e.left)/i.offsetWidth;return{style:`${d}: ${u/b}px; max-width: ${h/y}px`,class:"cm-completionInfo-"+(l?o?"left-narrow":"right-narrow":a?"left":"right")}}function D7(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(n){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),n.type&&r.classList.add(...n.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),r.setAttribute("aria-hidden","true"),r},position:20}),e.push({render(n,r,s,i){let o=document.createElement("span");o.className="cm-completionLabel";let a=n.displayLabel||n.label,l=0;for(let d=0;d<i.length;){let u=i[d++],h=i[d++];u>l&&o.appendChild(document.createTextNode(a.slice(l,u)));let f=o.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(a.slice(u,h))),f.className="cm-completionMatchedText",l=h}return l<a.length&&o.appendChild(document.createTextNode(a.slice(l))),o},position:50},{render(n){if(!n.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=n.detail,r},position:80}),e.sort((n,r)=>n.position-r.position).map(n=>n.render)}function ef(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let s=Math.floor(e/n);return{from:s*n,to:(s+1)*n}}let r=Math.floor((t-e)/n);return{from:t-(r+1)*n,to:t-r*n}}class A7{constructor(e,n,r){this.view=e,this.stateField=n,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:l=>this.placeInfo(l),key:this},this.space=null,this.currentClass="";let s=e.state.field(n),{options:i,selected:o}=s.open,a=e.state.facet(Pt);this.optionContent=D7(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=ef(i.length,o,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",l=>{let{options:d}=e.state.field(n).open;for(let u=l.target,h;u&&u!=this.dom;u=u.parentNode)if(u.nodeName=="LI"&&(h=/-(\d+)$/.exec(u.id))&&+h[1]<d.length){this.applyCompletion(e,d[+h[1]]),l.preventDefault();return}}),this.dom.addEventListener("focusout",l=>{let d=e.state.field(this.stateField,!1);d&&d.tooltip&&e.state.facet(Pt).closeOnBlur&&l.relatedTarget!=e.contentDOM&&e.dispatch({effects:Ba.of(null)})}),this.showOptions(i,s.id)}mount(){this.updateSel()}showOptions(e,n){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,n,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var n;let r=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),r!=s){let{options:i,selected:o,disabled:a}=r.open;(!s.open||s.open.options!=i)&&(this.range=ef(i.length,o,e.state.facet(Pt).maxRenderedOptions),this.showOptions(i,r.id)),this.updateSel(),a!=((n=s.open)===null||n===void 0?void 0:n.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let n=this.tooltipClass(e);if(n!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of n.split(" "))r&&this.dom.classList.add(r);this.currentClass=n}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),n=e.open;(n.selected>-1&&n.selected<this.range.from||n.selected>=this.range.to)&&(this.range=ef(n.options.length,n.selected,this.view.state.facet(Pt).maxRenderedOptions),this.showOptions(n.options,e.id));let r=this.updateSelectedOption(n.selected);if(r){this.destroyInfo();let{completion:s}=n.options[n.selected],{info:i}=s;if(!i)return;let o=typeof i=="string"?document.createTextNode(i):i(s);if(!o)return;"then"in o?o.then(a=>{a&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(a,s)}).catch(a=>sn(this.view.state,a,"completion info")):(this.addInfoPane(o,s),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,n){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)r.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:i}=e;r.appendChild(s),this.infoDestroy=i||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let n=null;for(let r=this.list.firstChild,s=this.range.from;r;r=r.nextSibling,s++)r.nodeName!="LI"||!r.id?s--:s==e?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),n=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return n&&T7(this.list,n),n}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let n=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),i=this.space;if(!i){let o=this.dom.ownerDocument.documentElement;i={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(i.bottom,n.bottom)-10||s.bottom<Math.max(i.top,n.top)+10?null:this.view.state.facet(Pt).positionInfo(this.view,n,s,r,i,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,n,r){const s=document.createElement("ul");s.id=n,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let i=null;for(let o=r.from;o<r.to;o++){let{completion:a,match:l}=e[o],{section:d}=a;if(d){let f=typeof d=="string"?d:d.name;if(f!=i&&(o>r.from||r.from==0))if(i=f,typeof d!="string"&&d.header)s.appendChild(d.header(d));else{let p=s.appendChild(document.createElement("completion-section"));p.textContent=f}}const u=s.appendChild(document.createElement("li"));u.id=n+"-"+o,u.setAttribute("role","option");let h=this.optionClass(a);h&&(u.className=h);for(let f of this.optionContent){let p=f(a,this.view.state,this.view,l);p&&u.appendChild(p)}}return r.from&&s.classList.add("cm-completionListIncompleteTop"),r.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function M7(t,e){return n=>new A7(n,t,e)}function T7(t,e){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),s=n.height/t.offsetHeight;r.top<n.top?t.scrollTop-=(n.top-r.top)/s:r.bottom>n.bottom&&(t.scrollTop+=(r.bottom-n.bottom)/s)}function Ub(t){return(t.boost||0)*100+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}function L7(t,e){let n=[],r=null,s=null,i=u=>{n.push(u);let{section:h}=u.completion;if(h){r||(r=[]);let f=typeof h=="string"?h:h.name;r.some(p=>p.name==f)||r.push(typeof h=="string"?{name:f}:h)}},o=e.facet(Pt);for(let u of t)if(u.hasResult()){let h=u.result.getMatch;if(u.result.filter===!1)for(let f of u.result.options)i(new Vb(f,u.source,h?h(f):[],1e9-n.length));else{let f=e.sliceDoc(u.from,u.to),p,m=o.filterStrict?new O7(f):new P7(f);for(let x of u.result.options)if(p=m.match(x.label)){let b=x.displayLabel?h?h(x,p.matched):[]:p.matched,y=p.score+(x.boost||0);if(i(new Vb(x,u.source,b,y)),typeof x.section=="object"&&x.section.rank==="dynamic"){let{name:w}=x.section;s||(s=Object.create(null)),s[w]=Math.max(y,s[w]||-1e9)}}}}if(r){let u=Object.create(null),h=0,f=(p,m)=>(p.rank==="dynamic"&&m.rank==="dynamic"?s[m.name]-s[p.name]:0)||(typeof p.rank=="number"?p.rank:1e9)-(typeof m.rank=="number"?m.rank:1e9)||(p.name<m.name?-1:1);for(let p of r.sort(f))h-=1e5,u[p.name]=h;for(let p of n){let{section:m}=p.completion;m&&(p.score+=u[typeof m=="string"?m:m.name])}}let a=[],l=null,d=o.compareCompletions;for(let u of n.sort((h,f)=>f.score-h.score||d(h.completion,f.completion))){let h=u.completion;!l||l.label!=h.label||l.detail!=h.detail||l.type!=null&&h.type!=null&&l.type!=h.type||l.apply!=h.apply||l.boost!=h.boost?a.push(u):Ub(u.completion)>Ub(l)&&(a[a.length-1]=u),l=u.completion}return a}class Mi{constructor(e,n,r,s,i,o){this.options=e,this.attrs=n,this.tooltip=r,this.timestamp=s,this.selected=i,this.disabled=o}setSelected(e,n){return e==this.selected||e>=this.options.length?this:new Mi(this.options,Kb(n,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,n,r,s,i,o){if(s&&!o&&e.some(d=>d.isPending))return s.setDisabled();let a=L7(e,n);if(!a.length)return s&&e.some(d=>d.isPending)?s.setDisabled():null;let l=n.facet(Pt).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let d=s.options[s.selected].completion;for(let u=0;u<a.length;u++)if(a[u].completion==d){l=u;break}}return new Mi(a,Kb(r,l),{pos:e.reduce((d,u)=>u.hasResult()?Math.min(d,u.from):d,1e8),create:F7,above:i.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(e){return new Mi(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Mi(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class au{constructor(e,n,r){this.active=e,this.id=n,this.open=r}static start(){return new au($7,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:n}=e,r=n.facet(Pt),i=(r.override||n.languageDataAt("autocomplete",Qs(n)).map(N7)).map(l=>(this.active.find(u=>u.source==l)||new Tn(l,this.active.some(u=>u.state!=0)?1:0)).update(e,r));i.length==this.active.length&&i.every((l,d)=>l==this.active[d])&&(i=this.active);let o=this.open,a=e.effects.some(l=>l.is(wg));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||i.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!R7(i,this.active)||a?o=Mi.build(i,n,this.id,o,r,a):o&&o.disabled&&!i.some(l=>l.isPending)&&(o=null),!o&&i.every(l=>!l.isPending)&&i.some(l=>l.hasResult())&&(i=i.map(l=>l.hasResult()?new Tn(l.source,0):l));for(let l of e.effects)l.is(BS)&&(o=o&&o.setSelected(l.value,this.id));return i==this.active&&o==this.open?this:new au(i,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?_7:I7}}function R7(t,e){if(t==e)return!0;for(let n=0,r=0;;){for(;n<t.length&&!t[n].hasResult();)n++;for(;r<e.length&&!e[r].hasResult();)r++;let s=n==t.length,i=r==e.length;if(s||i)return s==i;if(t[n++].result!=e[r++].result)return!1}}const _7={"aria-autocomplete":"list"},I7={};function Kb(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const $7=[];function $S(t,e){if(t.isUserEvent("input.complete")){let r=t.annotation(IS);if(r&&e.activateOnCompletion(r))return 12}let n=t.isUserEvent("input.type");return n&&e.activateOnTyping?5:n?1:t.isUserEvent("delete.backward")?2:t.selection?8:t.docChanged?16:0}class Tn{constructor(e,n,r=!1){this.source=e,this.state=n,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(e,n){let r=$S(e,n),s=this;(r&8||r&16&&this.touches(e))&&(s=new Tn(s.source,0)),r&4&&s.state==0&&(s=new Tn(this.source,1)),s=s.updateFor(e,r);for(let i of e.effects)if(i.is(ou))s=new Tn(s.source,1,i.value);else if(i.is(Ba))s=new Tn(s.source,0);else if(i.is(wg))for(let o of i.value)o.source==s.source&&(s=o);return s}updateFor(e,n){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(Qs(e.state))}}class Wi extends Tn{constructor(e,n,r,s,i,o){super(e,3,n),this.limit=r,this.result=s,this.from=i,this.to=o}hasResult(){return!0}updateFor(e,n){var r;if(!(n&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let i=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),a=Qs(e.state);if(a>o||!s||n&2&&(Qs(e.startState)==this.from||a<this.limit))return new Tn(this.source,n&4?1:0);let l=e.changes.mapPos(this.limit);return B7(s.validFor,e.state,i,o)?new Wi(this.source,this.explicit,l,s,i,o):s.update&&(s=s.update(s,i,o,new RS(e.state,a,!1)))?new Wi(this.source,this.explicit,l,s,s.from,(r=s.to)!==null&&r!==void 0?r:Qs(e.state)):new Tn(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new Wi(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Tn(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function B7(t,e,n,r){if(!t)return!1;let s=e.sliceDoc(n,r);return typeof t=="function"?t(s,n,r,e):_S(t,!0).test(s)}const wg=Ee.define({map(t,e){return t.map(n=>n.map(e))}}),BS=Ee.define(),nn=Bt.define({create(){return au.start()},update(t,e){return t.update(e)},provide:t=>[dg.from(t,e=>e.tooltip),ae.contentAttributes.from(t,e=>e.attrs)]});function kg(t,e){const n=e.completion.apply||e.completion.label;let r=t.state.field(nn).active.find(s=>s.source==e.source);return r instanceof Wi?(typeof n=="string"?t.dispatch({...j7(t.state,n,r.from,r.to),annotations:IS.of(e.completion)}):n(t,e.completion,r.from,r.to),!0):!1}const F7=M7(nn,kg);function Fc(t,e="option"){return n=>{let r=n.state.field(nn,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<n.state.facet(Pt).interactionDelay)return!1;let s=1,i;e=="page"&&(i=O2(n,r.open.tooltip))&&(s=Math.max(2,Math.floor(i.dom.offsetHeight/i.dom.querySelector("li").offsetHeight)-1));let{length:o}=r.open.options,a=r.open.selected>-1?r.open.selected+s*(t?1:-1):t?0:o-1;return a<0?a=e=="page"?0:o-1:a>=o&&(a=e=="page"?o-1:0),n.dispatch({effects:BS.of(a)}),!0}}const z7=t=>{let e=t.state.field(nn,!1);return t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(Pt).interactionDelay?!1:kg(t,e.open.options[e.open.selected])},tf=t=>t.state.field(nn,!1)?(t.dispatch({effects:ou.of(!0)}),!0):!1,V7=t=>{let e=t.state.field(nn,!1);return!e||!e.active.some(n=>n.state!=0)?!1:(t.dispatch({effects:Ba.of(null)}),!0)};class H7{constructor(e,n){this.active=e,this.context=n,this.time=Date.now(),this.updates=[],this.done=void 0}}const W7=50,U7=1e3,K7=ut.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(nn).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(nn),n=t.state.facet(Pt);if(!t.selectionSet&&!t.docChanged&&t.startState.field(nn)==e)return;let r=t.transactions.some(i=>{let o=$S(i,n);return o&8||(i.selection||i.docChanged)&&!(o&3)});for(let i=0;i<this.running.length;i++){let o=this.running[i];if(r||o.context.abortOnDocChange&&t.docChanged||o.updates.length+t.transactions.length>W7&&Date.now()-o.time>U7){for(let a of o.context.abortListeners)try{a()}catch(l){sn(this.view.state,l)}o.context.abortListeners=null,this.running.splice(i--,1)}else o.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(i=>i.effects.some(o=>o.is(ou)))&&(this.pendingStart=!0);let s=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(i=>i.isPending&&!this.running.some(o=>o.active.source==i.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let i of t.transactions)i.isUserEvent("input.type")?this.composing=2:this.composing==2&&i.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(nn);for(let n of e.active)n.isPending&&!this.running.some(r=>r.active.source==n.source)&&this.startQuery(n);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pt).updateSyncTime))}startQuery(t){let{state:e}=this.view,n=Qs(e),r=new RS(e,n,t.explicit,this.view),s=new H7(t,r);this.running.push(s),Promise.resolve(t.source(r)).then(i=>{s.context.aborted||(s.done=i||null,this.scheduleAccept())},i=>{this.view.dispatch({effects:Ba.of(null)}),sn(this.view.state,i)})}scheduleAccept(){this.running.every(t=>t.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Pt).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(Pt),r=this.view.state.field(nn);for(let s=0;s<this.running.length;s++){let i=this.running[s];if(i.done===void 0)continue;if(this.running.splice(s--,1),i.done){let a=Qs(i.updates.length?i.updates[0].startState:this.view.state),l=Math.min(a,i.done.from+(i.active.explicit?0:1)),d=new Wi(i.active.source,i.active.explicit,l,i.done,i.done.from,(t=i.done.to)!==null&&t!==void 0?t:a);for(let u of i.updates)d=d.update(u,n);if(d.hasResult()){e.push(d);continue}}let o=r.active.find(a=>a.source==i.active.source);if(o&&o.isPending)if(i.done==null){let a=new Tn(i.active.source,0);for(let l of i.updates)a=a.update(l,n);a.isPending||e.push(a)}else this.startQuery(o)}(e.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:wg.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(nn,!1);if(e&&e.tooltip&&this.view.state.facet(Pt).closeOnBlur){let n=e.open&&O2(this.view,e.open.tooltip);(!n||!n.dom.contains(t.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Ba.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:ou.of(!1)}),20),this.composing=0}}}),G7=typeof navigator=="object"&&/Win/.test(navigator.platform),q7=hi.highest(ae.domEventHandlers({keydown(t,e){let n=e.state.field(nn,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||t.key.length>1||t.ctrlKey&&!(G7&&t.altKey)||t.metaKey)return!1;let r=n.open.options[n.open.selected],s=n.active.find(o=>o.source==r.source),i=r.completion.commitCharacters||s.result.commitCharacters;return i&&i.indexOf(t.key)>-1&&kg(e,r),!1}})),Y7=ae.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),Fa={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Ys=Ee.define({map(t,e){let n=e.mapPos(t,-1,Gt.TrackAfter);return n??void 0}}),Sg=new class extends ks{};Sg.startSide=1;Sg.endSide=-1;const FS=Bt.define({create(){return Le.empty},update(t,e){if(t=t.map(e.changes),e.selection){let n=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:r=>r>=n.from&&r<=n.to})}for(let n of e.effects)n.is(Ys)&&(t=t.update({add:[Sg.range(n.value,n.value+1)]}));return t}});function X7(){return[Q7,FS]}const nf="()[]{}<>«»»«[]{}";function zS(t){for(let e=0;e<nf.length;e+=2)if(nf.charCodeAt(e)==t)return nf.charAt(e+1);return qm(t<128?t:t+1)}function VS(t,e){return t.languageDataAt("closeBrackets",e)[0]||Fa}const Z7=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Q7=ae.inputHandler.of((t,e,n,r)=>{if((Z7?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let s=t.state.selection.main;if(r.length>2||r.length==2&&gr(tn(r,0))==1||e!=s.from||n!=s.to)return!1;let i=t8(t.state,r);return i?(t.dispatch(i),!0):!1}),J7=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=VS(t,t.selection.main.head).brackets||Fa.brackets,s=null,i=t.changeByRange(o=>{if(o.empty){let a=n8(t.doc,o.head);for(let l of r)if(l==a&&Zu(t.doc,o.head)==zS(tn(l,0)))return{changes:{from:o.head-l.length,to:o.head+l.length},range:q.cursor(o.head-l.length)}}return{range:s=o}});return s||e(t.update(i,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},e8=[{key:"Backspace",run:J7}];function t8(t,e){let n=VS(t,t.selection.main.head),r=n.brackets||Fa.brackets;for(let s of r){let i=zS(tn(s,0));if(e==s)return i==s?i8(t,s,r.indexOf(s+s+s)>-1,n):r8(t,s,i,n.before||Fa.before);if(e==i&&HS(t,t.selection.main.from))return s8(t,s,i)}return null}function HS(t,e){let n=!1;return t.field(FS).between(0,t.doc.length,r=>{r==e&&(n=!0)}),n}function Zu(t,e){let n=t.sliceString(e,e+2);return n.slice(0,gr(tn(n,0)))}function n8(t,e){let n=t.sliceString(e-2,e);return gr(tn(n,0))==n.length?n:n.slice(1)}function r8(t,e,n,r){let s=null,i=t.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:n,from:o.to}],effects:Ys.of(o.to+e.length),range:q.range(o.anchor+e.length,o.head+e.length)};let a=Zu(t.doc,o.head);return!a||/\s/.test(a)||r.indexOf(a)>-1?{changes:{insert:e+n,from:o.head},effects:Ys.of(o.head+e.length),range:q.cursor(o.head+e.length)}:{range:s=o}});return s?null:t.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function s8(t,e,n){let r=null,s=t.changeByRange(i=>i.empty&&Zu(t.doc,i.head)==n?{changes:{from:i.head,to:i.head+n.length,insert:n},range:q.cursor(i.head+n.length)}:r={range:i});return r?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function i8(t,e,n,r){let s=r.stringPrefixes||Fa.stringPrefixes,i=null,o=t.changeByRange(a=>{if(!a.empty)return{changes:[{insert:e,from:a.from},{insert:e,from:a.to}],effects:Ys.of(a.to+e.length),range:q.range(a.anchor+e.length,a.head+e.length)};let l=a.head,d=Zu(t.doc,l),u;if(d==e){if(Gb(t,l))return{changes:{insert:e+e,from:l},effects:Ys.of(l+e.length),range:q.cursor(l+e.length)};if(HS(t,l)){let f=n&&t.sliceDoc(l,l+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+f.length,insert:f},range:q.cursor(l+f.length)}}}else{if(n&&t.sliceDoc(l-2*e.length,l)==e+e&&(u=qb(t,l-2*e.length,s))>-1&&Gb(t,u))return{changes:{insert:e+e+e+e,from:l},effects:Ys.of(l+e.length),range:q.cursor(l+e.length)};if(t.charCategorizer(l)(d)!=Je.Word&&qb(t,l,s)>-1&&!o8(t,l,e,s))return{changes:{insert:e+e,from:l},effects:Ys.of(l+e.length),range:q.cursor(l+e.length)}}return{range:i=a}});return i?null:t.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Gb(t,e){let n=Ht(t).resolveInner(e+1);return n.parent&&n.from==e}function o8(t,e,n,r){let s=Ht(t).resolveInner(e,-1),i=r.reduce((o,a)=>Math.max(o,a.length),0);for(let o=0;o<5;o++){let a=t.sliceDoc(s.from,Math.min(s.to,s.from+n.length+i)),l=a.indexOf(n);if(!l||l>-1&&r.indexOf(a.slice(0,l))>-1){let u=s.firstChild;for(;u&&u.from==s.from&&u.to-u.from>n.length+l;){if(t.sliceDoc(u.to-n.length,u.to)==n)return!1;u=u.firstChild}return!0}let d=s.to==e&&s.parent;if(!d)break;s=d}return!1}function qb(t,e,n){let r=t.charCategorizer(e);if(r(t.sliceDoc(e-1,e))!=Je.Word)return e;for(let s of n){let i=e-s.length;if(t.sliceDoc(i,e)==s&&r(t.sliceDoc(i-1,i))!=Je.Word)return i}return-1}function a8(t={}){return[q7,nn,Pt.of(t),K7,l8,Y7]}const WS=[{key:"Ctrl-Space",run:tf},{mac:"Alt-`",run:tf},{mac:"Alt-i",run:tf},{key:"Escape",run:V7},{key:"ArrowDown",run:Fc(!0)},{key:"ArrowUp",run:Fc(!1)},{key:"PageDown",run:Fc(!0,"page")},{key:"PageUp",run:Fc(!1,"page")},{key:"Enter",run:z7}],l8=hi.highest(Vu.computeN([Pt],t=>t.facet(Pt).defaultKeymap?[WS]:[]));class Yb{constructor(e,n,r){this.from=e,this.to=n,this.diagnostic=r}}class Vs{constructor(e,n,r){this.diagnostics=e,this.panel=n,this.selected=r}static init(e,n,r){let s=r.facet(za).markerFilter;s&&(e=s(e,r));let i=e.slice().sort((p,m)=>p.from-m.from||p.to-m.to),o=new Ur,a=[],l=0,d=r.doc.iter(),u=0,h=r.doc.length;for(let p=0;;){let m=p==i.length?null:i[p];if(!m&&!a.length)break;let x,b;if(a.length)x=l,b=a.reduce((v,k)=>Math.min(v,k.to),m&&m.from>x?m.from:1e8);else{if(x=m.from,x>h)break;b=m.to,a.push(m),p++}for(;p<i.length;){let v=i[p];if(v.from==x&&(v.to>v.from||v.to==x))a.push(v),p++,b=Math.min(v.to,b);else{b=Math.min(v.from,b);break}}b=Math.min(b,h);let y=!1;if(a.some(v=>v.from==x&&(v.to==b||b==h))&&(y=x==b,!y&&b-x<10)){let v=x-(u+d.value.length);v>0&&(d.next(v),u=x);for(let k=x;;){if(k>=b){y=!0;break}if(!d.lineBreak&&u+d.value.length>k)break;k=u+d.value.length,u+=d.value.length,d.next()}}let w=w8(a);if(y)o.add(x,x,Ce.widget({widget:new x8(w),diagnostics:a.slice()}));else{let v=a.reduce((k,C)=>C.markClass?k+" "+C.markClass:k,"");o.add(x,b,Ce.mark({class:"cm-lintRange cm-lintRange-"+w+v,diagnostics:a.slice(),inclusiveEnd:a.some(k=>k.to>b)}))}if(l=b,l==h)break;for(let v=0;v<a.length;v++)a[v].to<=l&&a.splice(v--,1)}let f=o.finish();return new Vs(f,n,ao(f))}}function ao(t,e=null,n=0){let r=null;return t.between(n,1e9,(s,i,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!r)r=new Yb(s,i,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new Yb(r.from,i,r.diagnostic)}}),r}function c8(t,e){let n=e.pos,r=e.end||n,s=t.state.facet(za).hideOn(t,n,r);if(s!=null)return s;let i=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(o=>o.is(US))||t.changes.touchesRange(i.from,Math.max(i.to,r)))}function d8(t,e){return t.field(gn,!1)?e:e.concat(Ee.appendConfig.of(k8))}const US=Ee.define(),Cg=Ee.define(),KS=Ee.define(),gn=Bt.define({create(){return new Vs(Ce.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let n=t.diagnostics.map(e.changes),r=null,s=t.panel;if(t.selected){let i=e.changes.mapPos(t.selected.from,1);r=ao(n,t.selected.diagnostic,i)||ao(n,null,i)}!n.size&&s&&e.state.facet(za).autoPanel&&(s=null),t=new Vs(n,s,r)}for(let n of e.effects)if(n.is(US)){let r=e.state.facet(za).autoPanel?n.value.length?Va.open:null:t.panel;t=Vs.init(n.value,r,e.state)}else n.is(Cg)?t=new Vs(t.diagnostics,n.value?Va.open:null,t.selected):n.is(KS)&&(t=new Vs(t.diagnostics,t.panel,n.value));return t},provide:t=>[_a.from(t,e=>e.panel),ae.decorations.from(t,e=>e.diagnostics)]}),u8=Ce.mark({class:"cm-lintRange cm-lintRange-active"});function h8(t,e,n){let{diagnostics:r}=t.state.field(gn),s,i=-1,o=-1;r.between(e-(n<0?1:0),e+(n>0?1:0),(l,d,{spec:u})=>{if(e>=l&&e<=d&&(l==d||(e>l||n>0)&&(e<d||n<0)))return s=u.diagnostics,i=l,o=d,!1});let a=t.state.facet(za).tooltipFilter;return s&&a&&(s=a(s,t.state)),s?{pos:i,end:o,above:t.state.doc.lineAt(i).to<o,create(){return{dom:f8(t,s)}}}:null}function f8(t,e){return Ke("ul",{class:"cm-tooltip-lint"},e.map(n=>qS(t,n,!1)))}const p8=t=>{let e=t.state.field(gn,!1);(!e||!e.panel)&&t.dispatch({effects:d8(t.state,[Cg.of(!0)])});let n=Ra(t,Va.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},Xb=t=>{let e=t.state.field(gn,!1);return!e||!e.panel?!1:(t.dispatch({effects:Cg.of(!1)}),!0)},m8=t=>{let e=t.state.field(gn,!1);if(!e)return!1;let n=t.state.selection.main,r=e.diagnostics.iter(n.to+1);return!r.value&&(r=e.diagnostics.iter(0),!r.value||r.from==n.from&&r.to==n.to)?!1:(t.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)},g8=[{key:"Mod-Shift-m",run:p8,preventDefault:!0},{key:"F8",run:m8}],za=me.define({combine(t){return{sources:t.map(e=>e.source).filter(e=>e!=null),...Or(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Zb,tooltipFilter:Zb,needsRefresh:(e,n)=>e?n?r=>e(r)||n(r):e:n,hideOn:(e,n)=>e?n?(r,s,i)=>e(r,s,i)||n(r,s,i):e:n,autoPanel:(e,n)=>e||n})}}});function Zb(t,e){return t?e?(n,r)=>e(t(n,r),r):t:e}function GS(t){let e=[];if(t)e:for(let{name:n}of t){for(let r=0;r<n.length;r++){let s=n[r];if(/[a-zA-Z]/.test(s)&&!e.some(i=>i.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function qS(t,e,n){var r;let s=n?GS(e.actions):[];return Ke("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Ke("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(r=e.actions)===null||r===void 0?void 0:r.map((i,o)=>{let a=!1,l=p=>{if(p.preventDefault(),a)return;a=!0;let m=ao(t.state.field(gn).diagnostics,e);m&&i.apply(t,m.from,m.to)},{name:d}=i,u=s[o]?d.indexOf(s[o]):-1,h=u<0?d:[d.slice(0,u),Ke("u",d.slice(u,u+1)),d.slice(u+1)],f=i.markClass?" "+i.markClass:"";return Ke("button",{type:"button",class:"cm-diagnosticAction"+f,onclick:l,onmousedown:l,"aria-label":` Action: ${d}${u<0?"":` (access key "${s[o]})"`}.`},h)}),e.source&&Ke("div",{class:"cm-diagnosticSource"},e.source))}class x8 extends Er{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Ke("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class Qb{constructor(e,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=qS(e,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Va{constructor(e){this.view=e,this.items=[];let n=s=>{if(s.keyCode==27)Xb(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:i}=this.items[this.selectedIndex],o=GS(i.actions);for(let a=0;a<o.length;a++)if(o[a].toUpperCase().charCodeAt(0)==s.keyCode){let l=ao(this.view.state.field(gn).diagnostics,i);l&&i.actions[a].apply(e,l.from,l.to)}}else return;s.preventDefault()},r=s=>{for(let i=0;i<this.items.length;i++)this.items[i].dom.contains(s.target)&&this.moveSelection(i)};this.list=Ke("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:r}),this.dom=Ke("div",{class:"cm-panel-lint"},this.list,Ke("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Xb(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(gn).selected;if(!e)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==e.diagnostic)return n;return-1}update(){let{diagnostics:e,selected:n}=this.view.state.field(gn),r=0,s=!1,i=null,o=new Set;for(e.between(0,this.view.state.doc.length,(a,l,{spec:d})=>{for(let u of d.diagnostics){if(o.has(u))continue;o.add(u);let h=-1,f;for(let p=r;p<this.items.length;p++)if(this.items[p].diagnostic==u){h=p;break}h<0?(f=new Qb(this.view,u),this.items.splice(r,0,f),s=!0):(f=this.items[h],h>r&&(this.items.splice(r,h-r),s=!0)),n&&f.diagnostic==n.diagnostic?f.dom.hasAttribute("aria-selected")||(f.dom.setAttribute("aria-selected","true"),i=f):f.dom.hasAttribute("aria-selected")&&f.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new Qb(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),i?(this.list.setAttribute("aria-activedescendant",i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:l})=>{let d=l.height/this.list.offsetHeight;a.top<l.top?this.list.scrollTop-=(l.top-a.top)/d:a.bottom>l.bottom&&(this.list.scrollTop+=(a.bottom-l.bottom)/d)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function n(){let r=e;e=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;e!=r.dom;)n();e=r.dom.nextSibling}else this.list.insertBefore(r.dom,e);for(;e;)n()}moveSelection(e){if(this.selectedIndex<0)return;let n=this.view.state.field(gn),r=ao(n.diagnostics,this.items[e].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:KS.of(r)})}static open(e){return new Va(e)}}function b8(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}function zc(t){return b8(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const y8=ae.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:zc("#d11")},".cm-lintRange-warning":{backgroundImage:zc("orange")},".cm-lintRange-info":{backgroundImage:zc("#999")},".cm-lintRange-hint":{backgroundImage:zc("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function v8(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function w8(t){let e="hint",n=1;for(let r of t){let s=v8(r.severity);s>n&&(n=s,e=r.severity)}return e}const k8=[gn,ae.decorations.compute([gn],t=>{let{selected:e,panel:n}=t.field(gn);return!e||!n||e.from==e.to?Ce.none:Ce.set([u8.range(e.from,e.to)])}),NT(h8,{hideOn:c8}),y8];var Jb=function(e){e===void 0&&(e={});var{crosshairCursor:n=!1}=e,r=[];e.closeBracketsKeymap!==!1&&(r=r.concat(e8)),e.defaultKeymap!==!1&&(r=r.concat(GL)),e.searchKeymap!==!1&&(r=r.concat(y7)),e.historyKeymap!==!1&&(r=r.concat(eL)),e.foldKeymap!==!1&&(r=r.concat(u6)),e.completionKeymap!==!1&&(r=r.concat(WS)),e.lintKeymap!==!1&&(r=r.concat(g8));var s=[];return e.lineNumbers!==!1&&s.push(IT()),e.highlightActiveLineGutter!==!1&&s.push(FT()),e.highlightSpecialChars!==!1&&s.push(tT()),e.history!==!1&&s.push(U6()),e.foldGutter!==!1&&s.push(m6()),e.drawSelection!==!1&&s.push(WM()),e.dropCursor!==!1&&s.push(YM()),e.allowMultipleSelections!==!1&&s.push(Ie.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&s.push(t6()),e.syntaxHighlighting!==!1&&s.push(fg(y6,{fallback:!0})),e.bracketMatching!==!1&&s.push(N6()),e.closeBrackets!==!1&&s.push(X7()),e.autocompletion!==!1&&s.push(a8()),e.rectangularSelection!==!1&&s.push(mT()),n!==!1&&s.push(bT()),e.highlightActiveLine!==!1&&s.push(aT()),e.highlightSelectionMatches!==!1&&s.push(e7()),e.tabSize&&typeof e.tabSize=="number"&&s.push(Wu.of(" ".repeat(e.tabSize))),s.concat([Vu.of(r.flat())]).filter(Boolean)};const S8="#e5c07b",ey="#e06c75",C8="#56b6c2",j8="#ffffff",xd="#abb2bf",tm="#7d8799",N8="#61afef",P8="#98c379",ty="#d19a66",O8="#c678dd",E8="#21252b",ny="#2c313a",ry="#282c34",rf="#353a42",D8="#3E4451",sy="#528bff",A8=ae.theme({"&":{color:xd,backgroundColor:ry},".cm-content":{caretColor:sy},".cm-cursor, .cm-dropCursor":{borderLeftColor:sy},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:D8},".cm-panels":{backgroundColor:E8,color:xd},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:ry,color:tm,border:"none"},".cm-activeLineGutter":{backgroundColor:ny},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:rf},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:rf,borderBottomColor:rf},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:ny,color:xd}}},{dark:!0}),M8=wo.define([{tag:W.keyword,color:O8},{tag:[W.name,W.deleted,W.character,W.propertyName,W.macroName],color:ey},{tag:[W.function(W.variableName),W.labelName],color:N8},{tag:[W.color,W.constant(W.name),W.standard(W.name)],color:ty},{tag:[W.definition(W.name),W.separator],color:xd},{tag:[W.typeName,W.className,W.number,W.changed,W.annotation,W.modifier,W.self,W.namespace],color:S8},{tag:[W.operator,W.operatorKeyword,W.url,W.escape,W.regexp,W.link,W.special(W.string)],color:C8},{tag:[W.meta,W.comment],color:tm},{tag:W.strong,fontWeight:"bold"},{tag:W.emphasis,fontStyle:"italic"},{tag:W.strikethrough,textDecoration:"line-through"},{tag:W.link,color:tm,textDecoration:"underline"},{tag:W.heading,fontWeight:"bold",color:ey},{tag:[W.atom,W.bool,W.special(W.variableName)],color:ty},{tag:[W.processingInstruction,W.string,W.inserted],color:P8},{tag:W.invalid,color:j8}]),T8=[A8,fg(M8)];var L8=ae.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),R8=function(e){e===void 0&&(e={});var{indentWithTab:n=!0,editable:r=!0,readOnly:s=!1,theme:i="light",placeholder:o="",basicSetup:a=!0}=e,l=[];switch(n&&l.unshift(Vu.of([qL])),a&&(typeof a=="boolean"?l.unshift(Jb()):l.unshift(Jb(a))),o&&l.unshift(uT(o)),i){case"light":l.push(L8);break;case"dark":l.push(T8);break;case"none":break;default:l.push(i);break}return r===!1&&l.push(ae.editable.of(!1)),s&&l.push(Ie.readOnly.of(!0)),[...l]},_8=t=>({line:t.state.doc.lineAt(t.state.selection.main.from),lineCount:t.state.doc.lines,lineBreak:t.state.lineBreak,length:t.state.doc.length,readOnly:t.state.readOnly,tabSize:t.state.tabSize,selection:t.state.selection,selectionAsSingle:t.state.selection.asSingle().main,ranges:t.state.selection.ranges,selectionCode:t.state.sliceDoc(t.state.selection.main.from,t.state.selection.main.to),selections:t.state.selection.ranges.map(e=>t.state.sliceDoc(e.from,e.to)),selectedText:t.state.selection.ranges.some(e=>!e.empty)});class I8{constructor(e,n){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=n,this.timeoutMS=n,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(n=>{try{n()}catch(r){console.error("TimeoutLatch callback error:",r)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class iy{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var sf=null,$8=()=>typeof window>"u"?new iy:(sf||(sf=new iy),sf),oy=Pr.define(),B8=200,F8=[];function z8(t){var{value:e,selection:n,onChange:r,onStatistics:s,onCreateEditor:i,onUpdate:o,extensions:a=F8,autoFocus:l,theme:d="light",height:u=null,minHeight:h=null,maxHeight:f=null,width:p=null,minWidth:m=null,maxWidth:x=null,placeholder:b="",editable:y=!0,readOnly:w=!1,indentWithTab:v=!0,basicSetup:k=!0,root:C,initialState:j}=t,[S,O]=g.useState(),[D,M]=g.useState(),[P,T]=g.useState(),$=g.useState(()=>({current:null}))[0],N=g.useState(()=>({current:null}))[0],E=ae.theme({"&":{height:u,minHeight:h,maxHeight:f,width:p,minWidth:m,maxWidth:x},"& .cm-scroller":{height:"100% !important"}}),A=ae.updateListener.of(I=>{if(I.docChanged&&typeof r=="function"&&!I.transactions.some(V=>V.annotation(oy))){$.current?$.current.reset():($.current=new I8(()=>{if(N.current){var V=N.current;N.current=null,V()}$.current=null},B8),$8().add($.current));var F=I.state.doc,H=F.toString();r(H,I)}s&&s(_8(I))}),R=R8({theme:d,editable:y,readOnly:w,placeholder:b,indentWithTab:v,basicSetup:k}),_=[A,E,...R];return o&&typeof o=="function"&&_.push(ae.updateListener.of(o)),_=_.concat(a),g.useLayoutEffect(()=>{if(S&&!P){var I={doc:e,selection:n,extensions:_},F=j?Ie.fromJSON(j.json,I,j.fields):Ie.create(I);if(T(F),!D){var H=new ae({state:F,parent:S,root:C});M(H),i&&i(H,F)}}return()=>{D&&(T(void 0),M(void 0))}},[S,P]),g.useEffect(()=>{t.container&&O(t.container)},[t.container]),g.useEffect(()=>()=>{D&&(D.destroy(),M(void 0)),$.current&&($.current.cancel(),$.current=null)},[D]),g.useEffect(()=>{l&&D&&D.focus()},[l,D]),g.useEffect(()=>{D&&D.dispatch({effects:Ee.reconfigure.of(_)})},[d,a,u,h,f,p,m,x,b,y,w,v,k,r,o]),g.useEffect(()=>{if(e!==void 0){var I=D?D.state.doc.toString():"";if(D&&e!==I){var F=$.current&&!$.current.isDone,H=()=>{D&&e!==D.state.doc.toString()&&D.dispatch({changes:{from:0,to:D.state.doc.toString().length,insert:e||""},annotations:[oy.of(!0)]})};F?N.current=H:H()}}},[e,D]),{state:P,setState:T,view:D,setView:M,container:S,setContainer:O}}var V8=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],YS=g.forwardRef((t,e)=>{var{className:n,value:r="",selection:s,extensions:i=[],onChange:o,onStatistics:a,onCreateEditor:l,onUpdate:d,autoFocus:u,theme:h="light",height:f,minHeight:p,maxHeight:m,width:x,minWidth:b,maxWidth:y,basicSetup:w,placeholder:v,indentWithTab:k,editable:C,readOnly:j,root:S,initialState:O}=t,D=R6(t,V8),M=g.useRef(null),{state:P,view:T,container:$,setContainer:N}=z8({root:S,value:r,autoFocus:u,theme:h,height:f,minHeight:p,maxHeight:m,width:x,minWidth:b,maxWidth:y,basicSetup:w,placeholder:v,indentWithTab:k,editable:C,readOnly:j,selection:s,onChange:o,onStatistics:a,onCreateEditor:l,onUpdate:d,extensions:i,initialState:O});g.useImperativeHandle(e,()=>({editor:M.current,state:P,view:T}),[M,$,P,T]);var E=g.useCallback(R=>{M.current=R,N(R)},[N]);if(typeof r!="string")throw new Error("value must be typeof string but got "+typeof r);var A=typeof h=="string"?"cm-theme-"+h:"cm-theme";return c.jsx("div",qp({ref:E,className:""+A+(n?" "+n:"")},D))});YS.displayName="CodeMirror";const H8=()=>{const t=ae.theme({"&":{backgroundColor:"var(--dash-surface)",color:"var(--dash-text)",height:"100%"},".cm-editor":{height:"100% !important"},".cm-content":{color:"var(--dash-text)",caretColor:"var(--dash-accent)",fontFamily:"'JetBrains Mono', Menlo, monospace",padding:"1rem"},".cm-line":{color:"var(--dash-text)"},".cm-cursor, .cm-dropCursor":{borderLeftColor:"var(--dash-accent)"},"& ::selection":{backgroundColor:"var(--dash-accent-selection) !important",color:"inherit !important"},".cm-gutters":{backgroundColor:"var(--dash-surface)",color:"var(--dash-text-muted)",border:"none",borderRight:"1px solid var(--dash-border)",paddingRight:"0.5rem"},".cm-lineNumbers .cm-gutterElement":{padding:"0 0.5rem 0 1rem",minWidth:"3rem"},".cm-activeLineGutter":{backgroundColor:"var(--dash-accent-subtle)",color:"var(--dash-accent)",fontWeight:"600"},".cm-activeLine":{backgroundColor:"color-mix(in srgb, var(--dash-accent) 8%, transparent)"},".cm-matchingBracket":{backgroundColor:"var(--dash-accent-subtle)",outline:"1px solid var(--dash-accent)"},".cm-scroller":{overflow:"auto !important",height:"100%",maxHeight:"100%"}}),e=wo.define([{tag:W.propertyName,color:"var(--dash-accent)"},{tag:W.string,color:"color-mix(in srgb, var(--dash-accent) 70%, var(--dash-text))"},{tag:W.number,color:"var(--dash-accent-hover)"},{tag:W.bool,color:"var(--dash-accent-hover)"},{tag:W.null,color:"var(--dash-text-muted)"},{tag:W.punctuation,color:"var(--dash-text-secondary)"},{tag:W.brace,color:"var(--dash-text-secondary)"},{tag:W.bracket,color:"var(--dash-text-secondary)"}]);return[t,fg(e)]},W8=({value:t,onChange:e,onCursorLineChange:n,onEditorFocus:r,height:s="100%",readOnly:i=!1,className:o})=>{const a=g.useMemo(()=>[L6(),ae.lineWrapping,...H8()],[]),l=g.useMemo(()=>{if(n)return d=>{const u=d.state.selection.main.head,h=d.view.state.doc.lineAt(u).number-1;n(h)}},[n]);return c.jsx("div",{className:`h-full [&_.cm-editor]:h-full [&_.cm-editor]:outline-none [&_.cm-focused]:outline-none ${o??""}`.trim(),children:c.jsx(YS,{value:t,height:s,extensions:a,onChange:e,onFocus:r,onUpdate:l,theme:"none",readOnly:i,basicSetup:{lineNumbers:!0,highlightActiveLineGutter:!0,highlightActiveLine:!0,foldGutter:!1,dropCursor:!0,drawSelection:!1,allowMultipleSelections:!1,indentOnInput:!0,bracketMatching:!0,closeBrackets:!0,autocompletion:!1,rectangularSelection:!1,crosshairCursor:!1,highlightSelectionMatches:!0}})})},jg=({width:t,isLoading:e,jsonText:n,cursorLine:r,syntaxError:s,onChange:i,onEditorFocus:o,onCursorLineChange:a,readOnly:l=!1,headerTitle:d,headerPath:u,headerActions:h})=>{const{t:f}=se(),p=m=>{if(l||!m.target.closest(".cm-editor"))return;const b=m.currentTarget;b.scrollHeight<=b.clientHeight||(b.scrollTop+=m.deltaY)};return c.jsxs("div",{style:{width:`${t}%`},className:"bg-dash-surface border border-dash-border rounded-xl overflow-hidden flex flex-col shadow-sm min-w-0 h-full",children:[c.jsx("div",{className:"p-3 border-b border-dash-border bg-dash-surface-hover/50 shrink-0",children:c.jsxs("div",{className:"flex items-end justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h3",{className:"text-xs font-bold text-dash-text-secondary uppercase tracking-widest",children:d??f("jsonTab")}),u&&c.jsx("p",{className:"mt-1 mono text-[11px] text-dash-text-muted truncate",children:u})]}),h&&c.jsx("div",{className:"flex items-center gap-2 shrink-0",children:h})]})}),c.jsx("div",{className:"flex-1 min-h-0 overflow-auto",onWheelCapture:p,children:e?c.jsx("div",{className:"h-full flex items-center justify-center",children:c.jsx("div",{className:"animate-pulse text-dash-text-muted text-sm",children:f("loading")})}):l?c.jsx("pre",{className:"h-full overflow-auto p-4 font-mono text-xs leading-4 text-dash-text whitespace-pre m-0",children:n}):c.jsx(W8,{value:n,onChange:i,onEditorFocus:o,onCursorLineChange:a,readOnly:l,className:"[&_.cm-content]:text-xs [&_.cm-content]:leading-4 [&_.cm-gutters]:text-xs [&_.cm-gutters]:leading-4"})}),c.jsxs("div",{className:"px-4 py-2 bg-dash-surface-hover/30 border-t border-dash-border text-[10px] text-dash-text-muted flex justify-between uppercase tracking-widest font-bold",children:[c.jsxs("div",{className:"flex gap-4",children:[c.jsx("span",{children:"UTF-8"}),c.jsx("span",{children:"JSON"}),c.jsxs("span",{children:["L:",r+1]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[l&&c.jsx("span",{children:f("readOnly")}),s?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-red-500"}),c.jsx("span",{className:"text-red-500 normal-case",children:s})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-dash-accent"}),f("syntaxValid")]})]})]})]})},ay=({label:t,value:e})=>c.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-dash-bg border border-dash-border rounded-md",children:[c.jsxs("span",{className:"text-[9px] font-bold text-dash-text-muted uppercase",children:[t,":"]}),c.jsx("span",{className:"text-[10px] mono font-bold text-dash-text-secondary",children:e})]}),XS=({width:t,fieldDoc:e,activeFieldPath:n,extraContent:r,overrideBadge:s})=>{const{t:i,lang:o}=se(),a=e??(n?Fw[n]??{path:n,type:"unknown",default:"n/a",description:"Help is being resolved for this field. Try editing the value or switching to the JSON view for schema-based details.",descriptionVi:"Đang tải trợ giúp cho trường này. Hãy thử chỉnh sửa giá trị hoặc chuyển sang chế độ JSON để xem mô tả suy ra từ schema."}:null);return c.jsxs("div",{style:{width:`${t}%`},className:"bg-dash-surface border border-dash-border rounded-xl flex flex-col shadow-sm overflow-hidden min-w-0",children:[c.jsx("div",{className:"p-3 border-b border-dash-border bg-dash-surface-hover/50 shrink-0",children:c.jsx("h3",{className:"text-xs font-bold text-dash-text-secondary uppercase tracking-widest",children:i("configurationHelp")})}),c.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:a?c.jsxs("div",{className:"space-y-5 animate-in fade-in duration-500",children:[c.jsxs("header",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[c.jsx("span",{className:"text-[10px] bg-dash-accent-subtle text-dash-accent px-1.5 py-0.5 rounded font-mono uppercase font-bold",children:i("field")}),c.jsx("h2",{className:"text-base font-bold text-dash-text mono break-all",children:a.path}),s]}),c.jsxs("div",{className:"flex flex-wrap gap-2 mt-2",children:[c.jsx(ay,{label:i("type"),value:a.type}),c.jsx(ay,{label:i("default"),value:a.default})]})]}),c.jsxs("section",{children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-text-muted uppercase tracking-widest mb-2",children:i("description")}),c.jsx("p",{className:"text-sm text-dash-text-secondary leading-relaxed italic",children:o==="vi"?a.descriptionVi:a.description})]}),a.validValues&&c.jsxs("section",{children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-text-muted uppercase tracking-widest mb-2",children:i("validValues")}),c.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.validValues.map(l=>c.jsx("span",{className:"px-2 py-0.5 bg-dash-bg border border-dash-border rounded text-[11px] mono text-dash-text",children:l},l))})]}),a.effect&&c.jsxs("section",{className:"bg-dash-accent-subtle/30 p-3 rounded-lg border border-dash-accent/10",children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-accent uppercase tracking-widest mb-1",children:i("systemEffect")}),c.jsx("p",{className:"text-[12px] text-dash-text-secondary leading-normal",children:o==="vi"&&a.effectVi?a.effectVi:a.effect})]}),a.example&&c.jsxs("section",{children:[c.jsx("h4",{className:"text-[10px] font-bold text-dash-text-muted uppercase tracking-widest mb-2",children:i("exampleUsage")}),c.jsx("div",{className:"bg-dash-bg p-3 rounded-lg border border-dash-border overflow-hidden",children:c.jsx("pre",{className:"text-[11px] mono text-dash-text-secondary whitespace-pre overflow-x-auto",children:a.example})})]}),r]}):c.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center opacity-40 space-y-4",children:[c.jsx("div",{className:"w-10 h-10 rounded-full bg-dash-bg border border-dash-border flex items-center justify-center text-lg",children:"?"}),c.jsxs("div",{className:"max-w-[180px]",children:[c.jsx("p",{className:"text-sm font-bold text-dash-text mb-1 italic",children:i("knowledgeBase")}),c.jsx("p",{className:"text-xs text-dash-text-secondary",children:i("clickToSeeHelp")})]})]})}),a&&c.jsx("div",{className:"p-3 bg-dash-surface-hover/20 border-t border-dash-border shrink-0",children:c.jsxs("p",{className:"text-[10px] text-dash-text-muted font-medium flex items-center gap-1.5 italic",children:[c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),i("extractedFrom")]})})]})},U8=({variant:t="development"})=>{const{t:e}=se(),n={development:e("developmentFeature"),beta:e("betaFeature"),experimental:e("experimentalFeature")};return c.jsx("span",{className:"text-[9px] bg-orange-500/10 text-orange-500 px-2 py-0.5 rounded-full font-bold border border-orange-500/30 uppercase tracking-wider",children:n[t]})},ly={codex:{heavy:{model:"gpt-5.4",effort:"xhigh"},balanced:{model:"gpt-5.4",effort:"high"},light:{model:"gpt-5.4-mini",effort:"medium"}},"gemini-cli":{heavy:{model:"gemini-3.1-pro-preview"},balanced:{model:"gemini-3.1-pro-preview"},light:{model:"gemini-3-flash-preview"}}},K8={codex:"Codex","gemini-cli":"Gemini CLI"},cy=["heavy","balanced","light"];function dy(t,e){return e.split(".").reduce((n,r)=>{if(n!=null&&typeof n=="object"&&r in n)return n[r]},t)}const uy="bg-transparent border border-dash-border rounded px-2 py-1 text-sm text-dash-text placeholder:text-dash-text-muted focus:border-dash-accent focus:outline-none w-full",G8=({config:t,onChange:e})=>{const{t:n}=se(),[r,s]=g.useState(!1),i=(l,d,u,h)=>{const f=`modelTaxonomy.${l}.${d}.${u}`;e(f,h===""?void 0:h)},o=l=>{for(const d of cy)e(`modelTaxonomy.${l}.${d}.model`,void 0),ly[l]?.[d]?.effort!==void 0&&e(`modelTaxonomy.${l}.${d}.effort`,void 0)},a=l=>n(l==="heavy"?"taxonomyTierHeavy":l==="balanced"?"taxonomyTierBalanced":"taxonomyTierLight");return c.jsxs("div",{className:"bg-dash-surface border border-dash-border rounded-lg overflow-hidden flex flex-col h-full",children:[c.jsxs("button",{type:"button",onClick:()=>s(!r),className:"w-full flex items-center justify-between px-4 py-3 bg-dash-surface-hover/30 hover:bg-dash-surface-hover/50 transition-colors","aria-expanded":!r,"aria-controls":"section-model-taxonomy",children:[c.jsx("h3",{className:"text-sm font-bold text-dash-text uppercase tracking-wider",children:n("sectionModelTaxonomy")}),c.jsx("svg",{className:`w-4 h-4 text-dash-text-muted transition-transform duration-200 ${r?"":"rotate-180"}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),!r&&c.jsx("div",{id:"section-model-taxonomy",className:"flex-1 overflow-y-auto min-h-0",children:c.jsxs("div",{className:"px-4 py-3 space-y-4",children:[c.jsx("p",{className:"text-xs text-dash-text-secondary",children:n("taxonomyDescription")}),Object.entries(ly).map(([l,d])=>{const u=Object.values(d).some(h=>h.effort!==void 0);return c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("span",{className:"text-xs font-semibold text-dash-text uppercase tracking-wider",children:K8[l]??l}),c.jsx("button",{type:"button",onClick:()=>o(l),className:"text-xs text-dash-text-muted hover:text-dash-text px-2 py-0.5 rounded border border-dash-border hover:border-dash-accent transition-colors",children:n("taxonomyResetProvider")})]}),c.jsx("div",{className:"overflow-hidden rounded border border-dash-border",children:c.jsxs("table",{className:"w-full text-xs",children:[c.jsx("thead",{children:c.jsxs("tr",{className:"bg-dash-surface-hover/40 border-b border-dash-border",children:[c.jsx("th",{className:"text-left px-3 py-2 text-dash-text-secondary font-medium w-1/4",children:n("taxonomyTier")}),c.jsx("th",{className:"text-left px-3 py-2 text-dash-text-secondary font-medium",children:n("taxonomyModel")}),u&&c.jsx("th",{className:"text-left px-3 py-2 text-dash-text-secondary font-medium w-1/4",children:n("taxonomyEffort")})]})}),c.jsx("tbody",{children:cy.map(h=>{const f=d[h],p=dy(t,`modelTaxonomy.${l}.${h}.model`),m=dy(t,`modelTaxonomy.${l}.${h}.effort`);return c.jsxs("tr",{className:"border-b border-dash-border last:border-0",children:[c.jsx("td",{className:"px-3 py-2 text-dash-text-secondary",children:a(h)}),c.jsx("td",{className:"px-3 py-2",children:c.jsx("input",{type:"text",className:uy,placeholder:f?.model??"",value:p??"",onChange:x=>i(l,h,"model",x.target.value)})}),u&&c.jsx("td",{className:"px-3 py-2",children:f?.effort!==void 0?c.jsx("input",{type:"text",className:uy,placeholder:f.effort,value:m??"",onChange:x=>i(l,h,"effort",x.target.value)}):null})]},h)})})]})})]},l)})]})})]})},q8=(t,e)=>{const[n,r]=g.useState(null);return g.useEffect(()=>{const s=t.split(`
271
271
  `),i=[];let o=null;for(let a=0;a<=Math.min(e,s.length-1);a++){const l=s[a].trim(),d=l.match(/"([^"]+)"\s*:\s*{/);if(d){i.push(d[1]),a===e&&(o=i.join("."));continue}if(l==="}"||l==="},"){i.pop();continue}const u=l.match(/"([^"]+)"\s*:/);if(u){const h=u[1];if(a===e){o=i.length>0?`${i.join(".")}.${h}`:h;break}}}r(o)},[t,e]),n};function ZS(t){const{scope:e,fetchConfig:n,fetchSchema:r,saveConfig:s,onReset:i}=t,[o,a]=g.useState("{}"),[l,d]=g.useState(0),[u,h]=g.useState(null),[f,p]=g.useState(null),[m,x]=g.useState({}),[b,y]=g.useState({}),[w,v]=g.useState({}),[k,C]=g.useState(!0),[j,S]=g.useState(null),[O,D]=g.useState("idle"),[M,P]=g.useState(!1),[T,$]=g.useState(null),[N,E]=g.useState(null),A=q8(o,l),R=cE(N,A),_=g.useMemo(()=>lE(R,f),[R,f]);g.useEffect(()=>{(async()=>{S(null);try{const[ee,ie]=await Promise.all([n(),r()]),le=ee.local??ee.config;x(le),y(ee.global??{}),v(ee.sources),p(ie),a(JSON.stringify(le,null,2))}catch(ee){const ie=ee instanceof Error?ee.message:String(ee);console.error("Failed to load config data:",ee),S(ie)}finally{C(!1)}})()},[n,r]),g.useEffect(()=>{try{JSON.parse(o),h(null)}catch(K){h(K instanceof Error?K.message:"Invalid JSON")}},[o]),g.useEffect(()=>{if(T==="json")try{const K=JSON.parse(o);x(K)}catch{}},[o,T]);const I=g.useCallback(K=>{E(null),$("json"),a(K)},[]),F=g.useCallback(()=>{E(null)},[]),H=g.useCallback((K,ee)=>{E(K),$("form"),x(ie=>{const le=zw(ie,K,ee);return a(JSON.stringify(le,null,2)),le}),v(ie=>({...ie,[K]:e}))},[e]),V=g.useCallback(async()=>{if(!u){D("saving");try{const K=JSON.parse(o),ie=await s(K)??K;x(ie),a(JSON.stringify(ie,null,2)),D("saved"),setTimeout(()=>D("idle"),2e3)}catch{D("error"),setTimeout(()=>D("idle"),3e3)}}},[o,u,s]),Z=g.useCallback(async()=>{if(P(!1),i){C(!0);try{const K=await i(),ee=K.local??K.config;x(ee),v(K.sources),a(JSON.stringify(ee,null,2))}catch(K){console.error("Failed to reset:",K)}finally{C(!1)}}else{const K={};x(K),a(JSON.stringify(K,null,2))}},[i]);return{jsonText:o,config:m,globalConfig:b,sources:w,schema:f,isLoading:k,loadError:j,saveStatus:O,syntaxError:u,cursorLine:l,showResetConfirm:M,activeFieldPath:R,fieldDoc:_,handleJsonChange:I,handleJsonEditorFocus:F,handleFormChange:H,handleSave:V,handleReset:Z,setCursorLine:d,setFocusedFieldPath:E,setShowResetConfirm:P}}function Ng({storageKey:t,defaultSizes:e,minSizes:n}){const[r,s]=g.useState(()=>{if(typeof window>"u")return e;const d=localStorage.getItem(t);if(d)try{const u=JSON.parse(d);if(Array.isArray(u)&&u.length===e.length){const h=u.reduce((f,p)=>f+p,0);if(Math.abs(h-100)<1)return u}}catch{}return e}),[i,o]=g.useState(!1);g.useEffect(()=>{localStorage.setItem(t,JSON.stringify(r))},[r,t]);const a=g.useCallback((d,u)=>{u.preventDefault(),o(!0);let h=u.currentTarget.parentElement;for(;h&&getComputedStyle(h).display!=="flex";)h=h.parentElement;if(!h)return;const p=h.getBoundingClientRect().width,m=u.clientX,x=[...r],b=w=>{const k=(w.clientX-m)/p*100,C=[...x],j=d,S=d+1;let O=x[j]+k,D=x[S]-k;O<n[j]&&(O=n[j],D=x[j]+x[S]-O),D<n[S]&&(D=n[S],O=x[j]+x[S]-D),C[j]=O,C[S]=D,s(C)},y=()=>{o(!1),document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",y),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",b),document.addEventListener("mouseup",y),document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[r,n]),l=g.useCallback(()=>{s(e)},[e]);return{sizes:r,isDragging:i,startDrag:a,reset:l}}function Y8(t,e,n,r){const[s,i]=g.useState(()=>{if(typeof window>"u")return e;const d=localStorage.getItem(t);if(d){const u=Number.parseFloat(d);if(!Number.isNaN(u)&&u>=n&&u<=100-r)return u}return e}),[o,a]=g.useState(!1),l=g.useCallback(d=>{d.preventDefault(),a(!0);const u=d.target.closest("[data-vresize-container]");if(!u)return;const h=p=>{const m=u.getBoundingClientRect(),x=(p.clientY-m.top)/m.height*100;i(Math.max(n,Math.min(100-r,x)))},f=()=>{a(!1),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",f),document.body.style.cursor="",document.body.style.userSelect=""};document.addEventListener("mousemove",h),document.addEventListener("mouseup",f),document.body.style.cursor="row-resize",document.body.style.userSelect="none"},[n,r]);return g.useEffect(()=>{localStorage.setItem(t,String(s))},[t,s]),{topPct:s,isDragging:o,startDrag:l}}const X8=()=>{const{t}=se(),e=$t(),{sizes:n,isDragging:r,startDrag:s}=Ng({storageKey:"claudekit-global-config-panels",defaultSizes:[35,40,25],minSizes:[20,25,15]}),i=Y8("claudekit-form-taxonomy-split",70,25,15),o=g.useCallback(async()=>await cx(),[]),a=g.useCallback(async f=>{await Ww({scope:"global",config:f})},[]),l=g.useCallback(async()=>await cx(),[]),d=ZS({scope:"global",fetchConfig:o,fetchSchema:Uw,saveConfig:a,onReset:l}),u=g.useMemo(()=>[{id:"general",title:t("sectionGeneral"),fields:[{path:"codingLevel",label:t("fieldCodingLevel"),description:t("fieldCodingLevelDesc")},{path:"statusline",label:t("fieldStatusline"),description:t("fieldStatuslineDesc")},{path:"statuslineColors",label:t("fieldStatuslineColors"),description:t("fieldStatuslineColorsDesc")},{path:"locale.thinkingLanguage",label:t("fieldThinkingLanguage"),description:t("fieldThinkingLanguageDesc")},{path:"locale.responseLanguage",label:t("fieldResponseLanguage"),description:t("fieldResponseLanguageDesc")}]},{id:"paths",title:t("sectionPaths"),fields:[{path:"paths.docs",label:t("fieldDocsPath"),description:t("fieldDocsPathDesc")},{path:"paths.plans",label:t("fieldPlansPath"),description:t("fieldPlansPathDesc")},{path:"paths.globalPlans",label:t("fieldGlobalPlansPath"),description:t("fieldGlobalPlansPathDesc")}]},{id:"privacy",title:t("sectionPrivacy"),defaultCollapsed:!0,fields:[{path:"privacyBlock",label:t("fieldPrivacyBlock"),description:t("fieldPrivacyBlockDesc")},{path:"trust.enabled",label:t("fieldTrustEnabled"),description:t("fieldTrustEnabledDesc")},{path:"trust.passphrase",label:t("fieldTrustPassphrase"),description:t("fieldTrustPassphraseDesc")}]},{id:"project",title:t("sectionProject"),defaultCollapsed:!0,fields:[{path:"project.type",label:t("fieldProjectType"),description:t("fieldProjectTypeDesc")},{path:"project.packageManager",label:t("fieldPackageManager"),description:t("fieldPackageManagerDesc")},{path:"project.framework",label:t("fieldFramework"),description:t("fieldFrameworkDesc")}]},{id:"integrations",title:t("sectionIntegrations"),defaultCollapsed:!0,fields:[{path:"gemini.model",label:t("fieldGeminiModel"),description:t("fieldGeminiModelDesc")},{path:"skills.research.useGemini",label:t("fieldResearchUseGemini"),description:t("fieldResearchUseGeminiDesc")}]},{id:"hooks",title:t("sectionHooks"),defaultCollapsed:!0,fields:[{path:"hooks.session-init",label:t("fieldHookSessionInit"),description:t("fieldHookSessionInitDesc")},{path:"hooks.subagent-init",label:t("fieldHookSubagentInit"),description:t("fieldHookSubagentInitDesc")},{path:"hooks.descriptive-name",label:t("fieldHookDescriptiveName"),description:t("fieldHookDescriptiveNameDesc")},{path:"hooks.dev-rules-reminder",label:t("fieldHookDevRulesReminder"),description:t("fieldHookDevRulesReminderDesc")},{path:"hooks.usage-context-awareness",label:t("fieldHookUsageContextAwareness"),description:t("fieldHookUsageContextAwarenessDesc")},{path:"hooks.context-tracking",label:t("fieldHookContextTracking"),description:t("fieldHookContextTrackingDesc")},{path:"hooks.scout-block",label:t("fieldHookScoutBlock"),description:t("fieldHookScoutBlockDesc")},{path:"hooks.privacy-block",label:t("fieldHookPrivacyBlock"),description:t("fieldHookPrivacyBlockDesc")},{path:"hooks.simplify-gate",label:t("fieldHookSimplifyGate"),description:t("fieldHookSimplifyGateDesc")}]},{id:"simplify",title:t("sectionSimplify"),defaultCollapsed:!0,fields:[{path:"simplify.threshold.locDelta",label:t("fieldSimplifyThresholdLocDelta"),description:t("fieldSimplifyThresholdLocDeltaDesc")},{path:"simplify.threshold.fileCount",label:t("fieldSimplifyThresholdFileCount"),description:t("fieldSimplifyThresholdFileCountDesc")},{path:"simplify.threshold.singleFileLoc",label:t("fieldSimplifyThresholdSingleFileLoc"),description:t("fieldSimplifyThresholdSingleFileLocDesc")},{path:"simplify.gate.enabled",label:t("fieldSimplifyGateEnabled"),description:t("fieldSimplifyGateEnabledDesc")},{path:"simplify.gate.hardVerbs",label:t("fieldSimplifyGateHardVerbs"),description:t("fieldSimplifyGateHardVerbsDesc")},{path:"simplify.gate.softVerbs",label:t("fieldSimplifyGateSoftVerbs"),description:t("fieldSimplifyGateSoftVerbsDesc")}]},{id:"advanced",title:t("sectionAdvanced"),defaultCollapsed:!0,fields:[{path:"docs.maxLoc",label:t("fieldDocsMaxLoc"),description:t("fieldDocsMaxLocDesc")},{path:"plan.namingFormat",label:t("fieldPlanNamingFormat"),description:t("fieldPlanNamingFormatDesc")},{path:"plan.dateFormat",label:t("fieldPlanDateFormat"),description:t("fieldPlanDateFormatDesc")},{path:"plan.validation.mode",label:t("fieldPlanValidationMode"),description:t("fieldPlanValidationModeDesc")},{path:"plan.validation.minQuestions",label:t("fieldPlanMinQuestions"),description:t("fieldPlanMinQuestionsDesc")},{path:"plan.validation.maxQuestions",label:t("fieldPlanMaxQuestions"),description:t("fieldPlanMaxQuestionsDesc")},{path:"assertions",label:t("fieldAssertions"),description:t("fieldAssertionsDesc")}]}],[t]),h=d.showResetConfirm?c.jsxs("div",{className:"flex items-center gap-2 bg-red-500/10 border border-red-500/30 rounded-lg px-2 py-1 animate-in fade-in duration-200",children:[c.jsx("span",{className:"text-xs text-red-500 font-medium",children:t("confirmReset")}),c.jsx("button",{type:"button",onClick:d.handleReset,className:"px-2 py-0.5 rounded bg-red-500 text-white text-xs font-bold hover:bg-red-600 transition-colors",children:t("confirm")}),c.jsx("button",{type:"button",onClick:()=>d.setShowResetConfirm(!1),className:"px-2 py-0.5 rounded bg-dash-surface text-dash-text-secondary text-xs font-bold hover:bg-dash-surface-hover transition-colors border border-dash-border",children:t("cancel")})]}):c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",onClick:()=>d.setShowResetConfirm(!0),className:"px-3 py-1.5 rounded-lg bg-dash-surface text-xs font-bold text-dash-text-secondary hover:bg-dash-surface-hover transition-colors border border-dash-border",children:t("resetToDefault")}),c.jsx("button",{type:"button",onClick:d.handleSave,disabled:!!d.syntaxError||d.saveStatus==="saving",className:`px-3 py-1.5 rounded-lg text-xs font-bold transition-all tracking-widest uppercase ${d.syntaxError?"bg-dash-surface text-dash-text-muted cursor-not-allowed border border-dash-border":d.saveStatus==="saved"?"bg-green-500 text-white shadow-lg shadow-green-500/20":d.saveStatus==="error"?"bg-red-500 text-white":"bg-dash-accent text-dash-bg hover:bg-dash-accent-hover shadow-lg shadow-dash-accent/20"}`,children:d.saveStatus==="saving"?t("saving"):d.saveStatus==="saved"?t("saved"):d.saveStatus==="error"?t("saveFailed"):t("saveChanges")})]});return c.jsxs("div",{className:"animate-in fade-in duration-300 w-full h-full flex flex-col transition-colors",children:[c.jsx(ek,{title:t("globalConfig"),filePath:"~/.claude/.ck.json",onBack:()=>e(-1),onSave:d.handleSave,onReset:d.handleReset,saveStatus:d.saveStatus,syntaxError:d.syntaxError,showResetConfirm:d.showResetConfirm,setShowResetConfirm:d.setShowResetConfirm,showActions:!1,showFilePath:!1}),!d.isLoading&&d.loadError&&c.jsxs("div",{className:"mx-4 mt-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/30 text-xs text-red-500",children:[c.jsx("p",{className:"font-medium",children:t("configLoadFailed")}),c.jsxs("p",{className:"mt-1 break-words",children:[t("configLoadFailedDetail")," ",d.loadError]})]}),c.jsx("div",{className:"flex-1 flex min-h-0",children:c.jsxs(c.Fragment,{children:[c.jsxs("div",{"data-vresize-container":!0,style:{width:`${n[0]}%`},className:"flex flex-col min-w-0 min-h-0",children:[c.jsx("div",{style:{height:`${d.isLoading?100:i.topPct}%`},className:"min-h-0",children:c.jsx(tk,{width:100,isLoading:d.isLoading,schema:d.schema,config:d.config,sources:d.sources,sections:u,onChange:d.handleFormChange})}),!d.isLoading&&c.jsxs(c.Fragment,{children:[c.jsx(Ln,{direction:"vertical",isDragging:i.isDragging,onMouseDown:i.startDrag}),c.jsx("div",{style:{height:`${100-i.topPct}%`},className:"min-h-0",children:c.jsx(G8,{config:d.config,onChange:d.handleFormChange})})]})]}),c.jsx(Ln,{direction:"horizontal",isDragging:r,onMouseDown:f=>s(0,f)}),c.jsx(jg,{width:n[1],isLoading:d.isLoading,jsonText:d.jsonText,cursorLine:d.cursorLine,syntaxError:d.syntaxError,onChange:d.handleJsonChange,onCursorLineChange:d.setCursorLine,headerPath:"~/.claude/.ck.json",headerActions:h}),c.jsx(Ln,{direction:"horizontal",isDragging:r,onMouseDown:f=>s(1,f)}),c.jsx(XS,{width:n[2],fieldDoc:d.fieldDoc,activeFieldPath:d.activeFieldPath})]})})]})};function Z8(t){const e=t.replace(/\\/g,"/"),n=e.split("/").filter(Boolean);return n.length<3?null:`${e.startsWith("/")?"/":""}${n.slice(0,-2).join("/")}`}function Q8(){const[t]=Vl(),e=t.get("projectId"),n=t.get("file"),r=n?Z8(n):null,s=new URLSearchParams;return r&&(s.set("dir",r),s.set("view","kanban"),e&&s.set("projectId",e)),c.jsx(gw,{replace:!0,to:r?`/plans?${s.toString()}`:"/plans"})}function J8(){const[t,e]=g.useState([]),[n,r]=g.useState(!0),[s,i]=g.useState(null),o=g.useCallback(async()=>{try{if(r(!0),i(null),Ze()){const d=await hP();e(d.map(u=>({name:u.name,command:u.command,args:u.args,source:u.source,sourceLabel:u.sourceLabel})));return}const a=await fetch("/api/mcp-servers");if(!a.ok)throw new Error(`Failed to fetch MCP servers: ${a.status}`);const l=await a.json();e(l.servers??[])}catch(a){i(a instanceof Error?a.message:"Failed to load MCP servers"),e([])}finally{r(!1)}},[]);return g.useEffect(()=>{o()},[o]),{servers:t,loading:n,error:s,reload:o}}function eR(){return c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-3.5 h-3.5 shrink-0 text-dash-accent",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 12h14M12 5l7 7-7 7"})})}function tR({label:t,count:e}){return c.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[c.jsx("span",{className:"text-xs font-bold text-dash-text-muted uppercase tracking-wider flex-1",children:t}),c.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-dash-accent-subtle text-dash-accent font-semibold",children:e})]})}function nR({server:t,selected:e,onClick:n}){return c.jsxs("button",{type:"button",onClick:n,className:["w-full flex items-start gap-2 px-3 py-2 rounded-md transition-colors text-left group",e?"bg-dash-accent/10 border border-dash-accent/30":"hover:bg-dash-surface-hover border border-transparent"].join(" "),children:[c.jsx(eR,{}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("span",{className:"text-sm font-semibold text-dash-accent font-mono",children:t.name}),c.jsx("p",{className:"text-xs text-dash-text-muted mt-0.5 truncate font-mono",children:t.command})]})]})}function rR({server:t}){const{t:e}=se();return c.jsxs("div",{className:"flex flex-col gap-4",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("h2",{className:"text-base font-semibold text-dash-text font-mono truncate flex-1",children:t.name}),c.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-dash-accent-subtle text-dash-accent font-semibold shrink-0",children:e("sessionReadOnly")})]}),c.jsx("div",{className:"flex items-center gap-2 text-xs text-dash-text-muted",children:c.jsx("span",{className:"font-mono px-2 py-0.5 rounded bg-dash-surface border border-dash-border text-dash-accent",children:t.sourceLabel})}),c.jsx("div",{className:"rounded-lg border border-dash-border bg-dash-surface p-5 overflow-x-auto",children:c.jsx("table",{className:"w-full text-sm",children:c.jsxs("tbody",{children:[c.jsxs("tr",{className:"border-b border-dash-border",children:[c.jsx("td",{className:"py-2 pr-4 font-mono text-xs text-dash-text-muted w-28 shrink-0 align-top",children:e("mcpCommand")}),c.jsx("td",{className:"py-2 font-mono text-xs text-dash-text break-all",children:t.command})]}),t.args.length>0&&c.jsxs("tr",{className:"border-b border-dash-border",children:[c.jsx("td",{className:"py-2 pr-4 font-mono text-xs text-dash-text-muted w-28 align-top",children:e("mcpArgs")}),c.jsx("td",{className:"py-2 text-xs text-dash-text",children:c.jsx("div",{className:"flex flex-col gap-1",children:t.args.map((n,r)=>c.jsx("code",{className:"font-mono bg-dash-surface border border-dash-border rounded px-1.5 py-0.5 text-[11px] break-all",children:n},r))})})]}),t.env&&Object.keys(t.env).length>0&&c.jsxs("tr",{className:"border-b border-dash-border",children:[c.jsx("td",{className:"py-2 pr-4 font-mono text-xs text-dash-text-muted w-28 align-top",children:"env"}),c.jsx("td",{className:"py-2 text-xs text-dash-text",children:c.jsx("div",{className:"flex flex-col gap-1",children:Object.keys(t.env).map(n=>c.jsxs("code",{className:"font-mono bg-dash-surface border border-dash-border rounded px-1.5 py-0.5 text-[11px]",children:[n,"=",c.jsx("span",{className:"text-dash-text-muted",children:"***"})]},n))})})]}),c.jsxs("tr",{children:[c.jsx("td",{className:"py-2 pr-4 font-mono text-xs text-dash-text-muted w-28 align-top",children:e("mcpSource")}),c.jsx("td",{className:"py-2 text-xs text-dash-text font-mono",children:t.sourceLabel})]})]})})})]})}const sR=({message:t})=>c.jsx("div",{className:"flex items-center justify-center h-full text-sm text-dash-text-muted",children:t}),iR=()=>{const{t}=se(),{servers:e,loading:n,error:r}=J8(),[s,i]=g.useState(""),[o,a]=g.useState(null),{size:l,isDragging:d,startDrag:u}=yo({storageKey:"ck-mcp-panel-width",defaultSize:380,minSize:260,maxSize:650}),h=x=>`${x.source}-${x.name}`,f=e.find(x=>h(x)===o)??null,p=g.useMemo(()=>{if(!s.trim())return e;const x=s.toLowerCase();return e.filter(b=>b.name.toLowerCase().includes(x)||b.command.toLowerCase().includes(x)||b.sourceLabel.toLowerCase().includes(x))},[e,s]),m=g.useMemo(()=>{const x=new Map;for(const b of p){const y=x.get(b.sourceLabel)??[];y.push(b),x.set(b.sourceLabel,y)}return x},[p]);return c.jsxs("div",{className:"flex h-full overflow-hidden",children:[c.jsxs("div",{style:{width:`${l}px`},className:"shrink-0 flex flex-col overflow-hidden border-r border-dash-border",children:[c.jsxs("div",{className:"shrink-0 px-4 pt-4 pb-3 border-b border-dash-border",children:[c.jsxs("div",{className:"flex items-start justify-between mb-3",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-base font-bold text-dash-text",children:t("mcpTitle")}),!n&&!r&&c.jsx("p",{className:"text-xs text-dash-text-muted mt-0.5",children:e.length===0?t("mcpNoServers"):`${e.length} ${e.length===1?"server":"servers"} configured`}),c.jsx("p",{className:"text-[11px] text-dash-text-muted font-mono mt-0.5",children:"~/.claude.json + settings.json + .mcp.json"})]}),c.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-dash-accent-subtle text-dash-accent font-semibold shrink-0",children:t("sessionReadOnly")})]}),c.jsxs("div",{className:"relative",children:[c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-dash-text-muted pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),c.jsx("input",{type:"text",value:s,onChange:x=>i(x.target.value),placeholder:t("mcpServerName"),className:"w-full pl-9 pr-4 py-2 text-sm bg-dash-surface border border-dash-border rounded-lg text-dash-text placeholder:text-dash-text-muted focus:outline-none focus:border-dash-accent/50 transition-colors"}),s&&c.jsx("button",{type:"button",onClick:()=>i(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-dash-text-muted hover:text-dash-text transition-colors",children:c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:[n&&c.jsx("div",{className:"flex flex-1 items-center justify-center text-dash-text-muted text-sm p-8",children:t("loading")}),!n&&r&&c.jsx("div",{className:"rounded-lg border border-red-300 bg-red-50 dark:bg-red-900/20 p-4 text-red-600 dark:text-red-400 text-sm m-2",children:r}),!n&&!r&&m.size===0&&c.jsx("div",{className:"flex items-center justify-center p-8 text-dash-text-muted text-sm",children:t("mcpNoServers")}),!n&&!r&&m.size>0&&c.jsx("div",{className:"flex flex-col gap-2 pb-4",children:Array.from(m.entries()).map(([x,b])=>c.jsxs("div",{children:[m.size>1&&c.jsx(tR,{label:x,count:b.length}),c.jsx("div",{className:"space-y-0.5",children:b.map(y=>{const w=h(y);return c.jsx(nR,{server:y,selected:o===w,onClick:()=>a(w)},w)})})]},x))})]})]}),c.jsx(Ln,{onMouseDown:u,isDragging:d,direction:"horizontal"}),c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:f?c.jsx(rR,{server:f}):c.jsx(sR,{message:t("selectToView")})})]})},Qu=({titleKey:t,descriptionKey:e,commandHintKey:n})=>{const{t:r}=se();return c.jsx("div",{className:"flex h-full items-center justify-center",children:c.jsxs("div",{className:"max-w-xl rounded-2xl border border-dash-border bg-dash-surface p-8 text-center shadow-sm",children:[c.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.2em] text-dash-accent",children:r("desktopModeLabel")}),c.jsx("h2",{className:"mt-3 text-xl font-semibold text-dash-text",children:r(t)}),c.jsx("p",{className:"mt-3 text-sm leading-relaxed text-dash-text-muted",children:r(e)}),n&&c.jsx("p",{className:"mt-4 rounded-lg border border-dash-border bg-dash-bg px-4 py-3 text-xs font-medium text-dash-text",children:r(n)})]})})},hy=[{key:"agent",labelKey:"migrateTypeAgents",badgeClass:"border-dash-accent/30 text-dash-accent"},{key:"command",labelKey:"migrateTypeCommands",badgeClass:"border-yellow-500/30 text-yellow-400"},{key:"skill",labelKey:"migrateTypeSkills",badgeClass:"border-purple-500/30 text-purple-400"},{key:"config",labelKey:"migrateTypeConfig",badgeClass:"border-teal-500/30 text-teal-400"},{key:"rules",labelKey:"migrateTypeRules",badgeClass:"border-rose-500/30 text-rose-400"},{key:"hooks",labelKey:"migrateTypeHooks",badgeClass:"border-cyan-500/30 text-cyan-400"}],oR=new Set([8203,8204,8205,8288,65279,8232,8233,8234,8235,8236,8237,8238,8294,8295,8296,8297]);function aR(t){return t===9||t===10||t===13?!0:t>=0&&t<=8||t>=11&&t<=31||t>=127&&t<=159||oR.has(t)}function Hs(t){let e="";for(const n of t){const r=n.codePointAt(0);r!==void 0&&(aR(r)||(e+=n))}return e}function fy(t){if(!t)return"-";const e=t.replace(/\\/g,"/"),n=e.match(/.*\/(\.[^/]+\/)/);if(n?.[1]){const s=(n.index??0)+n[0].length-n[1].length;return e.slice(s)}const r=e.split("/");return r.length>3?`.../${r.slice(-3).join("/")}`:e}function Ti(t){return t.success?t.skipped?"skipped":"installed":"failed"}function lR(t){const e={installed:0,skipped:0,failed:0};for(const n of t){const r=Ti(n);r==="installed"?e.installed+=1:r==="skipped"?e.skipped+=1:e.failed+=1}return e}function QS(t){switch(t){case"agent":case"command":case"skill":case"config":case"rules":case"hooks":case"unknown":return t;default:return"unknown"}}function cR(t,e){switch(t){case"failed":return{label:e("migrateStatusFailed"),className:"border-red-500/30 bg-red-500/10 text-red-400"};case"skipped":return{label:e("migrateStatusSkipped"),className:"border-yellow-500/30 bg-yellow-500/10 text-yellow-400"};default:return{label:e("migrateStatusInstalled"),className:"border-green-500/30 bg-green-500/10 text-green-400"}}}function dR(t){const e=new Map;for(const n of t){const r=QS(n.portableType),s=e.get(r)||[];s.push(n),e.set(r,s)}return e}function uR(t){return[QS(t.portableType),t.provider,t.providerDisplayName,t.itemName,t.path,t.success,t.skipped,t.overwritten,t.error,t.skipReason].map(n=>n===void 0?"":String(n)).join("|")}function hR(t){if(t.length===0)return!0;const e=t[0].provider;return t.every(n=>n.provider===e)}const Ui=({label:t,count:e,className:n})=>e<=0?null:c.jsxs("span",{className:`inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs ${n}`,children:[c.jsx("span",{className:"font-semibold",children:e}),c.jsx("span",{children:t})]}),py=({labelKey:t,badgeClass:e,items:n,isExpanded:r,onToggle:s,singleProvider:i})=>{const{t:o}=se(),a=n.filter(f=>Ti(f)==="installed").length,l=n.filter(f=>Ti(f)==="skipped").length,d=n.filter(f=>Ti(f)==="failed").length,u=i?"md:grid-cols-[minmax(0,1.5fr)_minmax(0,1.35fr)_auto_minmax(0,1fr)]":"md:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)_minmax(0,1.2fr)_auto_minmax(0,1fr)]",h=new Map;return c.jsxs("div",{className:"rounded-xl border border-dash-border bg-dash-surface overflow-hidden",children:[c.jsxs("button",{type:"button",onClick:s,className:"w-full flex flex-wrap items-center gap-2 px-4 py-3 text-left hover:bg-dash-surface-hover transition-colors",children:[c.jsx("svg",{className:`w-3.5 h-3.5 text-dash-text-muted transition-transform ${r?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c.jsx("path",{d:"M9 5l7 7-7 7"})}),c.jsx("p",{className:"text-sm font-semibold text-dash-text",children:o(t)}),c.jsx("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-semibold ${e}`,children:n.length}),c.jsx("span",{className:"hidden sm:block flex-1"}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px]",children:[c.jsx(Ui,{label:o("migrateStatusInstalled"),count:a,className:"border-green-500/30 bg-green-500/10 text-green-400"}),c.jsx(Ui,{label:o("migrateStatusSkipped"),count:l,className:"border-yellow-500/30 bg-yellow-500/10 text-yellow-400"}),c.jsx(Ui,{label:o("migrateStatusFailed"),count:d,className:"border-red-500/30 bg-red-500/10 text-red-400"})]})]}),r&&c.jsxs("div",{className:"border-t border-dash-border/80",children:[c.jsxs("div",{className:`hidden md:grid ${u} items-center gap-3 px-4 py-2 border-b border-dash-border/70 text-[10px] font-semibold uppercase tracking-wide text-dash-text-muted`,children:[c.jsx("p",{children:o("migrateItem")}),!i&&c.jsx("p",{children:o("migrateProvider")}),c.jsx("p",{children:o("migratePath")}),c.jsx("p",{children:o("migrateStatus")}),c.jsx("p",{children:o("migrateError")})]}),c.jsx("div",{className:"divide-y divide-dash-border/70",children:n.map(f=>{const p=uR(f),m=h.get(p)??0;h.set(p,m+1);const x=m===0?p:`${p}#${m}`,b=Ti(f),y=cR(b,o),w=Hs(f.itemName||fy(f.path)),v=Hs(f.providerDisplayName||f.provider||""),k=Hs(f.path||""),C=Hs(fy(f.path)),j=Hs(f.error||f.skipReason||"");return c.jsxs("div",{className:`grid gap-1.5 ${u} items-start px-4 py-2.5 hover:bg-dash-bg/60 transition-colors`,children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-xs font-semibold text-dash-text truncate",title:w,children:w}),c.jsxs("div",{className:"mt-0.5 space-y-0.5 md:hidden",children:[!i&&c.jsx("p",{className:"text-[11px] text-dash-text-secondary truncate",children:v}),c.jsx("p",{className:"font-mono text-[11px] text-dash-text-muted truncate",title:k,children:C}),j&&c.jsx("p",{className:"text-[11px] text-red-400/80 line-clamp-2",title:j,children:j})]})]}),!i&&c.jsx("p",{className:"hidden md:block text-[11px] text-dash-text-secondary truncate",children:v}),c.jsx("p",{className:"hidden md:block font-mono text-[11px] text-dash-text-muted truncate",title:k,children:C}),c.jsx("span",{className:`inline-flex w-fit items-center rounded-full border px-2 py-0.5 text-[11px] font-medium ${y.className}`,children:y.label}),c.jsx("p",{className:`hidden md:block text-[11px] truncate ${j?"text-red-400/80":"text-dash-text-muted"}`,title:j,children:j||"-"})]},x)})})]})]})},fR=({results:t,onReset:e})=>{const{t:n}=se(),[r,s]=g.useState(""),i=g.useDeferredValue(r),[o,a]=g.useState("all"),[l,d]=g.useState(()=>new Set(hy.map(k=>k.key))),u=g.useMemo(()=>{const k=i.trim().toLowerCase();return t.results.filter(C=>{if(o!=="all"&&Ti(C)!==o)return!1;if(!k)return!0;const j=(C.itemName||"").toLowerCase(),S=(C.path||"").toLowerCase(),O=(C.providerDisplayName||C.provider||"").toLowerCase();return j.includes(k)||S.includes(k)||O.includes(k)})},[t.results,i,o]),h=g.useMemo(()=>hR(u),[u]),f=g.useMemo(()=>{if(!h||u.length===0)return"";const k=Array.from(new Set(u.map(C=>C.providerDisplayName?.trim()||"").filter(C=>C.length>0)));return k.length===1?k[0]:u[0]?.provider||""},[u,h]),p=g.useMemo(()=>dR(u),[u]),m=g.useMemo(()=>lR(t.results),[t.results]),x=g.useMemo(()=>[...p.keys()],[p]),b=m.installed+m.skipped+m.failed,y=x.length>0&&x.every(k=>l.has(k)),w=k=>{d(C=>{const j=new Set(C);return j.has(k)?j.delete(k):j.add(k),j})},v=()=>{if(y){d(new Set);return}d(new Set(x))};return c.jsxs("div",{className:"dash-panel p-4 md:p-5 space-y-4",children:[c.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[c.jsxs("div",{children:[c.jsxs("h2",{className:"text-base font-semibold text-dash-text",children:[n("migrateSummaryTitle"),h&&f&&c.jsxs("span",{className:"text-dash-text-muted font-normal",children:[" ","· ",Hs(f)]})]}),c.jsxs("p",{className:"text-xs text-dash-text-muted mt-1",children:[b," ",n("migrateSummarySubtitle")]})]}),c.jsx("button",{type:"button",onClick:e,className:"dash-focus-ring px-4 py-2 text-sm font-semibold rounded-md bg-dash-bg border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover",children:n("migrateSummaryNewMigration")})]}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[c.jsx(Ui,{label:n("migrateStatusInstalled"),count:m.installed,className:"border-green-500/30 bg-green-500/10 text-green-400"}),c.jsx(Ui,{label:n("migrateStatusSkipped"),count:m.skipped,className:"border-yellow-500/30 bg-yellow-500/10 text-yellow-400"}),c.jsx(Ui,{label:n("migrateStatusFailed"),count:m.failed,className:"border-red-500/30 bg-red-500/10 text-red-400"})]}),t.warnings.length>0&&c.jsx("div",{className:"space-y-2",children:t.warnings.map((k,C)=>c.jsx("div",{className:"px-3 py-2 border border-yellow-500/30 bg-yellow-500/10 rounded-md text-xs text-yellow-400",children:Hs(k)},C))}),c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("div",{className:"relative",children:[c.jsxs("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 stroke-dash-text-muted",fill:"none",viewBox:"0 0 24 24",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"11",cy:"11",r:"8"}),c.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),c.jsx("input",{type:"text",value:r,onChange:k=>s(k.target.value),placeholder:n("migrateSummarySearchPlaceholder"),className:"dash-focus-ring w-full pl-9 pr-3 py-2 bg-dash-bg border border-dash-border rounded-lg text-dash-text text-sm focus:border-dash-accent transition-colors"})]}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[["all","installed","skipped","failed"].map(k=>{const C=k==="all"?"migrateSummaryFilterAll":k==="installed"?"migrateStatusInstalled":k==="skipped"?"migrateStatusSkipped":"migrateStatusFailed";return c.jsx("button",{type:"button",onClick:()=>a(k),className:`dash-focus-ring px-3 py-1 text-xs font-medium rounded-full border transition-colors ${o===k?"bg-dash-accent/10 border-dash-accent text-dash-accent":"border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover hover:text-dash-text"}`,children:n(C)},k)}),c.jsx("button",{type:"button",onClick:v,className:"dash-focus-ring ml-1 px-3 py-1 text-xs font-medium rounded-md border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover",children:n(y?"migrateSummaryCollapseAll":"migrateSummaryExpandAll")})]})]}),u.length===0?c.jsx("div",{className:"text-center py-8 text-sm text-dash-text-muted",children:n("migrateSummaryNoResults")}):c.jsxs("div",{className:"space-y-2.5",children:[hy.map(k=>{const C=p.get(k.key);return!C||C.length===0?null:c.jsx(py,{labelKey:k.labelKey,badgeClass:k.badgeClass,items:C,isExpanded:l.has(k.key),onToggle:()=>w(k.key),singleProvider:h},k.key)}),(()=>{const k=p.get("unknown");return!k||k.length===0?null:c.jsx(py,{labelKey:"migrateTypeUnknown",badgeClass:"border-dash-border text-dash-text-muted",items:k,isExpanded:l.has("unknown"),onToggle:()=>w("unknown"),singleProvider:h})})()]})]})},pR=500;function mR(t){return t>=0&&t<=8||t>=11&&t<=31||t>=127&&t<=159}function gR(t){let e="";for(const n of t){const r=n.codePointAt(0);r!==void 0&&(mR(r)||(e+=n))}return e}const xR=({diff:t,className:e=""})=>{const n=t.split(`
272
272
  `),r=n.slice(0,pR),s=n.length-r.length;return c.jsxs("pre",{className:`text-xs font-mono overflow-x-auto p-3 rounded bg-dash-bg border border-dash-border ${e}`,children:[r.map((i,o)=>{const a=gR(i);let l="text-dash-text";return a.startsWith("+")?l="text-green-400 bg-green-500/10":a.startsWith("-")?l="text-red-400 bg-red-500/10":a.startsWith("@@")&&(l="text-blue-400"),c.jsx("div",{className:l,children:a},`${o}:${a.slice(0,24)}`)}),s>0&&c.jsxs("div",{className:"text-dash-text-muted",children:["... truncated ",s," additional line(s)"]})]})};function bR(t){return t>=0&&t<=8||t>=11&&t<=31||t>=127&&t<=159}function Wo(t){let e="";for(const n of t){const r=n.codePointAt(0);r!==void 0&&(bR(r)||(e+=n))}return e}const yR=({action:t,resolution:e,onResolve:n})=>{const{t:r}=se(),[s,i]=g.useState(!1),o=t.ownedSections&&t.ownedSections.length>0;return c.jsxs("div",{className:"border border-dash-border rounded-lg p-4 mb-3 bg-dash-surface",children:[c.jsxs("div",{className:"flex justify-between items-start gap-4",children:[c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"font-mono text-sm text-dash-text truncate",children:[Wo(t.provider),"/",Wo(t.type),"/",Wo(t.item)]}),c.jsx("p",{className:"text-xs text-dash-text-muted mt-1",children:Wo(t.reason)}),t.targetPath&&c.jsx("p",{className:"text-xs text-dash-text-secondary mt-1 font-mono truncate",children:Wo(t.targetPath)})]}),c.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[c.jsx("button",{type:"button",onClick:()=>n({type:"overwrite"}),className:`dash-focus-ring px-3 py-1.5 text-xs font-semibold rounded-md transition-colors ${e?.type==="overwrite"?"bg-dash-accent text-white":"bg-dash-bg border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover"}`,children:r("migrateConflictUseCK")}),c.jsx("button",{type:"button",onClick:()=>n({type:"keep"}),className:`dash-focus-ring px-3 py-1.5 text-xs font-semibold rounded-md transition-colors ${e?.type==="keep"?"bg-dash-accent text-white":"bg-dash-bg border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover"}`,children:r("migrateConflictKeepMine")}),o&&c.jsx("button",{type:"button",onClick:()=>n({type:"smart-merge"}),className:`dash-focus-ring px-3 py-1.5 text-xs font-semibold rounded-md transition-colors ${e?.type==="smart-merge"?"bg-dash-accent text-white":"bg-dash-bg border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover"}`,children:r("migrateConflictSmartMerge")}),t.diff&&c.jsx("button",{type:"button",onClick:()=>i(!s),className:"dash-focus-ring px-3 py-1.5 text-xs font-medium rounded-md border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover",children:r(s?"migrateConflictHideDiff":"migrateConflictShowDiff")})]})]}),s&&t.diff&&c.jsx(xR,{diff:t.diff,className:"mt-3"}),e&&c.jsxs("div",{className:"mt-2 text-xs text-green-400 flex items-center gap-1.5",children:[c.jsx("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 20 20",children:c.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),c.jsxs("span",{children:[r("migrateConflictResolved"),": ",vR(e.type,r)]})]})]})};function vR(t,e){switch(t){case"overwrite":return e("migrateConflictUseCK");case"keep":return e("migrateConflictKeepMine");case"smart-merge":return e("migrateConflictSmartMerge");case"resolved":return e("migrateConflictManual");default:return String(t)}}const wR=[{key:"install",labelKey:"migrateActionInstall",activeClass:"border-green-400 text-green-400",badgeClass:"bg-green-500/10 border-green-500/30 text-green-400"},{key:"update",labelKey:"migrateActionUpdate",activeClass:"border-yellow-400 text-yellow-400",badgeClass:"bg-yellow-500/10 border-yellow-500/30 text-yellow-400"},{key:"conflict",labelKey:"migrateActionConflict",activeClass:"border-red-400 text-red-400",badgeClass:"bg-red-500/10 border-red-500/30 text-red-400"},{key:"delete",labelKey:"migrateActionDelete",activeClass:"border-dash-text-secondary text-dash-text-secondary",badgeClass:"bg-dash-bg border-dash-border text-dash-text-secondary"},{key:"skip",labelKey:"migrateActionSkip",activeClass:"border-dash-text-muted text-dash-text-muted",badgeClass:"bg-dash-bg border-dash-border text-dash-text-muted"}],my=["agent","command","skill","config","rules","hooks"],kR={agent:"migrateTypeAgents",command:"migrateTypeCommands",skill:"migrateTypeSkills",config:"migrateTypeConfig",rules:"migrateTypeRules",hooks:"migrateTypeHooks"},SR={agent:"border-dash-accent/30 text-dash-accent",command:"border-yellow-500/30 text-yellow-400",skill:"border-purple-500/30 text-purple-400",config:"border-teal-500/30 text-teal-400",rules:"border-rose-500/30 text-rose-400",hooks:"border-cyan-500/30 text-cyan-400"},wi=200;function CR(t){return t>=0&&t<=8||t>=11&&t<=31||t>=127&&t<=159}function Vc(t){let e="";for(const n of t){const r=n.codePointAt(0);r!==void 0&&(CR(r)||(e+=n))}return e}function jR(t){const e={install:[],update:[],skip:[],conflict:[],delete:[]};for(const n of t)e[n.action].push(n);return e}function NR(t){const e=new Map;for(const n of t){const r=e.get(n.type)||[];r.push(n),e.set(n.type,r)}return e}const PR=({plan:t,resolutions:e,onResolve:n,actionKey:r})=>{const{t:s}=se(),i=g.useMemo(()=>jR(t.actions),[t.actions]),o=g.useMemo(()=>wR.filter(f=>i[f.key].length>0),[i]),[a,l]=g.useState(()=>i.conflict.length>0?"conflict":i.install.length>0?"install":o[0]?.key??"install");g.useEffect(()=>{i[a]?.length===0&&o.length>0&&l(o[0].key)},[i,a,o]);const d=g.useMemo(()=>i[a]??[],[i,a]),u=g.useMemo(()=>NR(d),[d]),h=f=>{for(const p of i.conflict)n(p,{type:f})};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[t.summary.install>0&&c.jsxs("div",{className:"px-2.5 py-1 rounded-md bg-green-500/10 border border-green-500/30 text-green-400",children:[t.summary.install," ",s("migrateActionInstall")]}),t.summary.update>0&&c.jsxs("div",{className:"px-2.5 py-1 rounded-md bg-yellow-500/10 border border-yellow-500/30 text-yellow-400",children:[t.summary.update," ",s("migrateActionUpdate")]}),t.summary.skip>0&&c.jsxs("div",{className:"px-2.5 py-1 rounded-md bg-dash-bg border border-dash-border text-dash-text-muted",children:[t.summary.skip," ",s("migrateActionSkip")]}),t.summary.conflict>0&&c.jsxs("div",{className:"px-2.5 py-1 rounded-md bg-red-500/10 border border-red-500/30 text-red-400",children:[t.summary.conflict," ",s("migrateActionConflict")]}),t.summary.delete>0&&c.jsxs("div",{className:"px-2.5 py-1 rounded-md bg-dash-bg border border-dash-border text-dash-text-secondary",children:[t.summary.delete," ",s("migrateActionDelete")]})]}),o.length>1&&c.jsx("div",{className:"flex gap-1 border-b border-dash-border",children:o.map(f=>{const p=a===f.key;return c.jsxs("button",{type:"button",onClick:()=>l(f.key),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${p?f.activeClass:"border-transparent text-dash-text-muted hover:text-dash-text-secondary"}`,children:[s(f.labelKey)," ",c.jsx("span",{className:`ml-1 px-1.5 py-0.5 rounded text-[10px] border ${f.badgeClass}`,children:i[f.key].length})]},f.key)})}),a==="conflict"&&i.conflict.length>0&&c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsxs("h3",{className:"text-sm font-semibold text-red-400",children:[s("migrateConflictSectionTitle")," (",i.conflict.length,")"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{type:"button",onClick:()=>h("overwrite"),className:"dash-focus-ring px-3 py-1 text-xs font-medium rounded-md bg-dash-bg border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover",children:s("migrateConflictOverwriteAll")}),c.jsx("button",{type:"button",onClick:()=>h("keep"),className:"dash-focus-ring px-3 py-1 text-xs font-medium rounded-md bg-dash-bg border border-dash-border text-dash-text-secondary hover:bg-dash-surface-hover",children:s("migrateConflictKeepAll")})]})]}),a==="conflict"?my.map(f=>{const p=u.get(f);return!p||p.length===0?null:c.jsxs(gy,{type:f,count:p.length,children:[p.slice(0,wi).map(m=>c.jsx(yR,{action:m,resolution:e.get(r(m))||null,onResolve:x=>n(m,x)},r(m))),p.length>wi&&c.jsxs("div",{className:"text-xs text-dash-text-muted",children:["... ",p.length-wi," more"]})]},`${a}:${f}`)}):my.map(f=>{const p=u.get(f);return!p||p.length===0?null:c.jsxs(gy,{type:f,count:p.length,defaultExpanded:a!=="skip",children:[p.slice(0,wi).map(m=>c.jsx(OR,{action:m},`${m.provider}:${m.type}:${m.item}:${m.global}:${m.action}`)),p.length>wi&&c.jsxs("div",{className:"text-xs text-dash-text-muted",children:["... ",p.length-wi," more"]})]},`${a}:${f}`)})]})},gy=({type:t,count:e,defaultExpanded:n=!0,children:r})=>{const{t:s}=se(),[i,o]=g.useState(n),a=SR[t],l=s(kR[t]);return c.jsxs("div",{className:"border border-dash-border rounded-lg bg-dash-surface",children:[c.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>o(!i),className:"w-full px-4 py-2.5 flex items-center justify-between text-left hover:bg-dash-surface-hover transition-colors",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("h4",{className:"text-sm font-semibold text-dash-text",children:l}),c.jsx("span",{className:`px-2 py-0.5 text-xs rounded-md border ${a}`,children:e})]}),c.jsx("svg",{"aria-hidden":"true",className:`w-4 h-4 text-dash-text-muted transition-transform ${i?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),i&&c.jsx("div",{className:"px-4 pt-1 pb-4 space-y-2",children:r})]})},OR=({action:t})=>c.jsxs("div",{className:"px-3 py-2 bg-dash-bg rounded-md border border-dash-border",children:[c.jsxs("div",{className:"font-mono text-xs text-dash-text",children:[Vc(t.provider),"/",Vc(t.item)]}),c.jsx("div",{className:"text-xs text-dash-text-muted mt-1",children:Vc(t.reason)}),t.targetPath&&c.jsx("div",{className:"text-xs text-dash-text-secondary mt-0.5 font-mono truncate",children:Vc(t.targetPath)})]});var ER=function(e){return typeof window<"u"?matchMedia&&matchMedia("(prefers-color-scheme: ".concat(e,")")):{matches:!1}},of,DR=g.createContext({appearance:"light",setAppearance:function(){},isDarkMode:!1,themeMode:"light",setThemeMode:function(){},browserPrefers:(of=ER("dark"))!==null&&of!==void 0&&of.matches?"dark":"light"}),AR=function(){return g.useContext(DR)};const JS=(t,e)=>{if(e)return"row";switch(t){case"horizontal":return"row";case"horizontal-reverse":return"row-reverse";case"vertical":default:return"column";case"vertical-reverse":return"column-reverse"}},MR=t=>{if(t)return["space-between","space-around","space-evenly"].includes(t)},TR=(t,e)=>JS(t,e)==="row",ki=t=>typeof t=="number"?`${t}px`:t,LR=({visible:t,flex:e,gap:n,direction:r,horizontal:s,align:i,justify:o,distribution:a,height:l,width:d,padding:u,paddingInline:h,paddingBlock:f,prefixCls:p,as:m="div",className:x,style:b,children:y,wrap:w,ref:v,...k})=>{const C=o||a,S=TR(r,s)&&!d&&MR(C)?"100%":ki(d),O={...e!==void 0?{"--lobe-flex":String(e)}:{},...r||s?{"--lobe-flex-direction":JS(r,s)}:{},...w!==void 0?{"--lobe-flex-wrap":w}:{},...C!==void 0?{"--lobe-flex-justify":C}:{},...i!==void 0?{"--lobe-flex-align":i}:{},...S!==void 0?{"--lobe-flex-width":S}:{},...l!==void 0?{"--lobe-flex-height":ki(l)}:{},...u!==void 0?{"--lobe-flex-padding":ki(u)}:{},...h!==void 0?{"--lobe-flex-padding-inline":ki(h)}:{},...f!==void 0?{"--lobe-flex-padding-block":ki(f)}:{},...n!==void 0?{"--lobe-flex-gap":ki(n)}:{},...b},D="lobe-flex",M=[D,t===!1?`${D}--hidden`:void 0,p?`${p}-flex`:void 0,x].filter(Boolean).join(" ");return c.jsx(m,{ref:v,...k,className:M,style:O,children:y})};var eC=g.memo(LR);const RR=({children:t,ref:e,...n})=>c.jsx(eC,{...n,align:"center",justify:"center",ref:e,children:t});var _R=RR;const IR=/\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;function $R(t){return Array.from(t.match(IR)??[])}function BR(t){return $R(t).map(n=>n.toLowerCase()).join("-")}var tC={exports:{}},nC={};/**
273
273
  * @license React