/* esm.sh - @codemirror/autocomplete@6.20.4 */ import{Annotation as je,StateEffect as O,EditorSelection as v,codePointAt as w,codePointSize as T,fromCodePoint as Ee,Facet as De,combineConfig as He,StateField as ce,Prec as fe,Transaction as Ve,Text as qe,MapMode as J,RangeValue as Ke,RangeSet as ze,CharCategory as Z}from"./cm-state.mjs";import{Direction as Ye,logException as _,showTooltip as Qe,EditorView as L,ViewPlugin as Xe,getTooltip as Re,Decoration as q,WidgetType as Ge,keymap as Pe}from"./cm-view.mjs";import{syntaxTree as $,indentUnit as Je}from"./cm-language.mjs";var U=class{constructor(e,t,n,o){this.state=e,this.pos=t,this.explicit=n,this.view=o,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=$(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),n=Math.max(t.from,this.pos-250),o=t.text.slice(n-t.from,this.pos-t.from),s=o.search(Le(e,!1));return s<0?null:{from:n+s,to:this.pos,text:o.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,n){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),n&&n.onDocChange&&(this.abortOnDocChange=!0))}};function ge(i){let e=Object.keys(i).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function Ze(i){let e=Object.create(null),t=Object.create(null);for(let{label:o}of i){e[o[0]]=!0;for(let s=1;stypeof o=="string"?{label:o}:o),[t,n]=e.every(o=>/^\w+$/.test(o.label))?[/\w*$/,/\w+$/]:Ze(e);return o=>{let s=o.matchBefore(n);return s||o.explicit?{from:s?s.from:o.pos,options:e,validFor:t}:null}}function zt(i,e){return t=>{for(let n=$(t.state).resolveInner(t.pos,-1);n;n=n.parent){if(i.indexOf(n.name)>-1)return e(t);if(n.type.isTop)break}return null}}function Yt(i,e){return t=>{for(let n=$(t.state).resolveInner(t.pos,-1);n;n=n.parent){if(i.indexOf(n.name)>-1)return null;if(n.type.isTop)break}return e(t)}}var j=class{constructor(e,t,n,o){this.completion=e,this.source=t,this.match=n,this.score=o}};function E(i){return i.selection.main.from}function Le(i,e){var t;let{source:n}=i,o=e&&n[0]!="^",s=n[n.length-1]!="$";return!o&&!s?i:new RegExp(`${o?"^":""}(?:${n})${s?"$":""}`,(t=i.flags)!==null&&t!==void 0?t:i.ignoreCase?"i":"")}var he=je.define();function et(i,e,t,n){let{main:o}=i.selection,s=t-o.from,l=n-o.from;return{...i.changeByRange(a=>{if(a!=o&&t!=n&&i.sliceDoc(a.from+s,a.from+l)!=i.sliceDoc(t,n))return{range:a};let r=i.toText(e);return{changes:{from:a.from+s,to:n==o.from?a.to:a.from+l,insert:r},range:v.cursor(a.from+s+r.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}var ye=new WeakMap;function tt(i){if(!Array.isArray(i))return i;let e=ye.get(i);return e||ye.set(i,e=_e(i)),e}var H=O.define(),M=O.define(),ee=class{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t=48&&x<=57||x>=97&&x<=122?2:x>=65&&x<=90?1:0:(W=Ee(x))!=W.toLowerCase()?1:W!=W.toUpperCase()?2:0;(!d||Y==1&&k||C==0&&Y!=0)&&(t[f]==x||n[f]==x&&(u=!0)?l[f++]=d:l.length&&(I=!1)),C=Y,d+=T(x)}return f==r&&l[0]==0&&I?this.result(-100+(u?-200:0),l,e):p==r&&m==0?this.ret(-200-e.length+(b==e.length?0:-100),[0,b]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):p==r?this.ret(-900-e.length,[m,b]):f==r?this.result(-100+(u?-200:0)+-700+(I?0:-1100),l,e):t.length==2?null:this.result((o[0]?-700:0)+-200+-1100,o,e)}result(e,t,n){let o=[],s=0;for(let l of t){let a=l+(this.astral?T(w(n,l)):1);s&&o[s-1]==l?o[s-1]=a:(o[s++]=l,o[s++]=a)}return this.ret(e-n.length,o)}},te=class{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:it,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>n=>be(e(n),t(n)),optionClass:(e,t)=>n=>be(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function be(i,e){return i?e?i+" "+e:i:e}function it(i,e,t,n,o,s){let l=i.textDirection==Ye.RTL,a=l,r=!1,h="top",c,f,u=e.left-o.left,p=o.right-e.right,m=n.right-n.left,b=n.bottom-n.top;if(a&&u=b||d>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let k=(e.bottom-e.top)/s.offsetHeight,I=(e.right-e.left)/s.offsetWidth;return{style:`${h}: ${c/k}px; max-width: ${f/I}px`,class:"cm-completionInfo-"+(r?l?"left-narrow":"right-narrow":a?"left":"right")}}var K=O.define();function nt(i){let e=i.addToOptions.slice();return i.icons&&e.push({render(t){let n=document.createElement("div");return n.classList.add("cm-completionIcon"),t.type&&n.classList.add(...t.type.split(/\s+/g).map(o=>"cm-completionIcon-"+o)),n.setAttribute("aria-hidden","true"),n},position:20}),e.push({render(t,n,o,s){let l=document.createElement("span");l.className="cm-completionLabel";let a=t.displayLabel||t.label,r=0;for(let h=0;hr&&l.appendChild(document.createTextNode(a.slice(r,c)));let u=l.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(a.slice(c,f))),u.className="cm-completionMatchedText",r=f}return rt.position-n.position).map(t=>t.render)}function Q(i,e,t){if(i<=t)return{from:0,to:i};if(e<0&&(e=0),e<=i>>1){let o=Math.floor(e/t);return{from:o*t,to:(o+1)*t}}let n=Math.ceil((i-e)/t);return{from:i-n*t,to:i-(n-1)*t}}var ie=class{constructor(e,t,n){this.view=e,this.stateField=t,this.applyCompletion=n,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:r=>this.placeInfo(r),key:this},this.space=null,this.currentClass="";let o=e.state.field(t),{options:s,selected:l}=o.open,a=e.state.facet(y);this.optionContent=nt(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=Q(s.length,l,a.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",r=>{let{options:h}=e.state.field(t).open;for(let c=r.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;c!=null&&(e.dispatch({effects:K.of(c)}),r.preventDefault())}}),this.dom.addEventListener("focusout",r=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(y).closeOnBlur&&r.relatedTarget!=e.contentDOM&&e.dispatch({effects:M.of(null)})}),this.showOptions(s,o.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let n=e.state.field(this.stateField),o=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),n!=o){let{options:s,selected:l,disabled:a}=n.open;(!o.open||o.open.options!=s)&&(this.range=Q(s.length,l,e.state.facet(y).maxRenderedOptions),this.showOptions(s,n.id)),this.updateSel(),a!=((t=o.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!a)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let n of this.currentClass.split(" "))n&&this.dom.classList.remove(n);for(let n of t.split(" "))n&&this.dom.classList.add(n);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected=this.range.to)&&(this.range=Q(t.options.length,t.selected,this.view.state.facet(y).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:o}=t.options[t.selected],{info:s}=o;if(!s)return;let l=typeof s=="string"?document.createTextNode(s):s(o);if(!l)return;"then"in l?l.then(a=>{a&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(a,o)}).catch(a=>_(this.view.state,a,"completion info")):(this.addInfoPane(l,o),n.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let n=this.info=document.createElement("div");if(n.className="cm-tooltip cm-completionInfo",n.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)n.appendChild(e),this.infoDestroy=null;else{let{dom:o,destroy:s}=e;n.appendChild(o),this.infoDestroy=s||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,o=this.range.from;n;n=n.nextSibling,o++)n.nodeName!="LI"||!n.id?o--:o==e?n.hasAttribute("aria-selected")||(n.setAttribute("aria-selected","true"),t=n):n.hasAttribute("aria-selected")&&(n.removeAttribute("aria-selected"),n.removeAttribute("aria-describedby"));return t&&st(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),n=this.info.getBoundingClientRect(),o=e.getBoundingClientRect(),s=this.space;if(!s){let l=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:l.clientWidth,bottom:l.clientHeight}}return o.top>Math.min(s.bottom,t.bottom)-10||o.bottom{l.target==o&&l.preventDefault()});let s=null;for(let l=n.from;ln.from||n.from==0))if(s=u,typeof h!="string"&&h.header)o.appendChild(h.header(h));else{let p=o.appendChild(document.createElement("completion-section"));p.textContent=u}}let c=o.appendChild(document.createElement("li"));c.id=t+"-"+l,c.setAttribute("role","option");let f=this.optionClass(a);f&&(c.className=f);for(let u of this.optionContent){let p=u(a,this.view.state,this.view,r);p&&c.appendChild(p)}}return n.from&&o.classList.add("cm-completionListIncompleteTop"),n.tonew ie(t,i,e)}function st(i,e){let t=i.getBoundingClientRect(),n=e.getBoundingClientRect(),o=t.height/i.offsetHeight;n.topt.bottom&&(i.scrollTop+=(n.bottom-t.bottom)/o)}function xe(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function lt(i,e){let t=[],n=null,o=null,s=c=>{t.push(c);let{section:f}=c.completion;if(f){n||(n=[]);let u=typeof f=="string"?f:f.name;n.some(p=>p.name==u)||n.push(typeof f=="string"?{name:u}:f)}},l=e.facet(y);for(let c of i)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let u of c.result.options)s(new j(u,c.source,f?f(u):[],1e9-t.length));else{let u=e.sliceDoc(c.from,c.to),p,m=l.filterStrict?new te(u):new ee(u);for(let b of c.result.options)if(p=m.match(b.label)){let k=b.displayLabel?f?f(b,p.matched):[]:p.matched,I=p.score+(b.boost||0);if(s(new j(b,c.source,k,I)),typeof b.section=="object"&&b.section.rank==="dynamic"){let{name:d}=b.section;o||(o=Object.create(null)),o[d]=Math.max(I,o[d]||-1e9)}}}}if(n){let c=Object.create(null),f=0,u=(p,m)=>(p.rank==="dynamic"&&m.rank==="dynamic"?o[m.name]-o[p.name]:0)||(typeof p.rank=="number"?p.rank:1e9)-(typeof m.rank=="number"?m.rank:1e9)||(p.nameu.score-f.score||h(f.completion,u.completion))){let f=c.completion;!r||r.label!=f.label||r.detail!=f.detail||r.type!=null&&f.type!=null&&r.type!=f.type||r.apply!=f.apply||r.boost!=f.boost?a.push(c):xe(c.completion)>xe(r)&&(a[a.length-1]=c),r=c.completion}return a}var ne=class i{constructor(e,t,n,o,s,l){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=o,this.selected=s,this.disabled=l}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new i(this.options,ve(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,n,o,s,l){if(o&&!l&&e.some(h=>h.isPending))return o.setDisabled();let a=lt(e,t);if(!a.length)return o&&e.some(h=>h.isPending)?o.setDisabled():null;let r=t.facet(y).selectOnOpen?0:-1;if(o&&o.selected!=r&&o.selected!=-1){let h=o.options[o.selected].completion;for(let c=0;cc.hasResult()?Math.min(h,c.from):h,1e8),create:ut,above:s.aboveCursor},o?o.timestamp:Date.now(),r,!1)}map(e){return new i(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new i(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}},oe=class i{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new i(ft,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,n=t.facet(y),s=(n.override||t.languageDataAt("autocomplete",E(t)).map(tt)).map(r=>(this.active.find(c=>c.source==r)||new S(r,this.active.some(c=>c.state!=0)?1:0)).update(e,n));s.length==this.active.length&&s.every((r,h)=>r==this.active[h])&&(s=this.active);let l=this.open,a=e.effects.some(r=>r.is(ue));l&&e.docChanged&&(l=l.map(e.changes)),e.selection||s.some(r=>r.hasResult()&&e.changes.touchesRange(r.from,r.to))||!rt(s,this.active)||a?l=ne.build(s,t,this.id,l,n,a):l&&l.disabled&&!s.some(r=>r.isPending)&&(l=null),!l&&s.every(r=>!r.isPending)&&s.some(r=>r.hasResult())&&(s=s.map(r=>r.hasResult()?new S(r.source,0):r));for(let r of e.effects)r.is(K)&&(l=l&&l.setSelected(r.value,this.id));return s==this.active&&l==this.open?this:new i(s,this.id,l)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?at:ct}};function rt(i,e){if(i==e)return!0;for(let t=0,n=0;;){for(;t-1&&(t["aria-activedescendant"]=i+"-"+e),t}var ft=[];function ke(i,e){if(i.isUserEvent("input.complete")){let n=i.annotation(he);if(n&&e.activateOnCompletion(n))return 12}let t=i.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:i.isUserEvent("delete.backward")?2:i.selection?8:i.docChanged?16:0}var S=class i{constructor(e,t,n=!1){this.source=e,this.state=t,this.explicit=n}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let n=ke(e,t),o=this;(n&8||n&16&&this.touches(e))&&(o=new i(o.source,0)),n&4&&o.state==0&&(o=new i(this.source,1)),o=o.updateFor(e,n);for(let s of e.effects)if(s.is(H))o=new i(o.source,1,s.value);else if(s.is(M))o=new i(o.source,0);else if(s.is(ue))for(let l of s.value)l.source==o.source&&(o=l);return o}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(E(e.state))}},V=class i extends S{constructor(e,t,n,o,s,l){super(e,3,t),this.limit=n,this.result=o,this.from=s,this.to=l}hasResult(){return!0}updateFor(e,t){var n;if(!(t&3))return this.map(e.changes);let o=this.result;o.map&&!e.changes.empty&&(o=o.map(o,e.changes));let s=e.changes.mapPos(this.from),l=e.changes.mapPos(this.to,1),a=E(e.state);if(a>l||!o||t&2&&(E(e.startState)==this.from||at.map(e))}}),g=ce.define({create(){return oe.start()},update(i,e){return i.update(e)},provide:i=>[Qe.from(i,e=>e.tooltip),L.contentAttributes.from(i,e=>e.attrs)]});function pe(i,e){let t=e.completion.apply||e.completion.label,n=i.state.field(g).active.find(o=>o.source==e.source);return n instanceof V?(typeof t=="string"?i.dispatch({...et(i.state,t,n.from,n.to),annotations:he.of(e.completion)}):t(i,e.completion,n.from,n.to),!0):!1}var ut=ot(g,pe);function N(i,e="option"){return t=>{let n=t.state.field(g,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+o*(i?1:-1):i?0:l-1;return a<0?a=e=="page"?0:l-1:a>=l&&(a=e=="page"?l-1:0),t.dispatch({effects:K.of(a)}),!0}}var pt=i=>{let e=i.state.field(g,!1);return i.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampi.state.field(g,!1)?(i.dispatch({effects:H.of(!0)}),!0):!1,dt=i=>{let e=i.state.field(g,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(i.dispatch({effects:M.of(null)}),!0)},se=class{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}},mt=50,gt=1e3,yt=Xe.fromClass(class{constructor(i){this.view=i,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of i.state.field(g).active)e.isPending&&this.startQuery(e)}update(i){let e=i.state.field(g),t=i.state.facet(y);if(!i.selectionSet&&!i.docChanged&&i.startState.field(g)==e)return;let n=i.transactions.some(s=>{let l=ke(s,t);return l&8||(s.selection||s.docChanged)&&!(l&3)});for(let s=0;smt&&Date.now()-l.time>gt){for(let a of l.context.abortListeners)try{a()}catch(r){_(this.view.state,r)}l.context.abortListeners=null,this.running.splice(s--,1)}else l.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(s=>s.effects.some(l=>l.is(H)))&&(this.pendingStart=!0);let o=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.isPending&&!this.running.some(l=>l.active.source==s.source))?setTimeout(()=>this.startUpdate(),o):-1,this.composing!=0)for(let s of i.transactions)s.isUserEvent("input.type")?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:i}=this.view,e=i.field(g);for(let t of e.active)t.isPending&&!this.running.some(n=>n.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(y).updateSyncTime))}startQuery(i){let{state:e}=this.view,t=E(e),n=new U(e,t,i.explicit,this.view),o=new se(i,n);this.running.push(o),Promise.resolve(i.source(n)).then(s=>{o.context.aborted||(o.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:M.of(null)}),_(this.view.state,s)})}scheduleAccept(){this.running.every(i=>i.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(y).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(y),n=this.view.state.field(g);for(let o=0;oa.source==s.active.source);if(l&&l.isPending)if(s.done==null){let a=new S(s.active.source,0);for(let r of s.updates)a=a.update(r,t);a.isPending||e.push(a)}else this.startQuery(l)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:ue.of(e)})}},{eventHandlers:{blur(i){let e=this.view.state.field(g,!1);if(e&&e.tooltip&&this.view.state.facet(y).closeOnBlur){let t=e.open&&Re(this.view,e.open.tooltip);(!t||!t.dom.contains(i.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:M.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:H.of(!1)}),20),this.composing=0}}}),bt=typeof navigator=="object"&&/Win/.test(navigator.platform),xt=fe.highest(L.domEventHandlers({keydown(i,e){let t=e.state.field(g,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||!i.key||i.key.length>1||i.ctrlKey&&!(bt&&i.altKey)||i.metaKey)return!1;let n=t.open.options[t.open.selected],o=t.active.find(l=>l.source==n.source),s=n.completion.commitCharacters||o.result.commitCharacters;return s&&s.indexOf(i.key)>-1&&pe(e,n),!1}})),Me=L.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"\xB7\xB7\xB7"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'\u0192'"}},".cm-completionIcon-class":{"&:after":{content:"'\u25CB'"}},".cm-completionIcon-interface":{"&:after":{content:"'\u25CC'"}},".cm-completionIcon-variable":{"&:after":{content:"'\u{1D465}'"}},".cm-completionIcon-constant":{"&:after":{content:"'\u{1D436}'"}},".cm-completionIcon-type":{"&:after":{content:"'\u{1D461}'"}},".cm-completionIcon-enum":{"&:after":{content:"'\u222A'"}},".cm-completionIcon-property":{"&:after":{content:"'\u25A1'"}},".cm-completionIcon-keyword":{"&:after":{content:"'\u{1F511}\uFE0E'"}},".cm-completionIcon-namespace":{"&:after":{content:"'\u25A2'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),le=class{constructor(e,t,n,o){this.field=e,this.line=t,this.from=n,this.to=o}},re=class i{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,J.TrackDel),n=e.mapPos(this.to,1,J.TrackDel);return t==null||n==null?null:new i(this.field,t,n)}},ae=class i{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],o=[t],s=e.doc.lineAt(t),l=/^\s*/.exec(s.text)[0];for(let r of this.lines){if(n.length){let h=l,c=/^\t*/.exec(r)[0].length;for(let f=0;fnew re(r.field,o[r.line]+r.from,o[r.line]+r.to));return{text:n,ranges:a}}static parse(e){let t=[],n=[],o=[],s;for(let l of e.split(/\r\n?|\n/)){for(;s=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(l);){let a=s[1]?+s[1]:null,r=s[2]||s[3]||"",h=-1;a===0&&(a=1e9);let c=r.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f=h&&u.field++}for(let f of o)if(f.line==n.length&&f.from>s.index){let u=s[2]?3+(s[1]||"").length:2;f.from-=u,f.to-=u}o.push(new le(h,n.length,s.index,s.index+c.length)),l=l.slice(0,s.index)+r+l.slice(s.index+s[0].length)}l=l.replace(/\\([{}])/g,(a,r,h)=>{for(let c of o)c.line==n.length&&c.from>h&&(c.from--,c.to--);return r}),n.push(l)}return new i(n,o)}},vt=q.widget({widget:new class extends Ge{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),wt=q.mark({class:"cm-snippetField"}),P=class i{constructor(e,t){this.ranges=e,this.active=t,this.deco=q.set(e.map(n=>(n.from==n.to?vt:wt).range(n.from,n.to)),!0)}map(e){let t=[];for(let n of this.ranges){let o=n.map(e);if(!o)return null;t.push(o)}return new i(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(n=>n.field==this.active&&n.from<=t.from&&n.to>=t.to))}},F=O.define({map(i,e){return i&&i.map(e)}}),Ct=O.define(),D=ce.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is(F))return t.value;if(t.is(Ct)&&i)return new P(i.ranges,t.value)}return i&&e.docChanged&&(i=i.map(e.changes)),i&&e.selection&&!i.selectionInsideField(e.selection)&&(i=null),i},provide:i=>L.decorations.from(i,e=>e?e.deco:q.none)});function de(i,e){return v.create(i.filter(t=>t.field==e).map(t=>v.range(t.from,t.to)))}function St(i){let e=ae.parse(i);return(t,n,o,s)=>{let{text:l,ranges:a}=e.instantiate(t.state,o),{main:r}=t.state.selection,h={changes:{from:o,to:s==r.from?r.to:s,insert:qe.of(l)},scrollIntoView:!0,annotations:n?[he.of(n),Ve.userEvent.of("input.complete")]:void 0};if(a.length&&(h.selection=de(a,0)),a.some(c=>c.field>0)){let c=new P(a,0),f=h.effects=[F.of(c)];t.state.field(D,!1)===void 0&&f.push(O.appendConfig.of([D,Et,Dt,Me]))}t.dispatch(t.state.update(h))}}function Be(i){return({state:e,dispatch:t})=>{let n=e.field(D,!1);if(!n||i<0&&n.active==0)return!1;let o=n.active+i,s=i>0&&!n.ranges.some(l=>l.field==o+i);return t(e.update({selection:de(n.ranges,o),effects:F.of(s?null:new P(n.ranges,o)),scrollIntoView:!0})),!0}}var It=({state:i,dispatch:e})=>i.field(D,!1)?(e(i.update({effects:F.of(null)})),!0):!1,Tt=Be(1),Ot=Be(-1);function Qt(i){let e=i.field(D,!1);return!!(e&&e.ranges.some(t=>t.field==e.active+1))}function Xt(i){let e=i.field(D,!1);return!!(e&&e.active>0)}var At=[{key:"Tab",run:Tt,shift:Ot},{key:"Escape",run:It}],we=De.define({combine(i){return i.length?i[0]:At}}),Et=fe.highest(Pe.compute([we],i=>i.facet(we)));function Gt(i,e){return{...e,apply:St(i)}}var Dt=L.domEventHandlers({mousedown(i,e){let t=e.state.field(D,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let o=t.ranges.find(s=>s.from<=n&&s.to>=n);return!o||o.field==t.active?!1:(e.dispatch({selection:de(t.ranges,o.field),effects:F.of(t.ranges.some(s=>s.field>o.field)?new P(t.ranges,o.field):null),scrollIntoView:!0}),!0)}});function Rt(i){let e=i.replace(/[\]\-\\]/g,"\\$&");try{return new RegExp(`[\\p{Alphabetic}\\p{Number}_${e}]+`,"ug")}catch{return new RegExp(`[w${e}]`,"g")}}function Ce(i,e){return new RegExp(e(i.source),i.unicode?"u":"")}var Se=Object.create(null);function Pt(i){return Se[i]||(Se[i]=new WeakMap)}function Ie(i,e,t,n,o){for(let s=i.iterLines(),l=0;!s.next().done;){let{value:a}=s,r;for(e.lastIndex=0;r=e.exec(a);)if(!n[r[0]]&&l+r.index!=o&&(t.push({type:"text",label:r[0]}),n[r[0]]=!0,t.length>=2e3))return;l+=a.length+1}}function $e(i,e,t,n,o){let s=i.length>=1e3,l=s&&e.get(i);if(l)return l;let a=[],r=Object.create(null);if(i.children){let h=0;for(let c of i.children){if(c.length>=1e3)for(let f of $e(c,e,t,n-h,o-h))r[f.label]||(r[f.label]=!0,a.push(f));else Ie(c,t,a,r,o-h);h+=c.length+1}}else Ie(i,t,a,r,o);return s&&a.length<2e3&&e.set(i,a),a}var Jt=i=>{var e;let t=(e=i.state.languageDataAt("wordChars",i.pos)[0])!==null&&e!==void 0?e:"",n=Rt(t),o=i.matchBefore(Ce(n,a=>a+"$"));if(!o&&!i.explicit)return null;let s=o?o.from:i.pos,l=$e(i.state.doc,Pt(t),n,5e4,s);return{from:s,options:l,validFor:Ce(n,a=>"^"+a)}},B={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},A=O.define({map(i,e){let t=e.mapPos(i,-1,J.TrackAfter);return t??void 0}}),me=new class extends Ke{};me.startSide=1;me.endSide=-1;var Fe=ce.define({create(){return ze.empty},update(i,e){if(i=i.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);i=i.update({filter:n=>n>=t.from&&n<=t.to})}for(let t of e.effects)t.is(A)&&(i=i.update({add:[me.range(t.value,t.value+1)]}));return i}});function Zt(){return[kt,Fe]}var G="()[]{}<>\xAB\xBB\xBB\xAB\uFF3B\uFF3D\uFF5B\uFF5D";function We(i){for(let e=0;e{if((Lt?i.composing:i.compositionStarted)||i.state.readOnly)return!1;let o=i.state.selection.main;if(n.length>2||n.length==2&&T(w(n,0))==1||e!=o.from||t!=o.to)return!1;let s=Bt(i.state,n);return s?(i.dispatch(s),!0):!1}),Mt=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let n=Ne(i,i.selection.main.head).brackets||B.brackets,o=null,s=i.changeByRange(l=>{if(l.empty){let a=$t(i.doc,l.head);for(let r of n)if(r==a&&z(i.doc,l.head)==We(w(r,0)))return{changes:{from:l.head-r.length,to:l.head+r.length},range:v.cursor(l.head-r.length)}}return{range:o=l}});return o||e(i.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!o},_t=[{key:"Backspace",run:Mt}];function Bt(i,e){let t=Ne(i,i.selection.main.head),n=t.brackets||B.brackets;for(let o of n){let s=We(w(o,0));if(e==o)return s==o?Nt(i,o,n.indexOf(o+o+o)>-1,t):Ft(i,o,s,t.before||B.before);if(e==s&&Ue(i,i.selection.main.from))return Wt(i,o,s)}return null}function Ue(i,e){let t=!1;return i.field(Fe).between(0,i.doc.length,n=>{n==e&&(t=!0)}),t}function z(i,e){let t=i.sliceString(e,e+2);return t.slice(0,T(w(t,0)))}function $t(i,e){let t=i.sliceString(e-2,e);return T(w(t,0))==t.length?t:t.slice(1)}function Ft(i,e,t,n){let o=null,s=i.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:t,from:l.to}],effects:A.of(l.to+e.length),range:v.range(l.anchor+e.length,l.head+e.length)};let a=z(i.doc,l.head);return!a||/\s/.test(a)||n.indexOf(a)>-1?{changes:{insert:e+t,from:l.head},effects:A.of(l.head+e.length),range:v.cursor(l.head+e.length)}:{range:o=l}});return o?null:i.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Wt(i,e,t){let n=null,o=i.changeByRange(s=>s.empty&&z(i.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:v.cursor(s.head+t.length)}:n={range:s});return n?null:i.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Nt(i,e,t,n){let o=n.stringPrefixes||B.stringPrefixes,s=null,l=i.changeByRange(a=>{if(!a.empty)return{changes:[{insert:e,from:a.from},{insert:e,from:a.to}],effects:A.of(a.to+e.length),range:v.range(a.anchor+e.length,a.head+e.length)};let r=a.head,h=z(i.doc,r),c;if(h==e){if(Te(i,r))return{changes:{insert:e+e,from:r},effects:A.of(r+e.length),range:v.cursor(r+e.length)};if(Ue(i,r)){let u=t&&i.sliceDoc(r,r+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:r,to:r+u.length,insert:u},range:v.cursor(r+u.length)}}}else{if(t&&i.sliceDoc(r-2*e.length,r)==e+e&&(c=Oe(i,r-2*e.length,o))>-1&&Te(i,c))return{changes:{insert:e+e+e+e,from:r},effects:A.of(r+e.length),range:v.cursor(r+e.length)};if(i.charCategorizer(r)(h)!=Z.Word&&Oe(i,r,o)>-1&&!Ut(i,r,e,o))return{changes:{insert:e+e,from:r},effects:A.of(r+e.length),range:v.cursor(r+e.length)}}return{range:s=a}});return s?null:i.update(l,{scrollIntoView:!0,userEvent:"input.type"})}function Te(i,e){let t=$(i).resolveInner(e+1);return t.parent&&t.from==e}function Ut(i,e,t,n){let o=$(i).resolveInner(e,-1),s=n.reduce((l,a)=>Math.max(l,a.length),0);for(let l=0;l<5;l++){let a=i.sliceDoc(o.from,Math.min(o.to,o.from+t.length+s)),r=a.indexOf(t);if(!r||r>-1&&n.indexOf(a.slice(0,r))>-1){let c=o.firstChild;for(;c&&c.from==o.from&&c.to-c.from>t.length+r;){if(i.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=o.to==e&&o.parent;if(!h)break;o=h}return!1}function Oe(i,e,t){let n=i.charCategorizer(e);if(n(i.sliceDoc(e-1,e))!=Z.Word)return e;for(let o of t){let s=e-o.length;if(i.sliceDoc(s,e)==o&&n(i.sliceDoc(s-1,s))!=Z.Word)return s}return-1}function ei(i={}){return[xt,g,y.of(i),yt,Ht,Me]}var jt=[{key:"Ctrl-Space",run:X},{mac:"Alt-`",run:X},{mac:"Alt-i",run:X},{key:"Escape",run:dt},{key:"ArrowDown",run:N(!0)},{key:"ArrowUp",run:N(!1)},{key:"PageDown",run:N(!0,"page")},{key:"PageUp",run:N(!1,"page")},{key:"Enter",run:pt}],Ht=fe.highest(Pe.computeN([y],i=>i.facet(y).defaultKeymap?[jt]:[]));function ti(i){let e=i.field(g,!1);return e&&e.active.some(t=>t.isPending)?"pending":e&&e.active.some(t=>t.state!=0)?"active":null}var Ae=new WeakMap;function ii(i){var e;let t=(e=i.field(g,!1))===null||e===void 0?void 0:e.open;if(!t||t.disabled)return[];let n=Ae.get(t.options);return n||Ae.set(t.options,n=t.options.map(o=>o.completion)),n}function ni(i){var e;let t=(e=i.field(g,!1))===null||e===void 0?void 0:e.open;return t&&!t.disabled&&t.selected>=0?t.options[t.selected].completion:null}function oi(i){var e;let t=(e=i.field(g,!1))===null||e===void 0?void 0:e.open;return t&&!t.disabled&&t.selected>=0?t.selected:null}function si(i){return K.of(i)}export{U as CompletionContext,pt as acceptCompletion,ei as autocompletion,It as clearSnippet,Zt as closeBrackets,_t as closeBracketsKeymap,dt as closeCompletion,Jt as completeAnyWord,_e as completeFromList,jt as completionKeymap,ti as completionStatus,ii as currentCompletions,Mt as deleteBracketPair,Qt as hasNextSnippetField,Xt as hasPrevSnippetField,zt as ifIn,Yt as ifNotIn,Bt as insertBracket,et as insertCompletionText,N as moveCompletionSelection,Tt as nextSnippetField,he as pickedCompletion,Ot as prevSnippetField,ni as selectedCompletion,oi as selectedCompletionIndex,si as setSelectedCompletion,St as snippet,Gt as snippetCompletion,we as snippetKeymap,X as startCompletion}; //# sourceMappingURL=autocomplete.bundle.mjs.map