import{A as Re,T as Me,a as Le,S as O,b as _,P as ee,F as ye,E as w,c as v,d as T,R as ke,e as Be,M as G,f as be,g as Fe,C as J}from"./cm-state-X9WpHEQO.js";import{E as M,V as $e,D as H,k as xe,g as we,s as We,l as Z,W as Ne,a as Ue}from"./cm-view-CiSFjroV.js";import{s as q,i as je}from"./cm-language-CDsY7zq0.js";class Ce{constructor(e,t,n,s){this.state=e,this.pos=t,this.explicit=n,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=q(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),s=t.text.slice(n-t.from,this.pos-t.from),o=s.search(ve(e,!1));return o<0?null:{from:n+o,to:this.pos,text:s.slice(o)}}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 ae(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 Ve(i){let e=Object.create(null),t=Object.create(null);for(let{label:s}of i){e[s[0]]=!0;for(let o=1;otypeof s=="string"?{label:s}:s),[t,n]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:Ve(e);return s=>{let o=s.matchBefore(n);return o||s.explicit?{from:o?o.from:s.pos,options:e,validFor:t}:null}}function Nt(i,e){return t=>{for(let n=q(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)}}class ce{constructor(e,t,n,s){this.completion=e,this.source=t,this.match=n,this.score=s}}function A(i){return i.selection.main.from}function ve(i,e){var t;let{source:n}=i,s=e&&n[0]!="^",o=n[n.length-1]!="$";return!s&&!o?i:new RegExp(`${s?"^":""}(?:${n})${o?"$":""}`,(t=i.flags)!==null&&t!==void 0?t:i.ignoreCase?"i":"")}const te=Re.define();function qe(i,e,t,n){let{main:s}=i.selection,o=t-s.from,l=n-s.from;return{...i.changeByRange(a=>{if(a!=s&&t!=n&&i.sliceDoc(a.from+o,a.from+l)!=i.sliceDoc(t,n))return{range:a};let r=i.toText(e);return{changes:{from:a.from+o,to:n==s.from?a.to:a.from+l,insert:r},range:w.cursor(a.from+o+r.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const fe=new WeakMap;function ze(i){if(!Array.isArray(i))return i;let e=fe.get(i);return e||fe.set(i,e=He(i)),e}const j=O.define(),B=O.define();class Ke{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&&b<=57||b>=97&&b<=122?2:b>=65&&b<=90?1:0:(N=be(b))!=N.toLowerCase()?1:N!=N.toUpperCase()?2:0;(!d||K==1&&k||S==0&&K!=0)&&(t[f]==b||n[f]==b&&(p=!0)?l[f++]=d:l.length&&(I=!1)),S=K,d+=T(b)}return f==r&&l[0]==0&&I?this.result(-100+(p?-200:0),l,e):u==r&&m==0?this.ret(-200-e.length+(y==e.length?0:-100),[0,y]):a>-1?this.ret(-700-e.length,[a,a+this.pattern.length]):u==r?this.ret(-900-e.length,[m,y]):f==r?this.result(-100+(p?-200:0)+-700+(I?0:-1100),l,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,n){let s=[],o=0;for(let l of t){let a=l+(this.astral?T(v(n,l)):1);o&&s[o-1]==l?s[o-1]=a:(s[o++]=l,s[o++]=a)}return this.ret(e-n.length,s)}}class Qe{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:Xe,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=>he(e(n),t(n)),optionClass:(e,t)=>n=>he(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function he(i,e){return i?e?i+" "+e:i:e}function Xe(i,e,t,n,s,o){let l=i.textDirection==Ue.RTL,a=l,r=!1,h="top",c,f,p=e.left-s.left,u=s.right-e.right,m=n.right-n.left,y=n.bottom-n.top;if(a&&p=y||d>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let k=(e.bottom-e.top)/o.offsetHeight,I=(e.right-e.left)/o.offsetWidth;return{style:`${h}: ${c/k}px; max-width: ${f/I}px`,class:"cm-completionInfo-"+(r?l?"left-narrow":"right-narrow":a?"left":"right")}}function Ye(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(s=>"cm-completionIcon-"+s)),n.setAttribute("aria-hidden","true"),n},position:20}),e.push({render(t,n,s,o){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 p=l.appendChild(document.createElement("span"));p.appendChild(document.createTextNode(a.slice(c,f))),p.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 s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let n=Math.floor((i-e)/t);return{from:i-(n+1)*t,to:i-n*t}}class Ge{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 s=e.state.field(t),{options:o,selected:l}=s.open,a=e.state.facet(g);this.optionContent=Ye(a),this.optionClass=a.optionClass,this.tooltipClass=a.tooltipClass,this.range=Q(o.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]{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(g).closeOnBlur&&r.relatedTarget!=e.contentDOM&&e.dispatch({effects:B.of(null)})}),this.showOptions(o,s.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let n=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),n!=s){let{options:o,selected:l,disabled:a}=n.open;(!s.open||s.open.options!=o)&&(this.range=Q(o.length,l,e.state.facet(g).maxRenderedOptions),this.showOptions(o,n.id)),this.updateSel(),a!=((t=s.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(g).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:s}=t.options[t.selected],{info:o}=s;if(!o)return;let l=typeof o=="string"?document.createTextNode(o):o(s);if(!l)return;"then"in l?l.then(a=>{a&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(a,s)}).catch(a=>Z(this.view.state,a,"completion info")):(this.addInfoPane(l,s),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:s,destroy:o}=e;n.appendChild(s),this.infoDestroy=o||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,s=this.range.from;n;n=n.nextSibling,s++)n.nodeName!="LI"||!n.id?s--:s==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&&Ze(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(),s=e.getBoundingClientRect(),o=this.space;if(!o){let l=this.dom.ownerDocument.documentElement;o={left:0,top:0,right:l.clientWidth,bottom:l.clientHeight}}return s.top>Math.min(o.bottom,t.bottom)-10||s.bottom{l.target==s&&l.preventDefault()});let o=null;for(let l=n.from;ln.from||n.from==0))if(o=p,typeof h!="string"&&h.header)s.appendChild(h.header(h));else{let u=s.appendChild(document.createElement("completion-section"));u.textContent=p}}const c=s.appendChild(document.createElement("li"));c.id=t+"-"+l,c.setAttribute("role","option");let f=this.optionClass(a);f&&(c.className=f);for(let p of this.optionContent){let u=p(a,this.view.state,this.view,r);u&&c.appendChild(u)}}return n.from&&s.classList.add("cm-completionListIncompleteTop"),n.tonew Ge(t,i,e)}function Ze(i,e){let t=i.getBoundingClientRect(),n=e.getBoundingClientRect(),s=t.height/i.offsetHeight;n.topt.bottom&&(i.scrollTop+=(n.bottom-t.bottom)/s)}function pe(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function _e(i,e){let t=[],n=null,s=null,o=c=>{t.push(c);let{section:f}=c.completion;if(f){n||(n=[]);let p=typeof f=="string"?f:f.name;n.some(u=>u.name==p)||n.push(typeof f=="string"?{name:p}:f)}},l=e.facet(g);for(let c of i)if(c.hasResult()){let f=c.result.getMatch;if(c.result.filter===!1)for(let p of c.result.options)o(new ce(p,c.source,f?f(p):[],1e9-t.length));else{let p=e.sliceDoc(c.from,c.to),u,m=l.filterStrict?new Qe(p):new Ke(p);for(let y of c.result.options)if(u=m.match(y.label)){let k=y.displayLabel?f?f(y,u.matched):[]:u.matched,I=u.score+(y.boost||0);if(o(new ce(y,c.source,k,I)),typeof y.section=="object"&&y.section.rank==="dynamic"){let{name:d}=y.section;s||(s=Object.create(null)),s[d]=Math.max(I,s[d]||-1e9)}}}}if(n){let c=Object.create(null),f=0,p=(u,m)=>(u.rank==="dynamic"&&m.rank==="dynamic"?s[m.name]-s[u.name]:0)||(typeof u.rank=="number"?u.rank:1e9)-(typeof m.rank=="number"?m.rank:1e9)||(u.namep.score-f.score||h(f.completion,p.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):pe(c.completion)>pe(r)&&(a[a.length-1]=c),r=c.completion}return a}class P{constructor(e,t,n,s,o,l){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=s,this.selected=o,this.disabled=l}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new P(this.options,ue(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,n,s,o,l){if(s&&!l&&e.some(h=>h.isPending))return s.setDisabled();let a=_e(e,t);if(!a.length)return s&&e.some(h=>h.isPending)?s.setDisabled():null;let r=t.facet(g).selectOnOpen?0:-1;if(s&&s.selected!=r&&s.selected!=-1){let h=s.options[s.selected].completion;for(let c=0;cc.hasResult()?Math.min(h,c.from):h,1e8),create:ot,above:o.aboveCursor},s?s.timestamp:Date.now(),r,!1)}map(e){return new P(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new P(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class V{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new V(nt,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,n=t.facet(g),o=(n.override||t.languageDataAt("autocomplete",A(t)).map(ze)).map(r=>(this.active.find(c=>c.source==r)||new C(r,this.active.some(c=>c.state!=0)?1:0)).update(e,n));o.length==this.active.length&&o.every((r,h)=>r==this.active[h])&&(o=this.active);let l=this.open,a=e.effects.some(r=>r.is(ie));l&&e.docChanged&&(l=l.map(e.changes)),e.selection||o.some(r=>r.hasResult()&&e.changes.touchesRange(r.from,r.to))||!et(o,this.active)||a?l=P.build(o,t,this.id,l,n,a):l&&l.disabled&&!o.some(r=>r.isPending)&&(l=null),!l&&o.every(r=>!r.isPending)&&o.some(r=>r.hasResult())&&(o=o.map(r=>r.hasResult()?new C(r.source,0):r));for(let r of e.effects)r.is(Ie)&&(l=l&&l.setSelected(r.value,this.id));return o==this.active&&l==this.open?this:new V(o,this.id,l)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?tt:it}}function et(i,e){if(i==e)return!0;for(let t=0,n=0;;){for(;t-1&&(t["aria-activedescendant"]=i+"-"+e),t}const nt=[];function Se(i,e){if(i.isUserEvent("input.complete")){let n=i.annotation(te);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}class C{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=Se(e,t),s=this;(n&8||n&16&&this.touches(e))&&(s=new C(s.source,0)),n&4&&s.state==0&&(s=new C(this.source,1)),s=s.updateFor(e,n);for(let o of e.effects)if(o.is(j))s=new C(s.source,1,o.value);else if(o.is(B))s=new C(s.source,0);else if(o.is(ie))for(let l of o.value)l.source==s.source&&(s=l);return s}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(A(e.state))}}class R extends C{constructor(e,t,n,s,o,l){super(e,3,t),this.limit=n,this.result=s,this.from=o,this.to=l}hasResult(){return!0}updateFor(e,t){var n;if(!(t&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let o=e.changes.mapPos(this.from),l=e.changes.mapPos(this.to,1),a=A(e.state);if(a>l||!s||t&2&&(A(e.startState)==this.from||at.map(e))}}),Ie=O.define(),x=_.define({create(){return V.start()},update(i,e){return i.update(e)},provide:i=>[We.from(i,e=>e.tooltip),M.contentAttributes.from(i,e=>e.attrs)]});function ne(i,e){const t=e.completion.apply||e.completion.label;let n=i.state.field(x).active.find(s=>s.source==e.source);return n instanceof R?(typeof t=="string"?i.dispatch({...qe(i.state,t,n.from,n.to),annotations:te.of(e.completion)}):t(i,e.completion,n.from,n.to),!0):!1}const ot=Je(x,ne);function U(i,e="option"){return t=>{let n=t.state.field(x,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+s*(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:Ie.of(a)}),!0}}const lt=i=>{let e=i.state.field(x,!1);return i.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampi.state.field(x,!1)?(i.dispatch({effects:j.of(!0)}),!0):!1,rt=i=>{let e=i.state.field(x,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(i.dispatch({effects:B.of(null)}),!0)};class at{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const ct=50,ft=1e3,ht=$e.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(x).active)e.isPending&&this.startQuery(e)}update(i){let e=i.state.field(x),t=i.state.facet(g);if(!i.selectionSet&&!i.docChanged&&i.startState.field(x)==e)return;let n=i.transactions.some(o=>{let l=Se(o,t);return l&8||(o.selection||o.docChanged)&&!(l&3)});for(let o=0;oct&&Date.now()-l.time>ft){for(let a of l.context.abortListeners)try{a()}catch(r){Z(this.view.state,r)}l.context.abortListeners=null,this.running.splice(o--,1)}else l.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(o=>o.effects.some(l=>l.is(j)))&&(this.pendingStart=!0);let s=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(o=>o.isPending&&!this.running.some(l=>l.active.source==o.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let o of i.transactions)o.isUserEvent("input.type")?this.composing=2:this.composing==2&&o.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:i}=this.view,e=i.field(x);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(g).updateSyncTime))}startQuery(i){let{state:e}=this.view,t=A(e),n=new Ce(e,t,i.explicit,this.view),s=new at(i,n);this.running.push(s),Promise.resolve(i.source(n)).then(o=>{s.context.aborted||(s.done=o||null,this.scheduleAccept())},o=>{this.view.dispatch({effects:B.of(null)}),Z(this.view.state,o)})}scheduleAccept(){this.running.every(i=>i.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(g).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(g),n=this.view.state.field(x);for(let s=0;sa.source==o.active.source);if(l&&l.isPending)if(o.done==null){let a=new C(o.active.source,0);for(let r of o.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:ie.of(e)})}},{eventHandlers:{blur(i){let e=this.view.state.field(x,!1);if(e&&e.tooltip&&this.view.state.facet(g).closeOnBlur){let t=e.open&&we(this.view,e.open.tooltip);(!t||!t.dom.contains(i.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:B.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:j.of(!1)}),20),this.composing=0}}}),pt=typeof navigator=="object"&&/Win/.test(navigator.platform),ut=ee.highest(M.domEventHandlers({keydown(i,e){let t=e.state.field(x,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||i.key.length>1||i.ctrlKey&&!(pt&&i.altKey)||i.metaKey)return!1;let n=t.open.options[t.open.selected],s=t.active.find(l=>l.source==n.source),o=n.completion.commitCharacters||s.result.commitCharacters;return o&&o.indexOf(i.key)>-1&&ne(e,n),!1}})),Te=M.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 dt{constructor(e,t,n,s){this.field=e,this.line=t,this.from=n,this.to=s}}class se{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,G.TrackDel),n=e.mapPos(this.to,1,G.TrackDel);return t==null||n==null?null:new se(this.field,t,n)}}class oe{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],s=[t],o=e.doc.lineAt(t),l=/^\s*/.exec(o.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 se(r.field,s[r.line]+r.from,s[r.line]+r.to));return{text:n,ranges:a}}static parse(e){let t=[],n=[],s=[],o;for(let l of e.split(/\r\n?|\n/)){for(;o=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(l);){let a=o[1]?+o[1]:null,r=o[2]||o[3]||"",h=-1,c=r.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f=h&&p.field++}for(let f of s)if(f.line==n.length&&f.from>o.index){let p=o[2]?3+(o[1]||"").length:2;f.from-=p,f.to-=p}s.push(new dt(h,n.length,o.index,o.index+c.length)),l=l.slice(0,o.index)+r+l.slice(o.index+o[0].length)}l=l.replace(/\\([{}])/g,(a,r,h)=>{for(let c of s)c.line==n.length&&c.from>h&&(c.from--,c.to--);return r}),n.push(l)}return new oe(n,s)}}let mt=H.widget({widget:new class extends Ne{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),gt=H.mark({class:"cm-snippetField"});class L{constructor(e,t){this.ranges=e,this.active=t,this.deco=H.set(e.map(n=>(n.from==n.to?mt:gt).range(n.from,n.to)),!0)}map(e){let t=[];for(let n of this.ranges){let s=n.map(e);if(!s)return null;t.push(s)}return new L(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))}}const W=O.define({map(i,e){return i&&i.map(e)}}),yt=O.define(),F=_.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is(W))return t.value;if(t.is(yt)&&i)return new L(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=>M.decorations.from(i,e=>e?e.deco:H.none)});function le(i,e){return w.create(i.filter(t=>t.field==e).map(t=>w.range(t.from,t.to)))}function bt(i){let e=oe.parse(i);return(t,n,s,o)=>{let{text:l,ranges:a}=e.instantiate(t.state,s),{main:r}=t.state.selection,h={changes:{from:s,to:o==r.from?r.to:o,insert:Le.of(l)},scrollIntoView:!0,annotations:n?[te.of(n),Me.userEvent.of("input.complete")]:void 0};if(a.length&&(h.selection=le(a,0)),a.some(c=>c.field>0)){let c=new L(a,0),f=h.effects=[W.of(c)];t.state.field(F,!1)===void 0&&f.push(O.appendConfig.of([F,St,It,Te]))}t.dispatch(t.state.update(h))}}function Oe(i){return({state:e,dispatch:t})=>{let n=e.field(F,!1);if(!n||i<0&&n.active==0)return!1;let s=n.active+i,o=i>0&&!n.ranges.some(l=>l.field==s+i);return t(e.update({selection:le(n.ranges,s),effects:W.of(o?null:new L(n.ranges,s)),scrollIntoView:!0})),!0}}const xt=({state:i,dispatch:e})=>i.field(F,!1)?(e(i.update({effects:W.of(null)})),!0):!1,wt=Oe(1),Ct=Oe(-1),vt=[{key:"Tab",run:wt,shift:Ct},{key:"Escape",run:xt}],de=ye.define({combine(i){return i.length?i[0]:vt}}),St=ee.highest(xe.compute([de],i=>i.facet(de)));function Ut(i,e){return{...e,apply:bt(i)}}const It=M.domEventHandlers({mousedown(i,e){let t=e.state.field(F,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let s=t.ranges.find(o=>o.from<=n&&o.to>=n);return!s||s.field==t.active?!1:(e.dispatch({selection:le(t.ranges,s.field),effects:W.of(t.ranges.some(o=>o.field>s.field)?new L(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),$={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},E=O.define({map(i,e){let t=e.mapPos(i,-1,G.TrackAfter);return t??void 0}}),re=new class extends Fe{};re.startSide=1;re.endSide=-1;const Ee=_.define({create(){return ke.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(E)&&(i=i.update({add:[re.range(t.value,t.value+1)]}));return i}});function jt(){return[Ot,Ee]}const Y="()[]{}<>«»»«[]{}";function Ae(i){for(let e=0;e{if((Tt?i.composing:i.compositionStarted)||i.state.readOnly)return!1;let s=i.state.selection.main;if(n.length>2||n.length==2&&T(v(n,0))==1||e!=s.from||t!=s.to)return!1;let o=At(i.state,n);return o?(i.dispatch(o),!0):!1}),Et=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let n=De(i,i.selection.main.head).brackets||$.brackets,s=null,o=i.changeByRange(l=>{if(l.empty){let a=Dt(i.doc,l.head);for(let r of n)if(r==a&&z(i.doc,l.head)==Ae(v(r,0)))return{changes:{from:l.head-r.length,to:l.head+r.length},range:w.cursor(l.head-r.length)}}return{range:s=l}});return s||e(i.update(o,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},Vt=[{key:"Backspace",run:Et}];function At(i,e){let t=De(i,i.selection.main.head),n=t.brackets||$.brackets;for(let s of n){let o=Ae(v(s,0));if(e==s)return o==s?Mt(i,s,n.indexOf(s+s+s)>-1,t):Pt(i,s,o,t.before||$.before);if(e==o&&Pe(i,i.selection.main.from))return Rt(i,s,o)}return null}function Pe(i,e){let t=!1;return i.field(Ee).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(v(t,0)))}function Dt(i,e){let t=i.sliceString(e-2,e);return T(v(t,0))==t.length?t:t.slice(1)}function Pt(i,e,t,n){let s=null,o=i.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:t,from:l.to}],effects:E.of(l.to+e.length),range:w.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:E.of(l.head+e.length),range:w.cursor(l.head+e.length)}:{range:s=l}});return s?null:i.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Rt(i,e,t){let n=null,s=i.changeByRange(o=>o.empty&&z(i.doc,o.head)==t?{changes:{from:o.head,to:o.head+t.length,insert:t},range:w.cursor(o.head+t.length)}:n={range:o});return n?null:i.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Mt(i,e,t,n){let s=n.stringPrefixes||$.stringPrefixes,o=null,l=i.changeByRange(a=>{if(!a.empty)return{changes:[{insert:e,from:a.from},{insert:e,from:a.to}],effects:E.of(a.to+e.length),range:w.range(a.anchor+e.length,a.head+e.length)};let r=a.head,h=z(i.doc,r),c;if(h==e){if(me(i,r))return{changes:{insert:e+e,from:r},effects:E.of(r+e.length),range:w.cursor(r+e.length)};if(Pe(i,r)){let p=t&&i.sliceDoc(r,r+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:r,to:r+p.length,insert:p},range:w.cursor(r+p.length)}}}else{if(t&&i.sliceDoc(r-2*e.length,r)==e+e&&(c=ge(i,r-2*e.length,s))>-1&&me(i,c))return{changes:{insert:e+e+e+e,from:r},effects:E.of(r+e.length),range:w.cursor(r+e.length)};if(i.charCategorizer(r)(h)!=J.Word&&ge(i,r,s)>-1&&!Lt(i,r,e,s))return{changes:{insert:e+e,from:r},effects:E.of(r+e.length),range:w.cursor(r+e.length)}}return{range:o=a}});return o?null:i.update(l,{scrollIntoView:!0,userEvent:"input.type"})}function me(i,e){let t=q(i).resolveInner(e+1);return t.parent&&t.from==e}function Lt(i,e,t,n){let s=q(i).resolveInner(e,-1),o=n.reduce((l,a)=>Math.max(l,a.length),0);for(let l=0;l<5;l++){let a=i.sliceDoc(s.from,Math.min(s.to,s.from+t.length+o)),r=a.indexOf(t);if(!r||r>-1&&n.indexOf(a.slice(0,r))>-1){let c=s.firstChild;for(;c&&c.from==s.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=s.to==e&&s.parent;if(!h)break;s=h}return!1}function ge(i,e,t){let n=i.charCategorizer(e);if(n(i.sliceDoc(e-1,e))!=J.Word)return e;for(let s of t){let o=e-s.length;if(i.sliceDoc(o,e)==s&&n(i.sliceDoc(o-1,o))!=J.Word)return o}return-1}function Ht(i={}){return[ut,x,g.of(i),ht,Bt,Te]}const kt=[{key:"Ctrl-Space",run:X},{mac:"Alt-`",run:X},{mac:"Alt-i",run:X},{key:"Escape",run:rt},{key:"ArrowDown",run:U(!0)},{key:"ArrowUp",run:U(!1)},{key:"PageDown",run:U(!0,"page")},{key:"PageUp",run:U(!1,"page")},{key:"Enter",run:lt}],Bt=ee.highest(xe.computeN([g],i=>i.facet(g).defaultKeymap?[kt]:[]));export{Ce as C,jt as a,Ht as b,He as c,Vt as d,kt as e,Nt as i,Ut as s};