/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{codePointAt as t,EditorSelection as e,Transaction as n,Text as i,StateEffect as o,codePointSize as s,StateField as l,RangeSet as r,Prec as a,Facet as c,combineConfig as h,fromCodePoint as p,Annotation as f,MapMode as d,RangeValue as u,CharCategory as m}from"../../state/dist/index.js";import{EditorView as g,showTooltip as v,ViewPlugin as b,logException as y,getTooltip as w,keymap as x,Decoration as C,Direction as I,WidgetType as k}from"../../view/dist/index.js";import{syntaxTree as D,indentUnit as O}from"../../language/dist/index.js";class T{constructor(t,e,n,i){this.state=t,this.pos=e,this.explicit=n,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=D(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),n=Math.max(e.from,this.pos-250),i=e.text.slice(n-e.from,this.pos-e.from),o=i.search(M(t,!1));return o<0?null:{from:n+o,to:this.pos,text:i.slice(o)}}get aborted(){return null==this.abortListeners}addEventListener(t,e,n){"abort"==t&&this.abortListeners&&(this.abortListeners.push(e),n&&n.onDocChange&&(this.abortOnDocChange=!0))}}function A(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 S(t){let e=t.map(t=>"string"==typeof t?{label:t}:t),[n,i]=e.every(t=>/^\w+$/.test(t.label))?[/\w*$/,/\w+$/]:function(t){let e=/* @__PURE__ */Object.create(null),n=/* @__PURE__ */Object.create(null);for(let{label:o}of t){e[o[0]]=!0;for(let t=1;t<o.length;t++)n[o[t]]=!0}let i=A(e)+A(n)+"*$";return[new RegExp("^"+i),new RegExp(i)]}(e);return t=>{let o=t.matchBefore(i);return o||t.explicit?{from:o?o.from:t.pos,options:e,validFor:n}:null}}function L(t,e){return n=>{for(let e=D(n.state).resolveInner(n.pos,-1);e;e=e.parent){if(t.indexOf(e.name)>-1)return null;if(e.type.isTop)break}return e(n)}}class R{constructor(t,e,n,i){this.completion=t,this.source=e,this.match=n,this.score=i}}function E(t){return t.selection.main.from}function M(t,e){var n;let{source:i}=t,o=e&&"^"!=i[0],s="$"!=i[i.length-1];return o||s?new RegExp(`${o?"^":""}(?:${i})${s?"$":""}`,null!==(n=t.flags)&&void 0!==n?n:t.ignoreCase?"i":""):t}const P=/* @__PURE__ */f.define();function B(t,n,i,o){let{main:s}=t.selection,l=i-s.from,r=o-s.from;return{...t.changeByRange(a=>{if(a!=s&&i!=o&&t.sliceDoc(a.from+l,a.from+r)!=t.sliceDoc(i,o))return{range:a};let c=t.toText(n);return{changes:{from:a.from+l,to:o==s.from?a.to:a.from+r,insert:c},range:e.cursor(a.from+l+c.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const F=/* @__PURE__ */new WeakMap;function $(t){if(!Array.isArray(t))return t;let e=F.get(t);return e||F.set(t,e=S(t)),e}const N=/* @__PURE__ */o.define(),U=/* @__PURE__ */o.define();class q{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 i=t(e,n),o=s(i);this.chars.push(i);let l=e.slice(n,n+o),r=l.toUpperCase();this.folded.push(t(r==l?l.toLowerCase():r,0)),n+=o}this.astral=e.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(e){if(0==this.pattern.length)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:n,folded:i,any:o,precise:l,byWord:r}=this;if(1==n.length){let o=t(e,0),l=s(o),r=l==e.length?0:-100;if(o==n[0]);else{if(o!=i[0])return null;r+=-200}return this.ret(r,[0,l])}let a=e.indexOf(this.pattern);if(0==a)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let c=n.length,h=0;if(a<0){for(let l=0,r=Math.min(e.length,200);l<r&&h<c;){let r=t(e,l);r!=n[h]&&r!=i[h]||(o[h++]=l),l+=s(r)}if(h<c)return null}let f=0,d=0,u=!1,m=0,g=-1,v=-1,b=/[a-z]/.test(e),y=!0;for(let w=0,x=Math.min(e.length,200),C=0;w<x&&d<c;){let o=t(e,w);a<0&&(f<c&&o==n[f]&&(l[f++]=w),m<c&&(o==n[m]||o==i[m]?(0==m&&(g=w),v=w+1,m++):m=0));let h,x=o<255?o>=48&&o<=57||o>=97&&o<=122?2:o>=65&&o<=90?1:0:(h=p(o))!=h.toLowerCase()?1:h!=h.toUpperCase()?2:0;(!w||1==x&&b||0==C&&0!=x)&&(n[d]==o||i[d]==o&&(u=!0)?r[d++]=w:r.length&&(y=!1)),C=x,w+=s(o)}return d==c&&0==r[0]&&y?this.result((u?-200:0)-100,r,e):m==c&&0==g?this.ret(-200-e.length+(v==e.length?0:-100),[0,v]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):m==c?this.ret(-900-e.length,[g,v]):d==c?this.result((u?-200:0)-100-700+(y?0:-1100),r,e):2==n.length?null:this.result((o[0]?-700:0)-200-1100,o,e)}result(e,n,i){let o=[],l=0;for(let r of n){let e=r+(this.astral?s(t(i,r)):1);l&&o[l-1]==r?o[l-1]=e:(o[l++]=r,o[l++]=e)}return this.ret(e-i.length,o)}}class W{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let e=t.slice(0,this.pattern.length),n=e==this.pattern?0:e.toLowerCase()==this.folded?-200:null;return null==n?null:(this.matched=[0,e.length],this.score=n+(t.length==this.pattern.length?0:-100),this)}}const j=/* @__PURE__ */c.define({combine:t=>h(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:V,filterStrict:!1,compareCompletions:(t,e)=>(t.sortText||t.label).localeCompare(e.sortText||e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>n=>H(t(n),e(n)),optionClass:(t,e)=>n=>H(t(n),e(n)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function H(t,e){return t?e?t+" "+e:t:e}function V(t,e,n,i,o,s){let l,r,a=t.textDirection==I.RTL,c=a,h=!1,p="top",f=e.left-o.left,d=o.right-e.right,u=i.right-i.left,m=i.bottom-i.top;if(c&&f<Math.min(u,d)?c=!1:!c&&d<Math.min(u,f)&&(c=!0),u<=(c?f:d))l=Math.max(o.top,Math.min(n.top,o.bottom-m))-e.top,r=Math.min(400,c?f:d);else{h=!0,r=Math.min(400,(a?e.right:o.right-e.left)-30);let t=o.bottom-e.bottom;t>=m||t>e.top?l=n.bottom-e.top:(p="bottom",l=e.bottom-n.top)}return{style:`${p}: ${l/((e.bottom-e.top)/s.offsetHeight)}px; max-width: ${r/((e.right-e.left)/s.offsetWidth)}px`,class:"cm-completionInfo-"+(h?a?"left-narrow":"right-narrow":c?"left":"right")}}function z(t,e,n){if(t<=n)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/n);return{from:t*n,to:(t+1)*n}}let i=Math.floor((t-e)/n);return{from:t-(i+1)*n,to:t-i*n}}class K{constructor(t,e,n){this.view=t,this.stateField=e,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let i=t.state.field(e),{options:o,selected:s}=i.open,l=t.state.facet(j);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map(t=>"cm-completionIcon-"+t)),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,n,i){let o=document.createElement("span");o.className="cm-completionLabel";let s=t.displayLabel||t.label,l=0;for(let r=0;r<i.length;){let t=i[r++],e=i[r++];t>l&&o.appendChild(document.createTextNode(s.slice(l,t)));let n=o.appendChild(document.createElement("span"));n.appendChild(document.createTextNode(s.slice(t,e))),n.className="cm-completionMatchedText",l=e}return l<s.length&&o.appendChild(document.createTextNode(s.slice(l))),o},position:50},{render(t){if(!t.detail)return null;let e=document.createElement("span");return e.className="cm-completionDetail",e.textContent=t.detail,e},position:80}),e.sort((t,e)=>t.position-e.position).map(t=>t.render)}(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=z(o.length,s,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",n=>{let{options:i}=t.state.field(e).open;for(let e,o=n.target;o&&o!=this.dom;o=o.parentNode)if("LI"==o.nodeName&&(e=/-(\d+)$/.exec(o.id))&&+e[1]<i.length)return this.applyCompletion(t,i[+e[1]]),void n.preventDefault()}),this.dom.addEventListener("focusout",e=>{let n=t.state.field(this.stateField,!1);n&&n.tooltip&&t.state.facet(j).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:U.of(null)})}),this.showOptions(o,i.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let n=t.state.field(this.stateField),i=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),n!=i){let{options:o,selected:s,disabled:l}=n.open;i.open&&i.open.options==o||(this.range=z(o.length,s,t.state.facet(j).maxRenderedOptions),this.showOptions(o,n.id)),this.updateSel(),l!=(null===(e=i.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;(e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=z(e.options.length,e.selected,this.view.state.facet(j).maxRenderedOptions),this.showOptions(e.options,t.id));let n=this.updateSelectedOption(e.selected);if(n){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:o}=i;if(!o)return;let s="string"==typeof o?document.createTextNode(o):o(i);if(!s)return;"then"in s?s.then(e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,i)}).catch(t=>y(this.view.state,t,"completion info")):(this.addInfoPane(s,i),n.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,e){this.destroyInfo();let n=this.info=document.createElement("div");if(n.className="cm-tooltip cm-completionInfo",n.id="cm-completionInfo-"+Math.floor(65535*Math.random()).toString(16),null!=t.nodeType)n.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:i}=t;n.appendChild(e),this.infoDestroy=i||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let n=this.list.firstChild,i=this.range.from;n;n=n.nextSibling,i++)"LI"==n.nodeName&&n.id?i==t?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),e=n):n.hasAttribute("aria-selected")&&(n.removeAttribute("aria-selected"),n.removeAttribute("aria-describedby")):i--;return e&&function(t,e){let n=t.getBoundingClientRect(),i=e.getBoundingClientRect(),o=n.height/t.offsetHeight;i.top<n.top?t.scrollTop-=(n.top-i.top)/o:i.bottom>n.bottom&&(t.scrollTop+=(i.bottom-n.bottom)/o)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),i=t.getBoundingClientRect(),o=this.space;if(!o){let t=this.dom.ownerDocument.documentElement;o={left:0,top:0,right:t.clientWidth,bottom:t.clientHeight}}return i.top>Math.min(o.bottom,e.bottom)-10||i.bottom<Math.max(o.top,e.top)+10?null:this.view.state.facet(j).positionInfo(this.view,e,i,n,o,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,n){const i=document.createElement("ul");i.id=e,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",t=>{t.target==i&&t.preventDefault()});let o=null;for(let s=n.from;s<n.to;s++){let{completion:l,match:r}=t[s],{section:a}=l;if(a){let t="string"==typeof a?a:a.name;if(t!=o&&(s>n.from||0==n.from))if(o=t,"string"!=typeof a&&a.header)i.appendChild(a.header(a));else{i.appendChild(document.createElement("completion-section")).textContent=t}}const c=i.appendChild(document.createElement("li"));c.id=e+"-"+s,c.setAttribute("role","option");let h=this.optionClass(l);h&&(c.className=h);for(let t of this.optionContent){let e=t(l,this.view.state,this.view,r);e&&c.appendChild(e)}}return n.from&&i.classList.add("cm-completionListIncompleteTop"),n.to<t.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Q(t,e){return n=>new K(n,t,e)}function X(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class Y{constructor(t,e,n,i,o,s){this.options=t,this.attrs=e,this.tooltip=n,this.timestamp=i,this.selected=o,this.disabled=s}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Y(this.options,Z(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,n,i,o,s){if(i&&!s&&t.some(t=>t.isPending))return i.setDisabled();let l=function(t,e){let n=[],i=null,o=null,s=t=>{n.push(t);let{section:e}=t.completion;if(e){i||(i=[]);let t="string"==typeof e?e:e.name;i.some(e=>e.name==t)||i.push("string"==typeof e?{name:t}:e)}},l=e.facet(j);for(let h of t)if(h.hasResult()){let t=h.result.getMatch;if(!1===h.result.filter)for(let e of h.result.options)s(new R(e,h.source,t?t(e):[],1e9-n.length));else{let n,i=e.sliceDoc(h.from,h.to),r=l.filterStrict?new W(i):new q(i);for(let e of h.result.options)if(n=r.match(e.label)){let i=e.displayLabel?t?t(e,n.matched):[]:n.matched,l=n.score+(e.boost||0);if(s(new R(e,h.source,i,l)),"object"==typeof e.section&&"dynamic"===e.section.rank){let{name:t}=e.section;o||(o=/* @__PURE__ */Object.create(null)),o[t]=Math.max(l,o[t]||-1e9)}}}}if(i){let t=/* @__PURE__ */Object.create(null),e=0,s=(t,e)=>("dynamic"===t.rank&&"dynamic"===e.rank?o[e.name]-o[t.name]:0)||("number"==typeof t.rank?t.rank:1e9)-("number"==typeof e.rank?e.rank:1e9)||(t.name<e.name?-1:1);for(let n of i.sort(s))e-=1e5,t[n.name]=e;for(let i of n){let{section:e}=i.completion;e&&(i.score+=t["string"==typeof e?e:e.name])}}let r=[],a=null,c=l.compareCompletions;for(let h of n.sort((t,e)=>e.score-t.score||c(t.completion,e.completion))){let t=h.completion;!a||a.label!=t.label||a.detail!=t.detail||null!=a.type&&null!=t.type&&a.type!=t.type||a.apply!=t.apply||a.boost!=t.boost?r.push(h):X(h.completion)>X(a)&&(r[r.length-1]=h),a=h.completion}return r}(t,e);if(!l.length)return i&&t.some(t=>t.isPending)?i.setDisabled():null;let r=e.facet(j).selectOnOpen?0:-1;if(i&&i.selected!=r&&-1!=i.selected){let t=i.options[i.selected].completion;for(let e=0;e<l.length;e++)if(l[e].completion==t){r=e;break}}return new Y(l,Z(n,r),{pos:t.reduce((t,e)=>e.hasResult()?Math.min(t,e.from):t,1e8),create:at,above:o.aboveCursor},i?i.timestamp:Date.now(),r,!1)}map(t){return new Y(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Y(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class _{constructor(t,e,n){this.active=t,this.id=e,this.open=n}static start(){return new _(tt,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,n=e.facet(j),i=(n.override||e.languageDataAt("autocomplete",E(e)).map($)).map(e=>(this.active.find(t=>t.source==e)||new nt(e,this.active.some(t=>0!=t.state)?1:0)).update(t,n));i.length==this.active.length&&i.every((t,e)=>t==this.active[e])&&(i=this.active);let o=this.open,s=t.effects.some(t=>t.is(ot));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||i.some(e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to))||!function(t,e){if(t==e)return!0;for(let n=0,i=0;;){for(;n<t.length&&!t[n].hasResult();)n++;for(;i<e.length&&!e[i].hasResult();)i++;let o=n==t.length,s=i==e.length;if(o||s)return o==s;if(t[n++].result!=e[i++].result)return!1}}(i,this.active)||s?o=Y.build(i,e,this.id,o,n,s):o&&o.disabled&&!i.some(t=>t.isPending)&&(o=null),!o&&i.every(t=>!t.isPending)&&i.some(t=>t.hasResult())&&(i=i.map(t=>t.hasResult()?new nt(t.source,0):t));for(let l of t.effects)l.is(st)&&(o=o&&o.setSelected(l.value,this.id));return i==this.active&&o==this.open?this:new _(i,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?G:J}}const G={"aria-autocomplete":"list"},J={};function Z(t,e){let n={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(n["aria-activedescendant"]=t+"-"+e),n}const tt=[];function et(t,e){if(t.isUserEvent("input.complete")){let n=t.annotation(P);if(n&&e.activateOnCompletion(n))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 nt{constructor(t,e,n=!1){this.source=t,this.state=e,this.explicit=n}hasResult(){return!1}get isPending(){return 1==this.state}update(t,e){let n=et(t,e),i=this;(8&n||16&n&&this.touches(t))&&(i=new nt(i.source,0)),4&n&&0==i.state&&(i=new nt(this.source,1)),i=i.updateFor(t,n);for(let o of t.effects)if(o.is(N))i=new nt(i.source,1,o.value);else if(o.is(U))i=new nt(i.source,0);else if(o.is(ot))for(let t of o.value)t.source==i.source&&(i=t);return i}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(E(t.state))}}class it extends nt{constructor(t,e,n,i,o,s){super(t,3,e),this.limit=n,this.result=i,this.from=o,this.to=s}hasResult(){return!0}updateFor(t,e){var n;if(!(3&e))return this.map(t.changes);let i=this.result;i.map&&!t.changes.empty&&(i=i.map(i,t.changes));let o=t.changes.mapPos(this.from),s=t.changes.mapPos(this.to,1),l=E(t.state);if(l>s||!i||2&e&&(E(t.startState)==this.from||l<this.limit))return new nt(this.source,4&e?1:0);let r=t.changes.mapPos(this.limit);return function(t,e,n,i){if(!t)return!1;let o=e.sliceDoc(n,i);return"function"==typeof t?t(o,n,i,e):M(t,!0).test(o)}(i.validFor,t.state,o,s)?new it(this.source,this.explicit,r,i,o,s):i.update&&(i=i.update(i,o,s,new T(t.state,l,!1)))?new it(this.source,this.explicit,r,i,i.from,null!==(n=i.to)&&void 0!==n?n:E(t.state)):new nt(this.source,1,this.explicit)}map(t){if(t.empty)return this;return(this.result.map?this.result.map(this.result,t):this.result)?new it(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new nt(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}const ot=/* @__PURE__ */o.define({map:(t,e)=>t.map(t=>t.map(e))}),st=/* @__PURE__ */o.define(),lt=/* @__PURE__ */l.define({create:()=>_.start(),update:(t,e)=>t.update(e),provide:t=>[v.from(t,t=>t.tooltip),g.contentAttributes.from(t,t=>t.attrs)]});function rt(t,e){const n=e.completion.apply||e.completion.label;let i=t.state.field(lt).active.find(t=>t.source==e.source);return i instanceof it&&("string"==typeof n?t.dispatch({...B(t.state,n,i.from,i.to),annotations:P.of(e.completion)}):n(t,e.completion,i.from,i.to),!0)}const at=/* @__PURE__ */Q(lt,rt);function ct(t,e="option"){return n=>{let i=n.state.field(lt,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<n.state.facet(j).interactionDelay)return!1;let o,s=1;"page"==e&&(o=w(n,i.open.tooltip))&&(s=Math.max(2,Math.floor(o.dom.offsetHeight/o.dom.querySelector("li").offsetHeight)-1));let{length:l}=i.open.options,r=i.open.selected>-1?i.open.selected+s*(t?1:-1):t?0:l-1;return r<0?r="page"==e?0:l-1:r>=l&&(r="page"==e?l-1:0),n.dispatch({effects:st.of(r)}),!0}}const ht=t=>{let e=t.state.field(lt,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(j).interactionDelay)&&rt(t,e.open.options[e.open.selected])},pt=t=>!!t.state.field(lt,!1)&&(t.dispatch({effects:N.of(!0)}),!0),ft=t=>{let e=t.state.field(lt,!1);return!(!e||!e.active.some(t=>0!=t.state))&&(t.dispatch({effects:U.of(null)}),!0)};class dt{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const ut=/* @__PURE__ */b.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(lt).active)e.isPending&&this.startQuery(e)}update(t){let e=t.state.field(lt),n=t.state.facet(j);if(!t.selectionSet&&!t.docChanged&&t.startState.field(lt)==e)return;let i=t.transactions.some(t=>{let e=et(t,n);return 8&e||(t.selection||t.docChanged)&&!(3&e)});for(let l=0;l<this.running.length;l++){let e=this.running[l];if(i||e.context.abortOnDocChange&&t.docChanged||e.updates.length+t.transactions.length>50&&Date.now()-e.time>1e3){for(let t of e.context.abortListeners)try{t()}catch(s){y(this.view.state,s)}e.context.abortListeners=null,this.running.splice(l--,1)}else e.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some(t=>t.effects.some(t=>t.is(N)))&&(this.pendingStart=!0);let o=this.pendingStart?50:n.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(t=>t.isPending&&!this.running.some(e=>e.active.source==t.source))?setTimeout(()=>this.startUpdate(),o):-1,0!=this.composing)for(let l of t.transactions)l.isUserEvent("input.type")?this.composing=2:2==this.composing&&l.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(lt);for(let n of e.active)n.isPending&&!this.running.some(t=>t.active.source==n.source)&&this.startQuery(n);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(j).updateSyncTime))}startQuery(t){let{state:e}=this.view,n=E(e),i=new T(e,n,t.explicit,this.view),o=new dt(t,i);this.running.push(o),Promise.resolve(t.source(i)).then(t=>{o.context.aborted||(o.done=t||null,this.scheduleAccept())},t=>{this.view.dispatch({effects:U.of(null)}),y(this.view.state,t)})}scheduleAccept(){this.running.every(t=>void 0!==t.done)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(j).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],n=this.view.state.facet(j),i=this.view.state.field(lt);for(let o=0;o<this.running.length;o++){let s=this.running[o];if(void 0===s.done)continue;if(this.running.splice(o--,1),s.done){let i=E(s.updates.length?s.updates[0].startState:this.view.state),o=Math.min(i,s.done.from+(s.active.explicit?0:1)),l=new it(s.active.source,s.active.explicit,o,s.done,s.done.from,null!==(t=s.done.to)&&void 0!==t?t:i);for(let t of s.updates)l=l.update(t,n);if(l.hasResult()){e.push(l);continue}}let l=i.active.find(t=>t.source==s.active.source);if(l&&l.isPending)if(null==s.done){let t=new nt(s.active.source,0);for(let e of s.updates)t=t.update(e,n);t.isPending||e.push(t)}else this.startQuery(l)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:ot.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(lt,!1);if(e&&e.tooltip&&this.view.state.facet(j).closeOnBlur){let n=e.open&&w(this.view,e.open.tooltip);n&&n.dom.contains(t.relatedTarget)||setTimeout(()=>this.view.dispatch({effects:U.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout(()=>this.view.dispatch({effects:N.of(!1)}),20),this.composing=0}}}),mt="object"==typeof navigator&&/* @__PURE__ */ /Win/.test(navigator.platform),gt=/* @__PURE__ */a.highest(/* @__PURE__ */g.domEventHandlers({keydown(t,e){let n=e.state.field(lt,!1);if(!n||!n.open||n.open.disabled||n.open.selected<0||t.key.length>1||t.ctrlKey&&(!mt||!t.altKey)||t.metaKey)return!1;let i=n.open.options[n.open.selected],o=n.active.find(t=>t.source==i.source),s=i.completion.commitCharacters||o.result.commitCharacters;return s&&s.indexOf(t.key)>-1&&rt(e,i),!1}})),vt=/* @__PURE__ */g.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"}}});class bt{constructor(t,e,n,i){this.field=t,this.line=e,this.from=n,this.to=i}}class yt{constructor(t,e,n){this.field=t,this.from=e,this.to=n}map(t){let e=t.mapPos(this.from,-1,d.TrackDel),n=t.mapPos(this.to,1,d.TrackDel);return null==e||null==n?null:new yt(this.field,e,n)}}class wt{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let n=[],i=[e],o=t.doc.lineAt(e),s=/^\s*/.exec(o.text)[0];for(let l of this.lines){if(n.length){let n=s,o=/^\t*/.exec(l)[0].length;for(let e=0;e<o;e++)n+=t.facet(O);i.push(e+n.length-o),l=n+l.slice(o)}n.push(l),e+=l.length+1}return{text:n,ranges:this.fieldPositions.map(t=>new yt(t.field,i[t.line]+t.from,i[t.line]+t.to))}}static parse(t){let e,n=[],i=[],o=[];for(let s of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(s);){let t=e[1]?+e[1]:null,l=e[2]||e[3]||"",r=-1,a=l.replace(/\\[{}]/g,t=>t[1]);for(let e=0;e<n.length;e++)(null!=t?n[e].seq==t:a&&n[e].name==a)&&(r=e);if(r<0){let e=0;for(;e<n.length&&(null==t||null!=n[e].seq&&n[e].seq<t);)e++;n.splice(e,0,{seq:t,name:a}),r=e;for(let t of o)t.field>=r&&t.field++}for(let n of o)if(n.line==i.length&&n.from>e.index){let t=e[2]?3+(e[1]||"").length:2;n.from-=t,n.to-=t}o.push(new bt(r,i.length,e.index,e.index+a.length)),s=s.slice(0,e.index)+l+s.slice(e.index+e[0].length)}s=s.replace(/\\([{}])/g,(t,e,n)=>{for(let s of o)s.line==i.length&&s.from>n&&(s.from--,s.to--);return e}),i.push(s)}return new wt(i,o)}}let xt=/* @__PURE__ */C.widget({widget:/* @__PURE__ */new class extends k{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),Ct=/* @__PURE__ */C.mark({class:"cm-snippetField"});class It{constructor(t,e){this.ranges=t,this.active=e,this.deco=C.set(t.map(t=>(t.from==t.to?xt:Ct).range(t.from,t.to)),!0)}map(t){let e=[];for(let n of this.ranges){let i=n.map(t);if(!i)return null;e.push(i)}return new It(e,this.active)}selectionInsideField(t){return t.ranges.every(t=>this.ranges.some(e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))}}const kt=/* @__PURE__ */o.define({map:(t,e)=>t&&t.map(e)}),Dt=/* @__PURE__ */o.define(),Ot=/* @__PURE__ */l.define({create:()=>null,update(t,e){for(let n of e.effects){if(n.is(kt))return n.value;if(n.is(Dt)&&t)return new It(t.ranges,n.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>g.decorations.from(t,t=>t?t.deco:C.none)});function Tt(t,n){return e.create(t.filter(t=>t.field==n).map(t=>e.range(t.from,t.to)))}function At(t){let e=wt.parse(t);return(t,s,l,r)=>{let{text:a,ranges:c}=e.instantiate(t.state,l),{main:h}=t.state.selection,p={changes:{from:l,to:r==h.from?h.to:r,insert:i.of(a)},scrollIntoView:!0,annotations:s?[P.of(s),n.userEvent.of("input.complete")]:void 0};if(c.length&&(p.selection=Tt(c,0)),c.some(t=>t.field>0)){let e=new It(c,0),n=p.effects=[kt.of(e)];void 0===t.state.field(Ot,!1)&&n.push(o.appendConfig.of([Ot,Bt,$t,vt]))}t.dispatch(t.state.update(p))}}function St(t){return({state:e,dispatch:n})=>{let i=e.field(Ot,!1);if(!i||t<0&&0==i.active)return!1;let o=i.active+t,s=t>0&&!i.ranges.some(e=>e.field==o+t);return n(e.update({selection:Tt(i.ranges,o),effects:kt.of(s?null:new It(i.ranges,o)),scrollIntoView:!0})),!0}}const Lt=({state:t,dispatch:e})=>!!t.field(Ot,!1)&&(e(t.update({effects:kt.of(null)})),!0),Rt=/* @__PURE__ */St(1),Et=/* @__PURE__ */St(-1),Mt=[{key:"Tab",run:Rt,shift:Et},{key:"Escape",run:Lt}],Pt=/* @__PURE__ */c.define({combine:t=>t.length?t[0]:Mt}),Bt=/* @__PURE__ */a.highest(/* @__PURE__ */x.compute([Pt],t=>t.facet(Pt)));function Ft(t,e){return{...e,apply:At(t)}}const $t=/* @__PURE__ */g.domEventHandlers({mousedown(t,e){let n,i=e.state.field(Ot,!1);if(!i||null==(n=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let o=i.ranges.find(t=>t.from<=n&&t.to>=n);return!(!o||o.field==i.active)&&(e.dispatch({selection:Tt(i.ranges,o.field),effects:kt.of(i.ranges.some(t=>t.field>o.field)?new It(i.ranges,o.field):null),scrollIntoView:!0}),!0)}}),Nt={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Ut=/* @__PURE__ */o.define({map(t,e){let n=e.mapPos(t,-1,d.TrackAfter);return null==n?void 0:n}}),qt=/* @__PURE__ */new class extends u{};qt.startSide=1,qt.endSide=-1;const Wt=/* @__PURE__ */l.define({create:()=>r.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:t=>t>=n.from&&t<=n.to})}for(let n of e.effects)n.is(Ut)&&(t=t.update({add:[qt.range(n.value,n.value+1)]}));return t}});function jt(){return[Qt,Wt]}const Ht="()[]{}<>«»»«［］｛｝";function Vt(t){for(let e=0;e<16;e+=2)if(Ht.charCodeAt(e)==t)return Ht.charAt(e+1);return p(t<128?t:t+1)}function zt(t,e){return t.languageDataAt("closeBrackets",e)[0]||Nt}const Kt="object"==typeof navigator&&/* @__PURE__ */ /Android\b/.test(navigator.userAgent),Qt=/* @__PURE__ */g.inputHandler.of((e,n,i,o)=>{if((Kt?e.composing:e.compositionStarted)||e.state.readOnly)return!1;let l=e.state.selection.main;if(o.length>2||2==o.length&&1==s(t(o,0))||n!=l.from||i!=l.to)return!1;let r=_t(e.state,o);return!!r&&(e.dispatch(r),!0)}),Xt=({state:n,dispatch:i})=>{if(n.readOnly)return!1;let o=zt(n,n.selection.main.head).brackets||Nt.brackets,l=null,r=n.changeByRange(i=>{if(i.empty){let l=function(e,n){let i=e.sliceString(n-2,n);return s(t(i,0))==i.length?i:i.slice(1)}(n.doc,i.head);for(let s of o)if(s==l&&Jt(n.doc,i.head)==Vt(t(s,0)))return{changes:{from:i.head-s.length,to:i.head+s.length},range:e.cursor(i.head-s.length)}}return{range:l=i}});return l||i(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!l},Yt=[{key:"Backspace",run:Xt}];function _t(e,n){let i=zt(e,e.selection.main.head),o=i.brackets||Nt.brackets;for(let s of o){let l=Vt(t(s,0));if(n==s)return l==s?ee(e,s,o.indexOf(s+s+s)>-1,i):Zt(e,s,l,i.before||Nt.before);if(n==l&&Gt(e,e.selection.main.from))return te(e,s,l)}return null}function Gt(t,e){let n=!1;return t.field(Wt).between(0,t.doc.length,t=>{t==e&&(n=!0)}),n}function Jt(e,n){let i=e.sliceString(n,n+2);return i.slice(0,s(t(i,0)))}function Zt(t,n,i,o){let s=null,l=t.changeByRange(l=>{if(!l.empty)return{changes:[{insert:n,from:l.from},{insert:i,from:l.to}],effects:Ut.of(l.to+n.length),range:e.range(l.anchor+n.length,l.head+n.length)};let r=Jt(t.doc,l.head);return!r||/\s/.test(r)||o.indexOf(r)>-1?{changes:{insert:n+i,from:l.head},effects:Ut.of(l.head+n.length),range:e.cursor(l.head+n.length)}:{range:s=l}});return s?null:t.update(l,{scrollIntoView:!0,userEvent:"input.type"})}function te(t,n,i){let o=null,s=t.changeByRange(n=>n.empty&&Jt(t.doc,n.head)==i?{changes:{from:n.head,to:n.head+i.length,insert:i},range:e.cursor(n.head+i.length)}:o={range:n});return o?null:t.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function ee(t,n,i,o){let s=o.stringPrefixes||Nt.stringPrefixes,l=null,r=t.changeByRange(o=>{if(!o.empty)return{changes:[{insert:n,from:o.from},{insert:n,from:o.to}],effects:Ut.of(o.to+n.length),range:e.range(o.anchor+n.length,o.head+n.length)};let r,a=o.head,c=Jt(t.doc,a);if(c==n){if(ne(t,a))return{changes:{insert:n+n,from:a},effects:Ut.of(a+n.length),range:e.cursor(a+n.length)};if(Gt(t,a)){let o=i&&t.sliceDoc(a,a+3*n.length)==n+n+n?n+n+n:n;return{changes:{from:a,to:a+o.length,insert:o},range:e.cursor(a+o.length)}}}else{if(i&&t.sliceDoc(a-2*n.length,a)==n+n&&(r=ie(t,a-2*n.length,s))>-1&&ne(t,r))return{changes:{insert:n+n+n+n,from:a},effects:Ut.of(a+n.length),range:e.cursor(a+n.length)};if(t.charCategorizer(a)(c)!=m.Word&&ie(t,a,s)>-1&&!function(t,e,n,i){let o=D(t).resolveInner(e,-1),s=i.reduce((t,e)=>Math.max(t,e.length),0);for(let l=0;l<5;l++){let l=t.sliceDoc(o.from,Math.min(o.to,o.from+n.length+s)),r=l.indexOf(n);if(!r||r>-1&&i.indexOf(l.slice(0,r))>-1){let e=o.firstChild;for(;e&&e.from==o.from&&e.to-e.from>n.length+r;){if(t.sliceDoc(e.to-n.length,e.to)==n)return!1;e=e.firstChild}return!0}let a=o.to==e&&o.parent;if(!a)break;o=a}return!1}(t,a,n,s))return{changes:{insert:n+n,from:a},effects:Ut.of(a+n.length),range:e.cursor(a+n.length)}}return{range:l=o}});return l?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function ne(t,e){let n=D(t).resolveInner(e+1);return n.parent&&n.from==e}function ie(t,e,n){let i=t.charCategorizer(e);if(i(t.sliceDoc(e-1,e))!=m.Word)return e;for(let o of n){let n=e-o.length;if(t.sliceDoc(n,e)==o&&i(t.sliceDoc(n-1,n))!=m.Word)return n}return-1}function oe(t={}){return[gt,lt,j.of(t),ut,le,vt]}const se=[{key:"Ctrl-Space",run:pt},{mac:"Alt-`",run:pt},{mac:"Alt-i",run:pt},{key:"Escape",run:ft},{key:"ArrowDown",run:/* @__PURE__ */ct(!0)},{key:"ArrowUp",run:/* @__PURE__ */ct(!1)},{key:"PageDown",run:/* @__PURE__ */ct(!0,"page")},{key:"PageUp",run:/* @__PURE__ */ct(!1,"page")},{key:"Enter",run:ht}],le=/* @__PURE__ */a.highest(/* @__PURE__ */x.computeN([j],t=>t.facet(j).defaultKeymap?[se]:[]));export{T as CompletionContext,ht as acceptCompletion,oe as autocompletion,Lt as clearSnippet,jt as closeBrackets,Yt as closeBracketsKeymap,ft as closeCompletion,S as completeFromList,se as completionKeymap,Xt as deleteBracketPair,L as ifNotIn,_t as insertBracket,B as insertCompletionText,ct as moveCompletionSelection,Rt as nextSnippetField,P as pickedCompletion,Et as prevSnippetField,At as snippet,Ft as snippetCompletion,Pt as snippetKeymap,pt as startCompletion};