arize-phoenix 8.8.0__py3-none-any.whl → 8.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of arize-phoenix might be problematic. Click here for more details.
- {arize_phoenix-8.8.0.dist-info → arize_phoenix-8.10.0.dist-info}/METADATA +4 -4
- {arize_phoenix-8.8.0.dist-info → arize_phoenix-8.10.0.dist-info}/RECORD +30 -29
- phoenix/config.py +11 -0
- phoenix/experiments/types.py +2 -0
- phoenix/server/api/helpers/playground_clients.py +30 -2
- phoenix/server/api/helpers/prompts/models.py +23 -2
- phoenix/server/api/input_types/InvocationParameters.py +1 -0
- phoenix/server/api/mutations/__init__.py +3 -1
- phoenix/server/api/mutations/prompt_label_mutations.py +6 -5
- phoenix/server/api/mutations/prompt_mutations.py +6 -5
- phoenix/server/api/mutations/prompt_version_tag_mutations.py +3 -2
- phoenix/server/api/mutations/trace_mutations.py +74 -0
- phoenix/server/api/queries.py +14 -1
- phoenix/server/api/routers/v1/experiments.py +103 -2
- phoenix/server/api/routers/v1/prompts.py +14 -2
- phoenix/server/app.py +1 -1
- phoenix/server/static/.vite/manifest.json +44 -44
- phoenix/server/static/assets/{components-Cvwn-4Sk.js → components-CVzKofML.js} +245 -238
- phoenix/server/static/assets/{index-Cxmc6_pQ.js → index-Ctff7oin.js} +1 -1
- phoenix/server/static/assets/{pages-DLMdDkgQ.js → pages-CVFLHgre.js} +349 -340
- phoenix/server/static/assets/{vendor-yn6w6Ozi.js → vendor-VJCVsFqd.js} +161 -161
- phoenix/server/static/assets/{vendor-arizeai-DoGO67dU.js → vendor-arizeai-BiZagY4a.js} +22 -22
- phoenix/server/static/assets/{vendor-codemirror-BLdSYxpm.js → vendor-codemirror-0mUqu36F.js} +11 -11
- phoenix/server/static/assets/{vendor-recharts-CjOpOw1c.js → vendor-recharts-CfKQSOmq.js} +1 -1
- phoenix/server/static/assets/{vendor-shiki-BwTCxCQY.js → vendor-shiki-BsgMOuir.js} +1 -1
- phoenix/version.py +1 -1
- {arize_phoenix-8.8.0.dist-info → arize_phoenix-8.10.0.dist-info}/WHEEL +0 -0
- {arize_phoenix-8.8.0.dist-info → arize_phoenix-8.10.0.dist-info}/entry_points.txt +0 -0
- {arize_phoenix-8.8.0.dist-info → arize_phoenix-8.10.0.dist-info}/licenses/IP_NOTICE +0 -0
- {arize_phoenix-8.8.0.dist-info → arize_phoenix-8.10.0.dist-info}/licenses/LICENSE +0 -0
phoenix/server/static/assets/{vendor-codemirror-BLdSYxpm.js → vendor-codemirror-0mUqu36F.js}
RENAMED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{cA as ht,cB as yf,cC as bf,cD as xf,cE as Me,cF as Et,cG as
|
|
1
|
+
import{cA as ht,cB as yf,cC as bf,cD as xf,cE as Me,cF as Et,cG as kr,cH as cn,cI as vf,cJ as Cr,cK as wf,cL as Sf,z as m,y as kf,cM as Cf,cN as V,cO as qn,r as Se,cP as Af,cQ as Mf,cR as Tf,cS as Of,cT as Ql,cU as Df,cV as Ef,cW as Zl,cX as Pf,cY as ea,cZ as Bf}from"./vendor-VJCVsFqd.js";import{m as Rf}from"./vendor-shiki-BsgMOuir.js";class B{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=$t(this,e,t);let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),$e.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=$t(this,e,t);let i=[];return this.decompose(e,t,i,0),$e.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new ui(this),r=new ui(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new ui(this,e)}iterRange(e,t=this.length){return new ta(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new ia(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?B.empty:e.length<=32?new J(e):$e.from(J.split(e,[]))}}class J extends B{constructor(e,t=Lf(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new If(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new J(oo(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=fn(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new J(l,o.length+r.length));else{let a=l.length>>1;i.push(new J(l.slice(0,a)),new J(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof J))return super.replace(e,t,i);[e,t]=$t(this,e,t);let s=fn(this.text,fn(i.text,oo(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new J(s,r):$e.from(J.split(s,[]),r)}sliceString(e,t=this.length,i=`
|
|
2
2
|
`){[e,t]=$t(this,e,t);let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new J(i,s)),i=[],s=-1);return s>-1&&t.push(new J(i,s)),t}}class $e extends B{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let c=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!c?i.push(l):l.decompose(e-o,t-o,i,c)}o=a+1}}replace(e,t,i){if([e,t]=$t(this,e,t),i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),c=this.lines-o.lines+a.lines;if(a.lines<c>>4&&a.lines>c>>6){let h=this.children.slice();return h[s]=a,new $e(h,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
|
|
3
|
-
`){[e,t]=$t(this,e,t);let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof $e))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],c=e.children[r];if(a!=c)return i+a.scanIdentical(c,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new J(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,c=-1,h=[];function f(d){let p;if(d.lines>r&&d instanceof $e)for(let g of d.children)f(g);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof J&&a&&(p=h[h.length-1])instanceof J&&d.lines+p.lines<=32?(a+=d.lines,c+=d.length+1,h[h.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&u(),a+=d.lines,c+=d.length+1,h.push(d))}function u(){a!=0&&(l.push(h.length==1?h[0]:$e.from(h,c)),c=-1,a=h.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new $e(l,t)}}B.empty=new J([""],0);function
|
|
4
|
-
`,this;e--}else if(s instanceof J){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof J?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class ta{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ui(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class ia{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(B.prototype[Symbol.iterator]=function(){return this.iter()},ui.prototype[Symbol.iterator]=ta.prototype[Symbol.iterator]=ia.prototype[Symbol.iterator]=function(){return this});class Nf{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}}function $t(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}let Lt="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(n=>n?parseInt(n,36):1);for(let n=1;n<Lt.length;n++)Lt[n]+=Lt[n-1];function Ff(n){for(let e=1;e<Lt.length;e+=2)if(Lt[e]>n)return Lt[e-1]<=n;return!1}function lo(n){return n>=127462&&n<=127487}const ao=8205;function re(n,e,t=!0,i=!0){return(t?na:Vf)(n,e,i)}function na(n,e,t){if(e==n.length)return e;e&&sa(n.charCodeAt(e))&&ra(n.charCodeAt(e-1))&&e--;let i=ne(n,e);for(e+=ke(i);e<n.length;){let s=ne(n,e);if(i==ao||s==ao||t&&Ff(s))e+=ke(s),i=s;else if(lo(s)){let r=0,o=e-2;for(;o>=0&&lo(ne(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Vf(n,e,t){for(;e>0;){let i=na(n,e-2,t);if(i<e)return i;e--}return 0}function sa(n){return n>=56320&&n<57344}function ra(n){return n>=55296&&n<56320}function ne(n,e){let t=n.charCodeAt(e);if(!ra(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return sa(i)?(t-55296<<10)+(i-56320)+65536:t}function Ar(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function ke(n){return n<65536?1:2}const Es=/\r\n?|\n/;var te=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(te||(te={}));class _e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){Ps(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new _e(e)}composeDesc(e){return this.empty?e:e.empty?this:oa(this,e)}mapDesc(e,t=!1){return e.empty?this:Bs(this,e,t)}mapPos(e,t=-1,i=te.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],c=s+l;if(a<0){if(c>e)return r+(e-s);r+=l}else{if(i!=te.Simple&&c>=e&&(i==te.TrackDel&&s<e&&c>e||i==te.TrackBefore&&s<e||i==te.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=c}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new _e(e)}static create(e){return new _e(e)}}class ee extends _e{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Ps(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return Bs(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(B.empty);i.push(o?e.slice(r,r+o):B.empty)}r+=o}return new ee(t,i)}compose(e){return this.empty?e:e.empty?this:oa(this,e,!0)}map(e,t=!1){return e.empty?this:Bs(this,e,t,!0)}iterChanges(e,t=!1){Ps(this,e,t)}get desc(){return _e.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new bi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let h=Math.min(r.len,a-l);oe(s,h,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;oe(t,h,f),f>0&&st(i,t,r.text),r.forward(h),l+=h}let c=e[o++];for(;l<c;){if(r.done)break e;let h=Math.min(r.len,c-l);oe(t,h,-1),oe(s,h,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(h),l+=h}}return{changes:new ee(t,i),filtered:_e.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(h=!1){if(!h&&!s.length)return;o<t&&oe(s,t-o,-1);let f=new ee(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function c(h){if(Array.isArray(h))for(let f of h)c(f);else if(h instanceof ee){if(h.length!=t)throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${t})`);a(),l=l?l.compose(h.map(l)):h}else{let{from:f,to:u=f,insert:d}=h;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?B.of(d.split(i||Es)):d:B.empty,g=p.length;if(f==u&&g==0)return;f<o&&a(),f>o&&oe(s,f-o,-1),oe(s,u-f,g),st(r,s,p),o=u}}return c(e),a(!l),l}static empty(e){return new ee(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(B.empty);i[s]=B.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new ee(t,i)}static createSet(e,t){return new ee(e,t)}}function oe(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function st(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(B.empty);n.push(t)}}function Ps(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let c=s,h=r,f=B.empty;for(;c+=l,h+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,c,r,h,f),s=c,r=h}}}function Bs(n,e,t,i=!1){let s=[],r=i?[]:null,o=new bi(n),l=new bi(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let c=Math.min(o.len,l.len);oe(s,c,-1),o.forward(c),l.forward(c)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let c=l.len;for(oe(s,l.ins,-1);c;){let h=Math.min(o.len,c);o.ins>=0&&a<o.i&&o.len<=h&&(oe(s,0,o.ins),r&&st(r,s,o.text),a=o.i),o.forward(h),c-=h}l.next()}else if(o.ins>=0){let c=0,h=o.len;for(;h;)if(l.ins==-1){let f=Math.min(h,l.len);c+=f,h-=f,l.forward(f)}else if(l.ins==0&&l.len<h)h-=l.len,l.next();else break;oe(s,c,a<o.i?o.ins:0),r&&a<o.i&&st(r,s,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return r?ee.createSet(s,r):_e.create(s);throw new Error("Mismatched change set lengths")}}function oa(n,e,t=!1){let i=[],s=t?[]:null,r=new bi(n),o=new bi(e);for(let l=!1;;){if(r.done&&o.done)return s?ee.createSet(i,s):_e.create(i);if(r.ins==0)oe(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)oe(i,0,o.ins,l),s&&st(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),c=i.length;if(r.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;oe(i,a,h,l),s&&h&&st(s,i,o.text)}else o.ins==-1?(oe(i,r.off?0:r.len,a,l),s&&st(s,i,r.textBit(a))):(oe(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&st(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>c),r.forward2(a),o.forward(a)}}}}class bi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?B.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?B.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class bt{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new bt(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return x.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return x.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return x.range(e.anchor,e.head)}static create(e,t,i){return new bt(e,t,i)}}class x{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:x.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new x([this.main],0)}addRange(e,t=!0){return x.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,x.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new x(e.ranges.map(t=>bt.fromJSON(t)),e.main)}static single(e,t=e){return new x([x.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return x.normalized(e.slice(),t);i=r.to}return new x(e,t)}static cursor(e,t=0,i,s){return bt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(e,t,i,s){let r=(i??16777215)<<6|(s==null?7:Math.min(6,s));return t<e?bt.create(t,e,48|r):bt.create(e,t,(t>e?8:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?x.range(a,l):x.range(l,a))}}return new x(e,t)}}function la(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Mr=0;class A{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=Mr++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new A(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Tr),!!e.static,e.enables)}of(e){return new un([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new un(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new un(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Tr(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class un{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Mr++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,c=!1,h=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?c=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||h.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||c&&(u.docChanged||u.selection)||Rs(f,h)){let d=i(f);if(l?!ho(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[r];if(p!=null){let g=Cn(u,p);if(this.dependencies.every(y=>y instanceof A?u.facet(y)===f.facet(y):y instanceof Q?u.field(y,!1)==f.field(y,!1):!0)||(l?ho(d=i(f),g,s):s(d=i(f),g)))return f.values[o]=g,0}else d=i(f);return f.values[o]=d,1}}}}function ho(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function Rs(n,e){let t=!1;for(let i of e)di(n,i)&1&&(t=!0);return t}function Hf(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let c=[];for(let h=0;h<i.length;h++){let f=Cn(a,i[h]);if(s[h]==2)for(let u of f)c.push(u);else c.push(f)}return e.combine(c)}return{create(a){for(let c of i)di(a,c);return a.values[o]=l(a),1},update(a,c){if(!Rs(a,r))return 0;let h=l(a);return e.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,c){let h=Rs(a,i),f=c.config.facets[e.id],u=c.facet(e);if(f&&!h&&Tr(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const co=A.define({static:!0});class Q{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new Q(Mr++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(co).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}init(e){return[this,co.of({field:this,create:e})]}get extension(){return this}}const gt={lowest:4,low:3,default:2,high:1,highest:0};function ti(n){return e=>new aa(e,n)}const pt={highest:ti(gt.highest),high:ti(gt.high),default:ti(gt.default),low:ti(gt.low),lowest:ti(gt.lowest)};class aa{constructor(e,t){this.inner=e,this.prec=t}}class qn{of(e){return new Ls(this,e)}reconfigure(e){return qn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Ls{constructor(e,t){this.compartment=e,this.inner=t}}class kn{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let u of Wf(e,t,o))u instanceof Q?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],c=[];for(let u of s)l[u.id]=c.length<<1,c.push(d=>u.slot(d));let h=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=h&&h[u]||[];if(d.every(y=>y.type==0))if(l[p.id]=a.length<<1|1,Tr(g,d))a.push(i.facet(p));else{let y=p.combine(d.map(b=>b.value));a.push(i&&p.compare(y,i.facet(p))?i.facet(p):y)}else{for(let y of d)y.type==0?(l[y.id]=a.length<<1|1,a.push(y.value)):(l[y.id]=c.length<<1,c.push(b=>y.dynamicSlot(b)));l[p.id]=c.length<<1,c.push(y=>Hf(y,p,d))}}let f=c.map(u=>u(l));return new kn(e,o,f,l,a,r)}}function Wf(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let c=i[a].indexOf(o);c>-1&&i[a].splice(c,1),o instanceof Ls&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let c of o)r(c,l);else if(o instanceof Ls){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let c=e.get(o.compartment)||o.inner;t.set(o.compartment,c),r(c,l)}else if(o instanceof aa)r(o.inner,o.prec);else if(o instanceof Q)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof un)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,gt.default);else{let c=o.extension;if(!c)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(c,l)}}return r(n,gt.default),i.reduce((o,l)=>o.concat(l))}function di(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function Cn(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const ha=A.define(),Is=A.define({combine:n=>n.some(e=>e),static:!0}),ca=A.define({combine:n=>n.length?n[0]:void 0,static:!0}),fa=A.define(),ua=A.define(),da=A.define(),pa=A.define({combine:n=>n.length?n[0]:!1});class Ne{constructor(e,t){this.type=e,this.value=t}static define(){return new $f}}class $f{of(e){return new Ne(this,e)}}class zf{constructor(e){this.map=e}of(e){return new D(this,e)}}class D{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new D(this.type,t)}is(e){return this.type==e}static define(e={}){return new zf(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}}D.reconfigure=D.define();D.appendConfig=D.define();class Y{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&la(i,t.newLength),r.some(l=>l.type==Y.time)||(this.annotations=r.concat(Y.time.of(Date.now())))}static create(e,t,i,s,r,o){return new Y(e,t,i,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Y.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Y.time=Ne.define();Y.userEvent=Ne.define();Y.addToHistory=Ne.define();Y.remote=Ne.define();function jf(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function ma(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=ee.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:D.mapEffects(n.effects,s).concat(D.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Ns(n,e,t){let i=e.selection,s=It(e.annotations);return e.userEvent&&(s=s.concat(Y.userEvent.of(e.userEvent))),{changes:e.changes instanceof ee?e.changes:ee.of(e.changes||[],t,n.facet(ca)),selection:i&&(i instanceof x?i:x.single(i.anchor,i.head)),effects:It(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function ga(n,e,t){let i=Ns(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=ma(i,Ns(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=Y.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Kf(t?qf(s):s)}function qf(n){let e=n.startState,t=!0;for(let s of e.facet(fa)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:jf(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=ee.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=Y.create(e,s,n.selection&&n.selection.map(r),D.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(ua);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof Y?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Y?n=r[0]:n=ga(e,It(r),!1)}return n}function Kf(n){let e=n.startState,t=e.facet(da),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=ma(i,Ns(e,r,n.changes.newLength),!0))}return i==n?n:Y.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const _f=[];function It(n){return n==null?_f:Array.isArray(n)?n:[n]}var z=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(z||(z={}));const Jf=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Fs;try{Fs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Uf(n){if(Fs)return Fs.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||Jf.test(t)))return!0}return!1}function Yf(n){return e=>{if(!/\S/.test(e))return z.Space;if(Uf(e))return z.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return z.Word;return z.Other}}class P{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)di(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return di(this,i),Cn(this,i)}update(...e){return ga(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let l of e.effects)l.is(qn.reconfigure)?(t&&(s=new Map,t.compartments.forEach((a,c)=>s.set(c,a)),t=null),s.set(l.value.compartment,l.value.extension)):l.is(D.reconfigure)?(t=null,i=l.value):l.is(D.appendConfig)&&(t=null,i=It(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=kn.resolve(i,s,this),r=new P(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,c)=>c.reconfigure(a,this),null).values);let o=e.startState.facet(Is)?e.newSelection:e.newSelection.asSingle();new P(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:x.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=It(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),c=this.changes(a.changes),h=c.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(h);let f=s.mapDesc(c,!0);r.push(a.range.map(f)),s=s.compose(h),o=D.mapEffects(o,h).concat(D.mapEffects(It(a.effects),f))}return{changes:s,selection:x.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof ee?e:ee.of(e,this.doc.length,this.facet(P.lineSeparator))}toText(e){return B.of(e.split(this.facet(P.lineSeparator)||Es))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(di(this,t),Cn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof Q&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return P.create({doc:e.doc,selection:x.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=kn.resolve(e.extensions||[],new Map),i=e.doc instanceof B?e.doc:B.of((e.doc||"").split(t.staticFacet(P.lineSeparator)||Es)),s=e.selection?e.selection instanceof x?e.selection:x.single(e.selection.anchor,e.selection.head):x.single(0);return la(s,i.length),t.staticFacet(Is)||(s=s.asSingle()),new P(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(P.tabSize)}get lineBreak(){return this.facet(P.lineSeparator)||`
|
|
5
|
-
`}get readOnly(){return this.facet(pa)}phrase(e,...t){for(let i of this.facet(P.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let s=[];for(let r of this.facet(ha))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){return Yf(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=re(t,o,!1);if(r(t.slice(a,o))!=z.Word)break;o=a}for(;l<s;){let a=re(t,l);if(r(t.slice(l,a))!=z.Word)break;l=a}return o==l?null:x.range(o+i,l+i)}}P.allowMultipleSelections=Is;P.tabSize=A.define({combine:n=>n.length?n[0]:4});P.lineSeparator=ca;P.readOnly=pa;P.phrases=A.define({compare(n,e){let t=Object.keys(n),i=Object.keys(e);return t.length==i.length&&t.every(s=>n[s]==e[s])}});P.languageData=ha;P.changeFilter=fa;P.transactionFilter=ua;P.transactionExtender=da;qn.reconfigure=D.define();function Je(n,e,t={}){let i={};for(let s of n)for(let r of Object.keys(s)){let o=s[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)i[s]===void 0&&(i[s]=e[s]);return i}class ct{eq(e){return this==e}range(e,t=e){return xi.create(e,t,this)}}ct.prototype.startSide=ct.prototype.endSide=0;ct.prototype.point=!1;ct.prototype.mapMode=te.TrackDel;class xi{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new xi(e,t,i)}}function Vs(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class Or{constructor(e,t,i,s){this.from=e,this.to=t,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,c=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return c>=0?o:l;c>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let c=this.value[a],h=this.from[a]+e,f=this.to[a]+e,u,d;if(h==f){let p=t.mapPos(h,c.startSide,c.mapMode);if(p==null||(u=d=p,c.startSide!=c.endSide&&(d=t.mapPos(h,c.endSide),d<u)))continue}else if(u=t.mapPos(h,c.startSide),d=t.mapPos(f,c.endSide),u>d||u==d&&c.startSide>0&&c.endSide<=0)continue;(d-u||c.endSide-c.startSide)<0||(o<0&&(o=u),c.point&&(l=Math.max(l,d-u)),i.push(c),s.push(u-o),r.push(d-o))}return{mapped:i.length?new Or(s,r,i,l):null,pos:o}}}class R{constructor(e,t,i,s){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=s}static create(e,t,i,s){return new R(e,t,i,s)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(Vs)),this.isEmpty)return t.length?R.of(t):this;let l=new ya(this,null,-1).goto(0),a=0,c=[],h=new ft;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];h.addInner(f.from,f.to,f.value)||c.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&h.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(h.addInner(l.from,l.to,l.value)||c.push(xi.create(l.from,l.to,l.value))),l.next());return h.finishInner(this.nextLayer.isEmpty&&!c.length?R.empty:this.nextLayer.update({add:c,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],c=e.touchesRange(l,l+a.length);if(c===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(c===!0){let{mapped:h,pos:f}=a.map(l,e);h&&(s=Math.max(s,h.maxPoint),t.push(h),i.push(f))}}let r=this.nextLayer.map(e);return t.length==0?r:new R(i,t,r||R.empty,s)}between(e,t,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return vi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return vi.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=fo(o,l,i),c=new ii(o,a,r),h=new ii(l,a,r);i.iterGaps((f,u,d)=>uo(c,f,h,u,d,s)),i.empty&&i.length==0&&uo(c,0,h,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=999999999);let r=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0),o=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=fo(r,o),a=new ii(r,l,0).goto(i),c=new ii(o,l,0).goto(i);for(;;){if(a.to!=c.to||!Hs(a.active,c.active)||a.point&&(!c.point||!a.point.eq(c.point)))return!1;if(a.to>s)return!0;a.next(),c.next()}}static spans(e,t,i,s,r=-1){let o=new ii(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let c=Math.min(o.to,i);if(o.point){let h=o.activeForPoint(o.to),f=o.pointFrom<t?h.length+1:o.point.startSide<0?h.length:Math.min(h.length,a);s.point(l,c,o.point,h,f,o.pointRank),a=Math.min(o.openEnd(c),h.length)}else c>l&&(s.span(l,c,o.active,a),a=o.openEnd(c));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new ft;for(let s of e instanceof xi?[e]:t?Gf(e):e)i.add(s.from,s.to,s.value);return i.finish()}static join(e){if(!e.length)return R.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let s=e[i];s!=R.empty;s=s.nextLayer)t=new R(s.chunkPos,s.chunk,t,Math.max(s.maxPoint,t.maxPoint));return t}}R.empty=new R([],[],null,-1);function Gf(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(Vs(e,i)>0)return n.slice().sort(Vs);e=i}return n}R.empty.nextLayer=R.empty;class ft{finishChunk(e){this.chunks.push(new Or(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new ft)).add(e,t,i)}addInner(e,t,i){let s=e-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(R.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=R.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function fo(n,e,t){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}class ya{constructor(e,t,i,s=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class vi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new ya(o,t,i,r));return s.length==1?s[0]:new vi(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)rs(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)rs(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),rs(this.heap,0)}}}function rs(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let s=n[i];if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),t.compare(s)<0)break;n[i]=t,n[e]=s,e=i}}class ii{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=vi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ji(this.active,e),ji(this.activeTo,e),ji(this.activeRank,e),this.minActive=po(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||s-this.activeTo[t])>0;)t++;qi(this.active,t,i),qi(this.activeTo,t,s),qi(this.activeRank,t,r),e&&qi(e,t,this.cursor.from),this.minActive=po(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&ji(i,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function uo(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e;for(;;){let c=n.to+a-t.to||n.endSide-t.endSide,h=c<0?n.to+a:t.to,f=Math.min(h,o);if(n.point||t.point?n.point&&t.point&&(n.point==t.point||n.point.eq(t.point))&&Hs(n.activeForPoint(n.to),t.activeForPoint(t.to))||r.comparePoint(l,f,n.point,t.point):f>l&&!Hs(n.active,t.active)&&r.compareRange(l,f,n.active,t.active),h>o)break;l=h,c<=0&&n.next(),c>=0&&t.next()}}function Hs(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!n[t].eq(e[t]))return!1;return!0}function ji(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function qi(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function po(n,e){let t=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||n[s].endSide-n[t].endSide)<0&&(t=s,i=e[s]);return t}function Yt(n,e,t=n.length){let i=0;for(let s=0;s<t;)n.charCodeAt(s)==9?(i+=e-i%e,s++):(i++,s=re(n,s));return i}function Ws(n,e,t,i){for(let s=0,r=0;;){if(r>=e)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?t-r%t:1,s=re(n,s)}return i===!0?-1:n.length}function wi(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function $s(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function Xf(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function dn(n,e){if(!e.anchorNode)return!1;try{return $s(n,e.anchorNode)}catch{return!1}}function zt(n){return n.nodeType==3?St(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function pi(n,e,t,i){return t?mo(n,e,t,i,-1)||mo(n,e,t,i,1):!1}function wt(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function An(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function mo(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:Qe(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=wt(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=s<0?Qe(n):0}else return!1}}function Qe(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Kn(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Qf(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function ba(n,e){let t=e.width/n.offsetWidth,i=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-n.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Zf(n,e,t,i,s,r,o,l){let a=n.ownerDocument,c=a.defaultView||window;for(let h=n,f=!1;h&&!f;)if(h.nodeType==1){let u,d=h==a.body,p=1,g=1;if(d)u=Qf(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(f=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let v=h.getBoundingClientRect();({scaleX:p,scaleY:g}=ba(h,v)),u={left:v.left,right:v.left+h.clientWidth*p,top:v.top,bottom:v.top+h.clientHeight*g}}let y=0,b=0;if(s=="nearest")e.top<u.top?(b=-(u.top-e.top+o),t>0&&e.bottom>u.bottom+b&&(b=e.bottom-u.bottom+b+o)):e.bottom>u.bottom&&(b=e.bottom-u.bottom+o,t<0&&e.top-b<u.top&&(b=-(u.top+b-e.top+o)));else{let v=e.bottom-e.top,M=u.bottom-u.top;b=(s=="center"&&v<=M?e.top+v/2-M/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-M+o)-u.top}if(i=="nearest"?e.left<u.left?(y=-(u.left-e.left+r),t>0&&e.right>u.right+y&&(y=e.right-u.right+y+r)):e.right>u.right&&(y=e.right-u.right+r,t<0&&e.left<u.left+y&&(y=-(u.left+y-e.left+r))):y=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,y||b)if(d)c.scrollBy(y,b);else{let v=0,M=0;if(b){let S=h.scrollTop;h.scrollTop+=b/g,M=(h.scrollTop-S)*g}if(y){let S=h.scrollLeft;h.scrollLeft+=y/p,v=(h.scrollLeft-S)*p}e={left:e.left-v,top:e.top-M,right:e.right-v,bottom:e.bottom-M},v&&Math.abs(v-y)<1&&(i="nearest"),M&&Math.abs(M-b)<1&&(s="nearest")}if(d)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function eu(n){let e=n.ownerDocument,t,i;for(let s=n.parentNode;s&&!(s==e.body||t&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!t&&s.scrollWidth>s.clientWidth&&(t=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:t,y:i}}class tu{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Qe(t):0),i,Math.min(e.focusOffset,i?Qe(i):0))}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let Mt=null;function xa(n){if(n.setActive)return n.setActive();if(Mt)return n.focus(Mt);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Mt==null?{get preventScroll(){return Mt={preventScroll:!0},!0}}:void 0),!Mt){Mt=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let go;function St(n,e,t=e){let i=go||(go=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function Nt(n,e,t,i){let s={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function iu(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function va(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function nu(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Qe(t));;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=Qe(t))}else{if(t==n)return!0;i=wt(t),t=t.parentNode}}function wa(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Sa(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=Qe(t)}else if(t.parentNode&&!An(t))i=wt(t),t=t.parentNode;else return null}}function ka(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!An(t))i=wt(t)+1,t=t.parentNode;else return null}}class le{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new le(e.parentNode,wt(e),t)}static after(e,t){return new le(e.parentNode,wt(e)+1,t)}}const Dr=[];class F{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let i of this.children){if(i==e)return t;t+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}sync(e,t){if(this.flags&2){let i=this.dom,s=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=s?s.nextSibling:i.firstChild)){let l=F.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(e,t),o.flags&=-8}if(r=s?s.nextSibling:i.firstChild,t&&!t.written&&t.node==i&&r!=o.dom&&(t.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=yo(r);else i.insertBefore(o.dom,r);s=o.dom}for(r=s?s.nextSibling:i.firstChild,r&&t&&t.node==i&&(t.written=!0);r;)r=yo(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(e,t),i.flags&=-8)}reuseDOM(e){}localPosFromDOM(e,t){let i;if(e==this.dom)i=this.dom.childNodes[t];else{let s=Qe(e)==0?0:t==0?-1:1;for(;;){let r=e.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(e==r.firstChild?s=-1:s=1),e=r}s<0?i=e:i=e.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!F.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,i=0){let s=-1,r=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<this.children.length;a++){let f=this.children[a],u=c+f.length;if(c<e&&u>t)return f.domBoundsAround(e,t,c);if(u>=e&&s==-1&&(s=a,r=c),c>t&&f.dom.parentNode==this.dom){o=a,l=h;break}h=u,c=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=Dr){this.markDirty();for(let s=e;s<t;s++){let r=this.children[s];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(e,t-e,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new Ca(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(e,t,i,s,r,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor&&!((this.flags|e.flags)&8)}getSide(){return 0}destroy(){for(let e of this.children)e.parent==this&&e.destroy();this.parent=null}}F.prototype.breakAfter=0;function yo(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Ca{constructor(e,t,i){this.children=e,this.pos=t,this.i=i,this.off=0}findPos(e,t=1){for(;;){if(e>this.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Aa(n,e,t,i,s,r,o,l,a){let{children:c}=n,h=c.length?c[e]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(e==i&&h&&!o&&!u&&r.length<2&&h.merge(t,s,r.length?f:null,t==0,l,a))){if(i<c.length){let d=c[i];d&&(s<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(e==i&&(d=d.split(s),s=0),!u&&f&&d.merge(0,s,f,!0,0,a)?r[r.length-1]=d:((s||d.children.length&&!d.children[0].length)&&d.merge(0,s,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(h&&(h.breakAfter=o,t>0&&(!o&&r.length&&h.merge(t,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(t<h.length||h.children.length&&h.children[h.children.length-1].length==0)&&h.merge(t,h.length,null,!1,l,0),e++));e<i&&r.length;)if(c[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(c[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&i<c.length&&!c[e-1].breakAfter&&c[i].merge(0,0,c[e-1],!1,l,a)&&e--,(e<i||r.length)&&n.replaceChildren(e,i,r)}}function Ma(n,e,t,i,s,r){let o=n.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:c,off:h}=o.findPos(e,-1),f=e-t;for(let u of i)f+=u.length;n.length+=f,Aa(n,c,h,l,a,i,0,s,r)}let pe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},zs=typeof document<"u"?document:{documentElement:{style:{}}};const js=/Edge\/(\d+)/.exec(pe.userAgent),Ta=/MSIE \d/.test(pe.userAgent),qs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(pe.userAgent),_n=!!(Ta||qs||js),bo=!_n&&/gecko\/(\d+)/i.test(pe.userAgent),os=!_n&&/Chrome\/(\d+)/.exec(pe.userAgent),su="webkitFontSmoothing"in zs.documentElement.style,Oa=!_n&&/Apple Computer/.test(pe.vendor),xo=Oa&&(/Mobile\/\w+/.test(pe.userAgent)||pe.maxTouchPoints>2);var C={mac:xo||/Mac/.test(pe.platform),windows:/Win/.test(pe.platform),linux:/Linux|X11/.test(pe.platform),ie:_n,ie_version:Ta?zs.documentMode||6:qs?+qs[1]:js?+js[1]:0,gecko:bo,gecko_version:bo?+(/Firefox\/(\d+)/.exec(pe.userAgent)||[0,0])[1]:0,chrome:!!os,chrome_version:os?+os[1]:0,ios:xo,android:/Android\b/.test(pe.userAgent),safari:Oa,webkit_version:su?+(/\bAppleWebKit\/(\d+)/.exec(pe.userAgent)||[0,0])[1]:0,tabSize:zs.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const ru=256;class Le extends F{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return this.flags&8||i&&(!(i instanceof Le)||this.length-(t-e)+i.length>ru||i.flags&8)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new Le(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new le(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return ou(this.dom,e,t)}}class Ze extends F{constructor(e,t=[],i=0){super(),this.mark=e,this.children=t,this.length=i;for(let s of t)s.setParent(this)}setAttrs(e){if(va(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,i,s,r,o){return i&&(!(i instanceof Ze&&i.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(Ma(this,e,t,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],i=0,s=-1,r=0;for(let l of this.children){let a=i+l.length;a>e&&t.push(i<e?l.split(e-i):l),s<0&&i>=e&&(s=r),i=a,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new Ze(this.mark,t,o)}domAtPos(e){return Da(this,e)}coordsAt(e,t){return Pa(this,e,t)}}function ou(n,e,t){let i=n.nodeValue.length;e>i&&(e=i);let s=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?C.chrome||C.gecko||(e?(s--,o=1):r<i&&(r++,o=-1)):t<0?s--:r<i&&r++;let l=St(n,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return C.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,c=>c.width)||a),o?Kn(a,o<0):a||null}class rt extends F{static create(e,t,i){return new rt(e,t,i)}constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}split(e){let t=rt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(e,t,i,s,r,o){return i&&(!(i instanceof rt)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}become(e){return e instanceof rt&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.compare(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return B.empty;let e=this;for(;e.parent;)e=e.parent;let{view:t}=e,i=t&&t.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):B.empty}domAtPos(e){return(this.length?e==0:this.side>0)?le.before(this.dom):le.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let o=this.side?this.side<0:e>0;for(let l=o?s.length-1:0;r=s[l],!(e>0?l==0:l==s.length-1||r.top<r.bottom);l+=o?-1:1);return Kn(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class jt extends F{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof jt&&e.side==this.side}split(){return new jt(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return this.side>0?le.before(this.dom):le.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return B.empty}get isHidden(){return!0}}Le.prototype.children=rt.prototype.children=jt.prototype.children=Dr;function Da(n,e){let t=n.dom,{children:i}=n,s=0;for(let r=0;s<i.length;s++){let o=i[s],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(e>r&&e<l&&o.dom.parentNode==t)return o.domAtPos(e-r);if(e<=r)break;r=l}}for(let r=s;r>0;r--){let o=i[r-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let r=s;r<i.length;r++){let o=i[r];if(o.dom.parentNode==t)return o.domAtPos(0)}return new le(t,0)}function Ea(n,e,t){let i,{children:s}=n;t>0&&e instanceof Ze&&s.length&&(i=s[s.length-1])instanceof Ze&&i.mark.eq(e.mark)?Ea(i,e.children[0],t-1):(s.push(e),e.setParent(n)),n.length+=e.length}function Pa(n,e,t){let i=null,s=-1,r=null,o=-1;function l(c,h){for(let f=0,u=0;f<c.children.length&&u<=h;f++){let d=c.children[f],p=u+d.length;p>=h&&(d.children.length?l(d,h-u):(!r||r.isHidden&&t>0)&&(p>h||u==p&&d.getSide()>0)?(r=d,o=h-u):(u<h||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,s=h-u)),u=p}}l(n,e);let a=(t<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?s:o),t):lu(n)}function lu(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=zt(e);return t[t.length-1]||null}function Ks(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const vo=Object.create(null);function Mn(n,e,t){if(n==e)return!0;n||(n=vo),e||(e=vo);let i=Object.keys(n),s=Object.keys(e);if(i.length-(t&&i.indexOf(t)>-1?1:0)!=s.length-(t&&s.indexOf(t)>-1?1:0))return!1;for(let r of i)if(r!=t&&(s.indexOf(r)==-1||n[r]!==e[r]))return!1;return!0}function _s(n,e,t){let i=!1;if(e)for(let s in e)t&&s in t||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(i=!0,s=="style"?n.style.cssText=t[s]:n.setAttribute(s,t[s]));return i}function au(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class X extends F{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,s,r,o){if(i){if(!(i instanceof X))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ma(this,e,t,i?i.children.slice():[],r,o),!0}split(e){let t=new X;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:s}=this.childPos(e);s&&(t.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)t.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Mn(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Ea(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=Ks(t,this.attrs||{})),i&&(this.attrs=Ks({class:i},this.attrs||{}))}domAtPos(e){return Da(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var i;this.dom?this.flags&4&&(va(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(_s(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let s=this.dom.lastChild;for(;s&&F.get(s)instanceof Ze;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=F.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!C.ios||!this.children.some(r=>r instanceof Le))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let i of this.children){if(!(i instanceof Le)||/[^ -~]/.test(i.text))return null;let s=zt(i.dom);if(s.length!=1)return null;e+=s[0].width,t=s[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let i=Pa(this,e,t);if(!this.children.length&&i&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let o=(r-s.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(e){return e instanceof X&&this.children.length==0&&e.children.length==0&&Mn(this.attrs,e.attrs)&&this.breakAfter==e.breakAfter}covers(){return!0}static find(e,t){for(let i=0,s=0;i<e.children.length;i++){let r=e.children[i],o=s+r.length;if(o>=t){if(r instanceof X)return r;if(o>t)break}s=o+r.breakAfter}return null}}class Xe extends F{constructor(e,t,i){super(),this.widget=e,this.length=t,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,s,r,o){return i&&(!(i instanceof Xe)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}domAtPos(e){return e==0?le.before(this.dom):le.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let i=new Xe(this.widget,t,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Dr}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):B.empty}domBoundsAround(){return null}become(e){return e instanceof Xe&&e.widget.constructor==this.widget.constructor?(e.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.deco=e.deco,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(e,t){return this.widget.coordsAt(this.dom,e,t)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(e){let{startSide:t,endSide:i}=this.deco;return t==i?!1:e<0?t<0:i>0}}class Fe{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var ce=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(ce||(ce={}));class T extends ct{constructor(e,t,i,s){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(e){return new Li(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ut(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,s;if(e.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Ba(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new ut(e,i,s,t,e.widget||null,!0)}static line(e){return new Ii(e)}static set(e,t=!1){return R.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}T.none=R.empty;class Li extends T{constructor(e){let{start:t,end:i}=Ba(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,i;return this==e||e instanceof Li&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((i=e.attrs)===null||i===void 0?void 0:i.class))&&Mn(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Li.prototype.point=!1;class Ii extends T{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Ii&&this.spec.class==e.spec.class&&Mn(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Ii.prototype.mapMode=te.TrackBefore;Ii.prototype.point=!0;class ut extends T{constructor(e,t,i,s,r,o){super(t,i,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?te.TrackBefore:te.TrackAfter:te.TrackDel}get type(){return this.startSide!=this.endSide?ce.WidgetRange:this.startSide<=0?ce.WidgetBefore:ce.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof ut&&hu(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}ut.prototype.point=!0;function Ba(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function hu(n,e){return n==e||!!(n&&e&&n.compare(e))}function Js(n,e,t,i=0){let s=t.length-1;s>=0&&t[s]+i>=n?t[s]=Math.max(t[s],e):t.push(n,e)}class mi{constructor(e,t,i,s){this.doc=e,this.pos=t,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof Xe&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new X),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ki(new jt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof Xe)&&this.getLine()}buildText(e,t,i){for(;e>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(Ki(new Le(this.text.slice(this.textOff,this.textOff+s)),t),i),this.atCursorPos=!0,this.textOff+=s,e-=s,i=0}}span(e,t,i,s){this.buildText(t-e,i,s),this.pos=t,this.openStart<0&&(this.openStart=s)}point(e,t,i,s,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ut){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(i instanceof ut)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Xe(i.widget||qt.block,l,i));else{let a=rt.create(i.widget||qt.inline,l,l?0:i.startSide),c=this.atCursorPos&&!a.isEditable&&r<=s.length&&(e<t||i.startSide>0),h=!a.isEditable&&(e<t||r>s.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!c&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),c&&(f.append(Ki(new jt(1),s),r),r=s.length+Math.max(0,r-s.length)),f.append(Ki(a,s),r),this.atCursorPos=h,this.pendingBuffer=h?e<t||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,i,s,r){let o=new mi(e,t,i,r);return o.openEnd=R.spans(s,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Ki(n,e){for(let t of e)n=new Ze(t,[n],n.length);return n}class qt extends Fe{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}qt.inline=new qt("span");qt.block=new qt("div");var W=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(W||(W={}));const kt=W.LTR,Er=W.RTL;function Ra(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const cu=Ra("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),fu=Ra("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Us=Object.create(null),We=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Us[e]=t,Us[t]=-e}function La(n){return n<=247?cu[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?fu[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const uu=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class ot{get dir(){return this.level%2?Er:kt}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Ia(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],s=e[t];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!Ia(i.inner,s.inner))return!1}return!0}const N=[];function du(n,e,t,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:s;for(let c=o,h=a,f=a;c<l;c++){let u=La(n.charCodeAt(c));u==512?u=h:u==8&&f==4&&(u=16),N[c]=u==4?2:u,u&7&&(f=u),h=u}for(let c=o,h=a,f=a;c<l;c++){let u=N[c];if(u==128)c<l-1&&h==N[c+1]&&h&24?u=N[c]=h:N[c]=256;else if(u==64){let d=c+1;for(;d<l&&N[d]==64;)d++;let p=c&&h==8||d<t&&N[d]==8?f==1?1:8:256;for(let g=c;g<d;g++)N[g]=p;c=d-1}else u==8&&f==1&&(N[c]=1);h=u,u&7&&(f=u)}}}function pu(n,e,t,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let c=o?i[o-1].to:e,h=o<i.length?i[o].from:t;for(let f=c,u,d,p;f<h;f++)if(d=Us[u=n.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(We[g+1]==-d){let y=We[g+2],b=y&2?s:y&4?y&1?r:s:0;b&&(N[f]=N[We[g]]=b),l=g;break}}else{if(We.length==189)break;We[l++]=f,We[l++]=u,We[l++]=a}else if((p=N[f])==2||p==1){let g=p==s;a=g?0:1;for(let y=l-3;y>=0;y-=3){let b=We[y+2];if(b&2)break;if(g)We[y+2]|=2;else{if(b&4)break;We[y+2]|=4}}}}}function mu(n,e,t,i){for(let s=0,r=i;s<=t.length;s++){let o=s?t[s-1].to:n,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let c=N[a];if(c==256){let h=a+1;for(;;)if(h==l){if(s==t.length)break;h=t[s++].to,l=s<t.length?t[s].from:e}else if(N[h]==256)h++;else break;let f=r==1,u=(h<e?N[h]:i)==1,d=f==u?f?1:2:i;for(let p=h,g=s,y=g?t[g-1].to:n;p>a;)p==y&&(p=t[--g].from,y=g?t[g-1].to:n),N[--p]=d;a=h}else r=c,a++}}}function Ys(n,e,t,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=e,c=0;a<t;){let h=!0,f=!1;if(c==r.length||a<r[c].from){let g=N[a];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(c<r.length&&p==r[c].from){if(f)break e;let g=r[c];if(!h)for(let y=g.to,b=c+1;;){if(y==t)break e;if(b<r.length&&r[b].from==y)y=r[b++].to;else{if(N[y]==l)break e;break}}if(c++,u)u.push(g);else{g.from>a&&o.push(new ot(a,g.from,d));let y=g.direction==kt!=!(d%2);Gs(n,y?i+1:i,s,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==t||(h?N[p]!=l:N[p]==l))break;p++}u?Ys(n,a,p,i+1,s,u,o):a<p&&o.push(new ot(a,p,d)),a=p}else for(let a=t,c=r.length;a>e;){let h=!0,f=!1;if(!c||a>r[c-1].to){let g=N[a-1];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(c&&p==r[c-1].to){if(f)break e;let g=r[--c];if(!h)for(let y=g.from,b=c;;){if(y==e)break e;if(b&&r[b-1].to==y)y=r[--b].from;else{if(N[y-1]==l)break e;break}}if(u)u.push(g);else{g.to<a&&o.push(new ot(g.to,a,d));let y=g.direction==kt!=!(d%2);Gs(n,y?i+1:i,s,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==e||(h?N[p-1]!=l:N[p-1]==l))break;p--}u?Ys(n,p,a,i+1,s,u,o):p<a&&o.push(new ot(p,a,d)),a=p}}function Gs(n,e,t,i,s,r,o){let l=e%2?2:1;du(n,s,r,i,l),pu(n,s,r,i,l),mu(s,r,i,l),Ys(n,s,r,e,t,i,o)}function gu(n,e,t){if(!n)return[new ot(0,0,e==Er?1:0)];if(e==kt&&!t.length&&!uu.test(n))return Na(n.length);if(t.length)for(;n.length>N.length;)N[N.length]=256;let i=[],s=e==kt?0:1;return Gs(n,s,s,t,0,n.length,i),i}function Na(n){return[new ot(0,n,0)]}let Fa="";function yu(n,e,t,i,s){var r;let o=i.head-n.from,l=ot.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],c=a.side(s,t);if(o==c){let u=l+=s?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!s,t),c=a.side(s,t)}let h=re(n.text,o,a.forward(s,t));(h<a.from||h>a.to)&&(h=c),Fa=n.text.slice(Math.min(o,h),Math.max(o,h));let f=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return f&&h==c&&f.level+(s?0:1)<a.level?x.cursor(f.side(!s,t)+n.from,f.forward(s,t)?1:-1,f.level):x.cursor(h+n.from,a.forward(s,t)?-1:1,a.level)}function bu(n,e,t){for(let i=e;i<t;i++){let s=La(n.charCodeAt(i));if(s==1)return kt;if(s==2||s==4)return Er}return kt}const Va=A.define(),Ha=A.define(),Wa=A.define(),$a=A.define(),Xs=A.define(),za=A.define(),ja=A.define(),qa=A.define({combine:n=>n.some(e=>e)}),Ka=A.define({combine:n=>n.some(e=>e)}),_a=A.define();class Ft{constructor(e,t="nearest",i="nearest",s=5,r=5,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Ft(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Ft(x.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const _i=D.define({map:(n,e)=>n.map(e)}),Ja=D.define();function he(n,e,t){let i=n.facet($a);i.length?i[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}const it=A.define({combine:n=>n.length?n[0]:!0});let xu=0;const li=A.define();class _{constructor(e,t,i,s,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(e,t){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=t||{};return new _(xu++,e,i,s,l=>{let a=[li.of(l)];return o&&a.push(Si.of(c=>{let h=c.plugin(l);return h?o(h):T.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return _.define(i=>new e(i),t)}}class ls{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(he(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){he(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){he(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ua=A.define(),Pr=A.define(),Si=A.define(),Ya=A.define(),Br=A.define(),Ga=A.define();function wo(n,e){let t=n.state.facet(Ga);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(n):r),s=[];return R.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let c=r-e.from,h=o-e.from,f=s;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=bu(e.text,c,h)),a>0&&f.length&&(p=f[f.length-1]).to==c&&p.direction==d)p.to=h,f=p.inner;else{let g={from:c,to:h,direction:d,inner:[]};f.push(g),f=g.inner}}}}),s}const Xa=A.define();function Qa(n){let e=0,t=0,i=0,s=0;for(let r of n.state.facet(Xa)){let o=r(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:i,bottom:s}}const ai=A.define();class Ae{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new Ae(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==e.length?null:e[s],c=o-l,h=a?a.fromB:1e9;for(;r<t.length&&t[r]<h;){let f=t[r],u=t[r+1],d=Math.max(l,f),p=Math.min(h,u);if(d<=p&&new Ae(d+c,p+c,d,p).addToSet(i),u>h)break;r+=2}if(!a)return i;new Ae(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class Tn{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=ee.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new Ae(r,o,l,a))),this.changedRanges=s}static create(e,t,i){return new Tn(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class So extends F{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=T.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new X],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ae(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:h})=>h<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?s=this.domChanged.newSel.head:!Mu(e.changes,this.hasComposition)&&!e.selectionSet&&(s=e.state.selection.main.head));let r=s>-1?wu(this.view,e.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:c,to:h}=this.hasComposition;i=new Ae(c,h,e.changes.mapPos(c,-1),e.changes.mapPos(h,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(C.ie||C.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=Cu(o,l,e.changes);return i=Ae.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=C.chrome||C.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||s.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof Xe&&o.widget instanceof ko&&r.push(o.dom);s.updateGaps(r)}updateChildren(e,t,i){let s=i?i.range.addToSet(e.slice()):e,r=this.childCursor(t);for(let o=s.length-1;;o--){let l=o>=0?s[o]:null;if(!l)break;let{fromA:a,toA:c,fromB:h,toB:f}=l,u,d,p,g;if(i&&i.range.fromB<f&&i.range.toB>h){let S=mi.build(this.view.state.doc,h,i.range.fromB,this.decorations,this.dynamicDecorationMap),k=mi.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=S.breakAtStart,p=S.openStart,g=k.openEnd;let O=this.compositionView(i);k.breakAtStart?O.breakAfter=1:k.content.length&&O.merge(O.length,O.length,k.content[0],!1,k.openStart,0)&&(O.breakAfter=k.content[0].breakAfter,k.content.shift()),S.content.length&&O.merge(0,0,S.content[S.content.length-1],!0,0,S.openEnd)&&S.content.pop(),u=S.content.concat(O).concat(k.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=mi.build(this.view.state.doc,h,f,this.decorations,this.dynamicDecorationMap));let{i:y,off:b}=r.findPos(c,1),{i:v,off:M}=r.findPos(a,-1);Aa(this,v,M,y,b,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(Ja)&&(this.editContextFormatting=i.value)}compositionView(e){let t=new Le(e.text.nodeValue);t.flags|=8;for(let{deco:s}of e.marks)t=new Ze(s,[t],t.length);let i=new X;return i.append(t,0),i}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=F.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(e.range.fromB,1),s=this.children[i.i];t(e.line,s);for(let r=e.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],t(r>=0?e.marks[r].node:e.text,s)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&dn(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||t||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),c=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(C.gecko&&l.empty&&!this.hasComposition&&vu(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=c=new le(f,0),o=!0}let h=this.view.observer.selectionRange;(o||!h.focusNode||(!pi(a.node,a.offset,h.anchorNode,h.anchorOffset)||!pi(c.node,c.offset,h.focusNode,h.focusOffset))&&!this.suppressWidgetCursorChange(h,l))&&(this.view.observer.ignore(()=>{C.android&&C.chrome&&this.dom.contains(h.focusNode)&&Au(h.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=wi(this.view.root);if(f)if(l.empty){if(C.gecko){let u=Su(a.node,a.offset);if(u&&u!=3){let d=(u==1?Sa:ka)(a.node,a.offset);d&&(a=new le(d.node,d.offset))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,c]=[c,a]),u.setEnd(c.node,c.offset),u.setStart(a.node,a.offset),f.removeAllRanges(),f.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,c)),this.impreciseAnchor=a.precise?null:new le(h.anchorNode,h.anchorOffset),this.impreciseHead=c.precise?null:new le(h.focusNode,h.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&pi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=wi(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=X.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!a||!c||a.bottom>c.top)return;let h=this.domAtPos(t.head+t.assoc);i.collapse(h.node,h.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(s,r)}moveToLine(e){let t=this.dom,i;if(e.node!=t)return e;for(let s=e.offset;!i&&s<t.childNodes.length;s++){let r=F.get(t.childNodes[s]);r instanceof X&&(i=r.domAtPos(0))}for(let s=e.offset-1;!i&&s>=0;s--){let r=F.get(t.childNodes[s]);r instanceof X&&(i=r.domAtPos(r.length))}return i?new le(i.node,i.offset,!0):e}nearest(e){for(let t=e;t;){let i=F.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t<this.children.length-1;){let s=this.children[t];if(i<s.length||s instanceof X)break;t++,i=0}return this.children[t].domAtPos(i)}coordsAt(e,t){let i=null,s=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,c=a-l.length;if(a<e)break;if(c<=e&&(c<e||l.covers(-1))&&(a>e||l.covers(1))&&(!i||l instanceof X&&!(i instanceof X&&t>=0)))i=l,s=c;else if(i&&c==e&&a==e&&l instanceof Xe&&Math.abs(t)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=c}return i?i.coordsAt(e-s,t):null}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),s=this.children[t];if(!(s instanceof X))return null;for(;s.children.length;){let{i:l,off:a}=s.childPos(i,1);for(;;l++){if(l==s.children.length)return null;if((s=s.children[l]).length)break}i=a}if(!(s instanceof Le))return null;let r=re(s.text,i);if(r==i)return null;let o=St(s.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==W.LTR;for(let c=0,h=0;h<this.children.length;h++){let f=this.children[h],u=c+f.length;if(u>s)break;if(c>=i){let d=f.dom.getBoundingClientRect();if(t.push(d.height),o){let p=f.dom.lastChild,g=p?zt(p):[];if(g.length){let y=g[g.length-1],b=a?y.right-d.left:d.right-y.left;b>l&&(l=b,this.minWidth=r,this.minWidthFrom=c,this.minWidthTo=u)}}}c=u+f.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?W.RTL:W.LTR}measureTextSize(){for(let r of this.children)if(r instanceof X){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,i,s;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let r=zt(e.firstChild)[0];t=e.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:i,textHeight:s}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Ca(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(T.replace({widget:new ko(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return T.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Si).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(Ya).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[e++]=i,t.push(R.join(s))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;return this.decorations}scrollIntoView(e){if(e.isSnapshot){let c=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=c.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let c of this.view.state.facet(_a))try{if(c(this.view,e.range,e))return!0}catch(h){he(this.view.state,h,"scroll handler")}let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!i)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=Qa(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;Zf(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==W.LTR)}}function vu(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}class ko extends Fe{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Za(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let i=Sa(t.focusNode,t.focusOffset),s=ka(t.focusNode,t.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=F.get(s.node);if(!l||l instanceof Le&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=F.get(i.node);!a||a instanceof Le&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function wu(n,e,t){let i=Za(n,t);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc,c=new Ae(a.mapPos(r),a.mapPos(o),r,o),h=[];for(let f=s.parentNode;;f=f.parentNode){let u=F.get(f);if(u instanceof Ze)h.push({node:f,deco:u.mark});else{if(u instanceof X||f.nodeName=="DIV"&&f.parentNode==n.contentDOM)return{range:c,text:s,marks:h,line:f};if(f!=n.contentDOM)h.push({node:f,deco:new Li({inclusive:!0,attributes:au(f),tagName:f.tagName.toLowerCase()})});else return null}}}function Su(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let ku=class{constructor(){this.changes=[]}compareRange(e,t){Js(e,t,this.changes)}comparePoint(e,t){Js(e,t,this.changes)}};function Cu(n,e,t){let i=new ku;return R.compare(n,e,t,i),i.changes}function Au(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function Mu(n,e){let t=!1;return e&&n.iterChangedRanges((i,s)=>{i<e.to&&s>e.from&&(t=!0)}),t}function Tu(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return x.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=re(s.text,r,!1):l=re(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let c=re(s.text,o,!1);if(i(s.text.slice(c,o))!=a)break;o=c}for(;l<s.length;){let c=re(s.text,l);if(i(s.text.slice(l,c))!=a)break;l=c}return x.range(o+s.from,l+s.from)}function Ou(n,e){return e.left>n?e.left-n:Math.max(0,n-e.right)}function Du(n,e){return e.top>n?e.top-n:Math.max(0,n-e.bottom)}function as(n,e){return n.top<e.bottom-1&&n.bottom>e.top+1}function Co(n,e){return e<n.top?{top:e,left:n.left,right:n.right,bottom:n.bottom}:n}function Ao(n,e){return e>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:e}:n}function Qs(n,e,t){let i,s,r,o,l=!1,a,c,h,f;for(let p=n.firstChild;p;p=p.nextSibling){let g=zt(p);for(let y=0;y<g.length;y++){let b=g[y];s&&as(s,b)&&(b=Co(Ao(b,s.bottom),s.top));let v=Ou(e,b),M=Du(t,b);if(v==0&&M==0)return p.nodeType==3?Mo(p,e,t):Qs(p,e,t);if(!i||o>M||o==M&&r>v){i=p,s=b,r=v,o=M;let S=M?t<b.top?-1:1:v?e<b.left?-1:1:0;l=!S||(S>0?y<g.length-1:y>0)}v==0?t>b.bottom&&(!h||h.bottom<b.bottom)?(a=p,h=b):t<b.top&&(!f||f.top>b.top)&&(c=p,f=b):h&&as(h,b)?h=Ao(h,b.bottom):f&&as(f,b)&&(f=Co(f,b.top))}}if(h&&h.bottom>=t?(i=a,s=h):f&&f.top<=t&&(i=c,s=f),!i)return{node:n,offset:0};let u=Math.max(s.left,Math.min(s.right,e));if(i.nodeType==3)return Mo(i,u,t);if(l&&i.contentEditable!="false")return Qs(i,u,t);let d=Array.prototype.indexOf.call(n.childNodes,i)+(e>=(s.left+s.right)/2?1:0);return{node:n,offset:d}}function Mo(n,e,t){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=St(n,l,l+1).getClientRects();for(let c=0;c<a.length;c++){let h=a[c];if(h.top==h.bottom)continue;o||(o=e-h.left);let f=(h.top>t?h.top-t:t-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&f<r){let u=e>=(h.left+h.right)/2,d=u;if((C.chrome||C.gecko)&&St(n,l).getBoundingClientRect().left==h.right&&(d=!u),f<=0)return{node:n,offset:l+(d?1:0)};s=l+(d?1:0),r=f}}}return{node:n,offset:s>-1?s:o>0?n.nodeValue.length:0}}function eh(n,e,t,i=-1){var s,r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,a,{docHeight:c}=n.viewState,{x:h,y:f}=e,u=f-l;if(u<0)return 0;if(u>c)return n.state.doc.length;for(let S=n.viewState.heightOracle.textHeight/2,k=!1;a=n.elementAtHeight(u),a.type!=ce.Text;)for(;u=i>0?a.bottom+S:a.top-S,!(u>=0&&u<=c);){if(k)return t?null:0;k=!0,i=-i}f=l+u;let d=a.from;if(d<n.viewport.from)return n.viewport.from==0?0:t?null:To(n,o,a,h,f);if(d>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:t?null:To(n,o,a,h,f);let p=n.dom.ownerDocument,g=n.root.elementFromPoint?n.root:p,y=g.elementFromPoint(h,f);y&&!n.contentDOM.contains(y)&&(y=null),y||(h=Math.max(o.left+1,Math.min(o.right-1,h)),y=g.elementFromPoint(h,f),y&&!n.contentDOM.contains(y)&&(y=null));let b,v=-1;if(y&&((s=n.docView.nearest(y))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let S=p.caretPositionFromPoint(h,f);S&&({offsetNode:b,offset:v}=S)}else if(p.caretRangeFromPoint){let S=p.caretRangeFromPoint(h,f);S&&({startContainer:b,startOffset:v}=S,(!n.contentDOM.contains(b)||C.safari&&Eu(b,v,h)||C.chrome&&Pu(b,v,h))&&(b=void 0))}}if(!b||!n.docView.dom.contains(b)){let S=X.find(n.docView,d);if(!S)return u>a.top+a.height/2?a.to:a.from;({node:b,offset:v}=Qs(S.dom,h,f))}let M=n.docView.nearest(b);if(!M)return null;if(M.isWidget&&((r=M.dom)===null||r===void 0?void 0:r.nodeType)==1){let S=M.dom.getBoundingClientRect();return e.y<S.top||e.y<=S.bottom&&e.x<=(S.left+S.right)/2?M.posAtStart:M.posAtEnd}else return M.localPosFromDOM(b,v)+M.posAtStart}function To(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+Ws(o,r,n.state.tabSize)}function Eu(n,e,t){let i;if(n.nodeType!=3||e!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return St(n,i-1,i).getBoundingClientRect().left>t}function Pu(n,e,t){if(e!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():St(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function Zs(n,e){let t=n.lineBlockAt(e);if(Array.isArray(t.type)){for(let i of t.type)if(i.to>e||i.to==e&&(i.to==t.to||i.type==ce.Text))return i}return t}function Bu(n,e,t,i){let s=Zs(n,e.head),r=!i||s.type!=ce.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==W.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return x.cursor(a,t?-1:1)}return x.cursor(t?s.to:s.from,t?-1:1)}function Oo(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let c=yu(s,r,o,l,t),h=Fa;if(!c){if(s.number==(t?n.state.doc.lines:1))return l;h=`
|
|
6
|
-
`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),c=n.visualLineSide(s,!t)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function Ru(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==z.Space&&(s=o),s==o}}function Lu(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return x.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),c=n.coordsAtPos(s,e.assoc||-1),h=n.documentTop;if(c)o==null&&(o=c.left-a.left),l=r<0?c.top:c.bottom;else{let d=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+h}let f=a.left+o,u=i??n.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=eh(n,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<s:g>s)){let y=n.docView.coordsForChar(g),b=!y||p<y.top?-1:1;return x.cursor(g,b,void 0,o)}}}function pn(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function hs(n,e,t){let i=pn(n.state.facet(Br).map(s=>s(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:x.cursor(i,i<t.from?1:-1)}class Iu{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,C.safari&&e.contentDOM.addEventListener("input",()=>null),C.gecko&&Xu(e.contentDOM.ownerDocument)}handleEvent(e){!ju(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||this.runHandlers(e.type,e)}runHandlers(e,t){let i=this.handlers[e];if(i){for(let s of i.observers)s(this.view,t);for(let s of i.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Nu(e),i=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&ih.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),C.android&&C.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return C.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=th.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||Fu.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Nt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:C.safari&&!C.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Do(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(s){he(t.state,s)}}}function Nu(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec;if(s&&s.domEventHandlers)for(let r in s.domEventHandlers){let o=s.domEventHandlers[r];o&&t(r).handlers.push(Do(i.value,o))}if(s&&s.domEventObservers)for(let r in s.domEventObservers){let o=s.domEventObservers[r];o&&t(r).observers.push(Do(i.value,o))}}for(let i in Ie)t(i).handlers.push(Ie[i]);for(let i in Te)t(i).observers.push(Te[i]);return e}const th=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Fu="dthko",ih=[16,17,18,20,91,92,224,225],Ji=6;function Ui(n){return Math.max(0,n)*.7+8}function Vu(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class Hu{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=eu(e.contentDOM),this.atoms=e.state.facet(Br).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(P.allowMultipleSelections)&&Wu(e,t),this.dragging=zu(e,t)&&rh(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Vu(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=Qa(this.view);e.clientX-a.left<=s+Ji?t=-Ui(s-e.clientX):e.clientX+a.right>=o-Ji&&(t=Ui(e.clientX-o)),e.clientY-a.top<=r+Ji?i=-Ui(r-e.clientY):e.clientY+a.bottom>=l-Ji&&(i=Ui(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;i<e.ranges.length;i++){let s=e.ranges[i],r=null;if(s.empty){let o=pn(this.atoms,s.from,0);o!=s.from&&(r=x.cursor(o,-1))}else{let o=pn(this.atoms,s.from,-1),l=pn(this.atoms,s.to,1);(o!=s.from||l!=s.to)&&(r=x.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?x.create(t,e.mainIndex):e}select(e){let{view:t}=this,i=this.skipAtoms(this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Wu(n,e){let t=n.state.facet(Va);return t.length?t[0](e):C.mac?e.metaKey:e.ctrlKey}function $u(n,e){let t=n.state.facet(Ha);return t.length?t[0](e):C.mac?!e.altKey:!e.ctrlKey}function zu(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=wi(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function ju(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=F.get(t))&&i.ignoreEvent(e))return!1;return!0}const Ie=Object.create(null),Te=Object.create(null),nh=C.ie&&C.ie_version<15||C.ios&&C.webkit_version<604;function qu(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),sh(n,t.value)},50)}function sh(n,e){let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(er!=null&&t.selection.ranges.every(a=>a.empty)&&er==r.toString()){let a=-1;i=t.changeByRange(c=>{let h=t.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let f=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:f},range:x.cursor(c.from+f.length)}})}else o?i=t.changeByRange(a=>{let c=r.line(s++);return{changes:{from:a.from,to:a.to,insert:c.text},range:x.cursor(a.from+c.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Te.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Ie.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);Te.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};Te.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ie.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(Wa))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=Ju(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new Hu(n,e,t,i)),i&&n.observer.ignore(()=>{xa(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}return!1};function Eo(n,e,t,i){if(i==1)return x.cursor(e,t);if(i==2)return Tu(n.state,e,t);{let s=X.find(n.docView,e),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,x.range(o,l)}}let Po=(n,e,t)=>e>=t.top&&e<=t.bottom&&n>=t.left&&n<=t.right;function Ku(n,e,t,i){let s=X.find(n.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Po(t,i,o))return-1;let l=s.coordsAt(r,1);return l&&Po(t,i,l)?1:o&&o.bottom>=i?-1:1}function Bo(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Ku(n,t,e.clientX,e.clientY)}}const _u=C.ie&&C.ie_version<=11;let Ro=null,Lo=0,Io=0;function rh(n){if(!_u)return n.detail;let e=Ro,t=Io;return Ro=n,Io=Date.now(),Lo=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Lo+1)%3:1}function Ju(n,e){let t=Bo(n,e),i=rh(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=Bo(n,r),c,h=Eo(n,a.pos,a.bias,i);if(t.pos!=a.pos&&!o){let f=Eo(n,t.pos,t.bias,i),u=Math.min(f.from,h.from),d=Math.max(f.to,h.to);h=u<h.from?x.range(u,d):x.range(d,u)}return o?s.replaceRange(s.main.extend(h.from,h.to)):l&&i==1&&s.ranges.length>1&&(c=Uu(s,a.pos))?c:l?s.addRange(h):x.create([h])}}}function Uu(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:s}=n.ranges[t];if(i<=e&&s>=e)return x.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}Ie.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let s=n.docView.nearest(e.target);if(s&&s.isWidget){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=x.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",n.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove"),!1};Ie.dragend=n=>(n.inputState.draggedContent=null,!1);function No(n,e,t,i){if(!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&$u(n,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ie.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),s=0,r=()=>{++s==t.length&&No(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return No(n,e,i,!0),!0}return!1};Ie.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=nh?null:e.clipboardData;return t?(sh(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(qu(n),!1)};function Yu(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Gu(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:e.join(n.lineBreak),ranges:t,linewise:i}}let er=null;Ie.copy=Ie.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=Gu(n.state);if(!t&&!s)return!1;er=s?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=nh?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Yu(n,t),!1)};const oh=Ne.define();function lh(n,e){let t=[];for(let i of n.facet(ja)){let s=i(n,e);s&&t.push(s)}return t?n.update({effects:t,annotations:oh.of(!0)}):null}function ah(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=lh(n.state,e);t?n.dispatch(t):n.update([])}},10)}Te.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),ah(n)};Te.blur=n=>{n.observer.clearSelectionRange(),ah(n)};Te.compositionstart=Te.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};Te.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,C.chrome&&C.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};Te.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ie.beforeinput=(n,e)=>{var t;let i;if(C.chrome&&C.android&&(i=th.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return C.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),C.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>Te.compositionend(n,e),20),!1};const Fo=new Set;function Xu(n){Fo.has(n)||(Fo.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Vo=["pre-wrap","normal","pre-line","break-spaces"];class Qu{constructor(e){this.lineWrapping=e,this.doc=B.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Vo.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=Vo.indexOf(e)>-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}}class Zu{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class ze{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?ce.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ut?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new ze(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var H=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(H||(H={}));const mn=.001;class fe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>mn&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return fe.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:f}=s[l],u=r.lineAt(a,H.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=c?u:r.lineAt(c,H.ByPosNoHeight,i,0,0);for(f+=d.to-c,c=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,h=s[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,H.ByPosNoHeight,i,0,0));h+=u.from-a,a=u.from;let p=Rr.build(i.setDoc(o),e,h,f);r=r.replace(a,c,p)}return r.updateHeight(i,0)}static empty(){return new be(0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,s=0,r=0;for(;;)if(t==i)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new ed(fe.of(e.slice(0,t)),o,fe.of(e.slice(i)))}}fe.prototype.size=1;class hh extends fe{constructor(e,t,i){super(e,t),this.deco=i}blockAt(e,t,i,s){return new ze(s,this.length,i,this.height,this.deco||0)}lineAt(e,t,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(e,t,i,s,r,o){e<=r+this.length&&t>=r&&o(this.blockAt(0,i,s,r))}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(e,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class be extends hh{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,s){return new ze(s,this.length,i,this.height,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof be||s instanceof ie&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ie?s=new be(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):fe.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setHeight(e,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ie extends fe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let c=s+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),h=t.doc.lineAt(c),f=l+h.length*a,u=Math.max(i,e-f/2);return new ze(h.from,h.length,u,f,0)}else{let c=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:h,length:f}=t.doc.line(r+c);return new ze(h,f,i+l*c,l,0)}}lineAt(e,t,i,s,r){if(t==H.ByHeight)return this.blockAt(e,i,s,r);if(t==H.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new ze(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),c=i.doc.lineAt(e),h=l+c.length*a,f=c.number-o,u=s+l*f+a*(c.from-r-f);return new ze(c.from,c.length,Math.max(s,Math.min(u,s+this.height-h)),h,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,r);for(let h=e,f=s;h<=t;){let u=i.doc.lineAt(h);if(h==e){let p=u.number-l;f+=a*p+c*(e-r-p)}let d=a+c*u.length;o(new ze(u.from,u.length,f,d,0)),f+=d,h=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof ie?i[i.length-1]=new ie(r.length+s):i.push(null,new ie(s-1))}if(e>0){let r=i[0];r instanceof ie?i[0]=new ie(e+r.length):i.unshift(new ie(e-1),null)}return fe.of(i)}decomposeLeft(e,t){t.push(new ie(e-1),null)}decomposeRight(e,t){t.push(null,new ie(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new ie(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let h=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++];a==-1?a=f:Math.abs(f-a)>=mn&&(a=-2);let u=new be(h,f);u.outdated=!1,o.push(u),l+=h+1}l<=r&&o.push(null,new ie(r-l).updateHeight(e,l));let c=fe.of(o);return(a<0||Math.abs(c.height-this.height)>=mn||Math.abs(a-this.heightMetrics(e,t).perLine)>=mn)&&(e.heightChanged=!0),c}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class ed extends fe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==H.ByHeight?e<o:e<l,c=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=t==H.ByPosNoHeight?H.ByPosNoHeight:H.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,s,r).join(c)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let c=this.lineAt(a,H.ByPos,i,s,r);e<c.from&&this.left.forEachLine(e,c.from-1,i,s,r,o),c.to>=e&&c.from<=t&&o(c),t>c.to&&this.right.forEachLine(c.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Ho(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Ho(r,l)}return fe.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?fe.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ho(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof ie&&(i=n[e+1])instanceof ie&&n.splice(e-1,3,new ie(t.length+1+i.length))}const td=5;class Rr{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof be?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new be(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new hh(o,s,i)):(o||r||s>=td)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new be(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new ie(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof be)return e;let t=new be(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof be)&&!this.isCovered?this.nodes.push(new be(0,-1)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let s of this.nodes)s instanceof be&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new Rr(i,e);return R.spans(t,i,s,r,0),r.finish(i)}}function id(n,e,t){let i=new nd;return R.compare(n,e,t,i,0),i.changes}class nd{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&Js(e,t,this.changes,5)}}function sd(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let c=n.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,f=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&f.overflow!="visible"){let u=h.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=c==n.parentNode?u.bottom:Math.min(a,u.bottom)}c=f.position=="absolute"||f.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function rd(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class cs{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let s=e[i],r=t[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e,t){return T.replace({widget:new od(this.size*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class od extends Fe{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class Wo{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=$o,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=W.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(Pr).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Qu(t),this.stateDeco=e.facet(Si).filter(i=>typeof i!="function"),this.heightMap=fe.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle.setDoc(e.doc),[new Ae(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=T.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new Yi(r,o))}}return this.viewports=e.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?$o:new Lr(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(hi(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Si).filter(h=>typeof h!="function");let s=e.changedRanges,r=Ae.extendWithRanges(s,id(i,this.stateDeco,e?e.changes:ee.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(c||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Ka)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?W.RTL:W.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,h=0;if(l.width&&l.height){let{scaleX:S,scaleY:k}=ba(t,l);(S>.005&&Math.abs(this.scaleX-S)>.005||k>.005&&Math.abs(this.scaleY-k)>.005)&&(this.scaleX=S,this.scaleY=k,c|=8,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,c|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=wa(e.scrollDOM);let p=(this.printing?rd:sd)(t,this.paddingTop),g=p.top-this.pixelViewport.top,y=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,c|=8),a){let S=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(S)&&(o=!0),o||s.lineWrapping&&Math.abs(v-this.contentDOMWidth)>s.charWidth){let{lineHeight:k,charWidth:O,textHeight:L}=e.docView.measureTextSize();o=k>0&&s.refresh(r,k,O,L,v/O,S),o&&(e.docView.minWidth=0,c|=8)}g>0&&y>0?h=Math.max(g,y):g<0&&y<0&&(h=Math.min(g,y)),s.heightChanged=!1;for(let k of this.viewports){let O=k.from==this.viewport.from?S:e.docView.measureVisibleLineHeights(k);this.heightMap=(o?fe.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle,[new Ae(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Zu(k.from,O))}s.heightChanged&&(c|=2)}let M=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return M&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||M)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Yi(s.lineAt(o-i*1e3,H.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,H.ByHeight,r,0,0).to);if(t){let{head:c}=t.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(c,H.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-h/2:t.y=="start"||t.y=="nearest"&&c<a.from?u=f.top:u=f.bottom-h,a=new Yi(s.lineAt(u-1e3/2,H.ByHeight,r,0,0).from,s.lineAt(u+h+1e3/2,H.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Yi(this.heightMap.lineAt(i,H.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,H.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,H.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,H.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new cs(t.mapPos(s.from),t.mapPos(s.to),s.size));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=W.LTR&&!i)return[];let l=[],a=(h,f,u,d)=>{if(f-h<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let b of g)if(b>h&&b<f){a(h,b-10,u,d),a(b+10,f,u,d);return}let y=ad(e,b=>b.from>=u.from&&b.to<=u.to&&Math.abs(b.from-h)<r&&Math.abs(b.to-f)<r&&!g.some(v=>b.from<v&&b.to>v));if(!y){if(f<u.to&&t&&i&&t.visibleRanges.some(b=>b.from<=f&&b.to>=f)){let b=t.moveToLineBoundary(x.cursor(f),!1,!0).head;b>h&&(f=b)}y=new cs(h,f,this.gapSize(u,h,f,d))}l.push(y)},c=h=>{if(h.length<o||h.type!=ce.Text)return;let f=ld(h.from,h.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,y,b;if(u!=null){let v=Xi(f,u),M=((this.visibleBottom-this.visibleTop)/2+g)/h.height;y=v-M,b=v+M}else y=(this.visibleTop-h.top-g)/h.height,b=(this.visibleBottom-h.top+g)/h.height;d=Gi(f,y),p=Gi(f,b)}else{let g=f.total*this.heightOracle.charWidth,y=s*this.heightOracle.charWidth,b,v;if(u!=null){let M=Xi(f,u),S=((this.pixelViewport.right-this.pixelViewport.left)/2+y)/g;b=M-S,v=M+S}else b=(this.pixelViewport.left-y)/g,v=(this.pixelViewport.right+y)/g;d=Gi(f,b),p=Gi(f,v)}d>h.from&&a(h.from,d,h,f),p<h.to&&a(p,h.to,h,f)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(e,t,i,s){let r=Xi(s,i)-Xi(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){cs.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=T.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];R.spans(e,this.viewport.from,this.viewport.to,{span(s,r){t.push({from:s,to:r})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=t[r].from||s.to!=t[r].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||hi(this.heightMap.lineAt(e,H.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||hi(this.heightMap.lineAt(this.scaler.fromDOM(e),H.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return hi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Yi{constructor(e,t){this.from=e,this.to=t}}function ld(n,e,t){let i=[],s=n,r=0;return R.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(i.push({from:s,to:e}),r+=e-s),{total:r,ranges:i}}function Gi({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function Xi(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function ad(n,e){for(let t of n)if(e(t))return t}const $o={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};class Lr{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=t.lineAt(l,H.ByPos,e,0,0).top,h=t.lineAt(a,H.ByPos,e,0,0).bottom;return s+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,s=r.domBottom}}eq(e){return e instanceof Lr?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function hi(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new ze(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>hi(s,e)):n._content)}const Qi=A.define({combine:n=>n.join(" ")}),tr=A.define({combine:n=>n.indexOf(!0)>-1}),ir=ht.newName(),ch=ht.newName(),fh=ht.newName(),uh={"&light":"."+ch,"&dark":"."+fh};function nr(n,e,t){return new ht(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}const hd=nr("."+ir,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},uh),ci="";class cd{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(P.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=ci}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=s.nextSibling;if(o==t)break;let l=F.get(s),a=F.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:An(s))||An(o)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=o}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=F.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(fd(e,i.node,i.offset)?t:0))}}function fd(n,e,t){for(;;){if(!e||t<Qe(e))return!1;if(e==n)return!0;t=wt(e)+1,e=e.parentNode}}class zo{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class ud{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=r||o?[]:md(e),a=new cd(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=gd(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!$s(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!$s(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=e.viewport;if((C.ios||C.chrome)&&e.state.selection.main.empty&&a!=c&&(h.from>0||h.to<e.state.doc.length)){let f=Math.min(a,c),u=Math.max(a,c),d=h.from-f,p=h.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==e.state.doc.length)&&(a=0,c=e.state.doc.length)}this.newSel=x.single(c,a)}}}function dh(n,e){let t,{newSel:i}=e,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,c=null;(r===8||C.android&&e.text.length<l-o)&&(a=s.to,c="end");let h=pd(n.state.doc.sliceString(o,l,ci),e.text,a-o,c);h&&(C.chrome&&r==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==ci+ci&&h.toB--,t={from:o+h.from,to:o+h.toA,insert:B.of(e.text.slice(h.from,h.toB).split(ci))})}else i&&(!n.hasFocus&&n.state.facet(it)||i.main.eq(s))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!s.empty&&i&&i.main.empty?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,s.to))}:(C.mac||C.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=x.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:B.of([" "])}):C.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
7
|
-
`&&n.lineWrapping&&(i&&(i=x.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:B.of([" "])}),t)return ph(n,t,i,r);if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function ph(n,e,t,i=-1){if(C.ios&&n.inputState.flushIOSKey(e))return!0;let s=n.state.selection.main;if(C.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&n.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Nt(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&Nt(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&Nt(n.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=dd(n,e,t));return n.state.facet(za).some(a=>a(n,e.from,e.to,r,l))||n.dispatch(l()),!0}function dd(n,e,t){let i,s=n.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=r.from<e.from?s.sliceDoc(r.from,e.from):"",a=r.to>e.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+a))}else{let l=s.changes(e),a=t&&t.main.to<=l.newLength?t.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let c=n.state.sliceDoc(e.from,e.to),h,f=t&&Za(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);h={from:f.from,to:f.to-p}}else h=n.state.doc.lineAt(r.head);let u=r.to-e.to,d=r.to-r.from;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let g=p.to-u,y=g-c.length;if(p.to-p.from!=d||n.state.sliceDoc(y,g)!=c||p.to>=h.from&&p.from<=h.to)return{range:p};let b=s.changes({from:y,to:g,insert:e.insert}),v=p.to-r.to;return{changes:b,range:a?x.range(Math.max(0,a.anchor+v),Math.max(0,a.head+v)):p.map(b)}})}else i={changes:l,selection:a&&s.selection.replaceRange(a)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:o,scrollIntoView:!0})}function pd(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&n.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function md(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new zo(t,i)),(s!=t||r!=i)&&e.push(new zo(s,r))),e}function gd(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?x.single(t+e,i+e):null}const yd={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},fs=C.ie&&C.ie_version<=11;class bd{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new tu,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(C.ie&&C.ie_version<=11||C.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&e.constructor.EDIT_CONTEXT!==!1&&!(C.chrome&&C.chrome_version<126)&&(this.editContext=new vd(e),e.state.facet(it)&&(e.contentDOM.editContext=this.editContext.editContext)),fs&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){e.type=="change"&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(it)?i.root.activeElement!=this.dom:!dn(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(C.ie&&C.ie_version<=11||C.android&&C.chrome)&&!i.state.selection.main.empty&&s.focusNode&&pi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=wi(e.root);if(!t)return!1;let i=C.safari&&e.root.nodeType==11&&Xf(this.dom.ownerDocument)==this.dom&&xd(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let s=dn(this.dom,i);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&nu(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,yd),fs&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),fs&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Nt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&dn(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new ud(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,s=dh(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let i=jo(t,e.previousSibling||e.target.previousSibling,-1),s=jo(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(it)!=e.state.facet(it)&&(e.view.contentDOM.editContext=e.state.facet(it)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function jo(n,e,t){for(;e;){let i=F.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function qo(n,e){let t=e.startContainer,i=e.startOffset,s=e.endContainer,r=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor);return pi(o.node,o.offset,s,r)&&([t,i,s,r]=[s,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}}function xd(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return qo(n,s)}let t=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?qo(n,t):null}class vd{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:s}=e.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:B.of(i.text.split(`
|
|
8
|
-
`))};r.from==this.from&&s<this.from?r.from=s:r.to==this.to&&s>this.to&&(r.to=s),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,e.state.readOnly||ph(e,r,x.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)))},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}t.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;s.push(T.mark({attributes:{style:a}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}e.dispatch({effects:Ja.of(T.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{e.inputState.composing=-1,e.inputState.compositionFirstChange=null};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=wi(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,c)=>{if(i)return;let h=c.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(c)){s=this.pendingContextChange=null,t+=h,this.to+=h;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=h,this.to+=h;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),c.toString()),this.to+=h}t+=h}),s&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange;!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.resetRange(e.state),this.editContext.updateText(0,this.editContext.text.length,e.state.doc.sliceString(this.from,this.to)),this.setSelection(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e){return e+this.from}toContextPos(e){return e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class w{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(i=>i.forEach(s=>t(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||iu(e.parent)||document,this.viewState=new Wo(e.state||P.create(e)),e.scrollTo&&e.scrollTo.is(_i)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(li).map(i=>new ls(i));for(let i of this.plugins)i.update(this);this.observer=new bd(this),this.inputState=new Iu(this),this.inputState.ensureHandlers(this.plugins),this.docView=new So(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...e){let t=e.length==1&&e[0]instanceof Y?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(oh))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=lh(r,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(h=null)):this.observer.clear(),r.facet(P.phrases)!=this.state.facet(P.phrases))return this.setState(r);s=Tn.create(this,r,e),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new Ft(d.empty?d:x.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(_i)&&(f=d.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=On.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(ai)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Qi)!=s.state.facet(Qi)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(Xs))try{u(s)}catch(d){he(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!dh(this,h)&&c.force&&Nt(this.contentDOM,c.key,c.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Wo(e),this.plugins=e.facet(li).map(i=>new ls(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new So(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(li),i=e.state.facet(li);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new ls(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){he(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(wa(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return he(this.state,p),Ko}}),f=Tn.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f),u&&this.docViewUpdate());for(let d=0;d<c.length;d++)if(h[d]!=Ko)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){he(this.state,p)}if(u&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(p>1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Xs))l(t)}get themeClasses(){return ir+" "+(this.state.facet(tr)?fh:ch)+" "+this.state.facet(Qi)}updateAttrs(){let e=_o(this,Ua,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(it)?"true":"false",class:"cm-content",style:`${C.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),_o(this,Pr,t);let i=this.observer.ignore(()=>{let s=_s(this.contentDOM,this.contentAttrs,t),r=_s(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(w.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(ai);let e=this.state.facet(w.cspNonce);ht.mount(this.root,this.styleModules.concat(hd).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.spec!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return hs(this,e,Oo(this,e,t,i))}moveByGroup(e,t){return hs(this,e,Oo(this,e,t,i=>Ru(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return x.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,i=!0){return Bu(this,e,t,i)}moveVertically(e,t,i){return hs(this,e,Lu(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),eh(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[ot.find(r,e-s.from,-1,t)];return Kn(i,o.dir==W.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(qa)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>wd)return Na(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Ia(r.isolates,i=wo(this,e))))return r.order;i||(i=wo(this,e));let s=gu(e.text,t,i);return this.bidiCache.push(new On(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||C.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{xa(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return _i.of(new Ft(typeof e=="number"?x.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return _i.of(new Ft(x.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return _.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return _.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ht.newName(),s=[Qi.of(i),ai.of(nr(`.${i}`,e))];return t&&t.dark&&s.push(tr.of(!0)),s}static baseTheme(e){return pt.lowest(ai.of(nr("."+ir,e,uh)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&F.get(i)||F.get(e);return((t=s==null?void 0:s.rootView)===null||t===void 0?void 0:t.view)||null}}w.styleModule=ai;w.inputHandler=za;w.scrollHandler=_a;w.focusChangeEffect=ja;w.perLineTextDirection=qa;w.exceptionSink=$a;w.updateListener=Xs;w.editable=it;w.mouseSelectionStyle=Wa;w.dragMovesSelection=Ha;w.clickAddsSelectionRange=Va;w.decorations=Si;w.outerDecorations=Ya;w.atomicRanges=Br;w.bidiIsolatedRanges=Ga;w.scrollMargins=Xa;w.darkTheme=tr;w.cspNonce=A.define({combine:n=>n.length?n[0]:""});w.contentAttributes=Pr;w.editorAttributes=Ua;w.lineWrapping=w.contentAttributes.of({class:"cm-lineWrapping"});w.announce=D.define();const wd=4096,Ko={};class On{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:W.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&i.push(new On(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function _o(n,e,t){for(let i=n.state.facet(e),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&Ks(o,t)}return t}const Sd=C.mac?"mac":C.windows?"win":C.linux?"linux":"key";function kd(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const c=t[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))s=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Zi(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const Cd=pt.default(w.domEventHandlers({keydown(n,e){return gh(mh(e.state),n,e,"editor")}})),Gt=A.define({enables:Cd}),Jo=new WeakMap;function mh(n){let e=n.facet(Gt),t=Jo.get(e);return t||Jo.set(e,t=Td(e.reduce((i,s)=>i.concat(s),[]))),t}function Ad(n,e,t){return gh(mh(n.state),e,n,t)}let nt=null;const Md=4e3;function Td(n,e=Sd){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,c,h)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(b=>kd(b,e));for(let b=1;b<p.length;b++){let v=p.slice(0,b).join(" ");s(v,!0),d[v]||(d[v]={preventDefault:!0,stopPropagation:!1,run:[M=>{let S=nt={view:M,prefix:v,scope:o};return setTimeout(()=>{nt==S&&(nt=null)},Md),!0}]})}let g=p.join(" ");s(g,!1);let y=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&y.run.push(a),c&&(y.preventDefault=!0),h&&(y.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=t[c]||(t[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in h)h[u].run.push(d=>f(d,sr))}let a=o[e]||o.key;if(a)for(let c of l)r(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let sr=null;function gh(n,e,t,i){sr=e;let s=yf(e),r=ne(s,0),o=ke(r)==s.length&&s!=" ",l="",a=!1,c=!1,h=!1;nt&&nt.view==t&&nt.scope==i&&(l=nt.prefix+" ",ih.indexOf(e.keyCode)<0&&(c=!0,nt=null));let f=new Set,u=y=>{if(y){for(let b of y.run)if(!f.has(b)&&(f.add(b),b(t)))return y.stopPropagation&&(h=!0),!0;y.preventDefault&&(y.stopPropagation&&(h=!0),c=!0)}return!1},d=n[i],p,g;return d&&(u(d[l+Zi(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(C.windows&&e.ctrlKey&&e.altKey)&&(p=bf[e.keyCode])&&p!=s?(u(d[l+Zi(p,e,!0)])||e.shiftKey&&(g=xf[e.keyCode])!=s&&g!=p&&u(d[l+Zi(g,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Zi(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),c&&(a=!0),a&&h&&e.stopPropagation(),sr=null,a}class Ni{constructor(e,t,i,s,r){this.className=e,this.left=t,this.top=i,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let s=e.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=yh(e);return[new Ni(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Od(e,t,i)}}function yh(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==W.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function Uo(n,e,t,i){let s=n.coordsAtPos(e,t*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=n.posAtCoords({x:r.left+1,y:o}),a=n.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Od(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let i=Math.max(t.from,n.viewport.from),s=Math.min(t.to,n.viewport.to),r=n.textDirection==W.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=yh(n),c=o.querySelector(".cm-line"),h=c&&window.getComputedStyle(c),f=l.left+(h?parseInt(h.paddingLeft)+Math.min(0,parseInt(h.textIndent)):0),u=l.right-(h?parseInt(h.paddingRight):0),d=Zs(n,i),p=Zs(n,s),g=d.type==ce.Text?d:null,y=p.type==ce.Text?p:null;if(g&&(n.lineWrapping||d.widgetLineBreaks)&&(g=Uo(n,i,1,g)),y&&(n.lineWrapping||p.widgetLineBreaks)&&(y=Uo(n,s,-1,y)),g&&y&&g.from==y.from&&g.to==y.to)return v(M(t.from,t.to,g));{let k=g?M(t.from,null,g):S(d,!1),O=y?M(null,t.to,y):S(p,!0),L=[];return(g||d).to<(y||p).from-(g&&y?1:0)||d.widgetLineBreaks>1&&k.bottom+n.defaultLineHeight/2<O.top?L.push(b(f,k.bottom,u,O.top)):k.bottom<O.top&&n.elementAtHeight((k.bottom+O.top)/2).type==ce.Text&&(k.bottom=O.top=(k.bottom+O.top)/2),v(k).concat(L).concat(v(O))}function b(k,O,L,K){return new Ni(e,k-a.left,O-a.top-.01,L-k,K-O+.01)}function v({top:k,bottom:O,horizontal:L}){let K=[];for(let I=0;I<L.length;I+=2)K.push(b(L[I],k,L[I+1],O));return K}function M(k,O,L){let K=1e9,I=-1e9,ue=[];function Ye(Ee,He,we,Z,Pe){let de=n.coordsAtPos(Ee,Ee==L.to?-2:2),Be=n.coordsAtPos(we,we==L.from?2:-2);!de||!Be||(K=Math.min(de.top,Be.top,K),I=Math.max(de.bottom,Be.bottom,I),Pe==W.LTR?ue.push(r&&He?f:de.left,r&&Z?u:Be.right):ue.push(!r&&Z?f:Be.left,!r&&He?u:de.right))}let De=k??L.from,tt=O??L.to;for(let Ee of n.visibleRanges)if(Ee.to>De&&Ee.from<tt)for(let He=Math.max(Ee.from,De),we=Math.min(Ee.to,tt);;){let Z=n.state.doc.lineAt(He);for(let Pe of n.bidiSpans(Z)){let de=Pe.from+Z.from,Be=Pe.to+Z.from;if(de>=we)break;Be>He&&Ye(Math.max(de,He),k==null&&de<=De,Math.min(Be,we),O==null&&Be>=tt,Pe.dir)}if(He=Z.to+1,He>=we)break}return ue.length==0&&Ye(De,k==null,tt,O==null,n.textDirection),{top:K,bottom:I,horizontal:ue}}function S(k,O){let L=l.top+(O?k.top:k.bottom);return{top:L,bottom:L,horizontal:[]}}}function Dd(n,e){return n.constructor==e.constructor&&n.eq(e)}class Ed{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(gn)!=e.state.facet(gn)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(gn);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,i)=>!Dd(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[i].constructor&&s.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const gn=A.define();function bh(n){return[_.define(e=>new Ed(e,n)),gn.of(n)]}const xh=!C.ios,ki=A.define({combine(n){return Je(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Pd(n={}){return[ki.of(n),Bd,Rd,Ld,Ka.of(!0)]}function vh(n){return n.startState.facet(ki)!=n.state.facet(ki)}const Bd=bh({above:!0,markers(n){let{state:e}=n,t=e.facet(ki),i=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty?!r||xh:t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:x.cursor(s.head,s.head>s.anchor?-1:1);for(let a of Ni.forRange(n,o,l))i.push(a)}}return i},update(n,e){n.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=vh(n);return t&&Yo(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){Yo(e.state,n)},class:"cm-cursorLayer"});function Yo(n,e){e.style.animationDuration=n.facet(ki).cursorBlinkRate+"ms"}const Rd=bh({above:!1,markers(n){return n.state.selection.ranges.map(e=>e.empty?[]:Ni.forRange(n,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||vh(n)},class:"cm-selectionLayer"}),rr={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};xh&&(rr[".cm-line"].caretColor=rr[".cm-content"].caretColor="transparent !important");const Ld=pt.highest(w.theme(rr)),wh=D.define({map(n,e){return n==null?null:e.mapPos(n)}}),fi=Q.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(wh)?i.value:t,n)}}),Id=_.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(fi);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(fi)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,e=n.state.field(fi),t=e!=null&&n.coordsAtPos(e);if(!t)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:t.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:t.bottom-t.top}}drawCursor(n){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;n?(this.cursor.style.left=n.left/e+"px",this.cursor.style.top=n.top/t+"px",this.cursor.style.height=n.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(fi)!=n&&this.view.dispatch({effects:wh.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Nd(){return[fi,Id]}function Go(n,e,t,i,s){e.lastIndex=0;for(let r=n.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,l)}function Fd(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let i=[];for(let{from:s,to:r}of t)s=Math.max(n.state.doc.lineAt(s).from,s-e),r=Math.min(n.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}class Vd{constructor(e){const{regexp:t,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,c,h)=>s(h,c,c+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,c,h)=>{let f=i(l,a,c);f&&h(c,c+l[0].length,f)};else if(i)this.addMatch=(l,a,c,h)=>h(c,c+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new ft,i=t.add.bind(t);for(let{from:s,to:r}of Fd(e,this.maxLength))Go(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),e.viewportChanged||s-i>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),i,s):t}updateRange(e,t,i,s){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let a=e.state.doc.lineAt(o),c=a.to<l?e.state.doc.lineAt(l):a,h=Math.max(r.from,a.from),f=Math.min(r.to,c.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){h=o;break}for(;l<c.to;l++)if(this.boundary.test(c.text[l-c.from])){f=l;break}}let u=[],d,p=(g,y,b)=>u.push(b.range(g,y));if(a==c)for(this.regexp.lastIndex=h-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else Go(e.state.doc,this.regexp,h,f,(g,y)=>this.addMatch(y,e,g,p));t=t.update({filterFrom:h,filterTo:f,filter:(g,y)=>g<h||y>f,add:u})}}return t}}const or=/x/.unicode!=null?"gu":"g",Hd=new RegExp(`[\0-\b
|
|
9
|
-
--\u2028\u2029\uFEFF-]`,or),Wd={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let us=null;function $d(){var n;if(us==null&&typeof document<"u"&&document.body){let e=document.body.style;us=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return us||!1}const yn=A.define({combine(n){let e=Je(n,{render:null,specialChars:Hd,addSpecialChars:null});return(e.replaceTabs=!$d())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,or)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,or)),e}});function zd(n={}){return[yn.of(n),jd()]}let Xo=null;function jd(){return Xo||(Xo=_.fromClass(class{constructor(n){this.view=n,this.decorations=T.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(yn)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Vd({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=ne(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,a=Yt(o.text,l,i-o.from);return T.replace({widget:new Jd((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=T.replace({widget:new _d(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(yn);n.startState.facet(yn)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const qd="•";function Kd(n){return n>=32?qd:n==10?"":String.fromCharCode(9216+n)}class _d extends Fe{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=Kd(this.code),i=e.state.phrase("Control character")+" "+(Wd[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Jd extends Fe{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function Ud(){return Gd}const Yd=T.line({class:"cm-activeLine"}),Gd=_.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>e&&(t.push(Yd.range(s.from)),e=s.from)}return T.set(t)}},{decorations:n=>n.decorations});class Xd extends Fe{constructor(e){super(),this.content=e}toDOM(){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?e.setAttribute("aria-label","placeholder "+this.content):e.setAttribute("aria-hidden","true"),e}coordsAt(e){let t=e.firstChild?zt(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),s=Kn(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function Qd(n){return _.fromClass(class{constructor(e){this.view=e,this.placeholder=n?T.set([T.widget({widget:new Xd(n),side:1}).range(0)]):T.none}get decorations(){return this.view.state.doc.length?T.none:this.placeholder}},{decorations:e=>e.decorations})}const lr=2e3;function Zd(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>lr||t.off>lr||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=s;a++){let c=n.doc.line(a);c.length<=l&&r.push(x.range(c.from+o,c.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=s;a++){let c=n.doc.line(a),h=Ws(c.text,o,n.tabSize,!0);if(h<0)r.push(x.cursor(c.to));else{let f=Ws(c.text,l,n.tabSize);r.push(x.range(c.from+h,c.from+f))}}}return r}function ep(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function Qo(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=n.state.doc.lineAt(t),s=t-i.from,r=s>lr?-1:s==i.length?ep(n,e.clientX):Yt(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function tp(n,e){let t=Qo(n,e),i=n.state.selection;return t?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(t.line).from),o=s.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=Qo(n,s);if(!l)return i;let a=Zd(n.state,t,l);return a.length?o?x.create(a.concat(i.ranges)):x.create(a):i}}:null}function ip(n){let e=t=>t.altKey&&t.button==0;return w.mouseSelectionStyle.of((t,i)=>e(i)?tp(t,i):null)}const np={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},sp={style:"cursor: crosshair"};function rp(n={}){let[e,t]=np[n.key||"Alt"],i=_.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==e||t(s))},keyup(s){(s.keyCode==e||!t(s))&&this.set(!1)},mousemove(s){this.set(t(s))}}});return[i,w.contentAttributes.of(s=>{var r;return!((r=s.plugin(i))===null||r===void 0)&&r.isDown?sp:null})]}const ni="-10000px";class Sh{constructor(e,t,i,s){this.facet=t,this.createTooltipView=i,this.removeTooltipView=s,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(e,t){var i;let s=e.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let c=r[a],h=-1;if(c){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==c.create&&(h=f)}if(h<0)o[a]=this.createTooltipView(c,a?o[a-1]:null),l&&(l[a]=!!c.above);else{let f=o[a]=this.tooltipViews[h];l&&(l[a]=t[h]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,c)=>t[c]=a),t.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}}function op(n){let{win:e}=n;return{top:0,left:0,bottom:e.innerHeight,right:e.innerWidth}}const ds=A.define({combine:n=>{var e,t,i;return{position:C.ios?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||op}}}),Zo=new WeakMap,Ir=_.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(ds);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Sh(n,Nr,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(ds);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",t.dom.appendChild(s)}return t.dom.style.position=this.position,t.dom.style.top=ni,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect(),e=1,t=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(C.gecko)i=s.offsetParent!=this.container.ownerDocument.body;else if(s.style.top==ni&&s.style.left=="0px"){let r=s.getBoundingClientRect();i=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}}if(i||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(e=s.width/this.parent.offsetWidth,t=s.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((s,r)=>{let o=this.manager.tooltipViews[r];return o.getCoords?o.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(ds).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:i}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:t,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],c=this.manager.tooltipViews[l],{dom:h}=c,f=n.pos[l],u=n.size[l];if(!f||f.bottom<=Math.max(t.top,i.top)||f.top>=Math.min(t.bottom,i.bottom)||f.right<Math.max(t.left,i.left)-.1||f.left>Math.min(t.right,i.right)+.1){h.style.top=ni;continue}let d=a.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,y=(e=Zo.get(c))!==null&&e!==void 0?e:u.bottom-u.top,b=c.offset||ap,v=this.view.textDirection==W.LTR,M=u.width>i.right-i.left?v?i.left:i.right-u.width:v?Math.max(i.left,Math.min(f.left-(d?14:0)+b.x,i.right-g)):Math.min(Math.max(i.left,f.left-g+(d?14:0)-b.x),i.right-g),S=this.above[l];!a.strictSide&&(S?f.top-(u.bottom-u.top)-b.y<i.top:f.bottom+(u.bottom-u.top)+b.y>i.bottom)&&S==i.bottom-f.bottom>f.top-i.top&&(S=this.above[l]=!S);let k=(S?f.top-i.top:i.bottom-f.bottom)-p;if(k<y&&c.resize!==!1){if(k<this.view.defaultLineHeight){h.style.top=ni;continue}Zo.set(c,y),h.style.height=(y=k)/r+"px"}else h.style.height&&(h.style.height="");let O=S?f.top-y-p-b.y:f.bottom+p+b.y,L=M+g;if(c.overlap!==!0)for(let K of o)K.left<L&&K.right>M&&K.top<O+y&&K.bottom>O&&(O=S?K.top-y-2-p:K.bottom+p+2);if(this.position=="absolute"?(h.style.top=(O-n.parent.top)/r+"px",h.style.left=(M-n.parent.left)/s+"px"):(h.style.top=O/r+"px",h.style.left=M/s+"px"),d){let K=f.left+(v?b.x:-b.x)-(M+14-7);d.style.left=K/s+"px"}c.overlap!==!0&&o.push({left:M,top:O,right:L,bottom:O+y}),h.classList.toggle("cm-tooltip-above",S),h.classList.toggle("cm-tooltip-below",!S),c.positioned&&c.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=ni}},{eventObservers:{scroll(){this.maybeMeasure()}}}),lp=w.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),ap={x:0,y:0},Nr=A.define({enables:[Ir,lp]}),Dn=A.define({combine:n=>n.reduce((e,t)=>e.concat(t),[])});class Jn{static create(e){return new Jn(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Sh(e,Dn,(t,i)=>this.createHostedView(t,i),t=>t.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let s=i[e];if(s!==void 0){if(t===void 0)t=s;else if(t!==s)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const hp=Nr.compute([Dn],n=>{let e=n.facet(Dn);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var i;return(i=t.end)!==null&&i!==void 0?i:t.pos})),create:Jn.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class cp{constructor(e,t,i,s,r){this.view=e,this.source=t,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,i=e.docView.nearest(t.target);if(!i)return;let s,r=1;if(i instanceof rt)s=i.posAtStart;else{if(s=e.posAtCoords(t),s==null)return;let l=e.coordsAtPos(s);if(!l||t.y<l.top||t.y>l.bottom||t.x<l.left-e.defaultCharacterWidth||t.x>l.right+e.defaultCharacterWidth)return;let a=e.bidiSpans(e.state.doc.lineAt(s)).find(h=>h.from<=s&&h.to>=s),c=a&&a.dir==W.RTL?-1:1;r=t.x<l.left?-c:c}let o=this.source(e,s,r);if(o!=null&&o.then){let l=this.pending={pos:s};o.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>he(e.state,a,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let e=this.view.plugin(Ir),t=e?e.manager.tooltips.findIndex(i=>i.create==Jn.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:r}=this;if(s.length&&r&&!fp(r.dom,e)||this.pending){let{pos:o}=s[0]||this.pending,l=(i=(t=s[0])===null||t===void 0?void 0:t.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!up(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length){let{tooltip:i}=this;i&&i.dom.contains(e.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const en=4;function fp(n,e){let t=n.getBoundingClientRect();return e.clientX>=t.left-en&&e.clientX<=t.right+en&&e.clientY>=t.top-en&&e.clientY<=t.bottom+en}function up(n,e,t,i,s,r){let o=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(o.left>i||o.right<i||o.top>s||Math.min(o.bottom,l)<s)return!1;let a=n.posAtCoords({x:i,y:s},!1);return a>=e&&a<=t}function dp(n,e={}){let t=D.define(),i=Q.define({create(){return[]},update(s,r){if(s.length&&(e.hideOnChange&&(r.docChanged||r.selection)?s=[]:e.hideOn&&(s=s.filter(o=>!e.hideOn(r,o))),r.docChanged)){let o=[];for(let l of s){let a=r.changes.mapPos(l.pos,-1,te.TrackDel);if(a!=null){let c=Object.assign(Object.create(null),l);c.pos=a,c.end!=null&&(c.end=r.changes.mapPos(c.end)),o.push(c)}}s=o}for(let o of r.effects)o.is(t)&&(s=o.value),o.is(pp)&&(s=[]);return s},provide:s=>Dn.from(s)});return[i,_.define(s=>new cp(s,n,i,t,e.hoverTime||300)),hp]}function kh(n,e){let t=n.plugin(Ir);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const pp=D.define(),el=A.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Ci(n,e){let t=n.plugin(Ch),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Ch=_.fromClass(class{constructor(n){this.input=n.state.facet(Ai),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(el);this.top=new tn(n,!0,e.topContainer),this.bottom=new tn(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(el);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new tn(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new tn(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(Ai);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let c=this.specs.indexOf(a),h;c<0?(h=a(n.view),l.push(h)):(h=this.panels[c],h.update&&h.update(n)),s.push(h),(h.top?r:o).push(h)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>w.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class tn{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=tl(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=tl(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function tl(n){let e=n.nextSibling;return n.remove(),e}const Ai=A.define({enables:Ch});class et extends ct{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}et.prototype.elementClass="";et.prototype.toDOM=void 0;et.prototype.mapMode=te.TrackBefore;et.prototype.startSide=et.prototype.endSide=-1;et.prototype.point=!0;const bn=A.define(),mp={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>R.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},gi=A.define();function gp(n){return[Ah(),gi.of(Object.assign(Object.assign({},mp),n))]}const il=A.define({combine:n=>n.some(e=>e)});function Ah(n){return[yp]}const yp=_.fromClass(class{constructor(n){this.view=n,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(gi).map(e=>new sl(n,e));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!n.state.facet(il),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}n.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(il)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&this.dom.remove();let t=R.iter(this.view.state.facet(bn),this.view.viewport.from),i=[],s=this.gutters.map(r=>new bp(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==ce.Text&&o){ar(t,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==ce.Text){ar(t,i,r.from);for(let o of s)o.line(this.view,r,i)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();n&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(n){let e=n.startState.facet(gi),t=n.state.facet(gi),i=n.docChanged||n.heightChanged||n.viewportChanged||!R.eq(n.startState.facet(bn),n.state.facet(bn),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new sl(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove()}},{provide:n=>w.scrollMargins.of(e=>{let t=e.plugin(n);return!t||t.gutters.length==0||!t.fixed?null:e.textDirection==W.LTR?{left:t.dom.offsetWidth*e.scaleX}:{right:t.dom.offsetWidth*e.scaleX}})});function nl(n){return Array.isArray(n)?n:[n]}function ar(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class bp{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=R.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:s}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==s.elements.length){let l=new Mh(e,o,r,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let s=[];ar(this.cursor,s,t.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t);i&&this.addElement(e,t,[i])}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class sl{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,s)&&s.preventDefault()});this.markers=nl(t.markers(e)),t.initialSpacer&&(this.spacer=new Mh(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=nl(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!R.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Mh{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),xp(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,c=!1;if(a){let h=a.elementClass;h&&(i+=" "+h);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,c=!0;break}}else l=this.markers.length;for(;o<l;){let h=this.markers[o++];if(h.toDOM){h.destroy(s);let f=s.nextSibling;s.remove(),s=f}}if(!a)break;a.toDOM&&(c?s=s.nextSibling:this.dom.insertBefore(a.toDOM(e),s)),c&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function xp(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const vp=A.define(),Pt=A.define({combine(n){return Je(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let s in t){let r=i[s],o=t[s];i[s]=r?(l,a,c)=>r(l,a,c)||o(l,a,c):o}return i}})}});class ps extends et{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function ms(n,e){return n.state.facet(Pt).formatNumber(e,n.state)}const wp=gi.compute([Pt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(vp)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new ps(ms(e,e.state.doc.lineAt(t.from).number))},widgetMarker:()=>null,lineMarkerChange:e=>e.startState.facet(Pt)!=e.state.facet(Pt),initialSpacer(e){return new ps(ms(e,rl(e.state.doc.lines)))},updateSpacer(e,t){let i=ms(t.view,rl(t.view.state.doc.lines));return i==e.number?e:new ps(i)},domEventHandlers:n.facet(Pt).domEventHandlers}));function Sp(n={}){return[Pt.of(n),Ah(),wp]}function rl(n){let e=9;for(;e<n;)e=e*10+9;return e}const kp=new class extends et{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Cp=bn.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(kp.range(s)))}return R.of(e)});function Ap(){return Cp}var gs;const Bt=new Me;function Th(n){return A.define({combine:n?e=>e.concat(n):void 0})}const Fr=new Me;class Re{constructor(e,t,i=[],s=""){this.data=e,this.name=s,P.prototype.hasOwnProperty("tree")||Object.defineProperty(P.prototype,"tree",{get(){return j(this)}}),this.parser=t,this.extension=[dt.of(this),P.languageData.of((r,o,l)=>{let a=ol(r,o,l),c=a.type.prop(Bt);if(!c)return[];let h=r.facet(c),f=a.type.prop(Fr);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(h)}}return h})].concat(i)}isActiveAt(e,t,i=-1){return ol(e,t,i).type.prop(Bt)==this.data}findRegions(e){let t=e.facet(dt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(Bt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(Me.mounted);if(l){if(l.tree.prop(Bt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let c=r.children[a];c instanceof Et&&s(c,r.positions[a]+o)}};return s(j(e),0),i}get allowsNesting(){return!0}}Re.setState=D.define();function ol(n,e,t){let i=n.facet(dt),s=j(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,t,Sr.ExcludeBuffers))r.type.isTop&&(s=r);return s}class Kt extends Re{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Th(e.languageData);return new Kt(t,e.parser.configure({props:[Bt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Kt(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function j(n){let e=n.field(Re.state,!1);return e?e.tree:Et.empty}class Mp{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 i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let si=null;class En{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new En(e,t,[],Et.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Mp(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=Et.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(cn.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=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(cn.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=si;si=this;try{return e()}finally{si=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=ll(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((c,h,f,u)=>a.push({fromA:c,toA:h,fromB:f,toB:u})),i=cn.applyChanges(i,a),s=Et.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let h=e.mapPos(c.from,1),f=e.mapPos(c.to,-1);h<f&&l.push({from:h,to:f})}}}return new En(this.parser,t,i,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=ll(this.fragments,s,r),this.skipped.splice(i--,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 vf{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=si;if(a){for(let c of s)a.tempSkipped.push(c);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new Et(kr.none,[],[],o-r)},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 si}}function ll(n,e,t){return cn.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class _t{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),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new _t(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=En.create(e.facet(dt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new _t(i)}}Re.state=Q.define({create:_t.init,update(n,e){for(let t of e.effects)if(t.is(Re.setState))return t.value;return e.startState.facet(dt)!=e.state.facet(dt)?_t.init(e.state):n.apply(e)}});let Oh=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Oh=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const ys=typeof navigator<"u"&&(!((gs=navigator.scheduling)===null||gs===void 0)&&gs.isInputPending)?()=>navigator.scheduling.isInputPending():null,Tp=_.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(Re.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(Re.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Oh(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Re.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!ys?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>ys&&ys()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Re.setState.of(new _t(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>he(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()}}}),dt=A.define({combine(n){return n.length?n[0]:null},enables:n=>[Re.state,Tp,w.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Vr{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Op=A.define(),Xt=A.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Pn(n){let e=n.facet(Xt);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Mi(n,e){let t="",i=n.tabSize,s=n.facet(Xt)[0];if(s==" "){for(;e>=i;)t+=" ",e-=i;s=" "}for(let r=0;r<e;r++)t+=s;return t}function Hr(n,e){n instanceof P&&(n=new Un(n));for(let i of n.state.facet(Op)){let s=i(n,e);if(s!==void 0)return s}let t=j(n.state);return t.length>=e?Dp(n,t,e):null}class Un{constructor(e,t={}){this.state=e,this.options=t,this.unit=Pn(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(e,t);return i.slice(e-s,Math.min(i.length,e+100-s))}column(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.countColumn(i,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return Yt(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Yn=new Me;function Dp(n,e,t){let i=e.resolveStack(t),s=i.node.enterUnfinishedNodesBefore(t);if(s!=i.node){let r=[];for(let o=s;o!=i.node;o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return Dh(i,n,t)}function Dh(n,e,t){for(let i=n;i;i=i.next){let s=Pp(i.node);if(s)return s(Wr.create(e,t,i))}return 0}function Ep(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Pp(n){let e=n.type.prop(Yn);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(Me.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>Eh(o,!0,1,void 0,r&&!Ep(o)?s.from:void 0)}return n.parent==null?Bp:null}function Bp(){return 0}class Wr extends Un{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new Wr(e,t,i)}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 i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(Rp(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return Dh(this.context.next,this.base,this.pos)}}function Rp(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function Lp(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let c=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+c}}l=a.to}}function xn({closing:n,align:e=!0,units:t=1}){return i=>Eh(i,e,t,n)}function Eh(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=e?Lp(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const Ip=n=>n.baseIndent;function yi({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const Np=200;function Fp(){return P.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,s=t.lineAt(i);if(i>s.from+Np)return n;let r=t.sliceString(s.from,i);if(!e.some(c=>c.test(r)))return n;let{state:o}=n,l=-1,a=[];for(let{head:c}of o.selection.ranges){let h=o.doc.lineAt(c);if(h.from==l)continue;l=h.from;let f=Hr(o,h.from);if(f==null)continue;let u=/^\s*/.exec(h.text)[0],d=Mi(o,f);u!=d&&a.push({from:h.from,to:h.from+u.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}const Vp=A.define(),Gn=new Me;function $r(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function Hp(n,e,t){let i=j(n);if(i.length<t)return null;let s=i.resolveStack(t,1),r=null;for(let o=s;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(r&&l.from<e)break;let a=l.type.prop(Gn);if(a&&(l.to<i.length-50||i.length==n.doc.length||!Wp(l))){let c=a(l,n);c&&c.from<=t&&c.from>=e&&c.to>t&&(r=c)}}return r}function Wp(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function Bn(n,e,t){for(let i of n.facet(Vp)){let s=i(n,e,t);if(s)return s}return Hp(n,e,t)}function Ph(n,e){let t=e.mapPos(n.from,1),i=e.mapPos(n.to,-1);return t>=i?void 0:{from:t,to:i}}const Xn=D.define({map:Ph}),Fi=D.define({map:Ph});function Bh(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(n.lineBlockAt(t));return e}const Ct=Q.define({create(){return T.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)if(t.is(Xn)&&!$p(n,t.value.from,t.value.to)){let{preparePlaceholder:i}=e.state.facet(Ih),s=i?T.replace({widget:new Up(i(e.state,t.value))}):al;n=n.update({add:[s.range(t.value.from,t.value.to)]})}else t.is(Fi)&&(n=n.update({filter:(i,s)=>t.value.from!=i||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));if(e.selection){let t=!1,{head:i}=e.selection.main;n.between(i,i,(s,r)=>{s<i&&r>i&&(t=!0)}),t&&(n=n.update({filterFrom:i,filterTo:i,filter:(s,r)=>r<=i||s>=i}))}return n},provide:n=>w.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(i,s)=>{t.push(i,s)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let i=n[t++],s=n[t++];if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(al.range(i,s))}return T.set(e,!0)}});function Rn(n,e,t){var i;let s=null;return(i=n.field(Ct,!1))===null||i===void 0||i.between(e,t,(r,o)=>{(!s||s.from>r)&&(s={from:r,to:o})}),s}function $p(n,e,t){let i=!1;return n.between(e,e,(s,r)=>{s==e&&r==t&&(i=!0)}),i}function Rh(n,e){return n.field(Ct,!1)?e:e.concat(D.appendConfig.of(Nh()))}const zp=n=>{for(let e of Bh(n)){let t=Bn(n.state,e.from,e.to);if(t)return n.dispatch({effects:Rh(n.state,[Xn.of(t),Lh(n,t)])}),!0}return!1},jp=n=>{if(!n.state.field(Ct,!1))return!1;let e=[];for(let t of Bh(n)){let i=Rn(n.state,t.from,t.to);i&&e.push(Fi.of(i),Lh(n,i,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function Lh(n,e,t=!0){let i=n.state.doc.lineAt(e.from).number,s=n.state.doc.lineAt(e.to).number;return w.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${n.state.phrase("to")} ${s}.`)}const qp=n=>{let{state:e}=n,t=[];for(let i=0;i<e.doc.length;){let s=n.lineBlockAt(i),r=Bn(e,s.from,s.to);r&&t.push(Xn.of(r)),i=(r?n.lineBlockAt(r.to):s).to+1}return t.length&&n.dispatch({effects:Rh(n.state,t)}),!!t.length},Kp=n=>{let e=n.state.field(Ct,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(i,s)=>{t.push(Fi.of({from:i,to:s}))}),n.dispatch({effects:t}),!0},_p=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:zp},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:jp},{key:"Ctrl-Alt-[",run:qp},{key:"Ctrl-Alt-]",run:Kp}],Jp={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Ih=A.define({combine(n){return Je(n,Jp)}});function Nh(n){return[Ct,Xp]}function Fh(n,e){let{state:t}=n,i=t.facet(Ih),s=o=>{let l=n.lineBlockAt(n.posAtDOM(o.target)),a=Rn(n.state,l.from,l.to);a&&n.dispatch({effects:Fi.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(n,s,e);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const al=T.replace({widget:new class extends Fe{toDOM(n){return Fh(n,null)}}});class Up extends Fe{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Fh(e,this.value)}}const Yp={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class bs extends et{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function Gp(n={}){let e=Object.assign(Object.assign({},Yp),n),t=new bs(e,!0),i=new bs(e,!1),s=_.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(dt)!=o.state.facet(dt)||o.startState.field(Ct,!1)!=o.state.field(Ct,!1)||j(o.startState)!=j(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new ft;for(let a of o.viewportLineBlocks){let c=Rn(o.state,a.from,a.to)?i:Bn(o.state,a.from,a.to)?t:null;c&&l.add(a.from,a.from,c)}return l.finish()}}),{domEventHandlers:r}=e;return[s,gp({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||R.empty},initialSpacer(){return new bs(e,!1)},domEventHandlers:Object.assign(Object.assign({},r),{click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let c=Rn(o.state,l.from,l.to);if(c)return o.dispatch({effects:Fi.of(c)}),!0;let h=Bn(o.state,l.from,l.to);return h?(o.dispatch({effects:Xn.of(h)}),!0):!1}})}),Nh()]}const Xp=w.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class At{constructor(e,t){this.specs=e;let i;function s(l){let a=ht.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof Re?l=>l.prop(Bt)==o.data:o?l=>l==o:void 0,this.style=wf(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ht(i):null,this.themeType=t.themeType}static define(e,t){return new At(e,t||{})}}const hr=A.define(),Vh=A.define({combine(n){return n.length?[n[0]]:null}});function xs(n){let e=n.facet(hr);return e.length?e:n.facet(Vh)}function Qn(n,e){let t=[Zp],i;return n instanceof At&&(n.module&&t.push(w.styleModule.of(n.module)),i=n.themeType),e!=null&&e.fallback?t.push(Vh.of(n)):i?t.push(hr.computeN([w.darkTheme],s=>s.facet(w.darkTheme)==(i=="dark")?[n]:[])):t.push(hr.of(n)),t}class Qp{constructor(e){this.markCache=Object.create(null),this.tree=j(e.state),this.decorations=this.buildDeco(e,xs(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=j(e.state),i=xs(e.state),s=i!=xs(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!s&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return T.none;let i=new ft;for(let{from:s,to:r}of e.visibleRanges)Sf(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=T.mark({class:a})))},s,r);return i.finish()}}const Zp=pt.high(_.fromClass(Qp,{decorations:n=>n.decorations})),em=At.define([{tag:m.meta,color:"#404740"},{tag:m.link,textDecoration:"underline"},{tag:m.heading,textDecoration:"underline",fontWeight:"bold"},{tag:m.emphasis,fontStyle:"italic"},{tag:m.strong,fontWeight:"bold"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.keyword,color:"#708"},{tag:[m.atom,m.bool,m.url,m.contentSeparator,m.labelName],color:"#219"},{tag:[m.literal,m.inserted],color:"#164"},{tag:[m.string,m.deleted],color:"#a11"},{tag:[m.regexp,m.escape,m.special(m.string)],color:"#e40"},{tag:m.definition(m.variableName),color:"#00f"},{tag:m.local(m.variableName),color:"#30a"},{tag:[m.typeName,m.namespace],color:"#085"},{tag:m.className,color:"#167"},{tag:[m.special(m.variableName),m.macroName],color:"#256"},{tag:m.definition(m.propertyName),color:"#00c"},{tag:m.comment,color:"#940"},{tag:m.invalid,color:"#f00"}]),tm=w.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Hh=1e4,Wh="()[]{}",$h=A.define({combine(n){return Je(n,{afterCursor:!0,brackets:Wh,maxScanDistance:Hh,renderMatch:sm})}}),im=T.mark({class:"cm-matchingBracket"}),nm=T.mark({class:"cm-nonmatchingBracket"});function sm(n){let e=[],t=n.matched?im:nm;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const rm=Q.define({create(){return T.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet($h);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=je(e.state,s.head,-1,i)||s.head>0&&je(e.state,s.head-1,1,i)||i.afterCursor&&(je(e.state,s.head,1,i)||s.head<e.state.doc.length&&je(e.state,s.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e.state)))}return T.set(t,!0)},provide:n=>w.decorations.from(n)}),om=[rm,tm];function lm(n={}){return[$h.of(n),om]}const am=new Me;function cr(n,e,t){let i=n.prop(e<0?Me.openedBy:Me.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function fr(n){let e=n.type.prop(am);return e?e(n.node):n}function je(n,e,t,i={}){let s=i.maxScanDistance||Hh,r=i.brackets||Wh,o=j(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let c=cr(a.type,t,r);if(c&&a.from<a.to){let h=fr(a);if(h&&(t>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return hm(n,e,t,a,h,c,r)}}return cm(n,e,t,o,l.type,s,r)}function hm(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},c=0,h=l==null?void 0:l.cursor();if(h&&(t<0?h.childBefore(i.from):h.childAfter(i.to)))do if(t<0?h.to<=i.from:h.from>=i.to){if(c==0&&r.indexOf(h.type.name)>-1&&h.from<h.to){let f=fr(h);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(cr(h.type,t,o))c++;else if(cr(h.type,-t,o)){if(c==0){let f=fr(h);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}c--}}while(t<0?h.prevSibling():h.nextSibling());return{start:a,matched:!1}}function cm(n,e,t,i,s,r,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let c={from:t<0?e-1:e,to:t>0?e+1:e},h=n.doc.iterRange(e,t>0?n.doc.length:0),f=0;for(let u=0;!h.next().done&&u<=r;){let d=h.value;t<0&&(u+=d.length);let p=e+u*t;for(let g=t>0?0:d.length-1,y=t>0?d.length:-1;g!=y;g+=t){let b=o.indexOf(d[g]);if(!(b<0||i.resolveInner(p+g,1).type!=s))if(b%2==0==t>0)f++;else{if(f==1)return{start:c,end:{from:p+g,to:p+g+1},matched:b>>1==a>>1};f--}}t>0&&(u+=d.length)}return h.done?{start:c,matched:!1}:null}const fm=Object.create(null),hl=[kr.none],cl=[],fl=Object.create(null),um=Object.create(null);for(let[n,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"]])um[n]=dm(fm,e);function vs(n,e){cl.indexOf(n)>-1||(cl.push(n),console.warn(e))}function dm(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let c of l.split(".")){let h=n[c]||m[c];h?typeof h=="function"?a.length?a=a.map(h):vs(c,`Modifier ${c} used at start of tag`):a.length?vs(c,`Tag ${c} used as modifier`):a=Array.isArray(h)?h:[h]:vs(c,`Unknown highlighting tag ${c}`)}for(let c of a)t.push(c)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=fl[s];if(r)return r.id;let o=fl[s]=kr.define({id:hl.length,name:i,props:[kf({[i]:t})]});return hl.push(o),o.id}W.RTL,W.LTR;const pm=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=jr(n.state,t.from);return i.line?mm(n):i.block?ym(n):!1};function zr(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}const mm=zr(vm,0),gm=zr(zh,0),ym=zr((n,e)=>zh(n,e,xm(e)),0);function jr(n,e){let t=n.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const ri=50;function bm(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-ri,i),o=n.sliceDoc(s,s+ri),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,c=r.length-l;if(r.slice(c-e.length,c)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let h,f;s-i<=2*ri?h=f=n.sliceDoc(i,s):(h=n.sliceDoc(i,i+ri),f=n.sliceDoc(s-ri,s));let u=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return h.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(h.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function xm(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to);s.from>i.from&&s.from==t.to&&(s=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function zh(n,e,t=e.selection.ranges){let i=t.map(r=>jr(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>bm(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=i[o],{open:c,close:h}=l;r.push({from:c.pos-a.open.length,to:c.pos+c.margin},{from:h.pos-h.margin,to:h.pos+a.close.length})}return{changes:r}}return null}function vm(n,e,t=e.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of t){let l=i.length,a=1e9,c=jr(e,r).line;if(c){for(let h=r;h<=o;){let f=e.doc.lineAt(h);if(f.from>s&&(r==o||o>f.from)){s=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+c.length)==c?u:-1;u<f.text.length&&u<a&&(a=u),i.push({line:f,comment:p,token:c,indent:u,empty:d,single:!1})}h=f.to+1}if(a<1e9)for(let h=l;h<i.length;h++)i[h].indent<i[h].line.text.length&&(i[h].indent=a);i.length==l+1&&(i[l].single=!0)}}if(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:c,empty:h,single:f}of i)(f||!h)&&r.push({from:l.from+c,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let c=o.from+l,h=c+a.length;o.text[h-o.from]==" "&&h++,r.push({from:c,to:h})}return{changes:r}}return null}const ur=Ne.define(),wm=Ne.define(),Sm=A.define(),jh=A.define({combine(n){return Je(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}}),qh=Q.define({create(){return qe.empty},update(n,e){let t=e.state.facet(jh),i=e.annotation(ur);if(i){let a=ge.fromTransaction(e,i.selection),c=i.side,h=c==0?n.undone:n.done;return a?h=Ln(h,h.length,t.minDepth,a):h=Jh(h,e.startState.selection),new qe(c==0?i.rest:h,c==0?h:i.rest)}let s=e.annotation(wm);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(Y.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=ge.fromTransaction(e),o=e.annotation(Y.time),l=e.annotation(Y.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new qe(n.done.map(ge.fromJSON),n.undone.map(ge.fromJSON))}});function km(n={}){return[qh,jh.of(n),w.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?Kh:e.inputType=="historyRedo"?dr:null;return i?(e.preventDefault(),i(t)):!1}})]}function Zn(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(qh,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}const Kh=Zn(0,!1),dr=Zn(1,!1),Cm=Zn(0,!0),Am=Zn(1,!0);class ge{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new ge(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new ge(e.changes&&ee.fromJSON(e.changes),[],e.mapped&&_e.fromJSON(e.mapped),e.startSelection&&x.fromJSON(e.startSelection),e.selectionsAfter.map(x.fromJSON))}static fromTransaction(e,t){let i=Ce;for(let s of e.startState.facet(Sm)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new ge(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ce)}static selection(e){return new ge(void 0,Ce,void 0,void 0,e)}}function Ln(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function Mm(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let c=t[a++],h=t[a++];l>=c&&o<=h&&(i=!0)}}),i}function Tm(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function _h(n,e){return n.length?e.length?n.concat(e):n:e}const Ce=[],Om=200;function Jh(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Om));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),Ln(n,n.length-1,1e9,t.setSelAfter(i)))}else return[ge.selection([e])]}function Dm(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function ws(n,e){if(!n.length)return n;let t=n.length,i=Ce;for(;t;){let s=Em(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[ge.selection(i)]:Ce}function Em(n,e,t){let i=_h(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Ce,t);if(!n.changes)return ge.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new ge(s,D.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}const Pm=/^(input\.type|delete)($|\.)/;class qe{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new qe(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Pm.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,Mm(l.changes,e.changes))||i=="input.type.compose")?o=Ln(o,o.length-1,s.minDepth,new ge(e.changes.compose(l.changes),_h(D.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ce)):o=Ln(o,o.length,s.minDepth,e),new qe(o,Ce,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ce;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Tm(r[r.length-1],e)?this:new qe(Jh(this.done,e),this.undone,t,i)}addMapping(e){return new qe(ws(this.done,e),ws(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],o=r.selectionsAfter[0]||t.selection;if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:ur.of({side:e,rest:Dm(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=s.length==1?Ce:s.slice(0,s.length-1);return r.mapped&&(l=ws(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:ur.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}qe.empty=new qe(Ce,Ce);const Bm=[{key:"Mod-z",run:Kh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:dr,preventDefault:!0},{linux:"Ctrl-Shift-z",run:dr,preventDefault:!0},{key:"Mod-u",run:Cm,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Am,preventDefault:!0}];function Qt(n,e){return x.create(n.ranges.map(e),n.mainIndex)}function Ue(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Ve({state:n,dispatch:e},t){let i=Qt(n.selection,t);return i.eq(n.selection,!0)?!1:(e(Ue(n,i)),!0)}function es(n,e){return x.cursor(e?n.to:n.from)}function Uh(n,e){return Ve(n,t=>t.empty?n.moveByChar(t,e):es(t,e))}function ae(n){return n.textDirectionAt(n.state.selection.main.head)==W.LTR}const Yh=n=>Uh(n,!ae(n)),Gh=n=>Uh(n,ae(n));function Xh(n,e){return Ve(n,t=>t.empty?n.moveByGroup(t,e):es(t,e))}const Rm=n=>Xh(n,!ae(n)),Lm=n=>Xh(n,ae(n));function Im(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function ts(n,e,t){let i=j(n).resolveInner(e.head),s=t?Me.closedBy:Me.openedBy;for(let a=e.head;;){let c=t?i.childAfter(a):i.childBefore(a);if(!c)break;Im(n,c,s)?i=c:a=t?c.to:c.from}let r=i.type.prop(s),o,l;return r&&(o=t?je(n,i.from,1):je(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,x.cursor(l,t?-1:1)}const Nm=n=>Ve(n,e=>ts(n.state,e,!ae(n))),Fm=n=>Ve(n,e=>ts(n.state,e,ae(n)));function Qh(n,e){return Ve(n,t=>{if(!t.empty)return es(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const Zh=n=>Qh(n,!1),ec=n=>Qh(n,!0);function tc(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,s;if(e){for(let r of n.state.facet(w.scrollMargins)){let o=r(n);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}s=n.scrollDOM.clientHeight-t-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,s-5)}}function ic(n,e){let t=tc(n),{state:i}=n,s=Qt(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):es(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,c=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<c&&(r=w.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Ue(i,s),{effects:r}),!0}const ul=n=>ic(n,!1),pr=n=>ic(n,!0);function mt(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=x.cursor(i.from+r))}return s}const Vm=n=>Ve(n,e=>mt(n,e,!0)),Hm=n=>Ve(n,e=>mt(n,e,!1)),Wm=n=>Ve(n,e=>mt(n,e,!ae(n))),$m=n=>Ve(n,e=>mt(n,e,ae(n))),zm=n=>Ve(n,e=>x.cursor(n.lineBlockAt(e.head).from,1)),jm=n=>Ve(n,e=>x.cursor(n.lineBlockAt(e.head).to,-1));function qm(n,e,t){let i=!1,s=Qt(n.selection,r=>{let o=je(n,r.head,-1)||je(n,r.head,1)||r.head>0&&je(n,r.head-1,1)||r.head<n.doc.length&&je(n,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return x.cursor(l)});return i?(e(Ue(n,s)),!0):!1}const Km=({state:n,dispatch:e})=>qm(n,e);function Oe(n,e){let t=Qt(n.state.selection,i=>{let s=e(i);return x.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Ue(n.state,t)),!0)}function nc(n,e){return Oe(n,t=>n.moveByChar(t,e))}const sc=n=>nc(n,!ae(n)),rc=n=>nc(n,ae(n));function oc(n,e){return Oe(n,t=>n.moveByGroup(t,e))}const _m=n=>oc(n,!ae(n)),Jm=n=>oc(n,ae(n)),Um=n=>Oe(n,e=>ts(n.state,e,!ae(n))),Ym=n=>Oe(n,e=>ts(n.state,e,ae(n)));function lc(n,e){return Oe(n,t=>n.moveVertically(t,e))}const ac=n=>lc(n,!1),hc=n=>lc(n,!0);function cc(n,e){return Oe(n,t=>n.moveVertically(t,e,tc(n).height))}const dl=n=>cc(n,!1),pl=n=>cc(n,!0),Gm=n=>Oe(n,e=>mt(n,e,!0)),Xm=n=>Oe(n,e=>mt(n,e,!1)),Qm=n=>Oe(n,e=>mt(n,e,!ae(n))),Zm=n=>Oe(n,e=>mt(n,e,ae(n))),eg=n=>Oe(n,e=>x.cursor(n.lineBlockAt(e.head).from)),tg=n=>Oe(n,e=>x.cursor(n.lineBlockAt(e.head).to)),ml=({state:n,dispatch:e})=>(e(Ue(n,{anchor:0})),!0),gl=({state:n,dispatch:e})=>(e(Ue(n,{anchor:n.doc.length})),!0),yl=({state:n,dispatch:e})=>(e(Ue(n,{anchor:n.selection.main.anchor,head:0})),!0),bl=({state:n,dispatch:e})=>(e(Ue(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),ig=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),ng=({state:n,dispatch:e})=>{let t=is(n).map(({from:i,to:s})=>x.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:x.create(t),userEvent:"select"})),!0},sg=({state:n,dispatch:e})=>{let t=Qt(n.selection,i=>{let s=j(n),r=s.resolveStack(i.from,1);if(i.empty){let o=s.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return x.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ue(n,t)),!0)},rg=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=x.create([t.main]):t.main.empty||(i=x.create([x.cursor(t.main.head)])),i?(e(Ue(n,i)),!0):!1};function Vi(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=nn(n,a,!1)):a>o&&(t="delete.forward",a=nn(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=nn(n,o,!1),l=nn(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:x.cursor(o,o<r.head?-1:1)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?w.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function nn(n,e,t){if(n instanceof w)for(let i of n.state.facet(w.atomicRanges).map(s=>s(n)))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}const fc=(n,e,t)=>Vi(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let c=Yt(l,r.tabSize),h=c%Pn(r)||Pn(r);for(let f=0;f<h&&l[l.length-1-f]==" ";f++)s--;a=s}else a=re(o.text,s-o.from,e,e)+o.from,a==s&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,s-o.from))&&(a=re(o.text,a-o.from,!1,!1)+o.from);return a}),mr=n=>fc(n,!1,!0),uc=n=>fc(n,!0,!1),dc=(n,e)=>Vi(n,t=>{let i=t.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=re(r.text,i-r.from,e)+r.from,c=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),h=o(c);if(l!=null&&h!=l)break;(c!=" "||i!=t.head)&&(l=h),i=a}return i}),pc=n=>dc(n,!1),og=n=>dc(n,!0),lg=n=>Vi(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),ag=n=>Vi(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),hg=n=>Vi(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),cg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:B.of(["",""])},range:x.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},fg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:re(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:re(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:x.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function is(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function mc(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of is(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(x.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(x.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:x.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const ug=({state:n,dispatch:e})=>mc(n,e,!1),dg=({state:n,dispatch:e})=>mc(n,e,!0);function gc(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of is(n))t?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});return e(n.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const pg=({state:n,dispatch:e})=>gc(n,e,!1),mg=({state:n,dispatch:e})=>gc(n,e,!0),gg=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(is(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=Qt(e.selection,s=>{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function yg(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=j(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(Me.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const xl=yc(!1),bg=yc(!0);function yc(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&yg(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let c=new Un(e,{simulateBreak:r,simulateDoubleBreak:!!a}),h=Hr(c,r);for(h==null&&(h=Yt(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",Mi(e,h)];return a&&f.push(Mi(e,c.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:B.of(f)},range:x.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function qr(n,e){let t=-1;return n.changeByRange(i=>{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:x.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const xg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Un(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=qr(n,(r,o,l)=>{let a=Hr(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let c=/^\s*/.exec(r.text)[0],h=Mi(n,a);(c!=h||l.from<r.from+c.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+c.length,insert:h}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},bc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(qr(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Xt)})}),{userEvent:"input.indent"})),!0),xc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(qr(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=Yt(s,n.tabSize),o=0,l=Mi(n,Math.max(0,r-Pn(n)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),vg=n=>(n.setTabFocusMode(),!0),wg=[{key:"Ctrl-b",run:Yh,shift:sc,preventDefault:!0},{key:"Ctrl-f",run:Gh,shift:rc},{key:"Ctrl-p",run:Zh,shift:ac},{key:"Ctrl-n",run:ec,shift:hc},{key:"Ctrl-a",run:zm,shift:eg},{key:"Ctrl-e",run:jm,shift:tg},{key:"Ctrl-d",run:uc},{key:"Ctrl-h",run:mr},{key:"Ctrl-k",run:lg},{key:"Ctrl-Alt-h",run:pc},{key:"Ctrl-o",run:cg},{key:"Ctrl-t",run:fg},{key:"Ctrl-v",run:pr}],Sg=[{key:"ArrowLeft",run:Yh,shift:sc,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Rm,shift:_m,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Wm,shift:Qm,preventDefault:!0},{key:"ArrowRight",run:Gh,shift:rc,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Lm,shift:Jm,preventDefault:!0},{mac:"Cmd-ArrowRight",run:$m,shift:Zm,preventDefault:!0},{key:"ArrowUp",run:Zh,shift:ac,preventDefault:!0},{mac:"Cmd-ArrowUp",run:ml,shift:yl},{mac:"Ctrl-ArrowUp",run:ul,shift:dl},{key:"ArrowDown",run:ec,shift:hc,preventDefault:!0},{mac:"Cmd-ArrowDown",run:gl,shift:bl},{mac:"Ctrl-ArrowDown",run:pr,shift:pl},{key:"PageUp",run:ul,shift:dl},{key:"PageDown",run:pr,shift:pl},{key:"Home",run:Hm,shift:Xm,preventDefault:!0},{key:"Mod-Home",run:ml,shift:yl},{key:"End",run:Vm,shift:Gm,preventDefault:!0},{key:"Mod-End",run:gl,shift:bl},{key:"Enter",run:xl,shift:xl},{key:"Mod-a",run:ig},{key:"Backspace",run:mr,shift:mr},{key:"Delete",run:uc},{key:"Mod-Backspace",mac:"Alt-Backspace",run:pc},{key:"Mod-Delete",mac:"Alt-Delete",run:og},{mac:"Mod-Backspace",run:ag},{mac:"Mod-Delete",run:hg}].concat(wg.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),kg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Nm,shift:Um},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Fm,shift:Ym},{key:"Alt-ArrowUp",run:ug},{key:"Shift-Alt-ArrowUp",run:pg},{key:"Alt-ArrowDown",run:dg},{key:"Shift-Alt-ArrowDown",run:mg},{key:"Escape",run:rg},{key:"Mod-Enter",run:bg},{key:"Alt-l",mac:"Ctrl-l",run:ng},{key:"Mod-i",run:sg,preventDefault:!0},{key:"Mod-[",run:xc},{key:"Mod-]",run:bc},{key:"Mod-Alt-\\",run:xg},{key:"Shift-Mod-k",run:gg},{key:"Shift-Mod-\\",run:Km},{key:"Mod-/",run:pm},{key:"Alt-A",run:gm},{key:"Ctrl-m",mac:"Shift-Alt-m",run:vg}].concat(Sg),Cg={key:"Tab",run:bc,shift:xc},Bb=()=>n=>{try{JSON.parse(n.state.doc.toString())}catch(e){if(!(e instanceof SyntaxError))throw e;const t=Ag(e,n.state.doc);return[{from:t,message:e.message,severity:"error",to:t}]}return[]};function Ag(n,e){let t;return(t=n.message.match(/at position (\d+)/))?Math.min(+t[1],e.length):(t=n.message.match(/at line (\d+) column (\d+)/))?Math.min(e.line(+t[1]).from+ +t[2]-1,e.length):0}const Mg=Kt.define({name:"json",parser:Cf.configure({props:[Yn.add({Object:yi({except:/^\s*\}/}),Array:yi({except:/^\s*\]/})}),Gn.add({"Object Array":$r})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function Rb(){return new Vr(Mg)}class Tg{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class yt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let s=e,r=i.facet(Ke).markerFilter;r&&(s=r(s,i));let o=T.set(s.map(l=>l.from==l.to||l.from==l.to-1&&i.doc.lineAt(l.from).to==l.from?T.widget({widget:new Fg(l),diagnostic:l}).range(l.from):T.mark({attributes:{class:"cm-lintRange cm-lintRange-"+l.severity+(l.markClass?" "+l.markClass:"")},diagnostic:l}).range(l.from,l.to)),!0);return new yt(o,t,Jt(o))}}function Jt(n,e=null,t=0){let i=null;return n.between(t,1e9,(s,r,{spec:o})=>{if(!(e&&o.diagnostic!=e))return i=new Tg(s,r,o.diagnostic),!1}),i}function Og(n,e){let t=e.pos,i=e.end||t,s=n.state.facet(Ke).hideOn(n,t,i);if(s!=null)return s;let r=n.startState.doc.lineAt(e.pos);return!!(n.effects.some(o=>o.is(Kr))||n.changes.touchesRange(r.from,Math.max(r.to,i)))}function vc(n,e){return n.field(ve,!1)?e:e.concat(D.appendConfig.of(Cc))}function Dg(n,e){return{effects:vc(n,[Kr.of(e)])}}const Kr=D.define(),_r=D.define(),wc=D.define(),ve=Q.define({create(){return new yt(T.none,null,null)},update(n,e){if(e.docChanged&&n.diagnostics.size){let t=n.diagnostics.map(e.changes),i=null,s=n.panel;if(n.selected){let r=e.changes.mapPos(n.selected.from,1);i=Jt(t,n.selected.diagnostic,r)||Jt(t,null,r)}!t.size&&s&&e.state.facet(Ke).autoPanel&&(s=null),n=new yt(t,s,i)}for(let t of e.effects)if(t.is(Kr)){let i=e.state.facet(Ke).autoPanel?t.value.length?Ti.open:null:n.panel;n=yt.init(t.value,i,e.state)}else t.is(_r)?n=new yt(n.diagnostics,t.value?Ti.open:null,n.selected):t.is(wc)&&(n=new yt(n.diagnostics,n.panel,t.value));return n},provide:n=>[Ai.from(n,e=>e.panel),w.decorations.from(n,e=>e.diagnostics)]}),Eg=T.mark({class:"cm-lintRange cm-lintRange-active"});function Pg(n,e,t){let{diagnostics:i}=n.state.field(ve),s=[],r=2e8,o=0;i.between(e-(t<0?1:0),e+(t>0?1:0),(a,c,{spec:h})=>{e>=a&&e<=c&&(a==c||(e>a||t>0)&&(e<c||t<0))&&(s.push(h.diagnostic),r=Math.min(a,r),o=Math.max(c,o))});let l=n.state.facet(Ke).tooltipFilter;return l&&(s=l(s,n.state)),s.length?{pos:r,end:o,above:n.state.doc.lineAt(r).to<o,create(){return{dom:Bg(n,s)}}}:null}function Bg(n,e){return V("ul",{class:"cm-tooltip-lint"},e.map(t=>kc(n,t,!1)))}const Rg=n=>{let e=n.state.field(ve,!1);(!e||!e.panel)&&n.dispatch({effects:vc(n.state,[_r.of(!0)])});let t=Ci(n,Ti.open);return t&&t.dom.querySelector(".cm-panel-lint ul").focus(),!0},vl=n=>{let e=n.state.field(ve,!1);return!e||!e.panel?!1:(n.dispatch({effects:_r.of(!1)}),!0)},Lg=n=>{let e=n.state.field(ve,!1);if(!e)return!1;let t=n.state.selection.main,i=e.diagnostics.iter(t.to+1);return!i.value&&(i=e.diagnostics.iter(0),!i.value||i.from==t.from&&i.to==t.to)?!1:(n.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},Ig=[{key:"Mod-Shift-m",run:Rg,preventDefault:!0},{key:"F8",run:Lg}],Ng=_.fromClass(class{constructor(n){this.view=n,this.timeout=-1,this.set=!0;let{delay:e}=n.state.facet(Ke);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let n=Date.now();if(n<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-n);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(Ke);t.length&&Promise.all(t.map(i=>Promise.resolve(i(this.view)))).then(i=>{let s=i.reduce((r,o)=>r.concat(o));this.view.state.doc==e.doc&&this.view.dispatch(Dg(this.view.state,s))},i=>{he(this.view.state,i)})}}update(n){let e=n.state.facet(Ke);(n.docChanged||e!=n.startState.facet(Ke)||e.needsRefresh&&e.needsRefresh(n))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}}),Ke=A.define({combine(n){return Object.assign({sources:n.map(e=>e.source).filter(e=>e!=null)},Je(n.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t}))}});function Lb(n,e={}){return[Ke.of({source:n,config:e}),Ng,Cc]}function Sc(n){let e=[];if(n)e:for(let{name:t}of n){for(let i=0;i<t.length;i++){let s=t[i];if(/[a-zA-Z]/.test(s)&&!e.some(r=>r.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function kc(n,e,t){var i;let s=t?Sc(e.actions):[];return V("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},V("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(n):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=u=>{if(u.preventDefault(),l)return;l=!0;let d=Jt(n.state.field(ve).diagnostics,e);d&&r.apply(n,d.from,d.to)},{name:c}=r,h=s[o]?c.indexOf(s[o]):-1,f=h<0?c:[c.slice(0,h),V("u",c.slice(h,h+1)),c.slice(h+1)];return V("button",{type:"button",class:"cm-diagnosticAction",onclick:a,onmousedown:a,"aria-label":` Action: ${c}${h<0?"":` (access key "${s[o]})"`}.`},f)}),e.source&&V("div",{class:"cm-diagnosticSource"},e.source))}class Fg extends Fe{constructor(e){super(),this.diagnostic=e}eq(e){return e.diagnostic==this.diagnostic}toDOM(){return V("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class wl{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=kc(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Ti{constructor(e){this.view=e,this.items=[];let t=s=>{if(s.keyCode==27)vl(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=Sc(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==s.keyCode){let a=Jt(this.view.state.field(ve).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;s.preventDefault()},i=s=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(s.target)&&this.moveSelection(r)};this.list=V("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=V("div",{class:"cm-panel-lint"},this.list,V("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>vl(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(ve).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(ve),i=0,s=!1,r=null;for(e.between(0,this.view.state.doc.length,(o,l,{spec:a})=>{let c=-1,h;for(let f=i;f<this.items.length;f++)if(this.items[f].diagnostic==a.diagnostic){c=f;break}c<0?(h=new wl(this.view,a.diagnostic),this.items.splice(i,0,h),s=!0):(h=this.items[c],c>i&&(this.items.splice(i,c-i),s=!0)),t&&h.diagnostic==t.diagnostic?h.dom.hasAttribute("aria-selected")||(h.dom.setAttribute("aria-selected","true"),r=h):h.dom.hasAttribute("aria-selected")&&h.dom.removeAttribute("aria-selected"),i++});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new wl(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:o,panel:l})=>{let a=l.height/this.list.offsetHeight;o.top<l.top?this.list.scrollTop-=(l.top-o.top)/a:o.bottom>l.bottom&&(this.list.scrollTop+=(o.bottom-l.bottom)/a)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(ve),i=Jt(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:wc.of(i)})}static open(e){return new Ti(e)}}function Vg(n,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(n)}</svg>')`}function sn(n){return Vg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Hg=w.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:sn("#d11")},".cm-lintRange-warning":{backgroundImage:sn("orange")},".cm-lintRange-info":{backgroundImage:sn("#999")},".cm-lintRange-hint":{backgroundImage:sn("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}}),Cc=[ve,w.decorations.compute([ve],n=>{let{selected:e,panel:t}=n.field(ve);return!e||!t||e.from==e.to?T.none:T.set([Eg.range(e.from,e.to)])}),dp(Pg,{hideOn:Og}),Hg];var Ac=n=>{var{theme:e,settings:t={},styles:i=[]}=n,s={".cm-gutters":{}},r={};t.background&&(r.backgroundColor=t.background),t.backgroundImage&&(r.backgroundImage=t.backgroundImage),t.foreground&&(r.color=t.foreground),t.fontSize&&(r.fontSize=t.fontSize),(t.background||t.foreground)&&(s["&"]=r),t.fontFamily&&(s["&.cm-editor .cm-scroller"]={fontFamily:t.fontFamily}),t.gutterBackground&&(s[".cm-gutters"].backgroundColor=t.gutterBackground),t.gutterForeground&&(s[".cm-gutters"].color=t.gutterForeground),t.gutterBorder&&(s[".cm-gutters"].borderRightColor=t.gutterBorder),t.caret&&(s[".cm-content"]={caretColor:t.caret},s[".cm-cursor, .cm-dropCursor"]={borderLeftColor:t.caret});var o={};t.gutterActiveForeground&&(o.color=t.gutterActiveForeground),t.lineHighlight&&(s[".cm-activeLine"]={backgroundColor:t.lineHighlight},o.backgroundColor=t.lineHighlight),s[".cm-activeLineGutter"]=o,t.selection&&(s["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:t.selection+" !important"}),t.selectionMatch&&(s["& .cm-selectionMatch"]={backgroundColor:t.selectionMatch});var l=w.theme(s,{dark:e==="dark"}),a=At.define(i),c=[l,Qn(a)];return c},Wg={background:"#fff",foreground:"#24292e",selection:"#BBDFFF",selectionMatch:"#BBDFFF",gutterBackground:"#fff",gutterForeground:"#6e7781"},$g=[{tag:[m.standard(m.tagName),m.tagName],color:"#116329"},{tag:[m.comment,m.bracket],color:"#6a737d"},{tag:[m.className,m.propertyName],color:"#6f42c1"},{tag:[m.variableName,m.attributeName,m.number,m.operator],color:"#005cc5"},{tag:[m.keyword,m.typeName,m.typeOperator,m.typeName],color:"#d73a49"},{tag:[m.string,m.meta,m.regexp],color:"#032f62"},{tag:[m.name,m.quote],color:"#22863a"},{tag:[m.heading,m.strong],color:"#24292e",fontWeight:"bold"},{tag:[m.emphasis],color:"#24292e",fontStyle:"italic"},{tag:[m.deleted],color:"#b31d28",backgroundColor:"ffeef0"},{tag:[m.atom,m.bool,m.special(m.variableName)],color:"#e36209"},{tag:[m.url,m.escape,m.regexp,m.link],color:"#032f62"},{tag:m.link,textDecoration:"underline"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.invalid,color:"#cb2431"}],zg=n=>{var{theme:e="light",settings:t={},styles:i=[]}={};return Ac({theme:e,settings:Cr({},Wg,t),styles:[...$g,...i]})},Ib=zg(),jg={background:"#0d1117",foreground:"#c9d1d9",caret:"#c9d1d9",selection:"#003d73",selectionMatch:"#003d73",lineHighlight:"#36334280"},qg=[{tag:[m.standard(m.tagName),m.tagName],color:"#7ee787"},{tag:[m.comment,m.bracket],color:"#8b949e"},{tag:[m.className,m.propertyName],color:"#d2a8ff"},{tag:[m.variableName,m.attributeName,m.number,m.operator],color:"#79c0ff"},{tag:[m.keyword,m.typeName,m.typeOperator,m.typeName],color:"#ff7b72"},{tag:[m.string,m.meta,m.regexp],color:"#a5d6ff"},{tag:[m.name,m.quote],color:"#7ee787"},{tag:[m.heading,m.strong],color:"#d2a8ff",fontWeight:"bold"},{tag:[m.emphasis],color:"#d2a8ff",fontStyle:"italic"},{tag:[m.deleted],color:"#ffdcd7",backgroundColor:"ffeef0"},{tag:[m.atom,m.bool,m.special(m.variableName)],color:"#ffab70"},{tag:m.link,textDecoration:"underline"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.invalid,color:"#f97583"}],Kg=n=>{var{theme:e="dark",settings:t={},styles:i=[]}={};return Ac({theme:e,settings:Cr({},jg,t),styles:[...qg,...i]})};Kg();var _g=n=>{var{theme:e,settings:t={},styles:i=[]}=n,s={".cm-gutters":{}},r={};t.background&&(r.backgroundColor=t.background),t.backgroundImage&&(r.backgroundImage=t.backgroundImage),t.foreground&&(r.color=t.foreground),t.fontSize&&(r.fontSize=t.fontSize),(t.background||t.foreground)&&(s["&"]=r),t.fontFamily&&(s["&.cm-editor .cm-scroller"]={fontFamily:t.fontFamily}),t.gutterBackground&&(s[".cm-gutters"].backgroundColor=t.gutterBackground),t.gutterForeground&&(s[".cm-gutters"].color=t.gutterForeground),t.gutterBorder&&(s[".cm-gutters"].borderRightColor=t.gutterBorder),t.caret&&(s[".cm-content"]={caretColor:t.caret},s[".cm-cursor, .cm-dropCursor"]={borderLeftColor:t.caret});var o={};t.gutterActiveForeground&&(o.color=t.gutterActiveForeground),t.lineHighlight&&(s[".cm-activeLine"]={backgroundColor:t.lineHighlight},o.backgroundColor=t.lineHighlight),s[".cm-activeLineGutter"]=o,t.selection&&(s["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:t.selection+" !important"}),t.selectionMatch&&(s["& .cm-selectionMatch"]={backgroundColor:t.selectionMatch});var l=w.theme(s,{dark:e==="dark"}),a=At.define(i),c=[l,Qn(a)];return c},Jg={background:"#2e3440",foreground:"#FFFFFF",caret:"#FFFFFF",selection:"#00000073",selectionMatch:"#00000073",gutterBackground:"#2e3440",gutterForeground:"#4c566a",gutterActiveForeground:"#d8dee9",lineHighlight:"#4c566a29"},Ug=[{tag:m.keyword,color:"#5e81ac"},{tag:[m.name,m.deleted,m.character,m.propertyName,m.macroName],color:"#88c0d0"},{tag:[m.variableName],color:"#8fbcbb"},{tag:[m.function(m.variableName)],color:"#8fbcbb"},{tag:[m.labelName],color:"#81a1c1"},{tag:[m.color,m.constant(m.name),m.standard(m.name)],color:"#5e81ac"},{tag:[m.definition(m.name),m.separator],color:"#a3be8c"},{tag:[m.brace],color:"#8fbcbb"},{tag:[m.annotation],color:"#d30102"},{tag:[m.number,m.changed,m.annotation,m.modifier,m.self,m.namespace],color:"#b48ead"},{tag:[m.typeName,m.className],color:"#ebcb8b"},{tag:[m.operator,m.operatorKeyword],color:"#a3be8c"},{tag:[m.tagName],color:"#b48ead"},{tag:[m.squareBracket],color:"#bf616a"},{tag:[m.angleBracket],color:"#d08770"},{tag:[m.attributeName],color:"#ebcb8b"},{tag:[m.regexp],color:"#5e81ac"},{tag:[m.quote],color:"#b48ead"},{tag:[m.string],color:"#a3be8c"},{tag:m.link,color:"#a3be8c",textDecoration:"underline",textUnderlinePosition:"under"},{tag:[m.url,m.escape,m.special(m.string)],color:"#8fbcbb"},{tag:[m.meta],color:"#88c0d0"},{tag:[m.monospace],color:"#d8dee9",fontStyle:"italic"},{tag:[m.comment],color:"#4c566a",fontStyle:"italic"},{tag:m.strong,fontWeight:"bold",color:"#5e81ac"},{tag:m.emphasis,fontStyle:"italic",color:"#5e81ac"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.heading,fontWeight:"bold",color:"#5e81ac"},{tag:m.special(m.heading1),fontWeight:"bold",color:"#5e81ac"},{tag:m.heading1,fontWeight:"bold",color:"#5e81ac"},{tag:[m.heading2,m.heading3,m.heading4],fontWeight:"bold",color:"#5e81ac"},{tag:[m.heading5,m.heading6],color:"#5e81ac"},{tag:[m.atom,m.bool,m.special(m.variableName)],color:"#d08770"},{tag:[m.processingInstruction,m.inserted],color:"#8fbcbb"},{tag:[m.contentSeparator],color:"#ebcb8b"},{tag:m.invalid,color:"#434c5e",borderBottom:"1px dotted #d30102"}],Yg=n=>{var{theme:e="dark",settings:t={},styles:i=[]}={};return _g({theme:e,settings:Cr({},Jg,t),styles:[...Ug,...i]})},Nb=Yg();const Sl=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class Ut{constructor(e,t,i=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r(Sl(l)):Sl,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ne(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Ar(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=ke(e);let s=this.normalize(t);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==s.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t,i){let s=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:t,to:i}:this.matches.push(1,t)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Ut.prototype[Symbol.iterator]=function(){return this});const Mc={from:-1,to:-1,match:/.*/.exec("")},Jr="gm"+(/x/.unicode==null?"":"u");class Tc{constructor(e,t,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Mc,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Oc(e,t,i,s,r);this.re=new RegExp(t,Jr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=In(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=In(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Ss=new WeakMap;class Vt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=Ss.get(e);if(!s||s.from>=i||s.to<=t){let l=new Vt(t,e.sliceString(t,i));return Ss.set(e,l),l}if(s.from==t&&s.to==i)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to<i&&(r+=e.sliceString(s.to,i)),Ss.set(e,new Vt(o,r)),new Vt(t,r.slice(t-o,i-o))}}class Oc{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=Mc,this.matchPos=In(e,s),this.re=new RegExp(t,Jr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Vt.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,s=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this.matchPos=In(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Vt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Tc.prototype[Symbol.iterator]=Oc.prototype[Symbol.iterator]=function(){return this});function Gg(n){try{return new RegExp(n,Jr),!0}catch{return!1}}function In(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}function gr(n){let e=String(n.state.doc.lineAt(n.state.selection.main.head).number),t=V("input",{class:"cm-textfield",name:"line",value:e}),i=V("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),n.dispatch({effects:Nn.of(!1)}),n.focus()):r.keyCode==13&&(r.preventDefault(),s())},onsubmit:r=>{r.preventDefault(),s()}},V("label",n.state.phrase("Go to line"),": ",t)," ",V("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!r)return;let{state:o}=n,l=o.doc.lineAt(o.selection.main.head),[,a,c,h,f]=r,u=h?+h.slice(1):0,d=c?+c:l.number;if(c&&f){let y=d/100;a&&(y=y*(a=="-"?-1:1)+l.number/o.doc.lines),d=Math.round(o.doc.lines*y)}else c&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=o.doc.line(Math.max(1,Math.min(o.doc.lines,d))),g=x.cursor(p.from+Math.max(0,Math.min(u,p.length)));n.dispatch({effects:[Nn.of(!1),w.scrollIntoView(g.from,{y:"center"})],selection:g}),n.focus()}return{dom:i}}const Nn=D.define(),kl=Q.define({create(){return!0},update(n,e){for(let t of e.effects)t.is(Nn)&&(n=t.value);return n},provide:n=>Ai.from(n,e=>e?gr:null)}),Xg=n=>{let e=Ci(n,gr);if(!e){let t=[Nn.of(!0)];n.state.field(kl,!1)==null&&t.push(D.appendConfig.of([kl,Qg])),n.dispatch({effects:t}),e=Ci(n,gr)}return e&&e.dom.querySelector("input").select(),!0},Qg=w.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Zg={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},e0=A.define({combine(n){return Je(n,Zg,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function t0(n){return[o0,r0]}const i0=T.mark({class:"cm-selectionMatch"}),n0=T.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Cl(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=z.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=z.Word)}function s0(n,e,t,i){return n(e.sliceDoc(t,t+1))==z.Word&&n(e.sliceDoc(i-1,i))==z.Word}const r0=_.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(e0),{state:t}=n,i=t.selection;if(i.ranges.length>1)return T.none;let s=i.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return T.none;let a=t.wordAt(s.head);if(!a)return T.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<e.minSelectionLength||a>200)return T.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Cl(o,t,s.from,s.to)&&s0(o,t,s.from,s.to)))return T.none}else if(r=t.sliceDoc(s.from,s.to),!r)return T.none}let l=[];for(let a of n.visibleRanges){let c=new Ut(t.doc,r,a.from,a.to);for(;!c.next().done;){let{from:h,to:f}=c.value;if((!o||Cl(o,t,h,f))&&(s.empty&&h<=s.from&&f>=s.to?l.push(n0.range(h,f)):(h>=s.to||f<=s.from)&&l.push(i0.range(h,f)),l.length>e.maxMatches))return T.none}}return T.set(l)}},{decorations:n=>n.decorations}),o0=w.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),l0=({state:n,dispatch:e})=>{let{selection:t}=n,i=x.create(t.ranges.map(s=>n.wordAt(s.head)||x.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function a0(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new Ut(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Ut(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const h0=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return l0({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=a0(n,i);return s?(e(n.update({selection:n.selection.addRange(x.range(s.from,s.to),!1),effects:w.scrollIntoView(s.to)})),!0):!1},Zt=A.define({combine(n){return Je(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new w0(e),scrollToMatch:e=>w.scrollIntoView(e)})}});class Dc{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Gg(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
|
|
10
|
-
`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new d0(this):new f0(this)}getCursor(e,t=0,i){let s=e.doc?e:P.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Ot(this,s,t,i):Tt(this,s,t,i)}}class Ec{constructor(e){this.spec=e}}function Tt(n,e,t,i){return new Ut(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?c0(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function c0(n,e){return(t,i,s,r)=>((r>t||r+s.length<i)&&(r=Math.max(0,t-2),s=n.sliceString(r,Math.min(n.length,i+2))),(e(Fn(s,t-r))!=z.Word||e(Vn(s,t-r))!=z.Word)&&(e(Vn(s,i-r))!=z.Word||e(Fn(s,i-r))!=z.Word))}class f0 extends Ec{constructor(e){super(e)}nextMatch(e,t,i){let s=Tt(this.spec,e,i,e.doc.length).nextOverlapping();return s.done&&(s=Tt(this.spec,e,0,t).nextOverlapping()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let r=Math.max(t,s-1e4-this.spec.unquoted.length),o=Tt(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Tt(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Tt(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ot(n,e,t,i){return new Tc(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?u0(e.charCategorizer(e.selection.main.head)):void 0},t,i)}function Fn(n,e){return n.slice(re(n,e,!1),e)}function Vn(n,e){return n.slice(e,re(n,e))}function u0(n){return(e,t,i)=>!i[0].length||(n(Fn(i.input,i.index))!=z.Word||n(Vn(i.input,i.index))!=z.Word)&&(n(Vn(i.input,i.index+i[0].length))!=z.Word||n(Fn(i.input,i.index+i[0].length))!=z.Word)}class d0 extends Ec{nextMatch(e,t,i){let s=Ot(this.spec,e,i,e.doc.length).next();return s.done&&(s=Ot(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=1;;s++){let r=Math.max(t,i-s*1e4),o=Ot(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(t,i)=>i=="$"?"$":i=="&"?e.match[0]:i!="0"&&+i<e.match.length?e.match[i]:t)}matchAll(e,t){let i=Ot(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Ot(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const Oi=D.define(),Ur=D.define(),lt=Q.define({create(n){return new ks(yr(n).create(),null)},update(n,e){for(let t of e.effects)t.is(Oi)?n=new ks(t.value.create(),n.panel):t.is(Ur)&&(n=new ks(n.query,t.value?Yr:null));return n},provide:n=>Ai.from(n,e=>e.panel)});class ks{constructor(e,t){this.query=e,this.panel=t}}const p0=T.mark({class:"cm-searchMatch"}),m0=T.mark({class:"cm-searchMatch cm-searchMatch-selected"}),g0=_.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(lt))}update(n){let e=n.state.field(lt);(e!=n.startState.field(lt)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return T.none;let{view:t}=this,i=new ft;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-2*250;)a=r[++s].to;n.highlight(t.state,l,a,(c,h)=>{let f=t.state.selection.ranges.some(u=>u.from==c&&u.to==h);i.add(c,h,f?m0:p0)})}return i.finish()}},{decorations:n=>n.decorations});function Hi(n){return e=>{let t=e.state.field(lt,!1);return t&&t.query.spec.valid?n(e,t):Rc(e)}}const Hn=Hi((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let s=x.single(i.from,i.to),r=n.state.facet(Zt);return n.dispatch({selection:s,effects:[Gr(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),Bc(n),!0}),Wn=Hi((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,s=e.prevMatch(t,i,i);if(!s)return!1;let r=x.single(s.from,s.to),o=n.state.facet(Zt);return n.dispatch({selection:r,effects:[Gr(n,s),o.scrollToMatch(r.main,n)],userEvent:"select.search"}),Bc(n),!0}),y0=Hi((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:x.create(t.map(i=>x.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),b0=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:s}=t.main,r=[],o=0;for(let l=new Ut(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(x.range(l.value.from,l.value.to))}return e(n.update({selection:x.create(r,o),userEvent:"select.search.matches"})),!0},Al=Hi((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=[],l,a,c=[];if(r.from==i&&r.to==s&&(a=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=e.nextMatch(t,r.from,r.to),c.push(w.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))),r){let h=o.length==0||o[0].from>=r.to?0:r.to-r.from-a.length;l=x.single(r.from-h,r.to-h),c.push(Gr(n,r)),c.push(t.facet(Zt).scrollToMatch(l.main,n))}return n.dispatch({changes:o,selection:l,effects:c,userEvent:"input.replace"}),!0}),x0=Hi((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state,1e9).map(s=>{let{from:r,to:o}=s;return{from:r,to:o,insert:e.getReplacement(s)}});if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:w.announce.of(i),userEvent:"input.replace.all"}),!0});function Yr(n){return n.state.facet(Zt).createPanel(n)}function yr(n,e){var t,i,s,r,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let c=n.facet(Zt);return new Dc({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(s=e==null?void 0:e.literal)!==null&&s!==void 0?s:c.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:c.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function Pc(n){let e=Ci(n,Yr);return e&&e.dom.querySelector("[main-field]")}function Bc(n){let e=Pc(n);e&&e==n.root.activeElement&&e.select()}const Rc=n=>{let e=n.state.field(lt,!1);if(e&&e.panel){let t=Pc(n);if(t&&t!=n.root.activeElement){let i=yr(n.state,e.query.spec);i.valid&&n.dispatch({effects:Oi.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[Ur.of(!0),e?Oi.of(yr(n.state,e.query.spec)):D.appendConfig.of(k0)]});return!0},Lc=n=>{let e=n.state.field(lt,!1);if(!e||!e.panel)return!1;let t=Ci(n,Yr);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Ur.of(!1)}),!0},v0=[{key:"Mod-f",run:Rc,scope:"editor search-panel"},{key:"F3",run:Hn,shift:Wn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Hn,shift:Wn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Lc,scope:"editor search-panel"},{key:"Mod-Shift-l",run:b0},{key:"Mod-Alt-g",run:Xg},{key:"Mod-d",run:h0,preventDefault:!0}];class w0{constructor(e){this.view=e;let t=this.query=e.state.field(lt).query.spec;this.commit=this.commit.bind(this),this.searchField=V("input",{value:t.search,placeholder:ye(e,"Find"),"aria-label":ye(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=V("input",{value:t.replace,placeholder:ye(e,"Replace"),"aria-label":ye(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=V("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=V("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=V("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(s,r,o){return V("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=V("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>Hn(e),[ye(e,"next")]),i("prev",()=>Wn(e),[ye(e,"previous")]),i("select",()=>y0(e),[ye(e,"all")]),V("label",null,[this.caseField,ye(e,"match case")]),V("label",null,[this.reField,ye(e,"regexp")]),V("label",null,[this.wordField,ye(e,"by word")]),...e.state.readOnly?[]:[V("br"),this.replaceField,i("replace",()=>Al(e),[ye(e,"replace")]),i("replaceAll",()=>x0(e),[ye(e,"replace all")])],V("button",{name:"close",onclick:()=>Lc(e),"aria-label":ye(e,"close"),type:"button"},["×"])])}commit(){let e=new Dc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Oi.of(e)}))}keydown(e){Ad(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Wn:Hn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Al(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(Oi)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Zt).top}}function ye(n,e){return n.state.phrase(e)}const rn=30,on=/[\s\.,:;?!]/;function Gr(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),s=n.state.doc.lineAt(t).to,r=Math.max(i.from,e-rn),o=Math.min(s,t+rn),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<rn;a++)if(!on.test(l[a+1])&&on.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-rn;a--)if(!on.test(l[a-1])&&on.test(l[a])){l=l.slice(0,a);break}}return w.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const S0=w.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),k0=[lt,pt.low(g0),S0];class Ic{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=j(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),i=Math.max(t.from,this.pos-250),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(Fc(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t){e=="abort"&&this.abortListeners&&this.abortListeners.push(t)}}function Ml(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function C0(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let i=Ml(e)+Ml(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Xr(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:C0(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function Nc(n,e){return t=>{for(let i=j(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class Tl{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}}function at(n){return n.selection.main.from}function Fc(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const Vc=Ne.define();function A0(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return Object.assign(Object.assign({},n.changeByRange(l=>l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i)?{range:l}:{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:e},range:x.cursor(l.from+r+e.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const Ol=new WeakMap;function M0(n){if(!Array.isArray(n))return n;let e=Ol.get(n);return e||Ol.set(n,e=Xr(n)),e}const $n=D.define(),Di=D.define();class T0{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<e.length;){let i=ne(e,t),s=ke(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(ne(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,!0}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return!1;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let v=ne(e,0),M=ke(v),S=M==e.length?0:-100;if(v!=t[0])if(v==i[0])S+=-200;else return!1;return this.ret(S,[0,M])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,c=0;if(l<0){for(let v=0,M=Math.min(e.length,200);v<M&&c<a;){let S=ne(e,v);(S==t[c]||S==i[c])&&(s[c++]=v),v+=ke(S)}if(c<a)return!1}let h=0,f=0,u=!1,d=0,p=-1,g=-1,y=/[a-z]/.test(e),b=!0;for(let v=0,M=Math.min(e.length,200),S=0;v<M&&f<a;){let k=ne(e,v);l<0&&(h<a&&k==t[h]&&(r[h++]=v),d<a&&(k==t[d]||k==i[d]?(d==0&&(p=v),g=v+1,d++):d=0));let O,L=k<255?k>=48&&k<=57||k>=97&&k<=122?2:k>=65&&k<=90?1:0:(O=Ar(k))!=O.toLowerCase()?1:O!=O.toUpperCase()?2:0;(!v||L==1&&y||S==0&&L!=0)&&(t[f]==k||i[f]==k&&(u=!0)?o[f++]=v:o.length&&(b=!1)),S=L,v+=ke(k)}return f==a&&o[0]==0&&b?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(g==e.length?0:-100),[0,g]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,g]):f==a?this.result(-100+(u?-200:0)+-700+(b?0:-1100),o,e):t.length==2?!1:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?ke(ne(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}}const se=A.define({combine(n){return Je(n,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:O0,compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>Dl(e(i),t(i)),optionClass:(e,t)=>i=>Dl(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})}});function Dl(n,e){return n?e?n+" "+e:n:e}function O0(n,e,t,i,s,r){let o=n.textDirection==W.RTL,l=o,a=!1,c="top",h,f,u=e.left-s.left,d=s.right-e.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))h=Math.max(s.top,Math.min(t.top,s.bottom-g))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:s.right-e.left)-30);let v=s.bottom-e.bottom;v>=g||v>e.top?h=t.bottom-e.top:(c="bottom",h=e.bottom-t.top)}let y=(e.bottom-e.top)/r.offsetHeight,b=(e.right-e.left)/r.offsetWidth;return{style:`${c}: ${h/y}px; max-width: ${f/b}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function D0(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let c=0;c<r.length;){let h=r[c++],f=r[c++];h>a&&o.appendChild(document.createTextNode(l.slice(a,h)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(h,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function Cs(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class E0{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(se);this.optionContent=D0(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=Cs(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:c}=e.state.field(t).open;for(let h=a.target,f;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(f=/-(\d+)$/.exec(h.id))&&+f[1]<c.length){this.applyCompletion(e,c[+f[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let c=e.state.field(this.stateField,!1);c&&c.tooltip&&e.state.facet(se).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Di.of(null)})}),this.showOptions(r,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 i=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=Cs(r.length,o,e.state.facet(se).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=s.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);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;if((t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Cs(t.options.length,t.selected,this.view.state.facet(se).maxRenderedOptions),this.showOptions(t.options,e.id)),this.updateSelectedOption(t.selected)){this.destroyInfo();let{completion:i}=t.options[t.selected],{info:s}=i;if(!s)return;let r=typeof s=="string"?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,i)}).catch(o=>he(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return t&&B0(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return s.top>Math.min(r.bottom,t.bottom)-10||s.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(se).positionInfo(this.view,t,s,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:c}=l;if(c){let u=typeof c=="string"?c:c.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof c!="string"&&c.header)s.appendChild(c.header(c));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=u}}const h=s.appendChild(document.createElement("li"));h.id=t+"-"+o,h.setAttribute("role","option");let f=this.optionClass(l);f&&(h.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function P0(n,e){return t=>new E0(t,n,e)}function B0(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),s=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/s:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/s)}function El(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function R0(n,e){let t=[],i=null,s=a=>{t.push(a);let{section:c}=a.completion;if(c){i||(i=[]);let h=typeof c=="string"?c:c.name;i.some(f=>f.name==h)||i.push(typeof c=="string"?{name:h}:c)}};for(let a of n)if(a.hasResult()){let c=a.result.getMatch;if(a.result.filter===!1)for(let h of a.result.options)s(new Tl(h,a.source,c?c(h):[],1e9-t.length));else{let h=new T0(e.sliceDoc(a.from,a.to));for(let f of a.result.options)if(h.match(f.label)){let u=f.displayLabel?c?c(f,h.matched):[]:h.matched;s(new Tl(f,a.source,u,h.score+(f.boost||0)))}}}if(i){let a=Object.create(null),c=0,h=(f,u)=>{var d,p;return((d=f.rank)!==null&&d!==void 0?d:1e9)-((p=u.rank)!==null&&p!==void 0?p:1e9)||(f.name<u.name?-1:1)};for(let f of i.sort(h))c-=1e5,a[f.name]=c;for(let f of t){let{section:u}=f.completion;u&&(f.score+=a[typeof u=="string"?u:u.name])}}let r=[],o=null,l=e.facet(se).compareCompletions;for(let a of t.sort((c,h)=>h.score-c.score||l(c.completion,h.completion))){let c=a.completion;!o||o.label!=c.label||o.detail!=c.detail||o.type!=null&&c.type!=null&&o.type!=c.type||o.apply!=c.apply||o.boost!=c.boost?r.push(a):El(a.completion)>El(o)&&(r[r.length-1]=a),o=a.completion}return r}class Rt{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Rt(this.options,Pl(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r){let o=R0(e,t);if(!o.length)return s&&e.some(a=>a.state==1)?new Rt(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let l=t.facet(se).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let a=s.options[s.selected].completion;for(let c=0;c<o.length;c++)if(o[c].completion==a){l=c;break}}return new Rt(o,Pl(i,l),{pos:e.reduce((a,c)=>c.hasResult()?Math.min(a,c.from):a,1e8),create:V0,above:r.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(e){return new Rt(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class zn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new zn(N0,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(se),r=(i.override||t.languageDataAt("autocomplete",at(t)).map(M0)).map(l=>(this.active.find(c=>c.source==l)||new me(l,this.active.some(c=>c.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!L0(r,this.active)?o=Rt.build(r,t,this.id,o,i):o&&o.disabled&&!r.some(l=>l.state==1)&&(o=null),!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new me(l.source,0):l));for(let l of e.effects)l.is(Wc)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new zn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:I0}}function L0(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult;)t++;for(;i<e.length&&!e[i].hasResult;)i++;let s=t==n.length,r=i==e.length;if(s||r)return s==r;if(n[t++].result!=e[i++].result)return!1}}const I0={"aria-autocomplete":"list"};function Pl(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const N0=[];function br(n){return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}class me{constructor(e,t,i=-1){this.source=e,this.state=t,this.explicitPos=i}hasResult(){return!1}update(e,t){let i=br(e),s=this;i?s=s.handleUserEvent(e,i,t):e.docChanged?s=s.handleChange(e):e.selection&&s.state!=0&&(s=new me(s.source,0));for(let r of e.effects)if(r.is($n))s=new me(s.source,1,r.value?at(e.state):-1);else if(r.is(Di))s=new me(s.source,0);else if(r.is(Hc))for(let o of r.value)o.source==s.source&&(s=o);return s}handleUserEvent(e,t,i){return t=="delete"||!i.activateOnTyping?this.map(e.changes):new me(this.source,1)}handleChange(e){return e.changes.touchesRange(at(e.startState))?new me(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new me(this.source,this.state,e.mapPos(this.explicitPos))}}class Ht extends me{constructor(e,t,i,s,r){super(e,2,t),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(e,t,i){var s;let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=at(e.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||t=="delete"&&at(e.startState)==this.from)return new me(this.source,t=="input"&&i.activateOnTyping?1:0);let a=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos),c;return F0(this.result.validFor,e.state,r,o)?new Ht(this.source,a,this.result,r,o):this.result.update&&(c=this.result.update(this.result,r,o,new Ic(e.state,l,a>=0)))?new Ht(this.source,a,c,c.from,(s=c.to)!==null&&s!==void 0?s:at(e.state)):new me(this.source,1,a)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new me(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new Ht(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1))}}function F0(n,e,t,i){if(!n)return!1;let s=e.sliceDoc(t,i);return typeof n=="function"?n(s,t,i,e):Fc(n,!0).test(s)}const Hc=D.define({map(n,e){return n.map(t=>t.map(e))}}),Wc=D.define(),xe=Q.define({create(){return zn.start()},update(n,e){return n.update(e)},provide:n=>[Nr.from(n,e=>e.tooltip),w.contentAttributes.from(n,e=>e.attrs)]});function $c(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(xe).active.find(s=>s.source==e.source);return i instanceof Ht?(typeof t=="string"?n.dispatch(Object.assign(Object.assign({},A0(n.state,t,i.from,i.to)),{annotations:Vc.of(e.completion)})):t(n,e.completion,i.from,i.to),!0):!1}const V0=P0(xe,$c);function ln(n,e="option"){return t=>{let i=t.state.field(xe,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(se).interactionDelay)return!1;let s=1,r;e=="page"&&(r=kh(t,i.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+s*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Wc.of(l)}),!0}}const H0=n=>{let e=n.state.field(xe,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(se).interactionDelay?!1:$c(n,e.open.options[e.open.selected])},W0=n=>n.state.field(xe,!1)?(n.dispatch({effects:$n.of(!0)}),!0):!1,$0=n=>{let e=n.state.field(xe,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Di.of(null)}),!0)};class z0{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const j0=50,q0=1e3,K0=_.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(xe).active)e.state==1&&this.startQuery(e)}update(n){let e=n.state.field(xe);if(!n.selectionSet&&!n.docChanged&&n.startState.field(xe)==e)return;let t=n.transactions.some(s=>(s.selection||s.docChanged)&&!br(s));for(let s=0;s<this.running.length;s++){let r=this.running[s];if(t||r.updates.length+n.transactions.length>j0&&Date.now()-r.time>q0){for(let o of r.context.abortListeners)try{o()}catch(l){he(this.view.state,l)}r.context.abortListeners=null,this.running.splice(s--,1)}else r.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(r=>r.is($n)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.state.facet(se).activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.state==1&&!this.running.some(r=>r.active.source==s.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let s of n.transactions)br(s)=="input"?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,e=n.field(xe);for(let t of e.active)t.state==1&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t)}startQuery(n){let{state:e}=this.view,t=at(e),i=new Ic(e,t,n.explicitPos==t),s=new z0(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Di.of(null)}),he(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(se).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(se);for(let i=0;i<this.running.length;i++){let s=this.running[i];if(s.done===void 0)continue;if(this.running.splice(i--,1),s.done){let o=new Ht(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:at(s.updates.length?s.updates[0].startState:this.view.state));for(let l of s.updates)o=o.update(l,t);if(o.hasResult()){e.push(o);continue}}let r=this.view.state.field(xe).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new me(s.active.source,0);for(let l of s.updates)o=o.update(l,t);o.state!=1&&e.push(o)}else this.startQuery(r)}e.length&&this.view.dispatch({effects:Hc.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(xe,!1);if(e&&e.tooltip&&this.view.state.facet(se).closeOnBlur){let t=e.open&&kh(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Di.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:$n.of(!1)}),20),this.composing=0}}}),zc=w.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"},".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"}}});let _0=class{constructor(e,t,i,s){this.field=e,this.line=t,this.from=i,this.to=s}},J0=class jc{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,te.TrackDel),i=e.mapPos(this.to,1,te.TrackDel);return t==null||i==null?null:new jc(this.field,t,i)}},U0=class qc{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let f=0;f<h;f++)c+=e.facet(Xt);s.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new J0(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",c=-1;for(let h=0;h<t.length;h++)(l!=null?t[h].seq==l:a&&t[h].name==a)&&(c=h);if(c<0){let h=0;for(;h<t.length&&(l==null||t[h].seq!=null&&t[h].seq<l);)h++;t.splice(h,0,{seq:l,name:a}),c=h;for(let f of s)f.field>=c&&f.field++}s.push(new _0(c,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of s)a.line==i.length&&a.from>l.index&&(a.from--,a.to--)}i.push(o)}return new qc(i,s)}},Y0=T.widget({widget:new class extends Fe{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),G0=T.mark({class:"cm-snippetField"}),ns=class Kc{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(i=>(i.from==i.to?Y0:G0).range(i.from,i.to)))}map(e){let t=[];for(let i of this.ranges){let s=i.map(e);if(!s)return null;t.push(s)}return new Kc(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}};const Wi=D.define({map(n,e){return n&&n.map(e)}}),X0=D.define(),Ei=Q.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(Wi))return t.value;if(t.is(X0)&&n)return new ns(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>w.decorations.from(n,e=>e?e.deco:T.none)});function Qr(n,e){return x.create(n.filter(t=>t.field==e).map(t=>x.range(t.from,t.to)))}function Q0(n){let e=U0.parse(n);return(t,i,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),a={changes:{from:s,to:r,insert:B.of(o)},scrollIntoView:!0,annotations:i?[Vc.of(i),Y.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=Qr(l,0)),l.some(c=>c.field>0)){let c=new ns(l,0),h=a.effects=[Wi.of(c)];t.state.field(Ei,!1)===void 0&&h.push(D.appendConfig.of([Ei,ny,sy,zc]))}t.dispatch(t.state.update(a))}}function _c(n){return({state:e,dispatch:t})=>{let i=e.field(Ei,!1);if(!i||n<0&&i.active==0)return!1;let s=i.active+n,r=n>0&&!i.ranges.some(o=>o.field==s+n);return t(e.update({selection:Qr(i.ranges,s),effects:Wi.of(r?null:new ns(i.ranges,s)),scrollIntoView:!0})),!0}}const Z0=({state:n,dispatch:e})=>n.field(Ei,!1)?(e(n.update({effects:Wi.of(null)})),!0):!1,ey=_c(1),ty=_c(-1),iy=[{key:"Tab",run:ey,shift:ty},{key:"Escape",run:Z0}],Bl=A.define({combine(n){return n.length?n[0]:iy}}),ny=pt.highest(Gt.compute([Bl],n=>n.facet(Bl)));function q(n,e){return Object.assign(Object.assign({},e),{apply:Q0(n)})}const sy=w.domEventHandlers({mousedown(n,e){let t=e.state.field(Ei,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=t.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==t.active?!1:(e.dispatch({selection:Qr(t.ranges,s.field),effects:Wi.of(t.ranges.some(r=>r.field>s.field)?new ns(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Pi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},xt=D.define({map(n,e){let t=e.mapPos(n,-1,te.TrackAfter);return t??void 0}}),Zr=new class extends ct{};Zr.startSide=1;Zr.endSide=-1;const Jc=Q.define({create(){return R.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(xt)&&(n=n.update({add:[Zr.range(t.value,t.value+1)]}));return n}});function ry(){return[ly,Jc]}const As="()[]{}<>";function Uc(n){for(let e=0;e<As.length;e+=2)if(As.charCodeAt(e)==n)return As.charAt(e+1);return Ar(n<128?n:n+1)}function Yc(n,e){return n.languageDataAt("closeBrackets",e)[0]||Pi}const oy=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),ly=w.inputHandler.of((n,e,t,i)=>{if((oy?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&ke(ne(i,0))==1||e!=s.from||t!=s.to)return!1;let r=cy(n.state,i);return r?(n.dispatch(r),!0):!1}),ay=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=Yc(n,n.selection.main.head).brackets||Pi.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=fy(n.doc,o.head);for(let a of i)if(a==l&&ss(n.doc,o.head)==Uc(ne(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:x.cursor(o.head-a.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},hy=[{key:"Backspace",run:ay}];function cy(n,e){let t=Yc(n,n.selection.main.head),i=t.brackets||Pi.brackets;for(let s of i){let r=Uc(ne(s,0));if(e==s)return r==s?py(n,s,i.indexOf(s+s+s)>-1,t):uy(n,s,r,t.before||Pi.before);if(e==r&&Gc(n,n.selection.main.from))return dy(n,s,r)}return null}function Gc(n,e){let t=!1;return n.field(Jc).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function ss(n,e){let t=n.sliceString(e,e+2);return t.slice(0,ke(ne(t,0)))}function fy(n,e){let t=n.sliceString(e-2,e);return ke(ne(t,0))==t.length?t:t.slice(1)}function uy(n,e,t,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:xt.of(o.to+e.length),range:x.range(o.anchor+e.length,o.head+e.length)};let l=ss(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:xt.of(o.head+e.length),range:x.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function dy(n,e,t){let i=null,s=n.changeByRange(r=>r.empty&&ss(n.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:x.cursor(r.head+t.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function py(n,e,t,i){let s=i.stringPrefixes||Pi.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:xt.of(l.to+e.length),range:x.range(l.anchor+e.length,l.head+e.length)};let a=l.head,c=ss(n.doc,a),h;if(c==e){if(Rl(n,a))return{changes:{insert:e+e,from:a},effects:xt.of(a+e.length),range:x.cursor(a+e.length)};if(Gc(n,a)){let u=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:x.cursor(a+u.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(h=Ll(n,a-2*e.length,s))>-1&&Rl(n,h))return{changes:{insert:e+e+e+e,from:a},effects:xt.of(a+e.length),range:x.cursor(a+e.length)};if(n.charCategorizer(a)(c)!=z.Word&&Ll(n,a,s)>-1&&!my(n,a,e,s))return{changes:{insert:e+e,from:a},effects:xt.of(a+e.length),range:x.cursor(a+e.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Rl(n,e){let t=j(n).resolveInner(e+1);return t.parent&&t.from==e}function my(n,e,t,i){let s=j(n).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=s.firstChild;for(;h&&h.from==s.from&&h.to-h.from>t.length+a;){if(n.sliceDoc(h.to-t.length,h.to)==t)return!1;h=h.firstChild}return!0}let c=s.to==e&&s.parent;if(!c)break;s=c}return!1}function Ll(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=z.Word)return e;for(let s of t){let r=e-s.length;if(n.sliceDoc(r,e)==s&&i(n.sliceDoc(r-1,r))!=z.Word)return r}return-1}function gy(n={}){return[xe,se.of(n),K0,yy,zc]}const Xc=[{key:"Ctrl-Space",run:W0},{key:"Escape",run:$0},{key:"ArrowDown",run:ln(!0)},{key:"ArrowUp",run:ln(!1)},{key:"PageDown",run:ln(!0,"page")},{key:"PageUp",run:ln(!1,"page")},{key:"Enter",run:H0}],yy=pt.highest(Gt.computeN([se],n=>n.facet(se).defaultKeymap?[Xc]:[]));var Il=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,i=[];e.closeBracketsKeymap!==!1&&(i=i.concat(hy)),e.defaultKeymap!==!1&&(i=i.concat(kg)),e.searchKeymap!==!1&&(i=i.concat(v0)),e.historyKeymap!==!1&&(i=i.concat(Bm)),e.foldKeymap!==!1&&(i=i.concat(_p)),e.completionKeymap!==!1&&(i=i.concat(Xc)),e.lintKeymap!==!1&&(i=i.concat(Ig));var s=[];return e.lineNumbers!==!1&&s.push(Sp()),e.highlightActiveLineGutter!==!1&&s.push(Ap()),e.highlightSpecialChars!==!1&&s.push(zd()),e.history!==!1&&s.push(km()),e.foldGutter!==!1&&s.push(Gp()),e.drawSelection!==!1&&s.push(Pd()),e.dropCursor!==!1&&s.push(Nd()),e.allowMultipleSelections!==!1&&s.push(P.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&s.push(Fp()),e.syntaxHighlighting!==!1&&s.push(Qn(em,{fallback:!0})),e.bracketMatching!==!1&&s.push(lm()),e.closeBrackets!==!1&&s.push(ry()),e.autocompletion!==!1&&s.push(gy()),e.rectangularSelection!==!1&&s.push(ip()),t!==!1&&s.push(rp()),e.highlightActiveLine!==!1&&s.push(Ud()),e.highlightSelectionMatches!==!1&&s.push(t0()),e.tabSize&&typeof e.tabSize=="number"&&s.push(Xt.of(" ".repeat(e.tabSize))),s.concat([Gt.of(i.flat())]).filter(Boolean)};const by="#e5c07b",Nl="#e06c75",xy="#56b6c2",vy="#ffffff",vn="#abb2bf",xr="#7d8799",wy="#61afef",Sy="#98c379",Fl="#d19a66",ky="#c678dd",Cy="#21252b",Vl="#2c313a",Hl="#282c34",Ms="#353a42",Ay="#3E4451",Wl="#528bff",My=w.theme({"&":{color:vn,backgroundColor:Hl},".cm-content":{caretColor:Wl},".cm-cursor, .cm-dropCursor":{borderLeftColor:Wl},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Ay},".cm-panels":{backgroundColor:Cy,color:vn},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:Hl,color:xr,border:"none"},".cm-activeLineGutter":{backgroundColor:Vl},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Ms},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Ms,borderBottomColor:Ms},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:Vl,color:vn}}},{dark:!0}),Ty=At.define([{tag:m.keyword,color:ky},{tag:[m.name,m.deleted,m.character,m.propertyName,m.macroName],color:Nl},{tag:[m.function(m.variableName),m.labelName],color:wy},{tag:[m.color,m.constant(m.name),m.standard(m.name)],color:Fl},{tag:[m.definition(m.name),m.separator],color:vn},{tag:[m.typeName,m.className,m.number,m.changed,m.annotation,m.modifier,m.self,m.namespace],color:by},{tag:[m.operator,m.operatorKeyword,m.url,m.escape,m.regexp,m.link,m.special(m.string)],color:xy},{tag:[m.meta,m.comment],color:xr},{tag:m.strong,fontWeight:"bold"},{tag:m.emphasis,fontStyle:"italic"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.link,color:xr,textDecoration:"underline"},{tag:m.heading,fontWeight:"bold",color:Nl},{tag:[m.atom,m.bool,m.special(m.variableName)],color:Fl},{tag:[m.processingInstruction,m.string,m.inserted],color:Sy},{tag:m.invalid,color:vy}]),Oy=[My,Qn(Ty)];var Dy=w.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),Ey=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:i=!0,readOnly:s=!1,theme:r="light",placeholder:o="",basicSetup:l=!0}=e,a=[];switch(t&&a.unshift(Gt.of([Cg])),l&&(typeof l=="boolean"?a.unshift(Il()):a.unshift(Il(l))),o&&a.unshift(Qd(o)),r){case"light":a.push(Dy);break;case"dark":a.push(Oy);break;case"none":break;default:a.push(r);break}return i===!1&&a.push(w.editable.of(!1)),s&&a.push(P.readOnly.of(!0)),[...a]},Py=n=>({line:n.state.doc.lineAt(n.state.selection.main.from),lineCount:n.state.doc.lines,lineBreak:n.state.lineBreak,length:n.state.doc.length,readOnly:n.state.readOnly,tabSize:n.state.tabSize,selection:n.state.selection,selectionAsSingle:n.state.selection.asSingle().main,ranges:n.state.selection.ranges,selectionCode:n.state.sliceDoc(n.state.selection.main.from,n.state.selection.main.to),selections:n.state.selection.ranges.map(e=>n.state.sliceDoc(e.from,e.to)),selectedText:n.state.selection.ranges.some(e=>!e.empty)}),$l=Ne.define(),By=[];function Ry(n){var{value:e,selection:t,onChange:i,onStatistics:s,onCreateEditor:r,onUpdate:o,extensions:l=By,autoFocus:a,theme:c="light",height:h=null,minHeight:f=null,maxHeight:u=null,width:d=null,minWidth:p=null,maxWidth:g=null,placeholder:y="",editable:b=!0,readOnly:v=!1,indentWithTab:M=!0,basicSetup:S=!0,root:k,initialState:O}=n,[L,K]=Se.useState(),[I,ue]=Se.useState(),[Ye,De]=Se.useState(),tt=w.theme({"&":{height:h,minHeight:f,maxHeight:u,width:d,minWidth:p,maxWidth:g},"& .cm-scroller":{height:"100% !important"}}),Ee=w.updateListener.of(Z=>{if(Z.docChanged&&typeof i=="function"&&!Z.transactions.some(Be=>Be.annotation($l))){var Pe=Z.state.doc,de=Pe.toString();i(de,Z)}s&&s(Py(Z))}),He=Ey({theme:c,editable:b,readOnly:v,placeholder:y,indentWithTab:M,basicSetup:S}),we=[Ee,tt,...He];return o&&typeof o=="function"&&we.push(w.updateListener.of(o)),we=we.concat(l),Se.useEffect(()=>{if(L&&!Ye){var Z={doc:e,selection:t,extensions:we},Pe=O?P.fromJSON(O.json,Z,O.fields):P.create(Z);if(De(Pe),!I){var de=new w({state:Pe,parent:L,root:k});ue(de),r&&r(de,Pe)}}return()=>{I&&(De(void 0),ue(void 0))}},[L,Ye]),Se.useEffect(()=>K(n.container),[n.container]),Se.useEffect(()=>()=>{I&&(I.destroy(),ue(void 0))},[I]),Se.useEffect(()=>{a&&I&&I.focus()},[a,I]),Se.useEffect(()=>{I&&I.dispatch({effects:D.reconfigure.of(we)})},[c,l,h,f,u,d,p,g,y,b,v,M,S,i,o]),Se.useEffect(()=>{if(e!==void 0){var Z=I?I.state.doc.toString():"";I&&e!==Z&&I.dispatch({changes:{from:0,to:Z.length,insert:e||""},annotations:[$l.of(!0)]})}},[e,I]),{state:Ye,setState:De,view:I,setView:ue,container:L,setContainer:K}}var Ly=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],Iy=Se.forwardRef((n,e)=>{var{className:t,value:i="",selection:s,extensions:r=[],onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:c,autoFocus:h,theme:f="light",height:u,minHeight:d,maxHeight:p,width:g,minWidth:y,maxWidth:b,basicSetup:v,placeholder:M,indentWithTab:S,editable:k,readOnly:O,root:L,initialState:K}=n,I=Af(n,Ly),ue=Se.useRef(null),{state:Ye,view:De,container:tt}=Ry({container:ue.current,root:L,value:i,autoFocus:h,theme:f,height:u,minHeight:d,maxHeight:p,width:g,minWidth:y,maxWidth:b,basicSetup:v,placeholder:M,indentWithTab:S,editable:k,readOnly:O,selection:s,onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:c,extensions:r,initialState:K});if(Se.useImperativeHandle(e,()=>({editor:ue.current,state:Ye,view:De}),[ue,tt,Ye,De]),typeof i!="string")throw new Error("value must be typeof string but got "+typeof i);var Ee=typeof f=="string"?"cm-theme-"+f:"cm-theme";return Mf.jsx("div",Tf({ref:ue,className:""+Ee+(t?" "+t:"")},I))});Iy.displayName="CodeMirror";const Ny=Ne.define(),Fy=w.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 Vy{constructor(e,t,i,s){this.field=e,this.line=t,this.from=i,this.to=s}}class eo{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,te.TrackDel),i=e.mapPos(this.to,1,te.TrackDel);return t==null||i==null?null:new eo(this.field,t,i)}}class to{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let f=0;f<h;f++)c+=e.facet(Xt);s.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new eo(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",c=-1,h=a.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<t.length;f++)(l!=null?t[f].seq==l:h&&t[f].name==h)&&(c=f);if(c<0){let f=0;for(;f<t.length&&(l==null||t[f].seq!=null&&t[f].seq<l);)f++;t.splice(f,0,{seq:l,name:h}),c=f;for(let u of s)u.field>=c&&u.field++}s.push(new Vy(c,i.length,r.index,r.index+h.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,c)=>{for(let h of s)h.line==i.length&&h.from>c&&(h.from--,h.to--);return a}),i.push(o)}return new to(i,s)}}let Hy=T.widget({widget:new class extends Fe{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),Wy=T.mark({class:"cm-snippetField"});class ei{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(i=>(i.from==i.to?Hy:Wy).range(i.from,i.to)))}map(e){let t=[];for(let i of this.ranges){let s=i.map(e);if(!s)return null;t.push(s)}return new ei(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const $i=D.define({map(n,e){return n&&n.map(e)}}),$y=D.define(),Bi=Q.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is($i))return t.value;if(t.is($y)&&n)return new ei(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>w.decorations.from(n,e=>e?e.deco:T.none)});function io(n,e){return x.create(n.filter(t=>t.field==e).map(t=>x.range(t.from,t.to)))}function zy(n){let e=to.parse(n);return(t,i,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),a={changes:{from:s,to:r,insert:B.of(o)},scrollIntoView:!0,annotations:i?[Ny.of(i),Y.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=io(l,0)),l.some(c=>c.field>0)){let c=new ei(l,0),h=a.effects=[$i.of(c)];t.state.field(Bi,!1)===void 0&&h.push(D.appendConfig.of([Bi,Jy,Yy,Fy]))}t.dispatch(t.state.update(a))}}function Qc(n){return({state:e,dispatch:t})=>{let i=e.field(Bi,!1);if(!i||n<0&&i.active==0)return!1;let s=i.active+n,r=n>0&&!i.ranges.some(o=>o.field==s+n);return t(e.update({selection:io(i.ranges,s),effects:$i.of(r?null:new ei(i.ranges,s)),scrollIntoView:!0})),!0}}const jy=({state:n,dispatch:e})=>n.field(Bi,!1)?(e(n.update({effects:$i.of(null)})),!0):!1,qy=Qc(1),Ky=Qc(-1),_y=[{key:"Tab",run:qy,shift:Ky},{key:"Escape",run:jy}],zl=A.define({combine(n){return n.length?n[0]:_y}}),Jy=pt.highest(Gt.compute([zl],n=>n.facet(zl)));function Uy(n,e){return Object.assign(Object.assign({},e),{apply:zy(n)})}const Yy=w.domEventHandlers({mousedown(n,e){let t=e.state.field(Bi,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=t.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==t.active?!1:(e.dispatch({selection:io(t.ranges,s.field),effects:$i.of(t.ranges.some(r=>r.field>s.field)?new ei(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Zc=new class extends ct{};Zc.startSide=1;Zc.endSide=-1;const G={log:(...n)=>{},warn:(...n)=>{}},E={STRING:"String",NUMBER:"Number",TRUE:"True",FALSE:"False",NULL:"Null",OBJECT:"Object",ARRAY:"Array",PROPERTY:"Property",PROPERTY_NAME:"PropertyName",PROPERTY_COLON:"PropertyColon",ITEM:"Item",JSON_TEXT:"JsonText",INVALID:"⚠"},Gy={Pair:E.PROPERTY,Key:E.PROPERTY_NAME,BlockSequence:E.ARRAY,BlockMapping:E.OBJECT,FlowSequence:E.ARRAY,FlowMapping:E.OBJECT,QuotedLiteral:E.STRING,Literal:E.STRING,Stream:E.JSON_TEXT,Document:E.OBJECT},Xy={File:E.JSON_TEXT},no=[E.STRING,E.NUMBER,E.TRUE,E.FALSE,E.NULL],ef=[E.OBJECT,E.ARRAY,E.ITEM],$={JSON5:"json5",JSON:"json4",YAML:"yaml"},U=(n,e)=>{var t,i;switch(e){case $.YAML:return(t=Gy[n])!==null&&t!==void 0?t:n;case $.JSON5:return(i=Xy[n])!==null&&i!==void 0?i:n;default:return n}};function tf(n,e,t){const i=[];for(let s=e;s!=null&&s.parent;s=s.parent)switch(U(s.parent.name,t)){case E.PROPERTY:{const r=vr(s.parent,E.PROPERTY_NAME,t);r&&i.unshift(Dt(n,r).replace(/[/~]/g,o=>o==="~"?"~0":"~1"));break}case E.ARRAY:{if(Zy(s,t)){const r=rf(s.parent,s,t);i.unshift(`${r}`)}break}}return i.unshift(""),i.join("/")}const nf=(n,e,t=-1,i)=>tf(n.doc,j(n).resolve(e,t),i),so=(n,e)=>{const t=j(n),i=new Map;return t.iterate({enter:s=>{var r,o,l,a,c,h,f,u;if([E.PROPERTY_NAME,E.OBJECT].includes(U(s.name,e))){const d=tf(n.doc,s.node,e),{from:p,to:g}=s.node;if(!(!((o=(r=s.node)===null||r===void 0?void 0:r.nextSibling)===null||o===void 0)&&o.node))return i.set(d,{keyFrom:p,keyTo:g}),!0;const y=e===$.JSON?(a=(l=s.node)===null||l===void 0?void 0:l.nextSibling)===null||a===void 0?void 0:a.node:(u=(f=(h=(c=s.node)===null||c===void 0?void 0:c.nextSibling)===null||h===void 0?void 0:h.node)===null||f===void 0?void 0:f.nextSibling)===null||u===void 0?void 0:u.node;if(!y)return i.set(d,{keyFrom:p,keyTo:g}),!0;const{from:b,to:v}=y;return i.set(d,{keyFrom:p,keyTo:g,valueFrom:b,valueTo:v}),!0}}}),i},Ts=(n,e,t=-1)=>j(n).resolveInner(e,t),wn=n=>n.replace(/^"(.*)"$/,"$1").replace(/^'(.*)'$/,"$1"),Qy=n=>n.replace(/^"(.*)"$/,"'$1'"),Dt=(n,e,t=!0,i=!0)=>{const s=e?n.sliceString(e.from,e.to):"";return t?i?wn(s):s.replace(/(^["'])|(["']$)/g,""):s},sf=(n,e)=>{var t,i,s,r;return U(n.name,e)===E.INVALID&&(U((i=(t=n.prevSibling)===null||t===void 0?void 0:t.name)!==null&&i!==void 0?i:"",e)===E.PROPERTY_NAME||U((r=(s=n.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",e)===E.PROPERTY_COLON)},Sn=(n,e)=>no.includes(U(n.name,e))||sf(n,e),Zy=(n,e)=>[...no,...ef].includes(U(n.name,e))||sf(n,e),an=(n,e)=>{var t,i,s,r,o,l;return U(n.name,e)===E.PROPERTY_NAME||U(n.name,e)===E.INVALID&&(U((i=(t=n.prevSibling)===null||t===void 0?void 0:t.name)!==null&&i!==void 0?i:"",e)===E.PROPERTY||U((r=(s=n.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",e)==="{")||e===$.YAML&&U((l=(o=n.parent)===null||o===void 0?void 0:o.name)!==null&&l!==void 0?l:"",e)===E.OBJECT},zi=n=>{const e=[];let t=n.firstChild;for(;t;)t&&e.push(t),t=t==null?void 0:t.nextSibling;return e},eb=(n,e,t)=>zi(n).filter(i=>U(i.name,t)===e),vr=(n,e,t)=>{var i;return(i=zi(n).find(s=>U(s.name,t)===e))!==null&&i!==void 0?i:null},jl=(n,e)=>zi(n).find(t=>Sn(t,e)),tb=(n,e)=>zi(n).filter(t=>no.includes(U(t.name,e))||ef.includes(U(t.name,e))),rf=(n,e,t)=>tb(n,t).findIndex(i=>i.from===e.from&&i.to===e.to),ql=(n,e,t,i=1/0)=>{let s=n;for(;s&&i>0;){if(U(s.name,t)===e)return s;s=s.parent,i--}return null},ib=D.define(),jn=Q.define({create(){},update(n,e){for(const t of e.effects)if(t.is(ib))return t.value;return n}}),ro=n=>n.field(jn),Vb=n=>[jn.init(()=>n)],wr=Of({linkify:!0,typographer:!0});(async()=>{const n=await Lf({themes:{light:"vitesse-light",dark:"vitesse-dark"}});wr.use(n)})();function Wt(n,e=!0){return e?wr.renderInline(n):wr.render(n)}class nb{constructor(){this.completions=new Map,this.reservedKeys=new Set}reserve(e){this.reservedKeys.add(e)}add(e){this.reservedKeys.has(e.label)||this.completions.set(e.label,e)}}class sb{constructor(e){var t;this.opts=e,this.schema=null,this.mode=$.JSON,this.mode=(t=e.mode)!==null&&t!==void 0?t:$.JSON}doComplete(e){var t,i,s;const r=ro(e.state);if(this.schema=(t=this.expandSchemaProperty(r,r))!==null&&t!==void 0?t:r,!this.schema)return[];const o={from:e.pos,to:e.pos,options:[],filter:!1},l=e.state.doc.sliceString(0);let a=Ts(e.state,e.pos),c=e.state.sliceDoc(a.from,e.pos).replace(/^(["'])/,"");if(G.log("xxx","node",a,"prefix",c,"ctx",e),!(Sn(a,this.mode)||an(a,this.mode))&&!e.explicit)return G.log("xxx","no completions for non-word/primitive",a),o;const h=Dt(e.state.doc,a),f=Dt(e.state.doc,a,!1);if(a&&(Sn(a,this.mode)||an(a,this.mode)))o.from=a.from,o.to=a.to;else{const g=e.matchBefore(/[A-Za-z0-9._]*/),y=e.pos-h.length;G.log("xxx","overwriteStart after",y,"ctx.pos",e.pos,"word",g,"currentWord",h,"=>",l[y-1],"..",l[y],"..",l),o.from=a.name===E.INVALID?(i=g==null?void 0:g.from)!==null&&i!==void 0?i:e.pos:y,o.to=e.pos}const u=new nb;let d=!0;const p=ql(a,E.PROPERTY_NAME,this.mode);if(p&&(G.log("xxx","closestPropertyNameNode",p,"node",a),a=p),an(a,this.mode)){G.log("xxx","isPropertyNameNode",a);const g=a.parent;if(g){const y=jl(g,this.mode);d=!y||y.name===E.INVALID&&y.from-y.to===0||(y.parent?zi(y.parent).length<=1:!1),G.log("xxx","addValue",d,jl(g,this.mode),a),a=(s=ql(g,E.OBJECT,this.mode))!==null&&s!==void 0?s:null}}if(G.log("xxx",a,h,e,"node at pos",Ts(e.state,e.pos)),a&&[E.OBJECT,E.JSON_TEXT].includes(U(a.name,this.mode))&&(an(Ts(e.state,e.pos),this.mode)||p)){if(a.from===e.pos)return G.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(this.schema,e,a,u,d,f)}else{const g={},y=this.getValueCompletions(this.schema,e,g,u);G.log("xxx","getValueCompletions res",y)}return o.options=Array.from(u.completions.values()).filter(g=>wn(g.label).startsWith(c)),G.log("xxx","result",o,"prefix",c,"collector.completions",u.completions,"reservedKeys",u.reservedKeys),o}applySnippetCompletion(e){return Uy(typeof e.apply!="string"?e.label:e.apply,e)}getPropertyCompletions(e,t,i,s,r,o){const l=eb(i,E.PROPERTY,this.mode);G.log("xxx","getPropertyCompletions",i,t,l),l.forEach(c=>{const h=Dt(t.state.doc,vr(c,E.PROPERTY_NAME,this.mode));s.reserve(wn(h))});const a=this.getSchemas(e,t);G.log("xxx","propertyCompletion schemas",a),a.forEach(c=>{if(typeof c!="object")return;const h=c.properties;h&&Object.entries(h).forEach(([u,d])=>{var p,g;if(typeof d=="object"){const y=(p=d.description)!==null&&p!==void 0?p:"",b=(g=d.type)!==null&&g!==void 0?g:"",v=Array.isArray(b)?b.toString():b,M={label:u,apply:this.getInsertTextForProperty(u,r,o,d),type:"property",detail:v,info:Wt(y)};s.add(this.applySnippetCompletion(M))}});const f=c.propertyNames;if(typeof f=="object"&&(f.enum&&f.enum.forEach(u=>{const d=u==null?void 0:u.toString();if(d){const p={label:d,apply:this.getInsertTextForProperty(d,r,o),type:"property"};s.add(this.applySnippetCompletion(p))}}),f.const)){const u=f.const.toString(),d={label:u,apply:this.getInsertTextForProperty(u,r,o),type:"property"};s.add(this.applySnippetCompletion(d))}})}getInsertTextForProperty(e,t,i,s){s=s&&this.expandSchemaProperty(s,this.schema);let r=this.getInsertTextForPropertyName(e,i);if(!t)return r;r+=": ";let o,l=0;if(typeof s=="object"){if(typeof s.default<"u")o||(o=this.getInsertTextForGuessedValue(s.default,"")),l++;else if(s.enum&&(!o&&s.enum.length===1&&(o=this.getInsertTextForGuessedValue(s.enum[0],"")),l+=s.enum.length),typeof s.const<"u"&&(o||(o=this.getInsertTextForGuessedValue(s.const,"")),l++),Array.isArray(s.examples)&&s.examples.length&&(o||(o=this.getInsertTextForGuessedValue(s.examples[0],"")),l+=s.examples.length),o===void 0&&l===0){let a=Array.isArray(s.type)?s.type[0]:s.type;switch(a||(s.properties?a="object":s.items&&(a="array")),a){case"boolean":o="#{}";break;case"string":o=this.getInsertTextForString("");break;case"object":switch(this.mode){case $.JSON5:o="{#{}}";break;case $.YAML:o="#{}";break;default:o="{#{}}";break}break;case"array":o="[#{}]";break;case"number":case"integer":o="#{0}";break;case"null":o="#{null}";break;default:o="#{}";break}}}return(!o||l>1)&&(G.log("xxx","value",o,"nValueProposals",l,s),o="#{}"),r+o}getInsertTextForPropertyName(e,t){switch(this.mode){case $.JSON5:case $.YAML:return t.startsWith('"')?`"${e}"`:t.startsWith("'")?`'${e}'`:e;default:return`"${e}"`}}getInsertTextForString(e,t="#"){switch(this.mode){case $.JSON5:return`'${t}{${e}}'`;case $.YAML:return`${t}{${e}}`;default:return`"${t}{${e}}"`}}getInsertTextForGuessedValue(e,t=""){switch(typeof e){case"object":return e===null?"${null}"+t:this.getInsertTextForValue(e,t);case"string":{let i=JSON.stringify(e);return i=i.substr(1,i.length-2),i=this.getInsertTextForPlainText(i),this.getInsertTextForString(i,"$")+t}case"number":case"boolean":return"${"+JSON.stringify(e)+"}"+t}return this.getInsertTextForValue(e,t)}getInsertTextForPlainText(e){return e.replace(/[\\$}]/g,"\\$&")}getInsertTextForValue(e,t){const i=JSON.stringify(e,null," ");return i==="{}"?"{#{}}"+t:i==="[]"?"[#{}]"+t:this.getInsertTextForPlainText(i+t)}getValueCompletions(e,t,i,s){let r=j(t.state).resolveInner(t.pos,-1),o=null,l;if(G.log("xxx","getValueCompletions",r,t),r&&Sn(r,this.mode)&&(o=r,r=r.parent),!r){this.addSchemaValueCompletions(e,i,s);return}if(U(r.name,this.mode)===E.PROPERTY){const c=vr(r,E.PROPERTY_NAME,this.mode);c&&(l=Dt(t.state.doc,c),r=r.parent)}if(G.log("xxx","node",r,"parentKey",l),r&&(l!==void 0||U(r.name,this.mode)===E.ARRAY)){const c=this.getSchemas(e,t);for(const h of c){if(typeof h!="object")return;if(U(r.name,this.mode)===E.ARRAY&&h.items){let f=s;if(h.uniqueItems&&(f=Object.assign(Object.assign({},f),{add(u){f.completions.has(u.label)||s.add(u)},reserve(u){s.reserve(u)}})),Array.isArray(h.items)){let u=0;if(o){const p=rf(r,o,this.mode);p>=0&&(u=p)}const d=h.items[u];d&&this.addSchemaValueCompletions(d,i,f)}else this.addSchemaValueCompletions(h.items,i,f)}if(l!==void 0){let f=!1;if(h.properties){const u=h.properties[l];u&&(f=!0,this.addSchemaValueCompletions(u,i,s))}if(h.patternProperties&&!f)for(const u of Object.keys(h.patternProperties)){const d=this.extendedRegExp(u);if(d!=null&&d.test(l)){f=!0;const p=h.patternProperties[u];p&&this.addSchemaValueCompletions(p,i,s)}}if(h.additionalProperties&&!f){const u=h.additionalProperties;this.addSchemaValueCompletions(u,i,s)}}i.boolean&&(this.addBooleanValueCompletion(!0,s),this.addBooleanValueCompletion(!1,s)),i.null&&this.addNullValueCompletion(s)}}return{valuePrefix:o?Dt(t.state.doc,o,!0,!1):""}}addSchemaValueCompletions(e,t,i){typeof e=="object"&&(this.addEnumValueCompletions(e,i),this.addDefaultValueCompletions(e,i),this.collectTypes(e,t),Array.isArray(e.allOf)&&e.allOf.forEach(s=>this.addSchemaValueCompletions(s,t,i)),Array.isArray(e.anyOf)&&e.anyOf.forEach(s=>this.addSchemaValueCompletions(s,t,i)),Array.isArray(e.oneOf)&&e.oneOf.forEach(s=>this.addSchemaValueCompletions(s,t,i)))}addDefaultValueCompletions(e,t,i=0){let s=!1;if(typeof e.default<"u"){let r=e.type,o=e.default;for(let a=i;a>0;a--)o=[o],r="array";const l=Object.assign(Object.assign({type:r==null?void 0:r.toString()},this.getAppliedValue(o)),{detail:"Default value"});t.add(l),s=!0}Array.isArray(e.examples)&&e.examples.forEach(r=>{let o=e.type,l=r;for(let a=i;a>0;a--)l=[l],o="array";t.add(Object.assign({type:o==null?void 0:o.toString()},this.getAppliedValue(l))),s=!0}),!s&&typeof e.items=="object"&&!Array.isArray(e.items)&&i<5&&this.addDefaultValueCompletions(e.items,t,i+1)}addEnumValueCompletions(e,t){var i,s;if(typeof e.const<"u"&&t.add(Object.assign(Object.assign({type:(i=e.type)===null||i===void 0?void 0:i.toString()},this.getAppliedValue(e.const)),{info:e.description})),Array.isArray(e.enum))for(let r=0,o=e.enum.length;r<o;r++){const l=e.enum[r];t.add(Object.assign(Object.assign({type:(s=e.type)===null||s===void 0?void 0:s.toString()},this.getAppliedValue(l)),{info:e.description}))}}addBooleanValueCompletion(e,t){t.add({type:"boolean",label:e?"true":"false"})}addNullValueCompletion(e){e.add({type:"null",label:"null"})}collectTypes(e,t){if(Array.isArray(e.enum)||typeof e.const<"u")return;const i=e.type;Array.isArray(i)?i.forEach(s=>t[s]=!0):i&&(t[i]=!0)}getSchemas(e,t){var i,s;const r=new Df(this.schema);let o=nf(t.state,t.pos,-1,this.mode),l=r.getSchema({pointer:o});return Ql(l)&&(l=(i=l.data)===null||i===void 0?void 0:i.schema),(!l||l.name==="UnknownPropertyError"||l.enum||l.type==="undefined")&&(o=o.replace(/\/[^/]*$/,"/"),l=r.getSchema({pointer:o})),G.log("xxx","pointer..",JSON.stringify(o)),(!o||o==="/")&&(l=(s=this.expandSchemaProperty(e,e))!==null&&s!==void 0?s:e),G.log("xxx","subSchema..",l),l?Array.isArray(l.allOf)?[l,...l.allOf.map(a=>this.expandSchemaProperty(a,e))]:Array.isArray(l.oneOf)?[l,...l.oneOf.map(a=>this.expandSchemaProperty(a,e))]:Array.isArray(l.anyOf)?[l,...l.anyOf.map(a=>this.expandSchemaProperty(a,e))]:[l]:[]}expandSchemaProperty(e,t){if(typeof e=="object"&&e.$ref){const i=this.getReferenceSchema(t,e.$ref);if(typeof i=="object"){const s=Object.assign(Object.assign({},e),i);return Reflect.deleteProperty(s,"$ref"),s}}return e}getReferenceSchema(e,t){const i=t.split("/");let s=e;return i.forEach(r=>{if(r){if(r==="#"){s=e;return}typeof s=="object"&&(s=s[r])}}),s}getAppliedValue(e){const t=wn(JSON.stringify(e));switch(this.mode){case $.JSON5:return{label:t,apply:Qy(JSON.stringify(e))};case $.YAML:return{label:t,apply:t};default:return{label:t,apply:JSON.stringify(e)}}}getValueFromLabel(e){return JSON.parse(e)}extendedRegExp(e){let t="";e.startsWith("(?i)")&&(e=e.substring(4),t="i");try{return new RegExp(e,t+"u")}catch{try{return new RegExp(e,t)}catch{return}}}}function Hb(n={}){const e=new sb(n);return function(i){return e.doComplete(i)}}const Ri=(n,e)=>{const t=n.length>2;let i=n.map((s,r)=>{const o="`"+(e?e(s):s)+"`";return r===n.length-1?"or "+o:o});return t?i.join(", "):i.join(" ")};function of(n){let e=null;try{e=JSON.parse(n.doc.toString())}catch{}const t=so(n,$.JSON);return{data:e,pointers:t}}function Ge(n,e,t=[]){const i=document.createElement(n);return Object.entries(e).forEach(([s,r])=>{if(s==="text"){i.innerText=r;return}if(s==="inner"){i.innerHTML=r;return}i.setAttribute(s,r)}),t.forEach(s=>i.appendChild(s)),i}function rb(n){let e=null;try{e=Ef.parse(n.doc.toString())}catch{}const t=so(n,$.YAML);return{data:e,pointers:t}}function ob(n){let e=null;try{e=Pf.parse(n.doc.toString())}catch{}const t=so(n,$.JSON5);return{data:e,pointers:t}}const lb=n=>{switch(n){case $.JSON:return of;case $.JSON5:return ob;case $.YAML:return rb}},ab=n=>{var e,t,i;return!((e=n==null?void 0:n.data)===null||e===void 0)&&e.pointer&&((t=n==null?void 0:n.data)===null||t===void 0?void 0:t.pointer)!=="#"?n.data.pointer.slice(1):!((i=n==null?void 0:n.data)===null||i===void 0)&&i.property?`/${n.data.property}`:""},Wb=n=>n.startState.field(jn)!==n.state.field(jn);function $b(n){const e=new cb(n);return t=>e.doValidation(t)}const hb=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class cb{constructor(e){var t,i,s,r;this.options=e,this.schema=null,this.mode=$.JSON,this.parser=of,this.rewriteError=o=>{var l,a,c,h,f;const u=o==null?void 0:o.data,d=u==null?void 0:u.errors;return o.code==="one-of-error"&&(d!=null&&d.length)?`Expected one of ${Ri(d,g=>g.data.expected)}`:o.code==="type-error"?`Expected \`${!((l=o==null?void 0:o.data)===null||l===void 0)&&l.expected&&Array.isArray((a=o==null?void 0:o.data)===null||a===void 0?void 0:a.expected)?Ri((c=o==null?void 0:o.data)===null||c===void 0?void 0:c.expected):(h=o==null?void 0:o.data)===null||h===void 0?void 0:h.expected}\` but received \`${(f=o==null?void 0:o.data)===null||f===void 0?void 0:f.received}\``:o.message.replaceAll("in `#` ","").replaceAll("at `#`","").replaceAll("/",".").replaceAll("#.","")},this.mode=(i=(t=this.options)===null||t===void 0?void 0:t.mode)!==null&&i!==void 0?i:$.JSON,this.parser=(r=(s=this.options)===null||s===void 0?void 0:s.jsonParser)!==null&&r!==void 0?r:lb(this.mode)}get schemaTitle(){var e,t,i;return(i=(t=(e=this.schema)===null||e===void 0?void 0:e.getSchema())===null||t===void 0?void 0:t.title)!==null&&i!==void 0?i:"json-schema"}doValidation(e){const t=ro(e.state);if(!t)return[];if(this.schema=new Zl(t),!this.schema)return[];const i=e.state.doc.toString();if(!(i!=null&&i.length))return[];const s=this.parser(e.state);let r=[];try{r=this.schema.validate(s.data)}catch{}return G.log("xxx","validation errors",r,s.data),r.length?r.reduce((o,l)=>{const a=()=>{const f=this.rewriteError(l);o.push({from:0,to:0,message:f,severity:"error",source:this.schemaTitle,renderMessage:()=>{const u=Ge("div",{});return u.innerHTML=Wt(f),u}})},c=ab(l),h=s.pointers.get(c);if(l.name==="MaxPropertiesError"||l.name==="MinPropertiesError")a();else if(h){const f=hb.includes(l.name),u=this.rewriteError(l),d=f?h.keyFrom:h.valueFrom,p=f?h.keyTo:h.valueTo;p!==void 0&&d!==void 0&&o.push({from:d,to:p,message:u,renderMessage:()=>{const g=Ge("div",{});return g.innerHTML=Wt(u),g},severity:"error",source:this.schemaTitle})}else a();return o},[]):[]}}function zb(n){const e=new fb(n);return async function(i,s,r){return e.doHover(i,s,r)}}function Kl(n){if(n.type)return n.$ref?`${n.$ref} (${n.type})`:n.type;if(n.$ref)return`${n.$ref}`}function Os(n,e,t){return`${e}: ${Ri(n[e].map(i=>{try{const{data:s}=t.resolveRef({data:i,pointer:i.$ref});return Kl(s||i)}catch{return i.type}}))}`}class fb{constructor(e){var t,i;this.opts=e,this.schema=null,this.mode=$.JSON,this.opts=Object.assign({parser:JSON.parse},this.opts),this.mode=(i=(t=this.opts)===null||t===void 0?void 0:t.mode)!==null&&i!==void 0?i:$.JSON}getDataForCursor(e,t,i){const s=ro(e.state);if(!s)return null;this.schema=new Zl(s);const r=nf(e.state,t,i,this.mode);let o;try{o=this.opts.parser(e.state.doc.toString())}catch{}if(!r)return null;let l=this.schema.getSchema({pointer:r,data:o,withSchemaWarning:!0});return Ql(l)&&(l!=null&&l.data.schema.$ref?l=this.schema.resolveRef(l):l=l==null?void 0:l.data.schema),{schema:l,pointer:r}}formatMessage(e){const{message:t,typeInfo:i}=e;return t?Ge("div",{class:"cm6-json-schema-hover"},[Ge("div",{class:"cm6-json-schema-hover--description",inner:Wt(t,!1)}),Ge("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ge("div",{class:"cm6-json-schema-hover--code",inner:Wt(i,!1)})])]):Ge("div",{class:"cm6-json-schema-hover"},[Ge("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ge("code",{class:"cm6-json-schema-hover--code",inner:Wt(i,!1)})])])}getHoverTexts(e,t){let i="",s=null;const{schema:r}=e;return r.oneOf&&(i=Os(r,"oneOf",t)),r.anyOf&&(i=Os(r,"anyOf",t)),r.allOf&&(i=Os(r,"allOf",t)),r.type&&(i=Array.isArray(r.type)?Ri(r.type):r.type),r.$ref&&(i=` Reference: ${r.$ref}`),r.enum&&(i=`\`enum\`: ${Ri(r.enum)}`),r.format&&(i+=`\`format\`: ${r.format}`),r.pattern&&(i+=`\`pattern\`: ${r.pattern}`),r.description&&(s=r.description),{message:s,typeInfo:i}}async doHover(e,t,i){var s,r,o,l;const a=t,c=t;try{const h=this.getDataForCursor(e,t,i);if(G.log("cursorData",h),!(h!=null&&h.schema))return null;const u=((r=(s=this.opts)===null||s===void 0?void 0:s.getHoverTexts)!==null&&r!==void 0?r:this.getHoverTexts)(h,this.schema),p=((l=(o=this.opts)===null||o===void 0?void 0:o.formatHover)!==null&&l!==void 0?l:this.formatMessage)(u);return{pos:a,end:c,arrow:!0,above:!0,create:g=>({dom:p})}}catch(h){return G.log(h),null}}}const _l=new ea,lf=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function hn(n){return(e,t,i)=>{if(i)return!1;let s=e.node.getChild("VariableName");return s&&t(s,n),!0}}const ub={FunctionDefinition:hn("function"),ClassDefinition:hn("class"),ForStatement(n,e,t){if(t){for(let i=n.node.firstChild;i;i=i.nextSibling)if(i.name=="VariableName")e(i,"variable");else if(i.name=="in")break}},ImportStatement(n,e){var t,i;let{node:s}=n,r=((t=s.firstChild)===null||t===void 0?void 0:t.name)=="from";for(let o=s.getChild("import");o;o=o.nextSibling)o.name=="VariableName"&&((i=o.nextSibling)===null||i===void 0?void 0:i.name)!="as"&&e(o,r?"variable":"namespace")},AssignStatement(n,e){for(let t=n.node.firstChild;t;t=t.nextSibling)if(t.name=="VariableName")e(t,"variable");else if(t.name==":"||t.name=="AssignOp")break},ParamList(n,e){for(let t=null,i=n.node.firstChild;i;i=i.nextSibling)i.name=="VariableName"&&(!t||!/\*|AssignOp/.test(t.name))&&e(i,"variable"),t=i},CapturePattern:hn("variable"),AsPattern:hn("variable"),__proto__:null};function af(n,e){let t=_l.get(e);if(t)return t;let i=[],s=!0;function r(o,l){let a=n.sliceString(o.from,o.to);i.push({label:a,type:l})}return e.cursor(Sr.IncludeAnonymous).iterate(o=>{if(o.name){let l=ub[o.name];if(l&&l(o,r,s)||!s&&lf.has(o.name))return!1;s=!1}else if(o.to-o.from>8192){for(let l of af(n,o.node))i.push(l);return!1}}),_l.set(e,i),i}const Jl=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,hf=["String","FormatString","Comment","PropertyName"];function db(n){let e=j(n.state).resolveInner(n.pos,-1);if(hf.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&Jl.test(n.state.sliceDoc(e.from,e.to));if(!t&&!n.explicit)return null;let i=[];for(let s=e;s;s=s.parent)lf.has(s.name)&&(i=i.concat(af(n.state.doc,s)));return{options:i,from:t?e.from:n.pos,validFor:Jl}}const pb=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(n=>({label:n,type:"constant"})).concat(["ArithmeticError","AssertionError","AttributeError","BaseException","BlockingIOError","BrokenPipeError","BufferError","BytesWarning","ChildProcessError","ConnectionAbortedError","ConnectionError","ConnectionRefusedError","ConnectionResetError","DeprecationWarning","EOFError","Ellipsis","EncodingWarning","EnvironmentError","Exception","FileExistsError","FileNotFoundError","FloatingPointError","FutureWarning","GeneratorExit","IOError","ImportError","ImportWarning","IndentationError","IndexError","InterruptedError","IsADirectoryError","KeyError","KeyboardInterrupt","LookupError","MemoryError","ModuleNotFoundError","NameError","NotADirectoryError","NotImplemented","NotImplementedError","OSError","OverflowError","PendingDeprecationWarning","PermissionError","ProcessLookupError","RecursionError","ReferenceError","ResourceWarning","RuntimeError","RuntimeWarning","StopAsyncIteration","StopIteration","SyntaxError","SyntaxWarning","SystemError","SystemExit","TabError","TimeoutError","TypeError","UnboundLocalError","UnicodeDecodeError","UnicodeEncodeError","UnicodeError","UnicodeTranslateError","UnicodeWarning","UserWarning","ValueError","Warning","ZeroDivisionError"].map(n=>({label:n,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(n=>({label:n,type:"class"}))).concat(["abs","aiter","all","anext","any","ascii","bin","breakpoint","callable","chr","compile","delattr","dict","dir","divmod","enumerate","eval","exec","exit","filter","format","getattr","globals","hasattr","hash","help","hex","id","input","isinstance","issubclass","iter","len","license","locals","max","min","next","oct","open","ord","pow","print","property","quit","repr","reversed","round","setattr","slice","sorted","sum","vars","zip"].map(n=>({label:n,type:"function"}))),mb=[q("def ${name}(${params}):\n ${}",{label:"def",detail:"function",type:"keyword"}),q("for ${name} in ${collection}:\n ${}",{label:"for",detail:"loop",type:"keyword"}),q("while ${}:\n ${}",{label:"while",detail:"loop",type:"keyword"}),q("try:\n ${}\nexcept ${error}:\n ${}",{label:"try",detail:"/ except block",type:"keyword"}),q(`if \${}:
|
|
3
|
+
`){[e,t]=$t(this,e,t);let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof $e))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],c=e.children[r];if(a!=c)return i+a.scanIdentical(c,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new J(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,c=-1,h=[];function f(d){let p;if(d.lines>r&&d instanceof $e)for(let g of d.children)f(g);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof J&&a&&(p=h[h.length-1])instanceof J&&d.lines+p.lines<=32?(a+=d.lines,c+=d.length+1,h[h.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&u(),a+=d.lines,c+=d.length+1,h.push(d))}function u(){a!=0&&(l.push(h.length==1?h[0]:$e.from(h,c)),c=-1,a=h.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new $e(l,t)}}B.empty=new J([""],0);function Lf(n){let e=-1;for(let t of n)e+=t.length+1;return e}function fn(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function oo(n,e,t){return fn(n,[""],e,t)}class ui{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof J?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof J?s.text.length:s.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
4
|
+
`,this;e--}else if(s instanceof J){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof J?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class ta{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ui(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class ia{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(B.prototype[Symbol.iterator]=function(){return this.iter()},ui.prototype[Symbol.iterator]=ta.prototype[Symbol.iterator]=ia.prototype[Symbol.iterator]=function(){return this});class If{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}}function $t(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}let Lt="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(n=>n?parseInt(n,36):1);for(let n=1;n<Lt.length;n++)Lt[n]+=Lt[n-1];function Nf(n){for(let e=1;e<Lt.length;e+=2)if(Lt[e]>n)return Lt[e-1]<=n;return!1}function lo(n){return n>=127462&&n<=127487}const ao=8205;function re(n,e,t=!0,i=!0){return(t?na:Ff)(n,e,i)}function na(n,e,t){if(e==n.length)return e;e&&sa(n.charCodeAt(e))&&ra(n.charCodeAt(e-1))&&e--;let i=ne(n,e);for(e+=ke(i);e<n.length;){let s=ne(n,e);if(i==ao||s==ao||t&&Nf(s))e+=ke(s),i=s;else if(lo(s)){let r=0,o=e-2;for(;o>=0&&lo(ne(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Ff(n,e,t){for(;e>0;){let i=na(n,e-2,t);if(i<e)return i;e--}return 0}function sa(n){return n>=56320&&n<57344}function ra(n){return n>=55296&&n<56320}function ne(n,e){let t=n.charCodeAt(e);if(!ra(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return sa(i)?(t-55296<<10)+(i-56320)+65536:t}function Ar(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function ke(n){return n<65536?1:2}const Ps=/\r\n?|\n/;var te=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(te||(te={}));class _e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){Bs(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new _e(e)}composeDesc(e){return this.empty?e:e.empty?this:oa(this,e)}mapDesc(e,t=!1){return e.empty?this:Rs(this,e,t)}mapPos(e,t=-1,i=te.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],c=s+l;if(a<0){if(c>e)return r+(e-s);r+=l}else{if(i!=te.Simple&&c>=e&&(i==te.TrackDel&&s<e&&c>e||i==te.TrackBefore&&s<e||i==te.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=c}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new _e(e)}static create(e){return new _e(e)}}class ee extends _e{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Bs(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return Rs(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(B.empty);i.push(o?e.slice(r,r+o):B.empty)}r+=o}return new ee(t,i)}compose(e){return this.empty?e:e.empty?this:oa(this,e,!0)}map(e,t=!1){return e.empty?this:Rs(this,e,t,!0)}iterChanges(e,t=!1){Bs(this,e,t)}get desc(){return _e.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new bi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let h=Math.min(r.len,a-l);oe(s,h,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;oe(t,h,f),f>0&&st(i,t,r.text),r.forward(h),l+=h}let c=e[o++];for(;l<c;){if(r.done)break e;let h=Math.min(r.len,c-l);oe(t,h,-1),oe(s,h,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(h),l+=h}}return{changes:new ee(t,i),filtered:_e.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(h=!1){if(!h&&!s.length)return;o<t&&oe(s,t-o,-1);let f=new ee(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function c(h){if(Array.isArray(h))for(let f of h)c(f);else if(h instanceof ee){if(h.length!=t)throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${t})`);a(),l=l?l.compose(h.map(l)):h}else{let{from:f,to:u=f,insert:d}=h;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?B.of(d.split(i||Ps)):d:B.empty,g=p.length;if(f==u&&g==0)return;f<o&&a(),f>o&&oe(s,f-o,-1),oe(s,u-f,g),st(r,s,p),o=u}}return c(e),a(!l),l}static empty(e){return new ee(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(B.empty);i[s]=B.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new ee(t,i)}static createSet(e,t){return new ee(e,t)}}function oe(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function st(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(B.empty);n.push(t)}}function Bs(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let c=s,h=r,f=B.empty;for(;c+=l,h+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,c,r,h,f),s=c,r=h}}}function Rs(n,e,t,i=!1){let s=[],r=i?[]:null,o=new bi(n),l=new bi(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let c=Math.min(o.len,l.len);oe(s,c,-1),o.forward(c),l.forward(c)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let c=l.len;for(oe(s,l.ins,-1);c;){let h=Math.min(o.len,c);o.ins>=0&&a<o.i&&o.len<=h&&(oe(s,0,o.ins),r&&st(r,s,o.text),a=o.i),o.forward(h),c-=h}l.next()}else if(o.ins>=0){let c=0,h=o.len;for(;h;)if(l.ins==-1){let f=Math.min(h,l.len);c+=f,h-=f,l.forward(f)}else if(l.ins==0&&l.len<h)h-=l.len,l.next();else break;oe(s,c,a<o.i?o.ins:0),r&&a<o.i&&st(r,s,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return r?ee.createSet(s,r):_e.create(s);throw new Error("Mismatched change set lengths")}}function oa(n,e,t=!1){let i=[],s=t?[]:null,r=new bi(n),o=new bi(e);for(let l=!1;;){if(r.done&&o.done)return s?ee.createSet(i,s):_e.create(i);if(r.ins==0)oe(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)oe(i,0,o.ins,l),s&&st(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),c=i.length;if(r.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;oe(i,a,h,l),s&&h&&st(s,i,o.text)}else o.ins==-1?(oe(i,r.off?0:r.len,a,l),s&&st(s,i,r.textBit(a))):(oe(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&st(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>c),r.forward2(a),o.forward(a)}}}}class bi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?B.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?B.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class bt{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new bt(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return x.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return x.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return x.range(e.anchor,e.head)}static create(e,t,i){return new bt(e,t,i)}}class x{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:x.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new x([this.main],0)}addRange(e,t=!0){return x.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,x.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new x(e.ranges.map(t=>bt.fromJSON(t)),e.main)}static single(e,t=e){return new x([x.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return x.normalized(e.slice(),t);i=r.to}return new x(e,t)}static cursor(e,t=0,i,s){return bt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(e,t,i,s){let r=(i??16777215)<<6|(s==null?7:Math.min(6,s));return t<e?bt.create(t,e,48|r):bt.create(e,t,(t>e?8:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?x.range(a,l):x.range(l,a))}}return new x(e,t)}}function la(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Mr=0;class A{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=Mr++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new A(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:Tr),!!e.static,e.enables)}of(e){return new un([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new un(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new un(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Tr(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class un{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Mr++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,c=!1,h=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?c=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||h.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||c&&(u.docChanged||u.selection)||Ls(f,h)){let d=i(f);if(l?!ho(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[r];if(p!=null){let g=Cn(u,p);if(this.dependencies.every(y=>y instanceof A?u.facet(y)===f.facet(y):y instanceof Q?u.field(y,!1)==f.field(y,!1):!0)||(l?ho(d=i(f),g,s):s(d=i(f),g)))return f.values[o]=g,0}else d=i(f);return f.values[o]=d,1}}}}function ho(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function Ls(n,e){let t=!1;for(let i of e)di(n,i)&1&&(t=!0);return t}function Vf(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let c=[];for(let h=0;h<i.length;h++){let f=Cn(a,i[h]);if(s[h]==2)for(let u of f)c.push(u);else c.push(f)}return e.combine(c)}return{create(a){for(let c of i)di(a,c);return a.values[o]=l(a),1},update(a,c){if(!Ls(a,r))return 0;let h=l(a);return e.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,c){let h=Ls(a,i),f=c.config.facets[e.id],u=c.facet(e);if(f&&!h&&Tr(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const co=A.define({static:!0});class Q{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new Q(Mr++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(co).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}init(e){return[this,co.of({field:this,create:e})]}get extension(){return this}}const gt={lowest:4,low:3,default:2,high:1,highest:0};function ti(n){return e=>new aa(e,n)}const pt={highest:ti(gt.highest),high:ti(gt.high),default:ti(gt.default),low:ti(gt.low),lowest:ti(gt.lowest)};class aa{constructor(e,t){this.inner=e,this.prec=t}}class Kn{of(e){return new Is(this,e)}reconfigure(e){return Kn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Is{constructor(e,t){this.compartment=e,this.inner=t}}class kn{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let u of Hf(e,t,o))u instanceof Q?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],c=[];for(let u of s)l[u.id]=c.length<<1,c.push(d=>u.slot(d));let h=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=h&&h[u]||[];if(d.every(y=>y.type==0))if(l[p.id]=a.length<<1|1,Tr(g,d))a.push(i.facet(p));else{let y=p.combine(d.map(b=>b.value));a.push(i&&p.compare(y,i.facet(p))?i.facet(p):y)}else{for(let y of d)y.type==0?(l[y.id]=a.length<<1|1,a.push(y.value)):(l[y.id]=c.length<<1,c.push(b=>y.dynamicSlot(b)));l[p.id]=c.length<<1,c.push(y=>Vf(y,p,d))}}let f=c.map(u=>u(l));return new kn(e,o,f,l,a,r)}}function Hf(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let c=i[a].indexOf(o);c>-1&&i[a].splice(c,1),o instanceof Is&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let c of o)r(c,l);else if(o instanceof Is){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let c=e.get(o.compartment)||o.inner;t.set(o.compartment,c),r(c,l)}else if(o instanceof aa)r(o.inner,o.prec);else if(o instanceof Q)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof un)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,gt.default);else{let c=o.extension;if(!c)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(c,l)}}return r(n,gt.default),i.reduce((o,l)=>o.concat(l))}function di(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function Cn(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const ha=A.define(),Ns=A.define({combine:n=>n.some(e=>e),static:!0}),ca=A.define({combine:n=>n.length?n[0]:void 0,static:!0}),fa=A.define(),ua=A.define(),da=A.define(),pa=A.define({combine:n=>n.length?n[0]:!1});class Ne{constructor(e,t){this.type=e,this.value=t}static define(){return new Wf}}class Wf{of(e){return new Ne(this,e)}}class $f{constructor(e){this.map=e}of(e){return new D(this,e)}}class D{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new D(this.type,t)}is(e){return this.type==e}static define(e={}){return new $f(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}}D.reconfigure=D.define();D.appendConfig=D.define();class Y{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&la(i,t.newLength),r.some(l=>l.type==Y.time)||(this.annotations=r.concat(Y.time.of(Date.now())))}static create(e,t,i,s,r,o){return new Y(e,t,i,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Y.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Y.time=Ne.define();Y.userEvent=Ne.define();Y.addToHistory=Ne.define();Y.remote=Ne.define();function zf(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function ma(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=ee.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:D.mapEffects(n.effects,s).concat(D.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Fs(n,e,t){let i=e.selection,s=It(e.annotations);return e.userEvent&&(s=s.concat(Y.userEvent.of(e.userEvent))),{changes:e.changes instanceof ee?e.changes:ee.of(e.changes||[],t,n.facet(ca)),selection:i&&(i instanceof x?i:x.single(i.anchor,i.head)),effects:It(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function ga(n,e,t){let i=Fs(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=ma(i,Fs(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=Y.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return qf(t?jf(s):s)}function jf(n){let e=n.startState,t=!0;for(let s of e.facet(fa)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:zf(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=ee.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=Y.create(e,s,n.selection&&n.selection.map(r),D.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(ua);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof Y?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Y?n=r[0]:n=ga(e,It(r),!1)}return n}function qf(n){let e=n.startState,t=e.facet(da),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=ma(i,Fs(e,r,n.changes.newLength),!0))}return i==n?n:Y.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const Kf=[];function It(n){return n==null?Kf:Array.isArray(n)?n:[n]}var z=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(z||(z={}));const _f=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Vs;try{Vs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Jf(n){if(Vs)return Vs.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||_f.test(t)))return!0}return!1}function Uf(n){return e=>{if(!/\S/.test(e))return z.Space;if(Jf(e))return z.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return z.Word;return z.Other}}class P{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)di(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return di(this,i),Cn(this,i)}update(...e){return ga(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let l of e.effects)l.is(Kn.reconfigure)?(t&&(s=new Map,t.compartments.forEach((a,c)=>s.set(c,a)),t=null),s.set(l.value.compartment,l.value.extension)):l.is(D.reconfigure)?(t=null,i=l.value):l.is(D.appendConfig)&&(t=null,i=It(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=kn.resolve(i,s,this),r=new P(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,c)=>c.reconfigure(a,this),null).values);let o=e.startState.facet(Ns)?e.newSelection:e.newSelection.asSingle();new P(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:x.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=It(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),c=this.changes(a.changes),h=c.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(h);let f=s.mapDesc(c,!0);r.push(a.range.map(f)),s=s.compose(h),o=D.mapEffects(o,h).concat(D.mapEffects(It(a.effects),f))}return{changes:s,selection:x.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof ee?e:ee.of(e,this.doc.length,this.facet(P.lineSeparator))}toText(e){return B.of(e.split(this.facet(P.lineSeparator)||Ps))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(di(this,t),Cn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof Q&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return P.create({doc:e.doc,selection:x.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=kn.resolve(e.extensions||[],new Map),i=e.doc instanceof B?e.doc:B.of((e.doc||"").split(t.staticFacet(P.lineSeparator)||Ps)),s=e.selection?e.selection instanceof x?e.selection:x.single(e.selection.anchor,e.selection.head):x.single(0);return la(s,i.length),t.staticFacet(Ns)||(s=s.asSingle()),new P(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(P.tabSize)}get lineBreak(){return this.facet(P.lineSeparator)||`
|
|
5
|
+
`}get readOnly(){return this.facet(pa)}phrase(e,...t){for(let i of this.facet(P.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let s=[];for(let r of this.facet(ha))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){return Uf(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=re(t,o,!1);if(r(t.slice(a,o))!=z.Word)break;o=a}for(;l<s;){let a=re(t,l);if(r(t.slice(l,a))!=z.Word)break;l=a}return o==l?null:x.range(o+i,l+i)}}P.allowMultipleSelections=Ns;P.tabSize=A.define({combine:n=>n.length?n[0]:4});P.lineSeparator=ca;P.readOnly=pa;P.phrases=A.define({compare(n,e){let t=Object.keys(n),i=Object.keys(e);return t.length==i.length&&t.every(s=>n[s]==e[s])}});P.languageData=ha;P.changeFilter=fa;P.transactionFilter=ua;P.transactionExtender=da;Kn.reconfigure=D.define();function Je(n,e,t={}){let i={};for(let s of n)for(let r of Object.keys(s)){let o=s[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)i[s]===void 0&&(i[s]=e[s]);return i}class ct{eq(e){return this==e}range(e,t=e){return xi.create(e,t,this)}}ct.prototype.startSide=ct.prototype.endSide=0;ct.prototype.point=!1;ct.prototype.mapMode=te.TrackDel;class xi{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new xi(e,t,i)}}function Hs(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class Or{constructor(e,t,i,s){this.from=e,this.to=t,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,c=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return c>=0?o:l;c>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let c=this.value[a],h=this.from[a]+e,f=this.to[a]+e,u,d;if(h==f){let p=t.mapPos(h,c.startSide,c.mapMode);if(p==null||(u=d=p,c.startSide!=c.endSide&&(d=t.mapPos(h,c.endSide),d<u)))continue}else if(u=t.mapPos(h,c.startSide),d=t.mapPos(f,c.endSide),u>d||u==d&&c.startSide>0&&c.endSide<=0)continue;(d-u||c.endSide-c.startSide)<0||(o<0&&(o=u),c.point&&(l=Math.max(l,d-u)),i.push(c),s.push(u-o),r.push(d-o))}return{mapped:i.length?new Or(s,r,i,l):null,pos:o}}}class R{constructor(e,t,i,s){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=s}static create(e,t,i,s){return new R(e,t,i,s)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(Hs)),this.isEmpty)return t.length?R.of(t):this;let l=new ya(this,null,-1).goto(0),a=0,c=[],h=new ft;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];h.addInner(f.from,f.to,f.value)||c.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&h.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(h.addInner(l.from,l.to,l.value)||c.push(xi.create(l.from,l.to,l.value))),l.next());return h.finishInner(this.nextLayer.isEmpty&&!c.length?R.empty:this.nextLayer.update({add:c,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],c=e.touchesRange(l,l+a.length);if(c===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(c===!0){let{mapped:h,pos:f}=a.map(l,e);h&&(s=Math.max(s,h.maxPoint),t.push(h),i.push(f))}}let r=this.nextLayer.map(e);return t.length==0?r:new R(i,t,r||R.empty,s)}between(e,t,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return vi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return vi.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=fo(o,l,i),c=new ii(o,a,r),h=new ii(l,a,r);i.iterGaps((f,u,d)=>uo(c,f,h,u,d,s)),i.empty&&i.length==0&&uo(c,0,h,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=999999999);let r=e.filter(h=>!h.isEmpty&&t.indexOf(h)<0),o=t.filter(h=>!h.isEmpty&&e.indexOf(h)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=fo(r,o),a=new ii(r,l,0).goto(i),c=new ii(o,l,0).goto(i);for(;;){if(a.to!=c.to||!Ws(a.active,c.active)||a.point&&(!c.point||!a.point.eq(c.point)))return!1;if(a.to>s)return!0;a.next(),c.next()}}static spans(e,t,i,s,r=-1){let o=new ii(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let c=Math.min(o.to,i);if(o.point){let h=o.activeForPoint(o.to),f=o.pointFrom<t?h.length+1:o.point.startSide<0?h.length:Math.min(h.length,a);s.point(l,c,o.point,h,f,o.pointRank),a=Math.min(o.openEnd(c),h.length)}else c>l&&(s.span(l,c,o.active,a),a=o.openEnd(c));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new ft;for(let s of e instanceof xi?[e]:t?Yf(e):e)i.add(s.from,s.to,s.value);return i.finish()}static join(e){if(!e.length)return R.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let s=e[i];s!=R.empty;s=s.nextLayer)t=new R(s.chunkPos,s.chunk,t,Math.max(s.maxPoint,t.maxPoint));return t}}R.empty=new R([],[],null,-1);function Yf(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(Hs(e,i)>0)return n.slice().sort(Hs);e=i}return n}R.empty.nextLayer=R.empty;class ft{finishChunk(e){this.chunks.push(new Or(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new ft)).add(e,t,i)}addInner(e,t,i){let s=e-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(R.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=R.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function fo(n,e,t){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}class ya{constructor(e,t,i,s=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class vi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new ya(o,t,i,r));return s.length==1?s[0]:new vi(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)os(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)os(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),os(this.heap,0)}}}function os(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let s=n[i];if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),t.compare(s)<0)break;n[i]=t,n[e]=s,e=i}}class ii{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=vi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ji(this.active,e),ji(this.activeTo,e),ji(this.activeRank,e),this.minActive=po(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||s-this.activeTo[t])>0;)t++;qi(this.active,t,i),qi(this.activeTo,t,s),qi(this.activeRank,t,r),e&&qi(e,t,this.cursor.from),this.minActive=po(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&ji(i,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function uo(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e;for(;;){let c=n.to+a-t.to||n.endSide-t.endSide,h=c<0?n.to+a:t.to,f=Math.min(h,o);if(n.point||t.point?n.point&&t.point&&(n.point==t.point||n.point.eq(t.point))&&Ws(n.activeForPoint(n.to),t.activeForPoint(t.to))||r.comparePoint(l,f,n.point,t.point):f>l&&!Ws(n.active,t.active)&&r.compareRange(l,f,n.active,t.active),h>o)break;l=h,c<=0&&n.next(),c>=0&&t.next()}}function Ws(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!n[t].eq(e[t]))return!1;return!0}function ji(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function qi(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function po(n,e){let t=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||n[s].endSide-n[t].endSide)<0&&(t=s,i=e[s]);return t}function Yt(n,e,t=n.length){let i=0;for(let s=0;s<t;)n.charCodeAt(s)==9?(i+=e-i%e,s++):(i++,s=re(n,s));return i}function $s(n,e,t,i){for(let s=0,r=0;;){if(r>=e)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?t-r%t:1,s=re(n,s)}return i===!0?-1:n.length}function wi(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function zs(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function Gf(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function dn(n,e){if(!e.anchorNode)return!1;try{return zs(n,e.anchorNode)}catch{return!1}}function zt(n){return n.nodeType==3?St(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function pi(n,e,t,i){return t?mo(n,e,t,i,-1)||mo(n,e,t,i,1):!1}function wt(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function An(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function mo(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:Qe(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=wt(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=s<0?Qe(n):0}else return!1}}function Qe(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function _n(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Xf(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function ba(n,e){let t=e.width/n.offsetWidth,i=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-n.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Qf(n,e,t,i,s,r,o,l){let a=n.ownerDocument,c=a.defaultView||window;for(let h=n,f=!1;h&&!f;)if(h.nodeType==1){let u,d=h==a.body,p=1,g=1;if(d)u=Xf(c);else{if(/^(fixed|sticky)$/.test(getComputedStyle(h).position)&&(f=!0),h.scrollHeight<=h.clientHeight&&h.scrollWidth<=h.clientWidth){h=h.assignedSlot||h.parentNode;continue}let v=h.getBoundingClientRect();({scaleX:p,scaleY:g}=ba(h,v)),u={left:v.left,right:v.left+h.clientWidth*p,top:v.top,bottom:v.top+h.clientHeight*g}}let y=0,b=0;if(s=="nearest")e.top<u.top?(b=-(u.top-e.top+o),t>0&&e.bottom>u.bottom+b&&(b=e.bottom-u.bottom+b+o)):e.bottom>u.bottom&&(b=e.bottom-u.bottom+o,t<0&&e.top-b<u.top&&(b=-(u.top+b-e.top+o)));else{let v=e.bottom-e.top,M=u.bottom-u.top;b=(s=="center"&&v<=M?e.top+v/2-M/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-M+o)-u.top}if(i=="nearest"?e.left<u.left?(y=-(u.left-e.left+r),t>0&&e.right>u.right+y&&(y=e.right-u.right+y+r)):e.right>u.right&&(y=e.right-u.right+r,t<0&&e.left<u.left+y&&(y=-(u.left+y-e.left+r))):y=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,y||b)if(d)c.scrollBy(y,b);else{let v=0,M=0;if(b){let S=h.scrollTop;h.scrollTop+=b/g,M=(h.scrollTop-S)*g}if(y){let S=h.scrollLeft;h.scrollLeft+=y/p,v=(h.scrollLeft-S)*p}e={left:e.left-v,top:e.top-M,right:e.right-v,bottom:e.bottom-M},v&&Math.abs(v-y)<1&&(i="nearest"),M&&Math.abs(M-b)<1&&(s="nearest")}if(d)break;h=h.assignedSlot||h.parentNode}else if(h.nodeType==11)h=h.host;else break}function Zf(n){let e=n.ownerDocument,t,i;for(let s=n.parentNode;s&&!(s==e.body||t&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),!t&&s.scrollWidth>s.clientWidth&&(t=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:t,y:i}}class eu{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?Qe(t):0),i,Math.min(e.focusOffset,i?Qe(i):0))}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let Mt=null;function xa(n){if(n.setActive)return n.setActive();if(Mt)return n.focus(Mt);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Mt==null?{get preventScroll(){return Mt={preventScroll:!0},!0}}:void 0),!Mt){Mt=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let go;function St(n,e,t=e){let i=go||(go=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function Nt(n,e,t,i){let s={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function tu(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function va(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function iu(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,Qe(t));;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=Qe(t))}else{if(t==n)return!0;i=wt(t),t=t.parentNode}}function wa(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Sa(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=Qe(t)}else if(t.parentNode&&!An(t))i=wt(t),t=t.parentNode;else return null}}function ka(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!An(t))i=wt(t)+1,t=t.parentNode;else return null}}class le{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new le(e.parentNode,wt(e),t)}static after(e,t){return new le(e.parentNode,wt(e)+1,t)}}const Dr=[];class F{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let i of this.children){if(i==e)return t;t+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}sync(e,t){if(this.flags&2){let i=this.dom,s=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=s?s.nextSibling:i.firstChild)){let l=F.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(e,t),o.flags&=-8}if(r=s?s.nextSibling:i.firstChild,t&&!t.written&&t.node==i&&r!=o.dom&&(t.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=yo(r);else i.insertBefore(o.dom,r);s=o.dom}for(r=s?s.nextSibling:i.firstChild,r&&t&&t.node==i&&(t.written=!0);r;)r=yo(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(e,t),i.flags&=-8)}reuseDOM(e){}localPosFromDOM(e,t){let i;if(e==this.dom)i=this.dom.childNodes[t];else{let s=Qe(e)==0?0:t==0?-1:1;for(;;){let r=e.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(e==r.firstChild?s=-1:s=1),e=r}s<0?i=e:i=e.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!F.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,i=0){let s=-1,r=-1,o=-1,l=-1;for(let a=0,c=i,h=i;a<this.children.length;a++){let f=this.children[a],u=c+f.length;if(c<e&&u>t)return f.domBoundsAround(e,t,c);if(u>=e&&s==-1&&(s=a,r=c),c>t&&f.dom.parentNode==this.dom){o=a,l=h;break}h=u,c=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=Dr){this.markDirty();for(let s=e;s<t;s++){let r=this.children[s];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(e,t-e,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new Ca(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(e,t,i,s,r,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor&&!((this.flags|e.flags)&8)}getSide(){return 0}destroy(){for(let e of this.children)e.parent==this&&e.destroy();this.parent=null}}F.prototype.breakAfter=0;function yo(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Ca{constructor(e,t,i){this.children=e,this.pos=t,this.i=i,this.off=0}findPos(e,t=1){for(;;){if(e>this.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Aa(n,e,t,i,s,r,o,l,a){let{children:c}=n,h=c.length?c[e]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(e==i&&h&&!o&&!u&&r.length<2&&h.merge(t,s,r.length?f:null,t==0,l,a))){if(i<c.length){let d=c[i];d&&(s<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(e==i&&(d=d.split(s),s=0),!u&&f&&d.merge(0,s,f,!0,0,a)?r[r.length-1]=d:((s||d.children.length&&!d.children[0].length)&&d.merge(0,s,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(h&&(h.breakAfter=o,t>0&&(!o&&r.length&&h.merge(t,h.length,r[0],!1,l,0)?h.breakAfter=r.shift().breakAfter:(t<h.length||h.children.length&&h.children[h.children.length-1].length==0)&&h.merge(t,h.length,null,!1,l,0),e++));e<i&&r.length;)if(c[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(c[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&i<c.length&&!c[e-1].breakAfter&&c[i].merge(0,0,c[e-1],!1,l,a)&&e--,(e<i||r.length)&&n.replaceChildren(e,i,r)}}function Ma(n,e,t,i,s,r){let o=n.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:c,off:h}=o.findPos(e,-1),f=e-t;for(let u of i)f+=u.length;n.length+=f,Aa(n,c,h,l,a,i,0,s,r)}let pe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},js=typeof document<"u"?document:{documentElement:{style:{}}};const qs=/Edge\/(\d+)/.exec(pe.userAgent),Ta=/MSIE \d/.test(pe.userAgent),Ks=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(pe.userAgent),Jn=!!(Ta||Ks||qs),bo=!Jn&&/gecko\/(\d+)/i.test(pe.userAgent),ls=!Jn&&/Chrome\/(\d+)/.exec(pe.userAgent),nu="webkitFontSmoothing"in js.documentElement.style,Oa=!Jn&&/Apple Computer/.test(pe.vendor),xo=Oa&&(/Mobile\/\w+/.test(pe.userAgent)||pe.maxTouchPoints>2);var C={mac:xo||/Mac/.test(pe.platform),windows:/Win/.test(pe.platform),linux:/Linux|X11/.test(pe.platform),ie:Jn,ie_version:Ta?js.documentMode||6:Ks?+Ks[1]:qs?+qs[1]:0,gecko:bo,gecko_version:bo?+(/Firefox\/(\d+)/.exec(pe.userAgent)||[0,0])[1]:0,chrome:!!ls,chrome_version:ls?+ls[1]:0,ios:xo,android:/Android\b/.test(pe.userAgent),safari:Oa,webkit_version:nu?+(/\bAppleWebKit\/(\d+)/.exec(pe.userAgent)||[0,0])[1]:0,tabSize:js.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const su=256;class Le extends F{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return this.flags&8||i&&(!(i instanceof Le)||this.length-(t-e)+i.length>su||i.flags&8)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new Le(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new le(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return ru(this.dom,e,t)}}class Ze extends F{constructor(e,t=[],i=0){super(),this.mark=e,this.children=t,this.length=i;for(let s of t)s.setParent(this)}setAttrs(e){if(va(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,i,s,r,o){return i&&(!(i instanceof Ze&&i.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(Ma(this,e,t,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],i=0,s=-1,r=0;for(let l of this.children){let a=i+l.length;a>e&&t.push(i<e?l.split(e-i):l),s<0&&i>=e&&(s=r),i=a,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new Ze(this.mark,t,o)}domAtPos(e){return Da(this,e)}coordsAt(e,t){return Pa(this,e,t)}}function ru(n,e,t){let i=n.nodeValue.length;e>i&&(e=i);let s=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?C.chrome||C.gecko||(e?(s--,o=1):r<i&&(r++,o=-1)):t<0?s--:r<i&&r++;let l=St(n,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return C.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,c=>c.width)||a),o?_n(a,o<0):a||null}class rt extends F{static create(e,t,i){return new rt(e,t,i)}constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}split(e){let t=rt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(e,t,i,s,r,o){return i&&(!(i instanceof rt)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}become(e){return e instanceof rt&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.compare(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return B.empty;let e=this;for(;e.parent;)e=e.parent;let{view:t}=e,i=t&&t.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):B.empty}domAtPos(e){return(this.length?e==0:this.side>0)?le.before(this.dom):le.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let o=this.side?this.side<0:e>0;for(let l=o?s.length-1:0;r=s[l],!(e>0?l==0:l==s.length-1||r.top<r.bottom);l+=o?-1:1);return _n(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class jt extends F{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof jt&&e.side==this.side}split(){return new jt(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return this.side>0?le.before(this.dom):le.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return B.empty}get isHidden(){return!0}}Le.prototype.children=rt.prototype.children=jt.prototype.children=Dr;function Da(n,e){let t=n.dom,{children:i}=n,s=0;for(let r=0;s<i.length;s++){let o=i[s],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(e>r&&e<l&&o.dom.parentNode==t)return o.domAtPos(e-r);if(e<=r)break;r=l}}for(let r=s;r>0;r--){let o=i[r-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let r=s;r<i.length;r++){let o=i[r];if(o.dom.parentNode==t)return o.domAtPos(0)}return new le(t,0)}function Ea(n,e,t){let i,{children:s}=n;t>0&&e instanceof Ze&&s.length&&(i=s[s.length-1])instanceof Ze&&i.mark.eq(e.mark)?Ea(i,e.children[0],t-1):(s.push(e),e.setParent(n)),n.length+=e.length}function Pa(n,e,t){let i=null,s=-1,r=null,o=-1;function l(c,h){for(let f=0,u=0;f<c.children.length&&u<=h;f++){let d=c.children[f],p=u+d.length;p>=h&&(d.children.length?l(d,h-u):(!r||r.isHidden&&t>0)&&(p>h||u==p&&d.getSide()>0)?(r=d,o=h-u):(u<h||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,s=h-u)),u=p}}l(n,e);let a=(t<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?s:o),t):ou(n)}function ou(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=zt(e);return t[t.length-1]||null}function _s(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const vo=Object.create(null);function Mn(n,e,t){if(n==e)return!0;n||(n=vo),e||(e=vo);let i=Object.keys(n),s=Object.keys(e);if(i.length-(t&&i.indexOf(t)>-1?1:0)!=s.length-(t&&s.indexOf(t)>-1?1:0))return!1;for(let r of i)if(r!=t&&(s.indexOf(r)==-1||n[r]!==e[r]))return!1;return!0}function Js(n,e,t){let i=!1;if(e)for(let s in e)t&&s in t||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(i=!0,s=="style"?n.style.cssText=t[s]:n.setAttribute(s,t[s]));return i}function lu(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class X extends F{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,s,r,o){if(i){if(!(i instanceof X))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ma(this,e,t,i?i.children.slice():[],r,o),!0}split(e){let t=new X;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:s}=this.childPos(e);s&&(t.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)t.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){Mn(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Ea(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=_s(t,this.attrs||{})),i&&(this.attrs=_s({class:i},this.attrs||{}))}domAtPos(e){return Da(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var i;this.dom?this.flags&4&&(va(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(Js(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let s=this.dom.lastChild;for(;s&&F.get(s)instanceof Ze;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=F.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!C.ios||!this.children.some(r=>r instanceof Le))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let i of this.children){if(!(i instanceof Le)||/[^ -~]/.test(i.text))return null;let s=zt(i.dom);if(s.length!=1)return null;e+=s[0].width,t=s[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let i=Pa(this,e,t);if(!this.children.length&&i&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let o=(r-s.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(e){return e instanceof X&&this.children.length==0&&e.children.length==0&&Mn(this.attrs,e.attrs)&&this.breakAfter==e.breakAfter}covers(){return!0}static find(e,t){for(let i=0,s=0;i<e.children.length;i++){let r=e.children[i],o=s+r.length;if(o>=t){if(r instanceof X)return r;if(o>t)break}s=o+r.breakAfter}return null}}class Xe extends F{constructor(e,t,i){super(),this.widget=e,this.length=t,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,s,r,o){return i&&(!(i instanceof Xe)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}domAtPos(e){return e==0?le.before(this.dom):le.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let i=new Xe(this.widget,t,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Dr}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):B.empty}domBoundsAround(){return null}become(e){return e instanceof Xe&&e.widget.constructor==this.widget.constructor?(e.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.deco=e.deco,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(e,t){return this.widget.coordsAt(this.dom,e,t)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(e){let{startSide:t,endSide:i}=this.deco;return t==i?!1:e<0?t<0:i>0}}class Fe{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var ce=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(ce||(ce={}));class T extends ct{constructor(e,t,i,s){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(e){return new Li(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ut(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,s;if(e.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Ba(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new ut(e,i,s,t,e.widget||null,!0)}static line(e){return new Ii(e)}static set(e,t=!1){return R.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}T.none=R.empty;class Li extends T{constructor(e){let{start:t,end:i}=Ba(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,i;return this==e||e instanceof Li&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((i=e.attrs)===null||i===void 0?void 0:i.class))&&Mn(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Li.prototype.point=!1;class Ii extends T{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Ii&&this.spec.class==e.spec.class&&Mn(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Ii.prototype.mapMode=te.TrackBefore;Ii.prototype.point=!0;class ut extends T{constructor(e,t,i,s,r,o){super(t,i,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?te.TrackBefore:te.TrackAfter:te.TrackDel}get type(){return this.startSide!=this.endSide?ce.WidgetRange:this.startSide<=0?ce.WidgetBefore:ce.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof ut&&au(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}ut.prototype.point=!0;function Ba(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function au(n,e){return n==e||!!(n&&e&&n.compare(e))}function Us(n,e,t,i=0){let s=t.length-1;s>=0&&t[s]+i>=n?t[s]=Math.max(t[s],e):t.push(n,e)}class mi{constructor(e,t,i,s){this.doc=e,this.pos=t,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof Xe&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new X),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ki(new jt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof Xe)&&this.getLine()}buildText(e,t,i){for(;e>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(Ki(new Le(this.text.slice(this.textOff,this.textOff+s)),t),i),this.atCursorPos=!0,this.textOff+=s,e-=s,i=0}}span(e,t,i,s){this.buildText(t-e,i,s),this.pos=t,this.openStart<0&&(this.openStart=s)}point(e,t,i,s,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ut){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(i instanceof ut)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new Xe(i.widget||qt.block,l,i));else{let a=rt.create(i.widget||qt.inline,l,l?0:i.startSide),c=this.atCursorPos&&!a.isEditable&&r<=s.length&&(e<t||i.startSide>0),h=!a.isEditable&&(e<t||r>s.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!c&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),c&&(f.append(Ki(new jt(1),s),r),r=s.length+Math.max(0,r-s.length)),f.append(Ki(a,s),r),this.atCursorPos=h,this.pendingBuffer=h?e<t||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,i,s,r){let o=new mi(e,t,i,r);return o.openEnd=R.spans(s,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Ki(n,e){for(let t of e)n=new Ze(t,[n],n.length);return n}class qt extends Fe{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}qt.inline=new qt("span");qt.block=new qt("div");var W=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(W||(W={}));const kt=W.LTR,Er=W.RTL;function Ra(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const hu=Ra("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),cu=Ra("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ys=Object.create(null),We=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Ys[e]=t,Ys[t]=-e}function La(n){return n<=247?hu[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?cu[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const fu=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class ot{get dir(){return this.level%2?Er:kt}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Ia(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],s=e[t];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!Ia(i.inner,s.inner))return!1}return!0}const N=[];function uu(n,e,t,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:s;for(let c=o,h=a,f=a;c<l;c++){let u=La(n.charCodeAt(c));u==512?u=h:u==8&&f==4&&(u=16),N[c]=u==4?2:u,u&7&&(f=u),h=u}for(let c=o,h=a,f=a;c<l;c++){let u=N[c];if(u==128)c<l-1&&h==N[c+1]&&h&24?u=N[c]=h:N[c]=256;else if(u==64){let d=c+1;for(;d<l&&N[d]==64;)d++;let p=c&&h==8||d<t&&N[d]==8?f==1?1:8:256;for(let g=c;g<d;g++)N[g]=p;c=d-1}else u==8&&f==1&&(N[c]=1);h=u,u&7&&(f=u)}}}function du(n,e,t,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let c=o?i[o-1].to:e,h=o<i.length?i[o].from:t;for(let f=c,u,d,p;f<h;f++)if(d=Ys[u=n.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(We[g+1]==-d){let y=We[g+2],b=y&2?s:y&4?y&1?r:s:0;b&&(N[f]=N[We[g]]=b),l=g;break}}else{if(We.length==189)break;We[l++]=f,We[l++]=u,We[l++]=a}else if((p=N[f])==2||p==1){let g=p==s;a=g?0:1;for(let y=l-3;y>=0;y-=3){let b=We[y+2];if(b&2)break;if(g)We[y+2]|=2;else{if(b&4)break;We[y+2]|=4}}}}}function pu(n,e,t,i){for(let s=0,r=i;s<=t.length;s++){let o=s?t[s-1].to:n,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let c=N[a];if(c==256){let h=a+1;for(;;)if(h==l){if(s==t.length)break;h=t[s++].to,l=s<t.length?t[s].from:e}else if(N[h]==256)h++;else break;let f=r==1,u=(h<e?N[h]:i)==1,d=f==u?f?1:2:i;for(let p=h,g=s,y=g?t[g-1].to:n;p>a;)p==y&&(p=t[--g].from,y=g?t[g-1].to:n),N[--p]=d;a=h}else r=c,a++}}}function Gs(n,e,t,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=e,c=0;a<t;){let h=!0,f=!1;if(c==r.length||a<r[c].from){let g=N[a];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(c<r.length&&p==r[c].from){if(f)break e;let g=r[c];if(!h)for(let y=g.to,b=c+1;;){if(y==t)break e;if(b<r.length&&r[b].from==y)y=r[b++].to;else{if(N[y]==l)break e;break}}if(c++,u)u.push(g);else{g.from>a&&o.push(new ot(a,g.from,d));let y=g.direction==kt!=!(d%2);Xs(n,y?i+1:i,s,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==t||(h?N[p]!=l:N[p]==l))break;p++}u?Gs(n,a,p,i+1,s,u,o):a<p&&o.push(new ot(a,p,d)),a=p}else for(let a=t,c=r.length;a>e;){let h=!0,f=!1;if(!c||a>r[c-1].to){let g=N[a-1];g!=l&&(h=!1,f=g==16)}let u=!h&&l==1?[]:null,d=h?i:i+1,p=a;e:for(;;)if(c&&p==r[c-1].to){if(f)break e;let g=r[--c];if(!h)for(let y=g.from,b=c;;){if(y==e)break e;if(b&&r[b-1].to==y)y=r[--b].from;else{if(N[y-1]==l)break e;break}}if(u)u.push(g);else{g.to<a&&o.push(new ot(g.to,a,d));let y=g.direction==kt!=!(d%2);Xs(n,y?i+1:i,s,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==e||(h?N[p-1]!=l:N[p-1]==l))break;p--}u?Gs(n,p,a,i+1,s,u,o):p<a&&o.push(new ot(p,a,d)),a=p}}function Xs(n,e,t,i,s,r,o){let l=e%2?2:1;uu(n,s,r,i,l),du(n,s,r,i,l),pu(s,r,i,l),Gs(n,s,r,e,t,i,o)}function mu(n,e,t){if(!n)return[new ot(0,0,e==Er?1:0)];if(e==kt&&!t.length&&!fu.test(n))return Na(n.length);if(t.length)for(;n.length>N.length;)N[N.length]=256;let i=[],s=e==kt?0:1;return Xs(n,s,s,t,0,n.length,i),i}function Na(n){return[new ot(0,n,0)]}let Fa="";function gu(n,e,t,i,s){var r;let o=i.head-n.from,l=ot.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],c=a.side(s,t);if(o==c){let u=l+=s?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!s,t),c=a.side(s,t)}let h=re(n.text,o,a.forward(s,t));(h<a.from||h>a.to)&&(h=c),Fa=n.text.slice(Math.min(o,h),Math.max(o,h));let f=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return f&&h==c&&f.level+(s?0:1)<a.level?x.cursor(f.side(!s,t)+n.from,f.forward(s,t)?1:-1,f.level):x.cursor(h+n.from,a.forward(s,t)?-1:1,a.level)}function yu(n,e,t){for(let i=e;i<t;i++){let s=La(n.charCodeAt(i));if(s==1)return kt;if(s==2||s==4)return Er}return kt}const Va=A.define(),Ha=A.define(),Wa=A.define(),$a=A.define(),Qs=A.define(),za=A.define(),ja=A.define(),qa=A.define({combine:n=>n.some(e=>e)}),Ka=A.define({combine:n=>n.some(e=>e)}),_a=A.define();class Ft{constructor(e,t="nearest",i="nearest",s=5,r=5,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new Ft(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Ft(x.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const _i=D.define({map:(n,e)=>n.map(e)}),Ja=D.define();function he(n,e,t){let i=n.facet($a);i.length?i[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}const it=A.define({combine:n=>n.length?n[0]:!0});let bu=0;const li=A.define();class _{constructor(e,t,i,s,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(e,t){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=t||{};return new _(bu++,e,i,s,l=>{let a=[li.of(l)];return o&&a.push(Si.of(c=>{let h=c.plugin(l);return h?o(h):T.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return _.define(i=>new e(i),t)}}class as{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(he(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){he(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){he(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Ua=A.define(),Pr=A.define(),Si=A.define(),Ya=A.define(),Br=A.define(),Ga=A.define();function wo(n,e){let t=n.state.facet(Ga);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(n):r),s=[];return R.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let c=r-e.from,h=o-e.from,f=s;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=yu(e.text,c,h)),a>0&&f.length&&(p=f[f.length-1]).to==c&&p.direction==d)p.to=h,f=p.inner;else{let g={from:c,to:h,direction:d,inner:[]};f.push(g),f=g.inner}}}}),s}const Xa=A.define();function Qa(n){let e=0,t=0,i=0,s=0;for(let r of n.state.facet(Xa)){let o=r(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:i,bottom:s}}const ai=A.define();class Ae{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new Ae(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==e.length?null:e[s],c=o-l,h=a?a.fromB:1e9;for(;r<t.length&&t[r]<h;){let f=t[r],u=t[r+1],d=Math.max(l,f),p=Math.min(h,u);if(d<=p&&new Ae(d+c,p+c,d,p).addToSet(i),u>h)break;r+=2}if(!a)return i;new Ae(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class Tn{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=ee.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new Ae(r,o,l,a))),this.changedRanges=s}static create(e,t,i){return new Tn(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class So extends F{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=T.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new X],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ae(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:h})=>h<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?s=this.domChanged.newSel.head:!Au(e.changes,this.hasComposition)&&!e.selectionSet&&(s=e.state.selection.main.head));let r=s>-1?vu(this.view,e.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:c,to:h}=this.hasComposition;i=new Ae(c,h,e.changes.mapPos(c,-1),e.changes.mapPos(h,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(C.ie||C.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=ku(o,l,e.changes);return i=Ae.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=C.chrome||C.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||s.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof Xe&&o.widget instanceof ko&&r.push(o.dom);s.updateGaps(r)}updateChildren(e,t,i){let s=i?i.range.addToSet(e.slice()):e,r=this.childCursor(t);for(let o=s.length-1;;o--){let l=o>=0?s[o]:null;if(!l)break;let{fromA:a,toA:c,fromB:h,toB:f}=l,u,d,p,g;if(i&&i.range.fromB<f&&i.range.toB>h){let S=mi.build(this.view.state.doc,h,i.range.fromB,this.decorations,this.dynamicDecorationMap),k=mi.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=S.breakAtStart,p=S.openStart,g=k.openEnd;let O=this.compositionView(i);k.breakAtStart?O.breakAfter=1:k.content.length&&O.merge(O.length,O.length,k.content[0],!1,k.openStart,0)&&(O.breakAfter=k.content[0].breakAfter,k.content.shift()),S.content.length&&O.merge(0,0,S.content[S.content.length-1],!0,0,S.openEnd)&&S.content.pop(),u=S.content.concat(O).concat(k.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=mi.build(this.view.state.doc,h,f,this.decorations,this.dynamicDecorationMap));let{i:y,off:b}=r.findPos(c,1),{i:v,off:M}=r.findPos(a,-1);Aa(this,v,M,y,b,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(Ja)&&(this.editContextFormatting=i.value)}compositionView(e){let t=new Le(e.text.nodeValue);t.flags|=8;for(let{deco:s}of e.marks)t=new Ze(s,[t],t.length);let i=new X;return i.append(t,0),i}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=F.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(e.range.fromB,1),s=this.children[i.i];t(e.line,s);for(let r=e.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],t(r>=0?e.marks[r].node:e.text,s)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&dn(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||t||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),c=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(C.gecko&&l.empty&&!this.hasComposition&&xu(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=c=new le(f,0),o=!0}let h=this.view.observer.selectionRange;(o||!h.focusNode||(!pi(a.node,a.offset,h.anchorNode,h.anchorOffset)||!pi(c.node,c.offset,h.focusNode,h.focusOffset))&&!this.suppressWidgetCursorChange(h,l))&&(this.view.observer.ignore(()=>{C.android&&C.chrome&&this.dom.contains(h.focusNode)&&Cu(h.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=wi(this.view.root);if(f)if(l.empty){if(C.gecko){let u=wu(a.node,a.offset);if(u&&u!=3){let d=(u==1?Sa:ka)(a.node,a.offset);d&&(a=new le(d.node,d.offset))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(c.node,c.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,c]=[c,a]),u.setEnd(c.node,c.offset),u.setStart(a.node,a.offset),f.removeAllRanges(),f.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,c)),this.impreciseAnchor=a.precise?null:new le(h.anchorNode,h.anchorOffset),this.impreciseHead=c.precise?null:new le(h.focusNode,h.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&pi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=wi(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=X.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!a||!c||a.bottom>c.top)return;let h=this.domAtPos(t.head+t.assoc);i.collapse(h.node,h.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(s,r)}moveToLine(e){let t=this.dom,i;if(e.node!=t)return e;for(let s=e.offset;!i&&s<t.childNodes.length;s++){let r=F.get(t.childNodes[s]);r instanceof X&&(i=r.domAtPos(0))}for(let s=e.offset-1;!i&&s>=0;s--){let r=F.get(t.childNodes[s]);r instanceof X&&(i=r.domAtPos(r.length))}return i?new le(i.node,i.offset,!0):e}nearest(e){for(let t=e;t;){let i=F.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t<this.children.length-1;){let s=this.children[t];if(i<s.length||s instanceof X)break;t++,i=0}return this.children[t].domAtPos(i)}coordsAt(e,t){let i=null,s=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,c=a-l.length;if(a<e)break;if(c<=e&&(c<e||l.covers(-1))&&(a>e||l.covers(1))&&(!i||l instanceof X&&!(i instanceof X&&t>=0)))i=l,s=c;else if(i&&c==e&&a==e&&l instanceof Xe&&Math.abs(t)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=c}return i?i.coordsAt(e-s,t):null}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),s=this.children[t];if(!(s instanceof X))return null;for(;s.children.length;){let{i:l,off:a}=s.childPos(i,1);for(;;l++){if(l==s.children.length)return null;if((s=s.children[l]).length)break}i=a}if(!(s instanceof Le))return null;let r=re(s.text,i);if(r==i)return null;let o=St(s.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==W.LTR;for(let c=0,h=0;h<this.children.length;h++){let f=this.children[h],u=c+f.length;if(u>s)break;if(c>=i){let d=f.dom.getBoundingClientRect();if(t.push(d.height),o){let p=f.dom.lastChild,g=p?zt(p):[];if(g.length){let y=g[g.length-1],b=a?y.right-d.left:d.right-y.left;b>l&&(l=b,this.minWidth=r,this.minWidthFrom=c,this.minWidthTo=u)}}}c=u+f.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?W.RTL:W.LTR}measureTextSize(){for(let r of this.children)if(r instanceof X){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,i,s;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let r=zt(e.firstChild)[0];t=e.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:i,textHeight:s}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Ca(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(T.replace({widget:new ko(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return T.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Si).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(Ya).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[e++]=i,t.push(R.join(s))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;return this.decorations}scrollIntoView(e){if(e.isSnapshot){let c=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=c.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let c of this.view.state.facet(_a))try{if(c(this.view,e.range,e))return!0}catch(h){he(this.view.state,h,"scroll handler")}let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),s;if(!i)return;!t.empty&&(s=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let r=Qa(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;Qf(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==W.LTR)}}function xu(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}class ko extends Fe{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Za(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let i=Sa(t.focusNode,t.focusOffset),s=ka(t.focusNode,t.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=F.get(s.node);if(!l||l instanceof Le&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=F.get(i.node);!a||a instanceof Le&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function vu(n,e,t){let i=Za(n,t);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc,c=new Ae(a.mapPos(r),a.mapPos(o),r,o),h=[];for(let f=s.parentNode;;f=f.parentNode){let u=F.get(f);if(u instanceof Ze)h.push({node:f,deco:u.mark});else{if(u instanceof X||f.nodeName=="DIV"&&f.parentNode==n.contentDOM)return{range:c,text:s,marks:h,line:f};if(f!=n.contentDOM)h.push({node:f,deco:new Li({inclusive:!0,attributes:lu(f),tagName:f.tagName.toLowerCase()})});else return null}}}function wu(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let Su=class{constructor(){this.changes=[]}compareRange(e,t){Us(e,t,this.changes)}comparePoint(e,t){Us(e,t,this.changes)}};function ku(n,e,t){let i=new Su;return R.compare(n,e,t,i),i.changes}function Cu(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function Au(n,e){let t=!1;return e&&n.iterChangedRanges((i,s)=>{i<e.to&&s>e.from&&(t=!0)}),t}function Mu(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return x.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=re(s.text,r,!1):l=re(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let c=re(s.text,o,!1);if(i(s.text.slice(c,o))!=a)break;o=c}for(;l<s.length;){let c=re(s.text,l);if(i(s.text.slice(l,c))!=a)break;l=c}return x.range(o+s.from,l+s.from)}function Tu(n,e){return e.left>n?e.left-n:Math.max(0,n-e.right)}function Ou(n,e){return e.top>n?e.top-n:Math.max(0,n-e.bottom)}function hs(n,e){return n.top<e.bottom-1&&n.bottom>e.top+1}function Co(n,e){return e<n.top?{top:e,left:n.left,right:n.right,bottom:n.bottom}:n}function Ao(n,e){return e>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:e}:n}function Zs(n,e,t){let i,s,r,o,l=!1,a,c,h,f;for(let p=n.firstChild;p;p=p.nextSibling){let g=zt(p);for(let y=0;y<g.length;y++){let b=g[y];s&&hs(s,b)&&(b=Co(Ao(b,s.bottom),s.top));let v=Tu(e,b),M=Ou(t,b);if(v==0&&M==0)return p.nodeType==3?Mo(p,e,t):Zs(p,e,t);if(!i||o>M||o==M&&r>v){i=p,s=b,r=v,o=M;let S=M?t<b.top?-1:1:v?e<b.left?-1:1:0;l=!S||(S>0?y<g.length-1:y>0)}v==0?t>b.bottom&&(!h||h.bottom<b.bottom)?(a=p,h=b):t<b.top&&(!f||f.top>b.top)&&(c=p,f=b):h&&hs(h,b)?h=Ao(h,b.bottom):f&&hs(f,b)&&(f=Co(f,b.top))}}if(h&&h.bottom>=t?(i=a,s=h):f&&f.top<=t&&(i=c,s=f),!i)return{node:n,offset:0};let u=Math.max(s.left,Math.min(s.right,e));if(i.nodeType==3)return Mo(i,u,t);if(l&&i.contentEditable!="false")return Zs(i,u,t);let d=Array.prototype.indexOf.call(n.childNodes,i)+(e>=(s.left+s.right)/2?1:0);return{node:n,offset:d}}function Mo(n,e,t){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=St(n,l,l+1).getClientRects();for(let c=0;c<a.length;c++){let h=a[c];if(h.top==h.bottom)continue;o||(o=e-h.left);let f=(h.top>t?h.top-t:t-h.bottom)-1;if(h.left-1<=e&&h.right+1>=e&&f<r){let u=e>=(h.left+h.right)/2,d=u;if((C.chrome||C.gecko)&&St(n,l).getBoundingClientRect().left==h.right&&(d=!u),f<=0)return{node:n,offset:l+(d?1:0)};s=l+(d?1:0),r=f}}}return{node:n,offset:s>-1?s:o>0?n.nodeValue.length:0}}function eh(n,e,t,i=-1){var s,r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,a,{docHeight:c}=n.viewState,{x:h,y:f}=e,u=f-l;if(u<0)return 0;if(u>c)return n.state.doc.length;for(let S=n.viewState.heightOracle.textHeight/2,k=!1;a=n.elementAtHeight(u),a.type!=ce.Text;)for(;u=i>0?a.bottom+S:a.top-S,!(u>=0&&u<=c);){if(k)return t?null:0;k=!0,i=-i}f=l+u;let d=a.from;if(d<n.viewport.from)return n.viewport.from==0?0:t?null:To(n,o,a,h,f);if(d>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:t?null:To(n,o,a,h,f);let p=n.dom.ownerDocument,g=n.root.elementFromPoint?n.root:p,y=g.elementFromPoint(h,f);y&&!n.contentDOM.contains(y)&&(y=null),y||(h=Math.max(o.left+1,Math.min(o.right-1,h)),y=g.elementFromPoint(h,f),y&&!n.contentDOM.contains(y)&&(y=null));let b,v=-1;if(y&&((s=n.docView.nearest(y))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let S=p.caretPositionFromPoint(h,f);S&&({offsetNode:b,offset:v}=S)}else if(p.caretRangeFromPoint){let S=p.caretRangeFromPoint(h,f);S&&({startContainer:b,startOffset:v}=S,(!n.contentDOM.contains(b)||C.safari&&Du(b,v,h)||C.chrome&&Eu(b,v,h))&&(b=void 0))}}if(!b||!n.docView.dom.contains(b)){let S=X.find(n.docView,d);if(!S)return u>a.top+a.height/2?a.to:a.from;({node:b,offset:v}=Zs(S.dom,h,f))}let M=n.docView.nearest(b);if(!M)return null;if(M.isWidget&&((r=M.dom)===null||r===void 0?void 0:r.nodeType)==1){let S=M.dom.getBoundingClientRect();return e.y<S.top||e.y<=S.bottom&&e.x<=(S.left+S.right)/2?M.posAtStart:M.posAtEnd}else return M.localPosFromDOM(b,v)+M.posAtStart}function To(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+$s(o,r,n.state.tabSize)}function Du(n,e,t){let i;if(n.nodeType!=3||e!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return St(n,i-1,i).getBoundingClientRect().left>t}function Eu(n,e,t){if(e!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():St(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function er(n,e){let t=n.lineBlockAt(e);if(Array.isArray(t.type)){for(let i of t.type)if(i.to>e||i.to==e&&(i.to==t.to||i.type==ce.Text))return i}return t}function Pu(n,e,t,i){let s=er(n,e.head),r=!i||s.type!=ce.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==W.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return x.cursor(a,t?-1:1)}return x.cursor(t?s.to:s.from,t?-1:1)}function Oo(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let c=gu(s,r,o,l,t),h=Fa;if(!c){if(s.number==(t?n.state.doc.lines:1))return l;h=`
|
|
6
|
+
`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),c=n.visualLineSide(s,!t)}if(a){if(!a(h))return l}else{if(!i)return c;a=i(h)}l=c}}function Bu(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==z.Space&&(s=o),s==o}}function Ru(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return x.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),c=n.coordsAtPos(s,e.assoc||-1),h=n.documentTop;if(c)o==null&&(o=c.left-a.left),l=r<0?c.top:c.bottom;else{let d=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+h}let f=a.left+o,u=i??n.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=eh(n,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<s:g>s)){let y=n.docView.coordsForChar(g),b=!y||p<y.top?-1:1;return x.cursor(g,b,void 0,o)}}}function pn(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function cs(n,e,t){let i=pn(n.state.facet(Br).map(s=>s(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:x.cursor(i,i<t.from?1:-1)}class Lu{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,C.safari&&e.contentDOM.addEventListener("input",()=>null),C.gecko&&Gu(e.contentDOM.ownerDocument)}handleEvent(e){!zu(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||this.runHandlers(e.type,e)}runHandlers(e,t){let i=this.handlers[e];if(i){for(let s of i.observers)s(this.view,t);for(let s of i.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Iu(e),i=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&ih.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),C.android&&C.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return C.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=th.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||Nu.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Nt(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:C.safari&&!C.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Do(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(s){he(t.state,s)}}}function Iu(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec;if(s&&s.domEventHandlers)for(let r in s.domEventHandlers){let o=s.domEventHandlers[r];o&&t(r).handlers.push(Do(i.value,o))}if(s&&s.domEventObservers)for(let r in s.domEventObservers){let o=s.domEventObservers[r];o&&t(r).observers.push(Do(i.value,o))}}for(let i in Ie)t(i).handlers.push(Ie[i]);for(let i in Te)t(i).observers.push(Te[i]);return e}const th=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Nu="dthko",ih=[16,17,18,20,91,92,224,225],Ji=6;function Ui(n){return Math.max(0,n)*.7+8}function Fu(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class Vu{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Zf(e.contentDOM),this.atoms=e.state.facet(Br).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(P.allowMultipleSelections)&&Hu(e,t),this.dragging=$u(e,t)&&rh(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Fu(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=Qa(this.view);e.clientX-a.left<=s+Ji?t=-Ui(s-e.clientX):e.clientX+a.right>=o-Ji&&(t=Ui(e.clientX-o)),e.clientY-a.top<=r+Ji?i=-Ui(r-e.clientY):e.clientY+a.bottom>=l-Ji&&(i=Ui(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;i<e.ranges.length;i++){let s=e.ranges[i],r=null;if(s.empty){let o=pn(this.atoms,s.from,0);o!=s.from&&(r=x.cursor(o,-1))}else{let o=pn(this.atoms,s.from,-1),l=pn(this.atoms,s.to,1);(o!=s.from||l!=s.to)&&(r=x.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?x.create(t,e.mainIndex):e}select(e){let{view:t}=this,i=this.skipAtoms(this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Hu(n,e){let t=n.state.facet(Va);return t.length?t[0](e):C.mac?e.metaKey:e.ctrlKey}function Wu(n,e){let t=n.state.facet(Ha);return t.length?t[0](e):C.mac?!e.altKey:!e.ctrlKey}function $u(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=wi(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function zu(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=F.get(t))&&i.ignoreEvent(e))return!1;return!0}const Ie=Object.create(null),Te=Object.create(null),nh=C.ie&&C.ie_version<15||C.ios&&C.webkit_version<604;function ju(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),sh(n,t.value)},50)}function sh(n,e){let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(tr!=null&&t.selection.ranges.every(a=>a.empty)&&tr==r.toString()){let a=-1;i=t.changeByRange(c=>{let h=t.doc.lineAt(c.from);if(h.from==a)return{range:c};a=h.from;let f=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:h.from,insert:f},range:x.cursor(c.from+f.length)}})}else o?i=t.changeByRange(a=>{let c=r.line(s++);return{changes:{from:a.from,to:a.to,insert:c.text},range:x.cursor(a.from+c.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Te.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Ie.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);Te.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};Te.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ie.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(Wa))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=_u(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new Vu(n,e,t,i)),i&&n.observer.ignore(()=>{xa(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}return!1};function Eo(n,e,t,i){if(i==1)return x.cursor(e,t);if(i==2)return Mu(n.state,e,t);{let s=X.find(n.docView,e),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,x.range(o,l)}}let Po=(n,e,t)=>e>=t.top&&e<=t.bottom&&n>=t.left&&n<=t.right;function qu(n,e,t,i){let s=X.find(n.docView,e);if(!s)return 1;let r=e-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&Po(t,i,o))return-1;let l=s.coordsAt(r,1);return l&&Po(t,i,l)?1:o&&o.bottom>=i?-1:1}function Bo(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:qu(n,t,e.clientX,e.clientY)}}const Ku=C.ie&&C.ie_version<=11;let Ro=null,Lo=0,Io=0;function rh(n){if(!Ku)return n.detail;let e=Ro,t=Io;return Ro=n,Io=Date.now(),Lo=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Lo+1)%3:1}function _u(n,e){let t=Bo(n,e),i=rh(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=Bo(n,r),c,h=Eo(n,a.pos,a.bias,i);if(t.pos!=a.pos&&!o){let f=Eo(n,t.pos,t.bias,i),u=Math.min(f.from,h.from),d=Math.max(f.to,h.to);h=u<h.from?x.range(u,d):x.range(d,u)}return o?s.replaceRange(s.main.extend(h.from,h.to)):l&&i==1&&s.ranges.length>1&&(c=Ju(s,a.pos))?c:l?s.addRange(h):x.create([h])}}}function Ju(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:s}=n.ranges[t];if(i<=e&&s>=e)return x.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}Ie.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let s=n.docView.nearest(e.target);if(s&&s.isWidget){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=x.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",n.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove"),!1};Ie.dragend=n=>(n.inputState.draggedContent=null,!1);function No(n,e,t,i){if(!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&Wu(n,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ie.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),s=0,r=()=>{++s==t.length&&No(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return No(n,e,i,!0),!0}return!1};Ie.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=nh?null:e.clipboardData;return t?(sh(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(ju(n),!1)};function Uu(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Yu(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:e.join(n.lineBreak),ranges:t,linewise:i}}let tr=null;Ie.copy=Ie.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=Yu(n.state);if(!t&&!s)return!1;tr=s?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=nh?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Uu(n,t),!1)};const oh=Ne.define();function lh(n,e){let t=[];for(let i of n.facet(ja)){let s=i(n,e);s&&t.push(s)}return t?n.update({effects:t,annotations:oh.of(!0)}):null}function ah(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=lh(n.state,e);t?n.dispatch(t):n.update([])}},10)}Te.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),ah(n)};Te.blur=n=>{n.observer.clearSelectionRange(),ah(n)};Te.compositionstart=Te.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};Te.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,C.chrome&&C.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};Te.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ie.beforeinput=(n,e)=>{var t;let i;if(C.chrome&&C.android&&(i=th.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return C.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),C.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>Te.compositionend(n,e),20),!1};const Fo=new Set;function Gu(n){Fo.has(n)||(Fo.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Vo=["pre-wrap","normal","pre-line","break-spaces"];class Xu{constructor(e){this.lineWrapping=e,this.doc=B.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Vo.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=Vo.indexOf(e)>-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let c=0;c<o.length;c++){let h=o[c];h<0?c++:this.heightSamples[Math.floor(h*10)]=!0}}return a}}class Qu{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class ze{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?ce.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ut?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new ze(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var H=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(H||(H={}));const mn=.001;class fe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>mn&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return fe.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:c,fromB:h,toB:f}=s[l],u=r.lineAt(a,H.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=c?u:r.lineAt(c,H.ByPosNoHeight,i,0,0);for(f+=d.to-c,c=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,h=s[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,H.ByPosNoHeight,i,0,0));h+=u.from-a,a=u.from;let p=Rr.build(i.setDoc(o),e,h,f);r=r.replace(a,c,p)}return r.updateHeight(i,0)}static empty(){return new be(0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,s=0,r=0;for(;;)if(t==i)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Zu(fe.of(e.slice(0,t)),o,fe.of(e.slice(i)))}}fe.prototype.size=1;class hh extends fe{constructor(e,t,i){super(e,t),this.deco=i}blockAt(e,t,i,s){return new ze(s,this.length,i,this.height,this.deco||0)}lineAt(e,t,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(e,t,i,s,r,o){e<=r+this.length&&t>=r&&o(this.blockAt(0,i,s,r))}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(e,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class be extends hh{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,s){return new ze(s,this.length,i,this.height,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof be||s instanceof ie&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ie?s=new be(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):fe.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setHeight(e,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ie extends fe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let c=s+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),h=t.doc.lineAt(c),f=l+h.length*a,u=Math.max(i,e-f/2);return new ze(h.from,h.length,u,f,0)}else{let c=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:h,length:f}=t.doc.line(r+c);return new ze(h,f,i+l*c,l,0)}}lineAt(e,t,i,s,r){if(t==H.ByHeight)return this.blockAt(e,i,s,r);if(t==H.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new ze(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),c=i.doc.lineAt(e),h=l+c.length*a,f=c.number-o,u=s+l*f+a*(c.from-r-f);return new ze(c.from,c.length,Math.max(s,Math.min(u,s+this.height-h)),h,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:c}=this.heightMetrics(i,r);for(let h=e,f=s;h<=t;){let u=i.doc.lineAt(h);if(h==e){let p=u.number-l;f+=a*p+c*(e-r-p)}let d=a+c*u.length;o(new ze(u.from,u.length,f,d,0)),f+=d,h=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof ie?i[i.length-1]=new ie(r.length+s):i.push(null,new ie(s-1))}if(e>0){let r=i[0];r instanceof ie?i[0]=new ie(e+r.length):i.unshift(new ie(e-1),null)}return fe.of(i)}decomposeLeft(e,t){t.push(new ie(e-1),null)}decomposeRight(e,t){t.push(null,new ie(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new ie(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let h=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++];a==-1?a=f:Math.abs(f-a)>=mn&&(a=-2);let u=new be(h,f);u.outdated=!1,o.push(u),l+=h+1}l<=r&&o.push(null,new ie(r-l).updateHeight(e,l));let c=fe.of(o);return(a<0||Math.abs(c.height-this.height)>=mn||Math.abs(a-this.heightMetrics(e,t).perLine)>=mn)&&(e.heightChanged=!0),c}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Zu extends fe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==H.ByHeight?e<o:e<l,c=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?c.to<l:c.from>l))return c;let h=t==H.ByPosNoHeight?H.ByPosNoHeight:H.ByPos;return a?c.join(this.right.lineAt(l,h,i,o,l)):this.left.lineAt(l,h,i,s,r).join(c)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let c=this.lineAt(a,H.ByPos,i,s,r);e<c.from&&this.left.forEachLine(e,c.from-1,i,s,r,o),c.to>=e&&c.from<=t&&o(c),t>c.to&&this.right.forEachLine(c.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Ho(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Ho(r,l)}return fe.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?fe.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Ho(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof ie&&(i=n[e+1])instanceof ie&&n.splice(e-1,3,new ie(t.length+1+i.length))}const ed=5;class Rr{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof be?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new be(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new hh(o,s,i)):(o||r||s>=ed)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new be(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new ie(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof be)return e;let t=new be(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof be)&&!this.isCovered?this.nodes.push(new be(0,-1)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let s of this.nodes)s instanceof be&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new Rr(i,e);return R.spans(t,i,s,r,0),r.finish(i)}}function td(n,e,t){let i=new id;return R.compare(n,e,t,i,0),i.changes}class id{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&Us(e,t,this.changes,5)}}function nd(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let c=n.parentNode;c&&c!=i.body;)if(c.nodeType==1){let h=c,f=window.getComputedStyle(h);if((h.scrollHeight>h.clientHeight||h.scrollWidth>h.clientWidth)&&f.overflow!="visible"){let u=h.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=c==n.parentNode?u.bottom:Math.min(a,u.bottom)}c=f.position=="absolute"||f.position=="fixed"?h.offsetParent:h.parentNode}else if(c.nodeType==11)c=c.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function sd(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class fs{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let s=e[i],r=t[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e,t){return T.replace({widget:new rd(this.size*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class rd extends Fe{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class Wo{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=$o,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=W.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(Pr).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Xu(t),this.stateDeco=e.facet(Si).filter(i=>typeof i!="function"),this.heightMap=fe.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle.setDoc(e.doc),[new Ae(0,0,0,e.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=T.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new Yi(r,o))}}return this.viewports=e.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?$o:new Lr(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(hi(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Si).filter(h=>typeof h!="function");let s=e.changedRanges,r=Ae.extendWithRanges(s,td(i,this.stateDeco,e?e.changes:ee.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let c=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(c||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Ka)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?W.RTL:W.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let c=0,h=0;if(l.width&&l.height){let{scaleX:S,scaleY:k}=ba(t,l);(S>.005&&Math.abs(this.scaleX-S)>.005||k>.005&&Math.abs(this.scaleY-k)>.005)&&(this.scaleX=S,this.scaleY=k,c|=8,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,c|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=wa(e.scrollDOM);let p=(this.printing?sd:nd)(t,this.paddingTop),g=p.top-this.pixelViewport.top,y=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let v=l.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,c|=8),a){let S=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(S)&&(o=!0),o||s.lineWrapping&&Math.abs(v-this.contentDOMWidth)>s.charWidth){let{lineHeight:k,charWidth:O,textHeight:L}=e.docView.measureTextSize();o=k>0&&s.refresh(r,k,O,L,v/O,S),o&&(e.docView.minWidth=0,c|=8)}g>0&&y>0?h=Math.max(g,y):g<0&&y<0&&(h=Math.min(g,y)),s.heightChanged=!1;for(let k of this.viewports){let O=k.from==this.viewport.from?S:e.docView.measureVisibleLineHeights(k);this.heightMap=(o?fe.empty().applyChanges(this.stateDeco,B.empty,this.heightOracle,[new Ae(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Qu(k.from,O))}s.heightChanged&&(c|=2)}let M=!this.viewportIsAppropriate(this.viewport,h)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return M&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(h,this.scrollTarget),c|=this.updateForViewport()),(c&2||M)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Yi(s.lineAt(o-i*1e3,H.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,H.ByHeight,r,0,0).to);if(t){let{head:c}=t.range;if(c<a.from||c>a.to){let h=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(c,H.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-h/2:t.y=="start"||t.y=="nearest"&&c<a.from?u=f.top:u=f.bottom-h,a=new Yi(s.lineAt(u-1e3/2,H.ByHeight,r,0,0).from,s.lineAt(u+h+1e3/2,H.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Yi(this.heightMap.lineAt(i,H.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,H.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,H.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,H.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new fs(t.mapPos(s.from),t.mapPos(s.to),s.size));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=W.LTR&&!i)return[];let l=[],a=(h,f,u,d)=>{if(f-h<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let b of g)if(b>h&&b<f){a(h,b-10,u,d),a(b+10,f,u,d);return}let y=ld(e,b=>b.from>=u.from&&b.to<=u.to&&Math.abs(b.from-h)<r&&Math.abs(b.to-f)<r&&!g.some(v=>b.from<v&&b.to>v));if(!y){if(f<u.to&&t&&i&&t.visibleRanges.some(b=>b.from<=f&&b.to>=f)){let b=t.moveToLineBoundary(x.cursor(f),!1,!0).head;b>h&&(f=b)}y=new fs(h,f,this.gapSize(u,h,f,d))}l.push(y)},c=h=>{if(h.length<o||h.type!=ce.Text)return;let f=od(h.from,h.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,y,b;if(u!=null){let v=Xi(f,u),M=((this.visibleBottom-this.visibleTop)/2+g)/h.height;y=v-M,b=v+M}else y=(this.visibleTop-h.top-g)/h.height,b=(this.visibleBottom-h.top+g)/h.height;d=Gi(f,y),p=Gi(f,b)}else{let g=f.total*this.heightOracle.charWidth,y=s*this.heightOracle.charWidth,b,v;if(u!=null){let M=Xi(f,u),S=((this.pixelViewport.right-this.pixelViewport.left)/2+y)/g;b=M-S,v=M+S}else b=(this.pixelViewport.left-y)/g,v=(this.pixelViewport.right+y)/g;d=Gi(f,b),p=Gi(f,v)}d>h.from&&a(h.from,d,h,f),p<h.to&&a(p,h.to,h,f)};for(let h of this.viewportLines)Array.isArray(h.type)?h.type.forEach(c):c(h);return l}gapSize(e,t,i,s){let r=Xi(s,i)-Xi(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){fs.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=T.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];R.spans(e,this.viewport.from,this.viewport.to,{span(s,r){t.push({from:s,to:r})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=t[r].from||s.to!=t[r].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||hi(this.heightMap.lineAt(e,H.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||hi(this.heightMap.lineAt(this.scaler.fromDOM(e),H.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return hi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Yi{constructor(e,t){this.from=e,this.to=t}}function od(n,e,t){let i=[],s=n,r=0;return R.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(i.push({from:s,to:e}),r+=e-s),{total:r,ranges:i}}function Gi({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function Xi(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function ld(n,e){for(let t of n)if(e(t))return t}const $o={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};class Lr{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let c=t.lineAt(l,H.ByPos,e,0,0).top,h=t.lineAt(a,H.ByPos,e,0,0).bottom;return s+=h-c,{from:l,to:a,top:c,bottom:h,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,s=r.domBottom}}eq(e){return e instanceof Lr?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function hi(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new ze(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>hi(s,e)):n._content)}const Qi=A.define({combine:n=>n.join(" ")}),ir=A.define({combine:n=>n.indexOf(!0)>-1}),nr=ht.newName(),ch=ht.newName(),fh=ht.newName(),uh={"&light":"."+ch,"&dark":"."+fh};function sr(n,e,t){return new ht(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}const ad=sr("."+nr,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},uh),ci="";class hd{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(P.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=ci}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=s.nextSibling;if(o==t)break;let l=F.get(s),a=F.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:An(s))||An(o)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=o}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=F.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(cd(e,i.node,i.offset)?t:0))}}function cd(n,e,t){for(;;){if(!e||t<Qe(e))return!1;if(e==n)return!0;t=wt(e)+1,e=e.parentNode}}class zo{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class fd{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=r||o?[]:pd(e),a=new hd(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=md(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!zs(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),c=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!zs(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),h=e.viewport;if((C.ios||C.chrome)&&e.state.selection.main.empty&&a!=c&&(h.from>0||h.to<e.state.doc.length)){let f=Math.min(a,c),u=Math.max(a,c),d=h.from-f,p=h.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==e.state.doc.length)&&(a=0,c=e.state.doc.length)}this.newSel=x.single(c,a)}}}function dh(n,e){let t,{newSel:i}=e,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,c=null;(r===8||C.android&&e.text.length<l-o)&&(a=s.to,c="end");let h=dd(n.state.doc.sliceString(o,l,ci),e.text,a-o,c);h&&(C.chrome&&r==13&&h.toB==h.from+2&&e.text.slice(h.from,h.toB)==ci+ci&&h.toB--,t={from:o+h.from,to:o+h.toA,insert:B.of(e.text.slice(h.from,h.toB).split(ci))})}else i&&(!n.hasFocus&&n.state.facet(it)||i.main.eq(s))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!s.empty&&i&&i.main.empty?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,s.to))}:(C.mac||C.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=x.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:B.of([" "])}):C.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
|
7
|
+
`&&n.lineWrapping&&(i&&(i=x.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:B.of([" "])}),t)return ph(n,t,i,r);if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function ph(n,e,t,i=-1){if(C.ios&&n.inputState.flushIOSKey(e))return!0;let s=n.state.selection.main;if(C.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&n.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&Nt(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&Nt(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&Nt(n.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=ud(n,e,t));return n.state.facet(za).some(a=>a(n,e.from,e.to,r,l))||n.dispatch(l()),!0}function ud(n,e,t){let i,s=n.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=r.from<e.from?s.sliceDoc(r.from,e.from):"",a=r.to>e.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+a))}else{let l=s.changes(e),a=t&&t.main.to<=l.newLength?t.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let c=n.state.sliceDoc(e.from,e.to),h,f=t&&Za(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);h={from:f.from,to:f.to-p}}else h=n.state.doc.lineAt(r.head);let u=r.to-e.to,d=r.to-r.from;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let g=p.to-u,y=g-c.length;if(p.to-p.from!=d||n.state.sliceDoc(y,g)!=c||p.to>=h.from&&p.from<=h.to)return{range:p};let b=s.changes({from:y,to:g,insert:e.insert}),v=p.to-r.to;return{changes:b,range:a?x.range(Math.max(0,a.anchor+v),Math.max(0,a.head+v)):p.map(b)}})}else i={changes:l,selection:a&&s.selection.replaceRange(a)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:o,scrollIntoView:!0})}function dd(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&n.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function pd(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new zo(t,i)),(s!=t||r!=i)&&e.push(new zo(s,r))),e}function md(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?x.single(t+e,i+e):null}const gd={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},us=C.ie&&C.ie_version<=11;class yd{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new eu,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(C.ie&&C.ie_version<=11||C.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&e.constructor.EDIT_CONTEXT!==!1&&!(C.chrome&&C.chrome_version<126)&&(this.editContext=new xd(e),e.state.facet(it)&&(e.contentDOM.editContext=this.editContext.editContext)),us&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){e.type=="change"&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(it)?i.root.activeElement!=this.dom:!dn(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(C.ie&&C.ie_version<=11||C.android&&C.chrome)&&!i.state.selection.main.empty&&s.focusNode&&pi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=wi(e.root);if(!t)return!1;let i=C.safari&&e.root.nodeType==11&&Gf(this.dom.ownerDocument)==this.dom&&bd(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let s=dn(this.dom,i);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&iu(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,gd),us&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),us&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Nt(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&dn(this.dom,this.selectionRange);if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new fd(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,s=dh(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!t.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let i=jo(t,e.previousSibling||e.target.previousSibling,-1),s=jo(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(it)!=e.state.facet(it)&&(e.view.contentDOM.editContext=e.state.facet(it)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function jo(n,e,t){for(;e;){let i=F.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function qo(n,e){let t=e.startContainer,i=e.startOffset,s=e.endContainer,r=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor);return pi(o.node,o.offset,s,r)&&([t,i,s,r]=[s,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}}function bd(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return qo(n,s)}let t=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?qo(n,t):null}class xd{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:s}=e.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:B.of(i.text.split(`
|
|
8
|
+
`))};r.from==this.from&&s<this.from?r.from=s:r.to==this.to&&s>this.to&&(r.to=s),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,e.state.readOnly||ph(e,r,x.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)))},this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}t.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;s.push(T.mark({attributes:{style:a}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}e.dispatch({effects:Ja.of(T.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{e.inputState.composing=-1,e.inputState.compositionFirstChange=null};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=wi(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,c)=>{if(i)return;let h=c.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(c)){s=this.pendingContextChange=null,t+=h,this.to+=h;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=h,this.to+=h;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+c.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),c.toString()),this.to+=h}t+=h}),s&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange;!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.resetRange(e.state),this.editContext.updateText(0,this.editContext.text.length,e.state.doc.sliceString(this.from,this.to)),this.setSelection(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e){return e+this.from}toContextPos(e){return e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class w{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(i=>i.forEach(s=>t(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||tu(e.parent)||document,this.viewState=new Wo(e.state||P.create(e)),e.scrollTo&&e.scrollTo.is(_i)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(li).map(i=>new as(i));for(let i of this.plugins)i.update(this);this.observer=new yd(this),this.inputState=new Lu(this),this.inputState.ensureHandlers(this.plugins),this.docView=new So(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...e){let t=e.length==1&&e[0]instanceof Y?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(oh))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=lh(r,o),a||(l=1));let c=this.observer.delayedAndroidKey,h=null;if(c?(this.observer.clearDelayedAndroidKey(),h=this.observer.readChange(),(h&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(h=null)):this.observer.clear(),r.facet(P.phrases)!=this.state.facet(P.phrases))return this.setState(r);s=Tn.create(this,r,e),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new Ft(d.empty?d:x.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(_i)&&(f=d.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=On.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(ai)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Qi)!=s.state.facet(Qi)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(Qs))try{u(s)}catch(d){he(this.state,d,"update listener")}(a||h)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),h&&!dh(this,h)&&c.force&&Nt(this.contentDOM,c.key,c.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new Wo(e),this.plugins=e.facet(li).map(i=>new as(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new So(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(li),i=e.state.facet(li);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new as(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){he(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(wa(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let c=[];a&4||([this.measureRequests,c]=[c,this.measureRequests]);let h=c.map(d=>{try{return d.read(this)}catch(p){return he(this.state,p),Ko}}),f=Tn.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f),u&&this.docViewUpdate());for(let d=0;d<c.length;d++)if(h[d]!=Ko)try{let p=c[d];p.write&&p.write(h[d],this)}catch(p){he(this.state,p)}if(u&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(p>1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Qs))l(t)}get themeClasses(){return nr+" "+(this.state.facet(ir)?fh:ch)+" "+this.state.facet(Qi)}updateAttrs(){let e=_o(this,Ua,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(it)?"true":"false",class:"cm-content",style:`${C.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),_o(this,Pr,t);let i=this.observer.ignore(()=>{let s=Js(this.contentDOM,this.contentAttrs,t),r=Js(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(w.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(ai);let e=this.state.facet(w.cspNonce);ht.mount(this.root,this.styleModules.concat(ad).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.spec!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return cs(this,e,Oo(this,e,t,i))}moveByGroup(e,t){return cs(this,e,Oo(this,e,t,i=>Bu(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return x.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,i=!0){return Pu(this,e,t,i)}moveVertically(e,t,i){return cs(this,e,Ru(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),eh(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[ot.find(r,e-s.from,-1,t)];return _n(i,o.dir==W.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(qa)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>vd)return Na(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Ia(r.isolates,i=wo(this,e))))return r.order;i||(i=wo(this,e));let s=mu(e.text,t,i);return this.bidiCache.push(new On(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||C.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{xa(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return _i.of(new Ft(typeof e=="number"?x.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return _i.of(new Ft(x.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return _.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return _.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ht.newName(),s=[Qi.of(i),ai.of(sr(`.${i}`,e))];return t&&t.dark&&s.push(ir.of(!0)),s}static baseTheme(e){return pt.lowest(ai.of(sr("."+nr,e,uh)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&F.get(i)||F.get(e);return((t=s==null?void 0:s.rootView)===null||t===void 0?void 0:t.view)||null}}w.styleModule=ai;w.inputHandler=za;w.scrollHandler=_a;w.focusChangeEffect=ja;w.perLineTextDirection=qa;w.exceptionSink=$a;w.updateListener=Qs;w.editable=it;w.mouseSelectionStyle=Wa;w.dragMovesSelection=Ha;w.clickAddsSelectionRange=Va;w.decorations=Si;w.outerDecorations=Ya;w.atomicRanges=Br;w.bidiIsolatedRanges=Ga;w.scrollMargins=Xa;w.darkTheme=ir;w.cspNonce=A.define({combine:n=>n.length?n[0]:""});w.contentAttributes=Pr;w.editorAttributes=Ua;w.lineWrapping=w.contentAttributes.of({class:"cm-lineWrapping"});w.announce=D.define();const vd=4096,Ko={};class On{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:W.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&i.push(new On(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function _o(n,e,t){for(let i=n.state.facet(e),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&_s(o,t)}return t}const wd=C.mac?"mac":C.windows?"win":C.linux?"linux":"key";function Sd(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const c=t[a];if(/^(cmd|meta|m)$/i.test(c))l=!0;else if(/^a(lt)?$/i.test(c))s=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))o=!0;else if(/^mod$/i.test(c))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Zi(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const kd=pt.default(w.domEventHandlers({keydown(n,e){return gh(mh(e.state),n,e,"editor")}})),Gt=A.define({enables:kd}),Jo=new WeakMap;function mh(n){let e=n.facet(Gt),t=Jo.get(e);return t||Jo.set(e,t=Md(e.reduce((i,s)=>i.concat(s),[]))),t}function Cd(n,e,t){return gh(mh(n.state),e,n,t)}let nt=null;const Ad=4e3;function Md(n,e=wd){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,c,h)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(b=>Sd(b,e));for(let b=1;b<p.length;b++){let v=p.slice(0,b).join(" ");s(v,!0),d[v]||(d[v]={preventDefault:!0,stopPropagation:!1,run:[M=>{let S=nt={view:M,prefix:v,scope:o};return setTimeout(()=>{nt==S&&(nt=null)},Ad),!0}]})}let g=p.join(" ");s(g,!1);let y=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&y.run.push(a),c&&(y.preventDefault=!0),h&&(y.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let c of l){let h=t[c]||(t[c]=Object.create(null));h._any||(h._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in h)h[u].run.push(d=>f(d,rr))}let a=o[e]||o.key;if(a)for(let c of l)r(c,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(c,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let rr=null;function gh(n,e,t,i){rr=e;let s=yf(e),r=ne(s,0),o=ke(r)==s.length&&s!=" ",l="",a=!1,c=!1,h=!1;nt&&nt.view==t&&nt.scope==i&&(l=nt.prefix+" ",ih.indexOf(e.keyCode)<0&&(c=!0,nt=null));let f=new Set,u=y=>{if(y){for(let b of y.run)if(!f.has(b)&&(f.add(b),b(t)))return y.stopPropagation&&(h=!0),!0;y.preventDefault&&(y.stopPropagation&&(h=!0),c=!0)}return!1},d=n[i],p,g;return d&&(u(d[l+Zi(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(C.windows&&e.ctrlKey&&e.altKey)&&(p=bf[e.keyCode])&&p!=s?(u(d[l+Zi(p,e,!0)])||e.shiftKey&&(g=xf[e.keyCode])!=s&&g!=p&&u(d[l+Zi(g,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Zi(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),c&&(a=!0),a&&h&&e.stopPropagation(),rr=null,a}class Ni{constructor(e,t,i,s,r){this.className=e,this.left=t,this.top=i,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let s=e.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=yh(e);return[new Ni(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Td(e,t,i)}}function yh(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==W.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function Uo(n,e,t,i){let s=n.coordsAtPos(e,t*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=n.posAtCoords({x:r.left+1,y:o}),a=n.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function Td(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let i=Math.max(t.from,n.viewport.from),s=Math.min(t.to,n.viewport.to),r=n.textDirection==W.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=yh(n),c=o.querySelector(".cm-line"),h=c&&window.getComputedStyle(c),f=l.left+(h?parseInt(h.paddingLeft)+Math.min(0,parseInt(h.textIndent)):0),u=l.right-(h?parseInt(h.paddingRight):0),d=er(n,i),p=er(n,s),g=d.type==ce.Text?d:null,y=p.type==ce.Text?p:null;if(g&&(n.lineWrapping||d.widgetLineBreaks)&&(g=Uo(n,i,1,g)),y&&(n.lineWrapping||p.widgetLineBreaks)&&(y=Uo(n,s,-1,y)),g&&y&&g.from==y.from&&g.to==y.to)return v(M(t.from,t.to,g));{let k=g?M(t.from,null,g):S(d,!1),O=y?M(null,t.to,y):S(p,!0),L=[];return(g||d).to<(y||p).from-(g&&y?1:0)||d.widgetLineBreaks>1&&k.bottom+n.defaultLineHeight/2<O.top?L.push(b(f,k.bottom,u,O.top)):k.bottom<O.top&&n.elementAtHeight((k.bottom+O.top)/2).type==ce.Text&&(k.bottom=O.top=(k.bottom+O.top)/2),v(k).concat(L).concat(v(O))}function b(k,O,L,K){return new Ni(e,k-a.left,O-a.top-.01,L-k,K-O+.01)}function v({top:k,bottom:O,horizontal:L}){let K=[];for(let I=0;I<L.length;I+=2)K.push(b(L[I],k,L[I+1],O));return K}function M(k,O,L){let K=1e9,I=-1e9,ue=[];function Ye(Ee,He,we,Z,Pe){let de=n.coordsAtPos(Ee,Ee==L.to?-2:2),Be=n.coordsAtPos(we,we==L.from?2:-2);!de||!Be||(K=Math.min(de.top,Be.top,K),I=Math.max(de.bottom,Be.bottom,I),Pe==W.LTR?ue.push(r&&He?f:de.left,r&&Z?u:Be.right):ue.push(!r&&Z?f:Be.left,!r&&He?u:de.right))}let De=k??L.from,tt=O??L.to;for(let Ee of n.visibleRanges)if(Ee.to>De&&Ee.from<tt)for(let He=Math.max(Ee.from,De),we=Math.min(Ee.to,tt);;){let Z=n.state.doc.lineAt(He);for(let Pe of n.bidiSpans(Z)){let de=Pe.from+Z.from,Be=Pe.to+Z.from;if(de>=we)break;Be>He&&Ye(Math.max(de,He),k==null&&de<=De,Math.min(Be,we),O==null&&Be>=tt,Pe.dir)}if(He=Z.to+1,He>=we)break}return ue.length==0&&Ye(De,k==null,tt,O==null,n.textDirection),{top:K,bottom:I,horizontal:ue}}function S(k,O){let L=l.top+(O?k.top:k.bottom);return{top:L,bottom:L,horizontal:[]}}}function Od(n,e){return n.constructor==e.constructor&&n.eq(e)}class Dd{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(gn)!=e.state.facet(gn)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(gn);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,i)=>!Od(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[i].constructor&&s.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const gn=A.define();function bh(n){return[_.define(e=>new Dd(e,n)),gn.of(n)]}const xh=!C.ios,ki=A.define({combine(n){return Je(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function Ed(n={}){return[ki.of(n),Pd,Bd,Rd,Ka.of(!0)]}function vh(n){return n.startState.facet(ki)!=n.state.facet(ki)}const Pd=bh({above:!0,markers(n){let{state:e}=n,t=e.facet(ki),i=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty?!r||xh:t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:x.cursor(s.head,s.head>s.anchor?-1:1);for(let a of Ni.forRange(n,o,l))i.push(a)}}return i},update(n,e){n.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=vh(n);return t&&Yo(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){Yo(e.state,n)},class:"cm-cursorLayer"});function Yo(n,e){e.style.animationDuration=n.facet(ki).cursorBlinkRate+"ms"}const Bd=bh({above:!1,markers(n){return n.state.selection.ranges.map(e=>e.empty?[]:Ni.forRange(n,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||vh(n)},class:"cm-selectionLayer"}),or={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};xh&&(or[".cm-line"].caretColor=or[".cm-content"].caretColor="transparent !important");const Rd=pt.highest(w.theme(or)),wh=D.define({map(n,e){return n==null?null:e.mapPos(n)}}),fi=Q.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(wh)?i.value:t,n)}}),Ld=_.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(fi);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(fi)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,e=n.state.field(fi),t=e!=null&&n.coordsAtPos(e);if(!t)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:t.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:t.bottom-t.top}}drawCursor(n){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;n?(this.cursor.style.left=n.left/e+"px",this.cursor.style.top=n.top/t+"px",this.cursor.style.height=n.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(fi)!=n&&this.view.dispatch({effects:wh.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function Id(){return[fi,Ld]}function Go(n,e,t,i,s){e.lastIndex=0;for(let r=n.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)s(o+l.index,l)}function Nd(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let i=[];for(let{from:s,to:r}of t)s=Math.max(n.state.doc.lineAt(s).from,s-e),r=Math.min(n.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}class Fd{constructor(e){const{regexp:t,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,c,h)=>s(h,c,c+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,c,h)=>{let f=i(l,a,c);f&&h(c,c+l[0].length,f)};else if(i)this.addMatch=(l,a,c,h)=>h(c,c+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new ft,i=t.add.bind(t);for(let{from:s,to:r}of Nd(e,this.maxLength))Go(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),e.viewportChanged||s-i>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),i,s):t}updateRange(e,t,i,s){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let a=e.state.doc.lineAt(o),c=a.to<l?e.state.doc.lineAt(l):a,h=Math.max(r.from,a.from),f=Math.min(r.to,c.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){h=o;break}for(;l<c.to;l++)if(this.boundary.test(c.text[l-c.from])){f=l;break}}let u=[],d,p=(g,y,b)=>u.push(b.range(g,y));if(a==c)for(this.regexp.lastIndex=h-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else Go(e.state.doc,this.regexp,h,f,(g,y)=>this.addMatch(y,e,g,p));t=t.update({filterFrom:h,filterTo:f,filter:(g,y)=>g<h||y>f,add:u})}}return t}}const lr=/x/.unicode!=null?"gu":"g",Vd=new RegExp(`[\0-\b
|
|
9
|
+
--\u2028\u2029\uFEFF-]`,lr),Hd={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let ds=null;function Wd(){var n;if(ds==null&&typeof document<"u"&&document.body){let e=document.body.style;ds=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return ds||!1}const yn=A.define({combine(n){let e=Je(n,{render:null,specialChars:Vd,addSpecialChars:null});return(e.replaceTabs=!Wd())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,lr)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,lr)),e}});function $d(n={}){return[yn.of(n),zd()]}let Xo=null;function zd(){return Xo||(Xo=_.fromClass(class{constructor(n){this.view=n,this.decorations=T.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(yn)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Fd({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=ne(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,a=Yt(o.text,l,i-o.from);return T.replace({widget:new _d((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=T.replace({widget:new Kd(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(yn);n.startState.facet(yn)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const jd="•";function qd(n){return n>=32?jd:n==10?"":String.fromCharCode(9216+n)}class Kd extends Fe{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=qd(this.code),i=e.state.phrase("Control character")+" "+(Hd[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,t);if(s)return s;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class _d extends Fe{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}function Jd(){return Yd}const Ud=T.line({class:"cm-activeLine"}),Yd=_.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let i of n.state.selection.ranges){let s=n.lineBlockAt(i.head);s.from>e&&(t.push(Ud.range(s.from)),e=s.from)}return T.set(t)}},{decorations:n=>n.decorations});class Gd extends Fe{constructor(e){super(),this.content=e}toDOM(){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?e.setAttribute("aria-label","placeholder "+this.content):e.setAttribute("aria-hidden","true"),e}coordsAt(e){let t=e.firstChild?zt(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),s=_n(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function Xd(n){return _.fromClass(class{constructor(e){this.view=e,this.placeholder=n?T.set([T.widget({widget:new Gd(n),side:1}).range(0)]):T.none}get decorations(){return this.view.state.doc.length?T.none:this.placeholder}},{decorations:e=>e.decorations})}const ar=2e3;function Qd(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>ar||t.off>ar||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=s;a++){let c=n.doc.line(a);c.length<=l&&r.push(x.range(c.from+o,c.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=s;a++){let c=n.doc.line(a),h=$s(c.text,o,n.tabSize,!0);if(h<0)r.push(x.cursor(c.to));else{let f=$s(c.text,l,n.tabSize);r.push(x.range(c.from+h,c.from+f))}}}return r}function Zd(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function Qo(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1),i=n.state.doc.lineAt(t),s=t-i.from,r=s>ar?-1:s==i.length?Zd(n,e.clientX):Yt(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function ep(n,e){let t=Qo(n,e),i=n.state.selection;return t?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(t.line).from),o=s.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=Qo(n,s);if(!l)return i;let a=Qd(n.state,t,l);return a.length?o?x.create(a.concat(i.ranges)):x.create(a):i}}:null}function tp(n){let e=t=>t.altKey&&t.button==0;return w.mouseSelectionStyle.of((t,i)=>e(i)?ep(t,i):null)}const ip={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},np={style:"cursor: crosshair"};function sp(n={}){let[e,t]=ip[n.key||"Alt"],i=_.fromClass(class{constructor(s){this.view=s,this.isDown=!1}set(s){this.isDown!=s&&(this.isDown=s,this.view.update([]))}},{eventObservers:{keydown(s){this.set(s.keyCode==e||t(s))},keyup(s){(s.keyCode==e||!t(s))&&this.set(!1)},mousemove(s){this.set(t(s))}}});return[i,w.contentAttributes.of(s=>{var r;return!((r=s.plugin(i))===null||r===void 0)&&r.isDown?np:null})]}const ni="-10000px";class Sh{constructor(e,t,i,s){this.facet=t,this.createTooltipView=i,this.removeTooltipView=s,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(e,t){var i;let s=e.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let c=r[a],h=-1;if(c){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==c.create&&(h=f)}if(h<0)o[a]=this.createTooltipView(c,a?o[a-1]:null),l&&(l[a]=!!c.above);else{let f=o[a]=this.tooltipViews[h];l&&(l[a]=t[h]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,c)=>t[c]=a),t.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}}function rp(n){let{win:e}=n;return{top:0,left:0,bottom:e.innerHeight,right:e.innerWidth}}const ps=A.define({combine:n=>{var e,t,i;return{position:C.ios?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||rp}}}),Zo=new WeakMap,Ir=_.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(ps);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Sh(n,Nr,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(ps);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",t.dom.appendChild(s)}return t.dom.style.position=this.position,t.dom.style.top=ni,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect(),e=1,t=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(C.gecko)i=s.offsetParent!=this.container.ownerDocument.body;else if(s.style.top==ni&&s.style.left=="0px"){let r=s.getBoundingClientRect();i=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}}if(i||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(e=s.width/this.parent.offsetWidth,t=s.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((s,r)=>{let o=this.manager.tooltipViews[r];return o.getCoords?o.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(ps).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:i}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:t,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],c=this.manager.tooltipViews[l],{dom:h}=c,f=n.pos[l],u=n.size[l];if(!f||f.bottom<=Math.max(t.top,i.top)||f.top>=Math.min(t.bottom,i.bottom)||f.right<Math.max(t.left,i.left)-.1||f.left>Math.min(t.right,i.right)+.1){h.style.top=ni;continue}let d=a.arrow?c.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,y=(e=Zo.get(c))!==null&&e!==void 0?e:u.bottom-u.top,b=c.offset||lp,v=this.view.textDirection==W.LTR,M=u.width>i.right-i.left?v?i.left:i.right-u.width:v?Math.max(i.left,Math.min(f.left-(d?14:0)+b.x,i.right-g)):Math.min(Math.max(i.left,f.left-g+(d?14:0)-b.x),i.right-g),S=this.above[l];!a.strictSide&&(S?f.top-(u.bottom-u.top)-b.y<i.top:f.bottom+(u.bottom-u.top)+b.y>i.bottom)&&S==i.bottom-f.bottom>f.top-i.top&&(S=this.above[l]=!S);let k=(S?f.top-i.top:i.bottom-f.bottom)-p;if(k<y&&c.resize!==!1){if(k<this.view.defaultLineHeight){h.style.top=ni;continue}Zo.set(c,y),h.style.height=(y=k)/r+"px"}else h.style.height&&(h.style.height="");let O=S?f.top-y-p-b.y:f.bottom+p+b.y,L=M+g;if(c.overlap!==!0)for(let K of o)K.left<L&&K.right>M&&K.top<O+y&&K.bottom>O&&(O=S?K.top-y-2-p:K.bottom+p+2);if(this.position=="absolute"?(h.style.top=(O-n.parent.top)/r+"px",h.style.left=(M-n.parent.left)/s+"px"):(h.style.top=O/r+"px",h.style.left=M/s+"px"),d){let K=f.left+(v?b.x:-b.x)-(M+14-7);d.style.left=K/s+"px"}c.overlap!==!0&&o.push({left:M,top:O,right:L,bottom:O+y}),h.classList.toggle("cm-tooltip-above",S),h.classList.toggle("cm-tooltip-below",!S),c.positioned&&c.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=ni}},{eventObservers:{scroll(){this.maybeMeasure()}}}),op=w.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),lp={x:0,y:0},Nr=A.define({enables:[Ir,op]}),Dn=A.define({combine:n=>n.reduce((e,t)=>e.concat(t),[])});class Un{static create(e){return new Un(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Sh(e,Dn,(t,i)=>this.createHostedView(t,i),t=>t.dom.remove())}createHostedView(e,t){let i=e.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let i of this.manager.tooltipViews){let s=i[e];if(s!==void 0){if(t===void 0)t=s;else if(t!==s)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const ap=Nr.compute([Dn],n=>{let e=n.facet(Dn);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var i;return(i=t.end)!==null&&i!==void 0?i:t.pos})),create:Un.create,above:e[0].above,arrow:e.some(t=>t.arrow)}});class hp{constructor(e,t,i,s,r){this.view=e,this.source=t,this.field=i,this.setHover=s,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,i=e.docView.nearest(t.target);if(!i)return;let s,r=1;if(i instanceof rt)s=i.posAtStart;else{if(s=e.posAtCoords(t),s==null)return;let l=e.coordsAtPos(s);if(!l||t.y<l.top||t.y>l.bottom||t.x<l.left-e.defaultCharacterWidth||t.x>l.right+e.defaultCharacterWidth)return;let a=e.bidiSpans(e.state.doc.lineAt(s)).find(h=>h.from<=s&&h.to>=s),c=a&&a.dir==W.RTL?-1:1;r=t.x<l.left?-c:c}let o=this.source(e,s,r);if(o!=null&&o.then){let l=this.pending={pos:s};o.then(a=>{this.pending==l&&(this.pending=null,a&&!(Array.isArray(a)&&!a.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(a)?a:[a])}))},a=>he(e.state,a,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&e.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let e=this.view.plugin(Ir),t=e?e.manager.tooltips.findIndex(i=>i.create==Un.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,i;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:s,tooltip:r}=this;if(s.length&&r&&!cp(r.dom,e)||this.pending){let{pos:o}=s[0]||this.pending,l=(i=(t=s[0])===null||t===void 0?void 0:t.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!fp(this.view,o,l,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length){let{tooltip:i}=this;i&&i.dom.contains(e.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=i=>{e.removeEventListener("mouseleave",t),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const en=4;function cp(n,e){let t=n.getBoundingClientRect();return e.clientX>=t.left-en&&e.clientX<=t.right+en&&e.clientY>=t.top-en&&e.clientY<=t.bottom+en}function fp(n,e,t,i,s,r){let o=n.scrollDOM.getBoundingClientRect(),l=n.documentTop+n.documentPadding.top+n.contentHeight;if(o.left>i||o.right<i||o.top>s||Math.min(o.bottom,l)<s)return!1;let a=n.posAtCoords({x:i,y:s},!1);return a>=e&&a<=t}function up(n,e={}){let t=D.define(),i=Q.define({create(){return[]},update(s,r){if(s.length&&(e.hideOnChange&&(r.docChanged||r.selection)?s=[]:e.hideOn&&(s=s.filter(o=>!e.hideOn(r,o))),r.docChanged)){let o=[];for(let l of s){let a=r.changes.mapPos(l.pos,-1,te.TrackDel);if(a!=null){let c=Object.assign(Object.create(null),l);c.pos=a,c.end!=null&&(c.end=r.changes.mapPos(c.end)),o.push(c)}}s=o}for(let o of r.effects)o.is(t)&&(s=o.value),o.is(dp)&&(s=[]);return s},provide:s=>Dn.from(s)});return[i,_.define(s=>new hp(s,n,i,t,e.hoverTime||300)),ap]}function kh(n,e){let t=n.plugin(Ir);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const dp=D.define(),el=A.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Ci(n,e){let t=n.plugin(Ch),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Ch=_.fromClass(class{constructor(n){this.input=n.state.facet(Ai),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(el);this.top=new tn(n,!0,e.topContainer),this.bottom=new tn(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(el);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new tn(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new tn(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(Ai);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let c=this.specs.indexOf(a),h;c<0?(h=a(n.view),l.push(h)):(h=this.panels[c],h.update&&h.update(n)),s.push(h),(h.top?r:o).push(h)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>w.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class tn{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=tl(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=tl(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function tl(n){let e=n.nextSibling;return n.remove(),e}const Ai=A.define({enables:Ch});class et extends ct{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}et.prototype.elementClass="";et.prototype.toDOM=void 0;et.prototype.mapMode=te.TrackBefore;et.prototype.startSide=et.prototype.endSide=-1;et.prototype.point=!0;const bn=A.define(),pp={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>R.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},gi=A.define();function mp(n){return[Ah(),gi.of(Object.assign(Object.assign({},pp),n))]}const il=A.define({combine:n=>n.some(e=>e)});function Ah(n){return[gp]}const gp=_.fromClass(class{constructor(n){this.view=n,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(gi).map(e=>new sl(n,e));for(let e of this.gutters)this.dom.appendChild(e.dom);this.fixed=!n.state.facet(il),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}n.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(il)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&this.dom.remove();let t=R.iter(this.view.state.facet(bn),this.view.viewport.from),i=[],s=this.gutters.map(r=>new yp(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==ce.Text&&o){hr(t,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==ce.Text){hr(t,i,r.from);for(let o of s)o.line(this.view,r,i)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();n&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(n){let e=n.startState.facet(gi),t=n.state.facet(gi),i=n.docChanged||n.heightChanged||n.viewportChanged||!R.eq(n.startState.facet(bn),n.state.facet(bn),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new sl(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove()}},{provide:n=>w.scrollMargins.of(e=>{let t=e.plugin(n);return!t||t.gutters.length==0||!t.fixed?null:e.textDirection==W.LTR?{left:t.dom.offsetWidth*e.scaleX}:{right:t.dom.offsetWidth*e.scaleX}})});function nl(n){return Array.isArray(n)?n:[n]}function hr(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class yp{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=R.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:s}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==s.elements.length){let l=new Mh(e,o,r,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let s=[];hr(this.cursor,s,t.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t);i&&this.addElement(e,t,[i])}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class sl{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,s)&&s.preventDefault()});this.markers=nl(t.markers(e)),t.initialSpacer&&(this.spacer=new Mh(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=nl(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!R.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Mh{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),bp(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,c=!1;if(a){let h=a.elementClass;h&&(i+=" "+h);for(let f=o;f<this.markers.length;f++)if(this.markers[f].compare(a)){l=f,c=!0;break}}else l=this.markers.length;for(;o<l;){let h=this.markers[o++];if(h.toDOM){h.destroy(s);let f=s.nextSibling;s.remove(),s=f}}if(!a)break;a.toDOM&&(c?s=s.nextSibling:this.dom.insertBefore(a.toDOM(e),s)),c&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function bp(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const xp=A.define(),Pt=A.define({combine(n){return Je(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let s in t){let r=i[s],o=t[s];i[s]=r?(l,a,c)=>r(l,a,c)||o(l,a,c):o}return i}})}});class ms extends et{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function gs(n,e){return n.state.facet(Pt).formatNumber(e,n.state)}const vp=gi.compute([Pt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(xp)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new ms(gs(e,e.state.doc.lineAt(t.from).number))},widgetMarker:()=>null,lineMarkerChange:e=>e.startState.facet(Pt)!=e.state.facet(Pt),initialSpacer(e){return new ms(gs(e,rl(e.state.doc.lines)))},updateSpacer(e,t){let i=gs(t.view,rl(t.view.state.doc.lines));return i==e.number?e:new ms(i)},domEventHandlers:n.facet(Pt).domEventHandlers}));function wp(n={}){return[Pt.of(n),Ah(),vp]}function rl(n){let e=9;for(;e<n;)e=e*10+9;return e}const Sp=new class extends et{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},kp=bn.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(Sp.range(s)))}return R.of(e)});function Cp(){return kp}var ys;const Bt=new Me;function Th(n){return A.define({combine:n?e=>e.concat(n):void 0})}const Fr=new Me;class Re{constructor(e,t,i=[],s=""){this.data=e,this.name=s,P.prototype.hasOwnProperty("tree")||Object.defineProperty(P.prototype,"tree",{get(){return j(this)}}),this.parser=t,this.extension=[dt.of(this),P.languageData.of((r,o,l)=>{let a=ol(r,o,l),c=a.type.prop(Bt);if(!c)return[];let h=r.facet(c),f=a.type.prop(Fr);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(h)}}return h})].concat(i)}isActiveAt(e,t,i=-1){return ol(e,t,i).type.prop(Bt)==this.data}findRegions(e){let t=e.facet(dt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(Bt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(Me.mounted);if(l){if(l.tree.prop(Bt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let c=r.children[a];c instanceof Et&&s(c,r.positions[a]+o)}};return s(j(e),0),i}get allowsNesting(){return!0}}Re.setState=D.define();function ol(n,e,t){let i=n.facet(dt),s=j(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,t,kr.ExcludeBuffers))r.type.isTop&&(s=r);return s}class Kt extends Re{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Th(e.languageData);return new Kt(t,e.parser.configure({props:[Bt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Kt(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function j(n){let e=n.field(Re.state,!1);return e?e.tree:Et.empty}class Ap{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 i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let si=null;class En{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new En(e,t,[],Et.empty,0,i,[],null)}startParse(){return this.parser.startParse(new Ap(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=Et.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(cn.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=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(cn.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=si;si=this;try{return e()}finally{si=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=ll(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((c,h,f,u)=>a.push({fromA:c,toA:h,fromB:f,toB:u})),i=cn.applyChanges(i,a),s=Et.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let c of this.skipped){let h=e.mapPos(c.from,1),f=e.mapPos(c.to,-1);h<f&&l.push({from:h,to:f})}}}return new En(this.parser,t,i,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=ll(this.fragments,s,r),this.skipped.splice(i--,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 vf{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=si;if(a){for(let c of s)a.tempSkipped.push(c);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new Et(Cr.none,[],[],o-r)},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 si}}function ll(n,e,t){return cn.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class _t{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),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new _t(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=En.create(e.facet(dt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new _t(i)}}Re.state=Q.define({create:_t.init,update(n,e){for(let t of e.effects)if(t.is(Re.setState))return t.value;return e.startState.facet(dt)!=e.state.facet(dt)?_t.init(e.state):n.apply(e)}});let Oh=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Oh=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const bs=typeof navigator<"u"&&(!((ys=navigator.scheduling)===null||ys===void 0)&&ys.isInputPending)?()=>navigator.scheduling.isInputPending():null,Mp=_.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(Re.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(Re.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Oh(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Re.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!bs?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>bs&&bs()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Re.setState.of(new _t(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>he(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()}}}),dt=A.define({combine(n){return n.length?n[0]:null},enables:n=>[Re.state,Mp,w.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Vr{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Tp=A.define(),Xt=A.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Pn(n){let e=n.facet(Xt);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function Mi(n,e){let t="",i=n.tabSize,s=n.facet(Xt)[0];if(s==" "){for(;e>=i;)t+=" ",e-=i;s=" "}for(let r=0;r<e;r++)t+=s;return t}function Hr(n,e){n instanceof P&&(n=new Yn(n));for(let i of n.state.facet(Tp)){let s=i(n,e);if(s!==void 0)return s}let t=j(n.state);return t.length>=e?Op(n,t,e):null}class Yn{constructor(e,t={}){this.state=e,this.options=t,this.unit=Pn(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(e,t);return i.slice(e-s,Math.min(i.length,e+100-s))}column(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.countColumn(i,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return Yt(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Gn=new Me;function Op(n,e,t){let i=e.resolveStack(t),s=i.node.enterUnfinishedNodesBefore(t);if(s!=i.node){let r=[];for(let o=s;o!=i.node;o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return Dh(i,n,t)}function Dh(n,e,t){for(let i=n;i;i=i.next){let s=Ep(i.node);if(s)return s(Wr.create(e,t,i))}return 0}function Dp(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Ep(n){let e=n.type.prop(Gn);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(Me.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>Eh(o,!0,1,void 0,r&&!Dp(o)?s.from:void 0)}return n.parent==null?Pp:null}function Pp(){return 0}class Wr extends Yn{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new Wr(e,t,i)}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 i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(Bp(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return Dh(this.context.next,this.base,this.pos)}}function Bp(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function Rp(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let c=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+c}}l=a.to}}function xn({closing:n,align:e=!0,units:t=1}){return i=>Eh(i,e,t,n)}function Eh(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=e?Rp(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const Lp=n=>n.baseIndent;function yi({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const Ip=200;function Np(){return P.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:i}=n.newSelection.main,s=t.lineAt(i);if(i>s.from+Ip)return n;let r=t.sliceString(s.from,i);if(!e.some(c=>c.test(r)))return n;let{state:o}=n,l=-1,a=[];for(let{head:c}of o.selection.ranges){let h=o.doc.lineAt(c);if(h.from==l)continue;l=h.from;let f=Hr(o,h.from);if(f==null)continue;let u=/^\s*/.exec(h.text)[0],d=Mi(o,f);u!=d&&a.push({from:h.from,to:h.from+u.length,insert:d})}return a.length?[n,{changes:a,sequential:!0}]:n})}const Fp=A.define(),Xn=new Me;function $r(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function Vp(n,e,t){let i=j(n);if(i.length<t)return null;let s=i.resolveStack(t,1),r=null;for(let o=s;o;o=o.next){let l=o.node;if(l.to<=t||l.from>t)continue;if(r&&l.from<e)break;let a=l.type.prop(Xn);if(a&&(l.to<i.length-50||i.length==n.doc.length||!Hp(l))){let c=a(l,n);c&&c.from<=t&&c.from>=e&&c.to>t&&(r=c)}}return r}function Hp(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function Bn(n,e,t){for(let i of n.facet(Fp)){let s=i(n,e,t);if(s)return s}return Vp(n,e,t)}function Ph(n,e){let t=e.mapPos(n.from,1),i=e.mapPos(n.to,-1);return t>=i?void 0:{from:t,to:i}}const Qn=D.define({map:Ph}),Fi=D.define({map:Ph});function Bh(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(i=>i.from<=t&&i.to>=t)||e.push(n.lineBlockAt(t));return e}const Ct=Q.define({create(){return T.none},update(n,e){n=n.map(e.changes);for(let t of e.effects)if(t.is(Qn)&&!Wp(n,t.value.from,t.value.to)){let{preparePlaceholder:i}=e.state.facet(Ih),s=i?T.replace({widget:new Jp(i(e.state,t.value))}):al;n=n.update({add:[s.range(t.value.from,t.value.to)]})}else t.is(Fi)&&(n=n.update({filter:(i,s)=>t.value.from!=i||t.value.to!=s,filterFrom:t.value.from,filterTo:t.value.to}));if(e.selection){let t=!1,{head:i}=e.selection.main;n.between(i,i,(s,r)=>{s<i&&r>i&&(t=!0)}),t&&(n=n.update({filterFrom:i,filterTo:i,filter:(s,r)=>r<=i||s>=i}))}return n},provide:n=>w.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(i,s)=>{t.push(i,s)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let i=n[t++],s=n[t++];if(typeof i!="number"||typeof s!="number")throw new RangeError("Invalid JSON for fold state");e.push(al.range(i,s))}return T.set(e,!0)}});function Rn(n,e,t){var i;let s=null;return(i=n.field(Ct,!1))===null||i===void 0||i.between(e,t,(r,o)=>{(!s||s.from>r)&&(s={from:r,to:o})}),s}function Wp(n,e,t){let i=!1;return n.between(e,e,(s,r)=>{s==e&&r==t&&(i=!0)}),i}function Rh(n,e){return n.field(Ct,!1)?e:e.concat(D.appendConfig.of(Nh()))}const $p=n=>{for(let e of Bh(n)){let t=Bn(n.state,e.from,e.to);if(t)return n.dispatch({effects:Rh(n.state,[Qn.of(t),Lh(n,t)])}),!0}return!1},zp=n=>{if(!n.state.field(Ct,!1))return!1;let e=[];for(let t of Bh(n)){let i=Rn(n.state,t.from,t.to);i&&e.push(Fi.of(i),Lh(n,i,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function Lh(n,e,t=!0){let i=n.state.doc.lineAt(e.from).number,s=n.state.doc.lineAt(e.to).number;return w.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${i} ${n.state.phrase("to")} ${s}.`)}const jp=n=>{let{state:e}=n,t=[];for(let i=0;i<e.doc.length;){let s=n.lineBlockAt(i),r=Bn(e,s.from,s.to);r&&t.push(Qn.of(r)),i=(r?n.lineBlockAt(r.to):s).to+1}return t.length&&n.dispatch({effects:Rh(n.state,t)}),!!t.length},qp=n=>{let e=n.state.field(Ct,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(i,s)=>{t.push(Fi.of({from:i,to:s}))}),n.dispatch({effects:t}),!0},Kp=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:$p},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:zp},{key:"Ctrl-Alt-[",run:jp},{key:"Ctrl-Alt-]",run:qp}],_p={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},Ih=A.define({combine(n){return Je(n,_p)}});function Nh(n){return[Ct,Gp]}function Fh(n,e){let{state:t}=n,i=t.facet(Ih),s=o=>{let l=n.lineBlockAt(n.posAtDOM(o.target)),a=Rn(n.state,l.from,l.to);a&&n.dispatch({effects:Fi.of(a)}),o.preventDefault()};if(i.placeholderDOM)return i.placeholderDOM(n,s,e);let r=document.createElement("span");return r.textContent=i.placeholderText,r.setAttribute("aria-label",t.phrase("folded code")),r.title=t.phrase("unfold"),r.className="cm-foldPlaceholder",r.onclick=s,r}const al=T.replace({widget:new class extends Fe{toDOM(n){return Fh(n,null)}}});class Jp extends Fe{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return Fh(e,this.value)}}const Up={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class xs extends et{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function Yp(n={}){let e=Object.assign(Object.assign({},Up),n),t=new xs(e,!0),i=new xs(e,!1),s=_.fromClass(class{constructor(o){this.from=o.viewport.from,this.markers=this.buildMarkers(o)}update(o){(o.docChanged||o.viewportChanged||o.startState.facet(dt)!=o.state.facet(dt)||o.startState.field(Ct,!1)!=o.state.field(Ct,!1)||j(o.startState)!=j(o.state)||e.foldingChanged(o))&&(this.markers=this.buildMarkers(o.view))}buildMarkers(o){let l=new ft;for(let a of o.viewportLineBlocks){let c=Rn(o.state,a.from,a.to)?i:Bn(o.state,a.from,a.to)?t:null;c&&l.add(a.from,a.from,c)}return l.finish()}}),{domEventHandlers:r}=e;return[s,mp({class:"cm-foldGutter",markers(o){var l;return((l=o.plugin(s))===null||l===void 0?void 0:l.markers)||R.empty},initialSpacer(){return new xs(e,!1)},domEventHandlers:Object.assign(Object.assign({},r),{click:(o,l,a)=>{if(r.click&&r.click(o,l,a))return!0;let c=Rn(o.state,l.from,l.to);if(c)return o.dispatch({effects:Fi.of(c)}),!0;let h=Bn(o.state,l.from,l.to);return h?(o.dispatch({effects:Qn.of(h)}),!0):!1}})}),Nh()]}const Gp=w.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class At{constructor(e,t){this.specs=e;let i;function s(l){let a=ht.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof Re?l=>l.prop(Bt)==o.data:o?l=>l==o:void 0,this.style=wf(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ht(i):null,this.themeType=t.themeType}static define(e,t){return new At(e,t||{})}}const cr=A.define(),Vh=A.define({combine(n){return n.length?[n[0]]:null}});function vs(n){let e=n.facet(cr);return e.length?e:n.facet(Vh)}function Zn(n,e){let t=[Qp],i;return n instanceof At&&(n.module&&t.push(w.styleModule.of(n.module)),i=n.themeType),e!=null&&e.fallback?t.push(Vh.of(n)):i?t.push(cr.computeN([w.darkTheme],s=>s.facet(w.darkTheme)==(i=="dark")?[n]:[])):t.push(cr.of(n)),t}class Xp{constructor(e){this.markCache=Object.create(null),this.tree=j(e.state),this.decorations=this.buildDeco(e,vs(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=j(e.state),i=vs(e.state),s=i!=vs(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!s&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return T.none;let i=new ft;for(let{from:s,to:r}of e.visibleRanges)Sf(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=T.mark({class:a})))},s,r);return i.finish()}}const Qp=pt.high(_.fromClass(Xp,{decorations:n=>n.decorations})),Zp=At.define([{tag:m.meta,color:"#404740"},{tag:m.link,textDecoration:"underline"},{tag:m.heading,textDecoration:"underline",fontWeight:"bold"},{tag:m.emphasis,fontStyle:"italic"},{tag:m.strong,fontWeight:"bold"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.keyword,color:"#708"},{tag:[m.atom,m.bool,m.url,m.contentSeparator,m.labelName],color:"#219"},{tag:[m.literal,m.inserted],color:"#164"},{tag:[m.string,m.deleted],color:"#a11"},{tag:[m.regexp,m.escape,m.special(m.string)],color:"#e40"},{tag:m.definition(m.variableName),color:"#00f"},{tag:m.local(m.variableName),color:"#30a"},{tag:[m.typeName,m.namespace],color:"#085"},{tag:m.className,color:"#167"},{tag:[m.special(m.variableName),m.macroName],color:"#256"},{tag:m.definition(m.propertyName),color:"#00c"},{tag:m.comment,color:"#940"},{tag:m.invalid,color:"#f00"}]),em=w.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Hh=1e4,Wh="()[]{}",$h=A.define({combine(n){return Je(n,{afterCursor:!0,brackets:Wh,maxScanDistance:Hh,renderMatch:nm})}}),tm=T.mark({class:"cm-matchingBracket"}),im=T.mark({class:"cm-nonmatchingBracket"});function nm(n){let e=[],t=n.matched?tm:im;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}const sm=Q.define({create(){return T.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet($h);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=je(e.state,s.head,-1,i)||s.head>0&&je(e.state,s.head-1,1,i)||i.afterCursor&&(je(e.state,s.head,1,i)||s.head<e.state.doc.length&&je(e.state,s.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e.state)))}return T.set(t,!0)},provide:n=>w.decorations.from(n)}),rm=[sm,em];function om(n={}){return[$h.of(n),rm]}const lm=new Me;function fr(n,e,t){let i=n.prop(e<0?Me.openedBy:Me.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function ur(n){let e=n.type.prop(lm);return e?e(n.node):n}function je(n,e,t,i={}){let s=i.maxScanDistance||Hh,r=i.brackets||Wh,o=j(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let c=fr(a.type,t,r);if(c&&a.from<a.to){let h=ur(a);if(h&&(t>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return am(n,e,t,a,h,c,r)}}return hm(n,e,t,o,l.type,s,r)}function am(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},c=0,h=l==null?void 0:l.cursor();if(h&&(t<0?h.childBefore(i.from):h.childAfter(i.to)))do if(t<0?h.to<=i.from:h.from>=i.to){if(c==0&&r.indexOf(h.type.name)>-1&&h.from<h.to){let f=ur(h);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(fr(h.type,t,o))c++;else if(fr(h.type,-t,o)){if(c==0){let f=ur(h);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}c--}}while(t<0?h.prevSibling():h.nextSibling());return{start:a,matched:!1}}function hm(n,e,t,i,s,r,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let c={from:t<0?e-1:e,to:t>0?e+1:e},h=n.doc.iterRange(e,t>0?n.doc.length:0),f=0;for(let u=0;!h.next().done&&u<=r;){let d=h.value;t<0&&(u+=d.length);let p=e+u*t;for(let g=t>0?0:d.length-1,y=t>0?d.length:-1;g!=y;g+=t){let b=o.indexOf(d[g]);if(!(b<0||i.resolveInner(p+g,1).type!=s))if(b%2==0==t>0)f++;else{if(f==1)return{start:c,end:{from:p+g,to:p+g+1},matched:b>>1==a>>1};f--}}t>0&&(u+=d.length)}return h.done?{start:c,matched:!1}:null}const cm=Object.create(null),hl=[Cr.none],cl=[],fl=Object.create(null),fm=Object.create(null);for(let[n,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"]])fm[n]=um(cm,e);function ws(n,e){cl.indexOf(n)>-1||(cl.push(n),console.warn(e))}function um(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let c of l.split(".")){let h=n[c]||m[c];h?typeof h=="function"?a.length?a=a.map(h):ws(c,`Modifier ${c} used at start of tag`):a.length?ws(c,`Tag ${c} used as modifier`):a=Array.isArray(h)?h:[h]:ws(c,`Unknown highlighting tag ${c}`)}for(let c of a)t.push(c)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=fl[s];if(r)return r.id;let o=fl[s]=Cr.define({id:hl.length,name:i,props:[kf({[i]:t})]});return hl.push(o),o.id}W.RTL,W.LTR;const dm=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=jr(n.state,t.from);return i.line?pm(n):i.block?gm(n):!1};function zr(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}const pm=zr(xm,0),mm=zr(zh,0),gm=zr((n,e)=>zh(n,e,bm(e)),0);function jr(n,e){let t=n.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const ri=50;function ym(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-ri,i),o=n.sliceDoc(s,s+ri),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,c=r.length-l;if(r.slice(c-e.length,c)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let h,f;s-i<=2*ri?h=f=n.sliceDoc(i,s):(h=n.sliceDoc(i,i+ri),f=n.sliceDoc(s-ri,s));let u=/^\s*/.exec(h)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return h.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(h.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function bm(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to);s.from>i.from&&s.from==t.to&&(s=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function zh(n,e,t=e.selection.ranges){let i=t.map(r=>jr(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>ym(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=i[o],{open:c,close:h}=l;r.push({from:c.pos-a.open.length,to:c.pos+c.margin},{from:h.pos-h.margin,to:h.pos+a.close.length})}return{changes:r}}return null}function xm(n,e,t=e.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of t){let l=i.length,a=1e9,c=jr(e,r).line;if(c){for(let h=r;h<=o;){let f=e.doc.lineAt(h);if(f.from>s&&(r==o||o>f.from)){s=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+c.length)==c?u:-1;u<f.text.length&&u<a&&(a=u),i.push({line:f,comment:p,token:c,indent:u,empty:d,single:!1})}h=f.to+1}if(a<1e9)for(let h=l;h<i.length;h++)i[h].indent<i[h].line.text.length&&(i[h].indent=a);i.length==l+1&&(i[l].single=!0)}}if(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:c,empty:h,single:f}of i)(f||!h)&&r.push({from:l.from+c,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let c=o.from+l,h=c+a.length;o.text[h-o.from]==" "&&h++,r.push({from:c,to:h})}return{changes:r}}return null}const dr=Ne.define(),vm=Ne.define(),wm=A.define(),jh=A.define({combine(n){return Je(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}}),qh=Q.define({create(){return qe.empty},update(n,e){let t=e.state.facet(jh),i=e.annotation(dr);if(i){let a=ge.fromTransaction(e,i.selection),c=i.side,h=c==0?n.undone:n.done;return a?h=Ln(h,h.length,t.minDepth,a):h=Jh(h,e.startState.selection),new qe(c==0?i.rest:h,c==0?h:i.rest)}let s=e.annotation(vm);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(Y.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=ge.fromTransaction(e),o=e.annotation(Y.time),l=e.annotation(Y.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new qe(n.done.map(ge.fromJSON),n.undone.map(ge.fromJSON))}});function Sm(n={}){return[qh,jh.of(n),w.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?Kh:e.inputType=="historyRedo"?pr:null;return i?(e.preventDefault(),i(t)):!1}})]}function es(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(qh,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}const Kh=es(0,!1),pr=es(1,!1),km=es(0,!0),Cm=es(1,!0);class ge{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new ge(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new ge(e.changes&&ee.fromJSON(e.changes),[],e.mapped&&_e.fromJSON(e.mapped),e.startSelection&&x.fromJSON(e.startSelection),e.selectionsAfter.map(x.fromJSON))}static fromTransaction(e,t){let i=Ce;for(let s of e.startState.facet(wm)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new ge(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Ce)}static selection(e){return new ge(void 0,Ce,void 0,void 0,e)}}function Ln(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function Am(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let c=t[a++],h=t[a++];l>=c&&o<=h&&(i=!0)}}),i}function Mm(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function _h(n,e){return n.length?e.length?n.concat(e):n:e}const Ce=[],Tm=200;function Jh(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Tm));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),Ln(n,n.length-1,1e9,t.setSelAfter(i)))}else return[ge.selection([e])]}function Om(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function Ss(n,e){if(!n.length)return n;let t=n.length,i=Ce;for(;t;){let s=Dm(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[ge.selection(i)]:Ce}function Dm(n,e,t){let i=_h(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Ce,t);if(!n.changes)return ge.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new ge(s,D.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}const Em=/^(input\.type|delete)($|\.)/;class qe{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new qe(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Em.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,Am(l.changes,e.changes))||i=="input.type.compose")?o=Ln(o,o.length-1,s.minDepth,new ge(e.changes.compose(l.changes),_h(D.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Ce)):o=Ln(o,o.length,s.minDepth,e),new qe(o,Ce,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Ce;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Mm(r[r.length-1],e)?this:new qe(Jh(this.done,e),this.undone,t,i)}addMapping(e){return new qe(Ss(this.done,e),Ss(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],o=r.selectionsAfter[0]||t.selection;if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:dr.of({side:e,rest:Om(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=s.length==1?Ce:s.slice(0,s.length-1);return r.mapped&&(l=Ss(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:dr.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}qe.empty=new qe(Ce,Ce);const Pm=[{key:"Mod-z",run:Kh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:pr,preventDefault:!0},{linux:"Ctrl-Shift-z",run:pr,preventDefault:!0},{key:"Mod-u",run:km,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Cm,preventDefault:!0}];function Qt(n,e){return x.create(n.ranges.map(e),n.mainIndex)}function Ue(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Ve({state:n,dispatch:e},t){let i=Qt(n.selection,t);return i.eq(n.selection,!0)?!1:(e(Ue(n,i)),!0)}function ts(n,e){return x.cursor(e?n.to:n.from)}function Uh(n,e){return Ve(n,t=>t.empty?n.moveByChar(t,e):ts(t,e))}function ae(n){return n.textDirectionAt(n.state.selection.main.head)==W.LTR}const Yh=n=>Uh(n,!ae(n)),Gh=n=>Uh(n,ae(n));function Xh(n,e){return Ve(n,t=>t.empty?n.moveByGroup(t,e):ts(t,e))}const Bm=n=>Xh(n,!ae(n)),Rm=n=>Xh(n,ae(n));function Lm(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function is(n,e,t){let i=j(n).resolveInner(e.head),s=t?Me.closedBy:Me.openedBy;for(let a=e.head;;){let c=t?i.childAfter(a):i.childBefore(a);if(!c)break;Lm(n,c,s)?i=c:a=t?c.to:c.from}let r=i.type.prop(s),o,l;return r&&(o=t?je(n,i.from,1):je(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,x.cursor(l,t?-1:1)}const Im=n=>Ve(n,e=>is(n.state,e,!ae(n))),Nm=n=>Ve(n,e=>is(n.state,e,ae(n)));function Qh(n,e){return Ve(n,t=>{if(!t.empty)return ts(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const Zh=n=>Qh(n,!1),ec=n=>Qh(n,!0);function tc(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,s;if(e){for(let r of n.state.facet(w.scrollMargins)){let o=r(n);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}s=n.scrollDOM.clientHeight-t-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,s-5)}}function ic(n,e){let t=tc(n),{state:i}=n,s=Qt(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):ts(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,c=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<c&&(r=w.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Ue(i,s),{effects:r}),!0}const ul=n=>ic(n,!1),mr=n=>ic(n,!0);function mt(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=x.cursor(i.from+r))}return s}const Fm=n=>Ve(n,e=>mt(n,e,!0)),Vm=n=>Ve(n,e=>mt(n,e,!1)),Hm=n=>Ve(n,e=>mt(n,e,!ae(n))),Wm=n=>Ve(n,e=>mt(n,e,ae(n))),$m=n=>Ve(n,e=>x.cursor(n.lineBlockAt(e.head).from,1)),zm=n=>Ve(n,e=>x.cursor(n.lineBlockAt(e.head).to,-1));function jm(n,e,t){let i=!1,s=Qt(n.selection,r=>{let o=je(n,r.head,-1)||je(n,r.head,1)||r.head>0&&je(n,r.head-1,1)||r.head<n.doc.length&&je(n,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return x.cursor(l)});return i?(e(Ue(n,s)),!0):!1}const qm=({state:n,dispatch:e})=>jm(n,e);function Oe(n,e){let t=Qt(n.state.selection,i=>{let s=e(i);return x.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Ue(n.state,t)),!0)}function nc(n,e){return Oe(n,t=>n.moveByChar(t,e))}const sc=n=>nc(n,!ae(n)),rc=n=>nc(n,ae(n));function oc(n,e){return Oe(n,t=>n.moveByGroup(t,e))}const Km=n=>oc(n,!ae(n)),_m=n=>oc(n,ae(n)),Jm=n=>Oe(n,e=>is(n.state,e,!ae(n))),Um=n=>Oe(n,e=>is(n.state,e,ae(n)));function lc(n,e){return Oe(n,t=>n.moveVertically(t,e))}const ac=n=>lc(n,!1),hc=n=>lc(n,!0);function cc(n,e){return Oe(n,t=>n.moveVertically(t,e,tc(n).height))}const dl=n=>cc(n,!1),pl=n=>cc(n,!0),Ym=n=>Oe(n,e=>mt(n,e,!0)),Gm=n=>Oe(n,e=>mt(n,e,!1)),Xm=n=>Oe(n,e=>mt(n,e,!ae(n))),Qm=n=>Oe(n,e=>mt(n,e,ae(n))),Zm=n=>Oe(n,e=>x.cursor(n.lineBlockAt(e.head).from)),eg=n=>Oe(n,e=>x.cursor(n.lineBlockAt(e.head).to)),ml=({state:n,dispatch:e})=>(e(Ue(n,{anchor:0})),!0),gl=({state:n,dispatch:e})=>(e(Ue(n,{anchor:n.doc.length})),!0),yl=({state:n,dispatch:e})=>(e(Ue(n,{anchor:n.selection.main.anchor,head:0})),!0),bl=({state:n,dispatch:e})=>(e(Ue(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),tg=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),ig=({state:n,dispatch:e})=>{let t=ns(n).map(({from:i,to:s})=>x.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:x.create(t),userEvent:"select"})),!0},ng=({state:n,dispatch:e})=>{let t=Qt(n.selection,i=>{let s=j(n),r=s.resolveStack(i.from,1);if(i.empty){let o=s.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return x.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Ue(n,t)),!0)},sg=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=x.create([t.main]):t.main.empty||(i=x.create([x.cursor(t.main.head)])),i?(e(Ue(n,i)),!0):!1};function Vi(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=nn(n,a,!1)):a>o&&(t="delete.forward",a=nn(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=nn(n,o,!1),l=nn(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:x.cursor(o,o<r.head?-1:1)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?w.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function nn(n,e,t){if(n instanceof w)for(let i of n.state.facet(w.atomicRanges).map(s=>s(n)))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}const fc=(n,e,t)=>Vi(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let c=Yt(l,r.tabSize),h=c%Pn(r)||Pn(r);for(let f=0;f<h&&l[l.length-1-f]==" ";f++)s--;a=s}else a=re(o.text,s-o.from,e,e)+o.from,a==s&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,s-o.from))&&(a=re(o.text,a-o.from,!1,!1)+o.from);return a}),gr=n=>fc(n,!1,!0),uc=n=>fc(n,!0,!1),dc=(n,e)=>Vi(n,t=>{let i=t.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=re(r.text,i-r.from,e)+r.from,c=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),h=o(c);if(l!=null&&h!=l)break;(c!=" "||i!=t.head)&&(l=h),i=a}return i}),pc=n=>dc(n,!1),rg=n=>dc(n,!0),og=n=>Vi(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),lg=n=>Vi(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),ag=n=>Vi(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),hg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:B.of(["",""])},range:x.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},cg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:re(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:re(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:x.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function ns(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function mc(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of ns(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(x.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(x.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:x.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const fg=({state:n,dispatch:e})=>mc(n,e,!1),ug=({state:n,dispatch:e})=>mc(n,e,!0);function gc(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of ns(n))t?i.push({from:s.from,insert:n.doc.slice(s.from,s.to)+n.lineBreak}):i.push({from:s.to,insert:n.lineBreak+n.doc.slice(s.from,s.to)});return e(n.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const dg=({state:n,dispatch:e})=>gc(n,e,!1),pg=({state:n,dispatch:e})=>gc(n,e,!0),mg=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(ns(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=Qt(e.selection,s=>{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function gg(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=j(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(Me.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const xl=yc(!1),yg=yc(!0);function yc(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&gg(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let c=new Yn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),h=Hr(c,r);for(h==null&&(h=Yt(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",Mi(e,h)];return a&&f.push(Mi(e,c.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:B.of(f)},range:x.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function qr(n,e){let t=-1;return n.changeByRange(i=>{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:x.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const bg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Yn(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=qr(n,(r,o,l)=>{let a=Hr(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let c=/^\s*/.exec(r.text)[0],h=Mi(n,a);(c!=h||l.from<r.from+c.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+c.length,insert:h}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},bc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(qr(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Xt)})}),{userEvent:"input.indent"})),!0),xc=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(qr(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=Yt(s,n.tabSize),o=0,l=Mi(n,Math.max(0,r-Pn(n)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),xg=n=>(n.setTabFocusMode(),!0),vg=[{key:"Ctrl-b",run:Yh,shift:sc,preventDefault:!0},{key:"Ctrl-f",run:Gh,shift:rc},{key:"Ctrl-p",run:Zh,shift:ac},{key:"Ctrl-n",run:ec,shift:hc},{key:"Ctrl-a",run:$m,shift:Zm},{key:"Ctrl-e",run:zm,shift:eg},{key:"Ctrl-d",run:uc},{key:"Ctrl-h",run:gr},{key:"Ctrl-k",run:og},{key:"Ctrl-Alt-h",run:pc},{key:"Ctrl-o",run:hg},{key:"Ctrl-t",run:cg},{key:"Ctrl-v",run:mr}],wg=[{key:"ArrowLeft",run:Yh,shift:sc,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Bm,shift:Km,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Hm,shift:Xm,preventDefault:!0},{key:"ArrowRight",run:Gh,shift:rc,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Rm,shift:_m,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Wm,shift:Qm,preventDefault:!0},{key:"ArrowUp",run:Zh,shift:ac,preventDefault:!0},{mac:"Cmd-ArrowUp",run:ml,shift:yl},{mac:"Ctrl-ArrowUp",run:ul,shift:dl},{key:"ArrowDown",run:ec,shift:hc,preventDefault:!0},{mac:"Cmd-ArrowDown",run:gl,shift:bl},{mac:"Ctrl-ArrowDown",run:mr,shift:pl},{key:"PageUp",run:ul,shift:dl},{key:"PageDown",run:mr,shift:pl},{key:"Home",run:Vm,shift:Gm,preventDefault:!0},{key:"Mod-Home",run:ml,shift:yl},{key:"End",run:Fm,shift:Ym,preventDefault:!0},{key:"Mod-End",run:gl,shift:bl},{key:"Enter",run:xl,shift:xl},{key:"Mod-a",run:tg},{key:"Backspace",run:gr,shift:gr},{key:"Delete",run:uc},{key:"Mod-Backspace",mac:"Alt-Backspace",run:pc},{key:"Mod-Delete",mac:"Alt-Delete",run:rg},{mac:"Mod-Backspace",run:lg},{mac:"Mod-Delete",run:ag}].concat(vg.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Sg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Im,shift:Jm},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Nm,shift:Um},{key:"Alt-ArrowUp",run:fg},{key:"Shift-Alt-ArrowUp",run:dg},{key:"Alt-ArrowDown",run:ug},{key:"Shift-Alt-ArrowDown",run:pg},{key:"Escape",run:sg},{key:"Mod-Enter",run:yg},{key:"Alt-l",mac:"Ctrl-l",run:ig},{key:"Mod-i",run:ng,preventDefault:!0},{key:"Mod-[",run:xc},{key:"Mod-]",run:bc},{key:"Mod-Alt-\\",run:bg},{key:"Shift-Mod-k",run:mg},{key:"Shift-Mod-\\",run:qm},{key:"Mod-/",run:dm},{key:"Alt-A",run:mm},{key:"Ctrl-m",mac:"Shift-Alt-m",run:xg}].concat(wg),kg={key:"Tab",run:bc,shift:xc},Pb=()=>n=>{try{JSON.parse(n.state.doc.toString())}catch(e){if(!(e instanceof SyntaxError))throw e;const t=Cg(e,n.state.doc);return[{from:t,message:e.message,severity:"error",to:t}]}return[]};function Cg(n,e){let t;return(t=n.message.match(/at position (\d+)/))?Math.min(+t[1],e.length):(t=n.message.match(/at line (\d+) column (\d+)/))?Math.min(e.line(+t[1]).from+ +t[2]-1,e.length):0}const Ag=Kt.define({name:"json",parser:Cf.configure({props:[Gn.add({Object:yi({except:/^\s*\}/}),Array:yi({except:/^\s*\]/})}),Xn.add({"Object Array":$r})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function Bb(){return new Vr(Ag)}class Mg{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class yt{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let s=e,r=i.facet(Ke).markerFilter;r&&(s=r(s,i));let o=T.set(s.map(l=>l.from==l.to||l.from==l.to-1&&i.doc.lineAt(l.from).to==l.from?T.widget({widget:new Ng(l),diagnostic:l}).range(l.from):T.mark({attributes:{class:"cm-lintRange cm-lintRange-"+l.severity+(l.markClass?" "+l.markClass:"")},diagnostic:l}).range(l.from,l.to)),!0);return new yt(o,t,Jt(o))}}function Jt(n,e=null,t=0){let i=null;return n.between(t,1e9,(s,r,{spec:o})=>{if(!(e&&o.diagnostic!=e))return i=new Mg(s,r,o.diagnostic),!1}),i}function Tg(n,e){let t=e.pos,i=e.end||t,s=n.state.facet(Ke).hideOn(n,t,i);if(s!=null)return s;let r=n.startState.doc.lineAt(e.pos);return!!(n.effects.some(o=>o.is(Kr))||n.changes.touchesRange(r.from,Math.max(r.to,i)))}function vc(n,e){return n.field(ve,!1)?e:e.concat(D.appendConfig.of(Cc))}function Og(n,e){return{effects:vc(n,[Kr.of(e)])}}const Kr=D.define(),_r=D.define(),wc=D.define(),ve=Q.define({create(){return new yt(T.none,null,null)},update(n,e){if(e.docChanged&&n.diagnostics.size){let t=n.diagnostics.map(e.changes),i=null,s=n.panel;if(n.selected){let r=e.changes.mapPos(n.selected.from,1);i=Jt(t,n.selected.diagnostic,r)||Jt(t,null,r)}!t.size&&s&&e.state.facet(Ke).autoPanel&&(s=null),n=new yt(t,s,i)}for(let t of e.effects)if(t.is(Kr)){let i=e.state.facet(Ke).autoPanel?t.value.length?Ti.open:null:n.panel;n=yt.init(t.value,i,e.state)}else t.is(_r)?n=new yt(n.diagnostics,t.value?Ti.open:null,n.selected):t.is(wc)&&(n=new yt(n.diagnostics,n.panel,t.value));return n},provide:n=>[Ai.from(n,e=>e.panel),w.decorations.from(n,e=>e.diagnostics)]}),Dg=T.mark({class:"cm-lintRange cm-lintRange-active"});function Eg(n,e,t){let{diagnostics:i}=n.state.field(ve),s=[],r=2e8,o=0;i.between(e-(t<0?1:0),e+(t>0?1:0),(a,c,{spec:h})=>{e>=a&&e<=c&&(a==c||(e>a||t>0)&&(e<c||t<0))&&(s.push(h.diagnostic),r=Math.min(a,r),o=Math.max(c,o))});let l=n.state.facet(Ke).tooltipFilter;return l&&(s=l(s,n.state)),s.length?{pos:r,end:o,above:n.state.doc.lineAt(r).to<o,create(){return{dom:Pg(n,s)}}}:null}function Pg(n,e){return V("ul",{class:"cm-tooltip-lint"},e.map(t=>kc(n,t,!1)))}const Bg=n=>{let e=n.state.field(ve,!1);(!e||!e.panel)&&n.dispatch({effects:vc(n.state,[_r.of(!0)])});let t=Ci(n,Ti.open);return t&&t.dom.querySelector(".cm-panel-lint ul").focus(),!0},vl=n=>{let e=n.state.field(ve,!1);return!e||!e.panel?!1:(n.dispatch({effects:_r.of(!1)}),!0)},Rg=n=>{let e=n.state.field(ve,!1);if(!e)return!1;let t=n.state.selection.main,i=e.diagnostics.iter(t.to+1);return!i.value&&(i=e.diagnostics.iter(0),!i.value||i.from==t.from&&i.to==t.to)?!1:(n.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),!0)},Lg=[{key:"Mod-Shift-m",run:Bg,preventDefault:!0},{key:"F8",run:Rg}],Ig=_.fromClass(class{constructor(n){this.view=n,this.timeout=-1,this.set=!0;let{delay:e}=n.state.facet(Ke);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let n=Date.now();if(n<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-n);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(Ke);t.length&&Promise.all(t.map(i=>Promise.resolve(i(this.view)))).then(i=>{let s=i.reduce((r,o)=>r.concat(o));this.view.state.doc==e.doc&&this.view.dispatch(Og(this.view.state,s))},i=>{he(this.view.state,i)})}}update(n){let e=n.state.facet(Ke);(n.docChanged||e!=n.startState.facet(Ke)||e.needsRefresh&&e.needsRefresh(n))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}}),Ke=A.define({combine(n){return Object.assign({sources:n.map(e=>e.source).filter(e=>e!=null)},Je(n.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t}))}});function Rb(n,e={}){return[Ke.of({source:n,config:e}),Ig,Cc]}function Sc(n){let e=[];if(n)e:for(let{name:t}of n){for(let i=0;i<t.length;i++){let s=t[i];if(/[a-zA-Z]/.test(s)&&!e.some(r=>r.toLowerCase()==s.toLowerCase())){e.push(s);continue e}}e.push("")}return e}function kc(n,e,t){var i;let s=t?Sc(e.actions):[];return V("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},V("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(n):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,a=u=>{if(u.preventDefault(),l)return;l=!0;let d=Jt(n.state.field(ve).diagnostics,e);d&&r.apply(n,d.from,d.to)},{name:c}=r,h=s[o]?c.indexOf(s[o]):-1,f=h<0?c:[c.slice(0,h),V("u",c.slice(h,h+1)),c.slice(h+1)];return V("button",{type:"button",class:"cm-diagnosticAction",onclick:a,onmousedown:a,"aria-label":` Action: ${c}${h<0?"":` (access key "${s[o]})"`}.`},f)}),e.source&&V("div",{class:"cm-diagnosticSource"},e.source))}class Ng extends Fe{constructor(e){super(),this.diagnostic=e}eq(e){return e.diagnostic==this.diagnostic}toDOM(){return V("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class wl{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=kc(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Ti{constructor(e){this.view=e,this.items=[];let t=s=>{if(s.keyCode==27)vl(this.view),this.view.focus();else if(s.keyCode==38||s.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(s.keyCode==40||s.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(s.keyCode==36)this.moveSelection(0);else if(s.keyCode==35)this.moveSelection(this.items.length-1);else if(s.keyCode==13)this.view.focus();else if(s.keyCode>=65&&s.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=Sc(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==s.keyCode){let a=Jt(this.view.state.field(ve).diagnostics,r);a&&r.actions[l].apply(e,a.from,a.to)}}else return;s.preventDefault()},i=s=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(s.target)&&this.moveSelection(r)};this.list=V("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=V("div",{class:"cm-panel-lint"},this.list,V("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>vl(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(ve).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(ve),i=0,s=!1,r=null;for(e.between(0,this.view.state.doc.length,(o,l,{spec:a})=>{let c=-1,h;for(let f=i;f<this.items.length;f++)if(this.items[f].diagnostic==a.diagnostic){c=f;break}c<0?(h=new wl(this.view,a.diagnostic),this.items.splice(i,0,h),s=!0):(h=this.items[c],c>i&&(this.items.splice(i,c-i),s=!0)),t&&h.diagnostic==t.diagnostic?h.dom.hasAttribute("aria-selected")||(h.dom.setAttribute("aria-selected","true"),r=h):h.dom.hasAttribute("aria-selected")&&h.dom.removeAttribute("aria-selected"),i++});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();this.items.length==0&&(this.items.push(new wl(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:o,panel:l})=>{let a=l.height/this.list.offsetHeight;o.top<l.top?this.list.scrollTop-=(l.top-o.top)/a:o.bottom>l.bottom&&(this.list.scrollTop+=(o.bottom-l.bottom)/a)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(ve),i=Jt(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:wc.of(i)})}static open(e){return new Ti(e)}}function Fg(n,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(n)}</svg>')`}function sn(n){return Fg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Vg=w.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:sn("#d11")},".cm-lintRange-warning":{backgroundImage:sn("orange")},".cm-lintRange-info":{backgroundImage:sn("#999")},".cm-lintRange-hint":{backgroundImage:sn("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}}),Cc=[ve,w.decorations.compute([ve],n=>{let{selected:e,panel:t}=n.field(ve);return!e||!t||e.from==e.to?T.none:T.set([Dg.range(e.from,e.to)])}),up(Eg,{hideOn:Tg}),Vg];var Ac=n=>{var{theme:e,settings:t={},styles:i=[]}=n,s={".cm-gutters":{}},r={};t.background&&(r.backgroundColor=t.background),t.backgroundImage&&(r.backgroundImage=t.backgroundImage),t.foreground&&(r.color=t.foreground),t.fontSize&&(r.fontSize=t.fontSize),(t.background||t.foreground)&&(s["&"]=r),t.fontFamily&&(s["&.cm-editor .cm-scroller"]={fontFamily:t.fontFamily}),t.gutterBackground&&(s[".cm-gutters"].backgroundColor=t.gutterBackground),t.gutterForeground&&(s[".cm-gutters"].color=t.gutterForeground),t.gutterBorder&&(s[".cm-gutters"].borderRightColor=t.gutterBorder),t.caret&&(s[".cm-content"]={caretColor:t.caret},s[".cm-cursor, .cm-dropCursor"]={borderLeftColor:t.caret});var o={};t.gutterActiveForeground&&(o.color=t.gutterActiveForeground),t.lineHighlight&&(s[".cm-activeLine"]={backgroundColor:t.lineHighlight},o.backgroundColor=t.lineHighlight),s[".cm-activeLineGutter"]=o,t.selection&&(s["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:t.selection+" !important"}),t.selectionMatch&&(s["& .cm-selectionMatch"]={backgroundColor:t.selectionMatch});var l=w.theme(s,{dark:e==="dark"}),a=At.define(i),c=[l,Zn(a)];return c},Hg={background:"#fff",foreground:"#24292e",selection:"#BBDFFF",selectionMatch:"#BBDFFF",gutterBackground:"#fff",gutterForeground:"#6e7781"},Wg=[{tag:[m.standard(m.tagName),m.tagName],color:"#116329"},{tag:[m.comment,m.bracket],color:"#6a737d"},{tag:[m.className,m.propertyName],color:"#6f42c1"},{tag:[m.variableName,m.attributeName,m.number,m.operator],color:"#005cc5"},{tag:[m.keyword,m.typeName,m.typeOperator,m.typeName],color:"#d73a49"},{tag:[m.string,m.meta,m.regexp],color:"#032f62"},{tag:[m.name,m.quote],color:"#22863a"},{tag:[m.heading,m.strong],color:"#24292e",fontWeight:"bold"},{tag:[m.emphasis],color:"#24292e",fontStyle:"italic"},{tag:[m.deleted],color:"#b31d28",backgroundColor:"ffeef0"},{tag:[m.atom,m.bool,m.special(m.variableName)],color:"#e36209"},{tag:[m.url,m.escape,m.regexp,m.link],color:"#032f62"},{tag:m.link,textDecoration:"underline"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.invalid,color:"#cb2431"}],$g=n=>{var{theme:e="light",settings:t={},styles:i=[]}={};return Ac({theme:e,settings:qn({},Hg,t),styles:[...Wg,...i]})},Lb=$g(),zg={background:"#0d1117",foreground:"#c9d1d9",caret:"#c9d1d9",selection:"#003d73",selectionMatch:"#003d73",lineHighlight:"#36334280"},jg=[{tag:[m.standard(m.tagName),m.tagName],color:"#7ee787"},{tag:[m.comment,m.bracket],color:"#8b949e"},{tag:[m.className,m.propertyName],color:"#d2a8ff"},{tag:[m.variableName,m.attributeName,m.number,m.operator],color:"#79c0ff"},{tag:[m.keyword,m.typeName,m.typeOperator,m.typeName],color:"#ff7b72"},{tag:[m.string,m.meta,m.regexp],color:"#a5d6ff"},{tag:[m.name,m.quote],color:"#7ee787"},{tag:[m.heading,m.strong],color:"#d2a8ff",fontWeight:"bold"},{tag:[m.emphasis],color:"#d2a8ff",fontStyle:"italic"},{tag:[m.deleted],color:"#ffdcd7",backgroundColor:"ffeef0"},{tag:[m.atom,m.bool,m.special(m.variableName)],color:"#ffab70"},{tag:m.link,textDecoration:"underline"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.invalid,color:"#f97583"}],qg=n=>{var{theme:e="dark",settings:t={},styles:i=[]}={};return Ac({theme:e,settings:qn({},zg,t),styles:[...jg,...i]})};qg();var Kg=n=>{var{theme:e,settings:t={},styles:i=[]}=n,s={".cm-gutters":{}},r={};t.background&&(r.backgroundColor=t.background),t.backgroundImage&&(r.backgroundImage=t.backgroundImage),t.foreground&&(r.color=t.foreground),t.fontSize&&(r.fontSize=t.fontSize),(t.background||t.foreground)&&(s["&"]=r),t.fontFamily&&(s["&.cm-editor .cm-scroller"]={fontFamily:t.fontFamily}),t.gutterBackground&&(s[".cm-gutters"].backgroundColor=t.gutterBackground),t.gutterForeground&&(s[".cm-gutters"].color=t.gutterForeground),t.gutterBorder&&(s[".cm-gutters"].borderRightColor=t.gutterBorder),t.caret&&(s[".cm-content"]={caretColor:t.caret},s[".cm-cursor, .cm-dropCursor"]={borderLeftColor:t.caret});var o={};t.gutterActiveForeground&&(o.color=t.gutterActiveForeground),t.lineHighlight&&(s[".cm-activeLine"]={backgroundColor:t.lineHighlight},o.backgroundColor=t.lineHighlight),s[".cm-activeLineGutter"]=o,t.selection&&(s["&.cm-focused .cm-selectionBackground, & .cm-line::selection, & .cm-selectionLayer .cm-selectionBackground, .cm-content ::selection"]={background:t.selection+" !important"}),t.selectionMatch&&(s["& .cm-selectionMatch"]={backgroundColor:t.selectionMatch});var l=w.theme(s,{dark:e==="dark"}),a=At.define(i),c=[l,Zn(a)];return c},_g={background:"#2e3440",foreground:"#FFFFFF",caret:"#FFFFFF",selection:"#00000073",selectionMatch:"#00000073",gutterBackground:"#2e3440",gutterForeground:"#4c566a",gutterActiveForeground:"#d8dee9",lineHighlight:"#4c566a29"},Jg=[{tag:m.keyword,color:"#5e81ac"},{tag:[m.name,m.deleted,m.character,m.propertyName,m.macroName],color:"#88c0d0"},{tag:[m.variableName],color:"#8fbcbb"},{tag:[m.function(m.variableName)],color:"#8fbcbb"},{tag:[m.labelName],color:"#81a1c1"},{tag:[m.color,m.constant(m.name),m.standard(m.name)],color:"#5e81ac"},{tag:[m.definition(m.name),m.separator],color:"#a3be8c"},{tag:[m.brace],color:"#8fbcbb"},{tag:[m.annotation],color:"#d30102"},{tag:[m.number,m.changed,m.annotation,m.modifier,m.self,m.namespace],color:"#b48ead"},{tag:[m.typeName,m.className],color:"#ebcb8b"},{tag:[m.operator,m.operatorKeyword],color:"#a3be8c"},{tag:[m.tagName],color:"#b48ead"},{tag:[m.squareBracket],color:"#bf616a"},{tag:[m.angleBracket],color:"#d08770"},{tag:[m.attributeName],color:"#ebcb8b"},{tag:[m.regexp],color:"#5e81ac"},{tag:[m.quote],color:"#b48ead"},{tag:[m.string],color:"#a3be8c"},{tag:m.link,color:"#a3be8c",textDecoration:"underline",textUnderlinePosition:"under"},{tag:[m.url,m.escape,m.special(m.string)],color:"#8fbcbb"},{tag:[m.meta],color:"#88c0d0"},{tag:[m.monospace],color:"#d8dee9",fontStyle:"italic"},{tag:[m.comment],color:"#4c566a",fontStyle:"italic"},{tag:m.strong,fontWeight:"bold",color:"#5e81ac"},{tag:m.emphasis,fontStyle:"italic",color:"#5e81ac"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.heading,fontWeight:"bold",color:"#5e81ac"},{tag:m.special(m.heading1),fontWeight:"bold",color:"#5e81ac"},{tag:m.heading1,fontWeight:"bold",color:"#5e81ac"},{tag:[m.heading2,m.heading3,m.heading4],fontWeight:"bold",color:"#5e81ac"},{tag:[m.heading5,m.heading6],color:"#5e81ac"},{tag:[m.atom,m.bool,m.special(m.variableName)],color:"#d08770"},{tag:[m.processingInstruction,m.inserted],color:"#8fbcbb"},{tag:[m.contentSeparator],color:"#ebcb8b"},{tag:m.invalid,color:"#434c5e",borderBottom:"1px dotted #d30102"}],Ug=n=>{var{theme:e="dark",settings:t={},styles:i=[]}={};return Kg({theme:e,settings:qn({},_g,t),styles:[...Jg,...i]})},Ib=Ug();const Sl=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class Ut{constructor(e,t,i=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r(Sl(l)):Sl,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ne(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=Ar(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=ke(e);let s=this.normalize(t);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==s.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t,i){let s=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==e&&(o==this.query.length-1?s={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:t,to:i}:this.matches.push(1,t)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Ut.prototype[Symbol.iterator]=function(){return this});const Mc={from:-1,to:-1,match:/.*/.exec("")},Jr="gm"+(/x/.unicode==null?"":"u");class Tc{constructor(e,t,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Mc,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Oc(e,t,i,s,r);this.re=new RegExp(t,Jr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=In(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=In(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const ks=new WeakMap;class Vt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=ks.get(e);if(!s||s.from>=i||s.to<=t){let l=new Vt(t,e.sliceString(t,i));return ks.set(e,l),l}if(s.from==t&&s.to==i)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to<i&&(r+=e.sliceString(s.to,i)),ks.set(e,new Vt(o,r)),new Vt(t,r.slice(t-o,i-o))}}class Oc{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=Mc,this.matchPos=In(e,s),this.re=new RegExp(t,Jr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Vt.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,s=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this.matchPos=In(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Vt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Tc.prototype[Symbol.iterator]=Oc.prototype[Symbol.iterator]=function(){return this});function Yg(n){try{return new RegExp(n,Jr),!0}catch{return!1}}function In(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}function yr(n){let e=String(n.state.doc.lineAt(n.state.selection.main.head).number),t=V("input",{class:"cm-textfield",name:"line",value:e}),i=V("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),n.dispatch({effects:Nn.of(!1)}),n.focus()):r.keyCode==13&&(r.preventDefault(),s())},onsubmit:r=>{r.preventDefault(),s()}},V("label",n.state.phrase("Go to line"),": ",t)," ",V("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!r)return;let{state:o}=n,l=o.doc.lineAt(o.selection.main.head),[,a,c,h,f]=r,u=h?+h.slice(1):0,d=c?+c:l.number;if(c&&f){let y=d/100;a&&(y=y*(a=="-"?-1:1)+l.number/o.doc.lines),d=Math.round(o.doc.lines*y)}else c&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=o.doc.line(Math.max(1,Math.min(o.doc.lines,d))),g=x.cursor(p.from+Math.max(0,Math.min(u,p.length)));n.dispatch({effects:[Nn.of(!1),w.scrollIntoView(g.from,{y:"center"})],selection:g}),n.focus()}return{dom:i}}const Nn=D.define(),kl=Q.define({create(){return!0},update(n,e){for(let t of e.effects)t.is(Nn)&&(n=t.value);return n},provide:n=>Ai.from(n,e=>e?yr:null)}),Gg=n=>{let e=Ci(n,yr);if(!e){let t=[Nn.of(!0)];n.state.field(kl,!1)==null&&t.push(D.appendConfig.of([kl,Xg])),n.dispatch({effects:t}),e=Ci(n,yr)}return e&&e.dom.querySelector("input").select(),!0},Xg=w.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Qg={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Zg=A.define({combine(n){return Je(n,Qg,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function e0(n){return[r0,s0]}const t0=T.mark({class:"cm-selectionMatch"}),i0=T.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Cl(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=z.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=z.Word)}function n0(n,e,t,i){return n(e.sliceDoc(t,t+1))==z.Word&&n(e.sliceDoc(i-1,i))==z.Word}const s0=_.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.selectionSet||n.docChanged||n.viewportChanged)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=n.state.facet(Zg),{state:t}=n,i=t.selection;if(i.ranges.length>1)return T.none;let s=i.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return T.none;let a=t.wordAt(s.head);if(!a)return T.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<e.minSelectionLength||a>200)return T.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Cl(o,t,s.from,s.to)&&n0(o,t,s.from,s.to)))return T.none}else if(r=t.sliceDoc(s.from,s.to),!r)return T.none}let l=[];for(let a of n.visibleRanges){let c=new Ut(t.doc,r,a.from,a.to);for(;!c.next().done;){let{from:h,to:f}=c.value;if((!o||Cl(o,t,h,f))&&(s.empty&&h<=s.from&&f>=s.to?l.push(i0.range(h,f)):(h>=s.to||f<=s.from)&&l.push(t0.range(h,f)),l.length>e.maxMatches))return T.none}}return T.set(l)}},{decorations:n=>n.decorations}),r0=w.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),o0=({state:n,dispatch:e})=>{let{selection:t}=n,i=x.create(t.ranges.map(s=>n.wordAt(s.head)||x.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function l0(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new Ut(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Ut(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const a0=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return o0({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=l0(n,i);return s?(e(n.update({selection:n.selection.addRange(x.range(s.from,s.to),!1),effects:w.scrollIntoView(s.to)})),!0):!1},Zt=A.define({combine(n){return Je(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new v0(e),scrollToMatch:e=>w.scrollIntoView(e)})}});class Dc{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Yg(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
|
|
10
|
+
`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new u0(this):new c0(this)}getCursor(e,t=0,i){let s=e.doc?e:P.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Ot(this,s,t,i):Tt(this,s,t,i)}}class Ec{constructor(e){this.spec=e}}function Tt(n,e,t,i){return new Ut(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?h0(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function h0(n,e){return(t,i,s,r)=>((r>t||r+s.length<i)&&(r=Math.max(0,t-2),s=n.sliceString(r,Math.min(n.length,i+2))),(e(Fn(s,t-r))!=z.Word||e(Vn(s,t-r))!=z.Word)&&(e(Vn(s,i-r))!=z.Word||e(Fn(s,i-r))!=z.Word))}class c0 extends Ec{constructor(e){super(e)}nextMatch(e,t,i){let s=Tt(this.spec,e,i,e.doc.length).nextOverlapping();return s.done&&(s=Tt(this.spec,e,0,t).nextOverlapping()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let r=Math.max(t,s-1e4-this.spec.unquoted.length),o=Tt(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Tt(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Tt(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ot(n,e,t,i){return new Tc(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?f0(e.charCategorizer(e.selection.main.head)):void 0},t,i)}function Fn(n,e){return n.slice(re(n,e,!1),e)}function Vn(n,e){return n.slice(e,re(n,e))}function f0(n){return(e,t,i)=>!i[0].length||(n(Fn(i.input,i.index))!=z.Word||n(Vn(i.input,i.index))!=z.Word)&&(n(Vn(i.input,i.index+i[0].length))!=z.Word||n(Fn(i.input,i.index+i[0].length))!=z.Word)}class u0 extends Ec{nextMatch(e,t,i){let s=Ot(this.spec,e,i,e.doc.length).next();return s.done&&(s=Ot(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=1;;s++){let r=Math.max(t,i-s*1e4),o=Ot(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(t,i)=>i=="$"?"$":i=="&"?e.match[0]:i!="0"&&+i<e.match.length?e.match[i]:t)}matchAll(e,t){let i=Ot(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Ot(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const Oi=D.define(),Ur=D.define(),lt=Q.define({create(n){return new Cs(br(n).create(),null)},update(n,e){for(let t of e.effects)t.is(Oi)?n=new Cs(t.value.create(),n.panel):t.is(Ur)&&(n=new Cs(n.query,t.value?Yr:null));return n},provide:n=>Ai.from(n,e=>e.panel)});class Cs{constructor(e,t){this.query=e,this.panel=t}}const d0=T.mark({class:"cm-searchMatch"}),p0=T.mark({class:"cm-searchMatch cm-searchMatch-selected"}),m0=_.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(lt))}update(n){let e=n.state.field(lt);(e!=n.startState.field(lt)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return T.none;let{view:t}=this,i=new ft;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-2*250;)a=r[++s].to;n.highlight(t.state,l,a,(c,h)=>{let f=t.state.selection.ranges.some(u=>u.from==c&&u.to==h);i.add(c,h,f?p0:d0)})}return i.finish()}},{decorations:n=>n.decorations});function Hi(n){return e=>{let t=e.state.field(lt,!1);return t&&t.query.spec.valid?n(e,t):Rc(e)}}const Hn=Hi((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let s=x.single(i.from,i.to),r=n.state.facet(Zt);return n.dispatch({selection:s,effects:[Gr(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),Bc(n),!0}),Wn=Hi((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,s=e.prevMatch(t,i,i);if(!s)return!1;let r=x.single(s.from,s.to),o=n.state.facet(Zt);return n.dispatch({selection:r,effects:[Gr(n,s),o.scrollToMatch(r.main,n)],userEvent:"select.search"}),Bc(n),!0}),g0=Hi((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:x.create(t.map(i=>x.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),y0=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:s}=t.main,r=[],o=0;for(let l=new Ut(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(x.range(l.value.from,l.value.to))}return e(n.update({selection:x.create(r,o),userEvent:"select.search.matches"})),!0},Al=Hi((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=[],l,a,c=[];if(r.from==i&&r.to==s&&(a=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=e.nextMatch(t,r.from,r.to),c.push(w.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))),r){let h=o.length==0||o[0].from>=r.to?0:r.to-r.from-a.length;l=x.single(r.from-h,r.to-h),c.push(Gr(n,r)),c.push(t.facet(Zt).scrollToMatch(l.main,n))}return n.dispatch({changes:o,selection:l,effects:c,userEvent:"input.replace"}),!0}),b0=Hi((n,{query:e})=>{if(n.state.readOnly)return!1;let t=e.matchAll(n.state,1e9).map(s=>{let{from:r,to:o}=s;return{from:r,to:o,insert:e.getReplacement(s)}});if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:w.announce.of(i),userEvent:"input.replace.all"}),!0});function Yr(n){return n.state.facet(Zt).createPanel(n)}function br(n,e){var t,i,s,r,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let c=n.facet(Zt);return new Dc({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:c.caseSensitive,literal:(s=e==null?void 0:e.literal)!==null&&s!==void 0?s:c.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:c.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:c.wholeWord})}function Pc(n){let e=Ci(n,Yr);return e&&e.dom.querySelector("[main-field]")}function Bc(n){let e=Pc(n);e&&e==n.root.activeElement&&e.select()}const Rc=n=>{let e=n.state.field(lt,!1);if(e&&e.panel){let t=Pc(n);if(t&&t!=n.root.activeElement){let i=br(n.state,e.query.spec);i.valid&&n.dispatch({effects:Oi.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[Ur.of(!0),e?Oi.of(br(n.state,e.query.spec)):D.appendConfig.of(S0)]});return!0},Lc=n=>{let e=n.state.field(lt,!1);if(!e||!e.panel)return!1;let t=Ci(n,Yr);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Ur.of(!1)}),!0},x0=[{key:"Mod-f",run:Rc,scope:"editor search-panel"},{key:"F3",run:Hn,shift:Wn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Hn,shift:Wn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Lc,scope:"editor search-panel"},{key:"Mod-Shift-l",run:y0},{key:"Mod-Alt-g",run:Gg},{key:"Mod-d",run:a0,preventDefault:!0}];class v0{constructor(e){this.view=e;let t=this.query=e.state.field(lt).query.spec;this.commit=this.commit.bind(this),this.searchField=V("input",{value:t.search,placeholder:ye(e,"Find"),"aria-label":ye(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=V("input",{value:t.replace,placeholder:ye(e,"Replace"),"aria-label":ye(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=V("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=V("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=V("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(s,r,o){return V("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=V("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>Hn(e),[ye(e,"next")]),i("prev",()=>Wn(e),[ye(e,"previous")]),i("select",()=>g0(e),[ye(e,"all")]),V("label",null,[this.caseField,ye(e,"match case")]),V("label",null,[this.reField,ye(e,"regexp")]),V("label",null,[this.wordField,ye(e,"by word")]),...e.state.readOnly?[]:[V("br"),this.replaceField,i("replace",()=>Al(e),[ye(e,"replace")]),i("replaceAll",()=>b0(e),[ye(e,"replace all")])],V("button",{name:"close",onclick:()=>Lc(e),"aria-label":ye(e,"close"),type:"button"},["×"])])}commit(){let e=new Dc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Oi.of(e)}))}keydown(e){Cd(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Wn:Hn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Al(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(Oi)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Zt).top}}function ye(n,e){return n.state.phrase(e)}const rn=30,on=/[\s\.,:;?!]/;function Gr(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),s=n.state.doc.lineAt(t).to,r=Math.max(i.from,e-rn),o=Math.min(s,t+rn),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<rn;a++)if(!on.test(l[a+1])&&on.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-rn;a--)if(!on.test(l[a-1])&&on.test(l[a])){l=l.slice(0,a);break}}return w.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const w0=w.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),S0=[lt,pt.low(m0),w0];class Ic{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=j(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),i=Math.max(t.from,this.pos-250),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(Fc(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t){e=="abort"&&this.abortListeners&&this.abortListeners.push(t)}}function Ml(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function k0(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let i=Ml(e)+Ml(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Xr(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:k0(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function Nc(n,e){return t=>{for(let i=j(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class Tl{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}}function at(n){return n.selection.main.from}function Fc(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const Vc=Ne.define();function C0(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return Object.assign(Object.assign({},n.changeByRange(l=>l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i)?{range:l}:{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:e},range:x.cursor(l.from+r+e.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const Ol=new WeakMap;function A0(n){if(!Array.isArray(n))return n;let e=Ol.get(n);return e||Ol.set(n,e=Xr(n)),e}const $n=D.define(),Di=D.define();class M0{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<e.length;){let i=ne(e,t),s=ke(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(ne(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,!0}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return!1;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let v=ne(e,0),M=ke(v),S=M==e.length?0:-100;if(v!=t[0])if(v==i[0])S+=-200;else return!1;return this.ret(S,[0,M])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,c=0;if(l<0){for(let v=0,M=Math.min(e.length,200);v<M&&c<a;){let S=ne(e,v);(S==t[c]||S==i[c])&&(s[c++]=v),v+=ke(S)}if(c<a)return!1}let h=0,f=0,u=!1,d=0,p=-1,g=-1,y=/[a-z]/.test(e),b=!0;for(let v=0,M=Math.min(e.length,200),S=0;v<M&&f<a;){let k=ne(e,v);l<0&&(h<a&&k==t[h]&&(r[h++]=v),d<a&&(k==t[d]||k==i[d]?(d==0&&(p=v),g=v+1,d++):d=0));let O,L=k<255?k>=48&&k<=57||k>=97&&k<=122?2:k>=65&&k<=90?1:0:(O=Ar(k))!=O.toLowerCase()?1:O!=O.toUpperCase()?2:0;(!v||L==1&&y||S==0&&L!=0)&&(t[f]==k||i[f]==k&&(u=!0)?o[f++]=v:o.length&&(b=!1)),S=L,v+=ke(k)}return f==a&&o[0]==0&&b?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(g==e.length?0:-100),[0,g]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,g]):f==a?this.result(-100+(u?-200:0)+-700+(b?0:-1100),o,e):t.length==2?!1:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?ke(ne(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}}const se=A.define({combine(n){return Je(n,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:T0,compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>Dl(e(i),t(i)),optionClass:(e,t)=>i=>Dl(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})}});function Dl(n,e){return n?e?n+" "+e:n:e}function T0(n,e,t,i,s,r){let o=n.textDirection==W.RTL,l=o,a=!1,c="top",h,f,u=e.left-s.left,d=s.right-e.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))h=Math.max(s.top,Math.min(t.top,s.bottom-g))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:s.right-e.left)-30);let v=s.bottom-e.bottom;v>=g||v>e.top?h=t.bottom-e.top:(c="bottom",h=e.bottom-t.top)}let y=(e.bottom-e.top)/r.offsetHeight,b=(e.right-e.left)/r.offsetWidth;return{style:`${c}: ${h/y}px; max-width: ${f/b}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function O0(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let c=0;c<r.length;){let h=r[c++],f=r[c++];h>a&&o.appendChild(document.createTextNode(l.slice(a,h)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(h,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function As(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class D0{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(se);this.optionContent=O0(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=As(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:c}=e.state.field(t).open;for(let h=a.target,f;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(f=/-(\d+)$/.exec(h.id))&&+f[1]<c.length){this.applyCompletion(e,c[+f[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let c=e.state.field(this.stateField,!1);c&&c.tooltip&&e.state.facet(se).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Di.of(null)})}),this.showOptions(r,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 i=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=As(r.length,o,e.state.facet(se).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=s.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);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;if((t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=As(t.options.length,t.selected,this.view.state.facet(se).maxRenderedOptions),this.showOptions(t.options,e.id)),this.updateSelectedOption(t.selected)){this.destroyInfo();let{completion:i}=t.options[t.selected],{info:s}=i;if(!s)return;let r=typeof s=="string"?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,i)}).catch(o=>he(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return t&&P0(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return s.top>Math.min(r.bottom,t.bottom)-10||s.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(se).positionInfo(this.view,t,s,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:c}=l;if(c){let u=typeof c=="string"?c:c.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof c!="string"&&c.header)s.appendChild(c.header(c));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=u}}const h=s.appendChild(document.createElement("li"));h.id=t+"-"+o,h.setAttribute("role","option");let f=this.optionClass(l);f&&(h.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&h.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function E0(n,e){return t=>new D0(t,n,e)}function P0(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),s=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/s:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/s)}function El(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function B0(n,e){let t=[],i=null,s=a=>{t.push(a);let{section:c}=a.completion;if(c){i||(i=[]);let h=typeof c=="string"?c:c.name;i.some(f=>f.name==h)||i.push(typeof c=="string"?{name:h}:c)}};for(let a of n)if(a.hasResult()){let c=a.result.getMatch;if(a.result.filter===!1)for(let h of a.result.options)s(new Tl(h,a.source,c?c(h):[],1e9-t.length));else{let h=new M0(e.sliceDoc(a.from,a.to));for(let f of a.result.options)if(h.match(f.label)){let u=f.displayLabel?c?c(f,h.matched):[]:h.matched;s(new Tl(f,a.source,u,h.score+(f.boost||0)))}}}if(i){let a=Object.create(null),c=0,h=(f,u)=>{var d,p;return((d=f.rank)!==null&&d!==void 0?d:1e9)-((p=u.rank)!==null&&p!==void 0?p:1e9)||(f.name<u.name?-1:1)};for(let f of i.sort(h))c-=1e5,a[f.name]=c;for(let f of t){let{section:u}=f.completion;u&&(f.score+=a[typeof u=="string"?u:u.name])}}let r=[],o=null,l=e.facet(se).compareCompletions;for(let a of t.sort((c,h)=>h.score-c.score||l(c.completion,h.completion))){let c=a.completion;!o||o.label!=c.label||o.detail!=c.detail||o.type!=null&&c.type!=null&&o.type!=c.type||o.apply!=c.apply||o.boost!=c.boost?r.push(a):El(a.completion)>El(o)&&(r[r.length-1]=a),o=a.completion}return r}class Rt{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Rt(this.options,Pl(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r){let o=B0(e,t);if(!o.length)return s&&e.some(a=>a.state==1)?new Rt(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let l=t.facet(se).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let a=s.options[s.selected].completion;for(let c=0;c<o.length;c++)if(o[c].completion==a){l=c;break}}return new Rt(o,Pl(i,l),{pos:e.reduce((a,c)=>c.hasResult()?Math.min(a,c.from):a,1e8),create:F0,above:r.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(e){return new Rt(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class zn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new zn(I0,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(se),r=(i.override||t.languageDataAt("autocomplete",at(t)).map(A0)).map(l=>(this.active.find(c=>c.source==l)||new me(l,this.active.some(c=>c.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!R0(r,this.active)?o=Rt.build(r,t,this.id,o,i):o&&o.disabled&&!r.some(l=>l.state==1)&&(o=null),!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new me(l.source,0):l));for(let l of e.effects)l.is(Wc)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new zn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:L0}}function R0(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult;)t++;for(;i<e.length&&!e[i].hasResult;)i++;let s=t==n.length,r=i==e.length;if(s||r)return s==r;if(n[t++].result!=e[i++].result)return!1}}const L0={"aria-autocomplete":"list"};function Pl(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const I0=[];function xr(n){return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}class me{constructor(e,t,i=-1){this.source=e,this.state=t,this.explicitPos=i}hasResult(){return!1}update(e,t){let i=xr(e),s=this;i?s=s.handleUserEvent(e,i,t):e.docChanged?s=s.handleChange(e):e.selection&&s.state!=0&&(s=new me(s.source,0));for(let r of e.effects)if(r.is($n))s=new me(s.source,1,r.value?at(e.state):-1);else if(r.is(Di))s=new me(s.source,0);else if(r.is(Hc))for(let o of r.value)o.source==s.source&&(s=o);return s}handleUserEvent(e,t,i){return t=="delete"||!i.activateOnTyping?this.map(e.changes):new me(this.source,1)}handleChange(e){return e.changes.touchesRange(at(e.startState))?new me(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new me(this.source,this.state,e.mapPos(this.explicitPos))}}class Ht extends me{constructor(e,t,i,s,r){super(e,2,t),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(e,t,i){var s;let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=at(e.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||t=="delete"&&at(e.startState)==this.from)return new me(this.source,t=="input"&&i.activateOnTyping?1:0);let a=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos),c;return N0(this.result.validFor,e.state,r,o)?new Ht(this.source,a,this.result,r,o):this.result.update&&(c=this.result.update(this.result,r,o,new Ic(e.state,l,a>=0)))?new Ht(this.source,a,c,c.from,(s=c.to)!==null&&s!==void 0?s:at(e.state)):new me(this.source,1,a)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new me(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new Ht(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1))}}function N0(n,e,t,i){if(!n)return!1;let s=e.sliceDoc(t,i);return typeof n=="function"?n(s,t,i,e):Fc(n,!0).test(s)}const Hc=D.define({map(n,e){return n.map(t=>t.map(e))}}),Wc=D.define(),xe=Q.define({create(){return zn.start()},update(n,e){return n.update(e)},provide:n=>[Nr.from(n,e=>e.tooltip),w.contentAttributes.from(n,e=>e.attrs)]});function $c(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(xe).active.find(s=>s.source==e.source);return i instanceof Ht?(typeof t=="string"?n.dispatch(Object.assign(Object.assign({},C0(n.state,t,i.from,i.to)),{annotations:Vc.of(e.completion)})):t(n,e.completion,i.from,i.to),!0):!1}const F0=E0(xe,$c);function ln(n,e="option"){return t=>{let i=t.state.field(xe,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(se).interactionDelay)return!1;let s=1,r;e=="page"&&(r=kh(t,i.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+s*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Wc.of(l)}),!0}}const V0=n=>{let e=n.state.field(xe,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(se).interactionDelay?!1:$c(n,e.open.options[e.open.selected])},H0=n=>n.state.field(xe,!1)?(n.dispatch({effects:$n.of(!0)}),!0):!1,W0=n=>{let e=n.state.field(xe,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Di.of(null)}),!0)};class $0{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const z0=50,j0=1e3,q0=_.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(xe).active)e.state==1&&this.startQuery(e)}update(n){let e=n.state.field(xe);if(!n.selectionSet&&!n.docChanged&&n.startState.field(xe)==e)return;let t=n.transactions.some(s=>(s.selection||s.docChanged)&&!xr(s));for(let s=0;s<this.running.length;s++){let r=this.running[s];if(t||r.updates.length+n.transactions.length>z0&&Date.now()-r.time>j0){for(let o of r.context.abortListeners)try{o()}catch(l){he(this.view.state,l)}r.context.abortListeners=null,this.running.splice(s--,1)}else r.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(r=>r.is($n)))&&(this.pendingStart=!0);let i=this.pendingStart?50:n.state.facet(se).activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.state==1&&!this.running.some(r=>r.active.source==s.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let s of n.transactions)xr(s)=="input"?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,e=n.field(xe);for(let t of e.active)t.state==1&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t)}startQuery(n){let{state:e}=this.view,t=at(e),i=new Ic(e,t,n.explicitPos==t),s=new $0(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Di.of(null)}),he(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(se).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(se);for(let i=0;i<this.running.length;i++){let s=this.running[i];if(s.done===void 0)continue;if(this.running.splice(i--,1),s.done){let o=new Ht(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:at(s.updates.length?s.updates[0].startState:this.view.state));for(let l of s.updates)o=o.update(l,t);if(o.hasResult()){e.push(o);continue}}let r=this.view.state.field(xe).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new me(s.active.source,0);for(let l of s.updates)o=o.update(l,t);o.state!=1&&e.push(o)}else this.startQuery(r)}e.length&&this.view.dispatch({effects:Hc.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(xe,!1);if(e&&e.tooltip&&this.view.state.facet(se).closeOnBlur){let t=e.open&&kh(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Di.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:$n.of(!1)}),20),this.composing=0}}}),zc=w.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"},".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"}}});let K0=class{constructor(e,t,i,s){this.field=e,this.line=t,this.from=i,this.to=s}},_0=class jc{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,te.TrackDel),i=e.mapPos(this.to,1,te.TrackDel);return t==null||i==null?null:new jc(this.field,t,i)}},J0=class qc{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let f=0;f<h;f++)c+=e.facet(Xt);s.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new _0(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",c=-1;for(let h=0;h<t.length;h++)(l!=null?t[h].seq==l:a&&t[h].name==a)&&(c=h);if(c<0){let h=0;for(;h<t.length&&(l==null||t[h].seq!=null&&t[h].seq<l);)h++;t.splice(h,0,{seq:l,name:a}),c=h;for(let f of s)f.field>=c&&f.field++}s.push(new K0(c,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of s)a.line==i.length&&a.from>l.index&&(a.from--,a.to--)}i.push(o)}return new qc(i,s)}},U0=T.widget({widget:new class extends Fe{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),Y0=T.mark({class:"cm-snippetField"}),ss=class Kc{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(i=>(i.from==i.to?U0:Y0).range(i.from,i.to)))}map(e){let t=[];for(let i of this.ranges){let s=i.map(e);if(!s)return null;t.push(s)}return new Kc(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}};const Wi=D.define({map(n,e){return n&&n.map(e)}}),G0=D.define(),Ei=Q.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(Wi))return t.value;if(t.is(G0)&&n)return new ss(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>w.decorations.from(n,e=>e?e.deco:T.none)});function Qr(n,e){return x.create(n.filter(t=>t.field==e).map(t=>x.range(t.from,t.to)))}function X0(n){let e=J0.parse(n);return(t,i,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),a={changes:{from:s,to:r,insert:B.of(o)},scrollIntoView:!0,annotations:i?[Vc.of(i),Y.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=Qr(l,0)),l.some(c=>c.field>0)){let c=new ss(l,0),h=a.effects=[Wi.of(c)];t.state.field(Ei,!1)===void 0&&h.push(D.appendConfig.of([Ei,iy,ny,zc]))}t.dispatch(t.state.update(a))}}function _c(n){return({state:e,dispatch:t})=>{let i=e.field(Ei,!1);if(!i||n<0&&i.active==0)return!1;let s=i.active+n,r=n>0&&!i.ranges.some(o=>o.field==s+n);return t(e.update({selection:Qr(i.ranges,s),effects:Wi.of(r?null:new ss(i.ranges,s)),scrollIntoView:!0})),!0}}const Q0=({state:n,dispatch:e})=>n.field(Ei,!1)?(e(n.update({effects:Wi.of(null)})),!0):!1,Z0=_c(1),ey=_c(-1),ty=[{key:"Tab",run:Z0,shift:ey},{key:"Escape",run:Q0}],Bl=A.define({combine(n){return n.length?n[0]:ty}}),iy=pt.highest(Gt.compute([Bl],n=>n.facet(Bl)));function q(n,e){return Object.assign(Object.assign({},e),{apply:X0(n)})}const ny=w.domEventHandlers({mousedown(n,e){let t=e.state.field(Ei,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=t.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==t.active?!1:(e.dispatch({selection:Qr(t.ranges,s.field),effects:Wi.of(t.ranges.some(r=>r.field>s.field)?new ss(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Pi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},xt=D.define({map(n,e){let t=e.mapPos(n,-1,te.TrackAfter);return t??void 0}}),Zr=new class extends ct{};Zr.startSide=1;Zr.endSide=-1;const Jc=Q.define({create(){return R.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(xt)&&(n=n.update({add:[Zr.range(t.value,t.value+1)]}));return n}});function sy(){return[oy,Jc]}const Ms="()[]{}<>";function Uc(n){for(let e=0;e<Ms.length;e+=2)if(Ms.charCodeAt(e)==n)return Ms.charAt(e+1);return Ar(n<128?n:n+1)}function Yc(n,e){return n.languageDataAt("closeBrackets",e)[0]||Pi}const ry=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),oy=w.inputHandler.of((n,e,t,i)=>{if((ry?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&ke(ne(i,0))==1||e!=s.from||t!=s.to)return!1;let r=hy(n.state,i);return r?(n.dispatch(r),!0):!1}),ly=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=Yc(n,n.selection.main.head).brackets||Pi.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=cy(n.doc,o.head);for(let a of i)if(a==l&&rs(n.doc,o.head)==Uc(ne(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:x.cursor(o.head-a.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},ay=[{key:"Backspace",run:ly}];function hy(n,e){let t=Yc(n,n.selection.main.head),i=t.brackets||Pi.brackets;for(let s of i){let r=Uc(ne(s,0));if(e==s)return r==s?dy(n,s,i.indexOf(s+s+s)>-1,t):fy(n,s,r,t.before||Pi.before);if(e==r&&Gc(n,n.selection.main.from))return uy(n,s,r)}return null}function Gc(n,e){let t=!1;return n.field(Jc).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function rs(n,e){let t=n.sliceString(e,e+2);return t.slice(0,ke(ne(t,0)))}function cy(n,e){let t=n.sliceString(e-2,e);return ke(ne(t,0))==t.length?t:t.slice(1)}function fy(n,e,t,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:xt.of(o.to+e.length),range:x.range(o.anchor+e.length,o.head+e.length)};let l=rs(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:xt.of(o.head+e.length),range:x.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function uy(n,e,t){let i=null,s=n.changeByRange(r=>r.empty&&rs(n.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:x.cursor(r.head+t.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function dy(n,e,t,i){let s=i.stringPrefixes||Pi.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:xt.of(l.to+e.length),range:x.range(l.anchor+e.length,l.head+e.length)};let a=l.head,c=rs(n.doc,a),h;if(c==e){if(Rl(n,a))return{changes:{insert:e+e,from:a},effects:xt.of(a+e.length),range:x.cursor(a+e.length)};if(Gc(n,a)){let u=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:x.cursor(a+u.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(h=Ll(n,a-2*e.length,s))>-1&&Rl(n,h))return{changes:{insert:e+e+e+e,from:a},effects:xt.of(a+e.length),range:x.cursor(a+e.length)};if(n.charCategorizer(a)(c)!=z.Word&&Ll(n,a,s)>-1&&!py(n,a,e,s))return{changes:{insert:e+e,from:a},effects:xt.of(a+e.length),range:x.cursor(a+e.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Rl(n,e){let t=j(n).resolveInner(e+1);return t.parent&&t.from==e}function py(n,e,t,i){let s=j(n).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let h=s.firstChild;for(;h&&h.from==s.from&&h.to-h.from>t.length+a;){if(n.sliceDoc(h.to-t.length,h.to)==t)return!1;h=h.firstChild}return!0}let c=s.to==e&&s.parent;if(!c)break;s=c}return!1}function Ll(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=z.Word)return e;for(let s of t){let r=e-s.length;if(n.sliceDoc(r,e)==s&&i(n.sliceDoc(r-1,r))!=z.Word)return r}return-1}function my(n={}){return[xe,se.of(n),q0,gy,zc]}const Xc=[{key:"Ctrl-Space",run:H0},{key:"Escape",run:W0},{key:"ArrowDown",run:ln(!0)},{key:"ArrowUp",run:ln(!1)},{key:"PageDown",run:ln(!0,"page")},{key:"PageUp",run:ln(!1,"page")},{key:"Enter",run:V0}],gy=pt.highest(Gt.computeN([se],n=>n.facet(se).defaultKeymap?[Xc]:[]));var Il=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,i=[];e.closeBracketsKeymap!==!1&&(i=i.concat(ay)),e.defaultKeymap!==!1&&(i=i.concat(Sg)),e.searchKeymap!==!1&&(i=i.concat(x0)),e.historyKeymap!==!1&&(i=i.concat(Pm)),e.foldKeymap!==!1&&(i=i.concat(Kp)),e.completionKeymap!==!1&&(i=i.concat(Xc)),e.lintKeymap!==!1&&(i=i.concat(Lg));var s=[];return e.lineNumbers!==!1&&s.push(wp()),e.highlightActiveLineGutter!==!1&&s.push(Cp()),e.highlightSpecialChars!==!1&&s.push($d()),e.history!==!1&&s.push(Sm()),e.foldGutter!==!1&&s.push(Yp()),e.drawSelection!==!1&&s.push(Ed()),e.dropCursor!==!1&&s.push(Id()),e.allowMultipleSelections!==!1&&s.push(P.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&s.push(Np()),e.syntaxHighlighting!==!1&&s.push(Zn(Zp,{fallback:!0})),e.bracketMatching!==!1&&s.push(om()),e.closeBrackets!==!1&&s.push(sy()),e.autocompletion!==!1&&s.push(my()),e.rectangularSelection!==!1&&s.push(tp()),t!==!1&&s.push(sp()),e.highlightActiveLine!==!1&&s.push(Jd()),e.highlightSelectionMatches!==!1&&s.push(e0()),e.tabSize&&typeof e.tabSize=="number"&&s.push(Xt.of(" ".repeat(e.tabSize))),s.concat([Gt.of(i.flat())]).filter(Boolean)};const yy="#e5c07b",Nl="#e06c75",by="#56b6c2",xy="#ffffff",vn="#abb2bf",vr="#7d8799",vy="#61afef",wy="#98c379",Fl="#d19a66",Sy="#c678dd",ky="#21252b",Vl="#2c313a",Hl="#282c34",Ts="#353a42",Cy="#3E4451",Wl="#528bff",Ay=w.theme({"&":{color:vn,backgroundColor:Hl},".cm-content":{caretColor:Wl},".cm-cursor, .cm-dropCursor":{borderLeftColor:Wl},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Cy},".cm-panels":{backgroundColor:ky,color:vn},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:Hl,color:vr,border:"none"},".cm-activeLineGutter":{backgroundColor:Vl},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Ts},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Ts,borderBottomColor:Ts},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:Vl,color:vn}}},{dark:!0}),My=At.define([{tag:m.keyword,color:Sy},{tag:[m.name,m.deleted,m.character,m.propertyName,m.macroName],color:Nl},{tag:[m.function(m.variableName),m.labelName],color:vy},{tag:[m.color,m.constant(m.name),m.standard(m.name)],color:Fl},{tag:[m.definition(m.name),m.separator],color:vn},{tag:[m.typeName,m.className,m.number,m.changed,m.annotation,m.modifier,m.self,m.namespace],color:yy},{tag:[m.operator,m.operatorKeyword,m.url,m.escape,m.regexp,m.link,m.special(m.string)],color:by},{tag:[m.meta,m.comment],color:vr},{tag:m.strong,fontWeight:"bold"},{tag:m.emphasis,fontStyle:"italic"},{tag:m.strikethrough,textDecoration:"line-through"},{tag:m.link,color:vr,textDecoration:"underline"},{tag:m.heading,fontWeight:"bold",color:Nl},{tag:[m.atom,m.bool,m.special(m.variableName)],color:Fl},{tag:[m.processingInstruction,m.string,m.inserted],color:wy},{tag:m.invalid,color:xy}]),Ty=[Ay,Zn(My)];var Oy=w.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),Dy=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:i=!0,readOnly:s=!1,theme:r="light",placeholder:o="",basicSetup:l=!0}=e,a=[];switch(t&&a.unshift(Gt.of([kg])),l&&(typeof l=="boolean"?a.unshift(Il()):a.unshift(Il(l))),o&&a.unshift(Xd(o)),r){case"light":a.push(Oy);break;case"dark":a.push(Ty);break;case"none":break;default:a.push(r);break}return i===!1&&a.push(w.editable.of(!1)),s&&a.push(P.readOnly.of(!0)),[...a]},Ey=n=>({line:n.state.doc.lineAt(n.state.selection.main.from),lineCount:n.state.doc.lines,lineBreak:n.state.lineBreak,length:n.state.doc.length,readOnly:n.state.readOnly,tabSize:n.state.tabSize,selection:n.state.selection,selectionAsSingle:n.state.selection.asSingle().main,ranges:n.state.selection.ranges,selectionCode:n.state.sliceDoc(n.state.selection.main.from,n.state.selection.main.to),selections:n.state.selection.ranges.map(e=>n.state.sliceDoc(e.from,e.to)),selectedText:n.state.selection.ranges.some(e=>!e.empty)}),$l=Ne.define(),Py=[];function By(n){var{value:e,selection:t,onChange:i,onStatistics:s,onCreateEditor:r,onUpdate:o,extensions:l=Py,autoFocus:a,theme:c="light",height:h=null,minHeight:f=null,maxHeight:u=null,width:d=null,minWidth:p=null,maxWidth:g=null,placeholder:y="",editable:b=!0,readOnly:v=!1,indentWithTab:M=!0,basicSetup:S=!0,root:k,initialState:O}=n,[L,K]=Se.useState(),[I,ue]=Se.useState(),[Ye,De]=Se.useState(),tt=w.theme({"&":{height:h,minHeight:f,maxHeight:u,width:d,minWidth:p,maxWidth:g},"& .cm-scroller":{height:"100% !important"}}),Ee=w.updateListener.of(Z=>{if(Z.docChanged&&typeof i=="function"&&!Z.transactions.some(Be=>Be.annotation($l))){var Pe=Z.state.doc,de=Pe.toString();i(de,Z)}s&&s(Ey(Z))}),He=Dy({theme:c,editable:b,readOnly:v,placeholder:y,indentWithTab:M,basicSetup:S}),we=[Ee,tt,...He];return o&&typeof o=="function"&&we.push(w.updateListener.of(o)),we=we.concat(l),Se.useEffect(()=>{if(L&&!Ye){var Z={doc:e,selection:t,extensions:we},Pe=O?P.fromJSON(O.json,Z,O.fields):P.create(Z);if(De(Pe),!I){var de=new w({state:Pe,parent:L,root:k});ue(de),r&&r(de,Pe)}}return()=>{I&&(De(void 0),ue(void 0))}},[L,Ye]),Se.useEffect(()=>K(n.container),[n.container]),Se.useEffect(()=>()=>{I&&(I.destroy(),ue(void 0))},[I]),Se.useEffect(()=>{a&&I&&I.focus()},[a,I]),Se.useEffect(()=>{I&&I.dispatch({effects:D.reconfigure.of(we)})},[c,l,h,f,u,d,p,g,y,b,v,M,S,i,o]),Se.useEffect(()=>{if(e!==void 0){var Z=I?I.state.doc.toString():"";I&&e!==Z&&I.dispatch({changes:{from:0,to:Z.length,insert:e||""},annotations:[$l.of(!0)]})}},[e,I]),{state:Ye,setState:De,view:I,setView:ue,container:L,setContainer:K}}var Ry=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],Ly=Se.forwardRef((n,e)=>{var{className:t,value:i="",selection:s,extensions:r=[],onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:c,autoFocus:h,theme:f="light",height:u,minHeight:d,maxHeight:p,width:g,minWidth:y,maxWidth:b,basicSetup:v,placeholder:M,indentWithTab:S,editable:k,readOnly:O,root:L,initialState:K}=n,I=Af(n,Ry),ue=Se.useRef(null),{state:Ye,view:De,container:tt}=By({container:ue.current,root:L,value:i,autoFocus:h,theme:f,height:u,minHeight:d,maxHeight:p,width:g,minWidth:y,maxWidth:b,basicSetup:v,placeholder:M,indentWithTab:S,editable:k,readOnly:O,selection:s,onChange:o,onStatistics:l,onCreateEditor:a,onUpdate:c,extensions:r,initialState:K});if(Se.useImperativeHandle(e,()=>({editor:ue.current,state:Ye,view:De}),[ue,tt,Ye,De]),typeof i!="string")throw new Error("value must be typeof string but got "+typeof i);var Ee=typeof f=="string"?"cm-theme-"+f:"cm-theme";return Mf.jsx("div",qn({ref:ue,className:""+Ee+(t?" "+t:"")},I))});Ly.displayName="CodeMirror";const Iy=Ne.define(),Ny=w.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 Fy{constructor(e,t,i,s){this.field=e,this.line=t,this.from=i,this.to=s}}class eo{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,te.TrackDel),i=e.mapPos(this.to,1,te.TrackDel);return t==null||i==null?null:new eo(this.field,t,i)}}class to{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let c=o,h=/^\t*/.exec(a)[0].length;for(let f=0;f<h;f++)c+=e.facet(Xt);s.push(t+c.length-h),a=c+a.slice(h)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new eo(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",c=-1,h=a.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<t.length;f++)(l!=null?t[f].seq==l:h&&t[f].name==h)&&(c=f);if(c<0){let f=0;for(;f<t.length&&(l==null||t[f].seq!=null&&t[f].seq<l);)f++;t.splice(f,0,{seq:l,name:h}),c=f;for(let u of s)u.field>=c&&u.field++}s.push(new Fy(c,i.length,r.index,r.index+h.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,c)=>{for(let h of s)h.line==i.length&&h.from>c&&(h.from--,h.to--);return a}),i.push(o)}return new to(i,s)}}let Vy=T.widget({widget:new class extends Fe{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),Hy=T.mark({class:"cm-snippetField"});class ei{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(i=>(i.from==i.to?Vy:Hy).range(i.from,i.to)))}map(e){let t=[];for(let i of this.ranges){let s=i.map(e);if(!s)return null;t.push(s)}return new ei(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const $i=D.define({map(n,e){return n&&n.map(e)}}),Wy=D.define(),Bi=Q.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is($i))return t.value;if(t.is(Wy)&&n)return new ei(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>w.decorations.from(n,e=>e?e.deco:T.none)});function io(n,e){return x.create(n.filter(t=>t.field==e).map(t=>x.range(t.from,t.to)))}function $y(n){let e=to.parse(n);return(t,i,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),a={changes:{from:s,to:r,insert:B.of(o)},scrollIntoView:!0,annotations:i?[Iy.of(i),Y.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=io(l,0)),l.some(c=>c.field>0)){let c=new ei(l,0),h=a.effects=[$i.of(c)];t.state.field(Bi,!1)===void 0&&h.push(D.appendConfig.of([Bi,_y,Uy,Ny]))}t.dispatch(t.state.update(a))}}function Qc(n){return({state:e,dispatch:t})=>{let i=e.field(Bi,!1);if(!i||n<0&&i.active==0)return!1;let s=i.active+n,r=n>0&&!i.ranges.some(o=>o.field==s+n);return t(e.update({selection:io(i.ranges,s),effects:$i.of(r?null:new ei(i.ranges,s)),scrollIntoView:!0})),!0}}const zy=({state:n,dispatch:e})=>n.field(Bi,!1)?(e(n.update({effects:$i.of(null)})),!0):!1,jy=Qc(1),qy=Qc(-1),Ky=[{key:"Tab",run:jy,shift:qy},{key:"Escape",run:zy}],zl=A.define({combine(n){return n.length?n[0]:Ky}}),_y=pt.highest(Gt.compute([zl],n=>n.facet(zl)));function Jy(n,e){return Object.assign(Object.assign({},e),{apply:$y(n)})}const Uy=w.domEventHandlers({mousedown(n,e){let t=e.state.field(Bi,!1),i;if(!t||(i=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=t.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==t.active?!1:(e.dispatch({selection:io(t.ranges,s.field),effects:$i.of(t.ranges.some(r=>r.field>s.field)?new ei(t.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Zc=new class extends ct{};Zc.startSide=1;Zc.endSide=-1;const G={log:(...n)=>{},warn:(...n)=>{}},E={STRING:"String",NUMBER:"Number",TRUE:"True",FALSE:"False",NULL:"Null",OBJECT:"Object",ARRAY:"Array",PROPERTY:"Property",PROPERTY_NAME:"PropertyName",PROPERTY_COLON:"PropertyColon",ITEM:"Item",JSON_TEXT:"JsonText",INVALID:"⚠"},Yy={Pair:E.PROPERTY,Key:E.PROPERTY_NAME,BlockSequence:E.ARRAY,BlockMapping:E.OBJECT,FlowSequence:E.ARRAY,FlowMapping:E.OBJECT,QuotedLiteral:E.STRING,Literal:E.STRING,Stream:E.JSON_TEXT,Document:E.OBJECT},Gy={File:E.JSON_TEXT},no=[E.STRING,E.NUMBER,E.TRUE,E.FALSE,E.NULL],ef=[E.OBJECT,E.ARRAY,E.ITEM],$={JSON5:"json5",JSON:"json4",YAML:"yaml"},U=(n,e)=>{var t,i;switch(e){case $.YAML:return(t=Yy[n])!==null&&t!==void 0?t:n;case $.JSON5:return(i=Gy[n])!==null&&i!==void 0?i:n;default:return n}};function tf(n,e,t){const i=[];for(let s=e;s!=null&&s.parent;s=s.parent)switch(U(s.parent.name,t)){case E.PROPERTY:{const r=wr(s.parent,E.PROPERTY_NAME,t);r&&i.unshift(Dt(n,r).replace(/[/~]/g,o=>o==="~"?"~0":"~1"));break}case E.ARRAY:{if(Qy(s,t)){const r=rf(s.parent,s,t);i.unshift(`${r}`)}break}}return i.unshift(""),i.join("/")}const nf=(n,e,t=-1,i)=>tf(n.doc,j(n).resolve(e,t),i),so=(n,e)=>{const t=j(n),i=new Map;return t.iterate({enter:s=>{var r,o,l,a,c,h,f,u;if([E.PROPERTY_NAME,E.OBJECT].includes(U(s.name,e))){const d=tf(n.doc,s.node,e),{from:p,to:g}=s.node;if(!(!((o=(r=s.node)===null||r===void 0?void 0:r.nextSibling)===null||o===void 0)&&o.node))return i.set(d,{keyFrom:p,keyTo:g}),!0;const y=e===$.JSON?(a=(l=s.node)===null||l===void 0?void 0:l.nextSibling)===null||a===void 0?void 0:a.node:(u=(f=(h=(c=s.node)===null||c===void 0?void 0:c.nextSibling)===null||h===void 0?void 0:h.node)===null||f===void 0?void 0:f.nextSibling)===null||u===void 0?void 0:u.node;if(!y)return i.set(d,{keyFrom:p,keyTo:g}),!0;const{from:b,to:v}=y;return i.set(d,{keyFrom:p,keyTo:g,valueFrom:b,valueTo:v}),!0}}}),i},Os=(n,e,t=-1)=>j(n).resolveInner(e,t),wn=n=>n.replace(/^"(.*)"$/,"$1").replace(/^'(.*)'$/,"$1"),Xy=n=>n.replace(/^"(.*)"$/,"'$1'"),Dt=(n,e,t=!0,i=!0)=>{const s=e?n.sliceString(e.from,e.to):"";return t?i?wn(s):s.replace(/(^["'])|(["']$)/g,""):s},sf=(n,e)=>{var t,i,s,r;return U(n.name,e)===E.INVALID&&(U((i=(t=n.prevSibling)===null||t===void 0?void 0:t.name)!==null&&i!==void 0?i:"",e)===E.PROPERTY_NAME||U((r=(s=n.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",e)===E.PROPERTY_COLON)},Sn=(n,e)=>no.includes(U(n.name,e))||sf(n,e),Qy=(n,e)=>[...no,...ef].includes(U(n.name,e))||sf(n,e),an=(n,e)=>{var t,i,s,r,o,l;return U(n.name,e)===E.PROPERTY_NAME||U(n.name,e)===E.INVALID&&(U((i=(t=n.prevSibling)===null||t===void 0?void 0:t.name)!==null&&i!==void 0?i:"",e)===E.PROPERTY||U((r=(s=n.prevSibling)===null||s===void 0?void 0:s.name)!==null&&r!==void 0?r:"",e)==="{")||e===$.YAML&&U((l=(o=n.parent)===null||o===void 0?void 0:o.name)!==null&&l!==void 0?l:"",e)===E.OBJECT},zi=n=>{const e=[];let t=n.firstChild;for(;t;)t&&e.push(t),t=t==null?void 0:t.nextSibling;return e},Zy=(n,e,t)=>zi(n).filter(i=>U(i.name,t)===e),wr=(n,e,t)=>{var i;return(i=zi(n).find(s=>U(s.name,t)===e))!==null&&i!==void 0?i:null},jl=(n,e)=>zi(n).find(t=>Sn(t,e)),eb=(n,e)=>zi(n).filter(t=>no.includes(U(t.name,e))||ef.includes(U(t.name,e))),rf=(n,e,t)=>eb(n,t).findIndex(i=>i.from===e.from&&i.to===e.to),ql=(n,e,t,i=1/0)=>{let s=n;for(;s&&i>0;){if(U(s.name,t)===e)return s;s=s.parent,i--}return null},tb=D.define(),jn=Q.define({create(){},update(n,e){for(const t of e.effects)if(t.is(tb))return t.value;return n}}),ro=n=>n.field(jn),Fb=n=>[jn.init(()=>n)],Sr=Tf({linkify:!0,typographer:!0});(async()=>{const n=await Rf({themes:{light:"vitesse-light",dark:"vitesse-dark"}});Sr.use(n)})();function Wt(n,e=!0){return e?Sr.renderInline(n):Sr.render(n)}class ib{constructor(){this.completions=new Map,this.reservedKeys=new Set}reserve(e){this.reservedKeys.add(e)}add(e){this.reservedKeys.has(e.label)||this.completions.set(e.label,e)}}class nb{constructor(e){var t;this.opts=e,this.schema=null,this.mode=$.JSON,this.mode=(t=e.mode)!==null&&t!==void 0?t:$.JSON}doComplete(e){var t,i,s;const r=ro(e.state);if(this.schema=(t=this.expandSchemaProperty(r,r))!==null&&t!==void 0?t:r,!this.schema)return[];const o={from:e.pos,to:e.pos,options:[],filter:!1},l=e.state.doc.sliceString(0);let a=Os(e.state,e.pos),c=e.state.sliceDoc(a.from,e.pos).replace(/^(["'])/,"");if(G.log("xxx","node",a,"prefix",c,"ctx",e),!(Sn(a,this.mode)||an(a,this.mode))&&!e.explicit)return G.log("xxx","no completions for non-word/primitive",a),o;const h=Dt(e.state.doc,a),f=Dt(e.state.doc,a,!1);if(a&&(Sn(a,this.mode)||an(a,this.mode)))o.from=a.from,o.to=a.to;else{const g=e.matchBefore(/[A-Za-z0-9._]*/),y=e.pos-h.length;G.log("xxx","overwriteStart after",y,"ctx.pos",e.pos,"word",g,"currentWord",h,"=>",l[y-1],"..",l[y],"..",l),o.from=a.name===E.INVALID?(i=g==null?void 0:g.from)!==null&&i!==void 0?i:e.pos:y,o.to=e.pos}const u=new ib;let d=!0;const p=ql(a,E.PROPERTY_NAME,this.mode);if(p&&(G.log("xxx","closestPropertyNameNode",p,"node",a),a=p),an(a,this.mode)){G.log("xxx","isPropertyNameNode",a);const g=a.parent;if(g){const y=jl(g,this.mode);d=!y||y.name===E.INVALID&&y.from-y.to===0||(y.parent?zi(y.parent).length<=1:!1),G.log("xxx","addValue",d,jl(g,this.mode),a),a=(s=ql(g,E.OBJECT,this.mode))!==null&&s!==void 0?s:null}}if(G.log("xxx",a,h,e,"node at pos",Os(e.state,e.pos)),a&&[E.OBJECT,E.JSON_TEXT].includes(U(a.name,this.mode))&&(an(Os(e.state,e.pos),this.mode)||p)){if(a.from===e.pos)return G.log("xxx","no completions for just before opening brace"),o;this.getPropertyCompletions(this.schema,e,a,u,d,f)}else{const g={},y=this.getValueCompletions(this.schema,e,g,u);G.log("xxx","getValueCompletions res",y)}return o.options=Array.from(u.completions.values()).filter(g=>wn(g.label).startsWith(c)),G.log("xxx","result",o,"prefix",c,"collector.completions",u.completions,"reservedKeys",u.reservedKeys),o}applySnippetCompletion(e){return Jy(typeof e.apply!="string"?e.label:e.apply,e)}getPropertyCompletions(e,t,i,s,r,o){const l=Zy(i,E.PROPERTY,this.mode);G.log("xxx","getPropertyCompletions",i,t,l),l.forEach(c=>{const h=Dt(t.state.doc,wr(c,E.PROPERTY_NAME,this.mode));s.reserve(wn(h))});const a=this.getSchemas(e,t);G.log("xxx","propertyCompletion schemas",a),a.forEach(c=>{if(typeof c!="object")return;const h=c.properties;h&&Object.entries(h).forEach(([u,d])=>{var p,g;if(typeof d=="object"){const y=(p=d.description)!==null&&p!==void 0?p:"",b=(g=d.type)!==null&&g!==void 0?g:"",v=Array.isArray(b)?b.toString():b,M={label:u,apply:this.getInsertTextForProperty(u,r,o,d),type:"property",detail:v,info:Wt(y)};s.add(this.applySnippetCompletion(M))}});const f=c.propertyNames;if(typeof f=="object"&&(f.enum&&f.enum.forEach(u=>{const d=u==null?void 0:u.toString();if(d){const p={label:d,apply:this.getInsertTextForProperty(d,r,o),type:"property"};s.add(this.applySnippetCompletion(p))}}),f.const)){const u=f.const.toString(),d={label:u,apply:this.getInsertTextForProperty(u,r,o),type:"property"};s.add(this.applySnippetCompletion(d))}})}getInsertTextForProperty(e,t,i,s){s=s&&this.expandSchemaProperty(s,this.schema);let r=this.getInsertTextForPropertyName(e,i);if(!t)return r;r+=": ";let o,l=0;if(typeof s=="object"){if(typeof s.default<"u")o||(o=this.getInsertTextForGuessedValue(s.default,"")),l++;else if(s.enum&&(!o&&s.enum.length===1&&(o=this.getInsertTextForGuessedValue(s.enum[0],"")),l+=s.enum.length),typeof s.const<"u"&&(o||(o=this.getInsertTextForGuessedValue(s.const,"")),l++),Array.isArray(s.examples)&&s.examples.length&&(o||(o=this.getInsertTextForGuessedValue(s.examples[0],"")),l+=s.examples.length),o===void 0&&l===0){let a=Array.isArray(s.type)?s.type[0]:s.type;switch(a||(s.properties?a="object":s.items&&(a="array")),a){case"boolean":o="#{}";break;case"string":o=this.getInsertTextForString("");break;case"object":switch(this.mode){case $.JSON5:o="{#{}}";break;case $.YAML:o="#{}";break;default:o="{#{}}";break}break;case"array":o="[#{}]";break;case"number":case"integer":o="#{0}";break;case"null":o="#{null}";break;default:o="#{}";break}}}return(!o||l>1)&&(G.log("xxx","value",o,"nValueProposals",l,s),o="#{}"),r+o}getInsertTextForPropertyName(e,t){switch(this.mode){case $.JSON5:case $.YAML:return t.startsWith('"')?`"${e}"`:t.startsWith("'")?`'${e}'`:e;default:return`"${e}"`}}getInsertTextForString(e,t="#"){switch(this.mode){case $.JSON5:return`'${t}{${e}}'`;case $.YAML:return`${t}{${e}}`;default:return`"${t}{${e}}"`}}getInsertTextForGuessedValue(e,t=""){switch(typeof e){case"object":return e===null?"${null}"+t:this.getInsertTextForValue(e,t);case"string":{let i=JSON.stringify(e);return i=i.substr(1,i.length-2),i=this.getInsertTextForPlainText(i),this.getInsertTextForString(i,"$")+t}case"number":case"boolean":return"${"+JSON.stringify(e)+"}"+t}return this.getInsertTextForValue(e,t)}getInsertTextForPlainText(e){return e.replace(/[\\$}]/g,"\\$&")}getInsertTextForValue(e,t){const i=JSON.stringify(e,null," ");return i==="{}"?"{#{}}"+t:i==="[]"?"[#{}]"+t:this.getInsertTextForPlainText(i+t)}getValueCompletions(e,t,i,s){let r=j(t.state).resolveInner(t.pos,-1),o=null,l;if(G.log("xxx","getValueCompletions",r,t),r&&Sn(r,this.mode)&&(o=r,r=r.parent),!r){this.addSchemaValueCompletions(e,i,s);return}if(U(r.name,this.mode)===E.PROPERTY){const c=wr(r,E.PROPERTY_NAME,this.mode);c&&(l=Dt(t.state.doc,c),r=r.parent)}if(G.log("xxx","node",r,"parentKey",l),r&&(l!==void 0||U(r.name,this.mode)===E.ARRAY)){const c=this.getSchemas(e,t);for(const h of c){if(typeof h!="object")return;if(U(r.name,this.mode)===E.ARRAY&&h.items){let f=s;if(h.uniqueItems&&(f=Object.assign(Object.assign({},f),{add(u){f.completions.has(u.label)||s.add(u)},reserve(u){s.reserve(u)}})),Array.isArray(h.items)){let u=0;if(o){const p=rf(r,o,this.mode);p>=0&&(u=p)}const d=h.items[u];d&&this.addSchemaValueCompletions(d,i,f)}else this.addSchemaValueCompletions(h.items,i,f)}if(l!==void 0){let f=!1;if(h.properties){const u=h.properties[l];u&&(f=!0,this.addSchemaValueCompletions(u,i,s))}if(h.patternProperties&&!f)for(const u of Object.keys(h.patternProperties)){const d=this.extendedRegExp(u);if(d!=null&&d.test(l)){f=!0;const p=h.patternProperties[u];p&&this.addSchemaValueCompletions(p,i,s)}}if(h.additionalProperties&&!f){const u=h.additionalProperties;this.addSchemaValueCompletions(u,i,s)}}i.boolean&&(this.addBooleanValueCompletion(!0,s),this.addBooleanValueCompletion(!1,s)),i.null&&this.addNullValueCompletion(s)}}return{valuePrefix:o?Dt(t.state.doc,o,!0,!1):""}}addSchemaValueCompletions(e,t,i){typeof e=="object"&&(this.addEnumValueCompletions(e,i),this.addDefaultValueCompletions(e,i),this.collectTypes(e,t),Array.isArray(e.allOf)&&e.allOf.forEach(s=>this.addSchemaValueCompletions(s,t,i)),Array.isArray(e.anyOf)&&e.anyOf.forEach(s=>this.addSchemaValueCompletions(s,t,i)),Array.isArray(e.oneOf)&&e.oneOf.forEach(s=>this.addSchemaValueCompletions(s,t,i)))}addDefaultValueCompletions(e,t,i=0){let s=!1;if(typeof e.default<"u"){let r=e.type,o=e.default;for(let a=i;a>0;a--)o=[o],r="array";const l=Object.assign(Object.assign({type:r==null?void 0:r.toString()},this.getAppliedValue(o)),{detail:"Default value"});t.add(l),s=!0}Array.isArray(e.examples)&&e.examples.forEach(r=>{let o=e.type,l=r;for(let a=i;a>0;a--)l=[l],o="array";t.add(Object.assign({type:o==null?void 0:o.toString()},this.getAppliedValue(l))),s=!0}),!s&&typeof e.items=="object"&&!Array.isArray(e.items)&&i<5&&this.addDefaultValueCompletions(e.items,t,i+1)}addEnumValueCompletions(e,t){var i,s;if(typeof e.const<"u"&&t.add(Object.assign(Object.assign({type:(i=e.type)===null||i===void 0?void 0:i.toString()},this.getAppliedValue(e.const)),{info:e.description})),Array.isArray(e.enum))for(let r=0,o=e.enum.length;r<o;r++){const l=e.enum[r];t.add(Object.assign(Object.assign({type:(s=e.type)===null||s===void 0?void 0:s.toString()},this.getAppliedValue(l)),{info:e.description}))}}addBooleanValueCompletion(e,t){t.add({type:"boolean",label:e?"true":"false"})}addNullValueCompletion(e){e.add({type:"null",label:"null"})}collectTypes(e,t){if(Array.isArray(e.enum)||typeof e.const<"u")return;const i=e.type;Array.isArray(i)?i.forEach(s=>t[s]=!0):i&&(t[i]=!0)}getSchemas(e,t){var i,s;const r=new Of(this.schema);let o=nf(t.state,t.pos,-1,this.mode),l=r.getSchema({pointer:o});return Ql(l)&&(l=(i=l.data)===null||i===void 0?void 0:i.schema),(!l||l.name==="UnknownPropertyError"||l.enum||l.type==="undefined")&&(o=o.replace(/\/[^/]*$/,"/"),l=r.getSchema({pointer:o})),G.log("xxx","pointer..",JSON.stringify(o)),(!o||o==="/")&&(l=(s=this.expandSchemaProperty(e,e))!==null&&s!==void 0?s:e),G.log("xxx","subSchema..",l),l?Array.isArray(l.allOf)?[l,...l.allOf.map(a=>this.expandSchemaProperty(a,e))]:Array.isArray(l.oneOf)?[l,...l.oneOf.map(a=>this.expandSchemaProperty(a,e))]:Array.isArray(l.anyOf)?[l,...l.anyOf.map(a=>this.expandSchemaProperty(a,e))]:[l]:[]}expandSchemaProperty(e,t){if(typeof e=="object"&&e.$ref){const i=this.getReferenceSchema(t,e.$ref);if(typeof i=="object"){const s=Object.assign(Object.assign({},e),i);return Reflect.deleteProperty(s,"$ref"),s}}return e}getReferenceSchema(e,t){const i=t.split("/");let s=e;return i.forEach(r=>{if(r){if(r==="#"){s=e;return}typeof s=="object"&&(s=s[r])}}),s}getAppliedValue(e){const t=wn(JSON.stringify(e));switch(this.mode){case $.JSON5:return{label:t,apply:Xy(JSON.stringify(e))};case $.YAML:return{label:t,apply:t};default:return{label:t,apply:JSON.stringify(e)}}}getValueFromLabel(e){return JSON.parse(e)}extendedRegExp(e){let t="";e.startsWith("(?i)")&&(e=e.substring(4),t="i");try{return new RegExp(e,t+"u")}catch{try{return new RegExp(e,t)}catch{return}}}}function Vb(n={}){const e=new nb(n);return function(i){return e.doComplete(i)}}const Ri=(n,e)=>{const t=n.length>2;let i=n.map((s,r)=>{const o="`"+(e?e(s):s)+"`";return r===n.length-1?"or "+o:o});return t?i.join(", "):i.join(" ")};function of(n){let e=null;try{e=JSON.parse(n.doc.toString())}catch{}const t=so(n,$.JSON);return{data:e,pointers:t}}function Ge(n,e,t=[]){const i=document.createElement(n);return Object.entries(e).forEach(([s,r])=>{if(s==="text"){i.innerText=r;return}if(s==="inner"){i.innerHTML=r;return}i.setAttribute(s,r)}),t.forEach(s=>i.appendChild(s)),i}function sb(n){let e=null;try{e=Df.parse(n.doc.toString())}catch{}const t=so(n,$.YAML);return{data:e,pointers:t}}function rb(n){let e=null;try{e=Ef.parse(n.doc.toString())}catch{}const t=so(n,$.JSON5);return{data:e,pointers:t}}const ob=n=>{switch(n){case $.JSON:return of;case $.JSON5:return rb;case $.YAML:return sb}},lb=n=>{var e,t,i;return!((e=n==null?void 0:n.data)===null||e===void 0)&&e.pointer&&((t=n==null?void 0:n.data)===null||t===void 0?void 0:t.pointer)!=="#"?n.data.pointer.slice(1):!((i=n==null?void 0:n.data)===null||i===void 0)&&i.property?`/${n.data.property}`:""},Hb=n=>n.startState.field(jn)!==n.state.field(jn);function Wb(n){const e=new hb(n);return t=>e.doValidation(t)}const ab=["NoAdditionalPropertiesError","RequiredPropertyError","InvalidPropertyNameError","ForbiddenPropertyError","UndefinedValueError"];class hb{constructor(e){var t,i,s,r;this.options=e,this.schema=null,this.mode=$.JSON,this.parser=of,this.rewriteError=o=>{var l,a,c,h,f;const u=o==null?void 0:o.data,d=u==null?void 0:u.errors;return o.code==="one-of-error"&&(d!=null&&d.length)?`Expected one of ${Ri(d,g=>g.data.expected)}`:o.code==="type-error"?`Expected \`${!((l=o==null?void 0:o.data)===null||l===void 0)&&l.expected&&Array.isArray((a=o==null?void 0:o.data)===null||a===void 0?void 0:a.expected)?Ri((c=o==null?void 0:o.data)===null||c===void 0?void 0:c.expected):(h=o==null?void 0:o.data)===null||h===void 0?void 0:h.expected}\` but received \`${(f=o==null?void 0:o.data)===null||f===void 0?void 0:f.received}\``:o.message.replaceAll("in `#` ","").replaceAll("at `#`","").replaceAll("/",".").replaceAll("#.","")},this.mode=(i=(t=this.options)===null||t===void 0?void 0:t.mode)!==null&&i!==void 0?i:$.JSON,this.parser=(r=(s=this.options)===null||s===void 0?void 0:s.jsonParser)!==null&&r!==void 0?r:ob(this.mode)}get schemaTitle(){var e,t,i;return(i=(t=(e=this.schema)===null||e===void 0?void 0:e.getSchema())===null||t===void 0?void 0:t.title)!==null&&i!==void 0?i:"json-schema"}doValidation(e){const t=ro(e.state);if(!t)return[];if(this.schema=new Zl(t),!this.schema)return[];const i=e.state.doc.toString();if(!(i!=null&&i.length))return[];const s=this.parser(e.state);let r=[];try{r=this.schema.validate(s.data)}catch{}return G.log("xxx","validation errors",r,s.data),r.length?r.reduce((o,l)=>{const a=()=>{const f=this.rewriteError(l);o.push({from:0,to:0,message:f,severity:"error",source:this.schemaTitle,renderMessage:()=>{const u=Ge("div",{});return u.innerHTML=Wt(f),u}})},c=lb(l),h=s.pointers.get(c);if(l.name==="MaxPropertiesError"||l.name==="MinPropertiesError")a();else if(h){const f=ab.includes(l.name),u=this.rewriteError(l),d=f?h.keyFrom:h.valueFrom,p=f?h.keyTo:h.valueTo;p!==void 0&&d!==void 0&&o.push({from:d,to:p,message:u,renderMessage:()=>{const g=Ge("div",{});return g.innerHTML=Wt(u),g},severity:"error",source:this.schemaTitle})}else a();return o},[]):[]}}function $b(n){const e=new cb(n);return async function(i,s,r){return e.doHover(i,s,r)}}function Kl(n){if(n.type)return n.$ref?`${n.$ref} (${n.type})`:n.type;if(n.$ref)return`${n.$ref}`}function Ds(n,e,t){return`${e}: ${Ri(n[e].map(i=>{try{const{data:s}=t.resolveRef({data:i,pointer:i.$ref});return Kl(s||i)}catch{return i.type}}))}`}class cb{constructor(e){var t,i;this.opts=e,this.schema=null,this.mode=$.JSON,this.opts=Object.assign({parser:JSON.parse},this.opts),this.mode=(i=(t=this.opts)===null||t===void 0?void 0:t.mode)!==null&&i!==void 0?i:$.JSON}getDataForCursor(e,t,i){const s=ro(e.state);if(!s)return null;this.schema=new Zl(s);const r=nf(e.state,t,i,this.mode);let o;try{o=this.opts.parser(e.state.doc.toString())}catch{}if(!r)return null;let l=this.schema.getSchema({pointer:r,data:o,withSchemaWarning:!0});return Ql(l)&&(l!=null&&l.data.schema.$ref?l=this.schema.resolveRef(l):l=l==null?void 0:l.data.schema),{schema:l,pointer:r}}formatMessage(e){const{message:t,typeInfo:i}=e;return t?Ge("div",{class:"cm6-json-schema-hover"},[Ge("div",{class:"cm6-json-schema-hover--description",inner:Wt(t,!1)}),Ge("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ge("div",{class:"cm6-json-schema-hover--code",inner:Wt(i,!1)})])]):Ge("div",{class:"cm6-json-schema-hover"},[Ge("div",{class:"cm6-json-schema-hover--code-wrapper"},[Ge("code",{class:"cm6-json-schema-hover--code",inner:Wt(i,!1)})])])}getHoverTexts(e,t){let i="",s=null;const{schema:r}=e;return r.oneOf&&(i=Ds(r,"oneOf",t)),r.anyOf&&(i=Ds(r,"anyOf",t)),r.allOf&&(i=Ds(r,"allOf",t)),r.type&&(i=Array.isArray(r.type)?Ri(r.type):r.type),r.$ref&&(i=` Reference: ${r.$ref}`),r.enum&&(i=`\`enum\`: ${Ri(r.enum)}`),r.format&&(i+=`\`format\`: ${r.format}`),r.pattern&&(i+=`\`pattern\`: ${r.pattern}`),r.description&&(s=r.description),{message:s,typeInfo:i}}async doHover(e,t,i){var s,r,o,l;const a=t,c=t;try{const h=this.getDataForCursor(e,t,i);if(G.log("cursorData",h),!(h!=null&&h.schema))return null;const u=((r=(s=this.opts)===null||s===void 0?void 0:s.getHoverTexts)!==null&&r!==void 0?r:this.getHoverTexts)(h,this.schema),p=((l=(o=this.opts)===null||o===void 0?void 0:o.formatHover)!==null&&l!==void 0?l:this.formatMessage)(u);return{pos:a,end:c,arrow:!0,above:!0,create:g=>({dom:p})}}catch(h){return G.log(h),null}}}const _l=new ea,lf=new Set(["Script","Body","FunctionDefinition","ClassDefinition","LambdaExpression","ForStatement","MatchClause"]);function hn(n){return(e,t,i)=>{if(i)return!1;let s=e.node.getChild("VariableName");return s&&t(s,n),!0}}const fb={FunctionDefinition:hn("function"),ClassDefinition:hn("class"),ForStatement(n,e,t){if(t){for(let i=n.node.firstChild;i;i=i.nextSibling)if(i.name=="VariableName")e(i,"variable");else if(i.name=="in")break}},ImportStatement(n,e){var t,i;let{node:s}=n,r=((t=s.firstChild)===null||t===void 0?void 0:t.name)=="from";for(let o=s.getChild("import");o;o=o.nextSibling)o.name=="VariableName"&&((i=o.nextSibling)===null||i===void 0?void 0:i.name)!="as"&&e(o,r?"variable":"namespace")},AssignStatement(n,e){for(let t=n.node.firstChild;t;t=t.nextSibling)if(t.name=="VariableName")e(t,"variable");else if(t.name==":"||t.name=="AssignOp")break},ParamList(n,e){for(let t=null,i=n.node.firstChild;i;i=i.nextSibling)i.name=="VariableName"&&(!t||!/\*|AssignOp/.test(t.name))&&e(i,"variable"),t=i},CapturePattern:hn("variable"),AsPattern:hn("variable"),__proto__:null};function af(n,e){let t=_l.get(e);if(t)return t;let i=[],s=!0;function r(o,l){let a=n.sliceString(o.from,o.to);i.push({label:a,type:l})}return e.cursor(kr.IncludeAnonymous).iterate(o=>{if(o.name){let l=fb[o.name];if(l&&l(o,r,s)||!s&&lf.has(o.name))return!1;s=!1}else if(o.to-o.from>8192){for(let l of af(n,o.node))i.push(l);return!1}}),_l.set(e,i),i}const Jl=/^[\w\xa1-\uffff][\w\d\xa1-\uffff]*$/,hf=["String","FormatString","Comment","PropertyName"];function ub(n){let e=j(n.state).resolveInner(n.pos,-1);if(hf.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&Jl.test(n.state.sliceDoc(e.from,e.to));if(!t&&!n.explicit)return null;let i=[];for(let s=e;s;s=s.parent)lf.has(s.name)&&(i=i.concat(af(n.state.doc,s)));return{options:i,from:t?e.from:n.pos,validFor:Jl}}const db=["__annotations__","__builtins__","__debug__","__doc__","__import__","__name__","__loader__","__package__","__spec__","False","None","True"].map(n=>({label:n,type:"constant"})).concat(["ArithmeticError","AssertionError","AttributeError","BaseException","BlockingIOError","BrokenPipeError","BufferError","BytesWarning","ChildProcessError","ConnectionAbortedError","ConnectionError","ConnectionRefusedError","ConnectionResetError","DeprecationWarning","EOFError","Ellipsis","EncodingWarning","EnvironmentError","Exception","FileExistsError","FileNotFoundError","FloatingPointError","FutureWarning","GeneratorExit","IOError","ImportError","ImportWarning","IndentationError","IndexError","InterruptedError","IsADirectoryError","KeyError","KeyboardInterrupt","LookupError","MemoryError","ModuleNotFoundError","NameError","NotADirectoryError","NotImplemented","NotImplementedError","OSError","OverflowError","PendingDeprecationWarning","PermissionError","ProcessLookupError","RecursionError","ReferenceError","ResourceWarning","RuntimeError","RuntimeWarning","StopAsyncIteration","StopIteration","SyntaxError","SyntaxWarning","SystemError","SystemExit","TabError","TimeoutError","TypeError","UnboundLocalError","UnicodeDecodeError","UnicodeEncodeError","UnicodeError","UnicodeTranslateError","UnicodeWarning","UserWarning","ValueError","Warning","ZeroDivisionError"].map(n=>({label:n,type:"type"}))).concat(["bool","bytearray","bytes","classmethod","complex","float","frozenset","int","list","map","memoryview","object","range","set","staticmethod","str","super","tuple","type"].map(n=>({label:n,type:"class"}))).concat(["abs","aiter","all","anext","any","ascii","bin","breakpoint","callable","chr","compile","delattr","dict","dir","divmod","enumerate","eval","exec","exit","filter","format","getattr","globals","hasattr","hash","help","hex","id","input","isinstance","issubclass","iter","len","license","locals","max","min","next","oct","open","ord","pow","print","property","quit","repr","reversed","round","setattr","slice","sorted","sum","vars","zip"].map(n=>({label:n,type:"function"}))),pb=[q("def ${name}(${params}):\n ${}",{label:"def",detail:"function",type:"keyword"}),q("for ${name} in ${collection}:\n ${}",{label:"for",detail:"loop",type:"keyword"}),q("while ${}:\n ${}",{label:"while",detail:"loop",type:"keyword"}),q("try:\n ${}\nexcept ${error}:\n ${}",{label:"try",detail:"/ except block",type:"keyword"}),q(`if \${}:
|
|
11
11
|
|
|
12
|
-
`,{label:"if",detail:"block",type:"keyword"}),q("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),q("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),q("import ${module}",{label:"import",detail:"statement",type:"keyword"}),q("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],
|
|
12
|
+
`,{label:"if",detail:"block",type:"keyword"}),q("if ${}:\n ${}\nelse:\n ${}",{label:"if",detail:"/ else block",type:"keyword"}),q("class ${name}:\n def __init__(self, ${params}):\n ${}",{label:"class",detail:"definition",type:"keyword"}),q("import ${module}",{label:"import",detail:"statement",type:"keyword"}),q("from ${module} import ${names}",{label:"from",detail:"import",type:"keyword"})],mb=Nc(hf,Xr(db.concat(pb)));function Ul(n,e){let t=n.baseIndentFor(e),i=n.lineAt(n.pos,-1),s=i.from+i.text.length;return/^\s*($|#)/.test(i.text)&&n.node.to<s+100&&!/\S/.test(n.state.sliceDoc(s,n.node.to))&&n.lineIndent(n.pos,-1)<=t||/^\s*(else:|elif |except |finally:)/.test(n.textAfter)&&n.lineIndent(n.pos,-1)>t?null:t+n.unit}const Es=Kt.define({name:"python",parser:Pf.configure({props:[Gn.add({Body:n=>{var e;return(e=Ul(n,n.node))!==null&&e!==void 0?e:n.continue()},IfStatement:n=>/^\s*(else:|elif )/.test(n.textAfter)?n.baseIndent:n.continue(),TryStatement:n=>/^\s*(except |finally:|else:)/.test(n.textAfter)?n.baseIndent:n.continue(),"TupleExpression ComprehensionExpression ParamList ArgList ParenthesizedExpression":xn({closing:")"}),"DictionaryExpression DictionaryComprehensionExpression SetExpression SetComprehensionExpression":xn({closing:"}"}),"ArrayExpression ArrayComprehensionExpression":xn({closing:"]"}),"String FormatString":()=>null,Script:n=>{if(n.pos+/\s*/.exec(n.textAfter)[0].length>=n.node.to){let e=null;for(let t=n.node,i=t.to;t=t.lastChild,!(!t||t.to!=i);)t.type.name=="Body"&&(e=t);if(e){let t=Ul(n,e);if(t!=null)return t}}return n.continue()}}),Xn.add({"ArrayExpression DictionaryExpression SetExpression TupleExpression":$r,Body:(n,e)=>({from:n.from+1,to:n.to-(n.to==e.doc.length?0:1)})})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"'''",'"""'],stringPrefixes:["f","fr","rf","r","u","b","br","rb","F","FR","RF","R","U","B","BR","RB"]},commentTokens:{line:"#"},indentOnInput:/^\s*([\}\]\)]|else:|elif |except |finally:)$/}});function zb(){return new Vr(Es,[Es.data.of({autocomplete:ub}),Es.data.of({autocomplete:mb})])}const cf=[q("function ${name}(${params}) {\n ${}\n}",{label:"function",detail:"definition",type:"keyword"}),q("for (let ${index} = 0; ${index} < ${bound}; ${index}++) {\n ${}\n}",{label:"for",detail:"loop",type:"keyword"}),q("for (let ${name} of ${collection}) {\n ${}\n}",{label:"for",detail:"of loop",type:"keyword"}),q("do {\n ${}\n} while (${})",{label:"do",detail:"loop",type:"keyword"}),q("while (${}) {\n ${}\n}",{label:"while",detail:"loop",type:"keyword"}),q(`try {
|
|
13
13
|
\${}
|
|
14
14
|
} catch (\${error}) {
|
|
15
15
|
\${}
|
|
@@ -21,4 +21,4 @@ import{cA as ht,cB as yf,cC as bf,cD as xf,cE as Me,cF as Et,cG as Sr,cH as cn,c
|
|
|
21
21
|
constructor(\${params}) {
|
|
22
22
|
\${}
|
|
23
23
|
}
|
|
24
|
-
}`,{label:"class",detail:"definition",type:"keyword"}),q('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),q('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],
|
|
24
|
+
}`,{label:"class",detail:"definition",type:"keyword"}),q('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),q('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],gb=cf.concat([q("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),q("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),q("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),Yl=new ea,ff=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function oi(n){return(e,t)=>{let i=e.node.getChild("VariableDefinition");return i&&t(i,n),!0}}const yb=["FunctionDeclaration"],bb={FunctionDeclaration:oi("function"),ClassDeclaration:oi("class"),ClassExpression:()=>!0,EnumDeclaration:oi("constant"),TypeAliasDeclaration:oi("type"),NamespaceDeclaration:oi("namespace"),VariableDefinition(n,e){n.matchContext(yb)||e(n,"variable")},TypeDefinition(n,e){e(n,"type")},__proto__:null};function uf(n,e){let t=Yl.get(e);if(t)return t;let i=[],s=!0;function r(o,l){let a=n.sliceString(o.from,o.to);i.push({label:a,type:l})}return e.cursor(kr.IncludeAnonymous).iterate(o=>{if(s)s=!1;else if(o.name){let l=bb[o.name];if(l&&l(o,r)||ff.has(o.name))return!1}else if(o.to-o.from>8192){for(let l of uf(n,o.node))i.push(l);return!1}}),Yl.set(e,i),i}const Gl=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,df=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName",".","?."];function xb(n){let e=j(n.state).resolveInner(n.pos,-1);if(df.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&Gl.test(n.state.sliceDoc(e.from,e.to));if(!t&&!n.explicit)return null;let i=[];for(let s=e;s;s=s.parent)ff.has(s.name)&&(i=i.concat(uf(n.state.doc,s)));return{options:i,from:t?e.from:n.pos,validFor:Gl}}const vt=Kt.define({name:"javascript",parser:Bf.configure({props:[Gn.add({IfStatement:yi({except:/^\s*({|else\b)/}),TryStatement:yi({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:Lp,SwitchBody:n=>{let e=n.textAfter,t=/^\s*\}/.test(e),i=/^\s*(case|default)\b/.test(e);return n.baseIndent+(t?0:i?1:2)*n.unit},Block:xn({closing:"}"}),ArrowFunction:n=>n.baseIndent+n.unit,"TemplateString BlockComment":()=>null,"Statement Property":yi({except:/^{/}),JSXElement(n){let e=/^\s*<\//.test(n.textAfter);return n.lineIndent(n.node.from)+(e?0:n.unit)},JSXEscape(n){let e=/\s*\}/.test(n.textAfter);return n.lineIndent(n.node.from)+(e?0:n.unit)},"JSXOpenTag JSXSelfClosingTag"(n){return n.column(n.node.from)+n.unit}}),Xn.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":$r,BlockComment(n){return{from:n.from+2,to:n.to-2}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),pf={test:n=>/^JSX/.test(n.name),facet:Th({commentTokens:{block:{open:"{/*",close:"*/}"}}})},vb=vt.configure({dialect:"ts"},"typescript"),wb=vt.configure({dialect:"jsx",props:[Fr.add(n=>n.isTop?[pf]:void 0)]}),Sb=vt.configure({dialect:"jsx ts",props:[Fr.add(n=>n.isTop?[pf]:void 0)]},"typescript");let mf=n=>({label:n,type:"keyword"});const gf="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(mf),kb=gf.concat(["declare","implements","private","protected","public"].map(mf));function jb(n={}){let e=n.jsx?n.typescript?Sb:wb:n.typescript?vb:vt,t=n.typescript?gb.concat(kb):cf.concat(gf);return new Vr(e,[vt.data.of({autocomplete:Nc(df,Xr(t))}),vt.data.of({autocomplete:xb}),n.jsx?Mb:[]])}function Cb(n){for(;;){if(n.name=="JSXOpenTag"||n.name=="JSXSelfClosingTag"||n.name=="JSXFragmentTag")return n;if(n.name=="JSXEscape"||!n.parent)return null;n=n.parent}}function Xl(n,e,t=n.length){for(let i=e==null?void 0:e.firstChild;i;i=i.nextSibling)if(i.name=="JSXIdentifier"||i.name=="JSXBuiltin"||i.name=="JSXNamespacedName"||i.name=="JSXMemberExpression")return n.sliceString(i.from,Math.min(i.to,t));return""}const Ab=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Mb=w.inputHandler.of((n,e,t,i,s)=>{if((Ab?n.composing:n.compositionStarted)||n.state.readOnly||e!=t||i!=">"&&i!="/"||!vt.isActiveAt(n.state,e,-1))return!1;let r=s(),{state:o}=r,l=o.changeByRange(a=>{var c;let{head:h}=a,f=j(o).resolveInner(h-1,-1),u;if(f.name=="JSXStartTag"&&(f=f.parent),!(o.doc.sliceString(h-1,h)!=i||f.name=="JSXAttributeValue"&&f.to>h)){if(i==">"&&f.name=="JSXFragmentTag")return{range:a,changes:{from:h,insert:"</>"}};if(i=="/"&&f.name=="JSXStartCloseTag"){let d=f.parent,p=d.parent;if(p&&d.from==h-2&&((u=Xl(o.doc,p.firstChild,h))||((c=p.firstChild)===null||c===void 0?void 0:c.name)=="JSXFragmentTag")){let g=`${u}>`;return{range:x.cursor(h+g.length,-1),changes:{from:h,insert:g}}}}else if(i==">"){let d=Cb(f);if(d&&d.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(h,h+2))&&(u=Xl(o.doc,d,h)))return{range:a,changes:{from:h,insert:`</${u}>`}}}}return{range:a}});return l.changes.empty?!1:(n.dispatch([r,o.update(l,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});export{w as E,Kt as L,Ly as R,Vr as a,Pb as b,Wb as c,Sg as d,Ag as e,Vb as f,up as g,Hb as h,$b as i,Bb as j,Gt as k,Rb as l,Lb as m,Ib as n,jb as o,zb as p,my as q,Fb as s};
|