14 lines
330 KiB
JavaScript
14 lines
330 KiB
JavaScript
class I{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),Ke.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),Ke.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 oi(this),r=new oi(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 oi(this,e)}iterRange(e,t=this.length){return new hl(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 cl(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?I.empty:e.length<=32?new G(e):Ke.from(G.split(e,[]))}}class G extends I{constructor(e,t=tc(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 ic(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new G(Ar(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=Gi(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new G(l,o.length+r.length));else{let a=l.length>>1;i.push(new G(l.slice(0,a)),new G(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof G))return super.replace(e,t,i);let s=Gi(this.text,Gi(i.text,Ar(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new G(s,r):Ke.from(G.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],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new G(i,s)),i=[],s=-1);return s>-1&&t.push(new G(i,s)),t}}class Ke extends I{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+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 a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>5-1&&a.lines>h>>5+1){let c=this.children.slice();return c[s]=a,new Ke(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
|
||
`){let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Ke))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new G(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>r&&d instanceof Ke)for(let g of d.children)f(g);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof G&&a&&(p=c[c.length-1])instanceof G&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new G(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:Ke.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new Ke(l,t)}}I.empty=new G([""],0);function tc(n){let e=-1;for(let t of n)e+=t.length+1;return e}function Gi(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function Ar(n,e,t){return Gi(n,[""],e,t)}class oi{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 G?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 G?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 G){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof G?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class hl{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new oi(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 cl{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"&&(I.prototype[Symbol.iterator]=function(){return this.iter()},oi.prototype[Symbol.iterator]=hl.prototype[Symbol.iterator]=cl.prototype[Symbol.iterator]=function(){return this});class ic{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 It="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<It.length;n++)It[n]+=It[n-1];function nc(n){for(let e=1;e<It.length;e+=2)if(It[e]>n)return It[e-1]<=n;return!1}function Mr(n){return n>=127462&&n<=127487}const Dr=8205;function ce(n,e,t=!0,i=!0){return(t?fl:sc)(n,e,i)}function fl(n,e,t){if(e==n.length)return e;e&&ul(n.charCodeAt(e))&&dl(n.charCodeAt(e-1))&&e--;let i=ne(n,e);for(e+=Oe(i);e<n.length;){let s=ne(n,e);if(i==Dr||s==Dr||t&&nc(s))e+=Oe(s),i=s;else if(Mr(s)){let r=0,o=e-2;for(;o>=0&&Mr(ne(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function sc(n,e,t){for(;e>0;){let i=fl(n,e-2,t);if(i<e)return i;e--}return 0}function ul(n){return n>=56320&&n<57344}function dl(n){return n>=55296&&n<56320}function ne(n,e){let t=n.charCodeAt(e);if(!dl(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return ul(i)?(t-55296<<10)+(i-56320)+65536:t}function _s(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function Oe(n){return n<65536?1:2}const ns=/\r\n?|\n/;var he=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(he||(he={}));class Je{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){ss(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 Je(e)}composeDesc(e){return this.empty?e:e.empty?this:pl(this,e)}mapDesc(e,t=!1){return e.empty?this:rs(this,e,t)}mapPos(e,t=-1,i=he.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=s+l;if(a<0){if(h>e)return r+(e-s);r+=l}else{if(i!=he.Simple&&h>=e&&(i==he.TrackDel&&s<e&&h>e||i==he.TrackBefore&&s<e||i==he.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=h}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 Je(e)}static create(e){return new Je(e)}}class Z extends Je{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 ss(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return rs(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(I.empty);i.push(o?e.slice(r,r+o):I.empty)}r+=o}return new Z(t,i)}compose(e){return this.empty?e:e.empty?this:pl(this,e,!0)}map(e,t=!1){return e.empty?this:rs(this,e,t,!0)}iterChanges(e,t=!1){ss(this,e,t)}get desc(){return Je.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new hi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);ae(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;ae(t,c,f),f>0&&nt(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);ae(t,c,-1),ae(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new Z(t,i),filtered:Je.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<t&&ae(s,t-o,-1);let f=new Z(s,r);l=l?l.compose(f.map(l)):f,s=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof Z){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),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"?I.of(d.split(i||ns)):d:I.empty,g=p.length;if(f==u&&g==0)return;f<o&&a(),f>o&&ae(s,f-o,-1),ae(s,u-f,g),nt(r,s,p),o=u}}return h(e),a(!l),l}static empty(e){return new Z(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(I.empty);i[s]=I.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new Z(t,i)}static createSet(e,t){return new Z(e,t)}}function ae(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 nt(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(I.empty);n.push(t)}}function ss(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let h=s,c=r,f=I.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,h,r,c,f),s=h,r=c}}}function rs(n,e,t,i=!1){let s=[],r=i?[]:null,o=new hi(n),l=new hi(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);ae(s,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(ae(s,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(ae(s,0,o.ins),r&&nt(r,s,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;ae(s,h,a<o.i?o.ins:0),r&&a<o.i&&nt(r,s,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?Z.createSet(s,r):Je.create(s);throw new Error("Mismatched change set lengths")}}function pl(n,e,t=!1){let i=[],s=t?[]:null,r=new hi(n),o=new hi(e);for(let l=!1;;){if(r.done&&o.done)return s?Z.createSet(i,s):Je.create(i);if(r.ins==0)ae(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)ae(i,0,o.ins,l),s&&nt(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;ae(i,a,c,l),s&&c&&nt(s,i,o.text)}else o.ins==-1?(ae(i,r.off?0:r.len,a,l),s&&nt(s,i,r.textBit(a))):(ae(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&nt(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class hi{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?I.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?I.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 gt{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 gt(i,s,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return b.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return b.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 b.range(e.anchor,e.head)}static create(e,t,i){return new gt(e,t,i)}}class b{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:b.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 b([this.main],0)}addRange(e,t=!0){return b.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,b.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 b(e.ranges.map(t=>gt.fromJSON(t)),e.main)}static single(e,t=e){return new b([b.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 b.normalized(e.slice(),t);i=r.to}return new b(e,t)}static cursor(e,t=0,i,s){return gt.create(e,e,(t==0?0:t<0?4:8)|(i==null?3:Math.min(2,i))|(s??33554431)<<5)}static range(e,t,i,s){let r=(i??33554431)<<5|(s==null?3:Math.min(2,s));return t<e?gt.create(t,e,24|r):gt.create(e,t,(t>e?4:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?b.range(a,l):b.range(l,a))}}return new b(e,t)}}function gl(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let Xs=0;class D{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=Xs++,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:Ys),!!e.static,e.enables)}of(e){return new Ji([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function Ys(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class Ji{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=Xs++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||os(f,c)){let d=i(f);if(l?!Or(d,f.values[o],s):!s(d,f.values[o]))return f.values[o]=d,1}return 0},reconfigure:(f,u)=>{let d,p=u.config.address[r];if(p!=null){let g=nn(u,p);if(this.dependencies.every(m=>m instanceof D?u.facet(m)===f.facet(m):m instanceof be?u.field(m,!1)==f.field(m,!1):!0)||(l?Or(d=i(f),g,s):s(d=i(f),g)))return f.values[o]=g,0}else d=i(f);return f.values[o]=d,1}}}}function Or(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 os(n,e){let t=!1;for(let i of e)li(n,i)&1&&(t=!0);return t}function rc(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=nn(a,i[c]);if(s[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of i)li(a,h);return a.values[o]=l(a),1},update(a,h){if(!os(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=os(a,i),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&Ys(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Tr=D.define({static:!0});class be{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 be(Xs++,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(Tr).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,Tr.of({field:this,create:e})]}get extension(){return this}}const pt={lowest:4,low:3,default:2,high:1,highest:0};function Yt(n){return e=>new ml(e,n)}const At={highest:Yt(pt.highest),high:Yt(pt.high),default:Yt(pt.default),low:Yt(pt.low),lowest:Yt(pt.lowest)};class ml{constructor(e,t){this.inner=e,this.prec=t}}class An{of(e){return new ls(this,e)}reconfigure(e){return An.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class ls{constructor(e,t){this.compartment=e,this.inner=t}}class tn{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 oc(e,t,o))u instanceof be?s.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of s)l[u.id]=h.length<<1,h.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(m=>m.type==0))if(l[p.id]=a.length<<1|1,Ys(g,d))a.push(i.facet(p));else{let m=p.combine(d.map(y=>y.value));a.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=a.length<<1|1,a.push(m.value)):(l[m.id]=h.length<<1,h.push(y=>m.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(m=>rc(m,p,d))}}let f=h.map(u=>u(l));return new tn(e,o,f,l,a,r)}}function oc(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof ls&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof ls){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof ml)r(o.inner,o.prec);else if(o instanceof be)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Ji)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,pt.default);else{let h=o.extension;if(!h)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(h,l)}}return r(n,pt.default),i.reduce((o,l)=>o.concat(l))}function li(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 nn(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const yl=D.define(),bl=D.define({combine:n=>n.some(e=>e),static:!0}),xl=D.define({combine:n=>n.length?n[0]:void 0,static:!0}),wl=D.define(),kl=D.define(),Sl=D.define(),vl=D.define({combine:n=>n.length?n[0]:!1});class Ze{constructor(e,t){this.type=e,this.value=t}static define(){return new lc}}class lc{of(e){return new Ze(this,e)}}class ac{constructor(e){this.map=e}of(e){return new E(this,e)}}class E{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 E(this.type,t)}is(e){return this.type==e}static define(e={}){return new ac(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}}E.reconfigure=E.define();E.appendConfig=E.define();class ee{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&&gl(i,t.newLength),r.some(l=>l.type==ee.time)||(this.annotations=r.concat(ee.time.of(Date.now())))}static create(e,t,i,s,r,o){return new ee(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(ee.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}ee.time=Ze.define();ee.userEvent=Ze.define();ee.addToHistory=Ze.define();ee.remote=Ze.define();function hc(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 Cl(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=Z.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:E.mapEffects(n.effects,s).concat(E.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function as(n,e,t){let i=e.selection,s=Nt(e.annotations);return e.userEvent&&(s=s.concat(ee.userEvent.of(e.userEvent))),{changes:e.changes instanceof Z?e.changes:Z.of(e.changes||[],t,n.facet(xl)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Nt(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function Al(n,e,t){let i=as(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=Cl(i,as(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=ee.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return fc(t?cc(s):s)}function cc(n){let e=n.startState,t=!0;for(let s of e.facet(wl)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:hc(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=Z.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=ee.create(e,s,n.selection&&n.selection.map(r),E.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(kl);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof ee?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof ee?n=r[0]:n=Al(e,Nt(r),!1)}return n}function fc(n){let e=n.startState,t=e.facet(Sl),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=Cl(i,as(e,r,n.changes.newLength),!0))}return i==n?n:ee.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const uc=[];function Nt(n){return n==null?uc:Array.isArray(n)?n:[n]}var $=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}($||($={}));const dc=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let hs;try{hs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function pc(n){if(hs)return hs.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||dc.test(t)))return!0}return!1}function gc(n){return e=>{if(!/\S/.test(e))return $.Space;if(pc(e))return $.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return $.Word;return $.Other}}class N{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++)li(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 li(this,i),nn(this,i)}update(...e){return Al(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let o of e.effects)o.is(An.reconfigure)?(t&&(s=new Map,t.compartments.forEach((l,a)=>s.set(a,l)),t=null),s.set(o.value.compartment,o.value.extension)):o.is(E.reconfigure)?(t=null,i=o.value):o.is(E.appendConfig)&&(t=null,i=Nt(i).concat(o.value));let r;t?r=e.startState.values.slice():(t=tn.resolve(i,s,this),r=new N(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(l,a)=>a.reconfigure(l,this),null).values),new N(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:b.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=Nt(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(s);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=s.mapDesc(h,!0);r.push(a.range.map(f)),s=s.compose(c),o=E.mapEffects(o,c).concat(E.mapEffects(Nt(a.effects),f))}return{changes:s,selection:b.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof Z?e:Z.of(e,this.doc.length,this.facet(N.lineSeparator))}toText(e){return I.of(e.split(this.facet(N.lineSeparator)||ns))}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:(li(this,t),nn(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 be&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return N.create({doc:e.doc,selection:b.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=tn.resolve(e.extensions||[],new Map),i=e.doc instanceof I?e.doc:I.of((e.doc||"").split(t.staticFacet(N.lineSeparator)||ns)),s=e.selection?e.selection instanceof b?e.selection:b.single(e.selection.anchor,e.selection.head):b.single(0);return gl(s,i.length),t.staticFacet(bl)||(s=s.asSingle()),new N(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(N.tabSize)}get lineBreak(){return this.facet(N.lineSeparator)||`
|
||
`}get readOnly(){return this.facet(vl)}phrase(e,...t){for(let i of this.facet(N.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(yl))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){return gc(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=ce(t,o,!1);if(r(t.slice(a,o))!=$.Word)break;o=a}for(;l<s;){let a=ce(t,l);if(r(t.slice(l,a))!=$.Word)break;l=a}return o==l?null:b.range(o+i,l+i)}}N.allowMultipleSelections=bl;N.tabSize=D.define({combine:n=>n.length?n[0]:4});N.lineSeparator=xl;N.readOnly=vl;N.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])}});N.languageData=yl;N.changeFilter=wl;N.transactionFilter=kl;N.transactionExtender=Sl;An.reconfigure=E.define();function Mt(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 wt{eq(e){return this==e}range(e,t=e){return cs.create(e,t,this)}}wt.prototype.startSide=wt.prototype.endSide=0;wt.prototype.point=!1;wt.prototype.mapMode=he.TrackDel;let cs=class Ml{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Ml(e,t,i)}};function fs(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 a=o+l>>1,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],c=this.from[a]+e,f=this.to[a]+e,u,d;if(c==f){let p=t.mapPos(c,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=t.mapPos(c,h.endSide),d<u)))continue}else if(u=t.mapPos(c,h.startSide),d=t.mapPos(f,h.endSide),u>d||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(l=Math.max(l,d-u)),i.push(h),s.push(u-o),r.push(d-o))}return{mapped:i.length?new Qs(s,r,i,l):null,pos:o}}}class K{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 K(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(fs)),this.isEmpty)return t.length?K.of(t):this;let l=new Dl(this,null,-1).goto(0),a=0,h=[],c=new kt;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];c.addInner(f.from,f.to,f.value)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&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)||h.push(cs.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?K.empty:this.nextLayer.update({add:h,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:c,pos:f}=a.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 K(i,t,r||K.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 ci.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return ci.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=Br(o,l,i),h=new Qt(o,a,r),c=new Qt(l,a,r);i.iterGaps((f,u,d)=>Pr(h,f,c,u,d,s)),i.empty&&i.length==0&&Pr(h,0,c,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=1e9-1);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=Br(r,o),a=new Qt(r,l,0).goto(i),h=new Qt(o,l,0).goto(i);for(;;){if(a.to!=h.to||!us(a.active,h.active)||a.point&&(!h.point||!a.point.eq(h.point)))return!1;if(a.to>s)return!0;a.next(),h.next()}}static spans(e,t,i,s,r=-1){let o=new Qt(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<t?c.length+1:Math.min(c.length,a);s.point(l,h,o.point,c,f,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(s.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new kt;for(let s of e instanceof cs?[e]:t?mc(e):e)i.add(s.from,s.to,s.value);return i.finish()}}K.empty=new K([],[],null,-1);function mc(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(fs(e,i)>0)return n.slice().sort(fs);e=i}return n}K.empty.nextLayer=K.empty;class kt{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=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new kt)).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(K.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=K.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Br(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 ci{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 ci(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--)Hn(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--)Hn(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(),Hn(this.heap,0)}}}function Hn(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 Qt{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=ci.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){Di(this.active,e),Di(this.activeTo,e),Di(this.activeRank,e),this.minActive=Lr(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++;Oi(this.active,t,i),Oi(this.activeTo,t,s),Oi(this.activeRank,t,r),e&&Oi(e,t,this.cursor.from),this.minActive=Lr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&Di(i,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function Pr(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e;for(;;){let h=n.to+a-t.to||n.endSide-t.endSide,c=h<0?n.to+a: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))&&us(n.activeForPoint(n.to),t.activeForPoint(t.to))||r.comparePoint(l,f,n.point,t.point):f>l&&!us(n.active,t.active)&&r.compareRange(l,f,n.active,t.active),c>o)break;l=c,h<=0&&n.next(),h>=0&&t.next()}}function us(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 Di(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function Oi(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function Lr(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 Gt(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=ce(n,s));return i}function ds(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=ce(n,s)}return i===!0?-1:n.length}const ps="ͼ",Rr=typeof Symbol>"u"?"__"+ps:Symbol.for(ps),gs=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Er=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class lt{constructor(e,t){this.rules=[];let{finish:i}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],f=/^@(\w+)\b/.exec(o[0]),u=f&&f[1]=="keyframes";if(f&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,a);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)&&a.push((i&&!f&&!h?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=Er[Rr]||1;return Er[Rr]=e+1,ps+e.toString(36)}static mount(e,t,i){let s=e[gs],r=i&&i.nonce;s?r&&s.setNonce(r):s=new yc(e,r),s.mount(Array.isArray(t)?t:[t])}}let Ir=new Map;class yc{constructor(e,t){let i=e.ownerDocument||e,s=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&s.CSSStyleSheet){let r=Ir.get(i);if(r)return e.adoptedStyleSheets=[r.sheet,...e.adoptedStyleSheets],e[gs]=r;this.sheet=new s.CSSStyleSheet,e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets],Ir.set(i,this)}else{this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);let r=e.head||e;r.insertBefore(this.styleTag,r.firstChild)}this.modules=[],e[gs]=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 a=0;a<o.rules.length;a++)t.insertRule(o.rules[a],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}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var at={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:"'"},fi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},bc=typeof navigator<"u"&&/Mac/.test(navigator.platform),xc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var se=0;se<10;se++)at[48+se]=at[96+se]=String(se);for(var se=1;se<=24;se++)at[se+111]="F"+se;for(var se=65;se<=90;se++)at[se]=String.fromCharCode(se+32),fi[se]=String.fromCharCode(se);for(var Wn in at)fi.hasOwnProperty(Wn)||(fi[Wn]=at[Wn]);function wc(n){var e=bc&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||xc&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?fi:at)[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 sn(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function ms(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function kc(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function _i(n,e){if(!e.anchorNode)return!1;try{return ms(n,e.anchorNode)}catch{return!1}}function Vt(n){return n.nodeType==3?St(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function rn(n,e,t,i){return t?Nr(n,e,t,i,-1)||Nr(n,e,t,i,1):!1}function on(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Nr(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:ht(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=on(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?ht(n):0}else return!1}}function ht(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Mn(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Sc(n){return{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function vc(n,e,t,i,s,r,o,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,f=!1;c&&!f;)if(c.nodeType==1){let u,d=c==a.body;if(d)u=Sc(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(f=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let m=c.getBoundingClientRect();u={left:m.left,right:m.left+c.clientWidth,top:m.top,bottom:m.top+c.clientHeight}}let p=0,g=0;if(s=="nearest")e.top<u.top?(g=-(u.top-e.top+o),t>0&&e.bottom>u.bottom+g&&(g=e.bottom-u.bottom+g+o)):e.bottom>u.bottom&&(g=e.bottom-u.bottom+o,t<0&&e.top-g<u.top&&(g=-(u.top+g-e.top+o)));else{let m=e.bottom-e.top,y=u.bottom-u.top;g=(s=="center"&&m<=y?e.top+m/2-y/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-y+o)-u.top}if(i=="nearest"?e.left<u.left?(p=-(u.left-e.left+r),t>0&&e.right>u.right+p&&(p=e.right-u.right+p+r)):e.right>u.right&&(p=e.right-u.right+r,t<0&&e.left<u.left+p&&(p=-(u.left+p-e.left+r))):p=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,p||g)if(d)h.scrollBy(p,g);else{let m=0,y=0;if(g){let S=c.scrollTop;c.scrollTop+=g,y=c.scrollTop-S}if(p){let S=c.scrollLeft;c.scrollLeft+=p,m=c.scrollLeft-S}e={left:e.left-m,top:e.top-y,right:e.right-m,bottom:e.bottom-y},m&&Math.abs(m-p)<1&&(i="nearest"),y&&Math.abs(y-g)<1&&(s="nearest")}if(d)break;c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Cc(n){let e=n.ownerDocument;for(let t=n.parentNode;t&&t!=e.body;)if(t.nodeType==1){if(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)return t;t=t.assignedSlot||t.parentNode}else if(t.nodeType==11)t=t.host;else break;return null}class Ac{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?ht(t):0),i,Math.min(e.focusOffset,i?ht(i):0))}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let Bt=null;function Ol(n){if(n.setActive)return n.setActive();if(Bt)return n.focus(Bt);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Bt==null?{get preventScroll(){return Bt={preventScroll:!0},!0}}:void 0),!Bt){Bt=!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 Fr;function St(n,e,t=e){let i=Fr||(Fr=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function Ft(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 Mc(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function Tl(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function Dc(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,ht(t));;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=ht(t))}else{if(t==n)return!0;i=on(t),t=t.parentNode}}function Bl(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}class de{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new de(e.parentNode,on(e),t)}static after(e,t){return new de(e.parentNode,on(e)+1,t)}}const Zs=[];class V{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let i of this.children){if(i==e)return t;t+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}sync(e,t){if(this.flags&2){let i=this.dom,s=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=s?s.nextSibling:i.firstChild)){let l=V.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(e,t),o.flags&=-8}if(r=s?s.nextSibling:i.firstChild,t&&!t.written&&t.node==i&&r!=o.dom&&(t.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=Hr(r);else i.insertBefore(o.dom,r);s=o.dom}for(r=s?s.nextSibling:i.firstChild,r&&t&&t.node==i&&(t.written=!0);r;)r=Hr(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(e,t),i.flags&=-8)}reuseDOM(e){}localPosFromDOM(e,t){let i;if(e==this.dom)i=this.dom.childNodes[t];else{let s=ht(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&&!V.get(i);)i=i.nextSibling;if(!i)return this.length;for(let s=0,r=0;;s++){let o=this.children[s];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,i=0){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<this.children.length;a++){let f=this.children[a],u=h+f.length;if(h<e&&u>t)return f.domBoundsAround(e,t,h);if(u>=e&&s==-1&&(s=a,r=h),h>t&&f.dom.parentNode==this.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom&&(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=Zs){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 Pl(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(e,t,i,s,r,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor&&!((this.flags|e.flags)&8)}getSide(){return 0}destroy(){this.parent=null}}V.prototype.breakAfter=0;function Hr(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Pl{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 Ll(n,e,t,i,s,r,o,l,a){let{children:h}=n,c=h.length?h[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,a))){if(i<h.length){let d=h[i];d&&s<d.length?(e==i&&(d=d.split(s),s=0),!u&&f&&d.merge(0,s,f,!0,0,a)?r[r.length-1]=d:(s&&d.merge(0,s,null,!1,0,a),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(h[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(h[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&i<h.length&&!h[e-1].breakAfter&&h[i].merge(0,0,h[e-1],!1,l,a)&&e--,(e<i||r.length)&&n.replaceChildren(e,i,r)}}function Rl(n,e,t,i,s,r){let o=n.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:h,off:c}=o.findPos(e,-1),f=e-t;for(let u of i)f+=u.length;n.length+=f,Ll(n,h,c,l,a,i,0,s,r)}const Rt="";class El{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(N.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Rt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=s.nextSibling;if(o==t)break;let l=V.get(s),a=V.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:Wr(s))||Wr(o)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=o}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=V.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 Wr(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}}let De=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},ys=typeof document<"u"?document:{documentElement:{style:{}}};const bs=/Edge\/(\d+)/.exec(De.userAgent),Il=/MSIE \d/.test(De.userAgent),xs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(De.userAgent),Dn=!!(Il||xs||bs),zr=!Dn&&/gecko\/(\d+)/i.test(De.userAgent),Vn=!Dn&&/Chrome\/(\d+)/.exec(De.userAgent),qr="webkitFontSmoothing"in ys.documentElement.style,Nl=!Dn&&/Apple Computer/.test(De.vendor),Kr=Nl&&(/Mobile\/\w+/.test(De.userAgent)||De.maxTouchPoints>2);var A={mac:Kr||/Mac/.test(De.platform),windows:/Win/.test(De.platform),linux:/Linux|X11/.test(De.platform),ie:Dn,ie_version:Il?ys.documentMode||6:xs?+xs[1]:bs?+bs[1]:0,gecko:zr,gecko_version:zr?+(/Firefox\/(\d+)/.exec(De.userAgent)||[0,0])[1]:0,chrome:!!Vn,chrome_version:Vn?+Vn[1]:0,ios:Kr,android:/Android\b/.test(De.userAgent),webkit:qr,safari:Nl,webkit_version:qr?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:ys.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const Oc=256;class _e extends V{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return this.flags&8||i&&(!(i instanceof _e)||this.length-(t-e)+i.length>Oc||i.flags&8)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new _e(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new de(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 Tc(this.dom,e,t)}}class Qe extends V{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(Tl(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,i,s,r,o){return i&&(!(i instanceof Qe&&i.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(Rl(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 a=i+l.length;a>e&&t.push(i<e?l.split(e-i):l),s<0&&i>=e&&(s=r),i=a,r++}let o=this.length-e;return this.length=e,s>-1&&(this.children.length=s,this.markDirty()),new Qe(this.mark,t,o)}domAtPos(e){return Fl(this,e)}coordsAt(e,t){return Wl(this,e,t)}}function Tc(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=St(n,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return A.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Mn(a,o<0):a||null}class mt extends V{static create(e,t,i){return new mt(e,t,i)}constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}split(e){let t=mt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.dom.contentEditable="false")}getSide(){return this.side}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)}become(e){return e instanceof mt&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.compare(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return I.empty;let e=this;for(;e.parent;)e=e.parent;let{view:t}=e,i=t&&t.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):I.empty}domAtPos(e){return(this.length?e==0:this.side>0)?de.before(this.dom):de.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let o=this.side?this.side<0:e>0;for(let l=o?s.length-1:0;r=s[l],!(e>0?l==0:l==s.length-1||r.top<r.bottom);l+=o?-1:1);return Mn(r,!o)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class zt extends V{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof zt&&e.side==this.side}split(){return new zt(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return this.side>0?de.before(this.dom):de.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return I.empty}get isHidden(){return!0}}_e.prototype.children=mt.prototype.children=zt.prototype.children=Zs;function Fl(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 de(t,0)}function Hl(n,e,t){let i,{children:s}=n;t>0&&e instanceof Qe&&s.length&&(i=s[s.length-1])instanceof Qe&&i.mark.eq(e.mark)?Hl(i,e.children[0],t-1):(s.push(e),e.setParent(n)),n.length+=e.length}function Wl(n,e,t){let i=null,s=-1,r=null,o=-1;function l(h,c){for(let f=0,u=0;f<h.children.length&&u<=c;f++){let d=h.children[f],p=u+d.length;p>=c&&(d.children.length?l(d,c-u):(!r||r.isHidden&&t>0)&&(p>c||u==p&&d.getSide()>0)?(r=d,o=c-u):(u<c||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,s=c-u)),u=p}}l(n,e);let a=(t<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?s:o),t):Bc(n)}function Bc(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=Vt(e);return t[t.length-1]||null}function ws(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const $r=Object.create(null);function er(n,e,t){if(n==e)return!0;n||(n=$r),e||(e=$r);let i=Object.keys(n),s=Object.keys(e);if(i.length-(t&&i.indexOf(t)>-1?1:0)!=s.length-(t&&s.indexOf(t)>-1?1:0))return!1;for(let r of i)if(r!=t&&(s.indexOf(r)==-1||n[r]!==e[r]))return!1;return!0}function ks(n,e,t){let i=!1;if(e)for(let s in e)t&&s in t||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(i=!0,s=="style"?n.style.cssText=t[s]:n.setAttribute(s,t[s]));return i}function Pc(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class Dt{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}destroy(e){}}var _=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(_||(_={}));class B extends wt{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 ki(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new ct(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}=Vl(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new ct(e,i,s,t,e.widget||null,!0)}static line(e){return new Si(e)}static set(e,t=!1){return K.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}B.none=K.empty;class ki extends B{constructor(e){let{start:t,end:i}=Vl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,i;return this==e||e instanceof ki&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((i=e.attrs)===null||i===void 0?void 0:i.class))&&er(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}ki.prototype.point=!1;class Si extends B{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Si&&this.spec.class==e.spec.class&&er(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)}}Si.prototype.mapMode=he.TrackBefore;Si.prototype.point=!0;class ct extends B{constructor(e,t,i,s,r,o){super(t,i,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?he.TrackBefore:he.TrackAfter:he.TrackDel}get type(){return this.startSide<this.endSide?_.WidgetRange:this.startSide<=0?_.WidgetBefore:_.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof ct&&Lc(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)}}ct.prototype.point=!0;function Vl(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function Lc(n,e){return n==e||!!(n&&e&&n.compare(e))}function Ss(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 V{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),Rl(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){er(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){Hl(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=ws(t,this.attrs||{})),i&&(this.attrs=ws({class:i},this.attrs||{}))}domAtPos(e){return Fl(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var i;this.dom?this.flags&4&&(Tl(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&&(ks(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let s=this.dom.lastChild;for(;s&&V.get(s)instanceof Qe;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=V.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!A.ios||!this.children.some(r=>r instanceof _e))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let i of this.children){if(!(i instanceof _e)||/[^ -~]/.test(i.text))return null;let s=Vt(i.dom);if(s.length!=1)return null;e+=s[0].width,t=s[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let i=Wl(this,e,t);if(!this.children.length&&i&&this.parent){let{heightOracle:s}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-s.lineHeight)<2&&s.textHeight<r){let o=(r-s.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(e){return!1}get type(){return _.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 xt extends V{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 xt)||!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?de.before(this.dom):de.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let i=new xt(this.widget,t,this.type);return i.breakAfter=this.breakAfter,i}get children(){return Zs}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.dom.contentEditable="false")}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):I.empty}domBoundsAround(){return null}become(e){return e instanceof xt&&e.widget.constructor==this.widget.constructor?(e.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.type=e.type,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(e,t){return this.widget.coordsAt(this.dom,e,t)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class ai{constructor(e,t,i,s){this.doc=e,this.pos=t,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!e.breakAfter&&!(e instanceof xt&&e.type==_.WidgetBefore)}getLine(){return this.curLine||(this.content.push(this.curLine=new ue),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ti(new zt(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||this.getLine()}buildText(e,t,i){for(;e>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(Ti(new _e(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 ct){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 ct)if(i.block){let{type:a}=i;a==_.WidgetAfter&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new xt(i.widget||new jr("div"),l,a))}else{let a=mt.create(i.widget||new jr("span"),l,l?0:i.startSide),h=this.atCursorPos&&!a.isEditable&&r<=s.length&&(e<t||i.startSide>0),c=!a.isEditable&&(e<t||r>s.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!h&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),h&&(f.append(Ti(new zt(1),s),r),r=s.length+Math.max(0,r-s.length)),f.append(Ti(a,s),r),this.atCursorPos=c,this.pendingBuffer=c?e<t||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,i,s,r){let o=new ai(e,t,i,r);return o.openEnd=K.spans(s,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Ti(n,e){for(let t of e)n=new Qe(t,[n],n.length);return n}class jr extends Dt{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}const zl=D.define(),ql=D.define(),Kl=D.define(),$l=D.define(),vs=D.define(),jl=D.define(),Ul=D.define(),Gl=D.define({combine:n=>n.some(e=>e)}),Jl=D.define({combine:n=>n.some(e=>e)});class ln{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 ln(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin)}}const Ur=E.define({map:(n,e)=>n.map(e)});function Ie(n,e,t){let i=n.facet($l);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 On=D.define({combine:n=>n.length?n[0]:!0});let Rc=0;const ii=D.define();class ge{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 ge(Rc++,e,i,o=>{let l=[ii.of(o)];return r&&l.push(ui.of(a=>{let h=a.plugin(o);return h?r(h):B.none})),s&&l.push(s(o)),l})}static fromClass(e,t){return ge.define(i=>new e(i),t)}}class zn{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(Ie(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){Ie(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){Ie(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const _l=D.define(),tr=D.define(),ui=D.define(),ir=D.define(),Xl=D.define();function Gr(n,e,t){let i=n.state.facet(Xl);if(!i.length)return i;let s=i.map(o=>o instanceof Function?o(n):o),r=[];return K.spans(s,e,t,{point(){},span(o,l,a,h){let c=r;for(let f=a.length-1;f>=0;f--,h--){let u=a[f].spec.bidiIsolate,d;if(u!=null)if(h>0&&c.length&&(d=c[c.length-1]).to==o&&d.direction==u)d.to=l,c=d.inner;else{let p={from:o,to:l,direction:u,inner:[]};c.push(p),c=p.inner}}}}),r}const Yl=D.define();function Ql(n){let e=0,t=0,i=0,s=0;for(let r of n.state.facet(Yl)){let o=r(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:i,bottom:s}}const ni=D.define();class Le{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new Le(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==e.length?null:e[s],h=o-l,c=a?a.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 Le(d+h,p+h,d,p).addToSet(i),u>c)break;r+=2}if(!a)return i;new Le(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class an{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=Z.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new Le(r,o,l,a))),this.changedRanges=s}static create(e,t,i){return new an(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 J=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(J||(J={}));const di=J.LTR,Zl=J.RTL;function ea(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const Ec=ea("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Ic=ea("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Cs=Object.create(null),He=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Cs[e]=t,Cs[t]=-e}function Nc(n){return n<=247?Ec[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Ic[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8203?256:64336<=n&&n<=65023?4:n==8204?256:1}const Fc=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class st{get dir(){return this.level%2?Zl:di}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function ta(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],s=e[t];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!ta(i.inner,s.inner))return!1}return!0}const F=[];function Hc(n,e,t,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:s;for(let h=o,c=a,f=a;h<l;h++){let u=Nc(n.charCodeAt(h));u==512?u=c:u==8&&f==4&&(u=16),F[h]=u==4?2:u,u&7&&(f=u),c=u}for(let h=o,c=a,f=a;h<l;h++){let u=F[h];if(u==128)h<l-1&&c==F[h+1]&&c&24?u=F[h]=c:F[h]=256;else if(u==64){let d=h+1;for(;d<l&&F[d]==64;)d++;let p=h&&c==8||d<t&&F[d]==8?f==1?1:8:256;for(let g=h;g<d;g++)F[g]=p;h=d-1}else u==8&&f==1&&(F[h]=1);c=u,u&7&&(f=u)}}}function Wc(n,e,t,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,c=o<i.length?i[o].from:t;for(let f=h,u,d,p;f<c;f++)if(d=Cs[u=n.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(He[g+1]==-d){let m=He[g+2],y=m&2?s:m&4?m&1?r:s:0;y&&(F[f]=F[He[g]]=y),l=g;break}}else{if(He.length==189)break;He[l++]=f,He[l++]=u,He[l++]=a}else if((p=F[f])==2||p==1){let g=p==s;a=g?0:1;for(let m=l-3;m>=0;m-=3){let y=He[m+2];if(y&2)break;if(g)He[m+2]|=2;else{if(y&4)break;He[m+2]|=4}}}}}function Vc(n,e,t,i){for(let s=0,r=i;s<=t.length;s++){let o=s?t[s-1].to:n,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let h=F[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==t.length)break;c=t[s++].to,l=s<t.length?t[s].from:e}else if(F[c]==256)c++;else break;let f=r==1,u=(c<e?F[c]:i)==1,d=f==u?f?1:2:i;for(let p=c,g=s,m=g?t[g-1].to:n;p>a;)p==m&&(p=t[--g].from,m=g?t[g-1].to:n),F[--p]=d;a=c}else r=h,a++}}}function As(n,e,t,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=e,h=0;a<t;){let c=!0,f=!1;if(h==r.length||a<r[h].from){let g=F[a];g!=l&&(c=!1,f=g==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(f)break e;let g=r[h];if(!c)for(let m=g.to,y=h+1;;){if(m==t)break e;if(y<r.length&&r[y].from==m)m=r[y++].to;else{if(F[m]==l)break e;break}}if(h++,u)u.push(g);else{g.from>a&&o.push(new st(a,g.from,d));let m=g.direction==di!=!(d%2);Ms(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==t||(c?F[p]!=l:F[p]==l))break;p++}u?As(n,a,p,i+1,s,u,o):a<p&&o.push(new st(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let c=!0,f=!1;if(!h||a>r[h-1].to){let g=F[a-1];g!=l&&(c=!1,f=g==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(f)break e;let g=r[--h];if(!c)for(let m=g.from,y=h;;){if(m==e)break e;if(y&&r[y-1].to==m)m=r[--y].from;else{if(F[m-1]==l)break e;break}}if(u)u.push(g);else{g.to<a&&o.push(new st(g.to,a,d));let m=g.direction==di!=!(d%2);Ms(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==e||(c?F[p-1]!=l:F[p-1]==l))break;p--}u?As(n,p,a,i+1,s,u,o):p<a&&o.push(new st(p,a,d)),a=p}}function Ms(n,e,t,i,s,r,o){let l=e%2?2:1;Hc(n,s,r,i,l),Wc(n,s,r,i,l),Vc(s,r,i,l),As(n,s,r,e,t,i,o)}function zc(n,e,t){if(!n)return[new st(0,0,e==Zl?1:0)];if(e==di&&!t.length&&!Fc.test(n))return ia(n.length);if(t.length)for(;n.length>F.length;)F[F.length]=256;let i=[],s=e==di?0:1;return Ms(n,s,s,t,0,n.length,i),i}function ia(n){return[new st(0,n,0)]}let na="";function qc(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=st.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc));let a=e[l];o==a.side(s,t)&&(a=e[l+=s?1:-1],o=a.side(!s,t));let h=s==(a.dir==t),c=ce(n.text,o,h);if(na=n.text.slice(Math.min(o,c),Math.max(o,c)),c!=a.side(s,t))return b.cursor(c+n.from,h?-1:1,a.level);let f=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return!f&&a.level!=t?b.cursor(s?n.to:n.from,s?-1:1,t):f&&f.level<a.level?b.cursor(f.side(!s,t)+n.from,s?1:-1,f.level):b.cursor(c+n.from,s?-1:1,a.level)}class Jr extends V{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[],this.hasComposition=null,this.markedForComposition=new Set,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 Le(0,0,0,e.state.doc.length)],0,null)}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:l,toA:a})=>a<this.minWidthFrom||l>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);let i=this.view.inputState.composing<0?null:$c(this.view,e.changes);if(this.hasComposition){this.markedForComposition.clear();let{from:l,to:a}=this.hasComposition;t=new Le(l,a,e.changes.mapPos(l,-1),e.changes.mapPos(a,1)).addToSet(t.slice())}this.hasComposition=i?{from:i.range.fromB,to:i.range.toB}:null,(A.ie||A.chrome)&&!i&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let s=this.decorations,r=this.updateDeco(),o=Gc(s,r,e.changes);return t=Le.extendWithRanges(t,o),!(this.flags&7)&&t.length==0?!1:(this.updateInner(t,e.startState.doc.length,i),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=A.chrome||A.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||s.selectionRange.focusNode!=o.node)&&(this.forceSelection=!0),this.dom.style.height=""}),this.markedForComposition.forEach(o=>o.flags&=-9);let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let o of this.children)o instanceof xt&&o.widget instanceof _r&&r.push(o.dom);s.updateGaps(r)}updateChildren(e,t,i){let s=i?i.range.addToSet(e.slice()):e,r=this.childCursor(t);for(let o=s.length-1;;o--){let l=o>=0?s[o]:null;if(!l)break;let{fromA:a,toA:h,fromB:c,toB:f}=l,u,d,p,g;if(i&&i.range.fromB<f&&i.range.toB>c){let x=ai.build(this.view.state.doc,c,i.range.fromB,this.decorations,this.dynamicDecorationMap),w=ai.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=x.breakAtStart,p=x.openStart,g=w.openEnd;let k=this.compositionView(i);w.breakAtStart?k.breakAfter=1:w.content.length&&k.merge(k.length,k.length,w.content[0],!1,w.openStart,0)&&(k.breakAfter=w.content[0].breakAfter,w.content.shift()),x.content.length&&k.merge(0,0,x.content[x.content.length-1],!0,0,x.openEnd)&&x.content.pop(),u=x.content.concat(k).concat(w.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=ai.build(this.view.state.doc,c,f,this.decorations,this.dynamicDecorationMap));let{i:m,off:y}=r.findPos(h,1),{i:S,off:M}=r.findPos(a,-1);Ll(this,S,M,m,y,u,d,p,g)}i&&this.fixCompositionDOM(i)}compositionView(e){let t=new _e(e.text.nodeValue);t.flags|=8;for(let{deco:s}of e.marks)t=new Qe(s,[t],t.length);let i=new ue;return i.append(t,0),i}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8,this.markedForComposition.add(o);let l=V.get(r);l!=o&&(l&&(l.dom=null),o.setDOM(r))},i=this.childPos(e.range.fromB,1),s=this.children[i.i];t(e.line,s);for(let r=e.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],t(r>=0?e.marks[r].node:e.text,s)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&_i(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||t||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.domAtPos(l.anchor),h=l.empty?a:this.domAtPos(l.head);if(A.gecko&&l.empty&&!this.hasComposition&&Kc(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=h=new de(f,0),o=!0}let c=this.view.observer.selectionRange;(o||!c.focusNode||!rn(a.node,a.offset,c.anchorNode,c.anchorOffset)||!rn(h.node,h.offset,c.focusNode,c.focusOffset))&&(this.view.observer.ignore(()=>{A.android&&A.chrome&&this.dom.contains(c.focusNode)&&Jc(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=sn(this.view.root);if(f)if(l.empty){if(A.gecko){let u=jc(a.node,a.offset);if(u&&u!=3){let d=ra(a.node,a.offset,u==1?1:-1);d&&(a=new de(d,u==1?0:d.nodeValue.length))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&c.caretBidiLevel!=null&&(c.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(h.node,h.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([a,h]=[h,a]),u.setEnd(h.node,h.offset),u.setStart(a.node,a.offset),f.removeAllRanges(),f.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(a,h)),this.impreciseAnchor=a.precise?null:new de(c.anchorNode,c.anchorOffset),this.impreciseHead=h.precise?null:new de(c.focusNode,c.focusOffset)}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=sn(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=ue.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(s,r)}nearest(e){for(let t=e;t;){let i=V.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!=_.WidgetBefore&&r.type!=_.WidgetAfter&&(!s||t==2||this.children[s-1].breakAfter||this.children[s-1].type==_.WidgetBefore&&t>-2))return r.coordsAt(e-o,t);i=o}}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),s=this.children[t];if(!(s instanceof ue))return null;for(;s.children.length;){let{i:l,off:a}=s.childPos(i,1);for(;;l++){if(l==s.children.length)return null;if((s=s.children[l]).length)break}i=a}if(!(s instanceof _e))return null;let r=ce(s.text,i);if(r==i)return null;let o=St(s.dom,i,r).getClientRects();return!o.length||o[0].top>=o[0].bottom?null:o[0]}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==J.LTR;for(let h=0,c=0;c<this.children.length;c++){let f=this.children[c],u=h+f.length;if(u>s)break;if(h>=i){let d=f.dom.getBoundingClientRect();if(t.push(d.height),o){let p=f.dom.lastChild,g=p?Vt(p):[];if(g.length){let m=g[g.length-1],y=a?m.right-d.left:d.right-m.left;y>l&&(l=y,this.minWidth=r,this.minWidthFrom=h,this.minWidthTo=u)}}}h=u+f.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?J.RTL:J.LTR}measureTextSize(){for(let r of this.children)if(r instanceof ue){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,i,s;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let r=Vt(e.firstChild)[0];t=e.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:i,textHeight:s}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Pl(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(B.replace({widget:new _r(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return B.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.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=Ql(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom};vc(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,e.xMargin,e.yMargin,this.view.textDirection==J.LTR)}}function Kc(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 _r extends Dt{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 sa(n,e){let t=n.observer.selectionRange,i=t.focusNode&&ra(t.focusNode,t.focusOffset,0);if(!i)return null;let s=V.get(i),r,o;if(s instanceof _e)r=s.posAtStart,o=r+s.length;else{let l=Math.max(0,i.nodeValue.length-e);e:for(let a=0,h=i;;){for(let f=h.previousSibling,u;f;f=f.previousSibling){if(u=V.get(f)){o=u.posAtEnd+a,r=Math.max(0,o-l);break e}let d=new El([],n.state);if(d.readNode(f),d.text.indexOf(Rt)>-1)return null;a+=d.text.length}if(h=h.parentNode,!h)return null;let c=V.get(h);if(c){r=c.posAtStart+a,o=r+l;break}}}return{from:r,to:o,node:i}}function $c(n,e){let t=sa(n,e.newLength-e.length);if(!t)return null;let{from:i,to:s,node:r}=t,o=e.mapPos(i,-1),l=e.mapPos(s,1),a=r.nodeValue;if(/[\n\r]/.test(a))return null;if(l-o!=a.length){let u=e.mapPos(i,1),d=e.mapPos(s,-1);if(d-u==a.length)o=u,l=d;else if(n.state.doc.sliceString(l-a.length,l)==a)o=l-a.length;else if(n.state.doc.sliceString(o,o+a.length)==a)l=o+a.length;else return null}let{main:h}=n.state.selection;if(n.state.doc.sliceString(o,l)!=a||o>h.head||l<h.head)return null;let c=[],f=new Le(i,s,o,l);for(let u=r.parentNode;;u=u.parentNode){let d=V.get(u);if(d instanceof Qe)c.push({node:u,deco:d.mark});else{if(d instanceof ue||u.nodeName=="DIV"&&u.parentNode==n.contentDOM)return{range:f,text:r,marks:c,line:u};if(u!=n.contentDOM)c.push({node:u,deco:new ki({inclusive:!0,attributes:Pc(u),tagName:u.tagName.toLowerCase()})});else return null}}}function ra(n,e,t){if(t<=0)for(let i=n,s=e;;){if(i.nodeType==3)return i;if(i.nodeType==1&&s>0)i=i.childNodes[s-1],s=ht(i);else break}if(t>=0)for(let i=n,s=e;;){if(i.nodeType==3)return i;if(i.nodeType==1&&s<i.childNodes.length&&t>=0)i=i.childNodes[s],s=0;else break}return null}function jc(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let Uc=class{constructor(){this.changes=[]}compareRange(e,t){Ss(e,t,this.changes)}comparePoint(e,t){Ss(e,t,this.changes)}};function Gc(n,e,t){let i=new Uc;return K.compare(n,e,t,i),i.changes}function Jc(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 _c(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return b.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=ce(s.text,r,!1):l=ce(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let h=ce(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=ce(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return b.range(o+s.from,l+s.from)}function Xc(n,e){return e.left>n?e.left-n:Math.max(0,n-e.right)}function Yc(n,e){return e.top>n?e.top-n:Math.max(0,n-e.bottom)}function qn(n,e){return n.top<e.bottom-1&&n.bottom>e.top+1}function Xr(n,e){return e<n.top?{top:e,left:n.left,right:n.right,bottom:n.bottom}:n}function Yr(n,e){return e>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:e}:n}function Ds(n,e,t){let i,s,r,o,l=!1,a,h,c,f;for(let p=n.firstChild;p;p=p.nextSibling){let g=Vt(p);for(let m=0;m<g.length;m++){let y=g[m];s&&qn(s,y)&&(y=Xr(Yr(y,s.bottom),s.top));let S=Xc(e,y),M=Yc(t,y);if(S==0&&M==0)return p.nodeType==3?Qr(p,e,t):Ds(p,e,t);if(!i||o>M||o==M&&r>S){i=p,s=y,r=S,o=M;let x=M?t<y.top?-1:1:S?e<y.left?-1:1:0;l=!x||(x>0?m<g.length-1:m>0)}S==0?t>y.bottom&&(!c||c.bottom<y.bottom)?(a=p,c=y):t<y.top&&(!f||f.top>y.top)&&(h=p,f=y):c&&qn(c,y)?c=Yr(c,y.bottom):f&&qn(f,y)&&(f=Xr(f,y.top))}}if(c&&c.bottom>=t?(i=a,s=c):f&&f.top<=t&&(i=h,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 Ds(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 a=St(n,l,l+1).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];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)&&St(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 oa(n,e,t,i=-1){var s,r;let o=n.contentDOM.getBoundingClientRect(),l=o.top+n.viewState.paddingTop,a,{docHeight:h}=n.viewState,{x:c,y:f}=e,u=f-l;if(u<0)return 0;if(u>h)return n.state.doc.length;for(let x=n.viewState.heightOracle.textHeight/2,w=!1;a=n.elementAtHeight(u),a.type!=_.Text;)for(;u=i>0?a.bottom+x:a.top-x,!(u>=0&&u<=h);){if(w)return t?null:0;w=!0,i=-i}f=l+u;let d=a.from;if(d<n.viewport.from)return n.viewport.from==0?0:t?null:Zr(n,o,a,c,f);if(d>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:t?null:Zr(n,o,a,c,f);let p=n.dom.ownerDocument,g=n.root.elementFromPoint?n.root:p,m=g.elementFromPoint(c,f);m&&!n.contentDOM.contains(m)&&(m=null),m||(c=Math.max(o.left+1,Math.min(o.right-1,c)),m=g.elementFromPoint(c,f),m&&!n.contentDOM.contains(m)&&(m=null));let y,S=-1;if(m&&((s=n.docView.nearest(m))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let x=p.caretPositionFromPoint(c,f);x&&({offsetNode:y,offset:S}=x)}else if(p.caretRangeFromPoint){let x=p.caretRangeFromPoint(c,f);x&&({startContainer:y,startOffset:S}=x,(!n.contentDOM.contains(y)||A.safari&&Qc(y,S,c)||A.chrome&&Zc(y,S,c))&&(y=void 0))}}if(!y||!n.docView.dom.contains(y)){let x=ue.find(n.docView,d);if(!x)return u>a.top+a.height/2?a.to:a.from;({node:y,offset:S}=Ds(x.dom,c,f))}let M=n.docView.nearest(y);if(!M)return null;if(M.isWidget&&((r=M.dom)===null||r===void 0?void 0:r.nodeType)==1){let x=M.dom.getBoundingClientRect();return e.y<x.top||e.y<=x.bottom&&e.x<=(x.left+x.right)/2?M.posAtStart:M.posAtEnd}else return M.localPosFromDOM(y,S)+M.posAtStart}function Zr(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+ds(o,r,n.state.tabSize)}function Qc(n,e,t){let i;if(n.nodeType!=3||e!=(i=n.nodeValue.length))return!1;for(let s=n.nextSibling;s;s=s.nextSibling)if(s.nodeType!=1||s.nodeName!="BR")return!1;return St(n,i-1,i).getBoundingClientRect().left>t}function Zc(n,e,t){if(e!=0)return!1;for(let s=n;;){let r=s.parentNode;if(!r||r.nodeType!=1||r.firstChild!=s)return!1;if(r.classList.contains("cm-line"))break;s=r}let i=n.nodeType==1?n.getBoundingClientRect():St(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function Os(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==_.Text))return i}return t}function ef(n,e,t,i){let s=Os(n,e.head),r=!i||s.type!=_.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==J.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return b.cursor(a,t?-1:1)}return b.cursor(t?s.to:s.from,t?-1:1)}function eo(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let h=qc(s,r,o,l,t),c=na;if(!h){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),h=b.cursor(t?s.from:s.to)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function tf(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==$.Space&&(s=o),s==o}}function nf(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return b.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s),c=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let d=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-d.from))),l=(r<0?d.top:d.bottom)+c}let f=a.left+o,u=i??n.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=oa(n,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<s:g>s))return b.cursor(g,e.assoc,void 0,o)}}function Xi(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function Kn(n,e,t){let i=Xi(n.state.facet(ir).map(s=>s(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:b.cursor(i,i<t.from?1:-1)}class sf{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}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.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null;let t=(i,s)=>{this.ignoreDuringComposition(s)||s.type=="keydown"&&this.keydown(e,s)||(this.mustFlushObserver(s)&&e.observer.forceFlush(),this.runCustomHandlers(s.type,e,s)?s.preventDefault():i(e,s))};for(let i in X){let s=X[i];e.contentDOM.addEventListener(i,r=>{to(e,r)&&t(s,r)},Ts[i]),this.registeredEvents.push(i)}e.scrollDOM.addEventListener("mousedown",i=>{if(i.target==e.scrollDOM&&i.clientY>e.contentDOM.getBoundingClientRect().bottom&&(t(X.mousedown,i),!i.defaultPrevented&&i.button==2)){let s=e.contentDOM.style.minHeight;e.contentDOM.style.minHeight="100%",setTimeout(()=>e.contentDOM.style.minHeight=s,200)}}),e.scrollDOM.addEventListener("drop",i=>{i.target==e.scrollDOM&&i.clientY>e.contentDOM.getBoundingClientRect().bottom&&t(X.drop,i)}),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),A.gecko&&bf(e.contentDOM.ownerDocument)}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=>{to(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){Ie(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){Ie(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(t.keyCode!=27&&aa.indexOf(t.keyCode)<0&&(e.inputState.lastEscPress=0),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=la.find(s=>s.keyCode==t.keyCode))&&!t.ctrlKey||rf.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,Ft(e.contentDOM,t.key,t.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:A.safari&&!A.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!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 la=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],rf="dthko",aa=[16,17,18,20,91,92,224,225],Bi=6;function Pi(n){return Math.max(0,n)*.7+8}function of(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class lf{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=Cc(e.contentDOM),this.atoms=e.state.facet(ir).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(N.allowMultipleSelections)&&af(e,t),this.dragging=cf(e,t)&&ua(t)==1?null:!1}start(e){this.dragging===!1&&(e.preventDefault(),this.select(e))}move(e){var t;if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&of(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let i=0,s=0,r=((t=this.scrollParent)===null||t===void 0?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=Ql(this.view);e.clientX-o.left<=r.left+Bi?i=-Pi(r.left-e.clientX):e.clientX+o.right>=r.right-Bi&&(i=Pi(e.clientX-r.right)),e.clientY-o.top<=r.top+Bi?s=-Pi(r.top-e.clientY):e.clientY+o.bottom>=r.bottom-Bi&&(s=Pi(e.clientY-r.bottom)),this.setScrollSpeed(i,s)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;i<e.ranges.length;i++){let s=e.ranges[i],r=null;if(s.empty){let o=Xi(this.atoms,s.from,0);o!=s.from&&(r=b.cursor(o,-1))}else{let o=Xi(this.atoms,s.from,-1),l=Xi(this.atoms,s.to,1);(o!=s.from||l!=s.to)&&(r=b.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?b.create(t,e.mainIndex):e}select(e){let{view:t}=this,i=this.skipAtoms(this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection)||i.main.assoc!=t.state.selection.main.assoc&&this.dragging===!1)&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),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 af(n,e){let t=n.state.facet(zl);return t.length?t[0](e):A.mac?e.metaKey:e.ctrlKey}function hf(n,e){let t=n.state.facet(ql);return t.length?t[0](e):A.mac?!e.altKey:!e.ctrlKey}function cf(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=sn(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 to(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=V.get(t))&&i.ignoreEvent(e))return!1;return!0}const X=Object.create(null),Ts=Object.create(null),ha=A.ie&&A.ie_version<15||A.ios&&A.webkit_version<604;function ff(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(),ca(n,t.value)},50)}function ca(n,e){let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Bs!=null&&t.selection.ranges.every(a=>a.empty)&&Bs==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:b.cursor(h.from+f.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:b.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}X.keydown=(n,e)=>{n.inputState.setSelectionOrigin("select"),e.keyCode==27&&(n.inputState.lastEscPress=Date.now())};X.touchstart=(n,e)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};X.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ts.touchstart=Ts.touchmove={passive:!0};X.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return;let t=null;for(let i of n.state.facet(Kl))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=pf(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new lf(n,e,t,i)),i&&n.observer.ignore(()=>Ol(n.contentDOM)),n.inputState.mouseSelection&&n.inputState.mouseSelection.start(e)}};function io(n,e,t,i){if(i==1)return b.cursor(e,t);if(i==2)return _c(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++,b.range(o,l)}}let fa=(n,e)=>n>=e.top&&n<=e.bottom,no=(n,e,t)=>fa(e,t)&&n>=t.left&&n<=t.right;function uf(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&&no(t,i,o))return-1;let l=s.coordsAt(r,1);return l&&no(t,i,l)?1:o&&fa(i,o)?-1:1}function so(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:uf(n,t,e.clientX,e.clientY)}}const df=A.ie&&A.ie_version<=11;let ro=null,oo=0,lo=0;function ua(n){if(!df)return n.detail;let e=ro,t=lo;return ro=n,lo=Date.now(),oo=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(oo+1)%3:1}function pf(n,e){let t=so(n,e),i=ua(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=so(n,r),h,c=io(n,a.pos,a.bias,i);if(t.pos!=a.pos&&!o){let f=io(n,t.pos,t.bias,i),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u<c.from?b.range(u,d):b.range(d,u)}return o?s.replaceRange(s.main.extend(c.from,c.to)):l&&i==1&&s.ranges.length>1&&(h=gf(s,a.pos))?h:l?s.addRange(c):b.create([c])}}}function gf(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:s}=n.ranges[t];if(i<=e&&s>=e)return b.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}X.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 ao(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&&hf(n,e)?{from:r.dragging.from,to:r.dragging.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"})}X.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&&ao(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 ao(n,e,e.dataTransfer.getData("Text"),!0)};X.paste=(n,e)=>{if(n.state.readOnly)return e.preventDefault();n.observer.flush();let t=ha?null:e.clipboardData;t?(ca(n,t.getData("text/plain")||t.getData("text/uri-text")),e.preventDefault()):ff(n)};function mf(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 yf(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 Bs=null;X.copy=X.cut=(n,e)=>{let{text:t,ranges:i,linewise:s}=yf(n.state);if(!t&&!s)return;Bs=s?t:null;let r=ha?null:e.clipboardData;r?(e.preventDefault(),r.clearData(),r.setData("text/plain",t)):mf(n,t),e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"})};const da=Ze.define();function pa(n,e){let t=[];for(let i of n.facet(Ul)){let s=i(n,e);s&&t.push(s)}return t?n.update({effects:t,annotations:da.of(!0)}):null}function ga(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=pa(n.state,e);t?n.dispatch(t):n.update([])}},10)}X.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),ga(n)};X.blur=n=>{n.observer.clearSelectionRange(),ga(n)};X.compositionstart=X.compositionupdate=n=>{n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0)};X.compositionend=n=>{n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,A.chrome&&A.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50)};X.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};X.beforeinput=(n,e)=>{var t;let i;if(A.chrome&&A.android&&(i=la.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 ho=new Set;function bf(n){ho.has(n)||(ho.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const co=["pre-wrap","normal","pre-line","break-spaces"];class xf{constructor(e){this.lineWrapping=e,this.doc=I.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return co.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=co.indexOf(e)>-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class wf{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class $e{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?_.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof ct?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new $e(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var q=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(q||(q={}));const Yi=.001;class pe{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)>Yi&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return pe.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=s[l],u=r.lineAt(a,q.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,q.ByPosNoHeight,i,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,q.ByPosNoHeight,i,0,0));c+=u.from-a,a=u.from;let p=nr.build(i.setDoc(o),e,c,f);r=r.replace(a,h,p)}return r.updateHeight(i,0)}static empty(){return new Ae(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 kf(pe.of(e.slice(0,t)),o,pe.of(e.slice(i)))}}pe.prototype.size=1;class ma extends pe{constructor(e,t,i){super(e,t),this.deco=i}blockAt(e,t,i,s){return new $e(s,this.length,i,this.height,this.deco||0)}lineAt(e,t,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(e,t,i,s,r,o){e<=r+this.length&&t>=r&&o(this.blockAt(0,i,s,r))}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setHeight(e,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ae extends ma{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,s){return new $e(s,this.length,i,this.height,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof Ae||s instanceof ie&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ie?s=new Ae(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):pe.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setHeight(e,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ie extends pe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let h=s+Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length),c=t.doc.lineAt(h),f=l+c.length*a,u=Math.max(i,e-f/2);return new $e(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:c,length:f}=t.doc.line(r+h);return new $e(c,f,i+l*h,l,0)}}lineAt(e,t,i,s,r){if(t==q.ByHeight)return this.blockAt(e,i,s,r);if(t==q.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new $e(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),c=l+h.length*a,f=h.number-o,u=s+l*f+a*(h.from-r-f);return new $e(h.from,h.length,Math.max(s,Math.min(u,s+this.height-c)),c,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=e,f=s;c<=t;){let u=i.doc.lineAt(c);if(c==e){let p=u.number-l;f+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new $e(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof ie?i[i.length-1]=new ie(r.length+s):i.push(null,new ie(s-1))}if(e>0){let r=i[0];r instanceof ie?i[0]=new ie(e+r.length):i.unshift(new ie(e-1),null)}return pe.of(i)}decomposeLeft(e,t){t.push(new ie(e-1),null)}decomposeRight(e,t){t.push(null,new ie(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new ie(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++];a==-1?a=f:Math.abs(f-a)>=Yi&&(a=-2);let u=new Ae(c,f);u.outdated=!1,o.push(u),l+=c+1}l<=r&&o.push(null,new ie(r-l).updateHeight(e,l));let h=pe.of(o);return(a<0||Math.abs(h.height-this.height)>=Yi||Math.abs(a-this.heightMetrics(e,t).perLine)>=Yi)&&(e.heightChanged=!0),h}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class kf extends pe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==q.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==q.ByPosNoHeight?q.ByPosNoHeight:q.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,q.ByPos,i,s,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,s,r,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&fo(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),fo(r,l)}return pe.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?pe.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function fo(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof ie&&(i=n[e+1])instanceof ie&&n.splice(e-1,3,new ie(t.length+1+i.length))}const Sf=5;class nr{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 Ae?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ae(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new ma(o,s,i)):(o||r||s>=Sf)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Ae(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new ie(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ae)return e;let t=new Ae(0,-1);return this.nodes.push(t),t}addBlock(e){var t;this.enterLine();let i=(t=e.deco)===null||t===void 0?void 0:t.type;i==_.WidgetAfter&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,i!=_.WidgetBefore&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ae)&&!this.isCovered?this.nodes.push(new Ae(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 Ae&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new nr(i,e);return K.spans(t,i,s,r,0),r.finish(i)}}function vf(n,e,t){let i=new Cf;return K.compare(n,e,t,i,0),i.changes}class Cf{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&Ss(e,t,this.changes,5)}}function Af(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,f=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&f.overflow!="visible"){let u=c.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),a=h==n.parentNode?u.bottom:Math.min(a,u.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function Mf(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class $n{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 B.replace({widget:new Df(this.size,e)}).range(this.from,this.to)}}class Df extends Dt{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 uo{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!0,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=po,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=J.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(tr).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new xf(t),this.stateDeco=e.facet(ui).filter(i=>typeof i!="function"),this.heightMap=pe.empty().applyChanges(this.stateDeco,I.empty,this.heightOracle.setDoc(e.doc),[new Le(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=B.set(this.lineGaps.map(i=>i.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 Li(r,o))}}this.viewports=e.sort((i,s)=>i.from-s.from),this.scaler=this.heightMap.height<=7e6?po:new Bf(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:si(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(ui).filter(c=>typeof c!="function");let s=e.changedRanges,r=Le.extendWithRanges(s,vf(i,this.stateDeco,e?e.changes:Z.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=!e.changes.empty||e.flags&2||a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,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&&!e.state.facet(Jl)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?J.RTL:J.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0,f=parseInt(i.paddingTop)||0,u=parseInt(i.paddingBottom)||0;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8),this.scrollTop!=e.scrollDOM.scrollTop&&(this.scrollAnchorHeight=-1,this.scrollTop=e.scrollDOM.scrollTop),this.scrolledToBottom=Bl(e.scrollDOM);let d=(this.printing?Mf:Af)(t,this.paddingTop),p=d.top-this.pixelViewport.top,g=d.bottom-this.pixelViewport.bottom;this.pixelViewport=d;let m=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(m!=this.inView&&(this.inView=m,m&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let y=l.width;if((this.contentDOMWidth!=y||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=8),a){let M=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(M)&&(o=!0),o||s.lineWrapping&&Math.abs(y-this.contentDOMWidth)>s.charWidth){let{lineHeight:x,charWidth:w,textHeight:k}=e.docView.measureTextSize();o=x>0&&s.refresh(r,x,w,k,y/w,M),o&&(e.docView.minWidth=0,h|=8)}p>0&&g>0?c=Math.max(p,g):p<0&&g<0&&(c=Math.min(p,g)),s.heightChanged=!1;for(let x of this.viewports){let w=x.from==this.viewport.from?M:e.docView.measureVisibleLineHeights(x);this.heightMap=(o?pe.empty().applyChanges(this.stateDeco,I.empty,this.heightOracle,[new Le(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new wf(x.from,w))}s.heightChanged&&(h|=2)}let S=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(this.viewport=this.getViewport(c,this.scrollTarget)),this.updateForViewport(),(h&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),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.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new Li(s.lineAt(o-i*1e3,q.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,q.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,q.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new Li(s.lineAt(u-1e3/2,q.ByHeight,r,0,0).from,s.lineAt(u+c+1e3/2,q.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new Li(this.heightMap.lineAt(i,q.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,q.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,q.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,q.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new $n(t.mapPos(s.from),t.mapPos(s.to),s.size));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=J.LTR&&!i)return[];let l=[],a=(h,c,f,u)=>{if(c-h<r)return;let d=this.state.selection.main,p=[d.from];d.empty||p.push(d.to);for(let m of p)if(m>h&&m<c){a(h,m-10,f,u),a(m+10,c,f,u);return}let g=Tf(e,m=>m.from>=f.from&&m.to<=f.to&&Math.abs(m.from-h)<r&&Math.abs(m.to-c)<r&&!p.some(y=>m.from<y&&m.to>y));if(!g){if(c<f.to&&t&&i&&t.visibleRanges.some(m=>m.from<=c&&m.to>=c)){let m=t.moveToLineBoundary(b.cursor(c),!1,!0).head;m>h&&(c=m)}g=new $n(h,c,this.gapSize(f,h,c,u))}l.push(g)};for(let h of this.viewportLines){if(h.length<o)continue;let c=Of(h.from,h.to,this.stateDeco);if(c.total<o)continue;let f=this.scrollTarget?this.scrollTarget.range.head:null,u,d;if(i){let p=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,m;if(f!=null){let y=Ei(c,f),S=((this.visibleBottom-this.visibleTop)/2+p)/h.height;g=y-S,m=y+S}else g=(this.visibleTop-h.top-p)/h.height,m=(this.visibleBottom-h.top+p)/h.height;u=Ri(c,g),d=Ri(c,m)}else{let p=c.total*this.heightOracle.charWidth,g=s*this.heightOracle.charWidth,m,y;if(f!=null){let S=Ei(c,f),M=((this.pixelViewport.right-this.pixelViewport.left)/2+g)/p;m=S-M,y=S+M}else m=(this.pixelViewport.left-g)/p,y=(this.pixelViewport.right+g)/p;u=Ri(c,m),d=Ri(c,y)}u>h.from&&a(h.from,u,h,c),d<h.to&&a(d,h.to,h,c)}return l}gapSize(e,t,i,s){let r=Ei(s,i)-Ei(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){$n.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=B.set(e.map(t=>t.draw(this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];K.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)||si(this.heightMap.lineAt(e,q.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return si(this.heightMap.lineAt(this.scaler.fromDOM(e),q.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return si(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Li{constructor(e,t){this.from=e,this.to=t}}function Of(n,e,t){let i=[],s=n,r=0;return K.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 Ri({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 Ei(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 Tf(n,e){for(let t of n)if(e(t))return t}const po={toDOM(n){return n},fromDOM(n){return n},scale:1};class Bf{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,q.ByPos,e,0,0).top,c=t.lineAt(a,q.ByPos,e,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,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 si(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new $e(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>si(s,e)):n._content)}const Ii=D.define({combine:n=>n.join(" ")}),Ps=D.define({combine:n=>n.indexOf(!0)>-1}),Ls=lt.newName(),ya=lt.newName(),ba=lt.newName(),xa={"&light":"."+ya,"&dark":"."+ba};function Rs(n,e,t){return new lt(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 Pf=Rs("."+Ls,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},xa);class Lf{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=r||o?[]:If(e),a=new El(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Nf(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!ms(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!ms(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset);this.newSel=b.single(h,a)}}}function wa(n,e){let t,{newSel:i}=e,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=s.from,h=null;(r===8||A.android&&e.text.length<l-o)&&(a=s.to,h="end");let c=Ef(n.state.doc.sliceString(o,l,Rt),e.text,a-o,h);c&&(A.chrome&&r==13&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==Rt+Rt&&c.toB--,t={from:o+c.from,to:o+c.toA,insert:I.of(e.text.slice(c.from,c.toB).split(Rt))})}else i&&(!n.hasFocus&&n.state.facet(On)||i.main.eq(s))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!s.empty&&i&&i.main.empty?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:t&&t.from>=s.from&&t.to<=s.to&&(t.from!=s.from||t.to!=s.to)&&s.to-s.from-(t.to-t.from)<=4?t={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,t.from).append(t.insert).append(n.state.doc.slice(t.to,s.to))}:(A.mac||A.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:I.of([" "])}):A.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
|
||
`&&n.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:s.from,to:s.to,insert:I.of([" "])}),t){if(A.ios&&n.inputState.flushIOSKey(n)||A.android&&(t.from==s.from&&t.to==s.to&&t.insert.length==1&&t.insert.lines==2&&Ft(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||r==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&Ft(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&Ft(n.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,a=()=>l||(l=Rf(n,t,i));return n.state.facet(jl).some(h=>h(n,t.from,t.to,o,a))||n.dispatch(a()),!0}else if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Rf(n,e,t){let i,s=n.state,r=s.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let l=r.from<e.from?s.sliceDoc(r.from,e.from):"",a=r.to>e.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(l+e.insert.sliceString(0,void 0,n.state.lineBreak)+a))}else{let l=s.changes(e),a=t&&t.main.to<=l.newLength?t.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let h=n.state.sliceDoc(e.from,e.to),c=sa(n,e.insert.length-(e.to-e.from))||n.state.doc.lineAt(r.head),f=r.to-e.to,u=r.to-r.from;i=s.changeByRange(d=>{if(d.from==r.from&&d.to==r.to)return{changes:l,range:a||d.map(l)};let p=d.to-f,g=p-h.length;if(d.to-d.from!=u||n.state.sliceDoc(g,p)!=h||c&&d.to>=c.from&&d.from<=c.to)return{range:d};let m=s.changes({from:g,to:p,insert:e.insert}),y=d.to-r.to;return{changes:m,range:a?b.range(Math.max(0,a.anchor+y),Math.max(0,a.head+y)):d.map(m)}})}else i={changes:l,selection:a&&s.selection.replaceRange(a)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:o,scrollIntoView:!0})}function Ef(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&n.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function If(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 Nf(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?b.single(t+e,i+e):null}const Ff={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},jn=A.ie&&A.ie_version<=11;class Hf{constructor(e){this.view=e,this.active=!1,this.selectionRange=new Ac,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.resizeContent=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(A.ie&&A.ie_version<=11||A.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),jn&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM),this.resizeContent=new ResizeObserver(()=>this.view.requestMeasure()),this.resizeContent.observe(e.contentDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runScrollHandlers(this.view,e),this.intersecting&&this.view.measure()}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(On)?i.root.activeElement!=this.dom:!_i(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&&rn(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&&kc(this.dom.ownerDocument)==this.dom&&Wf(this.view)||sn(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=_i(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Dc(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,Ff),jn&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),jn&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Ft(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&_i(this.dom,this.selectionRange);return e<0&&!s?null:(e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1,new Lf(this.view,e,t,i))}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return!1;let i=this.view.state,s=wa(this.view,t);return this.view.state==i&&this.view.update([]),s}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let i=go(t,e.previousSibling||e.target.previousSibling,-1),s=go(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,s;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect(),(s=this.resizeContent)===null||s===void 0||s.disconnect();for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function go(n,e,t){for(;e;){let i=V.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 Wf(n){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.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 rn(l.node,l.offset,r,o)&&([i,s,r,o]=[r,o,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:o}}class O{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.style.cssText="position: fixed; top: -10000px",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(i=>i.forEach(s=>t(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Mc(e.parent)||document,this.viewState=new uo(e.state||N.create(e)),this.plugins=this.state.facet(ii).map(i=>new zn(i));for(let i of this.plugins)i.update(this);this.observer=new Hf(this),this.inputState=new sf(this),this.inputState.ensureHandlers(this,this.plugins),this.docView=new Jr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),e.parent&&e.parent.appendChild(this.dom)}dispatch(...e){let t=e.length==1&&e[0]instanceof ee?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,s,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(da))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=pa(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(N.phrases)!=this.state.facet(N.phrases))return this.setState(r);s=an.create(this,r,e),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new ln(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Ur)&&(f=d.value)}this.viewState.update(s,f),this.bidiCache=hn.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(ni)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Ii)!=s.state.facet(Ii)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!s.empty)for(let u of this.state.facet(vs))u(s);(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!wa(this,c)&&h.force&&Ft(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new uo(e),this.plugins=e.facet(ii).map(i=>new zn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView=new Jr(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(ii),i=e.state.facet(ii);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new zn(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;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,{scrollTop:s}=i,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;s!=this.viewState.scrollTop&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Bl(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure(this);if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(d=>{try{return d.read(this)}catch(p){return Ie(this.state,p),mo}}),f=an.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f));for(let d=0;d<h.length;d++)if(c[d]!=mo)try{let p=h[d];p.write&&p.write(c[d],this)}catch(p){Ie(this.state,p)}if(u&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null;continue}else{let p=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(p>1||p<-1){s=i.scrollTop=s+p,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(vs))l(t)}get themeClasses(){return Ls+" "+(this.state.facet(Ps)?ba:ya)+" "+this.state.facet(Ii)}updateAttrs(){let e=yo(this,_l,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(On)?"true":"false",class:"cm-content",style:`${A.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),yo(this,tr,t);let i=this.observer.ignore(()=>{let s=ks(this.contentDOM,this.contentAttrs,t),r=ks(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(ni);let e=this.state.facet(O.cspNonce);lt.mount(this.root,this.styleModules.concat(Pf).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.spec!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}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 Kn(this,e,eo(this,e,t,i))}moveByGroup(e,t){return Kn(this,e,eo(this,e,t,i=>tf(this,e.head,i)))}moveToLineBoundary(e,t,i=!0){return ef(this,e,t,i)}moveVertically(e,t,i){return Kn(this,e,nf(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(),oa(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[st.find(r,e-s.from,-1,t)];return Mn(i,o.dir==J.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Gl)||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>Vf)return ia(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||ta(r.isolates,i=Gr(this,e.from,e.to))))return r.order;i||(i=Gr(this,e.from,e.to));let s=zc(e.text,t,i);return this.bidiCache.push(new hn(e.from,e.to,t,i,!0,s)),s}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(()=>{Ol(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Ur.of(new ln(typeof e=="number"?b.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}static domEventHandlers(e){return ge.define(()=>({}),{eventHandlers:e})}static theme(e,t){let i=lt.newName(),s=[Ii.of(i),ni.of(Rs(`.${i}`,e))];return t&&t.dark&&s.push(Ps.of(!0)),s}static baseTheme(e){return At.lowest(ni.of(Rs("."+Ls,e,xa)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&V.get(i)||V.get(e);return((t=s==null?void 0:s.rootView)===null||t===void 0?void 0:t.view)||null}}O.styleModule=ni;O.inputHandler=jl;O.focusChangeEffect=Ul;O.perLineTextDirection=Gl;O.exceptionSink=$l;O.updateListener=vs;O.editable=On;O.mouseSelectionStyle=Kl;O.dragMovesSelection=ql;O.clickAddsSelectionRange=zl;O.decorations=ui;O.atomicRanges=ir;O.bidiIsolatedRanges=Xl;O.scrollMargins=Yl;O.darkTheme=Ps;O.cspNonce=D.define({combine:n=>n.length?n[0]:""});O.contentAttributes=tr;O.editorAttributes=_l;O.lineWrapping=O.contentAttributes.of({class:"cm-lineWrapping"});O.announce=E.define();const Vf=4096,mo={};class hn{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:J.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 hn(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function yo(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&&ws(o,t)}return t}const zf=A.mac?"mac":A.windows?"win":A.linux?"linux":"key";function qf(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Ni(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 Kf=At.default(O.domEventHandlers({keydown(n,e){return Sa(ka(e.state),n,e,"editor")}})),sr=D.define({enables:Kf}),bo=new WeakMap;function ka(n){let e=n.facet(sr),t=bo.get(e);return t||bo.set(e,t=Uf(e.reduce((i,s)=>i.concat(s),[]))),t}function $f(n,e,t){return Sa(ka(n.state),e,n,t)}let it=null;const jf=4e3;function Uf(n,e=zf){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>qf(y,e));for(let y=1;y<p.length;y++){let S=p.slice(0,y).join(" ");s(S,!0),d[S]||(d[S]={preventDefault:!0,stopPropagation:!1,run:[M=>{let x=it={view:M,prefix:S,scope:o};return setTimeout(()=>{it==x&&(it=null)},jf),!0}]})}let g=p.join(" ");s(g,!1);let m=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(f=d._any)===null||f===void 0?void 0:f.run)===null||u===void 0?void 0:u.slice())||[]});a&&m.run.push(a),h&&(m.preventDefault=!0),c&&(m.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let f in c)c[f].run.push(o.any)}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}function Sa(n,e,t,i){let s=wc(e),r=ne(s,0),o=Oe(r)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;it&&it.view==t&&it.scope==i&&(l=it.prefix+" ",aa.indexOf(e.keyCode)<0&&(h=!0,it=null));let f=new Set,u=m=>{if(m){for(let y of m.run)if(!f.has(y)&&(f.add(y),y(t,e)))return m.stopPropagation&&(c=!0),!0;m.preventDefault&&(m.stopPropagation&&(c=!0),h=!0)}return!1},d=n[i],p,g;return d&&(u(d[l+Ni(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(A.windows&&e.ctrlKey&&e.altKey)&&(p=at[e.keyCode])&&p!=s?(u(d[l+Ni(p,e,!0)])||e.shiftKey&&(g=fi[e.keyCode])!=s&&g!=p&&u(d[l+Ni(g,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Ni(s,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),a}class vi{constructor(e,t,i,s,r){this.className=e,this.left=t,this.top=i,this.width=s,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let s=e.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=va(e);return[new vi(t,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return Gf(e,t,i)}}function va(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==J.LTR?e.left:e.right-n.scrollDOM.clientWidth)-n.scrollDOM.scrollLeft,top:e.top-n.scrollDOM.scrollTop}}function xo(n,e,t){let i=b.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:_.Text}}function Gf(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let i=Math.max(t.from,n.viewport.from),s=Math.min(t.to,n.viewport.to),r=n.textDirection==J.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=va(n),h=o.querySelector(".cm-line"),c=h&&window.getComputedStyle(h),f=l.left+(c?parseInt(c.paddingLeft)+Math.min(0,parseInt(c.textIndent)):0),u=l.right-(c?parseInt(c.paddingRight):0),d=Os(n,i),p=Os(n,s),g=d.type==_.Text?d:null,m=p.type==_.Text?p:null;if(g&&(n.lineWrapping||d.widgetLineBreaks)&&(g=xo(n,i,g)),m&&(n.lineWrapping||p.widgetLineBreaks)&&(m=xo(n,s,m)),g&&m&&g.from==m.from)return S(M(t.from,t.to,g));{let w=g?M(t.from,null,g):x(d,!1),k=m?M(null,t.to,m):x(p,!0),T=[];return(g||d).to<(m||p).from-(g&&m?1:0)||d.widgetLineBreaks>1&&w.bottom+n.defaultLineHeight/2<k.top?T.push(y(f,w.bottom,u,k.top)):w.bottom<k.top&&n.elementAtHeight((w.bottom+k.top)/2).type==_.Text&&(w.bottom=k.top=(w.bottom+k.top)/2),S(w).concat(T).concat(S(k))}function y(w,k,T,H){return new vi(e,w-a.left,k-a.top-.01,T-w,H-k+.01)}function S({top:w,bottom:k,horizontal:T}){let H=[];for(let P=0;P<T.length;P+=2)H.push(y(T[P],w,T[P+1],k));return H}function M(w,k,T){let H=1e9,P=-1e9,R=[];function z(xe,te,oe,Fe,we){let U=n.coordsAtPos(xe,xe==T.to?-2:2),Q=n.coordsAtPos(oe,oe==T.from?2:-2);!U||!Q||(H=Math.min(U.top,Q.top,H),P=Math.max(U.bottom,Q.bottom,P),we==J.LTR?R.push(r&&te?f:U.left,r&&Fe?u:Q.right):R.push(!r&&Fe?f:Q.left,!r&&te?u:U.right))}let Y=w??T.from,re=k??T.to;for(let xe of n.visibleRanges)if(xe.to>Y&&xe.from<re)for(let te=Math.max(xe.from,Y),oe=Math.min(xe.to,re);;){let Fe=n.state.doc.lineAt(te);for(let we of n.bidiSpans(Fe)){let U=we.from+Fe.from,Q=we.to+Fe.from;if(U>=oe)break;Q>te&&z(Math.max(U,te),w==null&&U<=Y,Math.min(Q,oe),k==null&&Q>=re,we.dir)}if(te=Fe.to+1,te>=oe)break}return R.length==0&&z(Y,w==null,re,k==null,n.textDirection),{top:H,bottom:P,horizontal:R}}function x(w,k){let T=l.top+(k?w.top:w.bottom);return{top:T,bottom:T,horizontal:[]}}}function Jf(n,e){return n.constructor==e.constructor&&n.eq(e)}class _f{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(Qi)!=e.state.facet(Qi)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&e.view.requestMeasure(this.measureReq)}setOrder(e){let t=0,i=e.facet(Qi);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}draw(e){if(e.length!=this.drawn.length||e.some((t,i)=>!Jf(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let s of e)s.update&&t&&s.constructor&&this.drawn[i].constructor&&s.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(s.draw(),t);for(;t;){let s=t.nextSibling;t.remove(),t=s}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Qi=D.define();function Ca(n){return[ge.define(e=>new _f(e,n)),Qi.of(n)]}const Aa=!A.ios,pi=D.define({combine(n){return Mt(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function zg(n={}){return[pi.of(n),Xf,Yf,Qf,Jl.of(!0)]}function Ma(n){return n.startState.facet(pi)!=n.state.facet(pi)}const Xf=Ca({above:!0,markers(n){let{state:e}=n,t=e.facet(pi),i=[];for(let s of e.selection.ranges){let r=s==e.selection.main;if(s.empty?!r||Aa:t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=s.empty?s:b.cursor(s.head,s.head>s.anchor?-1:1);for(let a of vi.forRange(n,o,l))i.push(a)}}return i},update(n,e){n.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Ma(n);return t&&wo(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){wo(e.state,n)},class:"cm-cursorLayer"});function wo(n,e){e.style.animationDuration=n.facet(pi).cursorBlinkRate+"ms"}const Yf=Ca({above:!1,markers(n){return n.state.selection.ranges.map(e=>e.empty?[]:vi.forRange(n,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||Ma(n)},class:"cm-selectionLayer"}),Da={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Aa&&(Da[".cm-line"].caretColor="transparent !important");const Qf=At.highest(O.theme(Da)),Oa=E.define({map(n,e){return n==null?null:e.mapPos(n)}}),ri=be.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,i)=>i.is(Oa)?i.value:t,n)}}),Zf=ge.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(ri);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(ri)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let n=this.view.state.field(ri),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(ri)!=n&&this.view.dispatch({effects:Oa.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 qg(){return[ri,Zf]}function ko(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 eu(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 tu{constructor(e){const{regexp:t,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,s)this.addMatch=(l,a,h,c)=>s(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new kt,i=t.add.bind(t);for(let{from:s,to:r}of eu(e,this.maxLength))ko(e.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,s=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),e.viewportChanged||s-i>1e3?this.createDeco(e.view):s>-1?this.updateRange(e.view,t.map(e.changes),i,s):t}updateRange(e,t,i,s){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let a=e.state.doc.lineAt(o),h=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(r.from,a.from),f=Math.min(r.to,h.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let u=[],d,p=(g,m,y)=>u.push(y.range(g,m));if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else ko(e.state.doc,this.regexp,c,f,(g,m)=>this.addMatch(m,e,g,p));t=t.update({filterFrom:c,filterTo:f,filter:(g,m)=>g<c||m>f,add:u})}}return t}}const Es=/x/.unicode!=null?"gu":"g",iu=new RegExp(`[\0-\b
|
||
--\u2028\u2029\uFEFF-]`,Es),nu={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 Un=null;function su(){var n;if(Un==null&&typeof document<"u"&&document.body){let e=document.body.style;Un=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return Un||!1}const Zi=D.define({combine(n){let e=Mt(n,{render:null,specialChars:iu,addSpecialChars:null});return(e.replaceTabs=!su())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Es)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Es)),e}});function Kg(n={}){return[Zi.of(n),ru()]}let So=null;function ru(){return So||(So=ge.fromClass(class{constructor(n){this.view=n,this.decorations=B.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(Zi)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new tu({regexp:n.specialChars,decoration:(e,t,i)=>{let{doc:s}=t.state,r=ne(e[0],0);if(r==9){let o=s.lineAt(i),l=t.state.tabSize,a=Gt(o.text,l,i-o.from);return B.replace({widget:new hu((l-a%l)*this.view.defaultCharacterWidth)})}return this.decorationCache[r]||(this.decorationCache[r]=B.replace({widget:new au(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(Zi);n.startState.facet(Zi)!=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 ou="•";function lu(n){return n>=32?ou:n==10?"":String.fromCharCode(9216+n)}class au extends Dt{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=lu(this.code),i=e.state.phrase("Control character")+" "+(nu[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 hu extends Dt{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 cu extends Dt{constructor(e){super(),this.content=e}toDOM(){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?e.setAttribute("aria-label","placeholder "+this.content):e.setAttribute("aria-hidden","true"),e}coordsAt(e){let t=e.firstChild?Vt(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),s=Mn(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function $g(n){return ge.fromClass(class{constructor(e){this.view=e,this.placeholder=n?B.set([B.widget({widget:new cu(n),side:1}).range(0)]):B.none}get decorations(){return this.view.state.doc.length?B.none:this.placeholder}},{decorations:e=>e.decorations})}const Is=2e3;function fu(n,e,t){let i=Math.min(e.line,t.line),s=Math.max(e.line,t.line),r=[];if(e.off>Is||t.off>Is||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=s;a++){let h=n.doc.line(a);h.length<=l&&r.push(b.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),c=ds(h.text,o,n.tabSize,!0);if(c<0)r.push(b.cursor(h.to));else{let f=ds(h.text,l,n.tabSize);r.push(b.range(h.from+c,h.from+f))}}}return r}function uu(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function vo(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>Is?-1:s==i.length?uu(n,e.clientX):Gt(i.text,n.state.tabSize,t-i.from);return{line:i.number,col:r,off:s}}function du(n,e){let t=vo(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=vo(n,s);if(!l)return i;let a=fu(n.state,t,l);return a.length?o?b.create(a.concat(i.ranges)):b.create(a):i}}:null}function jg(n){let e=(n==null?void 0:n.eventFilter)||(t=>t.altKey&&t.button==0);return O.mouseSelectionStyle.of((t,i)=>e(i)?du(t,i):null)}const Fi="-10000px";class pu{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){var t;let i=e.state.facet(this.facet),s=i.filter(o=>o);if(i===this.input){for(let o of this.tooltipViews)o.update&&o.update(e);return!1}let r=[];for(let o=0;o<s.length;o++){let l=s[o],a=-1;if(l){for(let h=0;h<this.tooltips.length;h++){let c=this.tooltips[h];c&&c.create==l.create&&(a=h)}if(a<0)r[o]=this.createTooltipView(l);else{let h=r[o]=this.tooltipViews[a];h.update&&h.update(e)}}}for(let o of this.tooltipViews)r.indexOf(o)<0&&(o.dom.remove(),(t=o.destroy)===null||t===void 0||t.call(o));return this.input=i,this.tooltips=s,this.tooltipViews=r,!0}}function gu(n){let{win:e}=n;return{top:0,left:0,bottom:e.innerHeight,right:e.innerWidth}}const Gn=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)||gu}}}),Co=new WeakMap,Ta=ge.fromClass(class{constructor(n){this.view=n,this.inView=!0,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Gn);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 pu(n,Ba,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(Gn);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=Fi,this.container.appendChild(e.dom),e.mount&&e.mount(this.view),e}destroy(){var n,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let t of this.manager.tooltipViews)t.dom.remove(),(n=t.destroy)===null||n===void 0||n.call(t);(e=this.intersectionObserver)===null||e===void 0||e.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(Gn).tooltipSpace(this.view)}}writeMeasure(n){var e;let{editor:t,space:i}=n,s=[];for(let r=0;r<this.manager.tooltips.length;r++){let o=this.manager.tooltips[r],l=this.manager.tooltipViews[r],{dom:a}=l,h=n.pos[r],c=n.size[r];if(!h||h.bottom<=Math.max(t.top,i.top)||h.top>=Math.min(t.bottom,i.bottom)||h.right<Math.max(t.left,i.left)-.1||h.left>Math.min(t.right,i.right)+.1){a.style.top=Fi;continue}let f=o.arrow?l.dom.querySelector(".cm-tooltip-arrow"):null,u=f?7:0,d=c.right-c.left,p=(e=Co.get(l))!==null&&e!==void 0?e:c.bottom-c.top,g=l.offset||yu,m=this.view.textDirection==J.LTR,y=c.width>i.right-i.left?m?i.left:i.right-c.width:m?Math.min(h.left-(f?14:0)+g.x,i.right-d):Math.max(i.left,h.left-d+(f?14:0)-g.x),S=!!o.above;!o.strictSide&&(S?h.top-(c.bottom-c.top)-g.y<i.top:h.bottom+(c.bottom-c.top)+g.y>i.bottom)&&S==i.bottom-h.bottom>h.top-i.top&&(S=!S);let M=(S?h.top-i.top:i.bottom-h.bottom)-u;if(M<p&&l.resize!==!1){if(M<this.view.defaultLineHeight){a.style.top=Fi;continue}Co.set(l,p),a.style.height=(p=M)+"px"}else a.style.height&&(a.style.height="");let x=S?h.top-p-u-g.y:h.bottom+u+g.y,w=y+d;if(l.overlap!==!0)for(let k of s)k.left<w&&k.right>y&&k.top<x+p&&k.bottom>x&&(x=S?k.top-p-2-u:k.bottom+u+2);this.position=="absolute"?(a.style.top=x-n.parent.top+"px",a.style.left=y-n.parent.left+"px"):(a.style.top=x+"px",a.style.left=y+"px"),f&&(f.style.left=`${h.left+(m?g.x:-g.x)-(y+14-7)}px`),l.overlap!==!0&&s.push({left:y,top:x,right:w,bottom:x+p}),a.classList.toggle("cm-tooltip-above",S),a.classList.toggle("cm-tooltip-below",!S),l.positioned&&l.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=Fi}},{eventHandlers:{scroll(){this.maybeMeasure()}}}),mu=O.baseTheme({".cm-tooltip":{zIndex:100,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),yu={x:0,y:0},Ba=D.define({enables:[Ta,mu]});function Pa(n,e){let t=n.plugin(Ta);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Ao=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 cn(n,e){let t=n.plugin(La),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const La=ge.fromClass(class{constructor(n){this.input=n.state.facet(fn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(Ao);this.top=new Hi(n,!0,e.topContainer),this.bottom=new Hi(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(Ao);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Hi(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Hi(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(fn);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],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 a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>O.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Hi{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 fn=D.define({enables:La});class vt extends wt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}vt.prototype.elementClass="";vt.prototype.toDOM=void 0;vt.prototype.mapMode=he.TrackBefore;vt.prototype.startSide=vt.prototype.endSide=-1;vt.prototype.point=!0;const bu=D.define(),xu=new class extends vt{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},wu=bu.compute(["selection"],n=>{let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>t&&(t=s,e.push(xu.range(s)))}return K.of(e)});function Ug(){return wu}const ku=1024;let Su=0;class Te{constructor(e,t){this.from=e,this.to=t}}class L{constructor(e={}){this.id=Su++,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=me.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 vu{constructor(e,t,i){this.tree=e,this.overlay=t,this.parser=i}}const Cu=Object.create(null);class me{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):Cu,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new me(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}}}}me.none=new me("",Object.create(null),0,8);class rr{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 me(i.name,s,i.id,i.flags):i)}return new rr(t)}}const Wi=new WeakMap,Do=new WeakMap;var j;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays"})(j||(j={}));class W{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 gi(this.topNode,e)}cursorAt(e,t=0,i=0){let s=Wi.get(this)||this.topNode,r=new gi(s);return r.moveTo(e,t),Wi.set(this,r._tree),r}get topNode(){return new Re(this,0,0,null)}resolve(e,t=0){let i=qt(Wi.get(this)||this.topNode,e,t,!1);return Wi.set(this,i),i}resolveInner(e,t=0){let i=qt(Do.get(this)||this.topNode,e,t,!0);return Do.set(this,i),i}iterate(e){let{enter:t,leave:i,from:s=0,to:r=this.length}=e,o=e.mode||0,l=(o&j.IncludeAnonymous)>0;for(let a=this.cursor(o|j.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!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:ar(me.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new W(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new W(me.none,t,i,s)))}static build(e){return Mu(e)}}W.empty=new W(me.none,[],[],0);class or{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 or(this.buffer,this.index)}}class Ot{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return me.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 a=e;a!=t&&!(Ra(r,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=s[l++],r[a++]=s[l++]-i;let h=r[a++]=s[l++]-i;r[a++]=s[l++]-e,o=Math.max(o,h)}return new Ot(r,o,this.set)}}function Ra(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 Ea(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 qt(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 Re&&n.index<0?null:n.parent;if(!o)return n;n=o}let r=i?0:j.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof Re&&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 Re{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:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],f=a[e]+o.from;if(Ra(s,i,f,f+c.length)){if(c instanceof Ot){if(r&j.ExcludeBuffers)continue;let u=c.findChild(0,c.buffer.length,t,i-f,s);if(u>-1)return new je(new Au(o,c,e,f),null,u)}else if(r&j.IncludeAnonymous||!c.type.isAnonymous||lr(c)){let u;if(!(r&j.IgnoreMounts)&&c.props&&(u=c.prop(L.mounted))&&!u.overlay)return new Re(u.tree,f,e,o);let d=new Re(c,f,e,o);return r&j.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?c.children.length-1:0,t,i,s)}}}if(r&j.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&j.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 Re(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 gi(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return qt(this,e,t,!1)}resolveInner(e,t=0){return qt(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Ea(this,e)}getChild(e,t=null,i=null){let s=un(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return un(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return dn(this,e)}}function un(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 dn(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 Au{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}}class je{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]}constructor(e,t,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}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 je(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&j.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 je(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 je(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 je(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new gi(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];e.push(i.slice(s,r,o)),t.push(0)}return new W(this.type,e,t,this.to-this.from)}resolve(e,t=0){return qt(this,e,t,!1)}resolveInner(e,t=0){return qt(this,e,t,!0)}enterUnfinishedNodesBefore(e){return Ea(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let s=un(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return un(this,e,t,i)}get node(){return this}matchContext(e){return dn(this,e)}}class gi{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof Re)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)}}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 Re?(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&j.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&j.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&j.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&j.IncludeAnonymous||l instanceof Ot||!l.type.isAnonymous||lr(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 je(this.buffer,t,this.stack[s]);return this.bufferNode=new je(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 dn(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 dn(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 lr(n){return n.children.some(e=>e instanceof Ot||!e.type.isAnonymous||lr(e))}function Mu(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=ku,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new or(t,t.length):t,a=i.types,h=0,c=0;function f(x,w,k,T,H){let{id:P,start:R,end:z,size:Y}=l,re=c;for(;Y<0;)if(l.next(),Y==-1){let we=r[P];k.push(we),T.push(R-x);return}else if(Y==-3){h=P;return}else if(Y==-4){c=P;return}else throw new RangeError(`Unrecognized record size: ${Y}`);let xe=a[P],te,oe,Fe=R-x;if(z-R<=s&&(oe=g(l.pos-w,H))){let we=new Uint16Array(oe.size-oe.skip),U=l.pos-oe.size,Q=we.length;for(;l.pos>U;)Q=m(oe.start,we,Q);te=new Ot(we,z-oe.start,i),Fe=oe.start-x}else{let we=l.pos-Y;l.next();let U=[],Q=[],ut=P>=o?P:-1,Tt=0,Mi=z;for(;l.pos>we;)ut>=0&&l.id==ut&&l.size>=0?(l.end<=Mi-s&&(d(U,Q,R,Tt,l.end,Mi,ut,re),Tt=U.length,Mi=l.end),l.next()):f(R,we,U,Q,ut);if(ut>=0&&Tt>0&&Tt<U.length&&d(U,Q,R,Tt,R,Mi,ut,re),U.reverse(),Q.reverse(),ut>-1&&Tt>0){let Cr=u(xe);te=ar(xe,U,Q,0,U.length,0,z-R,Cr,Cr)}else te=p(xe,U,Q,z-R,re-z)}k.push(te),T.push(Fe)}function u(x){return(w,k,T)=>{let H=0,P=w.length-1,R,z;if(P>=0&&(R=w[P])instanceof W){if(!P&&R.type==x&&R.length==T)return R;(z=R.prop(L.lookAhead))&&(H=k[P]+R.length+z)}return p(x,w,k,T,H)}}function d(x,w,k,T,H,P,R,z){let Y=[],re=[];for(;x.length>T;)Y.push(x.pop()),re.push(w.pop()+k-H);x.push(p(i.types[R],Y,re,P-H,z-P)),w.push(H-k)}function p(x,w,k,T,H=0,P){if(h){let R=[L.contextHash,h];P=P?[R].concat(P):[R]}if(H>25){let R=[L.lookAhead,H];P=P?[R].concat(P):[R]}return new W(x,w,k,T,P)}function g(x,w){let k=l.fork(),T=0,H=0,P=0,R=k.end-s,z={size:0,start:0,skip:0};e:for(let Y=k.pos-x;k.pos>Y;){let re=k.size;if(k.id==w&&re>=0){z.size=T,z.start=H,z.skip=P,P+=4,T+=4,k.next();continue}let xe=k.pos-re;if(re<0||xe<Y||k.start<R)break;let te=k.id>=o?4:0,oe=k.start;for(k.next();k.pos>xe;){if(k.size<0)if(k.size==-3)te+=4;else break e;else k.id>=o&&(te+=4);k.next()}H=oe,T+=re,P+=te}return(w<0||T==x)&&(z.size=T,z.start=H,z.skip=P),z.size>4?z:void 0}function m(x,w,k){let{id:T,start:H,end:P,size:R}=l;if(l.next(),R>=0&&T<o){let z=k;if(R>4){let Y=l.pos-(R-4);for(;l.pos>Y;)k=m(x,w,k)}w[--k]=z,w[--k]=P-x,w[--k]=H-x,w[--k]=T}else R==-3?h=T:R==-4&&(c=T);return k}let y=[],S=[];for(;l.pos>0;)f(n.start||0,n.bufferStart||0,y,S,-1);let M=(e=n.length)!==null&&e!==void 0?e:y.length?S[0]+y[0].length:0;return new W(a[n.topID],y.reverse(),S.reverse(),M)}const Oo=new WeakMap;function en(n,e){if(!n.isAnonymous||e instanceof Ot||e.type!=n)return 1;let t=Oo.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof W)){t=1;break}t+=en(n,i)}Oo.set(e,t)}return t}function ar(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p<s;p++)h+=en(n,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,g,m,y,S){for(let M=m;M<y;){let x=M,w=g[M],k=en(n,p[M]);for(M++;M<y;M++){let T=en(n,p[M]);if(k+T>=c)break;k+=T}if(M==x+1){if(k>c){let T=p[x];d(T.children,T.positions,0,T.children.length,g[x]+S);continue}f.push(p[x])}else{let T=g[M-1]+p[M-1].length-w;f.push(ar(n,p,g,x,M,w,T,null,a))}u.push(w+S-r)}}return d(e,t,i,s,0),(l||a)(f,u,o)}class Gg{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 je?this.setBuffer(e.context.buffer,e.index,t):e instanceof Re&&this.map.set(e.tree,t)}get(e){return e instanceof je?this.getBuffer(e.context.buffer,e.index):e instanceof Re?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,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=i)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new Ye(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&s.push(u),o.to>f)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return s}}class Ia{startParse(e,t,i){return typeof e=="string"&&(e=new Du(e)),i=i?i.length?i.map(s=>new Te(s.from,s.to)):[new Te(0,0)]:[new Te(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 Du{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 Jg(n){return(e,t,i,s)=>new Tu(e,n,t,i,s)}class To{constructor(e,t,i,s,r){if(this.parser=e,this.parse=t,this.overlay=i,this.target=s,this.ranges=r,!r.length||r.some(o=>o.from>=o.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(r))}}class Ou{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 Ns=new L({perNode:!0});class Tu{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 W(i.type,i.children,i.positions,i.length,i.propValues.concat([[Ns,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 vu(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 Lu(this.fragments),t=null,i=null,s=new gi(new Re(this.baseTree,this.ranges[0].from,0,null),j.IncludeAnonymous|j.IgnoreMounts);e:for(let r,o;this.stoppedAt==null||s.from<this.stoppedAt;){let l=!0,a;if(e.hasNode(s)){if(t){let h=t.mounts.find(c=>c.frag.from<=s.from&&c.frag.to>=s.to&&c.mount.overlay);if(h)for(let c of h.mount.overlay){let f=c.from+h.pos,u=c.to+h.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=Bu(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||Pu(s);let h=e.findMounts(s.from,r.parser);if(typeof r.overlay=="function")t=new Ou(r.parser,r.overlay,h,this.inner.length,s.from,s.tree,t);else{let c=Lo(this.ranges,r.overlay||[new Te(s.from,s.to)]);c.length&&this.inner.push(new To(r.parser,r.parser.startParse(this.input,Ro(h,c),c),r.overlay?r.overlay.map(f=>new Te(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&&(a=t.predicate(s))&&(a===!0&&(a=new Te(s.from,s.to)),a.from<a.to&&t.ranges.push(a));if(l&&s.firstChild())t&&t.depth++,i&&i.depth++;else for(;!s.nextSibling();){if(!s.parent())break e;if(t&&!--t.depth){let h=Lo(this.ranges,t.ranges);h.length&&this.inner.splice(t.index,0,new To(t.parser,t.parser.startParse(this.input,Ro(t.mounts,h),h),t.ranges.map(c=>new Te(c.from-t.start,c.to-t.start)),t.target,h)),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function Bu(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 Bo(n,e,t,i,s,r){if(e<t){let o=n.buffer[e+1];i.push(n.slice(e,t,o)),s.push(o-r)}}function Pu(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 a(h,c,f,u,d){let p=h;for(;l[p+2]+r<=e.from;)p=l[p+3];let g=[],m=[];Bo(o,h,p,g,m,u);let y=l[p+1],S=l[p+2],M=y+r==e.from&&S+r==e.to&&l[p]==e.type.id;return g.push(M?e.toTree():a(p+4,l[p+3],o.set.types[l[p]],y,S-y)),m.push(y-u),Bo(o,l[p+3],c,g,m,u),new W(f,g,m,d)}s.children[i]=a(0,l.length,me.none,0,o.length);for(let h=0;h<=t;h++)n.childAfter(e.from)}class Po{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(j.IncludeAnonymous|j.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,j.IgnoreOverlays|j.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 W)t=t.children[0];else break}return!1}}class Lu{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(Ns))!==null&&t!==void 0?t:i.to,this.inner=new Po(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(Ns))!==null&&e!==void 0?e:t.to,this.inner=new Po(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 a=this.fragments[l];if(a.from>=r.to)break;a.tree==this.curFrag.tree&&s.push({frag:a,pos:r.from-a.offset,mount:o})}}}return s}}function Lo(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 a=i[r];if(a.from>=l)break;a.to<=o||(t||(i=t=e.slice()),a.from<o?(t[r]=new Te(a.from,o),a.to>l&&t.splice(r+1,0,new Te(l,a.to))):a.to>l?t[r--]=new Te(l,a.to):t.splice(r--,1))}}return i}function Ru(n,e,t,i){let s=0,r=0,o=!1,l=!1,a=-1e9,h=[];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(a,t),d=Math.min(c,f,i);u<d&&h.push(new Te(u,d))}if(a=Math.min(c,f),a==1e9)break;c==a&&(o?(o=!1,s++):o=!0),f==a&&(l?(l=!1,r++):l=!0)}return h}function Ro(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,a=Math.max(r.from,o),h=Math.min(r.to,l);if(s.overlay){let c=s.overlay.map(u=>new Te(u.from+i,u.to+i)),f=Ru(e,c,a,h);for(let u=0,d=a;;u++){let p=u==f.length,g=p?h: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(a,h,s.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return t}let Eu=0;class qe{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=Eu++}static define(e){if(e!=null&&e.base)throw new Error("Can not derive from a modified tag");let t=new qe([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new pn;return t=>t.modified.indexOf(e)>-1?t:pn.get(t.base||t,t.modified.concat(e).sort((i,s)=>i.id-s.id))}}let Iu=0;class pn{constructor(){this.instances=[],this.id=Iu++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Nu(t,l.modified));if(i)return i;let s=[],r=new qe(s,e,t);for(let l of t)l.instances.push(r);let o=Fu(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(pn.get(l,a));return r}}function Nu(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function Fu(n){let e=[[]];for(let t=0;t<n.length;t++)for(let i=0,s=e.length;i<s;i++)e.push(e[i].concat(n[t]));return e.sort((t,i)=>i.length-t.length)}function Hu(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 a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let c=new gn(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return Na.add(e)}const Na=new L;class gn{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}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}}gn.empty=new gn([],2,null);function Fa(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 a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function Wu(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function Vu(n,e,t,i=0,s=n.length){let r=new zu(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}class zu{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:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,c=qu(e)||gn.empty,f=Wu(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(s+=(s?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)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(m=>!m.scope||m.scope(u.tree.type)),g=e.firstChild();for(let m=0,y=l;;m++){let S=m<u.overlay.length?u.overlay[m]:null,M=S?S.from+l:a,x=Math.max(t,y),w=Math.min(i,M);if(x<w&&g)for(;e.from<w&&(this.highlightRange(e,x,w,s,r),this.startSpan(Math.min(w,e.to),h),!(e.to>=M||!e.nextSibling())););if(!S||M>i)break;y=S.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,S.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),h))}g&&e.parent()}else if(e.firstChild()){u&&(s="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}}function qu(n){let e=n.type.prop(Na);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const v=qe.define,Vi=v(),et=v(),Eo=v(et),Io=v(et),tt=v(),zi=v(tt),Jn=v(tt),ze=v(),dt=v(ze),We=v(),Ve=v(),Fs=v(),Zt=v(Fs),qi=v(),C={comment:Vi,lineComment:v(Vi),blockComment:v(Vi),docComment:v(Vi),name:et,variableName:v(et),typeName:Eo,tagName:v(Eo),propertyName:Io,attributeName:v(Io),className:v(et),labelName:v(et),namespace:v(et),macroName:v(et),literal:tt,string:zi,docString:v(zi),character:v(zi),attributeValue:v(zi),number:Jn,integer:v(Jn),float:v(Jn),bool:v(tt),regexp:v(tt),escape:v(tt),color:v(tt),url:v(tt),keyword:We,self:v(We),null:v(We),atom:v(We),unit:v(We),modifier:v(We),operatorKeyword:v(We),controlKeyword:v(We),definitionKeyword:v(We),moduleKeyword:v(We),operator:Ve,derefOperator:v(Ve),arithmeticOperator:v(Ve),logicOperator:v(Ve),bitwiseOperator:v(Ve),compareOperator:v(Ve),updateOperator:v(Ve),definitionOperator:v(Ve),typeOperator:v(Ve),controlOperator:v(Ve),punctuation:Fs,separator:v(Fs),bracket:Zt,angleBracket:v(Zt),squareBracket:v(Zt),paren:v(Zt),brace:v(Zt),content:ze,heading:dt,heading1:v(dt),heading2:v(dt),heading3:v(dt),heading4:v(dt),heading5:v(dt),heading6:v(dt),contentSeparator:v(ze),list:v(ze),quote:v(ze),emphasis:v(ze),strong:v(ze),link:v(ze),monospace:v(ze),strikethrough:v(ze),inserted:v(),deleted:v(),changed:v(),invalid:v(),meta:qi,documentMeta:v(qi),annotation:v(qi),processingInstruction:v(qi),definition:qe.defineModifier(),constant:qe.defineModifier(),function:qe.defineModifier(),standard:qe.defineModifier(),local:qe.defineModifier(),special:qe.defineModifier()};Fa([{tag:C.link,class:"tok-link"},{tag:C.heading,class:"tok-heading"},{tag:C.emphasis,class:"tok-emphasis"},{tag:C.strong,class:"tok-strong"},{tag:C.keyword,class:"tok-keyword"},{tag:C.atom,class:"tok-atom"},{tag:C.bool,class:"tok-bool"},{tag:C.url,class:"tok-url"},{tag:C.labelName,class:"tok-labelName"},{tag:C.inserted,class:"tok-inserted"},{tag:C.deleted,class:"tok-deleted"},{tag:C.literal,class:"tok-literal"},{tag:C.string,class:"tok-string"},{tag:C.number,class:"tok-number"},{tag:[C.regexp,C.escape,C.special(C.string)],class:"tok-string2"},{tag:C.variableName,class:"tok-variableName"},{tag:C.local(C.variableName),class:"tok-variableName tok-local"},{tag:C.definition(C.variableName),class:"tok-variableName tok-definition"},{tag:C.special(C.variableName),class:"tok-variableName2"},{tag:C.definition(C.propertyName),class:"tok-propertyName tok-definition"},{tag:C.typeName,class:"tok-typeName"},{tag:C.namespace,class:"tok-namespace"},{tag:C.className,class:"tok-className"},{tag:C.macroName,class:"tok-macroName"},{tag:C.propertyName,class:"tok-propertyName"},{tag:C.operator,class:"tok-operator"},{tag:C.comment,class:"tok-comment"},{tag:C.meta,class:"tok-meta"},{tag:C.invalid,class:"tok-invalid"},{tag:C.punctuation,class:"tok-punctuation"}]);var _n;const yt=new L;function Ha(n){return D.define({combine:n?e=>e.concat(n):void 0})}const Ku=new L;class Be{constructor(e,t,i=[],s=""){this.data=e,this.name=s,N.prototype.hasOwnProperty("tree")||Object.defineProperty(N.prototype,"tree",{get(){return ye(this)}}),this.parser=t,this.extension=[jt.of(this),N.languageData.of((r,o,l)=>{let a=No(r,o,l),h=a.type.prop(yt);if(!h)return[];let c=r.facet(h),f=a.type.prop(Ku);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return No(e,t,i).type.prop(yt)==this.data}findRegions(e){let t=e.facet(jt);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(yt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(L.mounted);if(l){if(l.tree.prop(yt)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let h=r.children[a];h instanceof W&&s(h,r.positions[a]+o)}};return s(ye(e),0),i}get allowsNesting(){return!0}}Be.setState=E.define();function No(n,e,t){let i=n.facet(jt),s=ye(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,t,j.ExcludeBuffers))r.type.isTop&&(s=r);return s}class Hs extends Be{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Ha(e.languageData);return new Hs(t,e.parser.configure({props:[yt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Hs(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function ye(n){let e=n.field(Be.state,!1);return e?e.tree:W.empty}class $u{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let ei=null;class Kt{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Kt(e,t,[],W.empty,0,i,[],null)}startParse(){return this.parser.startParse(new $u(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=W.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(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??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=ei;ei=this;try{return e()}finally{ei=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Fo(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=Ye.applyChanges(i,a),s=W.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new Kt(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=Fo(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 Ia{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=ei;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new W(me.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 ei}}function Fo(n,e,t){return Ye.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class $t{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new $t(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Kt.create(e.facet(jt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new $t(i)}}Be.state=be.define({create:$t.init,update(n,e){for(let t of e.effects)if(t.is(Be.setState))return t.value;return e.startState.facet(jt)!=e.state.facet(jt)?$t.init(e.state):n.apply(e)}});let Wa=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Wa=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:500-100})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Xn=typeof navigator<"u"&&(!((_n=navigator.scheduling)===null||_n===void 0)&&_n.isInputPending)?()=>navigator.scheduling.isInputPending():null,ju=ge.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(Be.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(Be.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Wa(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(Be.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!Xn?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>Xn&&Xn()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Be.setState.of(new $t(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Ie(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()}}}),jt=D.define({combine(n){return n.length?n[0]:null},enables:n=>[Be.state,ju,O.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Xg{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Va=D.define(),Tn=D.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function Ct(n){let e=n.facet(Tn);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function mn(n,e){let t="",i=n.tabSize,s=n.facet(Tn)[0];if(s==" "){for(;e>=i;)t+=" ",e-=i;s=" "}for(let r=0;r<e;r++)t+=s;return t}function za(n,e){n instanceof N&&(n=new Bn(n));for(let i of n.state.facet(Va)){let s=i(n,e);if(s!==void 0)return s}let t=ye(n.state);return t.length>=e?Gu(n,t,e):null}class Bn{constructor(e,t={}){this.state=e,this.options=t,this.unit=Ct(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 Gt(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 Uu=new L;function Gu(n,e,t){return qa(e.resolveInner(t).enterUnfinishedNodesBefore(t),t,n)}function Ju(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function _u(n){let e=n.type.prop(Uu);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=>Ka(o,!0,1,void 0,r&&!Ju(o)?s.from:void 0)}return n.parent==null?Xu:null}function qa(n,e,t){for(;n;n=n.parent){let i=_u(n);if(i)return i(hr.create(t,e,n))}return null}function Xu(){return 0}class hr extends Bn{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 hr(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(Yu(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){let e=this.node.parent;return e?qa(e,this.pos,this.base):0}}function Yu(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function Qu(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.from<o?t:null;l=a.to}}function Yg({closing:n,align:e=!0,units:t=1}){return i=>Ka(i,e,t,n)}function Ka(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=e?Qu(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}const Qg=n=>n.baseIndent;function Zg({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const em=new L;function tm(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 Pn{constructor(e,t){this.specs=e;let i;function s(l){let a=lt.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof Be?l=>l.prop(yt)==o.data:o?l=>l==o:void 0,this.style=Fa(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new lt(i):null,this.themeType=t.themeType}static define(e,t){return new Pn(e,t||{})}}const Ws=D.define(),$a=D.define({combine(n){return n.length?[n[0]]:null}});function Yn(n){let e=n.facet(Ws);return e.length?e:n.facet($a)}function im(n,e){let t=[ed],i;return n instanceof Pn&&(n.module&&t.push(O.styleModule.of(n.module)),i=n.themeType),e!=null&&e.fallback?t.push($a.of(n)):i?t.push(Ws.computeN([O.darkTheme],s=>s.facet(O.darkTheme)==(i=="dark")?[n]:[])):t.push(Ws.of(n)),t}class Zu{constructor(e){this.markCache=Object.create(null),this.tree=ye(e.state),this.decorations=this.buildDeco(e,Yn(e.state))}update(e){let t=ye(e.state),i=Yn(e.state),s=i!=Yn(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 B.none;let i=new kt;for(let{from:s,to:r}of e.visibleRanges)Vu(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=B.mark({class:a})))},s,r);return i.finish()}}const ed=At.high(ge.fromClass(Zu,{decorations:n=>n.decorations})),nm=Pn.define([{tag:C.meta,color:"#404740"},{tag:C.link,textDecoration:"underline"},{tag:C.heading,textDecoration:"underline",fontWeight:"bold"},{tag:C.emphasis,fontStyle:"italic"},{tag:C.strong,fontWeight:"bold"},{tag:C.strikethrough,textDecoration:"line-through"},{tag:C.keyword,color:"#708"},{tag:[C.atom,C.bool,C.url,C.contentSeparator,C.labelName],color:"#219"},{tag:[C.literal,C.inserted],color:"#164"},{tag:[C.string,C.deleted],color:"#a11"},{tag:[C.regexp,C.escape,C.special(C.string)],color:"#e40"},{tag:C.definition(C.variableName),color:"#00f"},{tag:C.local(C.variableName),color:"#30a"},{tag:[C.typeName,C.namespace],color:"#085"},{tag:C.className,color:"#167"},{tag:[C.special(C.variableName),C.macroName],color:"#256"},{tag:C.definition(C.propertyName),color:"#00c"},{tag:C.comment,color:"#940"},{tag:C.invalid,color:"#f00"}]),td=O.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),ja=1e4,Ua="()[]{}",Ga=D.define({combine(n){return Mt(n,{afterCursor:!0,brackets:Ua,maxScanDistance:ja,renderMatch:sd})}}),id=B.mark({class:"cm-matchingBracket"}),nd=B.mark({class:"cm-nonmatchingBracket"});function sd(n){let e=[],t=n.matched?id:nd;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 rd=be.define({create(){return B.none},update(n,e){if(!e.docChanged&&!e.selection)return n;let t=[],i=e.state.facet(Ga);for(let s of e.state.selection.ranges){if(!s.empty)continue;let r=Ue(e.state,s.head,-1,i)||s.head>0&&Ue(e.state,s.head-1,1,i)||i.afterCursor&&(Ue(e.state,s.head,1,i)||s.head<e.state.doc.length&&Ue(e.state,s.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e.state)))}return B.set(t,!0)},provide:n=>O.decorations.from(n)}),od=[rd,td];function sm(n={}){return[Ga.of(n),od]}const ld=new L;function Vs(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 zs(n){let e=n.type.prop(ld);return e?e(n.node):n}function Ue(n,e,t,i={}){let s=i.maxScanDistance||ja,r=i.brackets||Ua,o=ye(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Vs(a.type,t,r);if(h&&a.from<a.to){let c=zs(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return ad(n,e,t,a,c,h,r)}}return hd(n,e,t,o,l.type,s,r)}function ad(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},h=0,c=l==null?void 0:l.cursor();if(c&&(t<0?c.childBefore(i.from):c.childAfter(i.to)))do if(t<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let f=zs(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(Vs(c.type,t,o))h++;else if(Vs(c.type,-t,o)){if(h==0){let f=zs(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function hd(n,e,t,i,s,r,o){let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={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,m=t>0?d.length:-1;g!=m;g+=t){let y=o.indexOf(d[g]);if(!(y<0||i.resolveInner(p+g,1).type!=s))if(y%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+g,to:p+g+1},matched:y>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}function Ho(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 Ja{constructor(e,t,i,s){this.string=e,this.tabSize=t,this.indentUnit=i,this.overrideIndent=s,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=Ho(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:Ho(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 cd(n){return{name:n.name||"",token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||fd,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||fr}}function fd(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}const Wo=new WeakMap;class _a extends Be{constructor(e){let t=Ha(e.languageData),i=cd(e),s,r=new class extends Ia{createParse(o,l,a){return new dd(s,o,l,a)}};super(t,r,[Va.of((o,l)=>this.getIndent(o,l))],e.name),this.topNode=md(t),s=this,this.streamParser=i,this.stateAfter=new L({perNode:!0}),this.tokenTable=e.tokenTable?new Za(i.tokenTable):gd}static define(e){return new _a(e)}getIndent(e,t){let i=ye(e.state),s=i.resolve(t);for(;s&&s.type!=this.topNode;)s=s.parent;if(!s)return null;let r,{overrideIndentation:o}=e.options;o&&(r=Wo.get(e.state),r!=null&&r<t-1e4&&(r=void 0));let l=cr(this,i,0,s.from,r??t),a,h;if(l?(h=l.state,a=l.pos+1):(h=this.streamParser.startState(e.unit),a=0),t-a>1e4)return null;for(;a<t;){let f=e.state.doc.lineAt(a),u=Math.min(t,f.to);if(f.length){let d=o?o(f.from):-1,p=new Ja(f.text,e.state.tabSize,e.unit,d<0?void 0:d);for(;p.pos<u-f.from;)Ya(this.streamParser.token,p,h)}else this.streamParser.blankLine(h,e.unit);if(u==t)break;a=f.to+1}let c=e.lineAt(t);return o&&r==null&&Wo.set(e.state,c.from),this.streamParser.indent(h,/^\s*(.*)/.exec(c.text)[1],e)}get allowsNesting(){return!1}}function cr(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],a=t+e.positions[o],h=l instanceof W&&a<s&&cr(n,l,a,i,s);if(h)return h}return null}function Xa(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],a;if(o<i&&l instanceof W){if(!(a=Xa(n,l,t-o,i-o,s)))break;return s?new W(e.type,e.children.slice(0,r).concat(a),e.positions.slice(0,r+1),o+a.length):a}}return null}function ud(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&&cr(n,s.tree,0-s.offset,t,o),a;if(l&&(a=Xa(n,s.tree,t+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:a}}return{state:n.streamParser.startState(i?Ct(i):4),tree:W.empty}}class dd{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=Kt.get(),o=s[0].from,{state:l,tree:a}=ud(e,i,o,r==null?void 0:r.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);r&&this.parsedPos<r.viewport.from-1e5&&(this.state=this.lang.streamParser.startState(Ct(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=Kt.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;let o=this.ranges[++this.rangeIndex].from;t+=o-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 Ja(t,e?e.state.tabSize:4,e?Ct(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=Ya(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=W.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:pd,topID:0,maxBufferLength:2048,reused:this.chunkReused});e=new W(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 W(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function Ya(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 fr=Object.create(null),mi=[me.none],pd=new rr(mi),Vo=[],Qa=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"]])Qa[n]=eh(fr,e);class Za{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),Qa)}resolve(e){return e?this.table[e]||(this.table[e]=eh(this.extra,e)):0}}const gd=new Za(fr);function Qn(n,e){Vo.indexOf(n)>-1||(Vo.push(n),console.warn(e))}function eh(n,e){let t=null;for(let r of e.split(".")){let o=n[r]||C[r];o?typeof o=="function"?t?t=o(t):Qn(r,`Modifier ${r} used at start of tag`):t?Qn(r,`Tag ${r} used as modifier`):t=o:Qn(r,`Unknown highlighting tag ${r}`)}if(!t)return 0;let i=e.replace(/ /g,"_"),s=me.define({id:mi.length,name:i,props:[Hu({[i]:t})]});return mi.push(s),s.id}function md(n){let e=me.define({id:mi.length,name:"Document",props:[yt.add(()=>n)],top:!0});return mi.push(e),e}const yd=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=dr(n.state,t.from);return i.line?bd(n):i.block?wd(n):!1};function ur(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 bd=ur(vd,0),xd=ur(th,0),wd=ur((n,e)=>th(n,e,Sd(e)),0);function dr(n,e){let t=n.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const ti=50;function kd(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-ti,i),o=n.sliceDoc(s,s+ti),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let c,f;s-i<=2*ti?c=f=n.sliceDoc(i,s):(c=n.sliceDoc(i,i+ti),f=n.sliceDoc(s-ti,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 Sd(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+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function th(n,e,t=e.selection.ranges){let i=t.map(r=>dr(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>kd(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=i[o],{open:h,close:c}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function vd(n,e,t=e.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of t){let l=i.length,a=1e9,h=dr(e,r).line;if(h){for(let c=r;c<=o;){let f=e.doc.lineAt(c);if(f.from>s&&(r==o||o>f.from)){s=f.from;let u=/^\s*/.exec(f.text)[0].length,d=u==f.length,p=f.text.slice(u,u+h.length)==h?u:-1;u<f.text.length&&u<a&&(a=u),i.push({line:f,comment:p,token:h,indent:u,empty:d,single:!1})}c=f.to+1}if(a<1e9)for(let c=l;c<i.length;c++)i[c].indent<i[c].line.text.length&&(i[c].indent=a);i.length==l+1&&(i[l].single=!0)}}if(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of i)(f||!c)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,r.push({from:h,to:c})}return{changes:r}}return null}const qs=Ze.define(),Cd=Ze.define(),Ad=D.define(),ih=D.define({combine(n){return Mt(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}});function Md(n){let e=0;return n.iterChangedRanges((t,i)=>e=i),e}const nh=be.define({create(){return Ge.empty},update(n,e){let t=e.state.facet(ih),i=e.annotation(qs);if(i){let a=e.docChanged?b.single(Md(e.changes)):void 0,h=Se.fromTransaction(e,a),c=i.side,f=c==0?n.undone:n.done;return h?f=yn(f,f.length,t.minDepth,h):f=oh(f,e.startState.selection),new Ge(c==0?i.rest:f,c==0?f:i.rest)}let s=e.annotation(Cd);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(ee.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=Se.fromTransaction(e),o=e.annotation(ee.time),l=e.annotation(ee.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}},fromJSON(n){return new Ge(n.done.map(Se.fromJSON),n.undone.map(Se.fromJSON))}});function rm(n={}){return[nh,ih.of(n),O.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?sh:e.inputType=="historyRedo"?Ks:null;return i?(e.preventDefault(),i(t)):!1}})]}function Ln(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 sh=Ln(0,!1),Ks=Ln(1,!1),Dd=Ln(0,!0),Od=Ln(1,!0);class Se{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 Se(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 Se(e.changes&&Z.fromJSON(e.changes),[],e.mapped&&Je.fromJSON(e.mapped),e.startSelection&&b.fromJSON(e.startSelection),e.selectionsAfter.map(b.fromJSON))}static fromTransaction(e,t){let i=Pe;for(let s of e.startState.facet(Ad)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new Se(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Pe)}static selection(e){return new Se(void 0,Pe,void 0,void 0,e)}}function yn(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 Td(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(i=!0)}}),i}function Bd(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function rh(n,e){return n.length?e.length?n.concat(e):n:e}const Pe=[],Pd=200;function oh(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-Pd));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),yn(n,n.length-1,1e9,t.setSelAfter(i)))}else return[Se.selection([e])]}function Ld(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 Zn(n,e){if(!n.length)return n;let t=n.length,i=Pe;for(;t;){let s=Rd(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?[Se.selection(i)]:Pe}function Rd(n,e,t){let i=rh(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Pe,t);if(!n.changes)return Se.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new Se(s,E.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}const Ed=/^(input\.type|delete)($|\.)/;class Ge{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 Ge(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.newGroupDelay&&s.joinToEvent(r,Td(l.changes,e.changes))||i=="input.type.compose")?o=yn(o,o.length-1,s.minDepth,new Se(e.changes.compose(l.changes),rh(e.effects,l.effects),l.mapped,l.startSelection,Pe)):o=yn(o,o.length,s.minDepth,e),new Ge(o,Pe,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Pe;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Bd(r[r.length-1],e)?this:new Ge(oh(this.done,e),this.undone,t,i)}addMapping(e){return new Ge(Zn(this.done,e),Zn(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:qs.of({side:e,rest:Ld(s)}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let o=s.length==1?Pe:s.slice(0,s.length-1);return r.mapped&&(o=Zn(o,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:qs.of({side:e,rest:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Ge.empty=new Ge(Pe,Pe);const om=[{key:"Mod-z",run:sh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Ks,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Ks,preventDefault:!0},{key:"Mod-u",run:Dd,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Od,preventDefault:!0}];function Jt(n,e){return b.create(n.ranges.map(e),n.mainIndex)}function Xe(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Ne({state:n,dispatch:e},t){let i=Jt(n.selection,t);return i.eq(n.selection)?!1:(e(Xe(n,i)),!0)}function Rn(n,e){return b.cursor(e?n.to:n.from)}function lh(n,e){return Ne(n,t=>t.empty?n.moveByChar(t,e):Rn(t,e))}function fe(n){return n.textDirectionAt(n.state.selection.main.head)==J.LTR}const ah=n=>lh(n,!fe(n)),hh=n=>lh(n,fe(n));function ch(n,e){return Ne(n,t=>t.empty?n.moveByGroup(t,e):Rn(t,e))}const Id=n=>ch(n,!fe(n)),Nd=n=>ch(n,fe(n));function Fd(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 En(n,e,t){let i=ye(n).resolveInner(e.head),s=t?L.closedBy:L.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;Fd(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?Ue(n,i.from,1):Ue(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,b.cursor(l,t?-1:1)}const Hd=n=>Ne(n,e=>En(n.state,e,!fe(n))),Wd=n=>Ne(n,e=>En(n.state,e,fe(n)));function fh(n,e){return Ne(n,t=>{if(!t.empty)return Rn(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const uh=n=>fh(n,!1),dh=n=>fh(n,!0);function ph(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,s;if(e){for(let r of n.state.facet(O.scrollMargins)){let o=r(n);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}s=n.scrollDOM.clientHeight-t-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,s-5)}}function gh(n,e){let t=ph(n),{state:i}=n,s=Jt(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):Rn(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=O.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Xe(i,s),{effects:r}),!0}const zo=n=>gh(n,!1),$s=n=>gh(n,!0);function ft(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=b.cursor(i.from+r))}return s}const Vd=n=>Ne(n,e=>ft(n,e,!0)),zd=n=>Ne(n,e=>ft(n,e,!1)),qd=n=>Ne(n,e=>ft(n,e,!fe(n))),Kd=n=>Ne(n,e=>ft(n,e,fe(n))),$d=n=>Ne(n,e=>b.cursor(n.lineBlockAt(e.head).from,1)),jd=n=>Ne(n,e=>b.cursor(n.lineBlockAt(e.head).to,-1));function Ud(n,e,t){let i=!1,s=Jt(n.selection,r=>{let o=Ue(n,r.head,-1)||Ue(n,r.head,1)||r.head>0&&Ue(n,r.head-1,1)||r.head<n.doc.length&&Ue(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?b.range(r.anchor,l):b.cursor(l)});return i?(e(Xe(n,s)),!0):!1}const Gd=({state:n,dispatch:e})=>Ud(n,e,!1);function Ee(n,e){let t=Jt(n.state.selection,i=>{let s=e(i);return b.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return t.eq(n.state.selection)?!1:(n.dispatch(Xe(n.state,t)),!0)}function mh(n,e){return Ee(n,t=>n.moveByChar(t,e))}const yh=n=>mh(n,!fe(n)),bh=n=>mh(n,fe(n));function xh(n,e){return Ee(n,t=>n.moveByGroup(t,e))}const Jd=n=>xh(n,!fe(n)),_d=n=>xh(n,fe(n)),Xd=n=>Ee(n,e=>En(n.state,e,!fe(n))),Yd=n=>Ee(n,e=>En(n.state,e,fe(n)));function wh(n,e){return Ee(n,t=>n.moveVertically(t,e))}const kh=n=>wh(n,!1),Sh=n=>wh(n,!0);function vh(n,e){return Ee(n,t=>n.moveVertically(t,e,ph(n).height))}const qo=n=>vh(n,!1),Ko=n=>vh(n,!0),Qd=n=>Ee(n,e=>ft(n,e,!0)),Zd=n=>Ee(n,e=>ft(n,e,!1)),ep=n=>Ee(n,e=>ft(n,e,!fe(n))),tp=n=>Ee(n,e=>ft(n,e,fe(n))),ip=n=>Ee(n,e=>b.cursor(n.lineBlockAt(e.head).from)),np=n=>Ee(n,e=>b.cursor(n.lineBlockAt(e.head).to)),$o=({state:n,dispatch:e})=>(e(Xe(n,{anchor:0})),!0),jo=({state:n,dispatch:e})=>(e(Xe(n,{anchor:n.doc.length})),!0),Uo=({state:n,dispatch:e})=>(e(Xe(n,{anchor:n.selection.main.anchor,head:0})),!0),Go=({state:n,dispatch:e})=>(e(Xe(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),sp=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),rp=({state:n,dispatch:e})=>{let t=Nn(n).map(({from:i,to:s})=>b.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:b.create(t),userEvent:"select"})),!0},op=({state:n,dispatch:e})=>{let t=Jt(n.selection,i=>{var s;let r=ye(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 b.range(r.to,r.from)});return e(Xe(n,t)),!0},lp=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=b.create([t.main]):t.main.empty||(i=b.create([b.cursor(t.main.head)])),i?(e(Xe(n,i)),!0):!1};function In(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(o);a<o?(t="delete.backward",a=Ki(n,a,!1)):a>o&&(t="delete.forward",a=Ki(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Ki(n,o,!1),l=Ki(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?O.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Ki(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 Ch=(n,e)=>In(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=Gt(r,i.tabSize),a=l%Ct(i)||Ct(i);for(let h=0;h<a&&r[r.length-1-h]==" ";h++)t--;o=t}else o=ce(s.text,t-s.from,e,e)+s.from,o==t&&s.number!=(e?i.doc.lines:1)&&(o+=e?1:-1);return o}),js=n=>Ch(n,!1),Ah=n=>Ch(n,!0),Mh=(n,e)=>In(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 a=ce(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t)&&(l=c),i=a}return i}),Dh=n=>Mh(n,!1),ap=n=>Mh(n,!0),Oh=n=>In(n,e=>{let t=n.lineBlockAt(e).to;return e<t?t:Math.min(n.state.doc.length,e+1)}),hp=n=>In(n,e=>{let t=n.lineBlockAt(e).from;return e>t?t:Math.max(0,e-1)}),cp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:I.of(["",""])},range:b.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},fp=({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:ce(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:ce(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:b.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Nn(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 Th(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of Nn(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(b.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(b.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:b.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const up=({state:n,dispatch:e})=>Th(n,e,!1),dp=({state:n,dispatch:e})=>Th(n,e,!0);function Bh(n,e,t){if(n.readOnly)return!1;let i=[];for(let s of Nn(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 pp=({state:n,dispatch:e})=>Bh(n,e,!1),gp=({state:n,dispatch:e})=>Bh(n,e,!0),mp=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(Nn(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=Jt(e.selection,s=>n.moveVertically(s,!0)).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function yp(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=ye(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&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const bp=Ph(!1),xp=Ph(!0);function Ph(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&yp(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Bn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=za(h,r);for(c==null&&(c=Gt(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",mn(e,c)];return a&&f.push(mn(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:I.of(f)},range:b.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function pr(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:b.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const wp=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=Object.create(null),i=new Bn(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=pr(n,(r,o,l)=>{let a=za(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=mn(n,a);(h!=c||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},kp=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(pr(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Tn)})}),{userEvent:"input.indent"})),!0),Sp=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(pr(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=Gt(s,n.tabSize),o=0,l=mn(n,Math.max(0,r-Ct(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),vp=[{key:"Ctrl-b",run:ah,shift:yh,preventDefault:!0},{key:"Ctrl-f",run:hh,shift:bh},{key:"Ctrl-p",run:uh,shift:kh},{key:"Ctrl-n",run:dh,shift:Sh},{key:"Ctrl-a",run:$d,shift:ip},{key:"Ctrl-e",run:jd,shift:np},{key:"Ctrl-d",run:Ah},{key:"Ctrl-h",run:js},{key:"Ctrl-k",run:Oh},{key:"Ctrl-Alt-h",run:Dh},{key:"Ctrl-o",run:cp},{key:"Ctrl-t",run:fp},{key:"Ctrl-v",run:$s}],Cp=[{key:"ArrowLeft",run:ah,shift:yh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Id,shift:Jd,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:qd,shift:ep,preventDefault:!0},{key:"ArrowRight",run:hh,shift:bh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Nd,shift:_d,preventDefault:!0},{mac:"Cmd-ArrowRight",run:Kd,shift:tp,preventDefault:!0},{key:"ArrowUp",run:uh,shift:kh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:$o,shift:Uo},{mac:"Ctrl-ArrowUp",run:zo,shift:qo},{key:"ArrowDown",run:dh,shift:Sh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:jo,shift:Go},{mac:"Ctrl-ArrowDown",run:$s,shift:Ko},{key:"PageUp",run:zo,shift:qo},{key:"PageDown",run:$s,shift:Ko},{key:"Home",run:zd,shift:Zd,preventDefault:!0},{key:"Mod-Home",run:$o,shift:Uo},{key:"End",run:Vd,shift:Qd,preventDefault:!0},{key:"Mod-End",run:jo,shift:Go},{key:"Enter",run:bp},{key:"Mod-a",run:sp},{key:"Backspace",run:js,shift:js},{key:"Delete",run:Ah},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Dh},{key:"Mod-Delete",mac:"Alt-Delete",run:ap},{mac:"Mod-Backspace",run:hp},{mac:"Mod-Delete",run:Oh}].concat(vp.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),lm=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Hd,shift:Xd},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Wd,shift:Yd},{key:"Alt-ArrowUp",run:up},{key:"Shift-Alt-ArrowUp",run:pp},{key:"Alt-ArrowDown",run:dp},{key:"Shift-Alt-ArrowDown",run:gp},{key:"Escape",run:lp},{key:"Mod-Enter",run:xp},{key:"Alt-l",mac:"Ctrl-l",run:rp},{key:"Mod-i",run:op,preventDefault:!0},{key:"Mod-[",run:Sp},{key:"Mod-]",run:kp},{key:"Mod-Alt-\\",run:wp},{key:"Shift-Mod-k",run:mp},{key:"Shift-Mod-\\",run:Gd},{key:"Mod-/",run:yd},{key:"Alt-A",run:xd}].concat(Cp);function le(){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++)Lh(n,arguments[e]);return n}function Lh(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++)Lh(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}const Jo=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class Ut{constructor(e,t,i=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r(Jo(l)):Jo,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ne(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=_s(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=Oe(e);let s=this.normalize(t);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o);if(r==s.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t){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"&&(Ut.prototype[Symbol.iterator]=function(){return this});const Rh={from:-1,to:-1,match:/.*/.exec("")},gr="gm"+(/x/.unicode==null?"":"u");class Eh{constructor(e,t,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Rh,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Ih(e,t,i,s,r);this.re=new RegExp(t,gr+(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=bn(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=bn(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const es=new WeakMap;class Ht{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=es.get(e);if(!s||s.from>=i||s.to<=t){let l=new Ht(t,e.sliceString(t,i));return es.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)),es.set(e,new Ht(o,r)),new Ht(t,r.slice(t-o,i-o))}}class Ih{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=Rh,this.matchPos=bn(e,s),this.re=new RegExp(t,gr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=Ht.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=bn(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Ht.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Eh.prototype[Symbol.iterator]=Ih.prototype[Symbol.iterator]=function(){return this});function Ap(n){try{return new RegExp(n,gr),!0}catch{return!1}}function bn(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 Us(n){let e=le("input",{class:"cm-textfield",name:"line"}),t=le("form",{class:"cm-gotoLine",onkeydown:s=>{s.keyCode==27?(s.preventDefault(),n.dispatch({effects:xn.of(!1)}),n.focus()):s.keyCode==13&&(s.preventDefault(),i())},onsubmit:s=>{s.preventDefault(),i()}},le("label",n.state.phrase("Go to line"),": ",e)," ",le("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,a,h,c]=s,f=h?+h.slice(1):0,u=a?+a:o.number;if(a&&c){let g=u/100;l&&(g=g*(l=="-"?-1:1)+o.number/r.doc.lines),u=Math.round(r.doc.lines*g)}else a&&l&&(u=u*(l=="-"?-1:1)+o.number);let d=r.doc.line(Math.max(1,Math.min(r.doc.lines,u))),p=b.cursor(d.from+Math.max(0,Math.min(f,d.length)));n.dispatch({effects:[xn.of(!1),O.scrollIntoView(p.from,{y:"center"})],selection:p}),n.focus()}return{dom:t}}const xn=E.define(),_o=be.define({create(){return!0},update(n,e){for(let t of e.effects)t.is(xn)&&(n=t.value);return n},provide:n=>fn.from(n,e=>e?Us:null)}),Mp=n=>{let e=cn(n,Us);if(!e){let t=[xn.of(!0)];n.state.field(_o,!1)==null&&t.push(E.appendConfig.of([_o,Dp])),n.dispatch({effects:t}),e=cn(n,Us)}return e&&e.dom.querySelector("input").focus(),!0},Dp=O.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Op={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Nh=D.define({combine(n){return Mt(n,Op,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function am(n){let e=[Rp,Lp];return n&&e.push(Nh.of(n)),e}const Tp=B.mark({class:"cm-selectionMatch"}),Bp=B.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Xo(n,e,t,i){return(t==0||n(e.sliceDoc(t-1,t))!=$.Word)&&(i==e.doc.length||n(e.sliceDoc(i,i+1))!=$.Word)}function Pp(n,e,t,i){return n(e.sliceDoc(t,t+1))==$.Word&&n(e.sliceDoc(i-1,i))==$.Word}const Lp=ge.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(Nh),{state:t}=n,i=t.selection;if(i.ranges.length>1)return B.none;let s=i.main,r,o=null;if(s.empty){if(!e.highlightWordAroundCursor)return B.none;let a=t.wordAt(s.head);if(!a)return B.none;o=t.charCategorizer(s.head),r=t.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<e.minSelectionLength||a>200)return B.none;if(e.wholeWords){if(r=t.sliceDoc(s.from,s.to),o=t.charCategorizer(s.head),!(Xo(o,t,s.from,s.to)&&Pp(o,t,s.from,s.to)))return B.none}else if(r=t.sliceDoc(s.from,s.to).trim(),!r)return B.none}let l=[];for(let a of n.visibleRanges){let h=new Ut(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:c,to:f}=h.value;if((!o||Xo(o,t,c,f))&&(s.empty&&c<=s.from&&f>=s.to?l.push(Bp.range(c,f)):(c>=s.to||f<=s.from)&&l.push(Tp.range(c,f)),l.length>e.maxMatches))return B.none}}return B.set(l)}},{decorations:n=>n.decorations}),Rp=O.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Ep=({state:n,dispatch:e})=>{let{selection:t}=n,i=b.create(t.ranges.map(s=>n.wordAt(s.head)||b.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function Ip(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new Ut(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Ut(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const Np=({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=Ip(n,i);return s?(e(n.update({selection:n.selection.addRange(b.range(s.from,s.to),!1),effects:O.scrollIntoView(s.to)})),!0):!1},_t=D.define({combine(n){return Mt(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Gp(e),scrollToMatch:e=>O.scrollIntoView(e)})}});class Fh{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||Ap(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
|
||
`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new Vp(this):new Hp(this)}getCursor(e,t=0,i){let s=e.doc?e:N.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Lt(this,s,t,i):Pt(this,s,t,i)}}class Hh{constructor(e){this.spec=e}}function Pt(n,e,t,i){return new Ut(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?Fp(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function Fp(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(wn(s,t-r))!=$.Word||e(kn(s,t-r))!=$.Word)&&(e(kn(s,i-r))!=$.Word||e(wn(s,i-r))!=$.Word))}class Hp extends Hh{constructor(e){super(e)}nextMatch(e,t,i){let s=Pt(this.spec,e,i,e.doc.length).nextOverlapping();return s.done&&(s=Pt(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=Pt(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Pt(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=Pt(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 Lt(n,e,t,i){return new Eh(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?Wp(e.charCategorizer(e.selection.main.head)):void 0},t,i)}function wn(n,e){return n.slice(ce(n,e,!1),e)}function kn(n,e){return n.slice(e,ce(n,e))}function Wp(n){return(e,t,i)=>!i[0].length||(n(wn(i.input,i.index))!=$.Word||n(kn(i.input,i.index))!=$.Word)&&(n(kn(i.input,i.index+i[0].length))!=$.Word||n(wn(i.input,i.index+i[0].length))!=$.Word)}class Vp extends Hh{nextMatch(e,t,i){let s=Lt(this.spec,e,i,e.doc.length).next();return s.done&&(s=Lt(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=Lt(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace.replace(/\$([$&\d+])/g,(t,i)=>i=="$"?"$":i=="&"?e.match[0]:i!="0"&&+i<e.match.length?e.match[i]:t))}matchAll(e,t){let i=Lt(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=Lt(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 yi=E.define(),mr=E.define(),rt=be.define({create(n){return new ts(Gs(n).create(),null)},update(n,e){for(let t of e.effects)t.is(yi)?n=new ts(t.value.create(),n.panel):t.is(mr)&&(n=new ts(n.query,t.value?yr:null));return n},provide:n=>fn.from(n,e=>e.panel)});class ts{constructor(e,t){this.query=e,this.panel=t}}const zp=B.mark({class:"cm-searchMatch"}),qp=B.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Kp=ge.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(rt))}update(n){let e=n.state.field(rt);(e!=n.startState.field(rt)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return B.none;let{view:t}=this,i=new kt;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-2*250;)a=r[++s].to;n.highlight(t.state,l,a,(h,c)=>{let f=t.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?qp:zp)})}return i.finish()}},{decorations:n=>n.decorations});function Ci(n){return e=>{let t=e.state.field(rt,!1);return t&&t.query.spec.valid?n(e,t):zh(e)}}const Sn=Ci((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let s=b.single(i.from,i.to),r=n.state.facet(_t);return n.dispatch({selection:s,effects:[br(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),Vh(n),!0}),vn=Ci((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,s=e.prevMatch(t,i,i);if(!s)return!1;let r=b.single(s.from,s.to),o=n.state.facet(_t);return n.dispatch({selection:r,effects:[br(n,s),o.scrollToMatch(r.main,n)],userEvent:"select.search"}),Vh(n),!0}),$p=Ci((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:b.create(t.map(i=>b.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),jp=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:s}=t.main,r=[],o=0;for(let l=new Ut(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(b.range(l.value.from,l.value.to))}return e(n.update({selection:b.create(r,o),userEvent:"select.search.matches"})),!0},Yo=Ci((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=[],l,a,h=[];if(r.from==i&&r.to==s&&(a=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=e.nextMatch(t,r.from,r.to),h.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-a.length;l=b.single(r.from-c,r.to-c),h.push(br(n,r)),h.push(t.facet(_t).scrollToMatch(l.main,n))}return n.dispatch({changes:o,selection:l,effects:h,userEvent:"input.replace"}),!0}),Up=Ci((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 yr(n){return n.state.facet(_t).createPanel(n)}function Gs(n,e){var t,i,s,r,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=n.facet(_t);return new Fh({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:h.literal)?a:a.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,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function Wh(n){let e=cn(n,yr);return e&&e.dom.querySelector("[main-field]")}function Vh(n){let e=Wh(n);e&&e==n.root.activeElement&&e.select()}const zh=n=>{let e=n.state.field(rt,!1);if(e&&e.panel){let t=Wh(n);if(t&&t!=n.root.activeElement){let i=Gs(n.state,e.query.spec);i.valid&&n.dispatch({effects:yi.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[mr.of(!0),e?yi.of(Gs(n.state,e.query.spec)):E.appendConfig.of(_p)]});return!0},qh=n=>{let e=n.state.field(rt,!1);if(!e||!e.panel)return!1;let t=cn(n,yr);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:mr.of(!1)}),!0},hm=[{key:"Mod-f",run:zh,scope:"editor search-panel"},{key:"F3",run:Sn,shift:vn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Sn,shift:vn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:qh,scope:"editor search-panel"},{key:"Mod-Shift-l",run:jp},{key:"Alt-g",run:Mp},{key:"Mod-d",run:Np,preventDefault:!0}];class Gp{constructor(e){this.view=e;let t=this.query=e.state.field(rt).query.spec;this.commit=this.commit.bind(this),this.searchField=le("input",{value:t.search,placeholder:Ce(e,"Find"),"aria-label":Ce(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=le("input",{value:t.replace,placeholder:Ce(e,"Replace"),"aria-label":Ce(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=le("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=le("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=le("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(s,r,o){return le("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=le("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>Sn(e),[Ce(e,"next")]),i("prev",()=>vn(e),[Ce(e,"previous")]),i("select",()=>$p(e),[Ce(e,"all")]),le("label",null,[this.caseField,Ce(e,"match case")]),le("label",null,[this.reField,Ce(e,"regexp")]),le("label",null,[this.wordField,Ce(e,"by word")]),...e.state.readOnly?[]:[le("br"),this.replaceField,i("replace",()=>Yo(e),[Ce(e,"replace")]),i("replaceAll",()=>Up(e),[Ce(e,"replace all")])],le("button",{name:"close",onclick:()=>qh(e),"aria-label":Ce(e,"close"),type:"button"},["×"])])}commit(){let e=new Fh({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:yi.of(e)}))}keydown(e){$f(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?vn:Sn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Yo(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(yi)&&!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(_t).top}}function Ce(n,e){return n.state.phrase(e)}const $i=30,ji=/[\s\.,:;?!]/;function br(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-$i),o=Math.min(s,t+$i),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<$i;a++)if(!ji.test(l[a+1])&&ji.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-$i;a--)if(!ji.test(l[a-1])&&ji.test(l[a])){l=l.slice(0,a);break}}return O.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const Jp=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"}}),_p=[rt,At.low(Kp),Jp];class Kh{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=ye(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($h(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 Qo(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 Xp(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=Qo(e)+Qo(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+$/]:Xp(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function cm(n,e){return t=>{for(let i=ye(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class Zo{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}}function ot(n){return n.selection.main.from}function $h(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const jh=Ze.define();function Qp(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return Object.assign(Object.assign({},n.changeByRange(l=>l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i)?{range:l}:{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:e},range:b.cursor(l.from+r+e.length)})),{userEvent:"input.complete"})}const el=new WeakMap;function Zp(n){if(!Array.isArray(n))return n;let e=el.get(n);return e||el.set(n,e=Yp(n)),e}const xr=E.define(),bi=E.define();class eg{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=ne(e,t),s=Oe(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(ne(o==r?r.toLowerCase():o,0)),t+=s}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,!0}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return!1;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let S=ne(e,0),M=Oe(S),x=M==e.length?0:-100;if(S!=t[0])if(S==i[0])x+=-200;else return!1;return this.ret(x,[0,M])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let S=0,M=Math.min(e.length,200);S<M&&h<a;){let x=ne(e,S);(x==t[h]||x==i[h])&&(s[h++]=S),S+=Oe(x)}if(h<a)return!1}let c=0,f=0,u=!1,d=0,p=-1,g=-1,m=/[a-z]/.test(e),y=!0;for(let S=0,M=Math.min(e.length,200),x=0;S<M&&f<a;){let w=ne(e,S);l<0&&(c<a&&w==t[c]&&(r[c++]=S),d<a&&(w==t[d]||w==i[d]?(d==0&&(p=S),g=S+1,d++):d=0));let k,T=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(k=_s(w))!=k.toLowerCase()?1:k!=k.toUpperCase()?2:0;(!S||T==1&&m||x==0&&T!=0)&&(t[f]==w||i[f]==w&&(u=!0)?o[f++]=S:o.length&&(y=!1)),x=T,S+=Oe(w)}return f==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(g==e.length?0:-100),[0,g]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-200+-700-e.length,[p,g]):f==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?!1:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?Oe(ne(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}}const ve=D.define({combine(n){return Mt(n,{activateOnTyping:!0,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:tg,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,tooltipClass:(e,t)=>i=>tl(e(i),t(i)),optionClass:(e,t)=>i=>tl(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})}});function tl(n,e){return n?e?n+" "+e:n:e}function tg(n,e,t,i,s){let r=n.textDirection==J.RTL,o=r,l=!1,a="top",h,c,f=e.left-s.left,u=s.right-e.right,d=i.right-i.left,p=i.bottom-i.top;if(o&&f<Math.min(d,u)?o=!1:!o&&u<Math.min(d,f)&&(o=!0),d<=(o?f:u))h=Math.max(s.top,Math.min(t.top,s.bottom-p))-e.top,c=Math.min(400,o?f:u);else{l=!0,c=Math.min(400,(r?e.right:s.right-e.left)-30);let g=s.bottom-e.bottom;g>=p||g>e.top?h=t.bottom-e.top:(a="bottom",h=e.bottom-t.top)}return{style:`${a}: ${h}px; max-width: ${c}px`,class:"cm-completionInfo-"+(l?r?"left-narrow":"right-narrow":o?"left":"right")}}function ig(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 o=t.displayLabel||t.label,l=0;for(let a=0;a<s.length;){let h=s[a++],c=s[a++];h>l&&r.appendChild(document.createTextNode(o.slice(l,h)));let f=r.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(o.slice(h,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 il(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 ng{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(ve);this.optionContent=ig(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=il(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{for(let h=a.target,c;h&&h!=this.dom;h=h.parentNode)if(h.nodeName=="LI"&&(c=/-(\d+)$/.exec(h.id))&&+c[1]<r.length){this.applyCompletion(e,r[+c[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(ve).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:bi.of(null)})}),this.list=this.dom.appendChild(this.createListBox(r,s.id,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}mount(){this.updateSel()}update(e){var t,i,s;let r=e.state.field(this.stateField),o=e.startState.field(this.stateField);this.updateTooltipClass(e.state),r!=o&&(this.updateSel(),((t=r.open)===null||t===void 0?void 0:t.disabled)!=((i=o.open)===null||i===void 0?void 0:i.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!(!((s=r.open)===null||s===void 0)&&s.disabled)))}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;if((t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=il(t.options.length,t.selected,this.view.state.facet(ve).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.placeInfoReq)})),this.updateSelectedOption(t.selected)){this.destroyInfo();let{completion:i}=t.options[t.selected],{info:s}=i;if(!s)return;let r=typeof s=="string"?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,i)}).catch(o=>Ie(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return t&&rg(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return s.top>Math.min(r.bottom,t.bottom)-10||s.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(ve).positionInfo(this.view,t,s,i,r)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof h!="string"&&h.header)s.appendChild(h.header(h));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=s.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,a);d&&c.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function sg(n,e){return t=>new ng(t,n,e)}function rg(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 nl(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function og(n,e){let t=[],i=null,s=a=>{t.push(a);let{section:h}=a.completion;if(h){i||(i=[]);let c=typeof h=="string"?h:h.name;i.some(f=>f.name==c)||i.push(typeof h=="string"?{name:c}:h)}};for(let a of n)if(a.hasResult()){let h=a.result.getMatch;if(a.result.filter===!1)for(let c of a.result.options)s(new Zo(c,a.source,h?h(c):[],1e9-t.length));else{let c=new eg(e.sliceDoc(a.from,a.to));for(let f of a.result.options)if(c.match(f.label)){let u=f.displayLabel?h?h(f,c.matched):[]:c.matched;s(new Zo(f,a.source,u,c.score+(f.boost||0)))}}}if(i){let a=Object.create(null),h=0,c=(f,u)=>{var d,p;return((d=f.rank)!==null&&d!==void 0?d:1e9)-((p=u.rank)!==null&&p!==void 0?p:1e9)||(f.name<u.name?-1:1)};for(let f of i.sort(c))h-=1e5,a[f.name]=h;for(let f of t){let{section:u}=f.completion;u&&(f.score+=a[typeof u=="string"?u:u.name])}}let r=[],o=null,l=e.facet(ve).compareCompletions;for(let a of t.sort((h,c)=>c.score-h.score||l(h.completion,c.completion))){let h=a.completion;!o||o.label!=h.label||o.detail!=h.detail||o.type!=null&&h.type!=null&&o.type!=h.type||o.apply!=h.apply||o.boost!=h.boost?r.push(a):nl(a.completion)>nl(o)&&(r[r.length-1]=a),o=a.completion}return r}class Et{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Et(this.options,sl(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r){let o=og(e,t);if(!o.length)return s&&e.some(a=>a.state==1)?new Et(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let l=t.facet(ve).selectOnOpen?0:-1;if(s&&s.selected!=l&&s.selected!=-1){let a=s.options[s.selected].completion;for(let h=0;h<o.length;h++)if(o[h].completion==a){l=h;break}}return new Et(o,sl(i,l),{pos:e.reduce((a,h)=>h.hasResult()?Math.min(a,h.from):a,1e8),create:sg(Me,Jh),above:r.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(e){return new Et(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Cn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new Cn(hg,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(ve),r=(i.override||t.languageDataAt("autocomplete",ot(t)).map(Zp)).map(l=>(this.active.find(h=>h.source==l)||new ke(l,this.active.some(h=>h.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!lg(r,this.active)?o=Et.build(r,t,this.id,o,i):o&&o.disabled&&!r.some(l=>l.state==1)&&(o=null),!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new ke(l.source,0):l));for(let l of e.effects)l.is(Gh)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new Cn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:ag}}function lg(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 ag={"aria-autocomplete":"list"};function sl(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const hg=[];function Js(n){return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}class ke{constructor(e,t,i=-1){this.source=e,this.state=t,this.explicitPos=i}hasResult(){return!1}update(e,t){let i=Js(e),s=this;i?s=s.handleUserEvent(e,i,t):e.docChanged?s=s.handleChange(e):e.selection&&s.state!=0&&(s=new ke(s.source,0));for(let r of e.effects)if(r.is(xr))s=new ke(s.source,1,r.value?ot(e.state):-1);else if(r.is(bi))s=new ke(s.source,0);else if(r.is(Uh))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 ke(this.source,1)}handleChange(e){return e.changes.touchesRange(ot(e.startState))?new ke(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new ke(this.source,this.state,e.mapPos(this.explicitPos))}}class Wt extends ke{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=ot(e.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||t=="delete"&&ot(e.startState)==this.from)return new ke(this.source,t=="input"&&i.activateOnTyping?1:0);let a=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos),h;return cg(this.result.validFor,e.state,r,o)?new Wt(this.source,a,this.result,r,o):this.result.update&&(h=this.result.update(this.result,r,o,new Kh(e.state,l,a>=0)))?new Wt(this.source,a,h,h.from,(s=h.to)!==null&&s!==void 0?s:ot(e.state)):new ke(this.source,1,a)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new ke(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new Wt(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1))}}function cg(n,e,t,i){if(!n)return!1;let s=e.sliceDoc(t,i);return typeof n=="function"?n(s,t,i,e):$h(n,!0).test(s)}const Uh=E.define({map(n,e){return n.map(t=>t.map(e))}}),Gh=E.define(),Me=be.define({create(){return Cn.start()},update(n,e){return n.update(e)},provide:n=>[Ba.from(n,e=>e.tooltip),O.contentAttributes.from(n,e=>e.attrs)]});function Jh(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(Me).active.find(s=>s.source==e.source);return i instanceof Wt?(typeof t=="string"?n.dispatch(Object.assign(Object.assign({},Qp(n.state,t,i.from,i.to)),{annotations:jh.of(e.completion)})):t(n,e.completion,i.from,i.to),!0):!1}function Ui(n,e="option"){return t=>{let i=t.state.field(Me,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(ve).interactionDelay)return!1;let s=1,r;e=="page"&&(r=Pa(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:Gh.of(l)}),!0}}const fg=n=>{let e=n.state.field(Me,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(ve).interactionDelay?!1:Jh(n,e.open.options[e.open.selected])},ug=n=>n.state.field(Me,!1)?(n.dispatch({effects:xr.of(!0)}),!0):!1,dg=n=>{let e=n.state.field(Me,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:bi.of(null)}),!0)};class pg{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const rl=50,gg=50,mg=1e3,yg=ge.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(Me).active)e.state==1&&this.startQuery(e)}update(n){let e=n.state.field(Me);if(!n.selectionSet&&!n.docChanged&&n.startState.field(Me)==e)return;let t=n.transactions.some(i=>(i.selection||i.docChanged)&&!Js(i));for(let i=0;i<this.running.length;i++){let s=this.running[i];if(t||s.updates.length+n.transactions.length>gg&&Date.now()-s.time>mg){for(let r of s.context.abortListeners)try{r()}catch(o){Ie(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(),rl):-1,this.composing!=0)for(let i of n.transactions)Js(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(Me);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=ot(e),i=new Kh(e,t,n.explicitPos==t),s=new pg(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:bi.of(null)}),Ie(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),rl))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(ve);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 Wt(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:ot(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(Me).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new ke(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:Uh.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(Me,!1);if(e&&e.tooltip&&this.view.state.facet(ve).closeOnBlur){let t=e.open&&Pa(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&this.view.dispatch({effects:bi.of(null)})}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:xr.of(!1)}),20),this.composing=0}}}),_h=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",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class bg{constructor(e,t,i,s){this.field=e,this.line=t,this.from=i,this.to=s}}class wr{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,he.TrackDel),i=e.mapPos(this.to,1,he.TrackDel);return t==null||i==null?null:new wr(this.field,t,i)}}class kr{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],s=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let h=o,c=/^\t*/.exec(a)[0].length;for(let f=0;f<c;f++)h+=e.facet(Tn);s.push(t+h.length-c),a=h+a.slice(c)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new wr(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],s=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",h=-1;for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:a&&t[c].name==a)&&(h=c);if(h<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:a}),h=c;for(let f of s)f.field>=h&&f.field++}s.push(new bg(h,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of s)a.line==i.length&&a.from>l.index&&(a.from--,a.to--)}i.push(o)}return new kr(i,s)}}let xg=B.widget({widget:new class extends Dt{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),wg=B.mark({class:"cm-snippetField"});class Xt{constructor(e,t){this.ranges=e,this.active=t,this.deco=B.set(e.map(i=>(i.from==i.to?xg:wg).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 Xt(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 Ai=E.define({map(n,e){return n&&n.map(e)}}),kg=E.define(),xi=be.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(Ai))return t.value;if(t.is(kg)&&n)return new Xt(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:B.none)});function Sr(n,e){return b.create(n.filter(t=>t.field==e).map(t=>b.range(t.from,t.to)))}function Sg(n){let e=kr.parse(n);return(t,i,s,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,s),a={changes:{from:s,to:r,insert:I.of(o)},scrollIntoView:!0,annotations:i?jh.of(i):void 0};if(l.length&&(a.selection=Sr(l,0)),l.length>1){let h=new Xt(l,0),c=a.effects=[Ai.of(h)];t.state.field(xi,!1)===void 0&&c.push(E.appendConfig.of([xi,Dg,Og,_h]))}t.dispatch(t.state.update(a))}}function Xh(n){return({state:e,dispatch:t})=>{let i=e.field(xi,!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:Sr(i.ranges,s),effects:Ai.of(r?null:new Xt(i.ranges,s))})),!0}}const vg=({state:n,dispatch:e})=>n.field(xi,!1)?(e(n.update({effects:Ai.of(null)})),!0):!1,Cg=Xh(1),Ag=Xh(-1),Mg=[{key:"Tab",run:Cg,shift:Ag},{key:"Escape",run:vg}],ol=D.define({combine(n){return n.length?n[0]:Mg}}),Dg=At.highest(sr.compute([ol],n=>n.facet(ol)));function fm(n,e){return Object.assign(Object.assign({},e),{apply:Sg(n)})}const Og=O.domEventHandlers({mousedown(n,e){let t=e.state.field(xi,!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:Sr(t.ranges,s.field),effects:Ai.of(t.ranges.some(r=>r.field>s.field)?new Xt(t.ranges,s.field):null)}),!0)}}),wi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},bt=E.define({map(n,e){let t=e.mapPos(n,-1,he.TrackAfter);return t??void 0}}),vr=new class extends wt{};vr.startSide=1;vr.endSide=-1;const Yh=be.define({create(){return K.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=K.empty)}n=n.map(e.changes);for(let t of e.effects)t.is(bt)&&(n=n.update({add:[vr.range(t.value,t.value+1)]}));return n}});function um(){return[Bg,Yh]}const is="()[]{}<>";function Qh(n){for(let e=0;e<is.length;e+=2)if(is.charCodeAt(e)==n)return is.charAt(e+1);return _s(n<128?n:n+1)}function Zh(n,e){return n.languageDataAt("closeBrackets",e)[0]||wi}const Tg=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Bg=O.inputHandler.of((n,e,t,i)=>{if((Tg?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&Oe(ne(i,0))==1||e!=s.from||t!=s.to)return!1;let r=Lg(n.state,i);return r?(n.dispatch(r),!0):!1}),Pg=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let i=Zh(n,n.selection.main.head).brackets||wi.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=Rg(n.doc,o.head);for(let a of i)if(a==l&&Fn(n.doc,o.head)==Qh(ne(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:b.cursor(o.head-a.length)}}return{range:s=o}});return s||e(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},dm=[{key:"Backspace",run:Pg}];function Lg(n,e){let t=Zh(n,n.selection.main.head),i=t.brackets||wi.brackets;for(let s of i){let r=Qh(ne(s,0));if(e==s)return r==s?Ng(n,s,i.indexOf(s+s+s)>-1,t):Eg(n,s,r,t.before||wi.before);if(e==r&&ec(n,n.selection.main.from))return Ig(n,s,r)}return null}function ec(n,e){let t=!1;return n.field(Yh).between(0,n.doc.length,i=>{i==e&&(t=!0)}),t}function Fn(n,e){let t=n.sliceString(e,e+2);return t.slice(0,Oe(ne(t,0)))}function Rg(n,e){let t=n.sliceString(e-2,e);return Oe(ne(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:bt.of(o.to+e.length),range:b.range(o.anchor+e.length,o.head+e.length)};let l=Fn(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:bt.of(o.head+e.length),range:b.cursor(o.head+e.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Ig(n,e,t){let i=null,s=n.changeByRange(r=>r.empty&&Fn(n.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:b.cursor(r.head+t.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function Ng(n,e,t,i){let s=i.stringPrefixes||wi.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:bt.of(l.to+e.length),range:b.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=Fn(n.doc,a),c;if(h==e){if(ll(n,a))return{changes:{insert:e+e,from:a},effects:bt.of(a+e.length),range:b.cursor(a+e.length)};if(ec(n,a)){let u=t&&n.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:b.cursor(a+u.length)}}}else{if(t&&n.sliceDoc(a-2*e.length,a)==e+e&&(c=al(n,a-2*e.length,s))>-1&&ll(n,c))return{changes:{insert:e+e+e+e,from:a},effects:bt.of(a+e.length),range:b.cursor(a+e.length)};if(n.charCategorizer(a)(h)!=$.Word&&al(n,a,s)>-1&&!Fg(n,a,e,s))return{changes:{insert:e+e,from:a},effects:bt.of(a+e.length),range:b.cursor(a+e.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function ll(n,e){let t=ye(n).resolveInner(e+1);return t.parent&&t.from==e}function Fg(n,e,t,i){let s=ye(n).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=n.sliceDoc(s.from,Math.min(s.to,s.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let c=s.firstChild;for(;c&&c.from==s.from&&c.to-c.from>t.length+a;){if(n.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=s.to==e&&s.parent;if(!h)break;s=h}return!1}function al(n,e,t){let i=n.charCategorizer(e);if(i(n.sliceDoc(e-1,e))!=$.Word)return e;for(let s of t){let r=e-s.length;if(n.sliceDoc(r,e)==s&&i(n.sliceDoc(r-1,r))!=$.Word)return r}return-1}function pm(n={}){return[Me,ve.of(n),yg,Wg,_h]}const Hg=[{key:"Ctrl-Space",run:ug},{key:"Escape",run:dg},{key:"ArrowDown",run:Ui(!0)},{key:"ArrowUp",run:Ui(!1)},{key:"PageDown",run:Ui(!0,"page")},{key:"PageUp",run:Ui(!1,"page")},{key:"Enter",run:fg}],Wg=At.highest(sr.computeN([ve],n=>n.facet(ve).defaultKeymap?[Hg]:[]));export{Zg as A,em as B,An as C,ku as D,O as E,tm as F,Xg as G,ye as H,j as I,Gg as J,cm as K,Hs as L,Yp as M,rr as N,b as O,Ia as P,fm as Q,Qg as R,_a as S,W as T,Yg as U,Ku as V,Ha as W,ld as X,N as a,Kg as b,rm as c,zg as d,qg as e,sm as f,um as g,Ug as h,am as i,dm as j,sr as k,lm as l,hm as m,om as n,Hg as o,pm as p,$g as q,jg as r,im as s,nm as t,me as u,L as v,Hu as w,C as x,Jg as y,Uu as z};
|