-1&&it>0){let Se=h(he,$);Te=S0(he,Y,oe,0,Y.length,0,W-O,Se,Se)}else Te=f(he,Y,oe,W-O,Q-W,$)}_.push(Te),T.push(nt)}function d(z,k,_,T){let j=[],C=0,P=-1;for(;o.pos>k;){let{id:O,start:W,end:E,size:Q}=o;if(Q>4)o.next();else{if(P>-1&&W=0;E-=3)O[Q++]=j[E],O[Q++]=j[E+1]-W,O[Q++]=j[E+2]-W,O[Q++]=Q;_.push(new Mn(O,j[2]-W,n)),T.push(W-z)}}function h(z,k){return(_,T,j)=>{let C=0,P=_.length-1,O,W;if(P>=0&&(O=_[P])instanceof je){if(!P&&O.type==z&&O.length==j)return O;(W=O.prop(K.lookAhead))&&(C=T[P]+O.length+W-j)}return f(z,_,T,j,C,k)}}function g(z,k,_,T,j,C,P,O,W){let E=[],Q=[];for(;z.length>T;)E.push(z.pop()),Q.push(k.pop()+_-j);z.push(f(n.types[P],E,Q,C-j,O-C,W)),k.push(j-_)}function f(z,k,_,T,j,C,P){if(C){let O=[K.contextHash,C];P=P?[O].concat(P):[O]}if(j>25){let O=[K.lookAhead,j];P=P?[O].concat(P):[O]}return new je(z,k,_,T,P)}function x(z,k){let _=o.fork(),T=0,j=0,C=0,P=_.end-a,O={size:0,start:0,skip:0};e:for(let W=_.pos-z;_.pos>W;){let E=_.size;if(_.id==k&&E>=0){O.size=T,O.start=j,O.skip=C,C+=4,T+=4,_.next();continue}let Q=_.pos-E;if(E<0||Q=r?4:0,he=_.start;for(_.next();_.pos>Q;){if(_.size<0)if(_.size==-3||_.size==-4)$+=4;else break e;else _.id>=r&&($+=4);_.next()}j=he,T+=E,C+=$}return(k<0||T==z)&&(O.size=T,O.start=j,O.skip=C),O.size>4?O:void 0}function b(z,k,_){let{id:T,start:j,end:C,size:P}=o;if(o.next(),P>=0&&T4){let W=o.pos-(P-4);for(;o.pos>W;)_=b(z,k,_)}k[--_]=O,k[--_]=C-z,k[--_]=j-z,k[--_]=T}else P==-3?u=T:P==-4&&(m=T);return _}let v=[],w=[];for(;o.pos>0;)c(i.start||0,i.bufferStart||0,v,w,-1,0);let S=(e=i.length)!==null&&e!==void 0?e:v.length?w[0]+v[0].length:0;return new je(l[i.topID],v.reverse(),w.reverse(),S)}const oc=new WeakMap;function Ha(i,e){if(!i.isAnonymous||e instanceof Mn||e.type!=i)return 1;let t=oc.get(e);if(t==null){t=1;for(let n of e.children){if(n.type!=i||!(n instanceof je)){t=1;break}t+=Ha(i,n)}oc.set(e,t)}return t}function S0(i,e,t,n,a,s,r,o,l){let u=0;for(let g=n;g=m)break;k+=_}if(w==S+1){if(k>m){let _=g[S];h(_.children,_.positions,0,_.children.length,f[S]+v);continue}c.push(g[S])}else{let _=f[w-1]+g[w-1].length-z;c.push(S0(i,g,f,S,w,z,_,null,l))}d.push(z+v-s)}}return h(e,t,n,a,0),(o||l)(c,d,r)}class t1{constructor(e,t,n,a,s=!1,r=!1){this.from=e,this.to=t,this.tree=n,this.offset=a,this.open=(s?1:0)|(r?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],n=!1){let a=[new t1(0,e.length,e,0,!1,n)];for(let s of t)s.to>e.length&&a.push(s);return a}static applyChanges(e,t,n=128){if(!t.length)return e;let a=[],s=1,r=e.length?e[0]:null;for(let o=0,l=0,u=0;;o++){let m=o=n)for(;r&&r.from=d.from||c<=d.to||u){let h=Math.max(d.from,l)-u,g=Math.min(d.to,c)-u;d=h>=g?null:new t1(h,g,d.tree,d.offset+u,o>0,!!m)}if(d&&a.push(d),r.to>c)break;r=snew Mr(a.from,a.to)):[new Mr(0,0)]:[new Mr(0,e.length)],this.createParse(e,t||[],n)}parse(e,t,n){let a=this.startParse(e,t,n);for(;;){let s=a.advance();if(s)return s}}}class FL{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new K({perNode:!0});let JL=0;class Tt{constructor(e,t,n,a){this.name=e,this.set=t,this.base=n,this.modified=a,this.id=JL++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let n=typeof e=="string"?e:"?";if(e instanceof Tt&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let a=new Tt(n,[],null,[]);if(a.set.push(a),t)for(let s of t.set)a.set.push(s);return a}static defineModifier(e){let t=new Ss(e);return n=>n.modified.indexOf(t)>-1?n:Ss.get(n.base||n,n.modified.concat(t).sort((a,s)=>a.id-s.id))}}let RL=0;class Ss{constructor(e){this.name=e,this.instances=[],this.id=RL++}static get(e,t){if(!t.length)return e;let n=t[0].instances.find(o=>o.base==e&&GL(t,o.modified));if(n)return n;let a=[],s=new Tt(e.name,a,e,t);for(let o of t)o.instances.push(s);let r=HL(t);for(let o of e.set)if(!o.modified.length)for(let l of r)a.push(Ss.get(o,l));return s}}function GL(i,e){return i.length==e.length&&i.every((t,n)=>t==e[n])}function HL(i){let e=[[]];for(let t=0;tn.length-t.length)}function Cp(i){let e=Object.create(null);for(let t in i){let n=i[t];Array.isArray(n)||(n=[n]);for(let a of t.split(" "))if(a){let s=[],r=2,o=a;for(let c=0;;){if(o=="..."&&c>0&&c+3==a.length){r=1;break}let d=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!d)throw new RangeError("Invalid path: "+a);if(s.push(d[0]=="*"?"":d[0][0]=='"'?JSON.parse(d[0]):d[0]),c+=d[0].length,c==a.length)break;let h=a[c++];if(c==a.length&&h=="!"){r=0;break}if(h!="/")throw new RangeError("Invalid path: "+a);o=a.slice(c)}let l=s.length-1,u=s[l];if(!u)throw new RangeError("Invalid path: "+a);let m=new Pi(n,r,l>0?s.slice(0,l):null);e[u]=m.sort(e[u])}}return Bp.add(e)}const Bp=new K({combine(i,e){let t,n,a;for(;i||e;){if(!i||e&&i.depth<=e.depth?(a=e,e=e.next):(a=i,i=i.next),t&&t.mode==a.mode&&!a.context&&!t.context)continue;let s=new Pi(a.tags,a.mode,a.context);t?t.next=s:n=s,t=s}return n}});class Pi{constructor(e,t,n,a){this.tags=e,this.mode=t,this.context=n,this.next=a}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth{let r=a;for(let o of s)for(let l of o.set){let u=t[l.id];if(u){r=r?r+" "+u:u;break}}return r},scope:n}}function VL(i,e){let t=null;for(let n of i){let a=n.style(e);a&&(t=t?t+" "+a:a)}return t}function QL(i,e,t,n=0,a=i.length){let s=new qL(n,Array.isArray(e)?e:[e],t);s.highlightRange(i.cursor(),n,a,"",s.highlighters),s.flush(a)}class qL{constructor(e,t,n){this.at=e,this.highlighters=t,this.span=n,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,n,a,s){let{type:r,from:o,to:l}=e;if(o>=n||l<=t)return;r.isTop&&(s=this.highlighters.filter(h=>!h.scope||h.scope(r)));let u=a,m=UL(e)||Pi.empty,c=VL(s,m.tags);if(c&&(u&&(u+=" "),u+=c,m.mode==1&&(a+=(a?" ":"")+c)),this.startSpan(Math.max(t,o),u),m.opaque)return;let d=e.tree&&e.tree.prop(K.mounted);if(d&&d.overlay){let h=e.node.enter(d.overlay[0].from+o,1),g=this.highlighters.filter(x=>!x.scope||x.scope(d.tree.type)),f=e.firstChild();for(let x=0,b=o;;x++){let v=x=w||!e.nextSibling())););if(!v||w>n)break;b=v.to+o,b>t&&(this.highlightRange(h.cursor(),Math.max(t,v.from+o),Math.min(n,b),"",g),this.startSpan(Math.min(n,b),u))}f&&e.parent()}else if(e.firstChild()){d&&(a="");do if(!(e.to<=t)){if(e.from>=n)break;this.highlightRange(e,t,n,a,s),this.startSpan(Math.min(n,e.to),u)}while(e.nextSibling());e.parent()}}}function UL(i){let e=i.type.prop(Bp);for(;e&&e.context&&!i.matchContext(e.context);)e=e.next;return e||null}const N=Tt.define,Ia=N(),zn=N(),lc=N(zn),uc=N(zn),In=N(),ka=N(In),Lr=N(In),Xt=N(),Fn=N(Xt),$t=N(),Yt=N(),fl=N(),H1=N(fl),Sa=N(),M={comment:Ia,lineComment:N(Ia),blockComment:N(Ia),docComment:N(Ia),name:zn,variableName:N(zn),typeName:lc,tagName:N(lc),propertyName:uc,attributeName:N(uc),className:N(zn),labelName:N(zn),namespace:N(zn),macroName:N(zn),literal:In,string:ka,docString:N(ka),character:N(ka),attributeValue:N(ka),number:Lr,integer:N(Lr),float:N(Lr),bool:N(In),regexp:N(In),escape:N(In),color:N(In),url:N(In),keyword:$t,self:N($t),null:N($t),atom:N($t),unit:N($t),modifier:N($t),operatorKeyword:N($t),controlKeyword:N($t),definitionKeyword:N($t),moduleKeyword:N($t),operator:Yt,derefOperator:N(Yt),arithmeticOperator:N(Yt),logicOperator:N(Yt),bitwiseOperator:N(Yt),compareOperator:N(Yt),updateOperator:N(Yt),definitionOperator:N(Yt),typeOperator:N(Yt),controlOperator:N(Yt),punctuation:fl,separator:N(fl),bracket:H1,angleBracket:N(H1),squareBracket:N(H1),paren:N(H1),brace:N(H1),content:Xt,heading:Fn,heading1:N(Fn),heading2:N(Fn),heading3:N(Fn),heading4:N(Fn),heading5:N(Fn),heading6:N(Fn),contentSeparator:N(Xt),list:N(Xt),quote:N(Xt),emphasis:N(Xt),strong:N(Xt),link:N(Xt),monospace:N(Xt),strikethrough:N(Xt),inserted:N(),deleted:N(),changed:N(),invalid:N(),meta:Sa,documentMeta:N(Sa),annotation:N(Sa),processingInstruction:N(Sa),definition:Tt.defineModifier("definition"),constant:Tt.defineModifier("constant"),function:Tt.defineModifier("function"),standard:Tt.defineModifier("standard"),local:Tt.defineModifier("local"),special:Tt.defineModifier("special")};for(let i in M){let e=M[i];e instanceof Tt&&(e.name=i)}Dp([{tag:M.link,class:"tok-link"},{tag:M.heading,class:"tok-heading"},{tag:M.emphasis,class:"tok-emphasis"},{tag:M.strong,class:"tok-strong"},{tag:M.keyword,class:"tok-keyword"},{tag:M.atom,class:"tok-atom"},{tag:M.bool,class:"tok-bool"},{tag:M.url,class:"tok-url"},{tag:M.labelName,class:"tok-labelName"},{tag:M.inserted,class:"tok-inserted"},{tag:M.deleted,class:"tok-deleted"},{tag:M.literal,class:"tok-literal"},{tag:M.string,class:"tok-string"},{tag:M.number,class:"tok-number"},{tag:[M.regexp,M.escape,M.special(M.string)],class:"tok-string2"},{tag:M.variableName,class:"tok-variableName"},{tag:M.local(M.variableName),class:"tok-variableName tok-local"},{tag:M.definition(M.variableName),class:"tok-variableName tok-definition"},{tag:M.special(M.variableName),class:"tok-variableName2"},{tag:M.definition(M.propertyName),class:"tok-propertyName tok-definition"},{tag:M.typeName,class:"tok-typeName"},{tag:M.namespace,class:"tok-namespace"},{tag:M.className,class:"tok-className"},{tag:M.macroName,class:"tok-macroName"},{tag:M.propertyName,class:"tok-propertyName"},{tag:M.operator,class:"tok-operator"},{tag:M.comment,class:"tok-comment"},{tag:M.meta,class:"tok-meta"},{tag:M.invalid,class:"tok-invalid"},{tag:M.punctuation,class:"tok-punctuation"}]);var Wr;const v1=new K;function $L(i){return G.define({combine:i?e=>e.concat(i):void 0})}const YL=new K;class Rt{constructor(e,t,n=[],a=""){this.data=e,this.name=a,ie.prototype.hasOwnProperty("tree")||Object.defineProperty(ie.prototype,"tree",{get(){return et(this)}}),this.parser=t,this.extension=[Z1.of(this),ie.languageData.of((s,r,o)=>{let l=mc(s,r,o),u=l.type.prop(v1);if(!u)return[];let m=s.facet(u),c=l.type.prop(YL);if(c){let d=l.resolve(r-l.from,o);for(let h of c)if(h.test(d,s)){let g=s.facet(h.facet);return h.type=="replace"?g:g.concat(m)}}return m})].concat(n)}isActiveAt(e,t,n=-1){return mc(e,t,n).type.prop(v1)==this.data}findRegions(e){let t=e.facet(Z1);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let n=[],a=(s,r)=>{if(s.prop(v1)==this.data){n.push({from:r,to:r+s.length});return}let o=s.prop(K.mounted);if(o){if(o.tree.prop(v1)==this.data){if(o.overlay)for(let l of o.overlay)n.push({from:l.from+r,to:l.to+r});else n.push({from:r,to:r+s.length});return}else if(o.overlay){let l=n.length;if(a(o.tree,o.overlay[0].from+r),n.length>l)return}}for(let l=0;ln.isTop?t:void 0)]}),e.name)}configure(e,t){return new _s(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function et(i){let e=i.field(Rt.state,!1);return e?e.tree:je.empty}class XL{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let n=this.cursorPos-this.string.length;return e=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-n,t-n)}}let V1=null;class Ts{constructor(e,t,n=[],a,s,r,o,l){this.parser=e,this.state=t,this.fragments=n,this.tree=a,this.treeLen=s,this.viewport=r,this.skipped=o,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(e,t,n){return new Ts(e,t,[],je.empty,0,n,[],null)}startParse(){return this.parser.startParse(new XL(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=je.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var n;if(typeof e=="number"){let a=Date.now()+e;e=()=>Date.now()>a}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(t1.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=V1;V1=this;try{return e()}finally{V1=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=cc(e,t.from,t.to);return e}changes(e,t){let{fragments:n,tree:a,treeLen:s,viewport:r,skipped:o}=this;if(this.takeTree(),!e.empty){let l=[];if(e.iterChangedRanges((u,m,c,d)=>l.push({fromA:u,toA:m,fromB:c,toB:d})),n=t1.applyChanges(n,l),a=je.empty,s=0,r={from:e.mapPos(r.from,-1),to:e.mapPos(r.to,1)},this.skipped.length){o=[];for(let u of this.skipped){let m=e.mapPos(u.from,1),c=e.mapPos(u.to,-1);me.from&&(this.fragments=cc(this.fragments,a,s),this.skipped.splice(n--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends jp{createParse(t,n,a){let s=a[0].from,r=a[a.length-1].to;return{parsedPos:s,advance(){let l=V1;if(l){for(let u of a)l.tempSkipped.push(u);e&&(l.scheduleOn=l.scheduleOn?Promise.all([l.scheduleOn,e]):e)}return this.parsedPos=r,new je(dt.none,[],[],r-s)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return V1}}function cc(i,e,t){return t1.applyChanges(i,[{fromA:e,toA:t,fromB:e,toB:t}])}class D1{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),n=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,n)||t.takeTree(),new D1(t)}static init(e){let t=Math.min(3e3,e.doc.length),n=Ts.create(e.facet(Z1).parser,e,{from:0,to:t});return n.work(20,t)||n.takeTree(),new D1(n)}}Rt.state=Zt.define({create:D1.init,update(i,e){for(let t of e.effects)if(t.is(Rt.setState))return t.value;return e.startState.facet(Z1)!=e.state.facet(Z1)?D1.init(e.state):i.apply(e)}});let Zp=i=>{let e=setTimeout(()=>i(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Zp=i=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(i,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Er=typeof navigator<"u"&&(!((Wr=navigator.scheduling)===null||Wr===void 0)&&Wr.isInputPending)?()=>navigator.scheduling.isInputPending():null,KL=Dt.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Rt.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Rt.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Zp(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnda+1e3,l=s.context.work(()=>Er&&Er()||Date.now()>r,a+(o?0:1e5));this.chunkBudget-=Date.now()-t,(l||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Rt.setState.of(new D1(s.context))})),this.chunkBudget>0&&!(l&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>bt(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Z1=G.define({combine(i){return i.length?i[0]:null},enables:i=>[Rt.state,KL,H.contentAttributes.compute([i],e=>{let t=e.facet(i);return t&&t.name?{"data-language":t.name}:{}})]});class eW{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const tW=G.define(),Ri=G.define({combine:i=>{if(!i.length)return" ";let e=i[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(i[0]));return e}});function Os(i){let e=i.facet(Ri);return e.charCodeAt(0)==9?i.tabSize*e.length:e.length}function ji(i,e){let t="",n=i.tabSize,a=i.facet(Ri)[0];if(a==" "){for(;e>=n;)t+=" ",e-=n;a=" "}for(let s=0;s=e?nW(i,t,e):null}class Xs{constructor(e,t={}){this.state=e,this.options=t,this.unit=Os(e)}lineAt(e,t=1){let n=this.state.doc.lineAt(e),{simulateBreak:a,simulateDoubleBreak:s}=this.options;return a!=null&&a>=n.from&&a<=n.to?s&&a==e?{text:"",from:e}:(t<0?a-1&&(s+=r-this.countColumn(n,n.search(/\S|$/))),s}countColumn(e,t=e.length){return Wi(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:n,from:a}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let r=s(a);if(r>-1)return r}return this.countColumn(n,n.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Mp=new K;function nW(i,e,t){let n=e.resolveStack(t),a=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(a!=n.node){let s=[];for(let r=a;r&&!(r.fromn.node.to||r.from==n.node.from&&r.type==n.node.type);r=r.parent)s.push(r);for(let r=s.length-1;r>=0;r--)n={node:s[r],next:n}}return Lp(n,i,t)}function Lp(i,e,t){for(let n=i;n;n=n.next){let a=aW(n.node);if(a)return a(T0.create(e,t,n))}return 0}function iW(i){return i.pos==i.options.simulateBreak&&i.options.simulateDoubleBreak}function aW(i){let e=i.type.prop(Mp);if(e)return e;let t=i.firstChild,n;if(t&&(n=t.type.prop(K.closedBy))){let a=i.lastChild,s=a&&n.indexOf(a.name)>-1;return r=>Wp(r,!0,1,void 0,s&&!iW(r)?a.from:void 0)}return i.parent==null?sW:null}function sW(){return 0}class T0 extends Xs{constructor(e,t,n){super(e.state,e.options),this.base=e,this.pos=t,this.context=n}get node(){return this.context.node}static create(e,t,n){return new T0(e,t,n)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let n=e.resolve(t.from);for(;n.parent&&n.parent.from==n.from;)n=n.parent;if(rW(n,e))break;t=this.state.doc.lineAt(n.from)}return this.lineIndent(t.from)}continue(){return Lp(this.context.next,this.base,this.pos)}}function rW(i,e){for(let t=e;t;t=t.parent)if(i==t)return!0;return!1}function oW(i){let e=i.node,t=e.childAfter(e.from),n=e.lastChild;if(!t)return null;let a=i.options.simulateBreak,s=i.state.doc.lineAt(t.from),r=a==null||a<=s.from?s.to:Math.min(s.to,a);for(let o=t.to;;){let l=e.childAfter(o);if(!l||l==n)return null;if(!l.type.isSkipped){if(l.from>=r)return null;let u=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+u}}o=l.to}}function lW({closing:i,align:e=!0,units:t=1}){return n=>Wp(n,e,t,i)}function Wp(i,e,t,n,a){let s=i.textAfter,r=s.match(/^\s*/)[0].length,o=n&&s.slice(r,r+n.length)==n||a==i.pos+r,l=e?oW(i):null;return l?o?i.column(l.from):i.column(l.to):i.baseIndent+(o?0:i.unit*t)}const uW=i=>i.baseIndent;function Nr({except:i,units:e=1}={}){return t=>{let n=i&&i.test(t.textAfter);return t.baseIndent+(n?0:e*t.unit)}}const mW=200;function cW(){return ie.transactionFilter.of(i=>{if(!i.docChanged||!i.isUserEvent("input.type")&&!i.isUserEvent("input.complete"))return i;let e=i.startState.languageDataAt("indentOnInput",i.startState.selection.main.head);if(!e.length)return i;let t=i.newDoc,{head:n}=i.newSelection.main,a=t.lineAt(n);if(n>a.from+mW)return i;let s=t.sliceString(a.from,n);if(!e.some(u=>u.test(s)))return i;let{state:r}=i,o=-1,l=[];for(let{head:u}of r.selection.ranges){let m=r.doc.lineAt(u);if(m.from==o)continue;o=m.from;let c=_0(r,m.from);if(c==null)continue;let d=/^\s*/.exec(m.text)[0],h=ji(r,c);d!=h&&l.push({from:m.from,to:m.from+d.length,insert:h})}return l.length?[i,{changes:l,sequential:!0}]:i})}const dW=new K;function hW(i){let e=i.firstChild,t=i.lastChild;return e&&e.too.prop(v1)==r.data:r?o=>o==r:void 0,this.style=Dp(e.map(o=>({tag:o.tag,class:o.class||a(Object.assign({},o,{tag:null}))})),{all:s}).style,this.module=n?new Bn(n):null,this.themeType=t.themeType}static define(e,t){return new Ks(e,t||{})}}const xl=G.define(),gW=G.define({combine(i){return i.length?[i[0]]:null}});function Fr(i){let e=i.facet(xl);return e.length?e:i.facet(gW)}function pW(i,e){let t=[xW],n;return i instanceof Ks&&(i.module&&t.push(H.styleModule.of(i.module)),n=i.themeType),n?t.push(xl.computeN([H.darkTheme],a=>a.facet(H.darkTheme)==(n=="dark")?[i]:[])):t.push(xl.of(i)),t}class fW{constructor(e){this.markCache=Object.create(null),this.tree=et(e.state),this.decorations=this.buildDeco(e,Fr(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=et(e.state),n=Fr(e.state),a=n!=Fr(e.startState),{viewport:s}=e.view,r=e.changes.mapPos(this.decoratedTo,1);t.length=s.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=r):(t!=this.tree||e.viewportChanged||a)&&(this.tree=t,this.decorations=this.buildDeco(e.view,n),this.decoratedTo=s.to)}buildDeco(e,t){if(!t||!this.tree.length)return ue.none;let n=new e1;for(let{from:a,to:s}of e.visibleRanges)QL(this.tree,t,(r,o,l)=>{n.add(r,o,this.markCache[l]||(this.markCache[l]=ue.mark({class:l})))},a,s);return n.finish()}}const xW=r1.high(Dt.fromClass(fW,{decorations:i=>i.decorations})),bW=H.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ep=1e4,Np="()[]{}",Fp=G.define({combine(i){return u0(i,{afterCursor:!0,brackets:Np,maxScanDistance:Ep,renderMatch:wW})}}),vW=ue.mark({class:"cm-matchingBracket"}),yW=ue.mark({class:"cm-nonmatchingBracket"});function wW(i){let e=[],t=i.matched?vW:yW;return e.push(t.range(i.start.from,i.start.to)),i.end&&e.push(t.range(i.end.from,i.end.to)),e}function dc(i){let e=[],t=i.facet(Fp);for(let n of i.selection.ranges){if(!n.empty)continue;let a=sn(i,n.head,-1,t)||n.head>0&&sn(i,n.head-1,1,t)||t.afterCursor&&(sn(i,n.head,1,t)||n.headi.decorations}),IW=[zW,bW];function kW(i={}){return[Fp.of(i),IW]}const SW=new K;function bl(i,e,t){let n=i.prop(e<0?K.openedBy:K.closedBy);if(n)return n;if(i.name.length==1){let a=t.indexOf(i.name);if(a>-1&&a%2==(e<0?1:0))return[t[a+e]]}return null}function vl(i){let e=i.type.prop(SW);return e?e(i.node):i}function sn(i,e,t,n={}){let a=n.maxScanDistance||Ep,s=n.brackets||Np,r=et(i),o=r.resolveInner(e,t);for(let l=o;l;l=l.parent){let u=bl(l.type,t,s);if(u&&l.from0?e>=m.from&&em.from&&e<=m.to))return _W(i,e,t,l,m,u,s)}}return TW(i,e,t,r,o.type,a,s)}function _W(i,e,t,n,a,s,r){let o=n.parent,l={from:a.from,to:a.to},u=0,m=o==null?void 0:o.cursor();if(m&&(t<0?m.childBefore(n.from):m.childAfter(n.to)))do if(t<0?m.to<=n.from:m.from>=n.to){if(u==0&&s.indexOf(m.type.name)>-1&&m.from0)return null;let u={from:t<0?e-1:e,to:t>0?e+1:e},m=i.doc.iterRange(e,t>0?i.doc.length:0),c=0;for(let d=0;!m.next().done&&d<=s;){let h=m.value;t<0&&(d+=h.length);let g=e+d*t;for(let f=t>0?0:h.length-1,x=t>0?h.length:-1;f!=x;f+=t){let b=r.indexOf(h[f]);if(!(b<0||n.resolveInner(g+f,1).type!=a))if(b%2==0==t>0)c++;else{if(c==1)return{start:u,end:{from:g+f,to:g+f+1},matched:b>>1==l>>1};c--}}t>0&&(d+=h.length)}return m.done?{start:u,matched:!1}:null}const OW=Object.create(null),hc=[dt.none],gc=[],pc=Object.create(null),AW=Object.create(null);for(let[i,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])AW[i]=PW(OW,e);function Jr(i,e){gc.indexOf(i)>-1||(gc.push(i),console.warn(e))}function PW(i,e){let t=[];for(let o of e.split(" ")){let l=[];for(let u of o.split(".")){let m=i[u]||M[u];m?typeof m=="function"?l.length?l=l.map(m):Jr(u,`Modifier ${u} used at start of tag`):l.length?Jr(u,`Tag ${u} used as modifier`):l=Array.isArray(m)?m:[m]:Jr(u,`Unknown highlighting tag ${u}`)}for(let u of l)t.push(u)}if(!t.length)return 0;let n=e.replace(/ /g,"_"),a=n+" "+t.map(o=>o.id),s=pc[a];if(s)return s.id;let r=pc[a]=dt.define({id:hc.length,name:n,props:[Cp({[n]:t})]});return hc.push(r),r.id}de.RTL,de.LTR;class Jp{constructor(e,t,n,a){this.state=e,this.pos=t,this.explicit=n,this.view=a,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=et(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),a=t.text.slice(n-t.from,this.pos-t.from),s=a.search(Rp(e,!1));return s<0?null:{from:n+s,to:this.pos,text:a.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 fc(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 jW(i){let e=Object.create(null),t=Object.create(null);for(let{label:a}of i){e[a[0]]=!0;for(let s=1;stypeof a=="string"?{label:a}:a),[t,n]=e.every(a=>/^\w+$/.test(a.label))?[/\w*$/,/\w+$/]:jW(e);return a=>{let s=a.matchBefore(n);return s||a.explicit?{from:s?s.from:a.pos,options:e,validFor:t}:null}}class xc{constructor(e,t,n,a){this.completion=e,this.source=t,this.match=n,this.score=a}}function n1(i){return i.selection.main.from}function Rp(i,e){var t;let{source:n}=i,a=e&&n[0]!="^",s=n[n.length-1]!="$";return!a&&!s?i:new RegExp(`${a?"^":""}(?:${n})${s?"$":""}`,(t=i.flags)!==null&&t!==void 0?t:i.ignoreCase?"i":"")}const O0=Ln.define();function BW(i,e,t,n){let{main:a}=i.selection,s=t-a.from,r=n-a.from;return{...i.changeByRange(o=>{if(o!=a&&t!=n&&i.sliceDoc(o.from+s,o.from+r)!=i.sliceDoc(t,n))return{range:o};let l=i.toText(e);return{changes:{from:o.from+s,to:n==a.from?o.to:o.from+r,insert:l},range:B.cursor(o.from+s+l.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const bc=new WeakMap;function DW(i){if(!Array.isArray(i))return i;let e=bc.get(i);return e||bc.set(i,e=CW(i)),e}const As=re.define(),Ci=re.define();class ZW{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&&z<=57||z>=97&&z<=122?2:z>=65&&z<=90?1:0:(k=hg(z))!=k.toLowerCase()?1:k!=k.toUpperCase()?2:0;(!v||_==1&&x||S==0&&_!=0)&&(t[c]==z||n[c]==z&&(d=!0)?r[c++]=v:r.length&&(b=!1)),S=_,v+=un(z)}return c==l&&r[0]==0&&b?this.result(-100+(d?-200:0),r,e):h==l&&g==0?this.ret(-200-e.length+(f==e.length?0:-100),[0,f]):o>-1?this.ret(-700-e.length,[o,o+this.pattern.length]):h==l?this.ret(-900-e.length,[g,f]):c==l?this.result(-100+(d?-200:0)+-700+(b?0:-1100),r,e):t.length==2?null:this.result((a[0]?-700:0)+-200+-1100,a,e)}result(e,t,n){let a=[],s=0;for(let r of t){let o=r+(this.astral?un(_t(n,r)):1);s&&a[s-1]==r?a[s-1]=o:(a[s++]=r,a[s++]=o)}return this.ret(e-n.length,a)}}class MW{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:LW,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=>vc(e(n),t(n)),optionClass:(e,t)=>n=>vc(e(n),t(n)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function vc(i,e){return i?e?i+" "+e:i:e}function LW(i,e,t,n,a,s){let r=i.textDirection==de.RTL,o=r,l=!1,u="top",m,c,d=e.left-a.left,h=a.right-e.right,g=n.right-n.left,f=n.bottom-n.top;if(o&&d=f||v>e.top?m=t.bottom-e.top:(u="bottom",m=e.bottom-t.top)}let x=(e.bottom-e.top)/s.offsetHeight,b=(e.right-e.left)/s.offsetWidth;return{style:`${u}: ${m/x}px; max-width: ${c/b}px`,class:"cm-completionInfo-"+(l?r?"left-narrow":"right-narrow":o?"left":"right")}}const A0=re.define();function WW(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(a=>"cm-completionIcon-"+a)),n.setAttribute("aria-hidden","true"),n},position:20}),e.push({render(t,n,a,s){let r=document.createElement("span");r.className="cm-completionLabel";let o=t.displayLabel||t.label,l=0;for(let u=0;ul&&r.appendChild(document.createTextNode(o.slice(l,m)));let d=r.appendChild(document.createElement("span"));d.appendChild(document.createTextNode(o.slice(m,c))),d.className="cm-completionMatchedText",l=c}return lt.position-n.position).map(t=>t.render)}function Rr(i,e,t){if(i<=t)return{from:0,to:i};if(e<0&&(e=0),e<=i>>1){let a=Math.floor(e/t);return{from:a*t,to:(a+1)*t}}let n=Math.ceil((i-e)/t);return{from:i-n*t,to:i-(n-1)*t}}class EW{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:l=>this.placeInfo(l),key:this},this.space=null,this.currentClass="";let a=e.state.field(t),{options:s,selected:r}=a.open,o=e.state.facet(We);this.optionContent=WW(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=Rr(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",l=>{let{options:u}=e.state.field(t).open;for(let m=l.target,c;m&&m!=this.dom;m=m.parentNode)if(m.nodeName=="LI"&&(c=/-(\d+)$/.exec(m.id))&&+c[1]this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;m!=null&&(e.dispatch({effects:A0.of(m)}),l.preventDefault())}}),this.dom.addEventListener("focusout",l=>{let u=e.state.field(this.stateField,!1);u&&u.tooltip&&e.state.facet(We).closeOnBlur&&l.relatedTarget!=e.contentDOM&&e.dispatch({effects:Ci.of(null)})}),this.showOptions(s,a.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),a=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),n!=a){let{options:s,selected:r,disabled:o}=n.open;(!a.open||a.open.options!=s)&&(this.range=Rr(s.length,r,e.state.facet(We).maxRenderedOptions),this.showOptions(s,n.id)),this.updateSel(),o!=((t=a.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}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=Rr(t.options.length,t.selected,this.view.state.facet(We).maxRenderedOptions),this.showOptions(t.options,e.id));let n=this.updateSelectedOption(t.selected);if(n){this.destroyInfo();let{completion:a}=t.options[t.selected],{info:s}=a;if(!s)return;let r=typeof s=="string"?document.createTextNode(s):s(a);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,a)}).catch(o=>bt(this.view.state,o,"completion info")):(this.addInfoPane(r,a),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:a,destroy:s}=e;n.appendChild(a),this.infoDestroy=s||null}this.dom.appendChild(n),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let n=this.list.firstChild,a=this.range.from;n;n=n.nextSibling,a++)n.nodeName!="LI"||!n.id?a--:a==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&&FW(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(),a=e.getBoundingClientRect(),s=this.space;if(!s){let r=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:r.clientWidth,bottom:r.clientHeight}}return a.top>Math.min(s.bottom,t.bottom)-10||a.bottom{r.target==a&&r.preventDefault()});let s=null;for(let r=n.from;rn.from||n.from==0))if(s=d,typeof u!="string"&&u.header)a.appendChild(u.header(u));else{let h=a.appendChild(document.createElement("completion-section"));h.textContent=d}}const m=a.appendChild(document.createElement("li"));m.id=t+"-"+r,m.setAttribute("role","option");let c=this.optionClass(o);c&&(m.className=c);for(let d of this.optionContent){let h=d(o,this.view.state,this.view,l);h&&m.appendChild(h)}}return n.from&&a.classList.add("cm-completionListIncompleteTop"),n.tonew EW(t,i,e)}function FW(i,e){let t=i.getBoundingClientRect(),n=e.getBoundingClientRect(),a=t.height/i.offsetHeight;n.topt.bottom&&(i.scrollTop+=(n.bottom-t.bottom)/a)}function yc(i){return(i.boost||0)*100+(i.apply?10:0)+(i.info?5:0)+(i.type?1:0)}function JW(i,e){let t=[],n=null,a=null,s=m=>{t.push(m);let{section:c}=m.completion;if(c){n||(n=[]);let d=typeof c=="string"?c:c.name;n.some(h=>h.name==d)||n.push(typeof c=="string"?{name:d}:c)}},r=e.facet(We);for(let m of i)if(m.hasResult()){let c=m.result.getMatch;if(m.result.filter===!1)for(let d of m.result.options)s(new xc(d,m.source,c?c(d):[],1e9-t.length));else{let d=e.sliceDoc(m.from,m.to),h,g=r.filterStrict?new MW(d):new ZW(d);for(let f of m.result.options)if(h=g.match(f.label)){let x=f.displayLabel?c?c(f,h.matched):[]:h.matched,b=h.score+(f.boost||0);if(s(new xc(f,m.source,x,b)),typeof f.section=="object"&&f.section.rank==="dynamic"){let{name:v}=f.section;a||(a=Object.create(null)),a[v]=Math.max(b,a[v]||-1e9)}}}}if(n){let m=Object.create(null),c=0,d=(h,g)=>(h.rank==="dynamic"&&g.rank==="dynamic"?a[g.name]-a[h.name]:0)||(typeof h.rank=="number"?h.rank:1e9)-(typeof g.rank=="number"?g.rank:1e9)||(h.named.score-c.score||u(c.completion,d.completion))){let c=m.completion;!l||l.label!=c.label||l.detail!=c.detail||l.type!=null&&c.type!=null&&l.type!=c.type||l.apply!=c.apply||l.boost!=c.boost?o.push(m):yc(m.completion)>yc(l)&&(o[o.length-1]=m),l=m.completion}return o}class y1{constructor(e,t,n,a,s,r){this.options=e,this.attrs=t,this.tooltip=n,this.timestamp=a,this.selected=s,this.disabled=r}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new y1(this.options,wc(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,n,a,s,r){if(a&&!r&&e.some(u=>u.isPending))return a.setDisabled();let o=JW(e,t);if(!o.length)return a&&e.some(u=>u.isPending)?a.setDisabled():null;let l=t.facet(We).selectOnOpen?0:-1;if(a&&a.selected!=l&&a.selected!=-1){let u=a.options[a.selected].completion;for(let m=0;mm.hasResult()?Math.min(u,m.from):u,1e8),create:qW,above:s.aboveCursor},a?a.timestamp:Date.now(),l,!1)}map(e){return new y1(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new y1(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class Ps{constructor(e,t,n){this.active=e,this.id=t,this.open=n}static start(){return new Ps(VW,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,n=t.facet(We),s=(n.override||t.languageDataAt("autocomplete",n1(t)).map(DW)).map(l=>(this.active.find(m=>m.source==l)||new Ct(l,this.active.some(m=>m.state!=0)?1:0)).update(e,n));s.length==this.active.length&&s.every((l,u)=>l==this.active[u])&&(s=this.active);let r=this.open,o=e.effects.some(l=>l.is(P0));r&&e.docChanged&&(r=r.map(e.changes)),e.selection||s.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!RW(s,this.active)||o?r=y1.build(s,t,this.id,r,n,o):r&&r.disabled&&!s.some(l=>l.isPending)&&(r=null),!r&&s.every(l=>!l.isPending)&&s.some(l=>l.hasResult())&&(s=s.map(l=>l.hasResult()?new Ct(l.source,0):l));for(let l of e.effects)l.is(A0)&&(r=r&&r.setSelected(l.value,this.id));return s==this.active&&r==this.open?this:new Ps(s,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?GW:HW}}function RW(i,e){if(i==e)return!0;for(let t=0,n=0;;){for(;t-1&&(t["aria-activedescendant"]=i+"-"+e),t}const VW=[];function Gp(i,e){if(i.isUserEvent("input.complete")){let n=i.annotation(O0);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 Ct{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=Gp(e,t),a=this;(n&8||n&16&&this.touches(e))&&(a=new Ct(a.source,0)),n&4&&a.state==0&&(a=new Ct(this.source,1)),a=a.updateFor(e,n);for(let s of e.effects)if(s.is(As))a=new Ct(a.source,1,s.value);else if(s.is(Ci))a=new Ct(a.source,0);else if(s.is(P0))for(let r of s.value)r.source==a.source&&(a=r);return a}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(n1(e.state))}}class _1 extends Ct{constructor(e,t,n,a,s,r){super(e,3,t),this.limit=n,this.result=a,this.from=s,this.to=r}hasResult(){return!0}updateFor(e,t){var n;if(!(t&3))return this.map(e.changes);let a=this.result;a.map&&!e.changes.empty&&(a=a.map(a,e.changes));let s=e.changes.mapPos(this.from),r=e.changes.mapPos(this.to,1),o=n1(e.state);if(o>r||!a||t&2&&(n1(e.startState)==this.from||ot.map(e))}}),mt=Zt.define({create(){return Ps.start()},update(i,e){return i.update(e)},provide:i=>[Ip.from(i,e=>e.tooltip),H.contentAttributes.from(i,e=>e.attrs)]});function j0(i,e){const t=e.completion.apply||e.completion.label;let n=i.state.field(mt).active.find(a=>a.source==e.source);return n instanceof _1?(typeof t=="string"?i.dispatch({...BW(i.state,t,n.from,n.to),annotations:O0.of(e.completion)}):t(i,e.completion,n.from,n.to),!0):!1}const qW=NW(mt,j0);function _a(i,e="option"){return t=>{let n=t.state.field(mt,!1);if(!n||!n.open||n.open.disabled||Date.now()-n.open.timestamp-1?n.open.selected+a*(i?1:-1):i?0:r-1;return o<0?o=e=="page"?0:r-1:o>=r&&(o=e=="page"?r-1:0),t.dispatch({effects:A0.of(o)}),!0}}const UW=i=>{let e=i.state.field(mt,!1);return i.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestampi.state.field(mt,!1)?(i.dispatch({effects:As.of(!0)}),!0):!1,$W=i=>{let e=i.state.field(mt,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(i.dispatch({effects:Ci.of(null)}),!0)};class YW{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const XW=50,KW=1e3,eE=Dt.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(mt).active)e.isPending&&this.startQuery(e)}update(i){let e=i.state.field(mt),t=i.state.facet(We);if(!i.selectionSet&&!i.docChanged&&i.startState.field(mt)==e)return;let n=i.transactions.some(s=>{let r=Gp(s,t);return r&8||(s.selection||s.docChanged)&&!(r&3)});for(let s=0;sXW&&Date.now()-r.time>KW){for(let o of r.context.abortListeners)try{o()}catch(l){bt(this.view.state,l)}r.context.abortListeners=null,this.running.splice(s--,1)}else r.updates.push(...i.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),i.transactions.some(s=>s.effects.some(r=>r.is(As)))&&(this.pendingStart=!0);let a=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.isPending&&!this.running.some(r=>r.active.source==s.source))?setTimeout(()=>this.startUpdate(),a):-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(mt);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(We).updateSyncTime))}startQuery(i){let{state:e}=this.view,t=n1(e),n=new Jp(e,t,i.explicit,this.view),a=new YW(i,n);this.running.push(a),Promise.resolve(i.source(n)).then(s=>{a.context.aborted||(a.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:Ci.of(null)}),bt(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(We).updateSyncTime))}accept(){var i;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(We),n=this.view.state.field(mt);for(let a=0;ao.source==s.active.source);if(r&&r.isPending)if(s.done==null){let o=new Ct(s.active.source,0);for(let l of s.updates)o=o.update(l,t);o.isPending||e.push(o)}else this.startQuery(r)}(e.length||n.open&&n.open.disabled)&&this.view.dispatch({effects:P0.of(e)})}},{eventHandlers:{blur(i){let e=this.view.state.field(mt,!1);if(e&&e.tooltip&&this.view.state.facet(We).closeOnBlur){let t=e.open&&kp(this.view,e.open.tooltip);(!t||!t.dom.contains(i.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Ci.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:As.of(!1)}),20),this.composing=0}}}),tE=typeof navigator=="object"&&/Win/.test(navigator.platform),nE=r1.highest(H.domEventHandlers({keydown(i,e){let t=e.state.field(mt,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||!i.key||i.key.length>1||i.ctrlKey&&!(tE&&i.altKey)||i.metaKey)return!1;let n=t.open.options[t.open.selected],a=t.active.find(r=>r.source==n.source),s=n.completion.commitCharacters||a.result.commitCharacters;return s&&s.indexOf(i.key)>-1&&j0(e,n),!1}})),Hp=H.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",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:"'ƒ'"}},".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 iE{constructor(e,t,n,a){this.field=e,this.line=t,this.from=n,this.to=a}}class C0{constructor(e,t,n){this.field=e,this.from=t,this.to=n}map(e){let t=e.mapPos(this.from,-1,Xe.TrackDel),n=e.mapPos(this.to,1,Xe.TrackDel);return t==null||n==null?null:new C0(this.field,t,n)}}class B0{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let n=[],a=[t],s=e.doc.lineAt(t),r=/^\s*/.exec(s.text)[0];for(let l of this.lines){if(n.length){let u=r,m=/^\t*/.exec(l)[0].length;for(let c=0;cnew C0(l.field,a[l.line]+l.from,a[l.line]+l.to));return{text:n,ranges:o}}static parse(e){let t=[],n=[],a=[],s;for(let r of e.split(/\r\n?|\n/)){for(;s=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(r);){let o=s[1]?+s[1]:null,l=s[2]||s[3]||"",u=-1;o===0&&(o=1e9);let m=l.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c=u&&d.field++}for(let c of a)if(c.line==n.length&&c.from>s.index){let d=s[2]?3+(s[1]||"").length:2;c.from-=d,c.to-=d}a.push(new iE(u,n.length,s.index,s.index+m.length)),r=r.slice(0,s.index)+l+r.slice(s.index+s[0].length)}r=r.replace(/\\([{}])/g,(o,l,u)=>{for(let m of a)m.line==n.length&&m.from>u&&(m.from--,m.to--);return l}),n.push(r)}return new B0(n,a)}}let aE=ue.widget({widget:new class extends Ei{toDOM(){let i=document.createElement("span");return i.className="cm-snippetFieldPosition",i}ignoreEvent(){return!1}}}),sE=ue.mark({class:"cm-snippetField"});class M1{constructor(e,t){this.ranges=e,this.active=t,this.deco=ue.set(e.map(n=>(n.from==n.to?aE:sE).range(n.from,n.to)),!0)}map(e){let t=[];for(let n of this.ranges){let a=n.map(e);if(!a)return null;t.push(a)}return new M1(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 Gi=re.define({map(i,e){return i&&i.map(e)}}),rE=re.define(),Bi=Zt.define({create(){return null},update(i,e){for(let t of e.effects){if(t.is(Gi))return t.value;if(t.is(rE)&&i)return new M1(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=>H.decorations.from(i,e=>e?e.deco:ue.none)});function D0(i,e){return B.create(i.filter(t=>t.field==e).map(t=>B.range(t.from,t.to)))}function oE(i){let e=B0.parse(i);return(t,n,a,s)=>{let{text:r,ranges:o}=e.instantiate(t.state,a),{main:l}=t.state.selection,u={changes:{from:a,to:s==l.from?l.to:s,insert:ae.of(r)},scrollIntoView:!0,annotations:n?[O0.of(n),He.userEvent.of("input.complete")]:void 0};if(o.length&&(u.selection=D0(o,0)),o.some(m=>m.field>0)){let m=new M1(o,0),c=u.effects=[Gi.of(m)];t.state.field(Bi,!1)===void 0&&c.push(re.appendConfig.of([Bi,dE,hE,Hp]))}t.dispatch(t.state.update(u))}}function Vp(i){return({state:e,dispatch:t})=>{let n=e.field(Bi,!1);if(!n||i<0&&n.active==0)return!1;let a=n.active+i,s=i>0&&!n.ranges.some(r=>r.field==a+i);return t(e.update({selection:D0(n.ranges,a),effects:Gi.of(s?null:new M1(n.ranges,a)),scrollIntoView:!0})),!0}}const lE=({state:i,dispatch:e})=>i.field(Bi,!1)?(e(i.update({effects:Gi.of(null)})),!0):!1,uE=Vp(1),mE=Vp(-1),cE=[{key:"Tab",run:uE,shift:mE},{key:"Escape",run:lE}],zc=G.define({combine(i){return i.length?i[0]:cE}}),dE=r1.highest(Oi.compute([zc],i=>i.facet(zc)));function Z0(i,e){return{...e,apply:oE(i)}}const hE=H.domEventHandlers({mousedown(i,e){let t=e.state.field(Bi,!1),n;if(!t||(n=e.posAtCoords({x:i.clientX,y:i.clientY}))==null)return!1;let a=t.ranges.find(s=>s.from<=n&&s.to>=n);return!a||a.field==t.active?!1:(e.dispatch({selection:D0(t.ranges,a.field),effects:Gi.of(t.ranges.some(s=>s.field>a.field)?new M1(t.ranges,a.field):null),scrollIntoView:!0}),!0)}}),Di={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Un=re.define({map(i,e){let t=e.mapPos(i,-1,Xe.TrackAfter);return t??void 0}}),M0=new class extends Cn{};M0.startSide=1;M0.endSide=-1;const Qp=Zt.define({create(){return X.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(Un)&&(i=i.update({add:[M0.range(t.value,t.value+1)]}));return i}});function gE(){return[fE,Qp]}const Hr="()[]{}<>«»»«[]{}";function qp(i){for(let e=0;e{if((pE?i.composing:i.compositionStarted)||i.state.readOnly)return!1;let a=i.state.selection.main;if(n.length>2||n.length==2&&un(_t(n,0))==1||e!=a.from||t!=a.to)return!1;let s=vE(i.state,n);return s?(i.dispatch(s),!0):!1}),xE=({state:i,dispatch:e})=>{if(i.readOnly)return!1;let n=Up(i,i.selection.main.head).brackets||Di.brackets,a=null,s=i.changeByRange(r=>{if(r.empty){let o=yE(i.doc,r.head);for(let l of n)if(l==o&&er(i.doc,r.head)==qp(_t(l,0)))return{changes:{from:r.head-l.length,to:r.head+l.length},range:B.cursor(r.head-l.length)}}return{range:a=r}});return a||e(i.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!a},bE=[{key:"Backspace",run:xE}];function vE(i,e){let t=Up(i,i.selection.main.head),n=t.brackets||Di.brackets;for(let a of n){let s=qp(_t(a,0));if(e==a)return s==a?IE(i,a,n.indexOf(a+a+a)>-1,t):wE(i,a,s,t.before||Di.before);if(e==s&&$p(i,i.selection.main.from))return zE(i,a,s)}return null}function $p(i,e){let t=!1;return i.field(Qp).between(0,i.doc.length,n=>{n==e&&(t=!0)}),t}function er(i,e){let t=i.sliceString(e,e+2);return t.slice(0,un(_t(t,0)))}function yE(i,e){let t=i.sliceString(e-2,e);return un(_t(t,0))==t.length?t:t.slice(1)}function wE(i,e,t,n){let a=null,s=i.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:t,from:r.to}],effects:Un.of(r.to+e.length),range:B.range(r.anchor+e.length,r.head+e.length)};let o=er(i.doc,r.head);return!o||/\s/.test(o)||n.indexOf(o)>-1?{changes:{insert:e+t,from:r.head},effects:Un.of(r.head+e.length),range:B.cursor(r.head+e.length)}:{range:a=r}});return a?null:i.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function zE(i,e,t){let n=null,a=i.changeByRange(s=>s.empty&&er(i.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:B.cursor(s.head+t.length)}:n={range:s});return n?null:i.update(a,{scrollIntoView:!0,userEvent:"input.type"})}function IE(i,e,t,n){let a=n.stringPrefixes||Di.stringPrefixes,s=null,r=i.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:e,from:o.to}],effects:Un.of(o.to+e.length),range:B.range(o.anchor+e.length,o.head+e.length)};let l=o.head,u=er(i.doc,l),m;if(u==e){if(Ic(i,l))return{changes:{insert:e+e,from:l},effects:Un.of(l+e.length),range:B.cursor(l+e.length)};if($p(i,l)){let d=t&&i.sliceDoc(l,l+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+d.length,insert:d},range:B.cursor(l+d.length)}}}else{if(t&&i.sliceDoc(l-2*e.length,l)==e+e&&(m=kc(i,l-2*e.length,a))>-1&&Ic(i,m))return{changes:{insert:e+e+e+e,from:l},effects:Un.of(l+e.length),range:B.cursor(l+e.length)};if(i.charCategorizer(l)(u)!=Pt.Word&&kc(i,l,a)>-1&&!kE(i,l,e,a))return{changes:{insert:e+e,from:l},effects:Un.of(l+e.length),range:B.cursor(l+e.length)}}return{range:s=o}});return s?null:i.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Ic(i,e){let t=et(i).resolveInner(e+1);return t.parent&&t.from==e}function kE(i,e,t,n){let a=et(i).resolveInner(e,-1),s=n.reduce((r,o)=>Math.max(r,o.length),0);for(let r=0;r<5;r++){let o=i.sliceDoc(a.from,Math.min(a.to,a.from+t.length+s)),l=o.indexOf(t);if(!l||l>-1&&n.indexOf(o.slice(0,l))>-1){let m=a.firstChild;for(;m&&m.from==a.from&&m.to-m.from>t.length+l;){if(i.sliceDoc(m.to-t.length,m.to)==t)return!1;m=m.firstChild}return!0}let u=a.to==e&&a.parent;if(!u)break;a=u}return!1}function kc(i,e,t){let n=i.charCategorizer(e);if(n(i.sliceDoc(e-1,e))!=Pt.Word)return e;for(let a of t){let s=e-a.length;if(i.sliceDoc(s,e)==a&&n(i.sliceDoc(s-1,s))!=Pt.Word)return s}return-1}function SE(i={}){return[nE,mt,We.of(i),eE,_E,Hp]}const Yp=[{key:"Ctrl-Space",run:Gr},{mac:"Alt-`",run:Gr},{mac:"Alt-i",run:Gr},{key:"Escape",run:$W},{key:"ArrowDown",run:_a(!0)},{key:"ArrowUp",run:_a(!1)},{key:"PageDown",run:_a(!0,"page")},{key:"PageUp",run:_a(!1,"page")},{key:"Enter",run:UW}],_E=r1.highest(Oi.computeN([We],i=>i.facet(We).defaultKeymap?[Yp]:[])),TE=i=>{let{state:e}=i,t=e.doc.lineAt(e.selection.main.from),n=W0(i.state,t.from);return n.line?OE(i):n.block?PE(i):!1};function L0(i,e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let a=i(e,t);return a?(n(t.update(a)),!0):!1}}const OE=L0(BE,0),AE=L0(Xp,0),PE=L0((i,e)=>Xp(i,e,CE(e)),0);function W0(i,e){let t=i.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Q1=50;function jE(i,{open:e,close:t},n,a){let s=i.sliceDoc(n-Q1,n),r=i.sliceDoc(a,a+Q1),o=/\s*$/.exec(s)[0].length,l=/^\s*/.exec(r)[0].length,u=s.length-o;if(s.slice(u-e.length,u)==e&&r.slice(l,l+t.length)==t)return{open:{pos:n-o,margin:o&&1},close:{pos:a+l,margin:l&&1}};let m,c;a-n<=2*Q1?m=c=i.sliceDoc(n,a):(m=i.sliceDoc(n,n+Q1),c=i.sliceDoc(a-Q1,a));let d=/^\s*/.exec(m)[0].length,h=/\s*$/.exec(c)[0].length,g=c.length-h-t.length;return m.slice(d,d+e.length)==e&&c.slice(g,g+t.length)==t?{open:{pos:n+d+e.length,margin:/\s/.test(m.charAt(d+e.length))?1:0},close:{pos:a-h-t.length,margin:/\s/.test(c.charAt(g-1))?1:0}}:null}function CE(i){let e=[];for(let t of i.selection.ranges){let n=i.doc.lineAt(t.from),a=t.to<=n.to?n:i.doc.lineAt(t.to);a.from>n.from&&a.from==t.to&&(a=t.to==n.to+1?n:i.doc.lineAt(t.to-1));let s=e.length-1;s>=0&&e[s].to>n.from?e[s].to=a.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:a.to})}return e}function Xp(i,e,t=e.selection.ranges){let n=t.map(s=>W0(e,s.from).block);if(!n.every(s=>s))return null;let a=t.map((s,r)=>jE(e,n[r],s.from,s.to));if(i!=2&&!a.every(s=>s))return{changes:e.changes(t.map((s,r)=>a[r]?[]:[{from:s.from,insert:n[r].open+" "},{from:s.to,insert:" "+n[r].close}]))};if(i!=1&&a.some(s=>s)){let s=[];for(let r=0,o;ra&&(s==r||r>c.from)){a=c.from;let d=/^\s*/.exec(c.text)[0].length,h=d==c.length,g=c.text.slice(d,d+u.length)==u?d:-1;ds.comment<0&&(!s.empty||s.single))){let s=[];for(let{line:o,token:l,indent:u,empty:m,single:c}of n)(c||!m)&&s.push({from:o.from+u,insert:l+" "});let r=e.changes(s);return{changes:r,selection:e.selection.map(r,1)}}else if(i!=1&&n.some(s=>s.comment>=0)){let s=[];for(let{line:r,comment:o,token:l}of n)if(o>=0){let u=r.from+o,m=u+l.length;r.text[m-r.from]==" "&&m++,s.push({from:u,to:m})}return{changes:s}}return null}function L1(i,e){return B.create(i.ranges.map(e),i.mainIndex)}function Vt(i,e){return i.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Qt({state:i,dispatch:e},t){let n=L1(i.selection,t);return n.eq(i.selection,!0)?!1:(e(Vt(i,n)),!0)}function tr(i,e){return B.cursor(e?i.to:i.from)}function Kp(i,e){return Qt(i,t=>t.empty?i.moveByChar(t,e):tr(t,e))}function tt(i){return i.textDirectionAt(i.state.selection.main.head)==de.LTR}const ef=i=>Kp(i,!tt(i)),tf=i=>Kp(i,tt(i));function nf(i,e){return Qt(i,t=>t.empty?i.moveByGroup(t,e):tr(t,e))}const DE=i=>nf(i,!tt(i)),ZE=i=>nf(i,tt(i));function ME(i,e,t){if(e.type.prop(t))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(i.sliceDoc(e.from,e.to)))||e.firstChild}function nr(i,e,t){let n=et(i).resolveInner(e.head),a=t?K.closedBy:K.openedBy;for(let l=e.head;;){let u=t?n.childAfter(l):n.childBefore(l);if(!u)break;ME(i,u,a)?n=u:l=t?u.to:u.from}let s=n.type.prop(a),r,o;return s&&(r=t?sn(i,n.from,1):sn(i,n.to,-1))&&r.matched?o=t?r.end.to:r.end.from:o=t?n.to:n.from,B.cursor(o,t?-1:1)}const LE=i=>Qt(i,e=>nr(i.state,e,!tt(i))),WE=i=>Qt(i,e=>nr(i.state,e,tt(i)));function af(i,e){return Qt(i,t=>{if(!t.empty)return tr(t,e);let n=i.moveVertically(t,e);return n.head!=t.head?n:i.moveToLineBoundary(t,e)})}const sf=i=>af(i,!1),rf=i=>af(i,!0);function of(i){let e=i.scrollDOM.clientHeightr.empty?i.moveVertically(r,e,t.height):tr(r,e));if(a.eq(n.selection))return!1;let s;if(t.selfScroll){let r=i.coordsAtPos(n.selection.main.head),o=i.scrollDOM.getBoundingClientRect(),l=o.top+t.marginTop,u=o.bottom-t.marginBottom;r&&r.top>l&&r.bottomlf(i,!1),yl=i=>lf(i,!0);function Wn(i,e,t){let n=i.lineBlockAt(e.head),a=i.moveToLineBoundary(e,t);if(a.head==e.head&&a.head!=(t?n.to:n.from)&&(a=i.moveToLineBoundary(e,t,!1)),!t&&a.head==n.from&&n.length){let s=/^\s*/.exec(i.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;s&&e.head!=n.from+s&&(a=B.cursor(n.from+s))}return a}const EE=i=>Qt(i,e=>Wn(i,e,!0)),NE=i=>Qt(i,e=>Wn(i,e,!1)),FE=i=>Qt(i,e=>Wn(i,e,!tt(i))),JE=i=>Qt(i,e=>Wn(i,e,tt(i))),RE=i=>Qt(i,e=>i.moveToLineBoundary(e,!1,!1)),GE=i=>Qt(i,e=>i.moveToLineBoundary(e,!0,!1));function HE(i,e,t){let n=!1,a=L1(i.selection,s=>{let r=sn(i,s.head,-1)||sn(i,s.head,1)||s.head>0&&sn(i,s.head-1,1)||s.headHE(i,e);function Mt(i,e,t){let n=L1(i.state.selection,a=>{a.undirectional&&a.head>=a.anchor!=e&&(a=B.range(a.head,a.anchor));let s=t(a);return B.range(a.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return n.eq(i.state.selection)?!1:(i.dispatch(Vt(i.state,n)),!0)}function uf(i,e){return Mt(i,e,t=>i.moveByChar(t,e))}const mf=i=>uf(i,!tt(i)),cf=i=>uf(i,tt(i));function df(i,e){return Mt(i,e,t=>i.moveByGroup(t,e))}const QE=i=>df(i,!tt(i)),qE=i=>df(i,tt(i)),UE=i=>{let e=!tt(i);return Mt(i,e,t=>nr(i.state,t,e))},$E=i=>{let e=tt(i);return Mt(i,e,t=>nr(i.state,t,e))};function hf(i,e){return Mt(i,e,t=>i.moveVertically(t,e))}const gf=i=>hf(i,!1),pf=i=>hf(i,!0);function ff(i,e){return Mt(i,e,t=>i.moveVertically(t,e,of(i).height))}const _c=i=>ff(i,!1),Tc=i=>ff(i,!0),YE=i=>Mt(i,!0,e=>Wn(i,e,!0)),XE=i=>Mt(i,!1,e=>Wn(i,e,!1)),KE=i=>{let e=!tt(i);return Mt(i,e,t=>Wn(i,t,e))},eN=i=>{let e=tt(i);return Mt(i,e,t=>Wn(i,t,e))},tN=i=>Mt(i,!1,e=>B.cursor(i.lineBlockAt(e.head).from)),nN=i=>Mt(i,!0,e=>B.cursor(i.lineBlockAt(e.head).to)),Oc=({state:i,dispatch:e})=>(e(Vt(i,{anchor:0})),!0),Ac=({state:i,dispatch:e})=>(e(Vt(i,{anchor:i.doc.length})),!0),Pc=({state:i,dispatch:e})=>(e(Vt(i,{anchor:i.selection.main.anchor,head:0})),!0),jc=({state:i,dispatch:e})=>(e(Vt(i,{anchor:i.selection.main.anchor,head:i.doc.length})),!0),iN=({state:i,dispatch:e})=>(e(i.update({selection:{anchor:0,head:i.doc.length},userEvent:"select"})),!0),aN=({state:i,dispatch:e})=>{let t=ir(i).map(({from:n,to:a})=>B.undirectionalRange(n,Math.min(a+1,i.doc.length)));return e(i.update({selection:B.create(t),userEvent:"select"})),!0},sN=({state:i,dispatch:e})=>{let t=L1(i.selection,n=>{let a=et(i),s=a.resolveStack(n.from,1);if(n.empty){let r=a.resolveStack(n.from,-1);r.node.from>=s.node.from&&r.node.to<=s.node.to&&(s=r)}for(let r=s;r;r=r.next){let{node:o}=r;if((o.from=n.to||o.to>n.to&&o.from<=n.from)&&r.next)return B.undirectionalRange(o.from,o.to)}return n});return t.eq(i.selection)?!1:(e(Vt(i,t)),!0)};function xf(i,e){let{state:t}=i,n=t.selection,a=t.selection.ranges.slice();for(let s of t.selection.ranges){let r=t.doc.lineAt(s.head);if(e?r.to0)for(let o=s;;){let l=i.moveVertically(o,e);if(l.headr.to){a.some(u=>u.head==l.head)||a.push(l);break}else{if(l.head==o.head)break;o=l}}}return a.length==n.ranges.length?!1:(i.dispatch(Vt(t,B.create(a,a.length-1))),!0)}const rN=i=>xf(i,!1),oN=i=>xf(i,!0),lN=({state:i,dispatch:e})=>{let t=i.selection,n=null;return t.ranges.length>1?n=B.create([t.main]):t.main.empty||(n=B.create([B.cursor(t.main.head)])),n?(e(Vt(i,n)),!0):!1};function Hi(i,e){if(i.state.readOnly)return!1;let t="delete.selection",{state:n}=i,a=n.changeByRange(s=>{let{from:r,to:o}=s;if(r==o){let l=e(s);l