1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-01-25 14:43:42 +02:00
pocketbase/ui/dist/assets/index.2148ad18.js
2022-09-14 20:53:09 +03:00

13 lines
310 KiB
JavaScript

class N{constructor(){}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){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),ze.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){let i=[];return this.decompose(e,t,i,0),ze.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 ti(this),r=new ti(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 ti(this,e)}iterRange(e,t=this.length){return new Yo(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 _o(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?N.empty:e.length<=32?new J(e):ze.from(J.split(e,[]))}}class J extends N{constructor(e,t=Pa(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 La(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new J(yr(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=Fi(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new J(l,o.length+r.length));else{let h=l.length>>1;i.push(new J(l.slice(0,h)),new J(l.slice(h)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof J))return super.replace(e,t,i);let s=Fi(this.text,Fi(i.text,yr(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new J(s,r):ze.from(J.split(s,[]),r)}sliceString(e,t=this.length,i=`
`){let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],h=r+l.length;r>e&&o&&(s+=i),e<h&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=h+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 ze extends N{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,h=i+o.lines-1;if((t?h:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=h+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],h=o+l.length;if(e<=h&&t>=o){let a=s&((o<=e?1:0)|(h>=t?2:0));o>=e&&h<=t&&!a?i.push(l):l.decompose(e-o,t-o,i,a)}o=h+1}}replace(e,t,i){if(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 h=o.replace(e-r,t-r,i),a=this.lines-o.lines+h.lines;if(h.lines<a>>5-1&&h.lines>a>>5+1){let c=this.children.slice();return c[s]=h,new ze(c,this.length-(t-e)+i.length)}return super.replace(r,l,h)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
`){let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],h=o+l.length;o>e&&r&&(s+=i),e<h&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=h+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof ze))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 h=this.children[s],a=e.children[r];if(h!=a)return i+h.scanIdentical(a,t);i+=h.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=[],h=0,a=-1,c=[];function f(d){let p;if(d.lines>r&&d instanceof ze)for(let g of d.children)f(g);else d.lines>o&&(h>o||!h)?(u(),l.push(d)):d instanceof J&&h&&(p=c[c.length-1])instanceof J&&d.lines+p.lines<=32?(h+=d.lines,a+=d.length+1,c[c.length-1]=new J(p.text.concat(d.text),p.length+1+d.length)):(h+d.lines>s&&u(),h+=d.lines,a+=d.length+1,c.push(d))}function u(){h!=0&&(l.push(c.length==1?c[0]:ze.from(c,a)),a=-1,h=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new ze(l,t)}}N.empty=new J([""],0);function Pa(n){let e=-1;for(let t of n)e+=t.length+1;return e}function Fi(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],h=s+l.length;h>=t&&(h>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=h+1}return e}function yr(n,e,t){return Fi(n,[""],e,t)}class ti{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=`
`,this;e--}else if(s instanceof J){let h=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,h.length>Math.max(0,e))return this.value=e==0?h:t>0?h.slice(e):h.slice(0,h.length-e),this;e-=h.length}else{let h=s.children[o+(t<0?-1:0)];e>h.length?(e-=h.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(t>0?1:(h instanceof J?h.text.length:h.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class Yo{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ti(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 _o{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.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"&&(N.prototype[Symbol.iterator]=function(){return this.iter()},ti.prototype[Symbol.iterator]=Yo.prototype[Symbol.iterator]=_o.prototype[Symbol.iterator]=function(){return this});class La{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}}let Bt="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<Bt.length;n++)Bt[n]+=Bt[n-1];function Ra(n){for(let e=1;e<Bt.length;e+=2)if(Bt[e]>n)return Bt[e-1]<=n;return!1}function br(n){return n>=127462&&n<=127487}const wr=8205;function fe(n,e,t=!0,i=!0){return(t?Qo:Ea)(n,e,i)}function Qo(n,e,t){if(e==n.length)return e;e&&Zo(n.charCodeAt(e))&&el(n.charCodeAt(e-1))&&e--;let i=ie(n,e);for(e+=ve(i);e<n.length;){let s=ie(n,e);if(i==wr||s==wr||t&&Ra(s))e+=ve(s),i=s;else if(br(s)){let r=0,o=e-2;for(;o>=0&&br(ie(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Ea(n,e,t){for(;e>0;){let i=Qo(n,e-2,t);if(i<e)return i;e--}return 0}function Zo(n){return n>=56320&&n<57344}function el(n){return n>=55296&&n<56320}function ie(n,e){let t=n.charCodeAt(e);if(!el(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Zo(i)?(t-55296<<10)+(i-56320)+65536:t}function Ws(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function ve(n){return n<65536?1:2}const Yn=/\r\n?|\n/;var le=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(le||(le={}));class Ke{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){_n(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 Ke(e)}composeDesc(e){return this.empty?e:e.empty?this:tl(this,e)}mapDesc(e,t=!1){return e.empty?this:Qn(this,e,t)}mapPos(e,t=-1,i=le.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],a=s+l;if(h<0){if(a>e)return r+(e-s);r+=l}else{if(i!=le.Simple&&a>=e&&(i==le.TrackDel&&s<e&&a>e||i==le.TrackBefore&&s<e||i==le.TrackAfter&&a>e))return null;if(a>e||a==e&&t<0&&!l)return e==s||t<0?r:r+h;r+=h}s=a}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 Ke(e)}static create(e){return new Ke(e)}}class _ extends Ke{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 _n(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return Qn(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 h=s>>1;for(;i.length<h;)i.push(N.empty);i.push(o?e.slice(r,r+o):N.empty)}r+=o}return new _(t,i)}compose(e){return this.empty?e:e.empty?this:tl(this,e,!0)}map(e,t=!1){return e.empty?this:Qn(this,e,t,!0)}iterChanges(e,t=!1){_n(this,e,t)}get desc(){return Ke.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new oi(this);e:for(let o=0,l=0;;){let h=o==e.length?1e9:e[o++];for(;l<h||l==h&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,h-l);oe(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;oe(t,c,f),f>0&&et(i,t,r.text),r.forward(c),l+=c}let a=e[o++];for(;l<a;){if(r.done)break e;let c=Math.min(r.len,a-l);oe(t,c,-1),oe(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new _(t,i),filtered:Ke.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 h(c=!1){if(!c&&!s.length)return;o<t&&oe(s,t-o,-1);let f=new _(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function a(c){if(Array.isArray(c))for(let f of c)a(f);else if(c instanceof _){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);h(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;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"?N.of(d.split(i||Yn)):d:N.empty,g=p.length;if(f==u&&g==0)return;f<o&&h(),f>o&&oe(s,f-o,-1),oe(s,u-f,g),et(r,s,p),o=u}}return a(e),h(!l),l}static empty(e){return new _(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(N.empty);i[s]=N.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new _(t,i)}static createSet(e,t){return new _(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 et(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(N.empty);n.push(t)}}function _n(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],h=n.sections[o++];if(h<0)s+=l,r+=l;else{let a=s,c=r,f=N.empty;for(;a+=l,c+=h,h&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],h=n.sections[o++];e(s,a,r,c,f),s=a,r=c}}}function Qn(n,e,t,i=!1){let s=[],r=i?[]:null,o=new oi(n),l=new oi(e);for(let h=-1;;)if(o.ins==-1&&l.ins==-1){let a=Math.min(o.len,l.len);oe(s,a,-1),o.forward(a),l.forward(a)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let a=l.len;for(oe(s,l.ins,-1);a;){let c=Math.min(o.len,a);o.ins>=0&&h<o.i&&o.len<=c&&(oe(s,0,o.ins),r&&et(r,s,o.text),h=o.i),o.forward(c),a-=c}l.next()}else if(o.ins>=0){let a=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);a+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;oe(s,a,h<o.i?o.ins:0),r&&h<o.i&&et(r,s,o.text),h=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?_.createSet(s,r):Ke.create(s);throw new Error("Mismatched change set lengths")}}function tl(n,e,t=!1){let i=[],s=t?[]:null,r=new oi(n),o=new oi(e);for(let l=!1;;){if(r.done&&o.done)return s?_.createSet(i,s):Ke.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&&et(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(r.len2,o.len),a=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;oe(i,h,c,l),s&&c&&et(s,i,o.text)}else o.ins==-1?(oe(i,r.off?0:r.len,h,l),s&&et(s,i,r.textBit(h))):(oe(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&et(s,i,o.text));l=(r.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>a),r.forward2(h),o.forward(h)}}}}class oi{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?N.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?N.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 pt{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&16?this.to:this.from}get head(){return this.flags&16?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&4?-1:this.flags&8?1:0}get bidiLevel(){let e=this.flags&3;return e==3?null:e}get goalColumn(){let e=this.flags>>5;return e==33554431?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 pt(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return m.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return m.range(this.anchor,i)}eq(e){return this.anchor==e.anchor&&this.head==e.head}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 m.range(e.anchor,e.head)}static create(e,t,i){return new pt(e,t,i)}}class m{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:m.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let t=0;t<this.ranges.length;t++)if(!this.ranges[t].eq(e.ranges[t]))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new m([this.main],0)}addRange(e,t=!0){return m.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,m.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 m(e.ranges.map(t=>pt.fromJSON(t)),e.main)}static single(e,t=e){return new m([m.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 m.normalized(e.slice(),t);i=r.to}return new m(e,t)}static cursor(e,t=0,i,s){return pt.create(e,e,(t==0?0:t<0?4:8)|(i==null?3:Math.min(2,i))|(s!=null?s:33554431)<<5)}static range(e,t,i){let s=(i!=null?i:33554431)<<5;return t<e?pt.create(t,e,16|s|8):pt.create(e,t,s|(t>e?4:0))}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,h=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?m.range(h,l):m.range(l,h))}}return new m(e,t)}}function il(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Hs=0;class D{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=Hs++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}static define(e={}){return new D(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:zs),!!e.static,e.enables)}of(e){return new Wi([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Wi(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Wi(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function zs(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class Wi{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Hs++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,h=!1,a=!1,c=[];for(let f of this.dependencies)f=="doc"?h=!0:f=="selection"?a=!0:(((t=e[f.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(h&&u.docChanged||a&&(u.docChanged||u.selection)||Zn(f,c)){let d=i(f);if(l?!xr(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d=i(f),p=u.config.address[r];if(p!=null){let g=Ki(u,p);if(this.dependencies.every(y=>y instanceof D?u.facet(y)===f.facet(y):y instanceof me?u.field(y,!1)==f.field(y,!1):!0)||(l?xr(d,g,s):s(d,g)))return f.values[o]=g,0}return f.values[o]=d,1}}}}function xr(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 Zn(n,e){let t=!1;for(let i of e)ii(n,i)&1&&(t=!0);return t}function Ia(n,e,t){let i=t.map(h=>n[h.id]),s=t.map(h=>h.type),r=i.filter(h=>!(h&1)),o=n[e.id]>>1;function l(h){let a=[];for(let c=0;c<i.length;c++){let f=Ki(h,i[c]);if(s[c]==2)for(let u of f)a.push(u);else a.push(f)}return e.combine(a)}return{create(h){for(let a of i)ii(h,a);return h.values[o]=l(h),1},update(h,a){if(!Zn(h,r))return 0;let c=l(h);return e.compare(c,h.values[o])?0:(h.values[o]=c,1)},reconfigure(h,a){let c=Zn(h,i),f=a.config.facets[e.id],u=a.facet(e);if(f&&!c&&zs(t,f))return h.values[o]=u,0;let d=l(h);return e.compare(d,u)?(h.values[o]=u,0):(h.values[o]=d,1)}}}const kr=D.define({static:!0});class me{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 me(Hs++,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(kr).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,kr.of({field:this,create:e})]}get extension(){return this}}const dt={lowest:4,low:3,default:2,high:1,highest:0};function Kt(n){return e=>new nl(e,n)}const St={highest:Kt(dt.highest),high:Kt(dt.high),default:Kt(dt.default),low:Kt(dt.low),lowest:Kt(dt.lowest)};class nl{constructor(e,t){this.inner=e,this.prec=t}}class gn{of(e){return new es(this,e)}reconfigure(e){return gn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class es{constructor(e,t){this.compartment=e,this.inner=t}}class ji{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 Na(e,t,o))u instanceof me?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),h=[],a=[];for(let u of s)l[u.id]=a.length<<1,a.push(d=>u.slot(d));let c=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=c&&c[u]||[];if(d.every(y=>y.type==0))if(l[p.id]=h.length<<1|1,zs(g,d))h.push(i.facet(p));else{let y=p.combine(d.map(b=>b.value));h.push(i&&p.compare(y,i.facet(p))?i.facet(p):y)}else{for(let y of d)y.type==0?(l[y.id]=h.length<<1|1,h.push(y.value)):(l[y.id]=a.length<<1,a.push(b=>y.dynamicSlot(b)));l[p.id]=a.length<<1,a.push(y=>Ia(y,p,d))}}let f=a.map(u=>u(l));return new ji(e,o,f,l,h,r)}}function Na(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let h=s.get(o);if(h!=null){if(h<=l)return;let a=i[h].indexOf(o);a>-1&&i[h].splice(a,1),o instanceof es&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let a of o)r(a,l);else if(o instanceof es){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let a=e.get(o.compartment)||o.inner;t.set(o.compartment,a),r(a,l)}else if(o instanceof nl)r(o.inner,o.prec);else if(o instanceof me)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Wi)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,dt.default);else{let a=o.extension;if(!a)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(a,l)}}return r(n,dt.default),i.reduce((o,l)=>o.concat(l))}function ii(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 Ki(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const sl=D.define(),rl=D.define({combine:n=>n.some(e=>e),static:!0}),ol=D.define({combine:n=>n.length?n[0]:void 0,static:!0}),ll=D.define(),hl=D.define(),al=D.define(),cl=D.define({combine:n=>n.length?n[0]:!1});class vt{constructor(e,t){this.type=e,this.value=t}static define(){return new Va}}class Va{of(e){return new vt(this,e)}}class Fa{constructor(e){this.map=e}of(e){return new R(this,e)}}class R{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 R(this.type,t)}is(e){return this.type==e}static define(e={}){return new Fa(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}}R.reconfigure=R.define();R.appendConfig=R.define();class Q{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&&il(i,t.newLength),r.some(l=>l.type==Q.time)||(this.annotations=r.concat(Q.time.of(Date.now())))}static create(e,t,i,s,r,o){return new Q(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(Q.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Q.time=vt.define();Q.userEvent=vt.define();Q.addToHistory=vt.define();Q.remote=vt.define();function Wa(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 fl(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=_.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:R.mapEffects(n.effects,s).concat(R.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function ts(n,e,t){let i=e.selection,s=Pt(e.annotations);return e.userEvent&&(s=s.concat(Q.userEvent.of(e.userEvent))),{changes:e.changes instanceof _?e.changes:_.of(e.changes||[],t,n.facet(ol)),selection:i&&(i instanceof m?i:m.single(i.anchor,i.head)),effects:Pt(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function ul(n,e,t){let i=ts(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=fl(i,ts(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=Q.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return za(t?Ha(s):s)}function Ha(n){let e=n.startState,t=!0;for(let s of e.facet(ll)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:Wa(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=_.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=Q.create(e,s,n.selection&&n.selection.map(r),R.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(hl);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof Q?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Q?n=r[0]:n=ul(e,Pt(r),!1)}return n}function za(n){let e=n.startState,t=e.facet(al),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=fl(n,ts(e,r,n.changes.newLength),!0))}return i==n?n:Q.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const qa=[];function Pt(n){return n==null?qa:Array.isArray(n)?n:[n]}var j=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(j||(j={}));const $a=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let is;try{is=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function ja(n){if(is)return is.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||$a.test(t)))return!0}return!1}function Ka(n){return e=>{if(!/\S/.test(e))return j.Space;if(ja(e))return j.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return j.Word;return j.Other}}class I{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++)ii(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 ii(this,i),Ki(this,i)}update(...e){return ul(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let o of e.effects)o.is(gn.reconfigure)?(t&&(s=new Map,t.compartments.forEach((l,h)=>s.set(h,l)),t=null),s.set(o.value.compartment,o.value.extension)):o.is(R.reconfigure)?(t=null,i=o.value):o.is(R.appendConfig)&&(t=null,i=Pt(i).concat(o.value));let r;t?r=e.startState.values.slice():(t=ji.resolve(i,s,this),r=new I(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,h)=>h.reconfigure(l,this),null).values),new I(t,e.newDoc,e.newSelection,r,(o,l)=>l.update(o,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:m.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=Pt(i.effects);for(let l=1;l<t.ranges.length;l++){let h=e(t.ranges[l]),a=this.changes(h.changes),c=a.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=s.mapDesc(a,!0);r.push(h.range.map(f)),s=s.compose(c),o=R.mapEffects(o,c).concat(R.mapEffects(Pt(h.effects),f))}return{changes:s,selection:m.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof _?e:_.of(e,this.doc.length,this.facet(I.lineSeparator))}toText(e){return N.of(e.split(this.facet(I.lineSeparator)||Yn))}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:(ii(this,t),Ki(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 me&&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(h=>o.spec.fromJSON(l,h)))}}return I.create({doc:e.doc,selection:m.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=ji.resolve(e.extensions||[],new Map),i=e.doc instanceof N?e.doc:N.of((e.doc||"").split(t.staticFacet(I.lineSeparator)||Yn)),s=e.selection?e.selection instanceof m?e.selection:m.single(e.selection.anchor,e.selection.head):m.single(0);return il(s,i.length),t.staticFacet(rl)||(s=s.asSingle()),new I(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(I.tabSize)}get lineBreak(){return this.facet(I.lineSeparator)||`
`}get readOnly(){return this.facet(cl)}phrase(e,...t){for(let i of this.facet(I.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(sl))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){return Ka(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 h=fe(t,o,!1);if(r(t.slice(h,o))!=j.Word)break;o=h}for(;l<s;){let h=fe(t,l);if(r(t.slice(l,h))!=j.Word)break;l=h}return o==l?null:m.range(o+i,l+i)}}I.allowMultipleSelections=rl;I.tabSize=D.define({combine:n=>n.length?n[0]:4});I.lineSeparator=ol;I.readOnly=cl;I.phrases=D.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])}});I.languageData=sl;I.changeFilter=ll;I.transactionFilter=hl;I.transactionExtender=al;gn.reconfigure=R.define();function Ct(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 yt{eq(e){return this==e}range(e,t=e){return li.create(e,t,this)}}yt.prototype.startSide=yt.prototype.endSide=0;yt.prototype.point=!1;yt.prototype.mapMode=le.TrackDel;class li{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new li(e,t,i)}}function ns(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class qs{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 h=o+l>>1,a=r[h]-e||(i?this.value[h].endSide:this.value[h].startSide)-t;if(h==o)return a>=0?o:l;a>=0?l=h:o=h+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 h=0;h<this.value.length;h++){let a=this.value[h],c=this.from[h]+e,f=this.to[h]+e,u,d;if(c==f){let p=t.mapPos(c,a.startSide,a.mapMode);if(p==null||(u=d=p,a.startSide!=a.endSide&&(d=t.mapPos(c,a.endSide),d<u)))continue}else if(u=t.mapPos(c,a.startSide),d=t.mapPos(f,a.endSide),u>d||u==d&&a.startSide>0&&a.endSide<=0)continue;(d-u||a.endSide-a.startSide)<0||(o<0&&(o=u),a.point&&(l=Math.max(l,d-u)),i.push(a),s.push(u-o),r.push(d-o))}return{mapped:i.length?new qs(s,r,i,l):null,pos:o}}}class ${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 $(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(ns)),this.isEmpty)return t.length?$.of(t):this;let l=new dl(this,null,-1).goto(0),h=0,a=[],c=new bt;for(;l.value||h<t.length;)if(h<t.length&&(l.from-t[h].from||l.startSide-t[h].value.startSide)>=0){let f=t[h++];c.addInner(f.from,f.to,f.value)||a.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==t.length||this.chunkEnd(l.chunkIndex)<t[h].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.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))&&(c.addInner(l.from,l.to,l.value)||a.push(li.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!a.length?$.empty:this.nextLayer.update({add:a,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],h=this.chunk[o],a=e.touchesRange(l,l+h.length);if(a===!1)s=Math.max(s,h.maxPoint),t.push(h),i.push(e.mapPos(l));else if(a===!0){let{mapped:c,pos:f}=h.map(l,e);c&&(s=Math.max(s,c.maxPoint),t.push(c),i.push(f))}}let r=this.nextLayer.map(e);return t.length==0?r:new $(i,t,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 hi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return hi.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),h=Sr(o,l,i),a=new Ut(o,h,r),c=new Ut(l,h,r);i.iterGaps((f,u,d)=>vr(a,f,c,u,d,s)),i.empty&&i.length==0&&vr(a,0,c,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=1e9);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Sr(r,o),h=new Ut(r,l,0).goto(i),a=new Ut(o,l,0).goto(i);for(;;){if(h.to!=a.to||!ss(h.active,a.active)||h.point&&(!a.point||!h.point.eq(a.point)))return!1;if(h.to>s)return!0;h.next(),a.next()}}static spans(e,t,i,s,r=-1){let o=new Ut(e,null,r).goto(t),l=t,h=o.openStart;for(;;){let a=Math.min(o.to,i);if(o.point?(s.point(l,a,o.point,o.activeForPoint(o.to),h,o.pointRank),h=o.openEnd(a)+(o.to>a?1:0)):a>l&&(s.span(l,a,o.active,h),h=o.openEnd(a)),o.to>i)break;l=o.to,o.next()}return h}static of(e,t=!1){let i=new bt;for(let s of e instanceof li?[e]:t?Ua(e):e)i.add(s.from,s.to,s.value);return i.finish()}}$.empty=new $([],[],null,-1);function Ua(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(ns(e,i)>0)return n.slice().sort(ns);e=i}return n}$.empty.nextLayer=$.empty;class bt{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}finishChunk(e){this.chunks.push(new qs(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=[])}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new bt)).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($.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=$.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Sr(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 dl{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 hi{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 dl(o,t,i,r));return s.length==1?s[0]:new hi(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--)Bn(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--)Bn(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(),Bn(this.heap,0)}}}function Bn(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 Ut{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=hi.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){Si(this.active,e),Si(this.activeTo,e),Si(this.activeRank,e),this.minActive=Cr(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&this.activeRank[t]<=r;)t++;vi(this.active,t,i),vi(this.activeTo,t,s),vi(this.activeRank,t,r),e&&vi(e,t,this.cursor.from),this.minActive=Cr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null,s=0;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),i&&Si(i,r)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let o=this.cursor.value;if(!o.point)this.addActive(i),this.cursor.from<e&&this.cursor.to>e&&s++,this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=o,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=o.endSide,this.cursor.from<e&&(s=1),this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){let r=0;for(;r<i.length&&i[r]<e;)r++;this.openStart=r+s}}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 vr(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,h=i-e;for(;;){let a=n.to+h-t.to||n.endSide-t.endSide,c=a<0?n.to+h:t.to,f=Math.min(c,o);if(n.point||t.point?n.point&&t.point&&(n.point==t.point||n.point.eq(t.point))&&ss(n.activeForPoint(n.to+h),t.activeForPoint(t.to))||r.comparePoint(l,f,n.point,t.point):f>l&&!ss(n.active,t.active)&&r.compareRange(l,f,n.active,t.active),c>o)break;l=c,a<=0&&n.next(),a>=0&&t.next()}}function ss(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 Si(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function vi(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function Cr(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 yi(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=fe(n,s));return i}function rs(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=fe(n,s)}return i===!0?-1:n.length}const os="\u037C",Ar=typeof Symbol>"u"?"__"+os:Symbol.for(os),ls=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Mr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class ot{constructor(e,t){this.rules=[];let{finish:i}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,h,a){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return h.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(g=>o.map(y=>g.replace(/&/,y))).reduce((g,y)=>g.concat(y)),p,h);else if(p&&typeof p=="object"){if(!f)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(s(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(c.length||u)&&h.push((i&&!f&&!a?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(s(o),e[o],this.rules)}getRules(){return this.rules.join(`
`)}static newName(){let e=Mr[Ar]||1;return Mr[Ar]=e+1,os+e.toString(36)}static mount(e,t){(e[ls]||new Ga(e)).mount(Array.isArray(t)?t:[t])}}let Ci=null;class Ga{constructor(e){if(!e.head&&e.adoptedStyleSheets&&typeof CSSStyleSheet<"u"){if(Ci)return e.adoptedStyleSheets=[Ci.sheet].concat(e.adoptedStyleSheets),e[ls]=Ci;this.sheet=new CSSStyleSheet,e.adoptedStyleSheets=[this.sheet].concat(e.adoptedStyleSheets),Ci=this}else{this.styleTag=(e.ownerDocument||e).createElement("style");let t=e.head||e;t.insertBefore(this.styleTag,t.firstChild)}this.modules=[],e[ls]=this}mount(e){let t=this.sheet,i=0,s=0;for(let r=0;r<e.length;r++){let o=e[r],l=this.modules.indexOf(o);if(l<s&&l>-1&&(this.modules.splice(l,1),s--,l=-1),l==-1){if(this.modules.splice(s++,0,o),t)for(let h=0;h<o.rules.length;h++)t.insertRule(o.rules[h],i++)}else{for(;s<l;)i+=this.modules[s++].rules.length;i+=o.rules.length,s++}}if(!t){let r="";for(let o=0;o<this.modules.length;o++)r+=this.modules[o].getRules()+`
`;this.styleTag.textContent=r}}}var lt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},ai={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Dr=typeof navigator<"u"&&/Chrome\/(\d+)/.exec(navigator.userAgent);typeof navigator<"u"&&/Gecko\/\d+/.test(navigator.userAgent);var Ja=typeof navigator<"u"&&/Mac/.test(navigator.platform),Xa=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Ya=Ja||Dr&&+Dr[1]<57;for(var ne=0;ne<10;ne++)lt[48+ne]=lt[96+ne]=String(ne);for(var ne=1;ne<=24;ne++)lt[ne+111]="F"+ne;for(var ne=65;ne<=90;ne++)lt[ne]=String.fromCharCode(ne+32),ai[ne]=String.fromCharCode(ne);for(var Pn in lt)ai.hasOwnProperty(Pn)||(ai[Pn]=lt[Pn]);function _a(n){var e=Ya&&(n.ctrlKey||n.altKey||n.metaKey)||Xa&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?ai:lt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function Ui(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function Et(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function Qa(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Hi(n,e){if(!e.anchorNode)return!1;try{return Et(n,e.anchorNode)}catch{return!1}}function ci(n){return n.nodeType==3?It(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Gi(n,e,t,i){return t?Or(n,e,t,i,-1)||Or(n,e,t,i,1):!1}function Ji(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Or(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:fi(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=Ji(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?fi(n):0}else return!1}}function fi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}const pl={left:0,right:0,top:0,bottom:0};function mn(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Za(n){return{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function ec(n,e,t,i,s,r,o,l){let h=n.ownerDocument,a=h.defaultView;for(let c=n;c;)if(c.nodeType==1){let f,u=c==h.body;if(u)f=Za(a);else{if(c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.parentNode;continue}let g=c.getBoundingClientRect();f={left:g.left,right:g.left+c.clientWidth,top:g.top,bottom:g.top+c.clientHeight}}let d=0,p=0;if(s=="nearest")e.top<f.top?(p=-(f.top-e.top+o),t>0&&e.bottom>f.bottom+p&&(p=e.bottom-f.bottom+p+o)):e.bottom>f.bottom&&(p=e.bottom-f.bottom+o,t<0&&e.top-p<f.top&&(p=-(f.top+p-e.top+o)));else{let g=e.bottom-e.top,y=f.bottom-f.top;p=(s=="center"&&g<=y?e.top+g/2-y/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-y+o)-f.top}if(i=="nearest"?e.left<f.left?(d=-(f.left-e.left+r),t>0&&e.right>f.right+d&&(d=e.right-f.right+d+r)):e.right>f.right&&(d=e.right-f.right+r,t<0&&e.left<f.left+d&&(d=-(f.left+d-e.left+r))):d=(i=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:i=="start"==l?e.left-r:e.right-(f.right-f.left)+r)-f.left,d||p)if(u)a.scrollBy(d,p);else{if(p){let g=c.scrollTop;c.scrollTop+=p,p=c.scrollTop-g}if(d){let g=c.scrollLeft;c.scrollLeft+=d,d=c.scrollLeft-g}e={left:e.left-d,top:e.top-p,right:e.right-d,bottom:e.bottom-p}}if(u)break;c=c.assignedSlot||c.parentNode,i=s="nearest"}else if(c.nodeType==11)c=c.host;else break}class tc{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){this.set(e.anchorNode,e.anchorOffset,e.focusNode,e.focusOffset)}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let Dt=null;function gl(n){if(n.setActive)return n.setActive();if(Dt)return n.focus(Dt);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Dt==null?{get preventScroll(){return Dt={preventScroll:!0},!0}}:void 0),!Dt){Dt=!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 Tr;function It(n,e,t=e){let i=Tr||(Tr=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function ni(n,e,t){let i={key:e,code:e,keyCode:t,which:t,cancelable:!0},s=new KeyboardEvent("keydown",i);s.synthetic=!0,n.dispatchEvent(s);let r=new KeyboardEvent("keyup",i);return r.synthetic=!0,n.dispatchEvent(r),s.defaultPrevented||r.defaultPrevented}function ic(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function ml(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function nc(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(;;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=fi(t))}else{if(t==n)return!0;i=Ji(t),t=t.parentNode}}class he{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new he(e.parentNode,Ji(e),t)}static after(e,t){return new he(e.parentNode,Ji(e)+1,t)}}const $s=[];class H{constructor(){this.parent=null,this.dom=null,this.dirty=2}get editorView(){if(!this.parent)throw new Error("Accessing view in orphan content view");return this.parent.editorView}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}coordsAt(e,t){return null}sync(e){if(this.dirty&2){let t=this.dom,i=null,s;for(let r of this.children){if(r.dirty){if(!r.dom&&(s=i?i.nextSibling:t.firstChild)){let o=H.get(s);(!o||!o.parent&&o.constructor==r.constructor)&&r.reuseDOM(s)}r.sync(e),r.dirty=0}if(s=i?i.nextSibling:t.firstChild,e&&!e.written&&e.node==t&&s!=r.dom&&(e.written=!0),r.dom.parentNode==t)for(;s&&s!=r.dom;)s=Br(s);else t.insertBefore(r.dom,s);i=r.dom}for(s=i?i.nextSibling:t.firstChild,s&&e&&e.node==t&&(e.written=!0);s;)s=Br(s)}else if(this.dirty&1)for(let t of this.children)t.dirty&&(t.sync(e),t.dirty=0)}reuseDOM(e){}localPosFromDOM(e,t){let i;if(e==this.dom)i=this.dom.childNodes[t];else{let s=fi(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&&!H.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 h=0,a=i,c=i;h<this.children.length;h++){let f=this.children[h],u=a+f.length;if(a<e&&u>t)return f.domBoundsAround(e,t,a);if(u>=e&&s==-1&&(s=h,r=a),a>t&&f.dom.parentNode==this.dom){o=h,l=c;break}c=u,a=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.dirty|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.dirty|=2),t.dirty&1)return;t.dirty|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.dirty&&this.markParentsDirty(!0))}setDOM(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=$s){this.markDirty();for(let s=e;s<t;s++){let r=this.children[s];r.parent==this&&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 yl(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}merge(e,t,i,s,r,o){return!1}become(e){return!1}getSide(){return 0}destroy(){this.parent=null}}H.prototype.breakAfter=0;function Br(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class yl{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 bl(n,e,t,i,s,r,o,l,h){let{children:a}=n,c=a.length?a[e]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(e==i&&c&&!o&&!u&&r.length<2&&c.merge(t,s,r.length?f:null,t==0,l,h))){if(i<a.length){let d=a[i];d&&s<d.length?(e==i&&(d=d.split(s),s=0),!u&&f&&d.merge(0,s,f,!0,0,h)?r[r.length-1]=d:(s&&d.merge(0,s,null,!1,0,h),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(c&&(c.breakAfter=o,t>0&&(!o&&r.length&&c.merge(t,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(t<c.length||c.children.length&&c.children[c.children.length-1].length==0)&&c.merge(t,c.length,null,!1,l,0),e++));e<i&&r.length;)if(a[i-1].become(r[r.length-1]))i--,r.pop(),h=r.length?0:l;else if(a[e].become(r[0]))e++,r.shift(),l=r.length?0:h;else break;!r.length&&e&&i<a.length&&!a[e-1].breakAfter&&a[i].merge(0,0,a[e-1],!1,l,h)&&e--,(e<i||r.length)&&n.replaceChildren(e,i,r)}}function wl(n,e,t,i,s,r){let o=n.childCursor(),{i:l,off:h}=o.findPos(t,1),{i:a,off:c}=o.findPos(e,-1),f=e-t;for(let u of i)f+=u.length;n.length+=f,bl(n,a,c,l,h,i,0,s,r)}let Ce=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},hs=typeof document<"u"?document:{documentElement:{style:{}}};const as=/Edge\/(\d+)/.exec(Ce.userAgent),xl=/MSIE \d/.test(Ce.userAgent),cs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ce.userAgent),yn=!!(xl||cs||as),Pr=!yn&&/gecko\/(\d+)/i.test(Ce.userAgent),Ln=!yn&&/Chrome\/(\d+)/.exec(Ce.userAgent),Lr="webkitFontSmoothing"in hs.documentElement.style,kl=!yn&&/Apple Computer/.test(Ce.vendor),Rr=kl&&(/Mobile\/\w+/.test(Ce.userAgent)||Ce.maxTouchPoints>2);var A={mac:Rr||/Mac/.test(Ce.platform),windows:/Win/.test(Ce.platform),linux:/Linux|X11/.test(Ce.platform),ie:yn,ie_version:xl?hs.documentMode||6:cs?+cs[1]:as?+as[1]:0,gecko:Pr,gecko_version:Pr?+(/Firefox\/(\d+)/.exec(Ce.userAgent)||[0,0])[1]:0,chrome:!!Ln,chrome_version:Ln?+Ln[1]:0,ios:Rr,android:/Android\b/.test(Ce.userAgent),webkit:Lr,safari:kl,webkit_version:Lr?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:hs.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const sc=256;class ht extends H{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return i&&(!(i instanceof ht)||this.length-(t-e)+i.length>sc)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new ht(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new he(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 fs(this.dom,e,t)}}class Ue extends H{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(ml(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}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.dirty|=6)}sync(e){this.dom?this.dirty&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e)}merge(e,t,i,s,r,o){return i&&(!(i instanceof Ue&&i.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(wl(this,e,t,i?i.children:[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],i=0,s=-1,r=0;for(let l of this.children){let h=i+l.length;h>e&&t.push(i<e?l.split(e-i):l),s<0&&i>=e&&(s=r),i=h,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new Ue(this.mark,t,o)}domAtPos(e){return Cl(this,e)}coordsAt(e,t){return Ml(this,e,t)}}function fs(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?A.chrome||A.gecko||(e?(s--,o=1):r<i&&(r++,o=-1)):t<0?s--:r<i&&r++;let l=It(n,s,r).getClientRects();if(!l.length)return pl;let h=l[(o?o<0:t>=0)?0:l.length-1];return A.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,a=>a.width)||h),o?mn(h,o<0):h||null}class tt extends H{constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}static create(e,t,i){return new(e.customView||tt)(e,t,i)}split(e){let t=tt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}getSide(){return this.side}merge(e,t,i,s,r,o){return i&&(!(i instanceof tt)||!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.length==this.length&&e instanceof tt&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.eq(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return N.empty;let e=this;for(;e.parent;)e=e.parent;let t=e.editorView,i=t&&t.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):N.empty}domAtPos(e){return e==0?he.before(this.dom):he.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.dom.getClientRects(),s=null;if(!i.length)return pl;for(let r=e>0?i.length-1:0;s=i[r],!(e>0?r==0:r==i.length-1||s.top<s.bottom);r+=e>0?-1:1);return e==0&&t>0||e==this.length&&t<=0?s:mn(s,e==0)}get isEditable(){return!1}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Sl extends tt{domAtPos(e){let{topView:t,text:i}=this.widget;return t?us(e,0,t,i,(s,r)=>s.domAtPos(r),s=>new he(i,Math.min(s,i.nodeValue.length))):new he(i,Math.min(e,i.nodeValue.length))}sync(){this.setDOM(this.widget.toDOM())}localPosFromDOM(e,t){let{topView:i,text:s}=this.widget;return i?vl(e,t,i,s):Math.min(t,this.length)}ignoreMutation(){return!1}get overrideDOMText(){return null}coordsAt(e,t){let{topView:i,text:s}=this.widget;return i?us(e,t,i,s,(r,o,l)=>r.coordsAt(o,l),(r,o)=>fs(s,r,o)):fs(s,e,t)}destroy(){var e;super.destroy(),(e=this.widget.topView)===null||e===void 0||e.destroy()}get isEditable(){return!0}}function us(n,e,t,i,s,r){if(t instanceof Ue){for(let o=t.dom.firstChild;o;o=o.nextSibling){let l=H.get(o);if(!l)return r(n,e);let h=Et(o,i),a=l.length+(h?i.nodeValue.length:0);if(n<a||n==a&&l.getSide()<=0)return h?us(n,e,l,i,s,r):s(l,n,e);n-=a}return s(t,t.length,-1)}else return t.dom==i?r(n,e):s(t,n,e)}function vl(n,e,t,i){if(t instanceof Ue)for(let s of t.children){let r=0,o=Et(s.dom,i);if(Et(s.dom,n))return r+(o?vl(n,e,s,i):s.localPosFromDOM(n,e));r+=o?i.nodeValue.length:s.length}else if(t.dom==i)return Math.min(e,i.nodeValue.length);return t.localPosFromDOM(n,e)}class Nt extends H{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof Nt&&e.side==this.side}split(){return new Nt(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 he.before(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){let t=this.dom.getBoundingClientRect(),i=rc(this,this.side>0?-1:1);return i&&i.top<t.bottom&&i.bottom>t.top?{left:t.left,right:t.right,top:i.top,bottom:i.bottom}:t}get overrideDOMText(){return N.empty}}ht.prototype.children=tt.prototype.children=Nt.prototype.children=$s;function rc(n,e){let t=n.parent,i=t?t.children.indexOf(n):-1;for(;t&&i>=0;)if(e<0?i>0:i<t.children.length){let s=t.children[i+e];if(s instanceof ht){let r=s.coordsAt(e<0?s.length:0,e);if(r)return r}i+=e}else if(t instanceof Ue&&t.parent)i=t.parent.children.indexOf(t)+(e<0?0:1),t=t.parent;else{let s=t.dom.lastChild;if(s&&s.nodeName=="BR")return s.getClientRects()[0];break}}function Cl(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 he(t,0)}function Al(n,e,t){let i,{children:s}=n;t>0&&e instanceof Ue&&s.length&&(i=s[s.length-1])instanceof Ue&&i.mark.eq(e.mark)?Al(i,e.children[0],t-1):(s.push(e),e.setParent(n)),n.length+=e.length}function Ml(n,e,t){for(let r=0,o=0;o<n.children.length;o++){let l=n.children[o],h=r+l.length,a;if((t<=0||h==n.length||l.getSide()>0?h>=e:h>e)&&(e<h||o+1==n.children.length||(a=n.children[o+1]).length||a.getSide()>0)){let c=0;if(h==r){if(l.getSide()<=0)continue;c=t=-l.getSide()}let f=l.coordsAt(Math.max(0,e-r),t);return c&&f?mn(f,t<0):f}r=h}let i=n.dom.lastChild;if(!i)return n.dom.getBoundingClientRect();let s=ci(i);return s[s.length-1]||null}function ds(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}function js(n,e){if(n==e)return!0;if(!n||!e)return!1;let t=Object.keys(n),i=Object.keys(e);if(t.length!=i.length)return!1;for(let s of t)if(i.indexOf(s)==-1||n[s]!==e[s])return!1;return!0}function ps(n,e,t){let i=null;if(e)for(let s in e)t&&s in t||n.removeAttribute(i=s);if(t)for(let s in t)e&&e[s]==t[s]||n.setAttribute(i=s,t[s]);return!!i}class at{eq(e){return!1}updateDOM(e){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}ignoreEvent(e){return!0}get customView(){return null}destroy(e){}}var z=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(z||(z={}));class T extends yt{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 bn(e)}static widget(e){let t=e.side||0,i=!!e.block;return t+=i?t>0?3e8:-4e8:t>0?1e8:-1e8,new wt(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}=Dl(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new wt(e,i,s,t,e.widget||null,!0)}static line(e){return new bi(e)}static set(e,t=!1){return $.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}T.none=$.empty;class bn extends T{constructor(e){let{start:t,end:i}=Dl(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){return this==e||e instanceof bn&&this.tagName==e.tagName&&this.class==e.class&&js(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}bn.prototype.point=!1;class bi extends T{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof bi&&js(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)}}bi.prototype.mapMode=le.TrackBefore;bi.prototype.point=!0;class wt 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?le.TrackBefore:le.TrackAfter:le.TrackDel}get type(){return this.startSide<this.endSide?z.WidgetRange:this.startSide<=0?z.WidgetBefore:z.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&this.widget.estimatedHeight>=5}eq(e){return e instanceof wt&&oc(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)}}wt.prototype.point=!0;function Dl(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t!=null?t:e,end:i!=null?i:e}}function oc(n,e){return n==e||!!(n&&e&&n.compare(e))}function gs(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 ue extends H{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 ue))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),wl(this,e,t,i?i.children:[],r,o),!0}split(e){let t=new ue;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){js(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Al(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=ds(t,this.attrs||{})),i&&(this.attrs=ds({class:i},this.attrs||{}))}domAtPos(e){return Cl(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.dirty|=6)}sync(e){var t;this.dom?this.dirty&4&&(ml(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&&(ps(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e);let i=this.dom.lastChild;for(;i&&H.get(i)instanceof Ue;)i=i.lastChild;if(!i||!this.length||i.nodeName!="BR"&&((t=H.get(i))===null||t===void 0?void 0:t.isEditable)==!1&&(!A.ios||!this.children.some(s=>s instanceof ht))){let s=document.createElement("BR");s.cmIgnore=!0,this.dom.appendChild(s)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0;for(let t of this.children){if(!(t instanceof ht)||/[^ -~]/.test(t.text))return null;let i=ci(t.dom);if(i.length!=1)return null;e+=i[0].width}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length}:null}coordsAt(e,t){return Ml(this,e,t)}become(e){return!1}get type(){return z.Text}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 ue)return r;if(o>t)break}s=o+r.breakAfter}return null}}class mt extends H{constructor(e,t,i){super(),this.widget=e,this.length=t,this.type=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,s,r,o){return i&&(!(i instanceof mt)||!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?he.before(this.dom):he.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let i=new mt(this.widget,t,this.type);return i.breakAfter=this.breakAfter,i}get children(){return $s}sync(){(!this.dom||!this.widget.updateDOM(this.dom))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(this.editorView)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):N.empty}domBoundsAround(){return null}become(e){return e instanceof mt&&e.type==this.type&&e.widget.constructor==this.widget.constructor?(e.widget.eq(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Ks{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.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 mt&&e.type==z.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new ue),this.atCursorPos=!0),this.curLine}flushBuffer(e){this.pendingBuffer&&(this.curLine.append(Ai(new Nt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer([]),this.curLine=null,this.content.push(e)}finish(e){e?this.pendingBuffer=0:this.flushBuffer([]),this.posCovered()||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,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(0,i)),this.getLine().append(Ai(new ht(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 wt){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 wt)if(i.block){let{type:h}=i;h==z.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new mt(i.widget||new Er("div"),l,h))}else{let h=tt.create(i.widget||new Er("span"),l,i.startSide),a=this.atCursorPos&&!h.isEditable&&r<=s.length&&(e<t||i.startSide>0),c=!h.isEditable&&(e<t||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!a&&(this.pendingBuffer=0),this.flushBuffer(s),a&&(f.append(Ai(new Nt(1),s),r),r=s.length+Math.max(0,r-s.length)),f.append(Ai(h,s),r),this.atCursorPos=c,this.pendingBuffer=c?e<t?1:2:0}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 Ks(e,t,i,r);return o.openEnd=$.spans(s,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Ai(n,e){for(let t of e)n=new Ue(t,[n],n.length);return n}class Er extends at{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}}const Ol=D.define(),Tl=D.define(),Bl=D.define(),Pl=D.define(),ms=D.define(),Ll=D.define(),Rl=D.define({combine:n=>n.some(e=>e)});class Xi{constructor(e,t="nearest",i="nearest",s=5,r=5){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r}map(e){return e.empty?this:new Xi(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}}const Ir=R.define({map:(n,e)=>n.map(e)});function Ee(n,e,t){let i=n.facet(Pl);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 wn=D.define({combine:n=>n.length?n[0]:!0});let lc=0;const Yt=D.define();class de{constructor(e,t,i,s){this.id=e,this.create=t,this.domEventHandlers=i,this.extension=s(this)}static define(e,t){const{eventHandlers:i,provide:s,decorations:r}=t||{};return new de(lc++,e,i,o=>{let l=[Yt.of(o)];return r&&l.push(ui.of(h=>{let a=h.plugin(o);return a?r(a):T.none})),s&&l.push(s(o)),l})}static fromClass(e,t){return de.define(i=>new e(i),t)}}class Rn{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(Ee(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){Ee(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){Ee(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const El=D.define(),Il=D.define(),ui=D.define(),Nl=D.define(),Vl=D.define(),_t=D.define();class Xe{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new Xe(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 h=s==e.length?null:e[s],a=o-l,c=h?h.fromB:1e9;for(;r<t.length&&t[r]<c;){let f=t[r],u=t[r+1],d=Math.max(l,f),p=Math.min(c,u);if(d<=p&&new Xe(d+a,p+a,d,p).addToSet(i),u>c)break;r+=2}if(!h)return i;new Xe(h.fromA,h.toA,h.fromB,h.toB).addToSet(i),o=h.toA,l=h.toB}}}class Yi{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=_.empty(this.startState.doc.length);for(let o of i)this.changes=this.changes.compose(o.changes);let s=[];this.changes.iterChangedRanges((o,l,h,a)=>s.push(new Xe(o,l,h,a))),this.changedRanges=s;let r=e.hasFocus;r!=e.inputState.notifiedFocused&&(e.inputState.notifiedFocused=r,this.flags|=1)}static create(e,t,i){return new Yi(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}}var X=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(X||(X={}));const ys=X.LTR,hc=X.RTL;function Fl(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const ac=Fl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),cc=Fl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),bs=Object.create(null),Ne=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);bs[e]=t,bs[t]=-e}function fc(n){return n<=247?ac[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?cc[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8203?256:64336<=n&&n<=65023?4:n==8204?256:1}const uc=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Lt{constructor(e,t,i){this.from=e,this.to=t,this.level=i}get dir(){return this.level%2?hc:ys}side(e,t){return this.dir==t==e?this.to:this.from}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}}const q=[];function dc(n,e){let t=n.length,i=e==ys?1:2,s=e==ys?2:1;if(!n||i==1&&!uc.test(n))return Wl(t);for(let o=0,l=i,h=i;o<t;o++){let a=fc(n.charCodeAt(o));a==512?a=l:a==8&&h==4&&(a=16),q[o]=a==4?2:a,a&7&&(h=a),l=a}for(let o=0,l=i,h=i;o<t;o++){let a=q[o];if(a==128)o<t-1&&l==q[o+1]&&l&24?a=q[o]=l:q[o]=256;else if(a==64){let c=o+1;for(;c<t&&q[c]==64;)c++;let f=o&&l==8||c<t&&q[c]==8?h==1?1:8:256;for(let u=o;u<c;u++)q[u]=f;o=c-1}else a==8&&h==1&&(q[o]=1);l=a,a&7&&(h=a)}for(let o=0,l=0,h=0,a,c,f;o<t;o++)if(c=bs[a=n.charCodeAt(o)])if(c<0){for(let u=l-3;u>=0;u-=3)if(Ne[u+1]==-c){let d=Ne[u+2],p=d&2?i:d&4?d&1?s:i:0;p&&(q[o]=q[Ne[u]]=p),l=u;break}}else{if(Ne.length==189)break;Ne[l++]=o,Ne[l++]=a,Ne[l++]=h}else if((f=q[o])==2||f==1){let u=f==i;h=u?0:1;for(let d=l-3;d>=0;d-=3){let p=Ne[d+2];if(p&2)break;if(u)Ne[d+2]|=2;else{if(p&4)break;Ne[d+2]|=4}}}for(let o=0;o<t;o++)if(q[o]==256){let l=o+1;for(;l<t&&q[l]==256;)l++;let h=(o?q[o-1]:i)==1,a=(l<t?q[l]:i)==1,c=h==a?h?1:2:i;for(let f=o;f<l;f++)q[f]=c;o=l-1}let r=[];if(i==1)for(let o=0;o<t;){let l=o,h=q[o++]!=1;for(;o<t&&h==(q[o]!=1);)o++;if(h)for(let a=o;a>l;){let c=a,f=q[--a]!=2;for(;a>l&&f==(q[a-1]!=2);)a--;r.push(new Lt(a,c,f?2:1))}else r.push(new Lt(l,o,0))}else for(let o=0;o<t;){let l=o,h=q[o++]==2;for(;o<t&&h==(q[o]==2);)o++;r.push(new Lt(l,o,h?1:2))}return r}function Wl(n){return[new Lt(0,n,0)]}let Hl="";function pc(n,e,t,i,s){var r;let o=i.head-n.from,l=-1;if(o==0){if(!s||!n.length)return null;e[0].level!=t&&(o=e[0].side(!1,t),l=0)}else if(o==n.length){if(s)return null;let u=e[e.length-1];u.level!=t&&(o=u.side(!0,t),l=e.length-1)}l<0&&(l=Lt.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc));let h=e[l];o==h.side(s,t)&&(h=e[l+=s?1:-1],o=h.side(!s,t));let a=s==(h.dir==t),c=fe(n.text,o,a);if(Hl=n.text.slice(Math.min(o,c),Math.max(o,c)),c!=h.side(s,t))return m.cursor(c+n.from,a?-1:1,h.level);let f=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return!f&&h.level!=t?m.cursor(s?n.to:n.from,s?-1:1,t):f&&f.level<h.level?m.cursor(f.side(!s,t)+n.from,s?1:-1,f.level):m.cursor(c+n.from,s?-1:1,h.level)}const it="\uFFFF";class zl{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(I.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=it}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s),this.readNode(s);let r=s.nextSibling;if(r==t)break;let o=H.get(s),l=H.get(r);(o&&l?o.breakAfter:(o?o.breakAfter:Nr(s))||Nr(r)&&(s.nodeName!="BR"||s.cmIgnore))&&this.lineBreak(),s=r}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 h of this.points)h.node==e&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=H.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+Math.min(t,i.offset))}}function Nr(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}class Vr{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Fr extends H{constructor(e){super(),this.view=e,this.compositionDeco=T.none,this.decorations=[],this.dynamicDecorationMap=[],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 ue],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Xe(0,0,0,e.state.doc.length)],0)}get editorView(){return this.view}get length(){return this.view.state.doc.length}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:o,toA:l})=>l<this.minWidthFrom||o>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.view.inputState.composing<0?this.compositionDeco=T.none:(e.transactions.length||this.dirty)&&(this.compositionDeco=mc(this.view,e.changes)),(A.ie||A.chrome)&&!this.compositionDeco.size&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,s=this.updateDeco(),r=xc(i,s,e.changes);return t=Xe.extendWithRanges(t,r),this.dirty==0&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t);let{observer:i}=this.view;i.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=A.chrome||A.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.sync(r),this.dirty=0,r&&(r.written||i.selectionRange.focusNode!=r.node)&&(this.forceSelection=!0),this.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.children)r instanceof mt&&r.widget instanceof Wr&&s.push(r.dom);i.updateGaps(s)}updateChildren(e,t){let i=this.childCursor(t);for(let s=e.length-1;;s--){let r=s>=0?e[s]:null;if(!r)break;let{fromA:o,toA:l,fromB:h,toB:a}=r,{content:c,breakAtStart:f,openStart:u,openEnd:d}=Ks.build(this.view.state.doc,h,a,this.decorations,this.dynamicDecorationMap),{i:p,off:g}=i.findPos(l,1),{i:y,off:b}=i.findPos(o,-1);bl(this,y,b,p,g,c,f,u,d)}}updateSelection(e=!1,t=!1){if((e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange(),!(t||this.mayControlSelection()))return;let i=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,r=this.domAtPos(s.anchor),o=s.empty?r:this.domAtPos(s.head);if(A.gecko&&s.empty&&gc(r)){let h=document.createTextNode("");this.view.observer.ignore(()=>r.node.insertBefore(h,r.node.childNodes[r.offset]||null)),r=o=new he(h,0),i=!0}let l=this.view.observer.selectionRange;(i||!l.focusNode||!Gi(r.node,r.offset,l.anchorNode,l.anchorOffset)||!Gi(o.node,o.offset,l.focusNode,l.focusOffset))&&(this.view.observer.ignore(()=>{A.android&&A.chrome&&this.dom.contains(l.focusNode)&&kc(l.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let h=Ui(this.view.root);if(h)if(s.empty){if(A.gecko){let a=bc(r.node,r.offset);if(a&&a!=3){let c=$l(r.node,r.offset,a==1?1:-1);c&&(r=new he(c,a==1?0:c.nodeValue.length))}}h.collapse(r.node,r.offset),s.bidiLevel!=null&&l.cursorBidiLevel!=null&&(l.cursorBidiLevel=s.bidiLevel)}else if(h.extend)h.collapse(r.node,r.offset),h.extend(o.node,o.offset);else{let a=document.createRange();s.anchor>s.head&&([r,o]=[o,r]),a.setEnd(o.node,o.offset),a.setStart(r.node,r.offset),h.removeAllRanges(),h.addRange(a)}}),this.view.observer.setSelectionRange(r,o)),this.impreciseAnchor=r.precise?null:new he(l.anchorNode,l.anchorOffset),this.impreciseHead=o.precise?null:new he(l.focusNode,l.focusOffset)}enforceCursorAssoc(){if(this.compositionDeco.size)return;let e=this.view.state.selection.main,t=Ui(this.view.root);if(!t||!e.empty||!e.assoc||!t.modify)return;let i=ue.find(this,e.head);if(!i)return;let s=i.posAtStart;if(e.head==s||e.head==s+i.length)return;let r=this.coordsAt(e.head,-1),o=this.coordsAt(e.head,1);if(!r||!o||r.bottom>o.top)return;let l=this.domAtPos(e.head+e.assoc);t.collapse(l.node,l.offset),t.modify("move",e.assoc<0?"forward":"backward","lineboundary")}mayControlSelection(){let e=this.view.root.activeElement;return e==this.dom||Hi(this.dom,this.view.observer.selectionRange)&&!(e&&this.dom.contains(e))}nearest(e){for(let t=e;t;){let i=H.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 ue)break;t++,i=0}return this.children[t].domAtPos(i)}coordsAt(e,t){for(let i=this.length,s=this.children.length-1;;s--){let r=this.children[s],o=i-r.breakAfter-r.length;if(e>o||e==o&&r.type!=z.WidgetBefore&&r.type!=z.WidgetAfter&&(!s||t==2||this.children[s-1].breakAfter||this.children[s-1].type==z.WidgetBefore&&t>-2))return r.coordsAt(e-o,t);i=o}}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,h=this.view.textDirection==X.LTR;for(let a=0,c=0;c<this.children.length;c++){let f=this.children[c],u=a+f.length;if(u>s)break;if(a>=i){let d=f.dom.getBoundingClientRect();if(t.push(d.height),o){let p=f.dom.lastChild,g=p?ci(p):[];if(g.length){let y=g[g.length-1],b=h?y.right-d.left:d.right-y.left;b>l&&(l=b,this.minWidth=r,this.minWidthFrom=a,this.minWidthTo=u)}}}a=u+f.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?X.RTL:X.LTR}measureTextSize(){for(let s of this.children)if(s instanceof ue){let r=s.measureTextSize();if(r)return r}let e=document.createElement("div"),t,i;return e.className="cm-line",e.style.width="99999px",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let s=ci(e.firstChild)[0];t=e.getBoundingClientRect().height,i=s?s.width/27:7,e.remove()}),{lineHeight:t,charWidth:i}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new yl(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;e.push(T.replace({widget:new Wr(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return T.set(e)}updateDeco(){let e=this.view.state.facet(ui).map((t,i)=>(this.dynamicDecorationMap[i]=typeof t=="function")?t(this.view):t);for(let t=e.length;t<e.length+3;t++)this.dynamicDecorationMap[t]=!1;return this.decorations=[...e,this.compositionDeco,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco]}scrollIntoView(e){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=0,o=0,l=0,h=0;for(let c of this.view.state.facet(Vl).map(f=>f(this.view)))if(c){let{left:f,right:u,top:d,bottom:p}=c;f!=null&&(r=Math.max(r,f)),u!=null&&(o=Math.max(o,u)),d!=null&&(l=Math.max(l,d)),p!=null&&(h=Math.max(h,p))}let a={left:i.left-r,top:i.top-l,right:i.right+o,bottom:i.bottom+h};ec(this.view.scrollDOM,a,t.head<t.anchor?-1:1,e.x,e.y,e.xMargin,e.yMargin,this.view.textDirection==X.LTR)}}function gc(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 Wr extends at{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get estimatedHeight(){return this.height}}function ql(n){let e=n.observer.selectionRange,t=e.focusNode&&$l(e.focusNode,e.focusOffset,0);if(!t)return null;let i=n.docView.nearest(t);if(!i)return null;if(i instanceof ue){let s=t;for(;s.parentNode!=i.dom;)s=s.parentNode;let r=s.previousSibling;for(;r&&!H.get(r);)r=r.previousSibling;let o=r?H.get(r).posAtEnd:i.posAtStart;return{from:o,to:o,node:s,text:t}}else{for(;;){let{parent:r}=i;if(!r)return null;if(r instanceof ue)break;i=r}let s=i.posAtStart;return{from:s,to:s+i.length,node:i.dom,text:t}}}function mc(n,e){let t=ql(n);if(!t)return T.none;let{from:i,to:s,node:r,text:o}=t,l=e.mapPos(i,1),h=Math.max(l,e.mapPos(s,-1)),{state:a}=n,c=r.nodeType==3?r.nodeValue:new zl([],a).readRange(r.firstChild,null).text;if(h-l<c.length)if(a.doc.sliceString(l,Math.min(a.doc.length,l+c.length),it)==c)h=l+c.length;else if(a.doc.sliceString(Math.max(0,h-c.length),h,it)==c)l=h-c.length;else return T.none;else if(a.doc.sliceString(l,h,it)!=c)return T.none;let f=H.get(r);return f instanceof Sl?f=f.widget.topView:f&&(f.parent=null),T.set(T.replace({widget:new yc(r,o,f),inclusive:!0}).range(l,h))}class yc extends at{constructor(e,t,i){super(),this.top=e,this.text=t,this.topView=i}eq(e){return this.top==e.top&&this.text==e.text}toDOM(){return this.top}ignoreEvent(){return!1}get customView(){return Sl}}function $l(n,e,t){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&e>0&&t<=0)n=n.childNodes[e-1],e=fi(n);else if(n.nodeType==1&&e<n.childNodes.length&&t>=0)n=n.childNodes[e],e=0;else return null}}function bc(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)}class wc{constructor(){this.changes=[]}compareRange(e,t){gs(e,t,this.changes)}comparePoint(e,t){gs(e,t,this.changes)}}function xc(n,e,t){let i=new wc;return $.compare(n,e,t,i),i.changes}function kc(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 Sc(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return m.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=fe(s.text,r,!1):l=fe(s.text,r);let h=i(s.text.slice(o,l));for(;o>0;){let a=fe(s.text,o,!1);if(i(s.text.slice(a,o))!=h)break;o=a}for(;l<s.length;){let a=fe(s.text,l);if(i(s.text.slice(l,a))!=h)break;l=a}return m.range(o+s.from,l+s.from)}function vc(n,e){return e.left>n?e.left-n:Math.max(0,n-e.right)}function Cc(n,e){return e.top>n?e.top-n:Math.max(0,n-e.bottom)}function En(n,e){return n.top<e.bottom-1&&n.bottom>e.top+1}function Hr(n,e){return e<n.top?{top:e,left:n.left,right:n.right,bottom:n.bottom}:n}function zr(n,e){return e>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:e}:n}function ws(n,e,t){let i,s,r,o,l=!1,h,a,c,f;for(let p=n.firstChild;p;p=p.nextSibling){let g=ci(p);for(let y=0;y<g.length;y++){let b=g[y];s&&En(s,b)&&(b=Hr(zr(b,s.bottom),s.top));let S=vc(e,b),v=Cc(t,b);if(S==0&&v==0)return p.nodeType==3?qr(p,e,t):ws(p,e,t);(!i||o>v||o==v&&r>S)&&(i=p,s=b,r=S,o=v,l=!S||(S>0?y<g.length-1:y>0)),S==0?t>b.bottom&&(!c||c.bottom<b.bottom)?(h=p,c=b):t<b.top&&(!f||f.top>b.top)&&(a=p,f=b):c&&En(c,b)?c=zr(c,b.bottom):f&&En(f,b)&&(f=Hr(f,b.top))}}if(c&&c.bottom>=t?(i=h,s=c):f&&f.top<=t&&(i=a,s=f),!i)return{node:n,offset:0};let u=Math.max(s.left,Math.min(s.right,e));if(i.nodeType==3)return qr(i,u,t);if(l&&i.contentEditable!="false")return ws(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 qr(n,e,t){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let h=It(n,l,l+1).getClientRects();for(let a=0;a<h.length;a++){let c=h[a];if(c.top==c.bottom)continue;o||(o=e-c.left);let f=(c.top>t?c.top-t:t-c.bottom)-1;if(c.left-1<=e&&c.right+1>=e&&f<r){let u=e>=(c.left+c.right)/2,d=u;if((A.chrome||A.gecko)&&It(n,l).getBoundingClientRect().left==c.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 jl(n,{x:e,y:t},i,s=-1){var r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,h,{docHeight:a}=n.viewState,c=t-l;if(c<0)return 0;if(c>a)return n.state.doc.length;for(let b=n.defaultLineHeight/2,S=!1;h=n.elementAtHeight(c),h.type!=z.Text;)for(;c=s>0?h.bottom+b:h.top-b,!(c>=0&&c<=a);){if(S)return i?null:0;S=!0,s=-s}t=l+c;let f=h.from;if(f<n.viewport.from)return n.viewport.from==0?0:i?null:$r(n,o,h,e,t);if(f>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:i?null:$r(n,o,h,e,t);let u=n.dom.ownerDocument,d=n.root.elementFromPoint?n.root:u,p=d.elementFromPoint(e,t);p&&!n.contentDOM.contains(p)&&(p=null),p||(e=Math.max(o.left+1,Math.min(o.right-1,e)),p=d.elementFromPoint(e,t),p&&!n.contentDOM.contains(p)&&(p=null));let g,y=-1;if(p&&((r=n.docView.nearest(p))===null||r===void 0?void 0:r.isEditable)!=!1){if(u.caretPositionFromPoint){let b=u.caretPositionFromPoint(e,t);b&&({offsetNode:g,offset:y}=b)}else if(u.caretRangeFromPoint){let b=u.caretRangeFromPoint(e,t);b&&({startContainer:g,startOffset:y}=b,(!n.contentDOM.contains(g)||A.safari&&Ac(g,y,e)||A.chrome&&Mc(g,y,e))&&(g=void 0))}}if(!g||!n.docView.dom.contains(g)){let b=ue.find(n.docView,f);if(!b)return c>h.top+h.height/2?h.to:h.from;({node:g,offset:y}=ws(b.dom,e,t))}return n.docView.posFromDOM(g,y)}function $r(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);n.lineWrapping&&t.height>n.defaultLineHeight*1.5&&(r+=Math.floor((s-t.top)/n.defaultLineHeight)*n.viewState.heightOracle.lineLength);let o=n.state.sliceDoc(t.from,t.to);return t.from+rs(o,r,n.state.tabSize)}function Ac(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 It(n,i-1,i).getBoundingClientRect().left>t}function Mc(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():It(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function Dc(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=!i||!n.lineWrapping?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let h=n.dom.getBoundingClientRect(),a=n.textDirectionAt(s.from),c=n.posAtCoords({x:t==(a==X.LTR)?h.right-1:h.left+1,y:(r.top+r.bottom)/2});if(c!=null)return m.cursor(c,t?-1:1)}let o=ue.find(n.docView,e.head),l=o?t?o.posAtEnd:o.posAtStart:t?s.to:s.from;return m.cursor(l,t?-1:1)}function jr(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,h=null;;){let a=pc(s,r,o,l,t),c=Hl;if(!a){if(s.number==(t?n.state.doc.lines:1))return l;c=`
`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),a=m.cursor(t?s.from:s.to)}if(h){if(!h(c))return l}else{if(!i)return a;h=i(c)}l=a}}function Oc(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==j.Space&&(s=o),s==o}}function Tc(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return m.cursor(s,e.assoc);let o=e.goalColumn,l,h=n.contentDOM.getBoundingClientRect(),a=n.coordsAtPos(s),c=n.documentTop;if(a)o==null&&(o=a.left-h.left),l=r<0?a.top:a.bottom;else{let d=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(h.right-h.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+c}let f=h.left+o,u=i!=null?i:n.defaultLineHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=jl(n,{x:f,y:p},!1,r);if(p<h.top||p>h.bottom||(r<0?g<s:g>s))return m.cursor(g,e.assoc,void 0,o)}}function In(n,e,t){let i=n.state.facet(Nl).map(s=>s(n));for(;;){let s=!1;for(let r of i)r.between(t.from-1,t.from+1,(o,l,h)=>{t.from>o&&t.from<l&&(t=e.head>t.from?m.cursor(o,1):m.cursor(l,-1),s=!0)});if(!s)return t}}class Bc{constructor(e){this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.chromeScrollHack=-1,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.registeredEvents=[],this.customHandlers=[],this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.mouseSelection=null;for(let t in Z){let i=Z[t];e.contentDOM.addEventListener(t,s=>{!Kr(e,s)||this.ignoreDuringComposition(s)||t=="keydown"&&this.keydown(e,s)||(this.mustFlushObserver(s)&&e.observer.forceFlush(),this.runCustomHandlers(t,e,s)?s.preventDefault():i(e,s))},xs[t]),this.registeredEvents.push(t)}A.chrome&&A.chrome_version==102&&e.scrollDOM.addEventListener("wheel",()=>{this.chromeScrollHack<0?e.contentDOM.style.pointerEvents="none":window.clearTimeout(this.chromeScrollHack),this.chromeScrollHack=setTimeout(()=>{this.chromeScrollHack=-1,e.contentDOM.style.pointerEvents=""},100)},{passive:!0}),this.notifiedFocused=e.hasFocus,A.safari&&e.contentDOM.addEventListener("input",()=>null)}setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}ensureHandlers(e,t){var i;let s;this.customHandlers=[];for(let r of t)if(s=(i=r.update(e).spec)===null||i===void 0?void 0:i.domEventHandlers){this.customHandlers.push({plugin:r.value,handlers:s});for(let o in s)this.registeredEvents.indexOf(o)<0&&o!="scroll"&&(this.registeredEvents.push(o),e.contentDOM.addEventListener(o,l=>{!Kr(e,l)||this.runCustomHandlers(o,e,l)&&l.preventDefault()}))}}runCustomHandlers(e,t,i){for(let s of this.customHandlers){let r=s.handlers[e];if(r)try{if(r.call(s.plugin,i,t)||i.defaultPrevented)return!0}catch(o){Ee(t.state,o)}}return!1}runScrollHandlers(e,t){this.lastScrollTop=e.scrollDOM.scrollTop,this.lastScrollLeft=e.scrollDOM.scrollLeft;for(let i of this.customHandlers){let s=i.handlers.scroll;if(s)try{s.call(i.plugin,t,e)}catch(r){Ee(e.state,r)}}}keydown(e,t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&Date.now()<this.lastEscPress+2e3)return!0;if(A.android&&A.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return e.observer.delayAndroidKey(t.key,t.keyCode),!0;let i;return A.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((i=Kl.find(s=>s.keyCode==t.keyCode))&&!t.ctrlKey||Pc.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=i||t,setTimeout(()=>this.flushIOSKey(e),250),!0):!1}flushIOSKey(e){let t=this.pendingIOSKey;return t?(this.pendingIOSKey=void 0,ni(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:A.safari&&!A.ios&&Date.now()-this.compositionEndedAt<100?(this.compositionEndedAt=0,!0):!1:!1}mustFlushObserver(e){return e.type=="keydown"&&e.keyCode!=229}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}const Kl=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Pc="dthko",Ul=[16,17,18,20,91,92,224,225];class Lc{constructor(e,t,i,s){this.view=e,this.style=i,this.mustSelect=s,this.lastEvent=t;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(I.allowMultipleSelections)&&Rc(e,t),this.dragMove=Ec(e,t),this.dragging=Ic(e,t)&&Us(t)==1?null:!1,this.dragging===!1&&(t.preventDefault(),this.select(t))}move(e){if(e.buttons==0)return this.destroy();this.dragging===!1&&this.select(this.lastEvent=e)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}select(e){let t=this.style.get(e,this.extend,this.multiple);(this.mustSelect||!t.eq(this.view.state.selection)||t.main.assoc!=this.view.state.selection.main.assoc)&&this.view.dispatch({selection:t,userEvent:"select.pointer",scrollIntoView:!0}),this.mustSelect=!1}update(e){e.docChanged&&this.dragging&&(this.dragging=this.dragging.map(e.changes)),this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Rc(n,e){let t=n.state.facet(Ol);return t.length?t[0](e):A.mac?e.metaKey:e.ctrlKey}function Ec(n,e){let t=n.state.facet(Tl);return t.length?t[0](e):A.mac?!e.altKey:!e.ctrlKey}function Ic(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=Ui(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 Kr(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=H.get(t))&&i.ignoreEvent(e))return!1;return!0}const Z=Object.create(null),xs=Object.create(null),Gl=A.ie&&A.ie_version<15||A.ios&&A.webkit_version<604;function Nc(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(),Jl(n,t.value)},50)}function Jl(n,e){let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(ks!=null&&t.selection.ranges.every(h=>h.empty)&&ks==r.toString()){let h=-1;i=t.changeByRange(a=>{let c=t.doc.lineAt(a.from);if(c.from==h)return{range:a};h=c.from;let f=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:m.cursor(a.from+f.length)}})}else o?i=t.changeByRange(h=>{let a=r.line(s++);return{changes:{from:h.from,to:h.to,insert:a.text},range:m.cursor(h.from+a.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Z.keydown=(n,e)=>{n.inputState.setSelectionOrigin("select"),e.keyCode==27?n.inputState.lastEscPress=Date.now():Ul.indexOf(e.keyCode)<0&&(n.inputState.lastEscPress=0)};Z.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};Z.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};xs.touchstart=xs.touchmove={passive:!0};Z.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3&&Us(e)==1)return;let t=null;for(let i of n.state.facet(Bl))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=Wc(n,e)),t){let i=n.root.activeElement!=n.contentDOM;i&&n.observer.ignore(()=>gl(n.contentDOM)),n.inputState.startMouseSelection(new Lc(n,e,t,i))}};function Ur(n,e,t,i){if(i==1)return m.cursor(e,t);if(i==2)return Sc(n.state,e,t);{let s=ue.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++,m.range(o,l)}}let Xl=(n,e)=>n>=e.top&&n<=e.bottom,Gr=(n,e,t)=>Xl(e,t)&&n>=t.left&&n<=t.right;function Vc(n,e,t,i){let s=ue.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&&Gr(t,i,o))return-1;let l=s.coordsAt(r,1);return l&&Gr(t,i,l)?1:o&&Xl(i,o)?-1:1}function Jr(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Vc(n,t,e.clientX,e.clientY)}}const Fc=A.ie&&A.ie_version<=11;let Xr=null,Yr=0,_r=0;function Us(n){if(!Fc)return n.detail;let e=Xr,t=_r;return Xr=n,_r=Date.now(),Yr=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(Yr+1)%3:1}function Wc(n,e){let t=Jr(n,e),i=Us(e),s=n.state.selection,r=t,o=e;return{update(l){l.docChanged&&(t.pos=l.changes.mapPos(t.pos),s=s.map(l.changes),o=null)},get(l,h,a){let c;o&&l.clientX==o.clientX&&l.clientY==o.clientY?c=r:(c=r=Jr(n,l),o=l);let f=Ur(n,c.pos,c.bias,i);if(t.pos!=c.pos&&!h){let u=Ur(n,t.pos,t.bias,i),d=Math.min(u.from,f.from),p=Math.max(u.to,f.to);f=d<f.from?m.range(d,p):m.range(p,d)}return h?s.replaceRange(s.main.extend(f.from,f.to)):a&&s.ranges.length>1&&s.ranges.some(u=>u.eq(f))?Hc(s,f):a?s.addRange(f):m.create([f])}}}function Hc(n,e){for(let t=0;;t++)if(n.ranges[t].eq(e))return m.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}Z.dragstart=(n,e)=>{let{selection:{main:t}}=n.state,{mouseSelection:i}=n.inputState;i&&(i.dragging=t),e.dataTransfer&&(e.dataTransfer.setData("Text",n.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove")};function Qr(n,e,t,i){if(!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1);e.preventDefault();let{mouseSelection:r}=n.inputState,o=i&&r&&r.dragging&&r.dragMove?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:t},h=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:h,selection:{anchor:h.mapPos(s,-1),head:h.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}Z.drop=(n,e)=>{if(!e.dataTransfer)return;if(n.state.readOnly)return e.preventDefault();let t=e.dataTransfer.files;if(t&&t.length){e.preventDefault();let i=Array(t.length),s=0,r=()=>{++s==t.length&&Qr(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])}}else Qr(n,e,e.dataTransfer.getData("Text"),!0)};Z.paste=(n,e)=>{if(n.state.readOnly)return e.preventDefault();n.observer.flush();let t=Gl?null:e.clipboardData;t?(Jl(n,t.getData("text/plain")),e.preventDefault()):Nc(n)};function zc(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 qc(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 ks=null;Z.copy=Z.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=qc(n.state);if(!t&&!s)return;ks=s?t:null;let r=Gl?null:e.clipboardData;r?(e.preventDefault(),r.clearData(),r.setData("text/plain",t)):zc(n,t),e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};function Yl(n){setTimeout(()=>{n.hasFocus!=n.inputState.notifiedFocused&&n.update([])},10)}Z.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),Yl(n)};Z.blur=n=>{n.observer.clearSelectionRange(),Yl(n)};Z.compositionstart=Z.compositionupdate=n=>{n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0)};Z.compositionend=n=>{n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionFirstChange=null,A.chrome&&A.android&&n.observer.flushSoon(),setTimeout(()=>{n.inputState.composing<0&&n.docView.compositionDeco.size&&n.update([])},50)};Z.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Z.beforeinput=(n,e)=>{var t;let i;if(A.chrome&&A.android&&(i=Kl.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)}};const Zr=["pre-wrap","normal","pre-line","break-spaces"];class $c{constructor(){this.doc=N.empty,this.lineWrapping=!1,this.heightSamples={},this.lineHeight=14,this.charWidth=7,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.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 Zr.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){let o=Zr.indexOf(e)>-1,l=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=i,this.lineLength=s,l){this.heightSamples={};for(let h=0;h<r.length;h++){let a=r[h];a<0?h++:this.heightSamples[Math.floor(a*10)]=!0}}return l}}class jc{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class nt{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this.type=r}get to(){return this.from+this.length}get bottom(){return this.top+this.height}join(e){let t=(Array.isArray(this.type)?this.type:[this]).concat(Array.isArray(e.type)?e.type:[e]);return new nt(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var W=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(W||(W={}));const zi=.001;class we{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)>zi&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return we.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this;for(let o=s.length-1;o>=0;o--){let{fromA:l,toA:h,fromB:a,toB:c}=s[o],f=r.lineAt(l,W.ByPosNoHeight,t,0,0),u=f.to>=h?f:r.lineAt(h,W.ByPosNoHeight,t,0,0);for(c+=u.to-h,h=u.to;o>0&&f.from<=s[o-1].toA;)l=s[o-1].fromA,a=s[o-1].fromB,o--,l<f.from&&(f=r.lineAt(l,W.ByPosNoHeight,t,0,0));a+=f.from-l,l=f.from;let d=Gs.build(i,e,a,c);r=r.replace(l,h,d)}return r.updateHeight(i,0)}static empty(){return new Se(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 Kc(we.of(e.slice(0,t)),o,we.of(e.slice(i)))}}we.prototype.size=1;class _l extends we{constructor(e,t,i){super(e,t),this.type=i}blockAt(e,t,i,s){return new nt(s,this.length,i,this.height,this.type)}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 Se extends _l{constructor(e,t){super(e,t,z.Text),this.collapsed=0,this.widgetHeight=0}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof Se||s instanceof te&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof te?s=new Se(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):we.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.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class te extends we{constructor(e){super(e,0)}lines(e,t){let i=e.lineAt(t).number,s=e.lineAt(t+this.length).number;return{firstLine:i,lastLine:s,lineHeight:this.height/(s-i+1)}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,lineHeight:l}=this.lines(t,s),h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:a,length:c}=t.line(r+h);return new nt(a,c,i+l*h,l,z.Text)}lineAt(e,t,i,s,r){if(t==W.ByHeight)return this.blockAt(e,i,s,r);if(t==W.ByPosNoHeight){let{from:f,to:u}=i.lineAt(e);return new nt(f,u-f,0,0,z.Text)}let{firstLine:o,lineHeight:l}=this.lines(i,r),{from:h,length:a,number:c}=i.lineAt(e);return new nt(h,a,s+l*(c-o),l,z.Text)}forEachLine(e,t,i,s,r,o){let{firstLine:l,lineHeight:h}=this.lines(i,r);for(let a=Math.max(e,r),c=Math.min(r+this.length,t);a<=c;){let f=i.lineAt(a);a==e&&(s+=h*(f.number-l)),o(new nt(f.from,f.length,s,h,z.Text)),s+=h,a=f.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof te?i[i.length-1]=new te(r.length+s):i.push(null,new te(s-1))}if(e>0){let r=i[0];r instanceof te?i[0]=new te(e+r.length):i.unshift(new te(e-1),null)}return we.of(i)}decomposeLeft(e,t){t.push(new te(e-1),null)}decomposeRight(e,t){t.push(null,new te(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),h=-1,a=e.heightChanged;for(s.from>t&&o.push(new te(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let f=e.doc.lineAt(l).length;o.length&&o.push(null);let u=s.heights[s.index++];h==-1?h=u:Math.abs(u-h)>=zi&&(h=-2);let d=new Se(f,u);d.outdated=!1,o.push(d),l+=f+1}l<=r&&o.push(null,new te(r-l).updateHeight(e,l));let c=we.of(o);return e.heightChanged=a||h<0||Math.abs(c.height-this.height)>=zi||Math.abs(h-this.lines(e.doc,t).lineHeight)>=zi,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 Kc extends we{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,h=t==W.ByHeight?e<o:e<l,a=h?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(h?a.to<l:a.from>l))return a;let c=t==W.ByPosNoHeight?W.ByPosNoHeight:W.ByPos;return h?a.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(a)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,h=r+this.left.length+this.break;if(this.break)e<h&&this.left.forEachLine(e,t,i,s,r,o),t>=h&&this.right.forEachLine(e,t,i,l,h,o);else{let a=this.lineAt(h,W.ByPos,i,s,r);e<a.from&&this.left.forEachLine(e,a.from-1,i,s,r,o),a.to>=e&&a.from<=t&&o(a),t>a.to&&this.right.forEachLine(a.to+1,t,i,l,h,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&&eo(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),eo(r,l)}return we.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?we.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,h=null;return s&&s.from<=t+r.length&&s.more?h=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?h=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),h?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 eo(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof te&&(i=n[e+1])instanceof te&&n.splice(e-1,3,new te(t.length+1+i.length))}const Uc=5;class Gs{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 Se?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Se(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;s<0&&(s=this.oracle.lineHeight);let r=t-e;i.block?this.addBlock(new _l(r,s,i.type)):(r||s>=Uc)&&this.addLineDeco(s,r)}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 Se(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new te(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 Se)return e;let t=new Se(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine(),e.type==z.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,e.type!=z.WidgetBefore&&(this.covering=e)}addLineDeco(e,t){let i=this.ensureLine();i.length+=t,i.collapsed+=t,i.widgetHeight=Math.max(i.widgetHeight,e),this.writtenTo=this.pos=this.pos+t}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Se)&&!this.isCovered?this.nodes.push(new Se(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 Se&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new Gs(i,e);return $.spans(t,i,s,r,0),r.finish(i)}}function Gc(n,e,t){let i=new Jc;return $.compare(n,e,t,i,0),i.changes}class Jc{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&gs(e,t,this.changes,5)}}function Xc(n,e){let t=n.getBoundingClientRect(),i=Math.max(0,t.left),s=Math.min(innerWidth,t.right),r=Math.max(0,t.top),o=Math.min(innerHeight,t.bottom),l=n.ownerDocument.body;for(let h=n.parentNode;h&&h!=l;)if(h.nodeType==1){let a=h,c=window.getComputedStyle(a);if((a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth)&&c.overflow!="visible"){let f=a.getBoundingClientRect();i=Math.max(i,f.left),s=Math.min(s,f.right),r=Math.max(r,f.top),o=h==n.parentNode?f.bottom:Math.min(o,f.bottom)}h=c.position=="absolute"||c.position=="fixed"?a.offsetParent:a.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:i-t.left,right:Math.max(i,s)-t.left,top:r-(t.top+e),bottom:Math.max(r,o)-(t.top+e)}}function Yc(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Nn{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){return T.replace({widget:new _c(this.size,e)}).range(this.from,this.to)}}class _c extends at{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 to{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.heightOracle=new $c,this.scaler=so,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=X.RTL,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1,this.stateDeco=e.facet(ui).filter(t=>typeof t!="function"),this.heightMap=we.empty().applyChanges(this.stateDeco,N.empty,this.heightOracle.setDoc(e.doc),[new Xe(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=T.set(this.lineGaps.map(t=>t.draw(!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 Mi(r,o))}}this.viewports=e.sort((i,s)=>i.from-s.from),this.scaler=this.heightMap.height<=7e6?so:new ef(this.heightOracle.doc,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.state.doc,0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:Qt(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(ui).filter(a=>typeof a!="function");let s=e.changedRanges,r=Xe.extendWithRanges(s,Gc(i,this.stateDeco,e?e.changes:_.empty(this.state.doc.length))),o=this.heightMap.height;this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2);let l=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<l.from||t.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,t));let h=!e.changes.empty||e.flags&2||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),h&&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&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?X.RTL:X.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=o||this.mustMeasureContent||this.contentDOMHeight!=t.clientHeight;this.contentDOMHeight=t.clientHeight,this.mustMeasureContent=!1;let h=0,a=0,c=parseInt(i.paddingTop)||0,f=parseInt(i.paddingBottom)||0;(this.paddingTop!=c||this.paddingBottom!=f)&&(this.paddingTop=c,this.paddingBottom=f,h|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(l=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8);let u=(this.printing?Yc:Xc)(t,this.paddingTop),d=u.top-this.pixelViewport.top,p=u.bottom-this.pixelViewport.bottom;this.pixelViewport=u;let g=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(g!=this.inView&&(this.inView=g,g&&(l=!0)),!this.inView)return 0;let y=t.clientWidth;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=y,this.editorHeight=e.scrollDOM.clientHeight,h|=8),l){let S=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(S)&&(o=!0),o||s.lineWrapping&&Math.abs(y-this.contentDOMWidth)>s.charWidth){let{lineHeight:v,charWidth:k}=e.docView.measureTextSize();o=s.refresh(r,v,k,y/k,S),o&&(e.docView.minWidth=0,h|=8)}d>0&&p>0?a=Math.max(d,p):d<0&&p<0&&(a=Math.min(d,p)),s.heightChanged=!1;for(let v of this.viewports){let k=v.from==this.viewport.from?S:e.docView.measureVisibleLineHeights(v);this.heightMap=this.heightMap.updateHeight(s,0,o,new jc(v.from,k))}s.heightChanged&&(h|=2)}let b=!this.viewportIsAppropriate(this.viewport,a)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return b&&(this.viewport=this.getViewport(a,this.scrollTarget)),this.updateForViewport(),(h&2||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}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.state.doc,{visibleTop:o,visibleBottom:l}=this,h=new Mi(s.lineAt(o-i*1e3,W.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,W.ByHeight,r,0,0).to);if(t){let{head:a}=t.range;if(a<h.from||a>h.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(a,W.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&a<h.from?u=f.top:u=f.bottom-c,h=new Mi(s.lineAt(u-1e3/2,W.ByHeight,r,0,0).from,s.lineAt(u+c+1e3/2,W.ByHeight,r,0,0).to)}}return h}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Mi(this.heightMap.lineAt(i,W.ByPos,this.state.doc,0,0).from,this.heightMap.lineAt(s,W.ByPos,this.state.doc,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,W.ByPos,this.state.doc,0,0),{bottom:r}=this.heightMap.lineAt(t,W.ByPos,this.state.doc,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 Nn(t.mapPos(s.from),t.mapPos(s.to),s.size));return i}ensureLineGaps(e){let t=[];if(this.defaultTextDirection!=X.LTR)return t;for(let i of this.viewportLines){if(i.length<4e3)continue;let s=Qc(i.from,i.to,this.stateDeco);if(s.total<4e3)continue;let r,o;if(this.heightOracle.lineWrapping){let a=2e3/this.heightOracle.lineLength*this.heightOracle.lineHeight;r=Di(s,(this.visibleTop-i.top-a)/i.height),o=Di(s,(this.visibleBottom-i.top+a)/i.height)}else{let a=s.total*this.heightOracle.charWidth,c=2e3*this.heightOracle.charWidth;r=Di(s,(this.pixelViewport.left-c)/a),o=Di(s,(this.pixelViewport.right+c)/a)}let l=[];r>i.from&&l.push({from:i.from,to:r}),o<i.to&&l.push({from:o,to:i.to});let h=this.state.selection.main;h.from>=i.from&&h.from<=i.to&&no(l,h.from-10,h.from+10),!h.empty&&h.to>=i.from&&h.to<=i.to&&no(l,h.to-10,h.to+10);for(let{from:a,to:c}of l)c-a>1e3&&t.push(Zc(e,f=>f.from>=i.from&&f.to<=i.to&&Math.abs(f.from-a)<1e3&&Math.abs(f.to-c)<1e3)||new Nn(a,c,this.gapSize(i,a,c,s)))}return t}gapSize(e,t,i,s){let r=io(s,i)-io(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){Nn.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=T.set(e.map(t=>t.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];$.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)||Qt(this.heightMap.lineAt(e,W.ByPos,this.state.doc,0,0),this.scaler)}lineBlockAtHeight(e){return Qt(this.heightMap.lineAt(this.scaler.fromDOM(e),W.ByHeight,this.state.doc,0,0),this.scaler)}elementAtHeight(e){return Qt(this.heightMap.blockAt(this.scaler.fromDOM(e),this.state.doc,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Mi{constructor(e,t){this.from=e,this.to=t}}function Qc(n,e,t){let i=[],s=n,r=0;return $.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 Di({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 io(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 no(n,e,t){for(let i=0;i<n.length;i++){let s=n[i];if(s.from<t&&s.to>e){let r=[];s.from<e&&r.push({from:s.from,to:e}),s.to>t&&r.push({from:t,to:s.to}),n.splice(i,1,...r),i+=r.length-1}}}function Zc(n,e){for(let t of n)if(e(t))return t}const so={toDOM(n){return n},fromDOM(n){return n},scale:1};class ef{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let a=t.lineAt(l,W.ByPos,e,0,0).top,c=t.lineAt(h,W.ByPos,e,0,0).bottom;return s+=c-a,{from:l,to:h,top:a,bottom:c,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}}}function Qt(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new nt(n.from,n.length,t,i-t,Array.isArray(n.type)?n.type.map(s=>Qt(s,e)):n.type)}const Oi=D.define({combine:n=>n.join(" ")}),Ss=D.define({combine:n=>n.indexOf(!0)>-1}),vs=ot.newName(),Ql=ot.newName(),Zl=ot.newName(),eh={"&light":"."+Ql,"&dark":"."+Zl};function Cs(n,e,t){return new ot(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 tf=Cs("."+vs,{"&.cm-editor":{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,minHeight:"100%",display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",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 4px"},".cm-selectionLayer":{zIndex:-1,contain:"size style"},".cm-selectionBackground":{position:"absolute"},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{zIndex:100,contain:"size style",pointerEvents:"none"},"&.cm-focused .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":{position:"absolute",borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},"&.cm-focused .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#f3f9ff"},"&dark .cm-activeLine":{backgroundColor:"#223039"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",left: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-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"}},eh),nf={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Vn=A.ie&&A.ie_version<=11;class sf{constructor(e,t,i){this.view=e,this.onChange=t,this.onScrollChanged=i,this.active=!1,this.selectionRange=new tc,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resize=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(s=>{for(let r of s)this.queue.push(r);(A.ie&&A.ie_version<=11||A.ios&&e.composing)&&s.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),Vn&&(this.onCharData=s=>{this.queue.push({target:s.target,type:"characterData",oldValue:s.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),typeof ResizeObserver=="function"&&(this.resize=new ResizeObserver(()=>{this.view.docView.lastUpdate<Date.now()-75&&this.onResize()}),this.resize.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(s=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),s.length>0&&s[s.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(s=>{s.length>0&&s[s.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){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(wn)?i.root.activeElement!=this.dom:!Hi(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(A.ie&&A.ie_version<=11||A.android&&A.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Gi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=A.safari&&e.root.nodeType==11&&Qa(this.dom.ownerDocument)==this.dom&&rf(this.view)||Ui(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=Hi(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&nc(this.dom,t)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(t),i&&(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,nf),Vn&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){!this.active||(this.active=!1,this.observer.disconnect(),Vn&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;this.delayedAndroidKey||this.view.win.requestAnimationFrame(()=>{let s=this.delayedAndroidKey;this.delayedAndroidKey=null,this.delayedFlush=-1,!this.flush()&&s.force&&ni(this.dom,s.key,s.keyCode)}),(!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)})}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()}processRecords(){let e=this.queue;for(let r of this.observer.takeRecords())e.push(r);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}}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let{from:t,to:i,typeOver:s}=this.processRecords(),r=this.selectionChanged&&Hi(this.dom,this.selectionRange);if(t<0&&!r)return!1;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let o=this.view.state,l=this.onChange(t,i,s);return this.view.state==o&&this.view.update([]),l}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.dirty|=4),e.type=="childList"){let i=ro(t,e.previousSibling||e.target.previousSibling,-1),s=ro(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),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),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}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.resize)===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)}}function ro(n,e,t){for(;e;){let i=H.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 rf(n){let e=null;function t(h){h.preventDefault(),h.stopImmediatePropagation(),e=h.getTargetRanges()[0]}if(n.contentDOM.addEventListener("beforeinput",t,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,s=e.startOffset,r=e.endContainer,o=e.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor);return Gi(l.node,l.offset,r,o)&&([i,s,r,o]=[r,o,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:o}}function of(n,e,t,i){let s,r,o=n.state.selection.main;if(e>-1){let l=n.docView.domBoundsAround(e,t,0);if(!l||n.state.readOnly)return!1;let{from:h,to:a}=l,c=n.docView.impreciseHead||n.docView.impreciseAnchor?[]:hf(n),f=new zl(c,n.state);f.readRange(l.startDOM,l.endDOM);let u=o.from,d=null;(n.inputState.lastKeyCode===8&&n.inputState.lastKeyTime>Date.now()-100||A.android&&f.text.length<a-h)&&(u=o.to,d="end");let p=lf(n.state.doc.sliceString(h,a,it),f.text,u-h,d);p&&(A.chrome&&n.inputState.lastKeyCode==13&&p.toB==p.from+2&&f.text.slice(p.from,p.toB)==it+it&&p.toB--,s={from:h+p.from,to:h+p.toA,insert:N.of(f.text.slice(p.from,p.toB).split(it))}),r=af(c,h)}else if(n.hasFocus||!n.state.facet(wn)){let l=n.observer.selectionRange,{impreciseHead:h,impreciseAnchor:a}=n.docView,c=h&&h.node==l.focusNode&&h.offset==l.focusOffset||!Et(n.contentDOM,l.focusNode)?n.state.selection.main.head:n.docView.posFromDOM(l.focusNode,l.focusOffset),f=a&&a.node==l.anchorNode&&a.offset==l.anchorOffset||!Et(n.contentDOM,l.anchorNode)?n.state.selection.main.anchor:n.docView.posFromDOM(l.anchorNode,l.anchorOffset);(c!=o.head||f!=o.anchor)&&(r=m.single(f,c))}if(!s&&!r)return!1;if(!s&&i&&!o.empty&&r&&r.main.empty?s={from:o.from,to:o.to,insert:n.state.doc.slice(o.from,o.to)}:s&&s.from>=o.from&&s.to<=o.to&&(s.from!=o.from||s.to!=o.to)&&o.to-o.from-(s.to-s.from)<=4?s={from:o.from,to:o.to,insert:n.state.doc.slice(o.from,s.from).append(s.insert).append(n.state.doc.slice(s.to,o.to))}:(A.mac||A.android)&&s&&s.from==s.to&&s.from==o.head-1&&s.insert.toString()=="."&&(s={from:o.from,to:o.to,insert:N.of([" "])}),s){let l=n.state;if(A.ios&&n.inputState.flushIOSKey(n)||A.android&&(s.from==o.from&&s.to==o.to&&s.insert.length==1&&s.insert.lines==2&&ni(n.contentDOM,"Enter",13)||s.from==o.from-1&&s.to==o.to&&s.insert.length==0&&ni(n.contentDOM,"Backspace",8)||s.from==o.from&&s.to==o.to+1&&s.insert.length==0&&ni(n.contentDOM,"Delete",46)))return!0;let h=s.insert.toString();if(n.state.facet(Ll).some(f=>f(n,s.from,s.to,h)))return!0;n.inputState.composing>=0&&n.inputState.composing++;let a;if(s.from>=o.from&&s.to<=o.to&&s.to-s.from>=(o.to-o.from)/3&&(!r||r.main.empty&&r.main.from==s.from+s.insert.length)&&n.inputState.composing<0){let f=o.from<s.from?l.sliceDoc(o.from,s.from):"",u=o.to>s.to?l.sliceDoc(s.to,o.to):"";a=l.replaceSelection(n.state.toText(f+s.insert.sliceString(0,void 0,n.state.lineBreak)+u))}else{let f=l.changes(s),u=r&&!l.selection.main.eq(r.main)&&r.main.to<=f.newLength?r.main:void 0;if(l.selection.ranges.length>1&&n.inputState.composing>=0&&s.to<=o.to&&s.to>=o.to-10){let d=n.state.sliceDoc(s.from,s.to),p=ql(n)||n.state.doc.lineAt(o.head),g=o.to-s.to,y=o.to-o.from;a=l.changeByRange(b=>{if(b.from==o.from&&b.to==o.to)return{changes:f,range:u||b.map(f)};let S=b.to-g,v=S-d.length;if(b.to-b.from!=y||n.state.sliceDoc(v,S)!=d||p&&b.to>=p.from&&b.from<=p.to)return{range:b};let k=l.changes({from:v,to:S,insert:s.insert}),C=b.to-o.to;return{changes:k,range:u?m.range(Math.max(0,u.anchor+C),Math.max(0,u.head+C)):b.map(k)}})}else a={changes:f,selection:u&&l.selection.replaceRange(u)}}let c="input.type";return n.composing&&(c+=".compose",n.inputState.compositionFirstChange&&(c+=".start",n.inputState.compositionFirstChange=!1)),n.dispatch(a,{scrollIntoView:!0,userEvent:c}),!0}else if(r&&!r.main.eq(o)){let l=!1,h="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),h=n.inputState.lastSelectionOrigin),n.dispatch({selection:r,scrollIntoView:l,userEvent:h}),!0}else return!1}function lf(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 h=Math.max(0,r-Math.min(o,l));t-=o+h-r}return o<r&&n.length<e.length?(r-=t<=r&&t>=o?r-t:0,l=r+(l-o),o=r):l<r&&(r-=t<=r&&t>=l?r-t:0,o=r+(o-l),l=r),{from:r,toA:o,toB:l}}function hf(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 Vr(t,i)),(s!=t||r!=i)&&e.push(new Vr(s,r))),e}function af(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?m.single(t+e,i+e):null}class O{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.style.cssText="position: absolute; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),this._dispatch=e.dispatch||(t=>this.update([t])),this.dispatch=this.dispatch.bind(this),this._root=e.root||ic(e.parent)||document,this.viewState=new to(e.state||I.create(e)),this.plugins=this.state.facet(Yt).map(t=>new Rn(t));for(let t of this.plugins)t.update(this);this.observer=new sf(this,(t,i,s)=>of(this,t,i,s),t=>{this.inputState.runScrollHandlers(this,t),this.observer.intersecting&&this.measure()}),this.inputState=new Bc(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new Fr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}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}dispatch(...e){this._dispatch(e.length==1&&e[0]instanceof Q?e[0]:this.state.update(...e))}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 l of e){if(l.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=l.state}if(this.destroyed){this.viewState.state=r;return}if(this.observer.clear(),r.facet(I.phrases)!=this.state.facet(I.phrases))return this.setState(r);s=Yi.create(this,r,e);let o=this.viewState.scrollTarget;try{this.updateState=2;for(let l of e){if(o&&(o=o.map(l.changes)),l.scrollIntoView){let{main:h}=l.state.selection;o=new Xi(h.empty?h:m.cursor(h.head,h.head>h.anchor?-1:1))}for(let h of l.effects)h.is(Ir)&&(o=h.value)}this.viewState.update(s,o),this.bidiCache=_i.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(_t)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(l=>l.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Oi)!=s.state.facet(Oi)&&(this.viewState.mustMeasureContent=!0),(t||i||o||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!s.empty)for(let l of this.state.facet(ms))l(s)}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 to(e),this.plugins=e.facet(Yt).map(i=>new Rn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new Fr(this),this.inputState.ensureHandlers(this,this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Yt),i=e.state.facet(Yt);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new Rn(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(),this.inputState.ensureHandlers(this,this.plugins)}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this)}measure(e=!0){if(this.destroyed)return;this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,{scrollHeight:i,scrollTop:s,clientHeight:r}=this.scrollDOM,o=s>i-r-4?i:s;try{for(let l=0;;l++){this.updateState=1;let h=this.viewport,a=this.viewState.lineBlockAtHeight(o),c=this.viewState.measure(this);if(!c&&!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 f=[];c&4||([this.measureRequests,f]=[f,this.measureRequests]);let u=f.map(y=>{try{return y.read(this)}catch(b){return Ee(this.state,b),oo}}),d=Yi.create(this,this.state,[]),p=!1,g=!1;d.flags|=c,t?t.flags|=c:t=d,this.updateState=2,d.empty||(this.updatePlugins(d),this.inputState.update(d),this.updateAttrs(),p=this.docView.update(d));for(let y=0;y<f.length;y++)if(u[y]!=oo)try{let b=f[y];b.write&&b.write(u[y],this)}catch(b){Ee(this.state,b)}if(this.viewState.scrollTarget)this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,g=!0;else{let y=this.viewState.lineBlockAt(a.from).top-a.top;(y>1||y<-1)&&(this.scrollDOM.scrollTop+=y,g=!0)}if(p&&this.docView.updateSelection(!0),this.viewport.from==h.from&&this.viewport.to==h.to&&!g&&this.measureRequests.length==0)break}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(ms))l(t)}get themeClasses(){return vs+" "+(this.state.facet(Ss)?Zl:Ql)+" "+this.state.facet(Oi)}updateAttrs(){let e=lo(this,El,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(wn)?"true":"false",class:"cm-content",style:`${A.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),lo(this,Il,t);let i=this.observer.ignore(()=>{let s=ps(this.contentDOM,this.contentAttrs,t),r=ps(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(O.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(_t),ot.mount(this.root,this.styleModules.concat(tf).reverse())}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(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}}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 In(this,e,jr(this,e,t,i))}moveByGroup(e,t){return In(this,e,jr(this,e,t,i=>Oc(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return Dc(this,e,t,i)}moveVertically(e,t,i){return In(this,e,Tc(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(),jl(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[Lt.find(r,e-s.from,-1,t)];return mn(i,o.dir==X.LTR==t>0)}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(Rl)||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>cf)return Wl(e.length);let t=this.textDirectionAt(e.from);for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t)return s.order;let i=dc(e.text,t);return this.bidiCache.push(new _i(e.from,e.to,t,i)),i}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||A.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{gl(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Ir.of(new Xi(typeof e=="number"?m.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return de.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=ot.newName(),s=[Oi.of(i),_t.of(Cs(`.${i}`,e))];return t&&t.dark&&s.push(Ss.of(!0)),s}static baseTheme(e){return St.lowest(_t.of(Cs("."+vs,e,eh)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&H.get(i)||H.get(e);return((t=s==null?void 0:s.rootView)===null||t===void 0?void 0:t.view)||null}}O.styleModule=_t;O.inputHandler=Ll;O.perLineTextDirection=Rl;O.exceptionSink=Pl;O.updateListener=ms;O.editable=wn;O.mouseSelectionStyle=Bl;O.dragMovesSelection=Tl;O.clickAddsSelectionRange=Ol;O.decorations=ui;O.atomicRanges=Nl;O.scrollMargins=Vl;O.darkTheme=Ss;O.contentAttributes=Il;O.editorAttributes=El;O.lineWrapping=O.contentAttributes.of({class:"cm-lineWrapping"});O.announce=R.define();const cf=4096,oo={};class _i{constructor(e,t,i,s){this.from=e,this.to=t,this.dir=i,this.order=s}static update(e,t){if(t.empty)return e;let i=[],s=e.length?e[e.length-1].dir:X.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 _i(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.order))}return i}}function lo(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&&ds(o,t)}return t}const ff=A.mac?"mac":A.windows?"win":A.linux?"linux":"key";function uf(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let h=0;h<t.length-1;++h){const a=t[h];if(/^(cmd|meta|m)$/i.test(a))l=!0;else if(/^a(lt)?$/i.test(a))s=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))o=!0;else if(/^mod$/i.test(a))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Ti(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 df=St.default(O.domEventHandlers({keydown(n,e){return ih(th(e.state),n,e,"editor")}})),Js=D.define({enables:df}),ho=new WeakMap;function th(n){let e=n.facet(Js),t=ho.get(e);return t||ho.set(e,t=mf(e.reduce((i,s)=>i.concat(s),[]))),t}function pf(n,e,t){return ih(th(n.state),e,n,t)}let Ze=null;const gf=4e3;function mf(n,e=ff){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let h=i[o];if(h==null)i[o]=l;else if(h!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,h,a)=>{let c=t[o]||(t[o]=Object.create(null)),f=l.split(/ (?!$)/).map(p=>uf(p,e));for(let p=1;p<f.length;p++){let g=f.slice(0,p).join(" ");s(g,!0),c[g]||(c[g]={preventDefault:!0,commands:[y=>{let b=Ze={view:y,prefix:g,scope:o};return setTimeout(()=>{Ze==b&&(Ze=null)},gf),!0}]})}let u=f.join(" ");s(u,!1);let d=c[u]||(c[u]={preventDefault:!1,commands:[]});d.commands.push(h),a&&(d.preventDefault=!0)};for(let o of n){let l=o[e]||o.key;if(!!l)for(let h of o.scope?o.scope.split(" "):["editor"])r(h,l,o.run,o.preventDefault),o.shift&&r(h,"Shift-"+l,o.shift,o.preventDefault)}return t}function ih(n,e,t,i){let s=_a(e),r=ie(s,0),o=ve(r)==s.length&&s!=" ",l="",h=!1;Ze&&Ze.view==t&&Ze.scope==i&&(l=Ze.prefix+" ",(h=Ul.indexOf(e.keyCode)<0)&&(Ze=null));let a=d=>{if(d){for(let p of d.commands)if(p(t))return!0;d.preventDefault&&(h=!0)}return!1},c=n[i],f,u;if(c){if(a(c[l+Ti(s,e,!o)]))return!0;if(o&&(e.shiftKey||e.altKey||e.metaKey||r>127)&&(f=lt[e.keyCode])&&f!=s){if(a(c[l+Ti(f,e,!0)]))return!0;if(e.shiftKey&&(u=ai[e.keyCode])!=s&&u!=f&&a(c[l+Ti(u,e,!1)]))return!0}else if(o&&e.shiftKey&&a(c[l+Ti(s,e,!0)]))return!0}return h}const nh=!A.ios,Zt=D.define({combine(n){return Ct(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function og(n={}){return[Zt.of(n),yf,bf]}class sh{constructor(e,t,i,s,r){this.left=e,this.top=t,this.width=i,this.height=s,this.className=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width>=0&&(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}}const yf=de.fromClass(class{constructor(n){this.view=n,this.rangePieces=[],this.cursors=[],this.measureReq={read:this.readPos.bind(this),write:this.drawSel.bind(this)},this.selectionLayer=n.scrollDOM.appendChild(document.createElement("div")),this.selectionLayer.className="cm-selectionLayer",this.selectionLayer.setAttribute("aria-hidden","true"),this.cursorLayer=n.scrollDOM.appendChild(document.createElement("div")),this.cursorLayer.className="cm-cursorLayer",this.cursorLayer.setAttribute("aria-hidden","true"),n.requestMeasure(this.measureReq),this.setBlinkRate()}setBlinkRate(){this.cursorLayer.style.animationDuration=this.view.state.facet(Zt).cursorBlinkRate+"ms"}update(n){let e=n.startState.facet(Zt)!=n.state.facet(Zt);(e||n.selectionSet||n.geometryChanged||n.viewportChanged)&&this.view.requestMeasure(this.measureReq),n.transactions.some(t=>t.scrollIntoView)&&(this.cursorLayer.style.animationName=this.cursorLayer.style.animationName=="cm-blink"?"cm-blink2":"cm-blink"),e&&this.setBlinkRate()}readPos(){let{state:n}=this.view,e=n.facet(Zt),t=n.selection.ranges.map(s=>s.empty?[]:wf(this.view,s)).reduce((s,r)=>s.concat(r)),i=[];for(let s of n.selection.ranges){let r=s==n.selection.main;if(s.empty?!r||nh:e.drawRangeCursor){let o=xf(this.view,s,r);o&&i.push(o)}}return{rangePieces:t,cursors:i}}drawSel({rangePieces:n,cursors:e}){if(n.length!=this.rangePieces.length||n.some((t,i)=>!t.eq(this.rangePieces[i]))){this.selectionLayer.textContent="";for(let t of n)this.selectionLayer.appendChild(t.draw());this.rangePieces=n}if(e.length!=this.cursors.length||e.some((t,i)=>!t.eq(this.cursors[i]))){let t=this.cursorLayer.children;if(t.length!==e.length){this.cursorLayer.textContent="";for(const i of e)this.cursorLayer.appendChild(i.draw())}else e.forEach((i,s)=>i.adjust(t[s]));this.cursors=e}}destroy(){this.selectionLayer.remove(),this.cursorLayer.remove()}}),rh={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};nh&&(rh[".cm-line"].caretColor="transparent !important");const bf=St.highest(O.theme(rh));function oh(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==X.LTR?e.left:e.right-n.scrollDOM.clientWidth)-n.scrollDOM.scrollLeft,top:e.top-n.scrollDOM.scrollTop}}function ao(n,e,t){let i=m.cursor(e);return{from:Math.max(t.from,n.moveToLineBoundary(i,!1,!0).from),to:Math.min(t.to,n.moveToLineBoundary(i,!0,!0).from),type:z.Text}}function co(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==z.Text))return i}return t}function wf(n,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let t=Math.max(e.from,n.viewport.from),i=Math.min(e.to,n.viewport.to),s=n.textDirection==X.LTR,r=n.contentDOM,o=r.getBoundingClientRect(),l=oh(n),h=window.getComputedStyle(r.firstChild),a=o.left+parseInt(h.paddingLeft)+Math.min(0,parseInt(h.textIndent)),c=o.right-parseInt(h.paddingRight),f=co(n,t),u=co(n,i),d=f.type==z.Text?f:null,p=u.type==z.Text?u:null;if(n.lineWrapping&&(d&&(d=ao(n,t,d)),p&&(p=ao(n,i,p))),d&&p&&d.from==p.from)return y(b(e.from,e.to,d));{let v=d?b(e.from,null,d):S(f,!1),k=p?b(null,e.to,p):S(u,!0),C=[];return(d||f).to<(p||u).from-1?C.push(g(a,v.bottom,c,k.top)):v.bottom<k.top&&n.elementAtHeight((v.bottom+k.top)/2).type==z.Text&&(v.bottom=k.top=(v.bottom+k.top)/2),y(v).concat(C).concat(y(k))}function g(v,k,C,M){return new sh(v-l.left,k-l.top-.01,C-v,M-k+.01,"cm-selectionBackground")}function y({top:v,bottom:k,horizontal:C}){let M=[];for(let B=0;B<C.length;B+=2)M.push(g(C[B],v,C[B+1],k));return M}function b(v,k,C){let M=1e9,B=-1e9,K=[];function E(U,Y,xe,se,ce){let Le=n.coordsAtPos(U,U==C.to?-2:2),ee=n.coordsAtPos(xe,xe==C.from?2:-2);M=Math.min(Le.top,ee.top,M),B=Math.max(Le.bottom,ee.bottom,B),ce==X.LTR?K.push(s&&Y?a:Le.left,s&&se?c:ee.right):K.push(!s&&se?a:ee.left,!s&&Y?c:Le.right)}let P=v!=null?v:C.from,V=k!=null?k:C.to;for(let U of n.visibleRanges)if(U.to>P&&U.from<V)for(let Y=Math.max(U.from,P),xe=Math.min(U.to,V);;){let se=n.state.doc.lineAt(Y);for(let ce of n.bidiSpans(se)){let Le=ce.from+se.from,ee=ce.to+se.from;if(Le>=xe)break;ee>Y&&E(Math.max(Le,Y),v==null&&Le<=P,Math.min(ee,xe),k==null&&ee>=V,ce.dir)}if(Y=se.to+1,Y>=xe)break}return K.length==0&&E(P,v==null,V,k==null,n.textDirection),{top:M,bottom:B,horizontal:K}}function S(v,k){let C=o.top+(k?v.top:v.bottom);return{top:C,bottom:C,horizontal:[]}}}function xf(n,e,t){let i=n.coordsAtPos(e.head,e.assoc||1);if(!i)return null;let s=oh(n);return new sh(i.left-s.left,i.top-s.top,-1,i.bottom-i.top,t?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary")}const lh=R.define({map(n,e){return n==null?null:e.mapPos(n)}}),ei=me.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(lh)?i.value:t,n)}}),kf=de.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(ei);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(ei)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let n=this.view.state.field(ei),e=n!=null&&this.view.coordsAtPos(n);if(!e)return null;let t=this.view.scrollDOM.getBoundingClientRect();return{left:e.left-t.left+this.view.scrollDOM.scrollLeft,top:e.top-t.top+this.view.scrollDOM.scrollTop,height:e.bottom-e.top}}drawCursor(n){this.cursor&&(n?(this.cursor.style.left=n.left+"px",this.cursor.style.top=n.top+"px",this.cursor.style.height=n.height+"px"):this.cursor.style.left="-100000px")}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(ei)!=n&&this.view.dispatch({effects:lh.of(n)})}},{eventHandlers:{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 lg(){return[ei,kf]}function fo(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 Sf(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 vf{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,h,a,c)=>s(c,a,a+l[0].length,l,h);else if(i){let l=typeof i=="function"?i:()=>i;this.addMatch=(h,a,c,f)=>f(c,c+h[0].length,l(h,a,c))}else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new bt,i=t.add.bind(t);for(let{from:s,to:r}of Sf(e,this.maxLength))fo(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,h)=>{h>e.view.viewport.from&&l<e.view.viewport.to&&(i=Math.min(l,i),s=Math.max(h,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 h=e.state.doc.lineAt(o),a=h.to<l?e.state.doc.lineAt(l):h,c=Math.max(r.from,h.from),f=Math.min(r.to,a.to);if(this.boundary){for(;o>h.from;o--)if(this.boundary.test(h.text[o-1-h.from])){c=o;break}for(;l<a.to;l++)if(this.boundary.test(a.text[l-a.from])){f=l;break}}let u=[],d,p=(g,y,b)=>u.push(b.range(g,y));if(h==a)for(this.regexp.lastIndex=c-h.from;(d=this.regexp.exec(h.text))&&d.index<f-h.from;)this.addMatch(d,e,d.index+h.from,p);else fo(e.state.doc,this.regexp,c,f,(g,y)=>this.addMatch(y,e,g,p));t=t.update({filterFrom:c,filterTo:f,filter:(g,y)=>g<c||y>f,add:u})}}return t}}const As=/x/.unicode!=null?"gu":"g",Cf=new RegExp(`[\0-\b
-\x7F-\x9F\xAD\u061C\u200B\u200E\u200F\u2028\u2029\u202D\u202E\u2066\u2067\u2069\uFEFF\uFFF9-\uFFFC]`,As),Af={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 Fn=null;function Mf(){var n;if(Fn==null&&typeof document<"u"&&document.body){let e=document.body.style;Fn=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return Fn||!1}const qi=D.define({combine(n){let e=Ct(n,{render:null,specialChars:Cf,addSpecialChars:null});return(e.replaceTabs=!Mf())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,As)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,As)),e}});function hg(n={}){return[qi.of(n),Df()]}let uo=null;function Df(){return uo||(uo=de.fromClass(class{constructor(n){this.view=n,this.decorations=T.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(qi)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new vf({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=ie(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,h=yi(o.text,l,i-o.from);return T.replace({widget:new Pf((l-h%l)*this.view.defaultCharacterWidth)})}return this.decorationCache[r]||(this.decorationCache[r]=T.replace({widget:new Bf(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(qi);n.startState.facet(qi)!=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 Of="\u2022";function Tf(n){return n>=32?Of:n==10?"\u2424":String.fromCharCode(9216+n)}class Bf extends at{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=Tf(this.code),i=e.state.phrase("Control character")+" "+(Af[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 Pf extends at{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}}class Lf extends at{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}ignoreEvent(){return!1}}function ag(n){return de.fromClass(class{constructor(e){this.view=e,this.placeholder=T.set([T.widget({widget:new Lf(n),side:1}).range(0)])}get decorations(){return this.view.state.doc.length?T.none:this.placeholder}},{decorations:e=>e.decorations})}const Ms=2e3;function Rf(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>Ms||t.off>Ms||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let h=i;h<=s;h++){let a=n.doc.line(h);a.length<=l&&r.push(m.range(a.from+o,a.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let h=i;h<=s;h++){let a=n.doc.line(h),c=rs(a.text,o,n.tabSize,!0);if(c>-1){let f=rs(a.text,l,n.tabSize);r.push(m.range(a.from+c,a.from+f))}}}return r}function Ef(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function po(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>Ms?-1:s==i.length?Ef(n,e.clientX):yi(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function If(n,e){let t=po(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=po(n,s);if(!l)return i;let h=Rf(n.state,t,l);return h.length?o?m.create(h.concat(i.ranges)):m.create(h):i}}:null}function cg(n){let e=(n==null?void 0:n.eventFilter)||(t=>t.altKey&&t.button==0);return O.mouseSelectionStyle.of((t,i)=>e(i)?If(t,i):null)}const Wn="-10000px";class Nf{constructor(e,t,i){this.facet=t,this.createTooltipView=i,this.input=e.state.facet(t),this.tooltips=this.input.filter(s=>s),this.tooltipViews=this.tooltips.map(i)}update(e){let t=e.state.facet(this.facet),i=t.filter(r=>r);if(t===this.input){for(let r of this.tooltipViews)r.update&&r.update(e);return!1}let s=[];for(let r=0;r<i.length;r++){let o=i[r],l=-1;if(!!o){for(let h=0;h<this.tooltips.length;h++){let a=this.tooltips[h];a&&a.create==o.create&&(l=h)}if(l<0)s[r]=this.createTooltipView(o);else{let h=s[r]=this.tooltipViews[l];h.update&&h.update(e)}}}for(let r of this.tooltipViews)s.indexOf(r)<0&&r.dom.remove();return this.input=t,this.tooltips=i,this.tooltipViews=s,!0}}function Vf(){return{top:0,left:0,bottom:innerHeight,right:innerWidth}}const Hn=D.define({combine:n=>{var e,t,i;return{position:A.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)||Vf}}}),hh=de.fromClass(class{constructor(n){this.view=n,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Hn);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.manager=new Nf(n,ah,t=>this.createTooltip(t)),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);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Hn);if(i.position!=this.position){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){let e=n.create(this.view);if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",e.dom.appendChild(t)}return e.dom.style.position=this.position,e.dom.style.top=Wn,this.container.appendChild(e.dom),e.mount&&e.mount(this.view),e}destroy(){var n;this.view.win.removeEventListener("resize",this.measureSoon);for(let{dom:e}of this.manager.tooltipViews)e.remove();(n=this.intersectionObserver)===null||n===void 0||n.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect();return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((e,t)=>{let i=this.manager.tooltipViews[t];return i.getCoords?i.getCoords(e.pos):this.view.coordsAtPos(e.pos)}),size:this.manager.tooltipViews.map(({dom:e})=>e.getBoundingClientRect()),space:this.view.state.facet(Hn).tooltipSpace(this.view)}}writeMeasure(n){let{editor:e,space:t}=n,i=[];for(let s=0;s<this.manager.tooltips.length;s++){let r=this.manager.tooltips[s],o=this.manager.tooltipViews[s],{dom:l}=o,h=n.pos[s],a=n.size[s];if(!h||h.bottom<=Math.max(e.top,t.top)||h.top>=Math.min(e.bottom,t.bottom)||h.right<Math.max(e.left,t.left)-.1||h.left>Math.min(e.right,t.right)+.1){l.style.top=Wn;continue}let c=r.arrow?o.dom.querySelector(".cm-tooltip-arrow"):null,f=c?7:0,u=a.right-a.left,d=a.bottom-a.top,p=o.offset||Wf,g=this.view.textDirection==X.LTR,y=a.width>t.right-t.left?g?t.left:t.right-a.width:g?Math.min(h.left-(c?14:0)+p.x,t.right-u):Math.max(t.left,h.left-u+(c?14:0)-p.x),b=!!r.above;!r.strictSide&&(b?h.top-(a.bottom-a.top)-p.y<t.top:h.bottom+(a.bottom-a.top)+p.y>t.bottom)&&b==t.bottom-h.bottom>h.top-t.top&&(b=!b);let S=b?h.top-d-f-p.y:h.bottom+f+p.y,v=y+u;if(o.overlap!==!0)for(let k of i)k.left<v&&k.right>y&&k.top<S+d&&k.bottom>S&&(S=b?k.top-d-2-f:k.bottom+f+2);this.position=="absolute"?(l.style.top=S-n.parent.top+"px",l.style.left=y-n.parent.left+"px"):(l.style.top=S+"px",l.style.left=y+"px"),c&&(c.style.left=`${h.left+(g?p.x:-p.x)-(y+14-7)}px`),o.overlap!==!0&&i.push({left:y,top:S,right:v,bottom:S+d}),l.classList.toggle("cm-tooltip-above",b),l.classList.toggle("cm-tooltip-below",!b),o.positioned&&o.positioned()}}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=Wn}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),Ff=O.baseTheme({".cm-tooltip":{zIndex:100},"&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:`${7}px`,width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:`${7}px solid transparent`,borderRight:`${7}px solid transparent`},".cm-tooltip-above &":{bottom:`-${7}px`,"&:before":{borderTop:`${7}px solid #bbb`},"&:after":{borderTop:`${7}px solid #f5f5f5`,bottom:"1px"}},".cm-tooltip-below &":{top:`-${7}px`,"&:before":{borderBottom:`${7}px solid #bbb`},"&:after":{borderBottom:`${7}px solid #f5f5f5`,top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),Wf={x:0,y:0},ah=D.define({enables:[hh,Ff]});function Hf(n,e){let t=n.plugin(hh);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const go=D.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 Qi(n,e){let t=n.plugin(ch),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const ch=de.fromClass(class{constructor(n){this.input=n.state.facet(Zi),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(go);this.top=new Bi(n,!0,e.topContainer),this.bottom=new Bi(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(go);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Bi(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Bi(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(Zi);if(t!=this.input){let i=t.filter(h=>h),s=[],r=[],o=[],l=[];for(let h of i){let a=this.specs.indexOf(h),c;a<0?(c=h(n.view),l.push(c)):(c=this.panels[a],c.update&&c.update(n)),s.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let h of l)h.dom.classList.add("cm-panel"),h.mount&&h.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>O.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Bi{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=mo(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=mo(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 mo(n){let e=n.nextSibling;return n.remove(),e}const Zi=D.define({enables:ch});class xt extends yt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}xt.prototype.elementClass="";xt.prototype.toDOM=void 0;xt.prototype.mapMode=le.TrackBefore;xt.prototype.startSide=xt.prototype.endSide=-1;xt.prototype.point=!0;const zf=D.define(),qf=new class extends xt{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},$f=zf.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges)if(i.empty){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(qf.range(s)))}return $.of(e)});function fg(){return $f}const jf=1024;let Kf=0;class Me{constructor(e,t){this.from=e,this.to=t}}class L{constructor(e={}){this.id=Kf++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=pe.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}L.closedBy=new L({deserialize:n=>n.split(" ")});L.openedBy=new L({deserialize:n=>n.split(" ")});L.group=new L({deserialize:n=>n.split(" ")});L.contextHash=new L({perNode:!0});L.lookAhead=new L({perNode:!0});L.mounted=new L({perNode:!0});class Uf{constructor(e,t,i){this.tree=e,this.overlay=t,this.parser=i}}const Gf=Object.create(null);class pe{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Gf,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new pe(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(L.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(L.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}}pe.none=new pe("",Object.create(null),0,8);class Xs{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let s=null;for(let r of e){let o=r(i);o&&(s||(s=Object.assign({},i.props)),s[o[0].id]=o[1])}t.push(s?new pe(i.name,s,i.id,i.flags):i)}return new Xs(t)}}const Pi=new WeakMap,yo=new WeakMap;var G;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays"})(G||(G={}));class F{constructor(e,t,i,s,r){if(this.type=e,this.children=t,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=this.prop(L.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let s=i.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new di(this.topNode,e)}cursorAt(e,t=0,i=0){let s=Pi.get(this)||this.topNode,r=new di(s);return r.moveTo(e,t),Pi.set(this,r._tree),r}get topNode(){return new Te(this,0,0,null)}resolve(e,t=0){let i=Vt(Pi.get(this)||this.topNode,e,t,!1);return Pi.set(this,i),i}resolveInner(e,t=0){let i=Vt(yo.get(this)||this.topNode,e,t,!0);return yo.set(this,i),i}iterate(e){let{enter:t,leave:i,from:s=0,to:r=this.length}=e;for(let o=this.cursor((e.mode||0)|G.IncludeAnonymous);;){let l=!1;if(o.from<=r&&o.to>=s&&(o.type.isAnonymous||t(o)!==!1)){if(o.firstChild())continue;l=!0}for(;l&&i&&!o.type.isAnonymous&&i(o),!o.nextSibling();){if(!o.parent())return;l=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Qs(pe.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new F(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new F(pe.none,t,i,s)))}static build(e){return Xf(e)}}F.empty=new F(pe.none,[],[],0);class Ys{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new Ys(this.buffer,this.index)}}class At{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return pe.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],s=this.set.types[t],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,s,r){let{buffer:o}=this,l=-1;for(let h=e;h!=t&&!(fh(r,s,o[h+1],o[h+2])&&(l=h,i>0));h=o[h+3]);return l}slice(e,t,i,s){let r=this.buffer,o=new Uint16Array(t-e);for(let l=e,h=0;l<t;)o[h++]=r[l++],o[h++]=r[l++]-i,o[h++]=r[l++]-i,o[h++]=r[l++]-e;return new At(o,s-i,this.set)}}function fh(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function uh(n,e){let t=n.childBefore(e);for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(n=t,t=i.prevSibling):t=i}return n}function Vt(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!i&&n instanceof Te&&n.index<0?null:n.parent;if(!o)return n;n=o}let r=i?0:G.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof Te&&o.index<0&&((s=l.enter(e,t,r))===null||s===void 0?void 0:s.from)!=o.from&&(n=l);for(;;){let o=n.enter(e,t,r);if(!o)return n;n=o}}class Te{constructor(e,t,i,s){this._tree=e,this.from=t,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,s,r=0){for(let o=this;;){for(let{children:l,positions:h}=o._tree,a=t>0?l.length:-1;e!=a;e+=t){let c=l[e],f=h[e]+o.from;if(!!fh(s,i,f,f+c.length)){if(c instanceof At){if(r&G.ExcludeBuffers)continue;let u=c.findChild(0,c.buffer.length,t,i-f,s);if(u>-1)return new qe(new Jf(o,c,e,f),null,u)}else if(r&G.IncludeAnonymous||!c.type.isAnonymous||_s(c)){let u;if(!(r&G.IgnoreMounts)&&c.props&&(u=c.prop(L.mounted))&&!u.overlay)return new Te(u.tree,f,e,o);let d=new Te(c,f,e,o);return r&G.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?c.children.length-1:0,t,i,s)}}}if(r&G.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,i=0){let s;if(!(i&G.IgnoreOverlays)&&(s=this._tree.prop(L.mounted))&&s.overlay){let r=e-this.from;for(let{from:o,to:l}of s.overlay)if((t>0?o<=r:o<r)&&(t<0?l>=r:l>r))return new Te(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new di(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return Vt(this,e,t,!1)}resolveInner(e,t=0){return Vt(this,e,t,!0)}enterUnfinishedNodesBefore(e){return uh(this,e)}getChild(e,t=null,i=null){let s=en(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return en(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return tn(this,e)}}function en(n,e,t,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(;!s.type.is(t);)if(!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function tn(n,e,t=e.length-1){for(let i=n.parent;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class Jf{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}}class qe{constructor(e,t,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}child(e,t,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new qe(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,i=0){if(i&G.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new qe(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new qe(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new qe(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new di(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1],l=i.buffer[this.index+2];e.push(i.slice(s,r,o,l)),t.push(0)}return new F(this.type,e,t,this.to-this.from)}resolve(e,t=0){return Vt(this,e,t,!1)}resolveInner(e,t=0){return Vt(this,e,t,!0)}enterUnfinishedNodesBefore(e){return uh(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let s=en(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return en(this,e,t,i)}get node(){return this}matchContext(e){return tn(this,e)}}class di{constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof Te)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}get name(){return this.type.name}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof Te?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&G.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&G.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&G.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=s)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&G.IncludeAnonymous||l instanceof At||!l.type.isAnonymous||_s(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer){e:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}}for(let s=i;s<this.stack.length;s++)t=new qe(this.buffer,t,this.stack[s]);return this.bufferNode=new qe(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;s&&t&&t(this),s=this.type.isAnonymous,!this.nextSibling();){if(!i)return;this.parent(),i--,s=!0}}}matchContext(e){if(!this.buffer)return tn(this.node,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let s=e.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return tn(this.node,e,s);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}}function _s(n){return n.children.some(e=>e instanceof At||!e.type.isAnonymous||_s(e))}function Xf(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=jf,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new Ys(t,t.length):t,h=i.types,a=0,c=0;function f(k,C,M,B,K){let{id:E,start:P,end:V,size:U}=l,Y=c;for(;U<0;)if(l.next(),U==-1){let ee=r[E];M.push(ee),B.push(P-k);return}else if(U==-3){a=E;return}else if(U==-4){c=E;return}else throw new RangeError(`Unrecognized record size: ${U}`);let xe=h[E],se,ce,Le=P-k;if(V-P<=s&&(ce=g(l.pos-C,K))){let ee=new Uint16Array(ce.size-ce.skip),Re=l.pos-ce.size,Je=ee.length;for(;l.pos>Re;)Je=y(ce.start,ee,Je);se=new At(ee,V-ce.start,i),Le=ce.start-k}else{let ee=l.pos-U;l.next();let Re=[],Je=[],ft=E>=o?E:-1,Mt=0,ki=V;for(;l.pos>ee;)ft>=0&&l.id==ft&&l.size>=0?(l.end<=ki-s&&(d(Re,Je,P,Mt,l.end,ki,ft,Y),Mt=Re.length,ki=l.end),l.next()):f(P,ee,Re,Je,ft);if(ft>=0&&Mt>0&&Mt<Re.length&&d(Re,Je,P,Mt,P,ki,ft,Y),Re.reverse(),Je.reverse(),ft>-1&&Mt>0){let mr=u(xe);se=Qs(xe,Re,Je,0,Re.length,0,V-P,mr,mr)}else se=p(xe,Re,Je,V-P,Y-V)}M.push(se),B.push(Le)}function u(k){return(C,M,B)=>{let K=0,E=C.length-1,P,V;if(E>=0&&(P=C[E])instanceof F){if(!E&&P.type==k&&P.length==B)return P;(V=P.prop(L.lookAhead))&&(K=M[E]+P.length+V)}return p(k,C,M,B,K)}}function d(k,C,M,B,K,E,P,V){let U=[],Y=[];for(;k.length>B;)U.push(k.pop()),Y.push(C.pop()+M-K);k.push(p(i.types[P],U,Y,E-K,V-E)),C.push(K-M)}function p(k,C,M,B,K=0,E){if(a){let P=[L.contextHash,a];E=E?[P].concat(E):[P]}if(K>25){let P=[L.lookAhead,K];E=E?[P].concat(E):[P]}return new F(k,C,M,B,E)}function g(k,C){let M=l.fork(),B=0,K=0,E=0,P=M.end-s,V={size:0,start:0,skip:0};e:for(let U=M.pos-k;M.pos>U;){let Y=M.size;if(M.id==C&&Y>=0){V.size=B,V.start=K,V.skip=E,E+=4,B+=4,M.next();continue}let xe=M.pos-Y;if(Y<0||xe<U||M.start<P)break;let se=M.id>=o?4:0,ce=M.start;for(M.next();M.pos>xe;){if(M.size<0)if(M.size==-3)se+=4;else break e;else M.id>=o&&(se+=4);M.next()}K=ce,B+=Y,E+=se}return(C<0||B==k)&&(V.size=B,V.start=K,V.skip=E),V.size>4?V:void 0}function y(k,C,M){let{id:B,start:K,end:E,size:P}=l;if(l.next(),P>=0&&B<o){let V=M;if(P>4){let U=l.pos-(P-4);for(;l.pos>U;)M=y(k,C,M)}C[--M]=V,C[--M]=E-k,C[--M]=K-k,C[--M]=B}else P==-3?a=B:P==-4&&(c=B);return M}let b=[],S=[];for(;l.pos>0;)f(n.start||0,n.bufferStart||0,b,S,-1);let v=(e=n.length)!==null&&e!==void 0?e:b.length?S[0]+b[0].length:0;return new F(h[n.topID],b.reverse(),S.reverse(),v)}const bo=new WeakMap;function $i(n,e){if(!n.isAnonymous||e instanceof At||e.type!=n)return 1;let t=bo.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof F)){t=1;break}t+=$i(n,i)}bo.set(e,t)}return t}function Qs(n,e,t,i,s,r,o,l,h){let a=0;for(let p=i;p<s;p++)a+=$i(n,e[p]);let c=Math.ceil(a*1.5/8),f=[],u=[];function d(p,g,y,b,S){for(let v=y;v<b;){let k=v,C=g[v],M=$i(n,p[v]);for(v++;v<b;v++){let B=$i(n,p[v]);if(M+B>=c)break;M+=B}if(v==k+1){if(M>c){let B=p[k];d(B.children,B.positions,0,B.children.length,g[k]+S);continue}f.push(p[k])}else{let B=g[v-1]+p[v-1].length-C;f.push(Qs(n,p,g,k,v,C,B,null,h))}u.push(C+S-r)}}return d(e,t,i,s,0),(l||h)(f,u,o)}class ug{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let s=this.map.get(e);s||this.map.set(e,s=new Map),s.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof qe?this.setBuffer(e.context.buffer,e.index,t):e instanceof Te&&this.map.set(e.tree,t)}get(e){return e instanceof qe?this.getBuffer(e.context.buffer,e.index):e instanceof Te?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Ye{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new Ye(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,h=0,a=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-h>=i)for(;o&&o.from<f;){let u=o;if(h>=u.from||f<=u.to||a){let d=Math.max(u.from,h)-a,p=Math.min(u.to,f)-a;u=d>=p?null:new Ye(d,p,u.tree,u.offset+a,l>0,!!c)}if(u&&s.push(u),o.to>f)break;o=r<e.length?e[r++]:null}if(!c)break;h=c.toA,a=c.toA-c.toB}return s}}class dh{startParse(e,t,i){return typeof e=="string"&&(e=new Yf(e)),i=i?i.length?i.map(s=>new Me(s.from,s.to)):[new Me(0,0)]:[new Me(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}}class Yf{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function dg(n){return(e,t,i,s)=>new Qf(e,n,t,i,s)}class wo{constructor(e,t,i,s,r){this.parser=e,this.parse=t,this.overlay=i,this.target=s,this.ranges=r}}class _f{constructor(e,t,i,s,r,o,l){this.parser=e,this.predicate=t,this.mounts=i,this.index=s,this.start=r,this.target=o,this.prev=l,this.depth=0,this.ranges=[]}}const Ds=new L({perNode:!0});class Qf{constructor(e,t,i,s,r){this.nest=t,this.input=i,this.fragments=s,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let s of this.inner)s.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new F(i.type,i.children,i.positions,i.length,i.propValues.concat([[Ds,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[L.mounted.id]=new Uf(t,e.overlay,e.parser),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].ranges[0].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new tu(this.fragments),t=null,i=null,s=new di(new Te(this.baseTree,this.ranges[0].from,0,null),G.IncludeAnonymous|G.IgnoreMounts);e:for(let r,o;this.stoppedAt==null||s.from<this.stoppedAt;){let l=!0,h;if(e.hasNode(s)){if(t){let a=t.mounts.find(c=>c.frag.from<=s.from&&c.frag.to>=s.to&&c.mount.overlay);if(a)for(let c of a.mount.overlay){let f=c.from+a.pos,u=c.to+a.pos;f>=s.from&&u<=s.to&&!t.ranges.some(d=>d.from<u&&d.to>f)&&t.ranges.push({from:f,to:u})}}l=!1}else if(i&&(o=Zf(i.ranges,s.from,s.to)))l=o!=2;else if(!s.type.isAnonymous&&s.from<s.to&&(r=this.nest(s,this.input))){s.tree||eu(s);let a=e.findMounts(s.from,r.parser);if(typeof r.overlay=="function")t=new _f(r.parser,r.overlay,a,this.inner.length,s.from,s.tree,t);else{let c=So(this.ranges,r.overlay||[new Me(s.from,s.to)]);c.length&&this.inner.push(new wo(r.parser,r.parser.startParse(this.input,vo(a,c),c),r.overlay?r.overlay.map(f=>new Me(f.from-s.from,f.to-s.from)):null,s.tree,c)),r.overlay?c.length&&(i={ranges:c,depth:0,prev:i}):l=!1}}else t&&(h=t.predicate(s))&&(h===!0&&(h=new Me(s.from,s.to)),h.from<h.to&&t.ranges.push(h));if(l&&s.firstChild())t&&t.depth++,i&&i.depth++;else for(;!s.nextSibling();){if(!s.parent())break e;if(t&&!--t.depth){let a=So(this.ranges,t.ranges);a.length&&this.inner.splice(t.index,0,new wo(t.parser,t.parser.startParse(this.input,vo(t.mounts,a),a),t.ranges.map(c=>new Me(c.from-t.start,c.to-t.start)),t.target,a)),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function Zf(n,e,t){for(let i of n){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function xo(n,e,t,i,s,r){if(e<t){let o=n.buffer[e+1],l=n.buffer[t-2];i.push(n.slice(e,t,o,l)),s.push(o-r)}}function eu(n){let{node:e}=n,t=0;do n.parent(),t++;while(!n.tree);let i=0,s=n.tree,r=0;for(;r=s.positions[i]+n.from,!(r<=e.from&&r+s.children[i].length>=e.to);i++);let o=s.children[i],l=o.buffer;function h(a,c,f,u,d){let p=a;for(;l[p+2]+r<=e.from;)p=l[p+3];let g=[],y=[];xo(o,a,p,g,y,u);let b=l[p+1],S=l[p+2],v=b+r==e.from&&S+r==e.to&&l[p]==e.type.id;return g.push(v?e.toTree():h(p+4,l[p+3],o.set.types[l[p]],b,S-b)),y.push(b-u),xo(o,l[p+3],c,g,y,u),new F(f,g,y,d)}s.children[i]=h(0,l.length,pe.none,0,o.length);for(let a=0;a<=t;a++)n.childAfter(e.from)}class ko{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(G.IncludeAnonymous|G.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,G.IgnoreOverlays|G.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof F)t=t.children[0];else break}return!1}}class tu{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(Ds))!==null&&t!==void 0?t:i.to,this.inner=new ko(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Ds))!==null&&e!==void 0?e:t.to,this.inner=new ko(t.tree,-t.offset)}}findMounts(e,t){var i;let s=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let o=(i=r.tree)===null||i===void 0?void 0:i.prop(L.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let h=this.fragments[l];if(h.from>=r.to)break;h.tree==this.curFrag.tree&&s.push({frag:h,pos:r.from-h.offset,mount:o})}}}return s}}function So(n,e){let t=null,i=e;for(let s=1,r=0;s<n.length;s++){let o=n[s-1].to,l=n[s].from;for(;r<i.length;r++){let h=i[r];if(h.from>=l)break;h.to<=o||(t||(i=t=e.slice()),h.from<o?(t[r]=new Me(h.from,o),h.to>l&&t.splice(r+1,0,new Me(l,h.to))):h.to>l?t[r--]=new Me(l,h.to):t.splice(r--,1))}}return i}function iu(n,e,t,i){let s=0,r=0,o=!1,l=!1,h=-1e9,a=[];for(;;){let c=s==n.length?1e9:o?n[s].to:n[s].from,f=r==e.length?1e9:l?e[r].to:e[r].from;if(o!=l){let u=Math.max(h,t),d=Math.min(c,f,i);u<d&&a.push(new Me(u,d))}if(h=Math.min(c,f),h==1e9)break;c==h&&(o?(o=!1,s++):o=!0),f==h&&(l?(l=!1,r++):l=!0)}return a}function vo(n,e){let t=[];for(let{pos:i,mount:s,frag:r}of n){let o=i+(s.overlay?s.overlay[0].from:0),l=o+s.tree.length,h=Math.max(r.from,o),a=Math.min(r.to,l);if(s.overlay){let c=s.overlay.map(u=>new Me(u.from+i,u.to+i)),f=iu(e,c,h,a);for(let u=0,d=h;;u++){let p=u==f.length,g=p?a:f[u].from;if(g>d&&t.push(new Ye(d,g,s.tree,-o,r.from>=d||r.openStart,r.to<=g||r.openEnd)),p)break;d=f[u].to}}else t.push(new Ye(h,a,s.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return t}let nu=0;class He{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=nu++}static define(e){if(e!=null&&e.base)throw new Error("Can not derive from a modified tag");let t=new He([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new nn;return t=>t.modified.indexOf(e)>-1?t:nn.get(t.base||t,t.modified.concat(e).sort((i,s)=>i.id-s.id))}}let su=0;class nn{constructor(){this.instances=[],this.id=su++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&ru(t,l.modified));if(i)return i;let s=[],r=new He(s,e,t);for(let l of t)l.instances.push(r);let o=ph(t);for(let l of e.set)for(let h of o)s.push(nn.get(l,h));return r}}function ru(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function ph(n){let e=[n];for(let t=0;t<n.length;t++)for(let i of ph(n.slice(0,t).concat(n.slice(t+1))))e.push(i);return e}function ou(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let f=0;;){if(l=="..."&&f>0&&f+3==s.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+s);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==s.length)break;let d=s[f++];if(f==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(f)}let h=r.length-1,a=r[h];if(!a)throw new RangeError("Invalid path: "+s);let c=new lu(i,o,h>0?r.slice(0,h):null);e[a]=c.sort(e[a])}}return gh.add(e)}const gh=new L;class lu{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}function mh(n,e){let t=Object.create(null);for(let r of n)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:s=null}=e||{};return{style:r=>{let o=s;for(let l of r)for(let h of l.set){let a=t[h.id];if(a){o=o?o+" "+a:a;break}}return o},scope:i}}function hu(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function au(n,e,t,i=0,s=n.length){let r=new cu(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}class cu{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,s,r){let{type:o,from:l,to:h}=e;if(l>=i||h<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let a=s,c=o.prop(gh),f=!1;for(;c;){if(!c.context||e.matchContext(c.context)){let d=hu(r,c.tags);d&&(a&&(a+=" "),a+=d,c.mode==1?s+=(s?" ":"")+d:c.mode==0&&(f=!0));break}c=c.next}if(this.startSpan(e.from,a),f)return;let u=e.tree&&e.tree.prop(L.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(y=>!y.scope||y.scope(u.tree.type)),g=e.firstChild();for(let y=0,b=l;;y++){let S=y<u.overlay.length?u.overlay[y]:null,v=S?S.from+l:h,k=Math.max(t,b),C=Math.min(i,v);if(k<C&&g)for(;e.from<C&&(this.highlightRange(e,k,C,s,r),this.startSpan(Math.min(i,e.to),a),!(e.to>=v||!e.nextSibling())););if(!S||v>i)break;b=S.to+l,b>t&&(this.highlightRange(d.cursor(),Math.max(t,S.from+l),Math.min(i,b),s,p),this.startSpan(b,a))}g&&e.parent()}else if(e.firstChild()){do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),a)}while(e.nextSibling());e.parent()}}}const w=He.define,Li=w(),_e=w(),Co=w(_e),Ao=w(_e),Qe=w(),Ri=w(Qe),zn=w(Qe),We=w(),ut=w(We),Ve=w(),Fe=w(),Os=w(),Gt=w(Os),Ei=w(),x={comment:Li,lineComment:w(Li),blockComment:w(Li),docComment:w(Li),name:_e,variableName:w(_e),typeName:Co,tagName:w(Co),propertyName:Ao,attributeName:w(Ao),className:w(_e),labelName:w(_e),namespace:w(_e),macroName:w(_e),literal:Qe,string:Ri,docString:w(Ri),character:w(Ri),attributeValue:w(Ri),number:zn,integer:w(zn),float:w(zn),bool:w(Qe),regexp:w(Qe),escape:w(Qe),color:w(Qe),url:w(Qe),keyword:Ve,self:w(Ve),null:w(Ve),atom:w(Ve),unit:w(Ve),modifier:w(Ve),operatorKeyword:w(Ve),controlKeyword:w(Ve),definitionKeyword:w(Ve),moduleKeyword:w(Ve),operator:Fe,derefOperator:w(Fe),arithmeticOperator:w(Fe),logicOperator:w(Fe),bitwiseOperator:w(Fe),compareOperator:w(Fe),updateOperator:w(Fe),definitionOperator:w(Fe),typeOperator:w(Fe),controlOperator:w(Fe),punctuation:Os,separator:w(Os),bracket:Gt,angleBracket:w(Gt),squareBracket:w(Gt),paren:w(Gt),brace:w(Gt),content:We,heading:ut,heading1:w(ut),heading2:w(ut),heading3:w(ut),heading4:w(ut),heading5:w(ut),heading6:w(ut),contentSeparator:w(We),list:w(We),quote:w(We),emphasis:w(We),strong:w(We),link:w(We),monospace:w(We),strikethrough:w(We),inserted:w(),deleted:w(),changed:w(),invalid:w(),meta:Ei,documentMeta:w(Ei),annotation:w(Ei),processingInstruction:w(Ei),definition:He.defineModifier(),constant:He.defineModifier(),function:He.defineModifier(),standard:He.defineModifier(),local:He.defineModifier(),special:He.defineModifier()};mh([{tag:x.link,class:"tok-link"},{tag:x.heading,class:"tok-heading"},{tag:x.emphasis,class:"tok-emphasis"},{tag:x.strong,class:"tok-strong"},{tag:x.keyword,class:"tok-keyword"},{tag:x.atom,class:"tok-atom"},{tag:x.bool,class:"tok-bool"},{tag:x.url,class:"tok-url"},{tag:x.labelName,class:"tok-labelName"},{tag:x.inserted,class:"tok-inserted"},{tag:x.deleted,class:"tok-deleted"},{tag:x.literal,class:"tok-literal"},{tag:x.string,class:"tok-string"},{tag:x.number,class:"tok-number"},{tag:[x.regexp,x.escape,x.special(x.string)],class:"tok-string2"},{tag:x.variableName,class:"tok-variableName"},{tag:x.local(x.variableName),class:"tok-variableName tok-local"},{tag:x.definition(x.variableName),class:"tok-variableName tok-definition"},{tag:x.special(x.variableName),class:"tok-variableName2"},{tag:x.definition(x.propertyName),class:"tok-propertyName tok-definition"},{tag:x.typeName,class:"tok-typeName"},{tag:x.namespace,class:"tok-namespace"},{tag:x.className,class:"tok-className"},{tag:x.macroName,class:"tok-macroName"},{tag:x.propertyName,class:"tok-propertyName"},{tag:x.operator,class:"tok-operator"},{tag:x.comment,class:"tok-comment"},{tag:x.meta,class:"tok-meta"},{tag:x.invalid,class:"tok-invalid"},{tag:x.punctuation,class:"tok-punctuation"}]);var qn;const Ft=new L;function yh(n){return D.define({combine:n?e=>e.concat(n):void 0})}class De{constructor(e,t,i=[]){this.data=e,I.prototype.hasOwnProperty("tree")||Object.defineProperty(I.prototype,"tree",{get(){return ge(this)}}),this.parser=t,this.extension=[zt.of(this),I.languageData.of((s,r,o)=>s.facet(Mo(s,r,o)))].concat(i)}isActiveAt(e,t,i=-1){return Mo(e,t,i)==this.data}findRegions(e){let t=e.facet(zt);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(Ft)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(L.mounted);if(l){if(l.tree.prop(Ft)==this.data){if(l.overlay)for(let h of l.overlay)i.push({from:h.from+o,to:h.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let h=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>h)return}}for(let h=0;h<r.children.length;h++){let a=r.children[h];a instanceof F&&s(a,r.positions[h]+o)}};return s(ge(e),0),i}get allowsNesting(){return!0}}De.setState=R.define();function Mo(n,e,t){let i=n.facet(zt);if(!i)return null;let s=i.data;if(i.allowsNesting)for(let r=ge(n).topNode;r;r=r.enter(e,t,G.ExcludeBuffers))s=r.type.prop(Ft)||s;return s}class Ts extends De{constructor(e,t){super(e,t),this.parser=t}static define(e){let t=yh(e.languageData);return new Ts(t,e.parser.configure({props:[Ft.add(i=>i.isTop?t:void 0)]}))}configure(e){return new Ts(this.data,this.parser.configure(e))}get allowsNesting(){return this.parser.hasWrappers()}}function ge(n){let e=n.field(De.state,!1);return e?e.tree:F.empty}class fu{constructor(e,t=e.length){this.doc=e,this.length=t,this.cursorPos=0,this.string="",this.cursor=e.iter()}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 Jt=null;class Wt{constructor(e,t,i=[],s,r,o,l,h){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=h,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Wt(e,t,[],F.empty,0,i,[],null)}startParse(){return this.parser.startParse(new fu(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=F.empty&&this.isDone(t!=null?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(Ye.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!=null?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(Ye.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Jt;Jt=this;try{return e()}finally{Jt=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Do(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 h=[];if(e.iterChangedRanges((a,c,f,u)=>h.push({fromA:a,toA:c,fromB:f,toB:u})),i=Ye.applyChanges(i,h),s=F.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let a of this.skipped){let c=e.mapPos(a.from,1),f=e.mapPos(a.to,-1);c<f&&l.push({from:c,to:f})}}}return new Wt(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=Do(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 dh{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let h=Jt;if(h){for(let a of s)h.tempSkipped.push(a);e&&(h.scheduleOn=h.scheduleOn?Promise.all([h.scheduleOn,e]):e)}return this.parsedPos=o,new F(pe.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 Jt}}function Do(n,e,t){return Ye.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class Ht{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 Ht(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Wt.create(e.facet(zt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Ht(i)}}De.state=me.define({create:Ht.init,update(n,e){for(let t of e.effects)if(t.is(De.setState))return t.value;return e.startState.facet(zt)!=e.state.facet(zt)?Ht.init(e.state):n.apply(e)}});let bh=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(bh=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const $n=typeof navigator<"u"&&((qn=navigator.scheduling)===null||qn===void 0?void 0:qn.isInputPending)?()=>navigator.scheduling.isInputPending():null,uu=de.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(De.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),e.docChanged&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(De.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=bh(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(De.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!$n?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,h=r.context.work(()=>$n&&$n()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(h||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:De.setState.of(new Ht(r.context))})),this.chunkBudget>0&&!(h&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Ee(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()}}}),zt=D.define({combine(n){return n.length?n[0]:null},enables:[De.state,uu]});class gg{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const wh=D.define(),xn=D.define({combine:n=>{if(!n.length)return" ";if(!/^(?: +|\t+)$/.test(n[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return n[0]}});function kt(n){let e=n.facet(xn);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function sn(n,e){let t="",i=n.tabSize;if(n.facet(xn).charCodeAt(0)==9)for(;e>=i;)t+=" ",e-=i;for(let s=0;s<e;s++)t+=" ";return t}function xh(n,e){n instanceof I&&(n=new kn(n));for(let i of n.state.facet(wh)){let s=i(n,e);if(s!=null)return s}let t=ge(n.state);return t?pu(n,t,e):null}class kn{constructor(e,t={}){this.state=e,this.options=t,this.unit=kt(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 yi(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 du=new L;function pu(n,e,t){return kh(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,n)}function gu(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function mu(n){let e=n.type.prop(du);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(L.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>Sh(o,!0,1,void 0,r&&!gu(o)?s.from:void 0)}return n.parent==null?yu:null}function kh(n,e,t){for(;n;n=n.parent){let i=mu(n);if(i)return i(Zs.create(t,e,n))}return null}function yu(){return 0}class Zs extends kn{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.node=i}static create(e,t,i){return new Zs(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){let e=this.state.doc.lineAt(this.node.from);for(;;){let t=this.node.resolve(e.from);for(;t.parent&&t.parent.from==t.from;)t=t.parent;if(bu(t,this.node))break;e=this.state.doc.lineAt(t.from)}return this.lineIndent(e.from)}continue(){let e=this.node.parent;return e?kh(e,this.pos,this.base):0}}function bu(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function wu(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 h=e.childAfter(l);if(!h||h==i)return null;if(!h.type.isSkipped)return h.from<o?t:null;l=h.to}}function mg({closing:n,align:e=!0,units:t=1}){return i=>Sh(i,e,t,n)}function Sh(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,h=e?wu(n):null;return h?l?n.column(h.from):n.column(h.to):n.baseIndent+(l?0:n.unit*t)}const yg=n=>n.baseIndent;function bg({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const wg=new L;function xg(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}class Sn{constructor(e,t){let i;function s(l){let h=ot.newName();return(i||(i=Object.create(null)))["."+h]=l,h}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof De?l=>l.prop(Ft)==o.data:o?l=>l==o:void 0,this.style=mh(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ot(i):null,this.themeType=t.themeType}static define(e,t){return new Sn(e,t||{})}}const Bs=D.define(),vh=D.define({combine(n){return n.length?[n[0]]:null}});function jn(n){let e=n.facet(Bs);return e.length?e:n.facet(vh)}function kg(n,e){let t=[ku],i;return n instanceof Sn&&(n.module&&t.push(O.styleModule.of(n.module)),i=n.themeType),e!=null&&e.fallback?t.push(vh.of(n)):i?t.push(Bs.computeN([O.darkTheme],s=>s.facet(O.darkTheme)==(i=="dark")?[n]:[])):t.push(Bs.of(n)),t}class xu{constructor(e){this.markCache=Object.create(null),this.tree=ge(e.state),this.decorations=this.buildDeco(e,jn(e.state))}update(e){let t=ge(e.state),i=jn(e.state),s=i!=jn(e.startState);t.length<e.view.viewport.to&&!s&&t.type==this.tree.type?this.decorations=this.decorations.map(e.changes):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i))}buildDeco(e,t){if(!t||!this.tree.length)return T.none;let i=new bt;for(let{from:s,to:r}of e.visibleRanges)au(this.tree,t,(o,l,h)=>{i.add(o,l,this.markCache[h]||(this.markCache[h]=T.mark({class:h})))},s,r);return i.finish()}}const ku=St.high(de.fromClass(xu,{decorations:n=>n.decorations})),Sg=Sn.define([{tag:x.meta,color:"#7a757a"},{tag:x.link,textDecoration:"underline"},{tag:x.heading,textDecoration:"underline",fontWeight:"bold"},{tag:x.emphasis,fontStyle:"italic"},{tag:x.strong,fontWeight:"bold"},{tag:x.strikethrough,textDecoration:"line-through"},{tag:x.keyword,color:"#708"},{tag:[x.atom,x.bool,x.url,x.contentSeparator,x.labelName],color:"#219"},{tag:[x.literal,x.inserted],color:"#164"},{tag:[x.string,x.deleted],color:"#a11"},{tag:[x.regexp,x.escape,x.special(x.string)],color:"#e40"},{tag:x.definition(x.variableName),color:"#00f"},{tag:x.local(x.variableName),color:"#30a"},{tag:[x.typeName,x.namespace],color:"#085"},{tag:x.className,color:"#167"},{tag:[x.special(x.variableName),x.macroName],color:"#256"},{tag:x.definition(x.propertyName),color:"#00c"},{tag:x.comment,color:"#940"},{tag:x.invalid,color:"#f00"}]),Su=O.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ch=1e4,Ah="()[]{}",Mh=D.define({combine(n){return Ct(n,{afterCursor:!0,brackets:Ah,maxScanDistance:Ch,renderMatch:Au})}}),vu=T.mark({class:"cm-matchingBracket"}),Cu=T.mark({class:"cm-nonmatchingBracket"});function Au(n){let e=[],t=n.matched?vu:Cu;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 Mu=me.define({create(){return T.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(Mh);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=$e(e.state,s.head,-1,i)||s.head>0&&$e(e.state,s.head-1,1,i)||i.afterCursor&&($e(e.state,s.head,1,i)||s.head<e.state.doc.length&&$e(e.state,s.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e.state)))}return T.set(t,!0)},provide:n=>O.decorations.from(n)}),Du=[Mu,Su];function vg(n={}){return[Mh.of(n),Du]}function Ps(n,e,t){let i=n.prop(e<0?L.openedBy:L.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 $e(n,e,t,i={}){let s=i.maxScanDistance||Ch,r=i.brackets||Ah,o=ge(n),l=o.resolveInner(e,t);for(let h=l;h;h=h.parent){let a=Ps(h.type,t,r);if(a&&h.from<h.to)return Ou(n,e,t,h,a,r)}return Tu(n,e,t,o,l.type,s,r)}function Ou(n,e,t,i,s,r){let o=i.parent,l={from:i.from,to:i.to},h=0,a=o==null?void 0:o.cursor();if(a&&(t<0?a.childBefore(i.from):a.childAfter(i.to)))do if(t<0?a.to<=i.from:a.from>=i.to){if(h==0&&s.indexOf(a.type.name)>-1&&a.from<a.to)return{start:l,end:{from:a.from,to:a.to},matched:!0};if(Ps(a.type,t,r))h++;else if(Ps(a.type,-t,r)){if(h==0)return{start:l,end:a.from==a.to?void 0:{from:a.from,to:a.to},matched:!1};h--}}while(t<0?a.prevSibling():a.nextSibling());return{start:l,matched:!1}}function Tu(n,e,t,i,s,r,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),h=o.indexOf(l);if(h<0||h%2==0!=t>0)return null;let a={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=r;){let d=c.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:a,end:{from:p+g,to:p+g+1},matched:b>>1==h>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:a,matched:!1}:null}function Oo(n,e,t,i=0,s=0){e==null&&(e=n.search(/[^\s\u00a0]/),e==-1&&(e=n.length));let r=s;for(let o=i;o<e;o++)n.charCodeAt(o)==9?r+=t-r%t:r++;return r}class Dh{constructor(e,t,i){this.string=e,this.tabSize=t,this.indentUnit=i,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),i;if(typeof e=="string"?i=t==e:i=t&&(e instanceof RegExp?e.test(t):e(t)),i)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=Oo(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){return Oo(this.string,null,this.tabSize)}match(e,t,i){if(typeof e=="string"){let s=o=>i?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return s(r)==s(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let s=this.string.slice(this.pos).match(e);return s&&s.index>0?null:(s&&t!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}}function Bu(n){return{token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||Pu,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||tr}}function Pu(n){if(typeof n!="object")return n;let e={};for(let t in n){let i=n[t];e[t]=i instanceof Array?i.slice():i}return e}class Oh extends De{constructor(e){let t=yh(e.languageData),i=Bu(e),s,r=new class extends dh{createParse(o,l,h){return new Ru(s,o,l,h)}};super(t,r,[wh.of((o,l)=>this.getIndent(o,l))]),this.topNode=Nu(t),s=this,this.streamParser=i,this.stateAfter=new L({perNode:!0}),this.tokenTable=e.tokenTable?new Lh(i.tokenTable):Iu}static define(e){return new Oh(e)}getIndent(e,t){let i=ge(e.state),s=i.resolve(t);for(;s&&s.type!=this.topNode;)s=s.parent;if(!s)return null;let r=er(this,i,0,s.from,t),o,l;if(r?(l=r.state,o=r.pos+1):(l=this.streamParser.startState(e.unit),o=0),t-o>1e4)return null;for(;o<t;){let a=e.state.doc.lineAt(o),c=Math.min(t,a.to);if(a.length){let f=new Dh(a.text,e.state.tabSize,e.unit);for(;f.pos<c-a.from;)Bh(this.streamParser.token,f,l)}else this.streamParser.blankLine(l,e.unit);if(c==t)break;o=a.to+1}let{text:h}=e.lineAt(t);return this.streamParser.indent(l,/^\s*(.*)/.exec(h)[1],e)}get allowsNesting(){return!1}}function er(n,e,t,i,s){let r=t>=i&&t+e.length<=s&&e.prop(n.stateAfter);if(r)return{state:n.streamParser.copyState(r),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],h=t+e.positions[o],a=l instanceof F&&h<s&&er(n,l,h,i,s);if(a)return a}return null}function Th(n,e,t,i,s){if(s&&t<=0&&i>=e.length)return e;!s&&e.type==n.topNode&&(s=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],h;if(o<i&&l instanceof F){if(!(h=Th(n,l,t-o,i-o,s)))break;return s?new F(e.type,e.children.slice(0,r).concat(h),e.positions.slice(0,r+1),o+h.length):h}}return null}function Lu(n,e,t,i){for(let s of e){let r=s.from+(s.openStart?25:0),o=s.to-(s.openEnd?25:0),l=r<=t&&o>t&&er(n,s.tree,0-s.offset,t,o),h;if(l&&(h=Th(n,s.tree,t+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:h}}return{state:n.streamParser.startState(i?kt(i):4),tree:F.empty}}class Ru{constructor(e,t,i,s){this.lang=e,this.input=t,this.fragments=i,this.ranges=s,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=s[s.length-1].to;let r=Wt.get(),o=s[0].from,{state:l,tree:h}=Lu(e,i,o,r==null?void 0:r.state);this.state=l,this.parsedPos=this.chunkStart=o+h.length;for(let a=0;a<h.children.length;a++)this.chunks.push(h.children[a]),this.chunkPos.push(h.positions[a]);r&&this.parsedPos<r.viewport.from-1e5&&(this.state=this.lang.streamParser.startState(kt(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=Wt.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(t,this.chunkStart+2048);for(e&&(i=Math.min(i,e.viewport.to));this.parsedPos<i;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
`&&(t="");else{let i=t.indexOf(`
`);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let s=this.rangeIndex;;){let r=this.ranges[s].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let s=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?s>r:s>=r)break;t+=this.ranges[++this.rangeIndex].from-s}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,i,s,r){if(this.ranges.length>1){r=this.skipGapsTo(t,r,1),t+=r;let o=this.chunk.length;r=this.skipGapsTo(i,r,-1),i+=r,s+=this.chunk.length-o}return this.chunk.push(e,t,i,s),r}parseLine(e){let{line:t,end:i}=this.nextLine(),s=0,{streamParser:r}=this.lang,o=new Dh(t,e?e.state.tabSize:4,e?kt(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=Bh(r.token,o,this.state);if(l&&(s=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,4,s)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=F.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Eu,topID:0,maxBufferLength:2048,reused:this.chunkReused});e=new F(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new F(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function Bh(n,e,t){e.start=e.pos;for(let i=0;i<10;i++){let s=n(e,t);if(e.pos>e.start)return s}throw new Error("Stream parser failed to advance stream.")}const tr=Object.create(null),pi=[pe.none],Eu=new Xs(pi),To=[],Ph=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"]])Ph[n]=Rh(tr,e);class Lh{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),Ph)}resolve(e){return e?this.table[e]||(this.table[e]=Rh(this.extra,e)):0}}const Iu=new Lh(tr);function Kn(n,e){To.indexOf(n)>-1||(To.push(n),console.warn(e))}function Rh(n,e){let t=null;for(let r of e.split(".")){let o=n[r]||x[r];o?typeof o=="function"?t?t=o(t):Kn(r,`Modifier ${r} used at start of tag`):t?Kn(r,`Tag ${r} used as modifier`):t=o:Kn(r,`Unknown highlighting tag ${r}`)}if(!t)return 0;let i=e.replace(/ /g,"_"),s=pe.define({id:pi.length,name:i,props:[ou({[i]:t})]});return pi.push(s),s.id}function Nu(n){let e=pe.define({id:pi.length,name:"Document",props:[Ft.add(()=>n)]});return pi.push(e),e}const Vu=n=>{let e=nr(n.state);return e.line?Fu(n):e.block?Hu(n):!1};function ir(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 Fu=ir($u,0),Wu=ir(Eh,0),Hu=ir((n,e)=>Eh(n,e,qu(e)),0);function nr(n,e=n.selection.main.head){let t=n.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const Xt=50;function zu(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-Xt,i),o=n.sliceDoc(s,s+Xt),l=/\s*$/.exec(r)[0].length,h=/^\s*/.exec(o)[0].length,a=r.length-l;if(r.slice(a-e.length,a)==e&&o.slice(h,h+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+h,margin:h&&1}};let c,f;s-i<=2*Xt?c=f=n.sliceDoc(i,s):(c=n.sliceDoc(i,i+Xt),f=n.sliceDoc(s-Xt,s));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function qu(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),r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from,to:s.to})}return e}function Eh(n,e,t=e.selection.ranges){let i=t.map(r=>nr(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>zu(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 h=i[o],{open:a,close:c}=l;r.push({from:a.pos-h.open.length,to:a.pos+a.margin},{from:c.pos-c.margin,to:c.pos+h.close.length})}return{changes:r}}return null}function $u(n,e,t=e.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of t){let l=i.length,h=1e9;for(let a=r;a<=o;){let c=e.doc.lineAt(a);if(c.from>s&&(r==o||o>c.from)){s=c.from;let f=nr(e,a).line;if(!f)continue;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+f.length)==f?u:-1;u<c.text.length&&u<h&&(h=u),i.push({line:c,comment:p,token:f,indent:u,empty:d,single:!1})}a=c.to+1}if(h<1e9)for(let a=l;a<i.length;a++)i[a].indent<i[a].line.text.length&&(i[a].indent=h);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:h,indent:a,empty:c,single:f}of i)(f||!c)&&r.push({from:l.from+a,insert:h+" "});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:h}of i)if(l>=0){let a=o.from+l,c=a+h.length;o.text[c-o.from]==" "&&c++,r.push({from:a,to:c})}return{changes:r}}return null}const Ls=vt.define(),ju=vt.define(),Ku=D.define(),Ih=D.define({combine(n){return Ct(n,{minDepth:100,newGroupDelay:500},{minDepth:Math.max,newGroupDelay:Math.min})}});function Uu(n){let e=0;return n.iterChangedRanges((t,i)=>e=i),e}const Nh=me.define({create(){return je.empty},update(n,e){let t=e.state.facet(Ih),i=e.annotation(Ls);if(i){let h=e.docChanged?m.single(Uu(e.changes)):void 0,a=be.fromTransaction(e,h),c=i.side,f=c==0?n.undone:n.done;return a?f=rn(f,f.length,t.minDepth,a):f=Wh(f,e.startState.selection),new je(c==0?i.rest:f,c==0?f:i.rest)}let s=e.annotation(ju);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(Q.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=be.fromTransaction(e),o=e.annotation(Q.time),l=e.annotation(Q.userEvent);return r?n=n.addChanges(r,o,l,t.newGroupDelay,t.minDepth):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 je(n.done.map(be.fromJSON),n.undone.map(be.fromJSON))}});function Cg(n={}){return[Nh,Ih.of(n),O.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?Vh:e.inputType=="historyRedo"?Rs:null;return i?(e.preventDefault(),i(t)):!1}})]}function vn(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(Nh,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}const Vh=vn(0,!1),Rs=vn(1,!1),Gu=vn(0,!0),Ju=vn(1,!0);class be{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 be(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 be(e.changes&&_.fromJSON(e.changes),[],e.mapped&&Ke.fromJSON(e.mapped),e.startSelection&&m.fromJSON(e.startSelection),e.selectionsAfter.map(m.fromJSON))}static fromTransaction(e,t){let i=Oe;for(let s of e.startState.facet(Ku)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new be(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Oe)}static selection(e){return new be(void 0,Oe,void 0,void 0,e)}}function rn(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 Xu(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let h=0;h<t.length;){let a=t[h++],c=t[h++];l>=a&&o<=c&&(i=!0)}}),i}function Yu(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function Fh(n,e){return n.length?e.length?n.concat(e):n:e}const Oe=[],_u=200;function Wh(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-_u));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),rn(n,n.length-1,1e9,t.setSelAfter(i)))}else return[be.selection([e])]}function Qu(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 Un(n,e){if(!n.length)return n;let t=n.length,i=Oe;for(;t;){let s=Zu(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?[be.selection(i)]:Oe}function Zu(n,e,t){let i=Fh(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Oe,t);if(!n.changes)return be.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new be(s,R.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}const ed=/^(input\.type|delete)($|\.)/;class je{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 je(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||ed.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<s&&Xu(l.changes,e.changes)||i=="input.type.compose")?o=rn(o,o.length-1,r,new be(e.changes.compose(l.changes),Fh(e.effects,l.effects),l.mapped,l.startSelection,Oe)):o=rn(o,o.length,r,e),new je(o,Oe,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Oe;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Yu(r[r.length-1],e)?this:new je(Wh(this.done,e),this.undone,t,i)}addMapping(e){return new je(Un(this.done,e),Un(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];if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Ls.of({side:e,rest:Qu(s)}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let o=s.length==1?Oe:s.slice(0,s.length-1);return r.mapped&&(o=Un(o,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Ls.of({side:e,rest:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}je.empty=new je(Oe,Oe);const Ag=[{key:"Mod-z",run:Vh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Rs,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Rs,preventDefault:!0},{key:"Mod-u",run:Gu,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Ju,preventDefault:!0}];function $t(n,e){return m.create(n.ranges.map(e),n.mainIndex)}function Ge(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Ie({state:n,dispatch:e},t){let i=$t(n.selection,t);return i.eq(n.selection)?!1:(e(Ge(n,i)),!0)}function Cn(n,e){return m.cursor(e?n.to:n.from)}function Hh(n,e){return Ie(n,t=>t.empty?n.moveByChar(t,e):Cn(t,e))}function ae(n){return n.textDirectionAt(n.state.selection.main.head)==X.LTR}const zh=n=>Hh(n,!ae(n)),qh=n=>Hh(n,ae(n));function $h(n,e){return Ie(n,t=>t.empty?n.moveByGroup(t,e):Cn(t,e))}const td=n=>$h(n,!ae(n)),id=n=>$h(n,ae(n));function nd(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 An(n,e,t){let i=ge(n).resolveInner(e.head),s=t?L.closedBy:L.openedBy;for(let h=e.head;;){let a=t?i.childAfter(h):i.childBefore(h);if(!a)break;nd(n,a,s)?i=a:h=t?a.to:a.from}let r=i.type.prop(s),o,l;return r&&(o=t?$e(n,i.from,1):$e(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,m.cursor(l,t?-1:1)}const sd=n=>Ie(n,e=>An(n.state,e,!ae(n))),rd=n=>Ie(n,e=>An(n.state,e,ae(n)));function jh(n,e){return Ie(n,t=>{if(!t.empty)return Cn(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const Kh=n=>jh(n,!1),Uh=n=>jh(n,!0);function Gh(n){return Math.max(n.defaultLineHeight,Math.min(n.dom.clientHeight,innerHeight)-5)}function Jh(n,e){let{state:t}=n,i=$t(t.selection,l=>l.empty?n.moveVertically(l,e,Gh(n)):Cn(l,e));if(i.eq(t.selection))return!1;let s=n.coordsAtPos(t.selection.main.head),r=n.scrollDOM.getBoundingClientRect(),o;return s&&s.top>r.top&&s.bottom<r.bottom&&s.top-r.top<=n.scrollDOM.scrollHeight-n.scrollDOM.scrollTop-n.scrollDOM.clientHeight&&(o=O.scrollIntoView(i.main.head,{y:"start",yMargin:s.top-r.top})),n.dispatch(Ge(t,i),{effects:o}),!0}const Bo=n=>Jh(n,!1),Es=n=>Jh(n,!0);function ct(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=m.cursor(i.from+r))}return s}const od=n=>Ie(n,e=>ct(n,e,!0)),ld=n=>Ie(n,e=>ct(n,e,!1)),hd=n=>Ie(n,e=>ct(n,e,!ae(n))),ad=n=>Ie(n,e=>ct(n,e,ae(n))),cd=n=>Ie(n,e=>m.cursor(n.lineBlockAt(e.head).from,1)),fd=n=>Ie(n,e=>m.cursor(n.lineBlockAt(e.head).to,-1));function ud(n,e,t){let i=!1,s=$t(n.selection,r=>{let o=$e(n,r.head,-1)||$e(n,r.head,1)||r.head>0&&$e(n,r.head-1,1)||r.head<n.doc.length&&$e(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 t?m.range(r.anchor,l):m.cursor(l)});return i?(e(Ge(n,s)),!0):!1}const dd=({state:n,dispatch:e})=>ud(n,e,!1);function Pe(n,e){let t=$t(n.state.selection,i=>{let s=e(i);return m.range(i.anchor,s.head,s.goalColumn)});return t.eq(n.state.selection)?!1:(n.dispatch(Ge(n.state,t)),!0)}function Xh(n,e){return Pe(n,t=>n.moveByChar(t,e))}const Yh=n=>Xh(n,!ae(n)),_h=n=>Xh(n,ae(n));function Qh(n,e){return Pe(n,t=>n.moveByGroup(t,e))}const pd=n=>Qh(n,!ae(n)),gd=n=>Qh(n,ae(n)),md=n=>Pe(n,e=>An(n.state,e,!ae(n))),yd=n=>Pe(n,e=>An(n.state,e,ae(n)));function Zh(n,e){return Pe(n,t=>n.moveVertically(t,e))}const ea=n=>Zh(n,!1),ta=n=>Zh(n,!0);function ia(n,e){return Pe(n,t=>n.moveVertically(t,e,Gh(n)))}const Po=n=>ia(n,!1),Lo=n=>ia(n,!0),bd=n=>Pe(n,e=>ct(n,e,!0)),wd=n=>Pe(n,e=>ct(n,e,!1)),xd=n=>Pe(n,e=>ct(n,e,!ae(n))),kd=n=>Pe(n,e=>ct(n,e,ae(n))),Sd=n=>Pe(n,e=>m.cursor(n.lineBlockAt(e.head).from)),vd=n=>Pe(n,e=>m.cursor(n.lineBlockAt(e.head).to)),Ro=({state:n,dispatch:e})=>(e(Ge(n,{anchor:0})),!0),Eo=({state:n,dispatch:e})=>(e(Ge(n,{anchor:n.doc.length})),!0),Io=({state:n,dispatch:e})=>(e(Ge(n,{anchor:n.selection.main.anchor,head:0})),!0),No=({state:n,dispatch:e})=>(e(Ge(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),Cd=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Ad=({state:n,dispatch:e})=>{let t=On(n).map(({from:i,to:s})=>m.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:m.create(t),userEvent:"select"})),!0},Md=({state:n,dispatch:e})=>{let t=$t(n.selection,i=>{var s;let r=ge(n).resolveInner(i.head,1);for(;!(r.from<i.from&&r.to>=i.to||r.to>i.to&&r.from<=i.from||!(!((s=r.parent)===null||s===void 0)&&s.parent));)r=r.parent;return m.range(r.to,r.from)});return e(Ge(n,t)),!0},Dd=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=m.create([t.main]):t.main.empty||(i=m.create([m.cursor(t.main.head)])),i?(e(Ge(n,i)),!0):!1};function Mn({state:n,dispatch:e},t){if(n.readOnly)return!1;let i="delete.selection",s=n.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let h=t(o);h<o?i="delete.backward":h>o&&(i="delete.forward"),o=Math.min(o,h),l=Math.max(l,h)}return o==l?{range:r}:{changes:{from:o,to:l},range:m.cursor(o)}});return s.changes.empty?!1:(e(n.update(s,{scrollIntoView:!0,userEvent:i,effects:i=="delete.selection"?O.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function Dn(n,e,t){if(n instanceof O)for(let i of n.state.facet(O.atomicRanges).map(s=>s(n)))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}const na=(n,e)=>Mn(n,t=>{let{state:i}=n,s=i.doc.lineAt(t),r,o;if(!e&&t>s.from&&t<s.from+200&&!/[^ \t]/.test(r=s.text.slice(0,t-s.from))){if(r[r.length-1]==" ")return t-1;let l=yi(r,i.tabSize),h=l%kt(i)||kt(i);for(let a=0;a<h&&r[r.length-1-a]==" ";a++)t--;o=t}else o=fe(s.text,t-s.from,e,e)+s.from,o==t&&s.number!=(e?i.doc.lines:1)&&(o+=e?1:-1);return Dn(n,o,e)}),Is=n=>na(n,!1),sa=n=>na(n,!0),ra=(n,e)=>Mn(n,t=>{let i=t,{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&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let h=fe(r.text,i-r.from,e)+r.from,a=r.text.slice(Math.min(i,h)-r.from,Math.max(i,h)-r.from),c=o(a);if(l!=null&&c!=l)break;(a!=" "||i!=t)&&(l=c),i=h}return Dn(n,i,e)}),oa=n=>ra(n,!1),Od=n=>ra(n,!0),la=n=>Mn(n,e=>{let t=n.lineBlockAt(e).to;return Dn(n,e<t?t:Math.min(n.state.doc.length,e+1),!0)}),Td=n=>Mn(n,e=>{let t=n.lineBlockAt(e).from;return Dn(n,e>t?t:Math.max(0,e-1),!1)}),Bd=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:N.of(["",""])},range:m.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},Pd=({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:fe(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:fe(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:m.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function On(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 ha(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of On(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 h of r.ranges)s.push(m.range(Math.min(n.doc.length,h.anchor+l),Math.min(n.doc.length,h.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let h of r.ranges)s.push(m.range(h.anchor-l,h.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:m.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Ld=({state:n,dispatch:e})=>ha(n,e,!1),Rd=({state:n,dispatch:e})=>ha(n,e,!0);function aa(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of On(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 Ed=({state:n,dispatch:e})=>aa(n,e,!1),Id=({state:n,dispatch:e})=>aa(n,e,!0),Nd=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(On(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=$t(e.selection,s=>n.moveVertically(s,!0)).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Vd(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ge(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(L.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from?{from:i.to,to:s.from}:null}const Fd=ca(!1),Wd=ca(!0);function ca(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),h=!n&&r==o&&Vd(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let a=new kn(e,{simulateBreak:r,simulateDoubleBreak:!!h}),c=xh(a,r);for(c==null&&(c=/^\s*/.exec(e.doc.lineAt(r).text)[0].length);o<l.to&&/\s/.test(l.text[o-l.from]);)o++;h?{from:r,to:o}=h:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",sn(e,c)];return h&&f.push(sn(e,a.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:N.of(f)},range:m.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function sr(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:m.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Hd=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new kn(n,{overrideIndentation:r=>{let o=t[r];return o==null?-1:o}}),s=sr(n,(r,o,l)=>{let h=xh(i,r.from);if(h==null)return;/\S/.test(r.text)||(h=0);let a=/^\s*/.exec(r.text)[0],c=sn(n,h);(a!=c||l.from<r.from+a.length)&&(t[r.from]=h,o.push({from:r.from,to:r.from+a.length,insert:c}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},zd=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(sr(n,(t,i)=>{i.push({from:t.from,insert:n.facet(xn)})}),{userEvent:"input.indent"})),!0),qd=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(sr(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=yi(s,n.tabSize),o=0,l=sn(n,Math.max(0,r-kt(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),$d=[{key:"Ctrl-b",run:zh,shift:Yh,preventDefault:!0},{key:"Ctrl-f",run:qh,shift:_h},{key:"Ctrl-p",run:Kh,shift:ea},{key:"Ctrl-n",run:Uh,shift:ta},{key:"Ctrl-a",run:cd,shift:Sd},{key:"Ctrl-e",run:fd,shift:vd},{key:"Ctrl-d",run:sa},{key:"Ctrl-h",run:Is},{key:"Ctrl-k",run:la},{key:"Ctrl-Alt-h",run:oa},{key:"Ctrl-o",run:Bd},{key:"Ctrl-t",run:Pd},{key:"Ctrl-v",run:Es}],jd=[{key:"ArrowLeft",run:zh,shift:Yh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:td,shift:pd,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:hd,shift:xd,preventDefault:!0},{key:"ArrowRight",run:qh,shift:_h,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:id,shift:gd,preventDefault:!0},{mac:"Cmd-ArrowRight",run:ad,shift:kd,preventDefault:!0},{key:"ArrowUp",run:Kh,shift:ea,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ro,shift:Io},{mac:"Ctrl-ArrowUp",run:Bo,shift:Po},{key:"ArrowDown",run:Uh,shift:ta,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Eo,shift:No},{mac:"Ctrl-ArrowDown",run:Es,shift:Lo},{key:"PageUp",run:Bo,shift:Po},{key:"PageDown",run:Es,shift:Lo},{key:"Home",run:ld,shift:wd,preventDefault:!0},{key:"Mod-Home",run:Ro,shift:Io},{key:"End",run:od,shift:bd,preventDefault:!0},{key:"Mod-End",run:Eo,shift:No},{key:"Enter",run:Fd},{key:"Mod-a",run:Cd},{key:"Backspace",run:Is,shift:Is},{key:"Delete",run:sa},{key:"Mod-Backspace",mac:"Alt-Backspace",run:oa},{key:"Mod-Delete",mac:"Alt-Delete",run:Od},{mac:"Mod-Backspace",run:Td},{mac:"Mod-Delete",run:la}].concat($d.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Mg=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:sd,shift:md},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:rd,shift:yd},{key:"Alt-ArrowUp",run:Ld},{key:"Shift-Alt-ArrowUp",run:Ed},{key:"Alt-ArrowDown",run:Rd},{key:"Shift-Alt-ArrowDown",run:Id},{key:"Escape",run:Dd},{key:"Mod-Enter",run:Wd},{key:"Alt-l",mac:"Ctrl-l",run:Ad},{key:"Mod-i",run:Md,preventDefault:!0},{key:"Mod-[",run:qd},{key:"Mod-]",run:zd},{key:"Mod-Alt-\\",run:Hd},{key:"Shift-Mod-k",run:Nd},{key:"Shift-Mod-\\",run:dd},{key:"Mod-/",run:Vu},{key:"Alt-A",run:Wu}].concat(jd);function re(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var s=t[i];typeof s=="string"?n.setAttribute(i,s):s!=null&&(n[i]=s)}e++}for(;e<arguments.length;e++)fa(n,arguments[e]);return n}function fa(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)fa(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}const Vo=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class qt{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(Vo(l)):Vo,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 ie(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=Ws(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=ve(e);let s=this.normalize(t);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),h=this.match(l,o);if(h)return this.value=h,this;if(r==s.length-1)break;o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t){let i=null;for(let s=0;s<this.matches.length;s+=2){let r=this.matches[s],o=!1;this.query.charCodeAt(r)==e&&(r==this.query.length-1?i={from:this.matches[s+1],to:t+1}:(this.matches[s]++,o=!0)),o||(this.matches.splice(s,2),s-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:t+1}:this.matches.push(1,t)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferPos)&&(i=null),i}}typeof Symbol<"u"&&(qt.prototype[Symbol.iterator]=function(){return this});const ua={from:-1,to:-1,match:/.*/.exec("")},rr="gm"+(/x/.unicode==null?"":"u");class da{constructor(e,t,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=ua,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new pa(e,t,i,s,r);this.re=new RegExp(t,rr+(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=on(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=on(this.text,s+(i==s?1:0)),i==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 Gn=new WeakMap;class Rt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=Gn.get(e);if(!s||s.from>=i||s.to<=t){let l=new Rt(t,e.sliceString(t,i));return Gn.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)),Gn.set(e,new Rt(o,r)),new Rt(t,r.slice(t-o,i-o))}}class pa{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=ua,this.matchPos=on(e,s),this.re=new RegExp(t,rr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Rt.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=on(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Rt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(da.prototype[Symbol.iterator]=pa.prototype[Symbol.iterator]=function(){return this});function Kd(n){try{return new RegExp(n,rr),!0}catch{return!1}}function on(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 Ns(n){let e=re("input",{class:"cm-textfield",name:"line"}),t=re("form",{class:"cm-gotoLine",onkeydown:s=>{s.keyCode==27?(s.preventDefault(),n.dispatch({effects:ln.of(!1)}),n.focus()):s.keyCode==13&&(s.preventDefault(),i())},onsubmit:s=>{s.preventDefault(),i()}},re("label",n.state.phrase("Go to line"),": ",e)," ",re("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function i(){let s=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!s)return;let{state:r}=n,o=r.doc.lineAt(r.selection.main.head),[,l,h,a,c]=s,f=a?+a.slice(1):0,u=h?+h:o.number;if(h&&c){let p=u/100;l&&(p=p*(l=="-"?-1:1)+o.number/r.doc.lines),u=Math.round(r.doc.lines*p)}else h&&l&&(u=u*(l=="-"?-1:1)+o.number);let d=r.doc.line(Math.max(1,Math.min(r.doc.lines,u)));n.dispatch({effects:ln.of(!1),selection:m.cursor(d.from+Math.max(0,Math.min(f,d.length))),scrollIntoView:!0}),n.focus()}return{dom:t}}const ln=R.define(),Fo=me.define({create(){return!0},update(n,e){for(let t of e.effects)t.is(ln)&&(n=t.value);return n},provide:n=>Zi.from(n,e=>e?Ns:null)}),Ud=n=>{let e=Qi(n,Ns);if(!e){let t=[ln.of(!0)];n.state.field(Fo,!1)==null&&t.push(R.appendConfig.of([Fo,Gd])),n.dispatch({effects:t}),e=Qi(n,Ns)}return e&&e.dom.querySelector("input").focus(),!0},Gd=O.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Jd={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ga=D.define({combine(n){return Ct(n,Jd,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Dg(n){let e=[Zd,Qd];return n&&e.push(ga.of(n)),e}const Xd=T.mark({class:"cm-selectionMatch"}),Yd=T.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Wo(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=j.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=j.Word)}function _d(n,e,t,i){return n(e.sliceDoc(t,t+1))==j.Word&&n(e.sliceDoc(i-1,i))==j.Word}const Qd=de.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(ga),{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 h=t.wordAt(s.head);if(!h)return T.none;o=t.charCategorizer(s.head),r=t.sliceDoc(h.from,h.to)}else{let h=s.to-s.from;if(h<e.minSelectionLength||h>200)return T.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Wo(o,t,s.from,s.to)&&_d(o,t,s.from,s.to)))return T.none}else if(r=t.sliceDoc(s.from,s.to).trim(),!r)return T.none}let l=[];for(let h of n.visibleRanges){let a=new qt(t.doc,r,h.from,h.to);for(;!a.next().done;){let{from:c,to:f}=a.value;if((!o||Wo(o,t,c,f))&&(s.empty&&c<=s.from&&f>=s.to?l.push(Yd.range(c,f)):(c>=s.to||f<=s.from)&&l.push(Xd.range(c,f)),l.length>e.maxMatches))return T.none}}return T.set(l)}},{decorations:n=>n.decorations}),Zd=O.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),ep=({state:n,dispatch:e})=>{let{selection:t}=n,i=m.create(t.ranges.map(s=>n.wordAt(s.head)||m.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function tp(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 qt(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new qt(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(h=>h.from==l.value.from))continue;if(r){let h=n.wordAt(l.value.from);if(!h||h.from!=l.value.from||h.to!=l.value.to)continue}return l.value}}const ip=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return ep({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=tp(n,i);return s?(e(n.update({selection:n.selection.addRange(m.range(s.from,s.to),!1),effects:O.scrollIntoView(s.to)})),!0):!1},or=D.define({combine(n){return Ct(n,{top:!1,caseSensitive:!1,literal:!1,wholeWord:!1,createPanel:e=>new dp(e)})}});class ma{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||Kd(this.search)),this.unquoted=this.literal?this.search:this.search.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
`:i=="r"?"\r":i=="t"?" ":"\\"),this.wholeWord=!!e.wholeWord}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 op(this):new sp(this)}getCursor(e,t=0,i){let s=e.doc?e:I.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Tt(this,s,t,i):Ot(this,s,t,i)}}class ya{constructor(e){this.spec=e}}function Ot(n,e,t,i){return new qt(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?np(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function np(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(an(s,t-r))!=j.Word||e(hn(s,i-r))!=j.Word||e(hn(s,t-r))!=j.Word&&e(an(s,i-r))!=j.Word)}class sp extends ya{constructor(e){super(e)}nextMatch(e,t,i){let s=Ot(this.spec,e,i,e.doc.length).nextOverlapping();return s.done&&(s=Ot(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=Ot(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.replace}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-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 Tt(n,e,t,i){return new da(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?rp(e.charCategorizer(e.selection.main.head)):void 0},t,i)}function hn(n,e){return n.slice(fe(n,e,!1),e)}function an(n,e){return n.slice(e,fe(n,e))}function rp(n){return(e,t,i)=>!i[0].length||n(an(i.input,i.index))!=j.Word||n(hn(i.input,i.index+i[0].length))!=j.Word||n(hn(i.input,i.index))!=j.Word&&n(an(i.input,i.index+i[0].length))!=j.Word}class op extends ya{nextMatch(e,t,i){let s=Tt(this.spec,e,i,e.doc.length).next();return s.done&&(s=Tt(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=Tt(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.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=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-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const gi=R.define(),lr=R.define(),st=me.define({create(n){return new Jn(Vs(n).create(),null)},update(n,e){for(let t of e.effects)t.is(gi)?n=new Jn(t.value.create(),n.panel):t.is(lr)&&(n=new Jn(n.query,t.value?hr:null));return n},provide:n=>Zi.from(n,e=>e.panel)});class Jn{constructor(e,t){this.query=e,this.panel=t}}const lp=T.mark({class:"cm-searchMatch"}),hp=T.mark({class:"cm-searchMatch cm-searchMatch-selected"}),ap=de.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(st))}update(n){let e=n.state.field(st);(e!=n.startState.field(st)||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 bt;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:h}=r[s];for(;s<o-1&&h>r[s+1].from-2*250;)h=r[++s].to;n.highlight(t.state,l,h,(a,c)=>{let f=t.state.selection.ranges.some(u=>u.from==a&&u.to==c);i.add(a,c,f?hp:lp)})}return i.finish()}},{decorations:n=>n.decorations});function wi(n){return e=>{let t=e.state.field(st,!1);return t&&t.query.spec.valid?n(e,t):ba(e)}}const cn=wi((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);return i?(n.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:ar(n,i),userEvent:"select.search"}),!0):!1}),fn=wi((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,s=e.prevMatch(t,i,i);return s?(n.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0,effects:ar(n,s),userEvent:"select.search"}),!0):!1}),cp=wi((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:m.create(t.map(i=>m.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),fp=({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 qt(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(m.range(l.value.from,l.value.to))}return e(n.update({selection:m.create(r,o),userEvent:"select.search.matches"})),!0},Ho=wi((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,h,a=[];if(r.from==i&&r.to==s&&(h=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:h}),r=e.nextMatch(t,r.from,r.to),a.push(O.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))),r){let c=o.length==0||o[0].from>=r.to?0:r.to-r.from-h.length;l={anchor:r.from-c,head:r.to-c},a.push(ar(n,r))}return n.dispatch({changes:o,selection:l,scrollIntoView:!!l,effects:a,userEvent:"input.replace"}),!0}),up=wi((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:O.announce.of(i),userEvent:"input.replace.all"}),!0});function hr(n){return n.state.facet(or).createPanel(n)}function Vs(n,e){var t,i,s,r;let o=n.selection.main,l=o.empty||o.to>o.from+100?"":n.sliceDoc(o.from,o.to);if(e&&!l)return e;let h=n.facet(or);return new ma({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:h.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(s=e==null?void 0:e.literal)!==null&&s!==void 0?s:h.literal,wholeWord:(r=e==null?void 0:e.wholeWord)!==null&&r!==void 0?r:h.wholeWord})}const ba=n=>{let e=n.state.field(st,!1);if(e&&e.panel){let t=Qi(n,hr);if(!t)return!1;let i=t.dom.querySelector("[main-field]");if(i&&i!=n.root.activeElement){let s=Vs(n.state,e.query.spec);s.valid&&n.dispatch({effects:gi.of(s)}),i.focus(),i.select()}}else n.dispatch({effects:[lr.of(!0),e?gi.of(Vs(n.state,e.query.spec)):R.appendConfig.of(gp)]});return!0},wa=n=>{let e=n.state.field(st,!1);if(!e||!e.panel)return!1;let t=Qi(n,hr);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:lr.of(!1)}),!0},Og=[{key:"Mod-f",run:ba,scope:"editor search-panel"},{key:"F3",run:cn,shift:fn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:cn,shift:fn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:wa,scope:"editor search-panel"},{key:"Mod-Shift-l",run:fp},{key:"Alt-g",run:Ud},{key:"Mod-d",run:ip,preventDefault:!0}];class dp{constructor(e){this.view=e;let t=this.query=e.state.field(st).query.spec;this.commit=this.commit.bind(this),this.searchField=re("input",{value:t.search,placeholder:ke(e,"Find"),"aria-label":ke(e,"Find"),class:"cm-textfield",name:"search","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=re("input",{value:t.replace,placeholder:ke(e,"Replace"),"aria-label":ke(e,"Replace"),class:"cm-textfield",name:"replace",onchange:this.commit,onkeyup:this.commit}),this.caseField=re("input",{type:"checkbox",name:"case",checked:t.caseSensitive,onchange:this.commit}),this.reField=re("input",{type:"checkbox",name:"re",checked:t.regexp,onchange:this.commit}),this.wordField=re("input",{type:"checkbox",name:"word",checked:t.wholeWord,onchange:this.commit});function i(s,r,o){return re("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=re("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>cn(e),[ke(e,"next")]),i("prev",()=>fn(e),[ke(e,"previous")]),i("select",()=>cp(e),[ke(e,"all")]),re("label",null,[this.caseField,ke(e,"match case")]),re("label",null,[this.reField,ke(e,"regexp")]),re("label",null,[this.wordField,ke(e,"by word")]),...e.state.readOnly?[]:[re("br"),this.replaceField,i("replace",()=>Ho(e),[ke(e,"replace")]),i("replaceAll",()=>up(e),[ke(e,"replace all")]),re("button",{name:"close",onclick:()=>wa(e),"aria-label":ke(e,"close"),type:"button"},["\xD7"])]])}commit(){let e=new ma({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:gi.of(e)}))}keydown(e){pf(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?fn:cn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Ho(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(gi)&&!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(or).top}}function ke(n,e){return n.state.phrase(e)}const Ii=30,Ni=/[\s\.,:;?!]/;function ar(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-Ii),o=Math.min(s,t+Ii),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let h=0;h<Ii;h++)if(!Ni.test(l[h+1])&&Ni.test(l[h])){l=l.slice(h);break}}if(o!=s){for(let h=l.length-1;h>l.length-Ii;h--)if(!Ni.test(l[h-1])&&Ni.test(l[h])){l=l.slice(0,h);break}}return O.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const pp=O.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"}}),gp=[st,St.lowest(ap),pp];class xa{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=ge(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(ka(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 zo(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 mp(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=zo(e)+zo(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function yp(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:mp(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function Tg(n,e){return t=>{for(let i=ge(t.state).resolveInner(t.pos,-1);i;i=i.parent)if(n.indexOf(i.name)>-1)return null;return e(t)}}class qo{constructor(e,t,i){this.completion=e,this.source=t,this.match=i}}function rt(n){return n.selection.main.head}function ka(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":"")}function bp(n,e,t,i){return Object.assign(Object.assign({},n.changeByRange(s=>{if(s==n.selection.main)return{changes:{from:t,to:i,insert:e},range:m.cursor(t+e.length)};let r=i-t;return!s.empty||r&&n.sliceDoc(s.from-r,s.from)!=n.sliceDoc(t,i)?{range:s}:{changes:{from:s.from-r,to:s.from,insert:e},range:m.cursor(s.from-r+e.length)}})),{userEvent:"input.complete"})}function Sa(n,e){const t=e.completion.apply||e.completion.label;let i=e.source;typeof t=="string"?n.dispatch(bp(n.state,t,i.from,i.to)):t(n,e.completion,i.from,i.to)}const $o=new WeakMap;function wp(n){if(!Array.isArray(n))return n;let e=$o.get(n);return e||$o.set(n,e=yp(n)),e}class xp{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[];for(let t=0;t<e.length;){let i=ie(e,t),s=ve(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(ie(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}match(e){if(this.pattern.length==0)return[0];if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let S=ie(e,0);return S==t[0]?[0,0,ve(S)]:S==i[0]?[-200,0,ve(S)]:null}let l=e.indexOf(this.pattern);if(l==0)return[0,0,this.pattern.length];let h=t.length,a=0;if(l<0){for(let S=0,v=Math.min(e.length,200);S<v&&a<h;){let k=ie(e,S);(k==t[a]||k==i[a])&&(s[a++]=S),S+=ve(k)}if(a<h)return null}let c=0,f=0,u=!1,d=0,p=-1,g=-1,y=/[a-z]/.test(e),b=!0;for(let S=0,v=Math.min(e.length,200),k=0;S<v&&f<h;){let C=ie(e,S);l<0&&(c<h&&C==t[c]&&(r[c++]=S),d<h&&(C==t[d]||C==i[d]?(d==0&&(p=S),g=S+1,d++):d=0));let M,B=C<255?C>=48&&C<=57||C>=97&&C<=122?2:C>=65&&C<=90?1:0:(M=Ws(C))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!S||B==1&&y||k==0&&B!=0)&&(t[f]==C||i[f]==C&&(u=!0)?o[f++]=S:o.length&&(b=!1)),k=B,S+=ve(C)}return f==h&&o[0]==0&&b?this.result(-100+(u?-200:0),o,e):d==h&&p==0?[-200-e.length,0,g]:l>-1?[-700-e.length,l,l+this.pattern.length]:d==h?[-200+-700-e.length,p,g]:f==h?this.result(-100+(u?-200:0)+-700+(b?0:-1100),o,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[e-i.length],r=1;for(let o of t){let l=o+(this.astral?ve(ie(i,o)):1);r>1&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return s}}const Be=D.define({combine(n){return Ct(n,{activateOnTyping:!0,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,optionClass:(e,t)=>i=>kp(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})}});function kp(n,e){return n?e?n+" "+e:n:e}function Sp(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){let r=document.createElement("span");r.className="cm-completionLabel";let{label:o}=t,l=0;for(let h=1;h<s.length;){let a=s[h++],c=s[h++];a>l&&r.appendChild(document.createTextNode(o.slice(l,a)));let f=r.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(o.slice(a,c))),f.className="cm-completionMatchedText",l=c}return l<o.length&&r.appendChild(document.createTextNode(o.slice(l))),r},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 jo(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 vp{constructor(e,t){this.view=e,this.stateField=t,this.info=null,this.placeInfo={read:()=>this.measureInfo(),write:l=>this.positionInfo(l),key:this};let i=e.state.field(t),{options:s,selected:r}=i.open,o=e.state.facet(Be);this.optionContent=Sp(o),this.optionClass=o.optionClass,this.range=jo(s.length,r,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.dom.addEventListener("mousedown",l=>{for(let h=l.target,a;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(a=/-(\d+)$/.exec(h.id))&&+a[1]<s.length){Sa(e,s[+a[1]]),l.preventDefault();return}}),this.list=this.dom.appendChild(this.createListBox(s,i.id,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfo)})}mount(){this.updateSel()}update(e){e.state.field(this.stateField)!=e.startState.field(this.stateField)&&this.updateSel()}positioned(){this.info&&this.view.requestMeasure(this.placeInfo)}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=jo(t.options.length,t.selected,this.view.state.facet(Be).maxRenderedOptions),this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t.options,e.id,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfo)})),this.updateSelectedOption(t.selected)){this.info&&(this.info.remove(),this.info=null);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)}).catch(o=>Ee(this.view.state,o,"completion info")):this.addInfoPane(r)}}addInfoPane(e){let t=this.info=document.createElement("div");t.className="cm-tooltip cm-completionInfo",t.appendChild(e),this.dom.appendChild(t),this.view.requestMeasure(this.placeInfo)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return t&&Ap(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.ownerDocument.defaultView,i=this.dom.getBoundingClientRect(),s=this.info.getBoundingClientRect(),r=e.getBoundingClientRect();if(r.top>Math.min(t.innerHeight,i.bottom)-10||r.bottom<Math.max(0,i.top)+10)return null;let o=this.view.textDirection==X.RTL,l=o,h=!1,a,c="",f="",u=i.left,d=t.innerWidth-i.right;if(l&&u<Math.min(s.width,d)?l=!1:!l&&d<Math.min(s.width,u)&&(l=!0),s.width<=(l?u:d))c=Math.max(0,Math.min(r.top,t.innerHeight-s.height))-i.top+"px",a=Math.min(400,l?u:d)+"px";else{h=!0,a=Math.min(400,(o?i.right:t.innerWidth-i.left)-30)+"px";let p=t.innerHeight-i.bottom;p>=s.height||p>i.top?c=r.bottom-i.top+"px":f=i.bottom-r.top+"px"}return{top:c,bottom:f,maxWidth:a,class:h?o?"left-narrow":"right-narrow":l?"left":"right"}}positionInfo(e){this.info&&(e?(this.info.style.top=e.top,this.info.style.bottom=e.bottom,this.info.style.maxWidth=e.maxWidth,this.info.className="cm-tooltip cm-completionInfo cm-completionInfo-"+e.class):this.info.style.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"));for(let r=i.from;r<i.to;r++){let{completion:o,match:l}=e[r];const h=s.appendChild(document.createElement("li"));h.id=t+"-"+r,h.setAttribute("role","option");let a=this.optionClass(o);a&&(h.className=a);for(let c of this.optionContent){let f=c(o,this.view.state,l);f&&h.appendChild(f)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}}function Cp(n){return e=>new vp(e,n)}function Ap(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect();i.top<t.top?n.scrollTop-=t.top-i.top:i.bottom>t.bottom&&(n.scrollTop+=i.bottom-t.bottom)}function Ko(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function Mp(n,e){let t=[],i=0;for(let l of n)if(l.hasResult())if(l.result.filter===!1){let h=l.result.getMatch;for(let a of l.result.options){let c=[1e9-i++];if(h)for(let f of h(a))c.push(f);t.push(new qo(a,l,c))}}else{let h=new xp(e.sliceDoc(l.from,l.to)),a;for(let c of l.result.options)(a=h.match(c.label))&&(c.boost!=null&&(a[0]+=c.boost),t.push(new qo(c,l,a)))}let s=[],r=null,o=e.facet(Be).compareCompletions;for(let l of t.sort((h,a)=>a.match[0]-h.match[0]||o(h.completion,a.completion)))!r||r.label!=l.completion.label||r.detail!=l.completion.detail||r.type!=null&&l.completion.type!=null&&r.type!=l.completion.type||r.apply!=l.completion.apply?s.push(l):Ko(l.completion)>Ko(r)&&(s[s.length-1]=l),r=l.completion;return s}class si{constructor(e,t,i,s,r){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new si(this.options,Uo(t,e),this.tooltip,this.timestamp,e)}static build(e,t,i,s,r){let o=Mp(e,t);if(!o.length)return null;let l=t.facet(Be).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let h=s.options[s.selected].completion;for(let a=0;a<o.length;a++)if(o[a].completion==h){l=a;break}}return new si(o,Uo(i,l),{pos:e.reduce((h,a)=>a.hasResult()?Math.min(h,a.from):h,1e8),create:Cp(Ae),above:r.aboveCursor},s?s.timestamp:Date.now(),l)}map(e){return new si(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected)}}class un{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new un(Tp,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(Be),r=(i.override||t.languageDataAt("autocomplete",rt(t)).map(wp)).map(l=>(this.active.find(a=>a.source==l)||new ye(l,this.active.some(a=>a.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((l,h)=>l==this.active[h])&&(r=this.active);let o=e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!Dp(r,this.active)?si.build(r,t,this.id,this.open,i):this.open&&e.docChanged?this.open.map(e.changes):this.open;!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new ye(l.source,0):l));for(let l of e.effects)l.is(Ca)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new un(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Op}}function Dp(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 Op={"aria-autocomplete":"list"};function Uo(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const Tp=[];function Fs(n){return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}class ye{constructor(e,t,i=-1){this.source=e,this.state=t,this.explicitPos=i}hasResult(){return!1}update(e,t){let i=Fs(e),s=this;i?s=s.handleUserEvent(e,i,t):e.docChanged?s=s.handleChange(e):e.selection&&s.state!=0&&(s=new ye(s.source,0));for(let r of e.effects)if(r.is(cr))s=new ye(s.source,1,r.value?rt(e.state):-1);else if(r.is(dn))s=new ye(s.source,0);else if(r.is(va))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 ye(this.source,1)}handleChange(e){return e.changes.touchesRange(rt(e.startState))?new ye(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new ye(this.source,this.state,e.mapPos(this.explicitPos))}}class ri extends ye{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=rt(e.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||t=="delete"&&rt(e.startState)==this.from)return new ye(this.source,t=="input"&&i.activateOnTyping?1:0);let h=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos),a;return Bp(this.result.validFor,e.state,r,o)?new ri(this.source,h,this.result,r,o):this.result.update&&(a=this.result.update(this.result,r,o,new xa(e.state,l,h>=0)))?new ri(this.source,h,a,a.from,(s=a.to)!==null&&s!==void 0?s:rt(e.state)):new ye(this.source,1,h)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new ye(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new ri(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1))}}function Bp(n,e,t,i){if(!n)return!1;let s=e.sliceDoc(t,i);return typeof n=="function"?n(s,t,i,e):ka(n,!0).test(s)}const cr=R.define(),dn=R.define(),va=R.define({map(n,e){return n.map(t=>t.map(e))}}),Ca=R.define(),Ae=me.define({create(){return un.start()},update(n,e){return n.update(e)},provide:n=>[ah.from(n,e=>e.tooltip),O.contentAttributes.from(n,e=>e.attrs)]});function Vi(n,e="option"){return t=>{let i=t.state.field(Ae,!1);if(!i||!i.open||Date.now()-i.open.timestamp<t.state.facet(Be).interactionDelay)return!1;let s=1,r;e=="page"&&(r=Hf(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:Ca.of(l)}),!0}}const Pp=n=>{let e=n.state.field(Ae,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||Date.now()-e.open.timestamp<n.state.facet(Be).interactionDelay?!1:(Sa(n,e.open.options[e.open.selected]),!0)},Lp=n=>n.state.field(Ae,!1)?(n.dispatch({effects:cr.of(!0)}),!0):!1,Rp=n=>{let e=n.state.field(Ae,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:dn.of(null)}),!0)};class Ep{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Go=50,Ip=50,Np=1e3,Vp=de.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.composing=0;for(let e of n.state.field(Ae).active)e.state==1&&this.startQuery(e)}update(n){let e=n.state.field(Ae);if(!n.selectionSet&&!n.docChanged&&n.startState.field(Ae)==e)return;let t=n.transactions.some(i=>(i.selection||i.docChanged)&&!Fs(i));for(let i=0;i<this.running.length;i++){let s=this.running[i];if(t||s.updates.length+n.transactions.length>Ip&&Date.now()-s.time>Np){for(let r of s.context.abortListeners)try{r()}catch(o){Ee(this.view.state,o)}s.context.abortListeners=null,this.running.splice(i--,1)}else s.updates.push(...n.transactions)}if(this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),this.debounceUpdate=e.active.some(i=>i.state==1&&!this.running.some(s=>s.active.source==i.source))?setTimeout(()=>this.startUpdate(),Go):-1,this.composing!=0)for(let i of n.transactions)Fs(i)=="input"?this.composing=2:this.composing==2&&i.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1;let{state:n}=this.view,e=n.field(Ae);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=rt(e),i=new xa(e,t,n.explicitPos==t),s=new Ep(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:dn.of(null)}),Ee(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),Go))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Be);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 ri(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:rt(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(Ae).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new ye(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:va.of(e)})}},{eventHandlers:{blur(){let n=this.view.state.field(Ae,!1);n&&n.tooltip&&this.view.state.facet(Be).closeOnBlur&&this.view.dispatch({effects:dn.of(null)})},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:cr.of(!1)}),20),this.composing=0}}}),Aa=O.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",listStyle:"none",margin:0,padding:0,"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer",padding:"1px 3px",lineHeight:1.2}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"\xB7\xB7\xB7"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:`${400}px`,boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:`${30}px`},".cm-completionInfo.cm-completionInfo-right-narrow":{left:`${30}px`},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",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"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'\u0192'"}},".cm-completionIcon-class":{"&:after":{content:"'\u25CB'"}},".cm-completionIcon-interface":{"&:after":{content:"'\u25CC'"}},".cm-completionIcon-variable":{"&:after":{content:"'\u{1D465}'"}},".cm-completionIcon-constant":{"&:after":{content:"'\u{1D436}'"}},".cm-completionIcon-type":{"&:after":{content:"'\u{1D461}'"}},".cm-completionIcon-enum":{"&:after":{content:"'\u222A'"}},".cm-completionIcon-property":{"&:after":{content:"'\u25A1'"}},".cm-completionIcon-keyword":{"&:after":{content:"'\u{1F511}\uFE0E'"}},".cm-completionIcon-namespace":{"&:after":{content:"'\u25A2'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Fp{constructor(e,t,i,s){this.field=e,this.line=t,this.from=i,this.to=s}}class fr{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,le.TrackDel),i=e.mapPos(this.to,1,le.TrackDel);return t==null||i==null?null:new fr(this.field,t,i)}}class ur{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 h of this.lines){if(i.length){let a=o,c=/^\t*/.exec(h)[0].length;for(let f=0;f<c;f++)a+=e.facet(xn);s.push(t+a.length-c),h=a+h.slice(c)}i.push(h),t+=h.length+1}let l=this.fieldPositions.map(h=>new fr(h.field,s[h.line]+h.from,s[h.line]+h.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,h=r[2]||r[3]||"",a=-1;for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:h?t[c].name==h:!1)&&(a=c);if(a<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:h}),a=c;for(let f of s)f.field>=a&&f.field++}s.push(new Fp(a,i.length,r.index,r.index+h.length)),o=o.slice(0,r.index)+h+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 h of s)h.line==i.length&&h.from>l.index&&(h.from--,h.to--)}i.push(o)}return new ur(i,s)}}let Wp=T.widget({widget:new class extends at{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),Hp=T.mark({class:"cm-snippetField"});class jt{constructor(e,t){this.ranges=e,this.active=t,this.deco=T.set(e.map(i=>(i.from==i.to?Wp:Hp).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 jt(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 xi=R.define({map(n,e){return n&&n.map(e)}}),zp=R.define(),mi=me.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(xi))return t.value;if(t.is(zp)&&n)return new jt(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=>O.decorations.from(n,e=>e?e.deco:T.none)});function dr(n,e){return m.create(n.filter(t=>t.field==e).map(t=>m.range(t.from,t.to)))}function qp(n){let e=ur.parse(n);return(t,i,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),h={changes:{from:s,to:r,insert:N.of(o)},scrollIntoView:!0};if(l.length&&(h.selection=dr(l,0)),l.length>1){let a=new jt(l,0),c=h.effects=[xi.of(a)];t.state.field(mi,!1)===void 0&&c.push(R.appendConfig.of([mi,Gp,Jp,Aa]))}t.dispatch(t.state.update(h))}}function Ma(n){return({state:e,dispatch:t})=>{let i=e.field(mi,!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:dr(i.ranges,s),effects:xi.of(r?null:new jt(i.ranges,s))})),!0}}const $p=({state:n,dispatch:e})=>n.field(mi,!1)?(e(n.update({effects:xi.of(null)})),!0):!1,jp=Ma(1),Kp=Ma(-1),Up=[{key:"Tab",run:jp,shift:Kp},{key:"Escape",run:$p}],Jo=D.define({combine(n){return n.length?n[0]:Up}}),Gp=St.highest(Js.compute([Jo],n=>n.facet(Jo)));function Bg(n,e){return Object.assign(Object.assign({},e),{apply:qp(n)})}const Jp=O.domEventHandlers({mousedown(n,e){let t=e.state.field(mi,!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:dr(t.ranges,s.field),effects:xi.of(t.ranges.some(r=>r.field>s.field)?new jt(t.ranges,s.field):null)}),!0)}}),pn={brackets:["(","[","{","'",'"'],before:")]}:;>"},gt=R.define({map(n,e){let t=e.mapPos(n,-1,le.TrackAfter);return t==null?void 0:t}}),pr=R.define({map(n,e){return e.mapPos(n)}}),gr=new class extends yt{};gr.startSide=1;gr.endSide=-1;const Da=me.define({create(){return $.empty},update(n,e){if(e.selection){let t=e.state.doc.lineAt(e.selection.main.head).from,i=e.startState.doc.lineAt(e.startState.selection.main.head).from;t!=e.changes.mapPos(i,-1)&&(n=$.empty)}n=n.map(e.changes);for(let t of e.effects)t.is(gt)?n=n.update({add:[gr.range(t.value,t.value+1)]}):t.is(pr)&&(n=n.update({filter:i=>i!=t.value}));return n}});function Pg(){return[Yp,Da]}const Xn="()[]{}<>";function Oa(n){for(let e=0;e<Xn.length;e+=2)if(Xn.charCodeAt(e)==n)return Xn.charAt(e+1);return Ws(n<128?n:n+1)}function Ta(n,e){return n.languageDataAt("closeBrackets",e)[0]||pn}const Xp=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Yp=O.inputHandler.of((n,e,t,i)=>{if((Xp?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&ve(ie(i,0))==1||e!=s.from||t!=s.to)return!1;let r=Qp(n.state,i);return r?(n.dispatch(r),!0):!1}),_p=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=Ta(n,n.selection.main.head).brackets||pn.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=Zp(n.doc,o.head);for(let h of i)if(h==l&&Tn(n.doc,o.head)==Oa(ie(h,0)))return{changes:{from:o.head-h.length,to:o.head+h.length},range:m.cursor(o.head-h.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},Lg=[{key:"Backspace",run:_p}];function Qp(n,e){let t=Ta(n,n.selection.main.head),i=t.brackets||pn.brackets;for(let s of i){let r=Oa(ie(s,0));if(e==s)return r==s?ig(n,s,i.indexOf(s+s+s)>-1):eg(n,s,r,t.before||pn.before);if(e==r&&Ba(n,n.selection.main.from))return tg(n,s,r)}return null}function Ba(n,e){let t=!1;return n.field(Da).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function Tn(n,e){let t=n.sliceString(e,e+2);return t.slice(0,ve(ie(t,0)))}function Zp(n,e){let t=n.sliceString(e-2,e);return ve(ie(t,0))==t.length?t:t.slice(1)}function eg(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:gt.of(o.to+e.length),range:m.range(o.anchor+e.length,o.head+e.length)};let l=Tn(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:gt.of(o.head+e.length),range:m.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function tg(n,e,t){let i=null,s=n.selection.ranges.map(r=>r.empty&&Tn(n.doc,r.head)==t?m.cursor(r.head+t.length):i=r);return i?null:n.update({selection:m.create(s,n.selection.mainIndex),scrollIntoView:!0,effects:n.selection.ranges.map(({from:r})=>pr.of(r))})}function ig(n,e,t){let i=null,s=n.changeByRange(r=>{if(!r.empty)return{changes:[{insert:e,from:r.from},{insert:e,from:r.to}],effects:gt.of(r.to+e.length),range:m.range(r.anchor+e.length,r.head+e.length)};let o=r.head,l=Tn(n.doc,o);if(l==e){if(Xo(n,o))return{changes:{insert:e+e,from:o},effects:gt.of(o+e.length),range:m.cursor(o+e.length)};if(Ba(n,o)){let h=t&&n.sliceDoc(o,o+e.length*3)==e+e+e;return{range:m.cursor(o+e.length*(h?3:1)),effects:pr.of(o)}}}else{if(t&&n.sliceDoc(o-2*e.length,o)==e+e&&Xo(n,o-2*e.length))return{changes:{insert:e+e+e+e,from:o},effects:gt.of(o+e.length),range:m.cursor(o+e.length)};if(n.charCategorizer(o)(l)!=j.Word){let h=n.sliceDoc(o-1,o);if(h!=e&&n.charCategorizer(o)(h)!=j.Word&&!ng(n,o,e))return{changes:{insert:e+e,from:o},effects:gt.of(o+e.length),range:m.cursor(o+e.length)}}}return{range:i=r}});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Xo(n,e){let t=ge(n).resolveInner(e+1);return t.parent&&t.from==e}function ng(n,e,t){let i=ge(n).resolveInner(e,-1);for(let s=0;s<5;s++){if(n.sliceDoc(i.from,i.from+t.length)==t){let o=i.firstChild;for(;o&&o.from==i.from&&o.to-o.from>t.length;){if(n.sliceDoc(o.to-t.length,o.to)==t)return!1;o=o.firstChild}return!0}let r=i.to==e&&i.parent;if(!r)break;i=r}return!1}function Rg(n={}){return[Ae,Be.of(n),Vp,rg,Aa]}const sg=[{key:"Ctrl-Space",run:Lp},{key:"Escape",run:Rp},{key:"ArrowDown",run:Vi(!0)},{key:"ArrowUp",run:Vi(!1)},{key:"PageDown",run:Vi(!0,"page")},{key:"PageUp",run:Vi(!1,"page")},{key:"Enter",run:Pp}],rg=St.highest(Js.computeN([Be],n=>n.facet(Be).defaultKeymap?[sg]:[]));export{bg as A,wg as B,gn as C,jf as D,O as E,xg as F,gg as G,ge as H,G as I,Tg as J,yp as K,Ts as L,m as M,Xs as N,yg as O,dh as P,mg as Q,Bg as R,Oh as S,F as T,ug as U,I as a,hg as b,Cg as c,og as d,lg as e,Sg as f,vg as g,fg as h,Pg as i,Dg as j,Js as k,Lg as l,Mg as m,Og as n,Ag as o,sg as p,Rg as q,cg as r,kg as s,ag as t,pe as u,L as v,ou as w,x,dg as y,du as z};