pocketbase/ui/dist/assets/index-D0ZW3duE.js

15 lines
348 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class V{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=Ue(this,t,e);let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),Gt.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=Ue(this,t,e);let i=[];return this.decompose(t,e,i,0),Gt.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new gi(this),r=new gi(t);for(let o=e,l=e;;){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(t=1){return new gi(this,t)}iterRange(t,e=this.length){return new vl(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new kl(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?V.empty:t.length<=32?new _(t):Gt.from(_.split(t,[]))}}class _ extends V{constructor(t,e=mc(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((e?i:l)>=t)return new yc(s,l,i,o);s=l+1,i++}}decompose(t,e,i,s){let r=t<=0&&e>=this.length?this:new _(Wr(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(s&1){let o=i.pop(),l=on(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new _(l,o.length+r.length));else{let a=l.length>>1;i.push(new _(l.slice(0,a)),new _(l.slice(a)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof _))return super.replace(t,e,i);[t,e]=Ue(this,t,e);let s=on(this.text,on(i.text,Wr(this.text,0,t)),e),r=this.length+i.length-(e-t);return s.length<=32?new _(s,r):Gt.from(_.split(s,[]),r)}sliceString(t,e=this.length,i=`
`){[t,e]=Ue(this,t,e);let s="";for(let r=0,o=0;r<=e&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>t&&o&&(s+=i),t<a&&e>r&&(s+=l.slice(Math.max(0,t-r),e-r)),r=a+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],s=-1;for(let r of t)i.push(r),s+=r.length+1,i.length==32&&(e.push(new _(i,s)),i=[],s=-1);return s>-1&&e.push(new _(i,s)),e}}class Gt extends V{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((e?a:l)>=t)return o.lineInner(t,e,i,s);s=l+1,i=a+1}}decompose(t,e,i,s){for(let r=0,o=0;o<=e&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(t<=a&&e>=o){let h=s&((o<=t?1:0)|(a>=e?2:0));o>=t&&a<=e&&!h?i.push(l):l.decompose(t-o,e-o,i,h)}o=a+1}}replace(t,e,i){if([t,e]=Ue(this,t,e),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(t>=r&&e<=l){let a=o.replace(t-r,e-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[s]=a,new Gt(c,this.length-(e-t)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
`){[t,e]=Ue(this,t,e);let s="";for(let r=0,o=0;r<this.children.length&&o<=e;r++){let l=this.children[r],a=o+l.length;o>t&&r&&(s+=i),t<a&&e>o&&(s+=l.sliceString(t-o,e-o,i)),o=a+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof Gt))return 0;let i=0,[s,r,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,r+=e){if(s==o||r==l)return i;let a=this.children[s],h=t.children[r];if(a!=h)return i+a.scanIdentical(h,e);i+=a.length+1}}static from(t,e=t.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of t)i+=d.lines;if(i<32){let d=[];for(let p of t)p.flatten(d);return new _(d,e)}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 Gt)for(let g of d.children)f(g);else d.lines>o&&(a>o||!a)?(u(),l.push(d)):d instanceof _&&a&&(p=c[c.length-1])instanceof _&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new _(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]:Gt.from(c,h)),h=-1,a=c.length=0)}for(let d of t)f(d);return u(),l.length==1?l[0]:new Gt(l,e)}}V.empty=new _([""],0);function mc(n){let t=-1;for(let e of n)t+=e.length+1;return t}function on(n,t,e=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>=e&&(a>i&&(l=l.slice(0,i-s)),s<e&&(l=l.slice(e-s)),o?(t[t.length-1]+=l,o=!1):t.push(l)),s=a+1}return t}function Wr(n,t,e){return on(n,[""],t,e)}class gi{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof _?t.text.length:t.children.length)<<1]}nextInner(t,e){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 _?s.text.length:s.children.length;if(o==(e>0?l:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
`,this;t--}else if(s instanceof _){let a=s.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,a.length>Math.max(0,t))return this.value=t==0?a:e>0?a.slice(t):a.slice(0,a.length-t),this;t-=a.length}else{let a=s.children[o+(e<0?-1:0)];t>a.length?(t-=a.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(e>0?1:(a instanceof _?a.text.length:a.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class vl{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new gi(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class kl{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(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"&&(V.prototype[Symbol.iterator]=function(){return this.iter()},gi.prototype[Symbol.iterator]=vl.prototype[Symbol.iterator]=kl.prototype[Symbol.iterator]=function(){return this});class yc{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}function Ue(n,t,e){return t=Math.max(0,Math.min(n.length,t)),[t,Math.max(t,Math.min(n.length,e))]}let He="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<He.length;n++)He[n]+=He[n-1];function bc(n){for(let t=1;t<He.length;t+=2)if(He[t]>n)return He[t-1]<=n;return!1}function Hr(n){return n>=127462&&n<=127487}const zr=8205;function ot(n,t,e=!0,i=!0){return(e?Cl:xc)(n,t,i)}function Cl(n,t,e){if(t==n.length)return t;t&&Al(n.charCodeAt(t))&&Ml(n.charCodeAt(t-1))&&t--;let i=nt(n,t);for(t+=Bt(i);t<n.length;){let s=nt(n,t);if(i==zr||s==zr||e&&bc(s))t+=Bt(s),i=s;else if(Hr(s)){let r=0,o=t-2;for(;o>=0&&Hr(nt(n,o));)r++,o-=2;if(r%2==0)break;t+=2}else break}return t}function xc(n,t,e){for(;t>0;){let i=Cl(n,t-2,e);if(i<t)return i;t--}return 0}function Al(n){return n>=56320&&n<57344}function Ml(n){return n>=55296&&n<56320}function nt(n,t){let e=n.charCodeAt(t);if(!Ml(e)||t+1==n.length)return e;let i=n.charCodeAt(t+1);return Al(i)?(e-55296<<10)+(i-56320)+65536:e}function or(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function Bt(n){return n<65536?1:2}const fs=/\r\n?|\n/;var ht=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(ht||(ht={}));class Qt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,s=0;e<this.sections.length;){let r=this.sections[e++],o=this.sections[e++];o<0?(t(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(t,e=!1){us(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];s<0?t.push(i,s):t.push(s,i)}return new Qt(t)}composeDesc(t){return this.empty?t:t.empty?this:Dl(this,t)}mapDesc(t,e=!1){return t.empty?this:ds(this,t,e)}mapPos(t,e=-1,i=ht.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>t)return r+(t-s);r+=l}else{if(i!=ht.Simple&&h>=t&&(i==ht.TrackDel&&s<t&&h>t||i==ht.TrackBefore&&s<t||i==ht.TrackAfter&&h>t))return null;if(h>t||h==t&&e<0&&!l)return t==s||e<0?r:r+a;r+=a}s=h}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return r}touchesRange(t,e=t){for(let i=0,s=0;i<this.sections.length&&s<=e;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=e&&l>=t)return s<t&&l>e?"cover":!0;s=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];t+=(t?" ":"")+i+(s>=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Qt(t)}static create(t){return new Qt(t)}}class et extends Qt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return us(this,(e,i,s,r,o)=>t=t.replace(s,s+(i-e),o),!1),t}mapDesc(t,e=!1){return ds(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let s=0,r=0;s<e.length;s+=2){let o=e[s],l=e[s+1];if(l>=0){e[s]=l,e[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(V.empty);i.push(o?t.slice(r,r+o):V.empty)}r+=o}return new et(e,i)}compose(t){return this.empty?t:t.empty?this:Dl(this,t,!0)}map(t,e=!1){return t.empty?this:ds(this,t,e,!0)}iterChanges(t,e=!1){us(this,t,e)}get desc(){return Qt.create(this.sections)}filter(t){let e=[],i=[],s=[],r=new xi(this);t:for(let o=0,l=0;;){let a=o==t.length?1e9:t[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break t;let c=Math.min(r.len,a-l);at(s,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;at(e,c,f),f>0&&he(i,e,r.text),r.forward(c),l+=c}let h=t[o++];for(;l<h;){if(r.done)break t;let c=Math.min(r.len,h-l);at(e,c,-1),at(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new et(e,i),filtered:Qt.create(s)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],s=this.sections[e+1];s<0?t.push(i):s==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<e&&at(s,e-o,-1);let f=new et(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 et){if(c.length!=e)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${e})`);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>e)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${e})`);let p=d?typeof d=="string"?V.of(d.split(i||fs)):d:V.empty,g=p.length;if(f==u&&g==0)return;f<o&&a(),f>o&&at(s,f-o,-1),at(s,u-f,g),he(r,s,p),o=u}}return h(t),a(!l),l}static empty(t){return new et(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let s=0;s<t.length;s++){let r=t[s];if(typeof r=="number")e.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)e.push(r[0],0);else{for(;i.length<s;)i.push(V.empty);i[s]=V.of(r.slice(1)),e.push(r[0],i[s].length)}}}return new et(e,i)}static createSet(t,e){return new et(t,e)}}function at(n,t,e,i=!1){if(t==0&&e<=0)return;let s=n.length-2;s>=0&&e<=0&&e==n[s+1]?n[s]+=t:t==0&&n[s]==0?n[s+1]+=e:i?(n[s]+=t,n[s+1]+=e):n.push(t,e)}function he(n,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(e);else{for(;n.length<i;)n.push(V.empty);n.push(e)}}function us(n,t,e){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=V.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(e||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];t(s,h,r,c,f),s=h,r=c}}}function ds(n,t,e,i=!1){let s=[],r=i?[]:null,o=new xi(n),l=new xi(t);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);at(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&&!e))){let h=l.len;for(at(s,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(at(s,0,o.ins),r&&he(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;at(s,h,a<o.i?o.ins:0),r&&a<o.i&&he(r,s,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?et.createSet(s,r):Qt.create(s);throw new Error("Mismatched change set lengths")}}function Dl(n,t,e=!1){let i=[],s=e?[]:null,r=new xi(n),o=new xi(t);for(let l=!1;;){if(r.done&&o.done)return s?et.createSet(i,s):Qt.create(i);if(r.ins==0)at(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)at(i,0,o.ins,l),s&&he(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;at(i,a,c,l),s&&c&&he(s,i,o.text)}else o.ins==-1?(at(i,r.off?0:r.len,a,l),s&&he(s,i,r.textBit(a))):(at(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&he(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 xi{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[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:t}=this.set,e=this.i-2>>1;return e>=t.length?V.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?V.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class ve{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new ve(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return b.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return b.range(this.anchor,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(t.anchor,t.head)}static create(t,e,i){return new ve(t,e,i)}}class b{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:b.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(t,e=!0){return b.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,b.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(t.ranges.map(e=>ve.fromJSON(e)),t.main)}static single(t,e=t){return new b([b.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<t.length;s++){let r=t[s];if(r.empty?r.from<=i:r.from<i)return b.normalized(t.slice(),e);i=r.to}return new b(t,e)}static cursor(t,e=0,i,s){return ve.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(t,e,i,s){let r=(i??16777215)<<6|(s==null?7:Math.min(6,s));return e<t?ve.create(e,t,48|r):ve.create(t,e,(e>t?8:0)|r)}static normalized(t,e=0){let i=t[e];t.sort((s,r)=>s.from-r.from),e=t.indexOf(i);for(let s=1;s<t.length;s++){let r=t[s],o=t[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<=e&&e--,t.splice(--s,2,r.anchor>r.head?b.range(a,l):b.range(l,a))}}return new b(t,e)}}function Ol(n,t){for(let e of n.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}let lr=0;class T{constructor(t,e,i,s,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.id=lr++,this.default=t([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(t={}){return new T(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:ar),!!t.static,t.enables)}of(t){return new ln([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new ln(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new ln(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}}function ar(n,t){return n==t||n.length==t.length&&n.every((e,i)=>e===t[i])}class ln{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=lr++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,r=this.id,o=t[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:((e=t[f.id])!==null&&e!==void 0?e:1)&1||c.push(t[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||ps(f,c)){let d=i(f);if(l?!qr(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=gn(u,p);if(this.dependencies.every(m=>m instanceof T?u.facet(m)===f.facet(m):m instanceof bt?u.field(m,!1)==f.field(m,!1):!0)||(l?qr(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 qr(n,t,e){if(n.length!=t.length)return!1;for(let i=0;i<n.length;i++)if(!e(n[i],t[i]))return!1;return!0}function ps(n,t){let e=!1;for(let i of t)mi(n,i)&1&&(e=!0);return e}function wc(n,t,e){let i=e.map(a=>n[a.id]),s=e.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[t.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=gn(a,i[c]);if(s[c]==2)for(let u of f)h.push(u);else h.push(f)}return t.combine(h)}return{create(a){for(let h of i)mi(a,h);return a.values[o]=l(a),1},update(a,h){if(!ps(a,r))return 0;let c=l(a);return t.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=ps(a,i),f=h.config.facets[t.id],u=h.facet(t);if(f&&!c&&ar(e,f))return a.values[o]=u,0;let d=l(a);return t.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Kr=T.define({static:!0});class bt{constructor(t,e,i,s,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(t){let e=new bt(lr++,t.create,t.update,t.compare||((i,s)=>i===s),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(Kr).find(i=>i.field==this);return((e==null?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,s)=>{let r=i.values[e],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[e]=o,1)},reconfigure:(i,s)=>s.config.address[this.id]!=null?(i.values[e]=s.field(this),0):(i.values[e]=this.create(i),1)}}init(t){return[this,Kr.of({field:this,create:t})]}get extension(){return this}}const Se={lowest:4,low:3,default:2,high:1,highest:0};function si(n){return t=>new Tl(t,n)}const ye={highest:si(Se.highest),high:si(Se.high),default:si(Se.default),low:si(Se.low),lowest:si(Se.lowest)};class Tl{constructor(t,e){this.inner=t,this.prec=e}}class En{of(t){return new gs(this,t)}reconfigure(t){return En.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class gs{constructor(t,e){this.compartment=t,this.inner=e}}class pn{constructor(t,e,i,s,r,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let s=[],r=Object.create(null),o=new Map;for(let u of Sc(t,e,o))u instanceof bt?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,ar(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=>wc(m,p,d))}}let f=h.map(u=>u(l));return new pn(t,o,f,l,a,r)}}function Sc(n,t,e){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 gs&&e.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof gs){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=t.get(o.compartment)||o.inner;e.set(o.compartment,h),r(h,l)}else if(o instanceof Tl)r(o.inner,o.prec);else if(o instanceof bt)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof ln)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,Se.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,Se.default),i.reduce((o,l)=>o.concat(l))}function mi(n,t){if(t&1)return 2;let e=t>>1,i=n.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[e]=4;let s=n.computeSlot(n,n.config.dynamicSlots[e]);return n.status[e]=2|s}function gn(n,t){return t&1?n.config.staticValues[t>>1]:n.values[t>>1]}const Pl=T.define(),ms=T.define({combine:n=>n.some(t=>t),static:!0}),Bl=T.define({combine:n=>n.length?n[0]:void 0,static:!0}),Rl=T.define(),Ll=T.define(),El=T.define(),Il=T.define({combine:n=>n.length?n[0]:!1});class se{constructor(t,e){this.type=t,this.value=e}static define(){return new vc}}class vc{of(t){return new se(this,t)}}class kc{constructor(t){this.map=t}of(t){return new F(this,t)}}class F{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new F(this.type,e)}is(t){return this.type==t}static define(t={}){return new kc(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let r=s.map(e);r&&i.push(r)}return i}}F.reconfigure=F.define();F.appendConfig=F.define();class Q{constructor(t,e,i,s,r,o){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Ol(i,e.newLength),r.some(l=>l.type==Q.time)||(this.annotations=r.concat(Q.time.of(Date.now())))}static create(t,e,i,s,r,o){return new Q(t,e,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(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(Q.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}}Q.time=se.define();Q.userEvent=se.define();Q.addToHistory=se.define();Q.remote=se.define();function Cc(n,t){let e=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==t.length||t[s]>=n[i]))r=n[i++],o=n[i++];else if(s<t.length)r=t[s++],o=t[s++];else return e;!e.length||e[e.length-1]<r?e.push(r,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function Nl(n,t,e){var i;let s,r,o;return e?(s=t.changes,r=et.empty(t.changes.length),o=n.changes.compose(t.changes)):(s=t.changes.map(n.changes),r=n.changes.mapDesc(t.changes,!0),o=n.changes.compose(s)),{changes:o,selection:t.selection?t.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:F.mapEffects(n.effects,s).concat(F.mapEffects(t.effects,r)),annotations:n.annotations.length?n.annotations.concat(t.annotations):t.annotations,scrollIntoView:n.scrollIntoView||t.scrollIntoView}}function ys(n,t,e){let i=t.selection,s=ze(t.annotations);return t.userEvent&&(s=s.concat(Q.userEvent.of(t.userEvent))),{changes:t.changes instanceof et?t.changes:et.of(t.changes||[],e,n.facet(Bl)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:ze(t.effects),annotations:s,scrollIntoView:!!t.scrollIntoView}}function Fl(n,t,e){let i=ys(n,t.length?t[0]:{},n.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let r=1;r<t.length;r++){t[r].filter===!1&&(e=!1);let o=!!t[r].sequential;i=Nl(i,ys(n,t[r],o?i.changes.newLength:n.doc.length),o)}let s=Q.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Mc(e?Ac(s):s)}function Ac(n){let t=n.startState,e=!0;for(let s of t.facet(Rl)){let r=s(n);if(r===!1){e=!1;break}Array.isArray(r)&&(e=e===!0?r:Cc(e,r))}if(e!==!0){let s,r;if(e===!1)r=n.changes.invertedDesc,s=et.empty(t.doc.length);else{let o=n.changes.filter(e);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=Q.create(t,s,n.selection&&n.selection.map(r),F.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=t.facet(Ll);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof Q?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Q?n=r[0]:n=Fl(t,ze(r),!1)}return n}function Mc(n){let t=n.startState,e=t.facet(El),i=n;for(let s=e.length-1;s>=0;s--){let r=e[s](n);r&&Object.keys(r).length&&(i=Nl(i,ys(t,r,n.changes.newLength),!0))}return i==n?n:Q.create(t,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const Dc=[];function ze(n){return n==null?Dc:Array.isArray(n)?n:[n]}var G=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(G||(G={}));const Oc=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let bs;try{bs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Tc(n){if(bs)return bs.test(n);for(let t=0;t<n.length;t++){let e=n[t];if(/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||Oc.test(e)))return!0}return!1}function Pc(n){return t=>{if(!/\S/.test(t))return G.Space;if(Tc(t))return G.Word;for(let e=0;e<n.length;e++)if(t.indexOf(n[e])>-1)return G.Word;return G.Other}}class H{constructor(t,e,i,s,r,o){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)mi(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return mi(this,i),gn(this,i)}update(...t){return Fl(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:s}=e;for(let l of t.effects)l.is(En.reconfigure)?(e&&(s=new Map,e.compartments.forEach((a,h)=>s.set(h,a)),e=null),s.set(l.value.compartment,l.value.extension)):l.is(F.reconfigure)?(e=null,i=l.value):l.is(F.appendConfig)&&(e=null,i=ze(i).concat(l.value));let r;e?r=t.startState.values.slice():(e=pn.resolve(i,s,this),r=new H(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=t.startState.facet(ms)?t.newSelection:t.newSelection.asSingle();new H(e,t.newDoc,o,r,(l,a)=>a.update(l,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:b.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),r=[i.range],o=ze(i.effects);for(let l=1;l<e.ranges.length;l++){let a=t(e.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=F.mapEffects(o,c).concat(F.mapEffects(ze(a.effects),f))}return{changes:s,selection:b.create(r,e.mainIndex),effects:o}}changes(t=[]){return t instanceof et?t:et.of(t,this.doc.length,this.facet(H.lineSeparator))}toText(t){return V.of(t.split(this.facet(H.lineSeparator)||fs))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(mi(this,e),gn(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let s=t[i];s instanceof bt&&this.config.address[s.id]!=null&&(e[i]=s.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(t,r)){let o=i[r],l=t[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return H.create({doc:t.doc,selection:b.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(t={}){let e=pn.resolve(t.extensions||[],new Map),i=t.doc instanceof V?t.doc:V.of((t.doc||"").split(e.staticFacet(H.lineSeparator)||fs)),s=t.selection?t.selection instanceof b?t.selection:b.single(t.selection.anchor,t.selection.head):b.single(0);return Ol(s,i.length),e.staticFacet(ms)||(s=s.asSingle()),new H(e,i,s,e.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(H.tabSize)}get lineBreak(){return this.facet(H.lineSeparator)||`
`}get readOnly(){return this.facet(Il)}phrase(t,...e){for(let i of this.facet(H.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>e.length?i:e[r-1]})),t}languageDataAt(t,e,i=-1){let s=[];for(let r of this.facet(Pl))for(let o of r(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&s.push(o[t]);return s}charCategorizer(t){return Pc(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),r=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let a=ot(e,o,!1);if(r(e.slice(a,o))!=G.Word)break;o=a}for(;l<s;){let a=ot(e,l);if(r(e.slice(l,a))!=G.Word)break;l=a}return o==l?null:b.range(o+i,l+i)}}H.allowMultipleSelections=ms;H.tabSize=T.define({combine:n=>n.length?n[0]:4});H.lineSeparator=Bl;H.readOnly=Il;H.phrases=T.define({compare(n,t){let e=Object.keys(n),i=Object.keys(t);return e.length==i.length&&e.every(s=>n[s]==t[s])}});H.languageData=Pl;H.changeFilter=Rl;H.transactionFilter=Ll;H.transactionExtender=El;En.reconfigure=F.define();function Le(n,t,e={}){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(e,r))i[r]=e[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in t)i[s]===void 0&&(i[s]=t[s]);return i}class Me{eq(t){return this==t}range(t,e=t){return xs.create(t,e,this)}}Me.prototype.startSide=Me.prototype.endSide=0;Me.prototype.point=!1;Me.prototype.mapMode=ht.TrackDel;let xs=class Vl{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new Vl(t,e,i)}};function ws(n,t){return n.from-t.from||n.value.startSide-t.value.startSide}class hr{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,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]-t||(i?this.value[a].endSide:this.value[a].startSide)-e;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(t,e,i,s){for(let r=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+t,this.to[r]+t,this.value[r])===!1)return!1}map(t,e){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]+t,f=this.to[a]+t,u,d;if(c==f){let p=e.mapPos(c,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=e.mapPos(c,h.endSide),d<u)))continue}else if(u=e.mapPos(c,h.startSide),d=e.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 hr(s,r,i,l):null,pos:o}}}class K{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new K(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(ws)),this.isEmpty)return e.length?K.of(e):this;let l=new Wl(this,null,-1).goto(0),a=0,h=[],c=new De;for(;l.value||a<e.length;)if(a<e.length&&(l.from-e[a].from||l.startSide-e[a].value.startSide)>=0){let f=e[a++];c.addInner(f.from,f.to,f.value)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==e.length||this.chunkEnd(l.chunkIndex)<e[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(xs.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(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=t.touchesRange(l,l+a.length);if(h===!1)s=Math.max(s,a.maxPoint),e.push(a),i.push(t.mapPos(l));else if(h===!0){let{mapped:c,pos:f}=a.map(l,t);c&&(s=Math.max(s,c.maxPoint),e.push(c),i.push(f))}}let r=this.nextLayer.map(t);return e.length==0?r:new K(i,e,r||K.empty,s)}between(t,e,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(e>=r&&t<=r+o.length&&o.between(r,t-r,e-r,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return wi.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return wi.from(t).goto(e)}static compare(t,e,i,s,r=-1){let o=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=$r(o,l,i),h=new ri(o,a,r),c=new ri(l,a,r);i.iterGaps((f,u,d)=>jr(h,f,c,u,d,s)),i.empty&&i.length==0&&jr(h,0,c,0,0,s)}static eq(t,e,i=0,s){s==null&&(s=999999999);let r=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0),o=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=$r(r,o),a=new ri(r,l,0).goto(i),h=new ri(o,l,0).goto(i);for(;;){if(a.to!=h.to||!Ss(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(t,e,i,s,r=-1){let o=new ri(t,null,r).goto(e),l=e,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<e?c.length+1:o.point.startSide<0?c.length: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(t,e=!1){let i=new De;for(let s of t instanceof xs?[t]:e?Bc(t):t)i.add(s.from,s.to,s.value);return i.finish()}static join(t){if(!t.length)return K.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let s=t[i];s!=K.empty;s=s.nextLayer)e=new K(s.chunkPos,s.chunk,e,Math.max(s.maxPoint,e.maxPoint));return e}}K.empty=new K([],[],null,-1);function Bc(n){if(n.length>1)for(let t=n[0],e=1;e<n.length;e++){let i=n[e];if(ws(t,i)>0)return n.slice().sort(ws);t=i}return n}K.empty.nextLayer=K.empty;class De{finishChunk(t){this.chunks.push(new hr(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,t&&(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(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new De)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-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=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(K.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=K.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function $r(n,t,e){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 t)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(e?e.mapPos(l):l)==r.chunkPos[o]&&!(e!=null&&e.touchesRange(l,l+r.chunk[o].length))&&s.add(r.chunk[o])}return s}class Wl{constructor(t,e,i,s=0){this.layer=t,this.skip=e,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(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,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)<t||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==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=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class wi{constructor(t){this.heap=t}static from(t,e=null,i=-1){let s=[];for(let r=0;r<t.length;r++)for(let o=t[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new Wl(o,e,i,r));return s.length==1?s[0]:new wi(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)jn(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)jn(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),jn(this.heap,0)}}}function jn(n,t){for(let e=n[t];;){let i=(t<<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++),e.compare(s)<0)break;n[i]=e,n[t]=s,t=i}}class ri{constructor(t,e,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=wi.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Wi(this.active,t),Wi(this.activeTo,t),Wi(this.activeRank,t),this.minActive=Ur(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:r}=this.cursor;for(;e<this.activeRank.length&&(r-this.activeRank[e]||s-this.activeTo[e])>0;)e++;Hi(this.active,e,i),Hi(this.activeTo,e,s),Hi(this.activeRank,e,r),t&&Hi(t,e,this.cursor.from),this.minActive=Ur(this.active,this.activeTo)}next(){let t=this.to,e=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]>t){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&Wi(i,s)}else if(this.cursor.value)if(this.cursor.from>t){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(e&&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]<t;s--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function jr(n,t,e,i,s,r){n.goto(t),e.goto(i);let o=i+s,l=i,a=i-t;for(;;){let h=n.to+a-e.to||n.endSide-e.endSide,c=h<0?n.to+a:e.to,f=Math.min(c,o);if(n.point||e.point?n.point&&e.point&&(n.point==e.point||n.point.eq(e.point))&&Ss(n.activeForPoint(n.to),e.activeForPoint(e.to))||r.comparePoint(l,f,n.point,e.point):f>l&&!Ss(n.active,e.active)&&r.compareRange(l,f,n.active,e.active),c>o)break;l=c,h<=0&&n.next(),h>=0&&e.next()}}function Ss(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!=t[e]&&!n[e].eq(t[e]))return!1;return!0}function Wi(n,t){for(let e=t,i=n.length-1;e<i;e++)n[e]=n[e+1];n.pop()}function Hi(n,t,e){for(let i=n.length-1;i>=t;i--)n[i+1]=n[i];n[t]=e}function Ur(n,t){let e=-1,i=1e9;for(let s=0;s<t.length;s++)(t[s]-i||n[s].endSide-n[e].endSide)<0&&(e=s,i=t[s]);return e}function ti(n,t,e=n.length){let i=0;for(let s=0;s<e;)n.charCodeAt(s)==9?(i+=t-i%t,s++):(i++,s=ot(n,s));return i}function vs(n,t,e,i){for(let s=0,r=0;;){if(r>=t)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?e-r%e:1,s=ot(n,s)}return i===!0?-1:n.length}const ks="ͼ",Gr=typeof Symbol>"u"?"__"+ks:Symbol.for(ks),Cs=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Jr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class de{constructor(t,e){this.rules=[];let{finish:i}=e||{};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 t)r(s(o),t[o],this.rules)}getRules(){return this.rules.join(`
`)}static newName(){let t=Jr[Gr]||1;return Jr[Gr]=t+1,ks+t.toString(36)}static mount(t,e,i){let s=t[Cs],r=i&&i.nonce;s?r&&s.setNonce(r):s=new Rc(t,r),s.mount(Array.isArray(e)?e:[e],t)}}let Yr=new Map;class Rc{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let r=Yr.get(i);if(r)return t[Cs]=r;this.sheet=new s.CSSStyleSheet,Yr.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Cs]=this}mount(t,e){let i=this.sheet,s=0,r=0;for(let o=0;o<t.length;o++){let l=t[o],a=this.modules.indexOf(l);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),a==-1){if(this.modules.splice(r++,0,l),i)for(let h=0;h<l.rules.length;h++)i.insertRule(l.rules[h],s++)}else{for(;r<a;)s+=this.modules[r++].rules.length;s+=l.rules.length,r++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let o="";for(let a=0;a<this.modules.length;a++)o+=this.modules[a].getRules()+`
`;this.styleTag.textContent=o;let l=e.head||e;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}var pe={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:"'"},Si={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Lc=typeof navigator<"u"&&/Mac/.test(navigator.platform),Ec=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var st=0;st<10;st++)pe[48+st]=pe[96+st]=String(st);for(var st=1;st<=24;st++)pe[st+111]="F"+st;for(var st=65;st<=90;st++)pe[st]=String.fromCharCode(st+32),Si[st]=String.fromCharCode(st);for(var Un in pe)Si.hasOwnProperty(Un)||(Si[Un]=pe[Un]);function Ic(n){var t=Lc&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Ec&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",e=!t&&n.key||(n.shiftKey?Si:pe)[n.keyCode]||n.key||"Unidentified";return e=="Esc"&&(e="Escape"),e=="Del"&&(e="Delete"),e=="Left"&&(e="ArrowLeft"),e=="Up"&&(e="ArrowUp"),e=="Right"&&(e="ArrowRight"),e=="Down"&&(e="ArrowDown"),e}function vi(n){let t;return n.nodeType==11?t=n.getSelection?n:n.ownerDocument:t=n,t.getSelection()}function As(n,t){return t?n==t||n.contains(t.nodeType!=1?t.parentNode:t):!1}function Nc(n){let t=n.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function an(n,t){if(!t.anchorNode)return!1;try{return As(n,t.anchorNode)}catch{return!1}}function Ge(n){return n.nodeType==3?Te(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function yi(n,t,e,i){return e?Xr(n,t,e,i,-1)||Xr(n,t,e,i,1):!1}function Oe(n){for(var t=0;;t++)if(n=n.previousSibling,!n)return t}function mn(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Xr(n,t,e,i,s){for(;;){if(n==e&&t==i)return!0;if(t==(s<0?0:ie(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;t=Oe(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[t+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;t=s<0?ie(n):0}else return!1}}function ie(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function In(n,t){let e=t?n.left:n.right;return{left:e,right:e,top:n.top,bottom:n.bottom}}function Fc(n){let t=n.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Hl(n,t){let e=t.width/n.offsetWidth,i=t.height/n.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-n.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-n.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function Vc(n,t,e,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,p=1,g=1;if(d)u=Fc(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 x=c.getBoundingClientRect();({scaleX:p,scaleY:g}=Hl(c,x)),u={left:x.left,right:x.left+c.clientWidth*p,top:x.top,bottom:x.top+c.clientHeight*g}}let m=0,y=0;if(s=="nearest")t.top<u.top?(y=-(u.top-t.top+o),e>0&&t.bottom>u.bottom+y&&(y=t.bottom-u.bottom+y+o)):t.bottom>u.bottom&&(y=t.bottom-u.bottom+o,e<0&&t.top-y<u.top&&(y=-(u.top+y-t.top+o)));else{let x=t.bottom-t.top,v=u.bottom-u.top;y=(s=="center"&&x<=v?t.top+x/2-v/2:s=="start"||s=="center"&&e<0?t.top-o:t.bottom-v+o)-u.top}if(i=="nearest"?t.left<u.left?(m=-(u.left-t.left+r),e>0&&t.right>u.right+m&&(m=t.right-u.right+m+r)):t.right>u.right&&(m=t.right-u.right+r,e<0&&t.left<u.left+m&&(m=-(u.left+m-t.left+r))):m=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-r:t.right-(u.right-u.left)+r)-u.left,m||y)if(d)h.scrollBy(m,y);else{let x=0,v=0;if(y){let S=c.scrollTop;c.scrollTop+=y/g,v=(c.scrollTop-S)*g}if(m){let S=c.scrollLeft;c.scrollLeft+=m/p,x=(c.scrollLeft-S)*p}t={left:t.left-x,top:t.top-v,right:t.right-x,bottom:t.bottom-v},x&&Math.abs(x-m)<1&&(i="nearest"),v&&Math.abs(v-y)<1&&(s="nearest")}if(d)break;c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Wc(n){let t=n.ownerDocument;for(let e=n.parentNode;e&&e!=t.body;)if(e.nodeType==1){if(e.scrollHeight>e.clientHeight||e.scrollWidth>e.clientWidth)return e;e=e.assignedSlot||e.parentNode}else if(e.nodeType==11)e=e.host;else break;return null}class Hc{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?ie(e):0),i,Math.min(t.focusOffset,i?ie(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let Ne=null;function zl(n){if(n.setActive)return n.setActive();if(Ne)return n.focus(Ne);let t=[];for(let e=n;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(n.focus(Ne==null?{get preventScroll(){return Ne={preventScroll:!0},!0}}:void 0),!Ne){Ne=!1;for(let e=0;e<t.length;){let i=t[e++],s=t[e++],r=t[e++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let _r;function Te(n,t,e=t){let i=_r||(_r=document.createRange());return i.setEnd(n,e),i.setStart(n,t),i}function qe(n,t,e,i){let s={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function zc(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function ql(n){for(;n.attributes.length;)n.removeAttributeNode(n.attributes[0])}function qc(n,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,ie(e));;)if(i){if(e.nodeType!=1)return!1;let s=e.childNodes[i-1];s.contentEditable=="false"?i--:(e=s,i=ie(e))}else{if(e==n)return!0;i=Oe(e),e=e.parentNode}}function Kl(n){return n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function $l(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=ie(e)}else if(e.parentNode&&!mn(e))i=Oe(e),e=e.parentNode;else return null}}function jl(n,t){for(let e=n,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!mn(e))i=Oe(e)+1,e=e.parentNode;else return null}}class ct{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new ct(t.parentNode,Oe(t),e)}static after(t,e){return new ct(t.parentNode,Oe(t)+1,e)}}const cr=[];class ${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(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){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=$.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=s?s.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=Qr(r);else i.insertBefore(o.dom,r);s=o.dom}for(r=s?s.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=Qr(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=ie(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;s==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?s=-1:s=1),t=r}s<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!$.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(t,e,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<t&&u>e)return f.domBoundsAround(t,e,h);if(u>=t&&s==-1&&(s=a,r=h),h>e&&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(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=cr){this.markDirty();for(let s=t;s<e;s++){let r=this.children[s];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(t,e-t,...i);for(let s=0;s<i.length;s++)i[s].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new Ul(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,s,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}$.prototype.breakAfter=0;function Qr(n){let t=n.nextSibling;return n.parentNode.removeChild(n),t}class Ul{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Gl(n,t,e,i,s,r,o,l,a){let{children:h}=n,c=h.length?h[t]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(t==i&&c&&!o&&!u&&r.length<2&&c.merge(e,s,r.length?f:null,e==0,l,a))){if(i<h.length){let d=h[i];d&&(s<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(t==i&&(d=d.split(s),s=0),!u&&f&&d.merge(0,s,f,!0,0,a)?r[r.length-1]=d:((s||d.children.length&&!d.children[0].length)&&d.merge(0,s,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(c&&(c.breakAfter=o,e>0&&(!o&&r.length&&c.merge(e,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(e<c.length||c.children.length&&c.children[c.children.length-1].length==0)&&c.merge(e,c.length,null,!1,l,0),t++));t<i&&r.length;)if(h[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(h[t].become(r[0]))t++,r.shift(),l=r.length?0:a;else break;!r.length&&t&&i<h.length&&!h[t-1].breakAfter&&h[i].merge(0,0,h[t-1],!1,l,a)&&t--,(t<i||r.length)&&n.replaceChildren(t,i,r)}}function Jl(n,t,e,i,s,r){let o=n.childCursor(),{i:l,off:a}=o.findPos(e,1),{i:h,off:c}=o.findPos(t,-1),f=t-e;for(let u of i)f+=u.length;n.length+=f,Gl(n,h,c,l,a,i,0,s,r)}let St=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Ms=typeof document<"u"?document:{documentElement:{style:{}}};const Ds=/Edge\/(\d+)/.exec(St.userAgent),Yl=/MSIE \d/.test(St.userAgent),Os=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(St.userAgent),Nn=!!(Yl||Os||Ds),Zr=!Nn&&/gecko\/(\d+)/i.test(St.userAgent),Gn=!Nn&&/Chrome\/(\d+)/.exec(St.userAgent),to="webkitFontSmoothing"in Ms.documentElement.style,Xl=!Nn&&/Apple Computer/.test(St.vendor),eo=Xl&&(/Mobile\/\w+/.test(St.userAgent)||St.maxTouchPoints>2);var D={mac:eo||/Mac/.test(St.platform),windows:/Win/.test(St.platform),linux:/Linux|X11/.test(St.platform),ie:Nn,ie_version:Yl?Ms.documentMode||6:Os?+Os[1]:Ds?+Ds[1]:0,gecko:Zr,gecko_version:Zr?+(/Firefox\/(\d+)/.exec(St.userAgent)||[0,0])[1]:0,chrome:!!Gn,chrome_version:Gn?+Gn[1]:0,ios:eo,android:/Android\b/.test(St.userAgent),webkit:to,safari:Xl,webkit_version:to?+(/\bAppleWebKit\/(\d+)/.exec(St.userAgent)||[0,0])[1]:0,tabSize:Ms.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const Kc=256;class Vt extends ${constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof Vt)||this.length-(e-t)+i.length>Kc||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Vt(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new ct(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return $c(this.dom,t,e)}}class ne extends ${constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let s of e)s.setParent(this)}setAttrs(t){if(ql(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,s,r,o){return i&&(!(i instanceof ne&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(Jl(this,t,e,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let l of this.children){let a=i+l.length;a>t&&e.push(i<t?l.split(t-i):l),s<0&&i>=t&&(s=r),i=a,r++}let o=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new ne(this.mark,e,o)}domAtPos(t){return _l(this,t)}coordsAt(t,e){return Zl(this,t,e)}}function $c(n,t,e){let i=n.nodeValue.length;t>i&&(t=i);let s=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?D.chrome||D.gecko||(t?(s--,o=1):r<i&&(r++,o=-1)):e<0?s--:r<i&&r++;let l=Te(n,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:e>=0)?0:l.length-1];return D.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?In(a,o<0):a||null}class ke extends ${static create(t,e,i){return new ke(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=ke.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,s,r,o){return i&&(!(i instanceof ke)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof ke&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return V.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,s=this.posAtStart;return i?i.slice(s,s+this.length):V.empty}domAtPos(t){return(this.length?t==0:this.side>0)?ct.before(this.dom):ct.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?s.length-1:0;r=s[l],!(t>0?l==0:l==s.length-1||r.top<r.bottom);l+=o?-1:1);return In(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 Je extends ${constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof Je&&t.side==this.side}split(){return new Je(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?ct.before(this.dom):ct.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return V.empty}get isHidden(){return!0}}Vt.prototype.children=ke.prototype.children=Je.prototype.children=cr;function _l(n,t){let e=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(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=s;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=s;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new ct(e,0)}function Ql(n,t,e){let i,{children:s}=n;e>0&&t instanceof ne&&s.length&&(i=s[s.length-1])instanceof ne&&i.mark.eq(t.mark)?Ql(i,t.children[0],e-1):(s.push(t),t.setParent(n)),n.length+=t.length}function Zl(n,t,e){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&&e>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,t);let a=(e<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?s:o),e):jc(n)}function jc(n){let t=n.dom.lastChild;if(!t)return n.dom.getBoundingClientRect();let e=Ge(t);return e[e.length-1]||null}function Ts(n,t){for(let e in n)e=="class"&&t.class?t.class+=" "+n.class:e=="style"&&t.style?t.style+=";"+n.style:t[e]=n[e];return t}const io=Object.create(null);function fr(n,t,e){if(n==t)return!0;n||(n=io),t||(t=io);let i=Object.keys(n),s=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=s.length-(e&&s.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(s.indexOf(r)==-1||n[r]!==t[r]))return!1;return!0}function Ps(n,t,e){let i=!1;if(t)for(let s in t)e&&s in e||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(e)for(let s in e)t&&t[s]==e[s]||(i=!0,s=="style"?n.style.cssText=e[s]:n.setAttribute(s,e[s]));return i}function Uc(n){let t=Object.create(null);for(let e=0;e<n.attributes.length;e++){let i=n.attributes[e];t[i.name]=i.value}return t}class tt extends ${constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,o){if(i){if(!(i instanceof tt))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Jl(this,t,e,i?i.children.slice():[],r,o),!0}split(t){let e=new tt;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:s}=this.childPos(t);s&&(e.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++)e.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=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){fr(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Ql(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Ts(e,this.attrs||{})),i&&(this.attrs=Ts({class:i},this.attrs||{}))}domAtPos(t){return _l(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(ql(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(Ps(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let s=this.dom.lastChild;for(;s&&$.get(s)instanceof ne;)s=s.lastChild;if(!s||!this.length||s.nodeName!="BR"&&((i=$.get(s))===null||i===void 0?void 0:i.isEditable)==!1&&(!D.ios||!this.children.some(r=>r instanceof Vt))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof Vt)||/[^ -~]/.test(i.text))return null;let s=Ge(i.dom);if(s.length!=1)return null;t+=s[0].width,e=s[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=Zl(this,t,e);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(t){return!1}covers(){return!0}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],o=s+r.length;if(o>=e){if(r instanceof tt)return r;if(o>e)break}s=o+r.breakAfter}return null}}class te extends ${constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,o){return i&&(!(i instanceof te)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?ct.before(this.dom):ct.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new te(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return cr}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):V.empty}domBoundsAround(){return null}become(t){return t instanceof te&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}}class Ee{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var Ot=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(Ot||(Ot={}));class P extends Me{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new Ri(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new ge(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,s;if(t.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=ta(t,e);i=(r?e?-3e8:-1:5e8)-1,s=(o?e?2e8:1:-6e8)+1}return new ge(t,i,s,e,t.widget||null,!0)}static line(t){return new Li(t)}static set(t,e=!1){return K.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}P.none=K.empty;class Ri extends P{constructor(t){let{start:e,end:i}=ta(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof Ri&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&fr(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Ri.prototype.point=!1;class Li extends P{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Li&&this.spec.class==t.spec.class&&fr(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Li.prototype.mapMode=ht.TrackBefore;Li.prototype.point=!0;class ge extends P{constructor(t,e,i,s,r,o){super(e,i,r,t),this.block=s,this.isReplace=o,this.mapMode=s?e<=0?ht.TrackBefore:ht.TrackAfter:ht.TrackDel}get type(){return this.startSide!=this.endSide?Ot.WidgetRange:this.startSide<=0?Ot.WidgetBefore:Ot.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof ge&&Gc(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}ge.prototype.point=!0;function ta(n,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=n;return e==null&&(e=n.inclusive),i==null&&(i=n.inclusive),{start:e??t,end:i??t}}function Gc(n,t){return n==t||!!(n&&t&&n.compare(t))}function Bs(n,t,e,i=0){let s=e.length-1;s>=0&&e[s]+i>=n?e[s]=Math.max(e[s],t):e.push(n,t)}class bi{constructor(t,e,i,s){this.doc=t,this.pos=e,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=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof te&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new tt),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(zi(new Je(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof te)&&this.getLine()}buildText(t,e,i){for(;t>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,t--;continue}else this.text=r,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(zi(new Vt(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ge){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof ge)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new te(i.widget||Ye.block,l,i));else{let a=ke.create(i.widget||Ye.inline,l,l?0:i.startSide),h=this.atCursorPos&&!a.isEditable&&r<=s.length&&(t<e||i.startSide>0),c=!a.isEditable&&(t<e||r>s.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!h&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(s),h&&(f.append(zi(new Je(1),s),r),r=s.length+Math.max(0,r-s.length)),f.append(zi(a,s),r),this.atCursorPos=c,this.pendingBuffer=c?t<e||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=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let o=new bi(t,e,i,r);return o.openEnd=K.spans(s,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function zi(n,t){for(let e of t)n=new ne(e,[n],n.length);return n}class Ye extends Ee{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}Ye.inline=new Ye("span");Ye.block=new Ye("div");var X=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(X||(X={}));const Pe=X.LTR,ur=X.RTL;function ea(n){let t=[];for(let e=0;e<n.length;e++)t.push(1<<+n[e]);return t}const Jc=ea("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Yc=ea("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Rs=Object.create(null),qt=[];for(let n of["()","[]","{}"]){let t=n.charCodeAt(0),e=n.charCodeAt(1);Rs[t]=e,Rs[e]=-t}function ia(n){return n<=247?Jc[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Yc[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const Xc=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class ce{get dir(){return this.level%2?ur:Pe}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function na(n,t){if(n.length!=t.length)return!1;for(let e=0;e<n.length;e++){let i=n[e],s=t[e];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!na(i.inner,s.inner))return!1}return!0}const q=[];function _c(n,t,e,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,a=r?256:s;for(let h=o,c=a,f=a;h<l;h++){let u=ia(n.charCodeAt(h));u==512?u=c:u==8&&f==4&&(u=16),q[h]=u==4?2:u,u&7&&(f=u),c=u}for(let h=o,c=a,f=a;h<l;h++){let u=q[h];if(u==128)h<l-1&&c==q[h+1]&&c&24?u=q[h]=c:q[h]=256;else if(u==64){let d=h+1;for(;d<l&&q[d]==64;)d++;let p=h&&c==8||d<e&&q[d]==8?f==1?1:8:256;for(let g=h;g<d;g++)q[g]=p;h=d-1}else u==8&&f==1&&(q[h]=1);c=u,u&7&&(f=u)}}}function Qc(n,t,e,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:t,c=o<i.length?i[o].from:e;for(let f=h,u,d,p;f<c;f++)if(d=Rs[u=n.charCodeAt(f)])if(d<0){for(let g=l-3;g>=0;g-=3)if(qt[g+1]==-d){let m=qt[g+2],y=m&2?s:m&4?m&1?r:s:0;y&&(q[f]=q[qt[g]]=y),l=g;break}}else{if(qt.length==189)break;qt[l++]=f,qt[l++]=u,qt[l++]=a}else if((p=q[f])==2||p==1){let g=p==s;a=g?0:1;for(let m=l-3;m>=0;m-=3){let y=qt[m+2];if(y&2)break;if(g)qt[m+2]|=2;else{if(y&4)break;qt[m+2]|=4}}}}}function Zc(n,t,e,i){for(let s=0,r=i;s<=e.length;s++){let o=s?e[s-1].to:n,l=s<e.length?e[s].from:t;for(let a=o;a<l;){let h=q[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==e.length)break;c=e[s++].to,l=s<e.length?e[s].from:t}else if(q[c]==256)c++;else break;let f=r==1,u=(c<t?q[c]:i)==1,d=f==u?f?1:2:i;for(let p=c,g=s,m=g?e[g-1].to:n;p>a;)p==m&&(p=e[--g].from,m=g?e[g-1].to:n),q[--p]=d;a=c}else r=h,a++}}}function Ls(n,t,e,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=t,h=0;a<e;){let c=!0,f=!1;if(h==r.length||a<r[h].from){let g=q[a];g!=l&&(c=!1,f=g==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;t:for(;;)if(h<r.length&&p==r[h].from){if(f)break t;let g=r[h];if(!c)for(let m=g.to,y=h+1;;){if(m==e)break t;if(y<r.length&&r[y].from==m)m=r[y++].to;else{if(q[m]==l)break t;break}}if(h++,u)u.push(g);else{g.from>a&&o.push(new ce(a,g.from,d));let m=g.direction==Pe!=!(d%2);Es(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.to}p=g.to}else{if(p==e||(c?q[p]!=l:q[p]==l))break;p++}u?Ls(n,a,p,i+1,s,u,o):a<p&&o.push(new ce(a,p,d)),a=p}else for(let a=e,h=r.length;a>t;){let c=!0,f=!1;if(!h||a>r[h-1].to){let g=q[a-1];g!=l&&(c=!1,f=g==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;t:for(;;)if(h&&p==r[h-1].to){if(f)break t;let g=r[--h];if(!c)for(let m=g.from,y=h;;){if(m==t)break t;if(y&&r[y-1].to==m)m=r[--y].from;else{if(q[m-1]==l)break t;break}}if(u)u.push(g);else{g.to<a&&o.push(new ce(g.to,a,d));let m=g.direction==Pe!=!(d%2);Es(n,m?i+1:i,s,g.inner,g.from,g.to,o),a=g.from}p=g.from}else{if(p==t||(c?q[p-1]!=l:q[p-1]==l))break;p--}u?Ls(n,p,a,i+1,s,u,o):p<a&&o.push(new ce(p,a,d)),a=p}}function Es(n,t,e,i,s,r,o){let l=t%2?2:1;_c(n,s,r,i,l),Qc(n,s,r,i,l),Zc(s,r,i,l),Ls(n,s,r,t,e,i,o)}function tf(n,t,e){if(!n)return[new ce(0,0,t==ur?1:0)];if(t==Pe&&!e.length&&!Xc.test(n))return sa(n.length);if(e.length)for(;n.length>q.length;)q[q.length]=256;let i=[],s=t==Pe?0:1;return Es(n,s,s,e,0,n.length,i),i}function sa(n){return[new ce(0,n,0)]}let ra="";function ef(n,t,e,i,s){var r;let o=i.head-n.from,l=ce.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=t[l],h=a.side(s,e);if(o==h){let u=l+=s?1:-1;if(u<0||u>=t.length)return null;a=t[l=u],o=a.side(!s,e),h=a.side(s,e)}let c=ot(n.text,o,a.forward(s,e));(c<a.from||c>a.to)&&(c=h),ra=n.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(s?t.length-1:0)?null:t[l+(s?1:-1)];return f&&c==h&&f.level+(s?0:1)<a.level?b.cursor(f.side(!s,e)+n.from,f.forward(s,e)?1:-1,f.level):b.cursor(c+n.from,a.forward(s,e)?-1:1,a.level)}function nf(n,t,e){for(let i=t;i<e;i++){let s=ia(n.charCodeAt(i));if(s==1)return Pe;if(s==2||s==4)return ur}return Pe}const oa=T.define(),la=T.define(),aa=T.define(),ha=T.define(),Is=T.define(),ca=T.define(),fa=T.define(),ua=T.define({combine:n=>n.some(t=>t)}),da=T.define({combine:n=>n.some(t=>t)}),pa=T.define();class Ke{constructor(t,e="nearest",i="nearest",s=5,r=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new Ke(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Ke(b.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const qi=F.define({map:(n,t)=>n.map(t)}),ga=F.define();function Dt(n,t,e){let i=n.facet(ha);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const le=T.define({combine:n=>n.length?n[0]:!0});let sf=0;const ci=T.define();class ut{constructor(t,e,i,s,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=e||{};return new ut(sf++,t,i,s,l=>{let a=[ci.of(l)];return o&&a.push(ki.of(h=>{let c=h.plugin(l);return c?o(c):P.none})),r&&a.push(r(l)),a})}static fromClass(t,e){return ut.define(i=>new t(i),e)}}class Jn{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(Dt(e.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(t)}catch(e){Dt(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){Dt(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const ma=T.define(),dr=T.define(),ki=T.define(),ya=T.define(),pr=T.define(),ba=T.define();function no(n,t){let e=n.state.facet(ba);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(n):r),s=[];return K.spans(i,t.from,t.to,{point(){},span(r,o,l,a){let h=r-t.from,c=o-t.from,f=s;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=nf(t.text,h,c)),a>0&&f.length&&(p=f[f.length-1]).to==h&&p.direction==d)p.to=c,f=p.inner;else{let g={from:h,to:c,direction:d,inner:[]};f.push(g),f=g.inner}}}}),s}const xa=T.define();function wa(n){let t=0,e=0,i=0,s=0;for(let r of n.state.facet(xa)){let o=r(n);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:t,right:e,top:i,bottom:s}}const fi=T.define();class It{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new It(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let s=0,r=0,o=0,l=0;;s++){let a=s==t.length?null:t[s],h=o-l,c=a?a.fromB:1e9;for(;r<e.length&&e[r]<c;){let f=e[r],u=e[r+1],d=Math.max(l,f),p=Math.min(c,u);if(d<=p&&new It(d+h,p+h,d,p).addToSet(i),u>c)break;r+=2}if(!a)return i;new It(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class yn{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=et.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 It(r,o,l,a))),this.changedRanges=s}static create(t,e,i){return new yn(t,e,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(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class so extends ${get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=P.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new tt],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new It(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:h,toA:c})=>c<this.minWidthFrom||h>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?s=this.domChanged.newSel.head:!ff(t.changes,this.hasComposition)&&!t.selectionSet&&(s=t.state.selection.main.head));let r=s>-1?of(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:h,to:c}=this.hasComposition;i=new It(h,c,t.changes.mapPos(h,-1),t.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(D.ie||D.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=hf(o,l,t.changes);return i=It.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:s}=this.view;s.ignore(()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let o=D.chrome||D.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 te&&o.widget instanceof ro&&r.push(o.dom);s.updateGaps(r)}updateChildren(t,e,i){let s=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);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 S=bi.build(this.view.state.doc,c,i.range.fromB,this.decorations,this.dynamicDecorationMap),w=bi.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=S.breakAtStart,p=S.openStart,g=w.openEnd;let A=this.compositionView(i);w.breakAtStart?A.breakAfter=1:w.content.length&&A.merge(A.length,A.length,w.content[0],!1,w.openStart,0)&&(A.breakAfter=w.content[0].breakAfter,w.content.shift()),S.content.length&&A.merge(0,0,S.content[S.content.length-1],!0,0,S.openEnd)&&S.content.pop(),u=S.content.concat(A).concat(w.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=bi.build(this.view.state.doc,c,f,this.decorations,this.dynamicDecorationMap));let{i:m,off:y}=r.findPos(h,1),{i:x,off:v}=r.findPos(a,-1);Gl(this,x,v,m,y,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(ga)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new Vt(t.text.nodeValue);e.flags|=8;for(let{deco:s}of t.marks)e=new ne(s,[e],e.length);let i=new tt;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=$.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(t.range.fromB,1),s=this.children[i.i];e(t.line,s);for(let r=t.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],e(r>=0?t.marks[r].node:t.text,s)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&an(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,a=this.moveToLine(this.domAtPos(l.anchor)),h=l.empty?a:this.moveToLine(this.domAtPos(l.head));if(D.gecko&&l.empty&&!this.hasComposition&&rf(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=h=new ct(f,0),o=!0}let c=this.view.observer.selectionRange;(o||!c.focusNode||(!yi(a.node,a.offset,c.anchorNode,c.anchorOffset)||!yi(h.node,h.offset,c.focusNode,c.focusOffset))&&!this.suppressWidgetCursorChange(c,l))&&(this.view.observer.ignore(()=>{D.android&&D.chrome&&this.dom.contains(c.focusNode)&&cf(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=vi(this.view.root);if(f)if(l.empty){if(D.gecko){let u=lf(a.node,a.offset);if(u&&u!=3){let d=(u==1?$l:jl)(a.node,a.offset);d&&(a=new ct(d.node,d.offset))}}f.collapse(a.node,a.offset),l.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=l.bidiLevel)}else if(f.extend){f.collapse(a.node,a.offset);try{f.extend(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 ct(c.anchorNode,c.anchorOffset),this.impreciseHead=h.precise?null:new ct(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&yi(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=vi(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=tt.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let a=this.coordsAt(e.head,-1),h=this.coordsAt(e.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(e.head+e.assoc);i.collapse(c.node,c.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(s,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let s=t.offset;!i&&s<e.childNodes.length;s++){let r=$.get(e.childNodes[s]);r instanceof tt&&(i=r.domAtPos(0))}for(let s=t.offset-1;!i&&s>=0;s--){let r=$.get(e.childNodes[s]);r instanceof tt&&(i=r.domAtPos(r.length))}return i?new ct(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=$.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let s=this.children[e];if(i<s.length||s instanceof tt)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,s=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],a=r-l.breakAfter,h=a-l.length;if(a<t)break;if(h<=t&&(h<t||l.covers(-1))&&(a>t||l.covers(1))&&(!i||l instanceof tt&&!(i instanceof tt&&e>=0)))i=l,s=h;else if(i&&h==t&&a==t&&l instanceof te&&Math.abs(e)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=h}return i?i.coordsAt(t-s,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),s=this.children[e];if(!(s instanceof tt))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 Vt))return null;let r=ot(s.text,i);if(r==i)return null;let o=Te(s.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==X.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(e.push(d.height),o){let p=f.dom.lastChild,g=p?Ge(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 e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?X.RTL:X.LTR}measureTextSize(){for(let r of this.children)if(r instanceof tt){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let r=Ge(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,s=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:s}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Ul(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],o=r?r.from-1:this.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(P.replace({widget:new ro(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return P.set(t)}updateDeco(){let t=1,e=this.view.state.facet(ki).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(ya).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(K.join(s))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let h=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=h.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let h of this.view.state.facet(pa))try{if(h(this.view,t.range,t))return!0}catch(c){Dt(this.view.state,c,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),s;if(!i)return;!e.empty&&(s=this.coordsAt(e.anchor,e.anchor>e.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=wa(this.view),o={left:i.left-r.left,top:i.top-r.top,right:i.right+r.right,bottom:i.bottom+r.bottom},{offsetWidth:l,offsetHeight:a}=this.view.scrollDOM;Vc(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,a),-a),this.view.textDirection==X.LTR)}}function rf(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 ro extends Ee{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function Sa(n,t){let e=n.observer.selectionRange;if(!e.focusNode)return null;let i=$l(e.focusNode,e.focusOffset),s=jl(e.focusNode,e.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=$.get(s.node);if(!l||l instanceof Vt&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=$.get(i.node);!a||a instanceof Vt&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function of(n,t,e){let i=Sa(n,e);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=t.invertedDesc,h=new It(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let f=s.parentNode;;f=f.parentNode){let u=$.get(f);if(u instanceof ne)c.push({node:f,deco:u.mark});else{if(u instanceof tt||f.nodeName=="DIV"&&f.parentNode==n.contentDOM)return{range:h,text:s,marks:c,line:f};if(f!=n.contentDOM)c.push({node:f,deco:new Ri({inclusive:!0,attributes:Uc(f),tagName:f.tagName.toLowerCase()})});else return null}}}function lf(n,t){return n.nodeType!=1?0:(t&&n.childNodes[t-1].contentEditable=="false"?1:0)|(t<n.childNodes.length&&n.childNodes[t].contentEditable=="false"?2:0)}let af=class{constructor(){this.changes=[]}compareRange(t,e){Bs(t,e,this.changes)}comparePoint(t,e){Bs(t,e,this.changes)}};function hf(n,t,e){let i=new af;return K.compare(n,t,e,i),i.changes}function cf(n,t){for(let e=n;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function ff(n,t){let e=!1;return t&&n.iterChangedRanges((i,s)=>{i<t.to&&s>t.from&&(e=!0)}),e}function uf(n,t,e=1){let i=n.charCategorizer(t),s=n.doc.lineAt(t),r=t-s.from;if(s.length==0)return b.cursor(t);r==0?e=1:r==s.length&&(e=-1);let o=r,l=r;e<0?o=ot(s.text,r,!1):l=ot(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;){let h=ot(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=ot(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return b.range(o+s.from,l+s.from)}function df(n,t){return t.left>n?t.left-n:Math.max(0,n-t.right)}function pf(n,t){return t.top>n?t.top-n:Math.max(0,n-t.bottom)}function Yn(n,t){return n.top<t.bottom-1&&n.bottom>t.top+1}function oo(n,t){return t<n.top?{top:t,left:n.left,right:n.right,bottom:n.bottom}:n}function lo(n,t){return t>n.bottom?{top:n.top,left:n.left,right:n.right,bottom:t}:n}function Ns(n,t,e){let i,s,r,o,l=!1,a,h,c,f;for(let p=n.firstChild;p;p=p.nextSibling){let g=Ge(p);for(let m=0;m<g.length;m++){let y=g[m];s&&Yn(s,y)&&(y=oo(lo(y,s.bottom),s.top));let x=df(t,y),v=pf(e,y);if(x==0&&v==0)return p.nodeType==3?ao(p,t,e):Ns(p,t,e);if(!i||o>v||o==v&&r>x){i=p,s=y,r=x,o=v;let S=v?e<y.top?-1:1:x?t<y.left?-1:1:0;l=!S||(S>0?m<g.length-1:m>0)}x==0?e>y.bottom&&(!c||c.bottom<y.bottom)?(a=p,c=y):e<y.top&&(!f||f.top>y.top)&&(h=p,f=y):c&&Yn(c,y)?c=lo(c,y.bottom):f&&Yn(f,y)&&(f=oo(f,y.top))}}if(c&&c.bottom>=e?(i=a,s=c):f&&f.top<=e&&(i=h,s=f),!i)return{node:n,offset:0};let u=Math.max(s.left,Math.min(s.right,t));if(i.nodeType==3)return ao(i,u,e);if(l&&i.contentEditable!="false")return Ns(i,u,e);let d=Array.prototype.indexOf.call(n.childNodes,i)+(t>=(s.left+s.right)/2?1:0);return{node:n,offset:d}}function ao(n,t,e){let i=n.nodeValue.length,s=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=Te(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=t-c.left);let f=(c.top>e?c.top-e:e-c.bottom)-1;if(c.left-1<=t&&c.right+1>=t&&f<r){let u=t>=(c.left+c.right)/2,d=u;if((D.chrome||D.gecko)&&Te(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 va(n,t,e,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}=t,u=f-l;if(u<0)return 0;if(u>h)return n.state.doc.length;for(let S=n.viewState.heightOracle.textHeight/2,w=!1;a=n.elementAtHeight(u),a.type!=Ot.Text;)for(;u=i>0?a.bottom+S:a.top-S,!(u>=0&&u<=h);){if(w)return e?null:0;w=!0,i=-i}f=l+u;let d=a.from;if(d<n.viewport.from)return n.viewport.from==0?0:e?null:ho(n,o,a,c,f);if(d>n.viewport.to)return n.viewport.to==n.state.doc.length?n.state.doc.length:e?null:ho(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,x=-1;if(m&&((s=n.docView.nearest(m))===null||s===void 0?void 0:s.isEditable)!=!1){if(p.caretPositionFromPoint){let S=p.caretPositionFromPoint(c,f);S&&({offsetNode:y,offset:x}=S)}else if(p.caretRangeFromPoint){let S=p.caretRangeFromPoint(c,f);S&&({startContainer:y,startOffset:x}=S,(!n.contentDOM.contains(y)||D.safari&&gf(y,x,c)||D.chrome&&mf(y,x,c))&&(y=void 0))}}if(!y||!n.docView.dom.contains(y)){let S=tt.find(n.docView,d);if(!S)return u>a.top+a.height/2?a.to:a.from;({node:y,offset:x}=Ns(S.dom,c,f))}let v=n.docView.nearest(y);if(!v)return null;if(v.isWidget&&((r=v.dom)===null||r===void 0?void 0:r.nodeType)==1){let S=v.dom.getBoundingClientRect();return t.y<S.top||t.y<=S.bottom&&t.x<=(S.left+S.right)/2?v.posAtStart:v.posAtEnd}else return v.localPosFromDOM(y,x)+v.posAtStart}function ho(n,t,e,i,s){let r=Math.round((i-t.left)*n.defaultCharacterWidth);if(n.lineWrapping&&e.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-e.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(e.from,e.to);return e.from+vs(o,r,n.state.tabSize)}function gf(n,t,e){let i;if(n.nodeType!=3||t!=(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 Te(n,i-1,i).getBoundingClientRect().left>e}function mf(n,t,e){if(t!=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():Te(n,0,Math.max(n.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function Fs(n,t){let e=n.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==Ot.Text))return i}return e}function yf(n,t,e,i){let s=Fs(n,t.head),r=!i||s.type!=Ot.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(t.assoc<0&&t.head>s.from?t.head-1:t.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:e==(l==X.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return b.cursor(a,e?-1:1)}return b.cursor(e?s.to:s.from,e?-1:1)}function co(n,t,e,i){let s=n.state.doc.lineAt(t.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=t,a=null;;){let h=ef(s,r,o,l,e),c=ra;if(!h){if(s.number==(e?n.state.doc.lines:1))return l;c=`
`,s=n.state.doc.line(s.number+(e?1:-1)),r=n.bidiSpans(s),h=n.visualLineSide(s,!e)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function bf(n,t,e){let i=n.state.charCategorizer(t),s=i(e);return r=>{let o=i(r);return s==G.Space&&(s=o),s==o}}function xf(n,t,e,i){let s=t.head,r=e?1:-1;if(s==(e?n.state.doc.length:0))return b.cursor(s,t.assoc);let o=t.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,t.assoc||-1),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=va(n,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?g<s:g>s)){let m=n.docView.coordsForChar(g),y=!m||p<m.top?-1:1;return b.cursor(g,y,void 0,o)}}}function hn(n,t,e){for(;;){let i=0;for(let s of n)s.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let a=i||e||(t-r<o-t?-1:1);t=a<0?r:o,i=a}});if(!i)return t}}function Xn(n,t,e){let i=hn(n.state.facet(pr).map(s=>s(n)),e.from,t.head>e.from?-1:1);return i==e.from?e:b.cursor(i,i<e.from?1:-1)}class wf{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,D.safari&&t.contentDOM.addEventListener("input",()=>null),D.gecko&&Nf(t.contentDOM.ownerDocument)}handleEvent(t){!Of(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let s of i.observers)s(this.view,e);for(let s of i.handlers){if(e.defaultPrevented)break;if(s(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Sf(t),i=this.handlers,s=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&Ca.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),D.android&&D.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return D.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=ka.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||vf.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,qe(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:D.safari&&!D.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function fo(n,t){return(e,i)=>{try{return t.call(n,i,e)}catch(s){Dt(e.state,s)}}}function Sf(n){let t=Object.create(null);function e(i){return t[i]||(t[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec;if(s&&s.domEventHandlers)for(let r in s.domEventHandlers){let o=s.domEventHandlers[r];o&&e(r).handlers.push(fo(i.value,o))}if(s&&s.domEventObservers)for(let r in s.domEventObservers){let o=s.domEventObservers[r];o&&e(r).observers.push(fo(i.value,o))}}for(let i in Wt)e(i).handlers.push(Wt[i]);for(let i in Nt)e(i).observers.push(Nt[i]);return t}const ka=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],vf="dthko",Ca=[16,17,18,20,91,92,224,225],Ki=6;function $i(n){return Math.max(0,n)*.7+8}function kf(n,t){return Math.max(Math.abs(n.clientX-t.clientX),Math.abs(n.clientY-t.clientY))}class Cf{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParent=Wc(t.contentDOM),this.atoms=t.state.facet(pr).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(H.allowMultipleSelections)&&Af(t,e),this.dragging=Df(t,e)&&Oa(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){var e;if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&kf(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let i=0,s=0,r=((e=this.scrollParent)===null||e===void 0?void 0:e.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=wa(this.view);t.clientX-o.left<=r.left+Ki?i=-$i(r.left-t.clientX):t.clientX+o.right>=r.right-Ki&&(i=$i(t.clientX-r.right)),t.clientY-o.top<=r.top+Ki?s=-$i(r.top-t.clientY):t.clientY+o.bottom>=r.bottom-Ki&&(s=$i(t.clientY-r.bottom)),this.setScrollSpeed(i,s)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?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(t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let o=hn(this.atoms,s.from,0);o!=s.from&&(r=b.cursor(o,-1))}else{let o=hn(this.atoms,s.from,-1),l=hn(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&&(e||(e=t.ranges.slice()),e[i]=r)}return e?b.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Af(n,t){let e=n.state.facet(oa);return e.length?e[0](t):D.mac?t.metaKey:t.ctrlKey}function Mf(n,t){let e=n.state.facet(la);return e.length?e[0](t):D.mac?!t.altKey:!t.ctrlKey}function Df(n,t){let{main:e}=n.state.selection;if(e.empty)return!1;let i=vi(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<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function Of(n,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=n.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=$.get(e))&&i.ignoreEvent(t))return!1;return!0}const Wt=Object.create(null),Nt=Object.create(null),Aa=D.ie&&D.ie_version<15||D.ios&&D.webkit_version<604;function Tf(n){let t=n.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{n.focus(),e.remove(),Ma(n,e.value)},50)}function Ma(n,t){let{state:e}=n,i,s=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(Vs!=null&&e.selection.ranges.every(a=>a.empty)&&Vs==r.toString()){let a=-1;i=e.changeByRange(h=>{let c=e.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=e.toText((o?r.line(s++).text:t)+e.lineBreak);return{changes:{from:c.from,insert:f},range:b.cursor(h.from+f.length)}})}else o?i=e.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=e.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Nt.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Wt.keydown=(n,t)=>(n.inputState.setSelectionOrigin("select"),t.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);Nt.touchstart=(n,t)=>{n.inputState.lastTouchTime=Date.now(),n.inputState.setSelectionOrigin("select.pointer")};Nt.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Wt.mousedown=(n,t)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of n.state.facet(aa))if(e=i(n,t),e)break;if(!e&&t.button==0&&(e=Rf(n,t)),e){let i=!n.hasFocus;n.inputState.startMouseSelection(new Cf(n,t,e,i)),i&&n.observer.ignore(()=>{zl(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(t),s.dragging===!1}return!1};function uo(n,t,e,i){if(i==1)return b.cursor(t,e);if(i==2)return uf(n.state,t,e);{let s=tt.find(n.docView,t),r=n.state.doc.lineAt(s?s.posAtEnd:t),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 Da=(n,t)=>n>=t.top&&n<=t.bottom,po=(n,t,e)=>Da(t,e)&&n>=e.left&&n<=e.right;function Pf(n,t,e,i){let s=tt.find(n.docView,t);if(!s)return 1;let r=t-s.posAtStart;if(r==0)return 1;if(r==s.length)return-1;let o=s.coordsAt(r,-1);if(o&&po(e,i,o))return-1;let l=s.coordsAt(r,1);return l&&po(e,i,l)?1:o&&Da(i,o)?-1:1}function go(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:Pf(n,e,t.clientX,t.clientY)}}const Bf=D.ie&&D.ie_version<=11;let mo=null,yo=0,bo=0;function Oa(n){if(!Bf)return n.detail;let t=mo,e=bo;return mo=n,bo=Date.now(),yo=!t||e>Date.now()-400&&Math.abs(t.clientX-n.clientX)<2&&Math.abs(t.clientY-n.clientY)<2?(yo+1)%3:1}function Rf(n,t){let e=go(n,t),i=Oa(t),s=n.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),s=s.map(r.changes))},get(r,o,l){let a=go(n,r),h,c=uo(n,a.pos,a.bias,i);if(e.pos!=a.pos&&!o){let f=uo(n,e.pos,e.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=Lf(s,a.pos))?h:l?s.addRange(c):b.create([c])}}}function Lf(n,t){for(let e=0;e<n.ranges.length;e++){let{from:i,to:s}=n.ranges[e];if(i<=t&&s>=t)return b.create(n.ranges.slice(0,e).concat(n.ranges.slice(e+1)),n.mainIndex==e?0:n.mainIndex-(n.mainIndex>e?1:0))}return null}Wt.dragstart=(n,t)=>{let{selection:{main:e}}=n.state;if(t.target.draggable){let s=n.docView.nearest(t.target);if(s&&s.isWidget){let r=s.posAtStart,o=r+s.length;(r>=e.to||o<=e.from)&&(e=b.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",n.state.sliceDoc(e.from,e.to)),t.dataTransfer.effectAllowed="copyMove"),!1};Wt.dragend=n=>(n.inputState.draggedContent=null,!1);function xo(n,t,e,i){if(!e)return;let s=n.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&Mf(n,t)?{from:r.from,to:r.to}:null,l={from:s,insert:e},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Wt.drop=(n,t)=>{if(!t.dataTransfer)return!1;if(n.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),s=0,r=()=>{++s==e.length&&xo(n,t,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<e.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(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return xo(n,t,i,!0),!0}return!1};Wt.paste=(n,t)=>{if(n.state.readOnly)return!0;n.observer.flush();let e=Aa?null:t.clipboardData;return e?(Ma(n,e.getData("text/plain")||e.getData("text/uri-list")),!0):(Tf(n),!1)};function Ef(n,t){let e=n.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function If(n){let t=[],e=[],i=!1;for(let s of n.selection.ranges)s.empty||(t.push(n.sliceDoc(s.from,s.to)),e.push(s));if(!t.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(t.push(o.text),e.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:t.join(n.lineBreak),ranges:e,linewise:i}}let Vs=null;Wt.copy=Wt.cut=(n,t)=>{let{text:e,ranges:i,linewise:s}=If(n.state);if(!e&&!s)return!1;Vs=s?e:null,t.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=Aa?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(Ef(n,e),!1)};const Ta=se.define();function Pa(n,t){let e=[];for(let i of n.facet(fa)){let s=i(n,t);s&&e.push(s)}return e?n.update({effects:e,annotations:Ta.of(!0)}):null}function Ba(n){setTimeout(()=>{let t=n.hasFocus;if(t!=n.inputState.notifiedFocused){let e=Pa(n.state,t);e?n.dispatch(e):n.update([])}},10)}Nt.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),Ba(n)};Nt.blur=n=>{n.observer.clearSelectionRange(),Ba(n)};Nt.compositionstart=Nt.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};Nt.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,D.chrome&&D.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};Nt.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Wt.beforeinput=(n,t)=>{var e;let i;if(D.chrome&&D.android&&(i=ka.find(s=>s.inputType==t.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((e=window.visualViewport)===null||e===void 0?void 0:e.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return D.ios&&t.inputType=="deleteContentForward"&&n.observer.flushSoon(),D.safari&&t.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>Nt.compositionend(n,t),20),!1};const wo=new Set;function Nf(n){wo.has(n)||(wo.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const So=["pre-wrap","normal","pre-line","break-spaces"];class Ff{constructor(t){this.lineWrapping=t,this.doc=V.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return So.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(e=!0,this.heightSamples[Math.floor(s*10)]=!0)}return e}refresh(t,e,i,s,r,o){let l=So.indexOf(t)>-1,a=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,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 Vf{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class Jt{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?Ot.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 ge?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new Jt(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var U=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(U||(U={}));const cn=.001;class gt{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>cn&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return gt.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,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,U.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=h?u:r.lineAt(h,U.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,U.ByPosNoHeight,i,0,0));c+=u.from-a,a=u.from;let p=gr.build(i.setDoc(o),t,c,f);r=r.replace(a,h,p)}return r.updateHeight(i,0)}static empty(){return new Mt(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=t[e++];l&&(s+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new Wf(gt.of(t.slice(0,e)),o,gt.of(t.slice(i)))}}gt.prototype.size=1;class Ra extends gt{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,s){return new Jt(s,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Mt extends Ra{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,s){return new Jt(s,this.length,i,this.height,this.breaks)}replace(t,e,i){let s=i[0];return i.length==1&&(s instanceof Mt||s instanceof it&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof it?s=new Mt(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):gt.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class it extends gt{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,s=t.doc.lineAt(e+this.length).number,r=s-i+1,o,l=0;if(t.lineWrapping){let a=Math.min(this.height,t.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(t,e,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(e,s);if(e.lineWrapping){let h=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),c=e.doc.lineAt(h),f=l+c.length*a,u=Math.max(i,t-f/2);return new Jt(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:c,length:f}=e.doc.line(r+h);return new Jt(c,f,i+l*h,l,0)}}lineAt(t,e,i,s,r){if(e==U.ByHeight)return this.blockAt(t,i,s,r);if(e==U.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new Jt(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(t),c=l+h.length*a,f=h.number-o,u=s+l*f+a*(h.from-r-f);return new Jt(h.from,h.length,Math.max(s,Math.min(u,s+this.height-c)),c,0)}forEachLine(t,e,i,s,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=t,f=s;c<=e;){let u=i.doc.lineAt(c);if(c==t){let p=u.number-l;f+=a*p+h*(t-r-p)}let d=a+h*u.length;o(new Jt(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let r=i[i.length-1];r instanceof it?i[i.length-1]=new it(r.length+s):i.push(null,new it(s-1))}if(t>0){let r=i[0];r instanceof it?i[0]=new it(t+r.length):i.unshift(new it(t-1),null)}return gt.of(i)}decomposeLeft(t,e){e.push(new it(t-1),null)}decomposeRight(t,e){e.push(null,new it(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let o=[],l=Math.max(e,s.from),a=-1;for(s.from>e&&o.push(new it(s.from-e-1).updateHeight(t,e));l<=r&&s.more;){let c=t.doc.lineAt(l).length;o.length&&o.push(null);let f=s.heights[s.index++];a==-1?a=f:Math.abs(f-a)>=cn&&(a=-2);let u=new Mt(c,f);u.outdated=!1,o.push(u),l+=c+1}l<=r&&o.push(null,new it(r-l).updateHeight(t,l));let h=gt.of(o);return(a<0||Math.abs(h.height-this.height)>=cn||Math.abs(a-this.heightMetrics(t,e).perLine)>=cn)&&(t.heightChanged=!0),h}else(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Wf extends gt{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=e==U.ByHeight?t<o:t<l,h=a?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=e==U.ByPosNoHeight?U.ByPosNoHeight:U.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(t,e,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)t<a&&this.left.forEachLine(t,e,i,s,r,o),e>=a&&this.right.forEachLine(t,e,i,l,a,o);else{let h=this.lineAt(a,U.ByPos,i,s,r);t<h.from&&this.left.forEachLine(t,h.from-1,i,s,r,o),h.to>=t&&h.from<=e&&o(h),e>h.to&&this.right.forEachLine(h.to+1,e,i,l,a,o)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&vo(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),vo(r,l)}return gt.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?gt.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:o}=this,l=e+r.length+this.break,a=null;return s&&s.from<=e+r.length&&s.more?a=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(t,l,i,s):o.updateHeight(t,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 vo(n,t){let e,i;n[t]==null&&(e=n[t-1])instanceof it&&(i=n[t+1])instanceof it&&n.splice(t-1,3,new it(e.length+1+i.length))}const Hf=5;class gr{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Mt?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Mt(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||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=e-t;i.block?this.addBlock(new Ra(o,s,i)):(o||r||s>=Hf)&&this.addLineDeco(s,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new Mt(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new it(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof Mt)return t;let e=new Mt(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof Mt)&&!this.isCovered?this.nodes.push(new Mt(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let s of this.nodes)s instanceof Mt&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(t,e,i,s){let r=new gr(i,t);return K.spans(e,i,s,r,0),r.finish(i)}}function zf(n,t,e){let i=new qf;return K.compare(n,t,e,i,0),i.changes}class qf{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&Bs(t,e,this.changes,5)}}function Kf(n,t){let e=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(s.innerWidth,e.right),l=Math.max(0,e.top),a=Math.min(s.innerHeight,e.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-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,a)-(e.top+t)}}function $f(n,t){let e=n.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class _n{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t,e){return P.replace({widget:new jf(this.size*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class jf extends Ee{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class ko{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Co,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=X.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(dr).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Ff(e),this.stateDeco=t.facet(ki).filter(i=>typeof i!="function"),this.heightMap=gt.empty().applyChanges(this.stateDeco,V.empty,this.heightOracle.setDoc(t.doc),[new It(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=P.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);t.push(new ji(r,o))}}return this.viewports=t.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?Co:new mr(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(ui(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(ki).filter(c=>typeof c!="function");let s=t.changedRanges,r=It.extendWithRanges(s,zf(i,this.stateDeco,t?t.changes:et.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(t.flags|=2),l?(this.scrollAnchorPos=t.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,t.changes):this.viewport;(e&&(e.range.head<a.from||e.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,e));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,t.flags|=this.updateForViewport(),(h||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(da)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?X.RTL:X.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:S,scaleY:w}=Hl(e,l);(S>.005&&Math.abs(this.scaleX-S)>.005||w>.005&&Math.abs(this.scaleY-w)>.005)&&(this.scaleX=S,this.scaleY=w,h|=8,o=a=!0)}let f=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=f||this.paddingBottom!=u)&&(this.paddingTop=f,this.paddingBottom=u,h|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=t.scrollDOM.clientWidth,h|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Kl(t.scrollDOM);let p=(this.printing?$f:Kf)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(a=!0)),!this.inView&&!this.scrollTarget)return 0;let x=l.width;if((this.contentDOMWidth!=x||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,h|=8),a){let S=t.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(S)&&(o=!0),o||s.lineWrapping&&Math.abs(x-this.contentDOMWidth)>s.charWidth){let{lineHeight:w,charWidth:A,textHeight:C}=t.docView.measureTextSize();o=w>0&&s.refresh(r,w,A,C,x/A,S),o&&(t.docView.minWidth=0,h|=8)}g>0&&m>0?c=Math.max(g,m):g<0&&m<0&&(c=Math.min(g,m)),s.heightChanged=!1;for(let w of this.viewports){let A=w.from==this.viewport.from?S:t.docView.measureVisibleLineHeights(w);this.heightMap=(o?gt.empty().applyChanges(this.stateDeco,V.empty,this.heightOracle,[new It(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Vf(w.from,A))}s.heightChanged&&(h|=2)}let v=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return v&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new ji(s.lineAt(o-i*1e3,U.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,U.ByHeight,r,0,0).to);if(e){let{head:h}=e.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=s.lineAt(h,U.ByPos,r,0,0),u;e.y=="center"?u=(f.top+f.bottom)/2-c/2:e.y=="start"||e.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new ji(s.lineAt(u-1e3/2,U.ByHeight,r,0,0).from,s.lineAt(u+c+1e3/2,U.ByHeight,r,0,0).to)}}return a}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new ji(this.heightMap.lineAt(i,U.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,U.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,U.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,U.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||s<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new _n(e.mapPos(s.from),e.mapPos(s.to),s.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=X.LTR&&!i)return[];let l=[],a=(c,f,u,d)=>{if(f-c<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let y of g)if(y>c&&y<f){a(c,y-10,u,d),a(y+10,f,u,d);return}let m=Gf(t,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-c)<r&&Math.abs(y.to-f)<r&&!g.some(x=>y.from<x&&y.to>x));if(!m){if(f<u.to&&e&&i&&e.visibleRanges.some(y=>y.from<=f&&y.to>=f)){let y=e.moveToLineBoundary(b.cursor(f),!1,!0).head;y>c&&(f=y)}m=new _n(c,f,this.gapSize(u,c,f,d))}l.push(m)},h=c=>{if(c.length<o||c.type!=Ot.Text)return;let f=Uf(c.from,c.to,this.stateDeco);if(f.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,y;if(u!=null){let x=Gi(f,u),v=((this.visibleBottom-this.visibleTop)/2+g)/c.height;m=x-v,y=x+v}else m=(this.visibleTop-c.top-g)/c.height,y=(this.visibleBottom-c.top+g)/c.height;d=Ui(f,m),p=Ui(f,y)}else{let g=f.total*this.heightOracle.charWidth,m=s*this.heightOracle.charWidth,y,x;if(u!=null){let v=Gi(f,u),S=((this.pixelViewport.right-this.pixelViewport.left)/2+m)/g;y=v-S,x=v+S}else y=(this.pixelViewport.left-m)/g,x=(this.pixelViewport.right+m)/g;d=Ui(f,y),p=Ui(f,x)}d>c.from&&a(c.from,d,c,f),p<c.to&&a(p,c.to,c,f)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(t,e,i,s){let r=Gi(s,i)-Gi(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){_n.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=P.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];K.spans(t,this.viewport.from,this.viewport.to,{span(s,r){e.push({from:s,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((s,r)=>s.from!=e[r].from||s.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||ui(this.heightMap.lineAt(t,U.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||ui(this.heightMap.lineAt(this.scaler.fromDOM(t),U.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return ui(this.heightMap.blockAt(this.scaler.fromDOM(t),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 ji{constructor(t,e){this.from=t,this.to=e}}function Uf(n,t,e){let i=[],s=n,r=0;return K.spans(e,n,t,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<t&&(i.push({from:s,to:t}),r+=t-s),{total:r,ranges:i}}function Ui({total:n,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(n*e);for(let s=0;;s++){let{from:r,to:o}=t[s],l=o-r;if(i<=l)return r+i;i-=l}}function Gi(n,t){let e=0;for(let{from:i,to:s}of n.ranges){if(t<=s){e+=t-i;break}e+=s-i}return e/n.total}function Gf(n,t){for(let e of n)if(t(e))return e}const Co={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};class mr{constructor(t,e,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=e.lineAt(l,U.ByPos,t,0,0).top,c=e.lineAt(a,U.ByPos,t,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(e.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(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}eq(t){return t instanceof mr?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function ui(n,t){if(t.scale==1)return n;let e=t.toDOM(n.top),i=t.toDOM(n.bottom);return new Jt(n.from,n.length,e,i-e,Array.isArray(n._content)?n._content.map(s=>ui(s,t)):n._content)}const Ji=T.define({combine:n=>n.join(" ")}),Ws=T.define({combine:n=>n.indexOf(!0)>-1}),Hs=de.newName(),La=de.newName(),Ea=de.newName(),Ia={"&light":"."+La,"&dark":"."+Ea};function zs(n,t,e){return new de(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!e||!e[s])throw new RangeError(`Unsupported selector: ${s}`);return e[s]}):n+" "+i}})}const Jf=zs("."+Hs,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Ia),di="￿";class Yf{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(H.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=di}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=s.nextSibling;if(o==e)break;let l=$.get(s),a=$.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:mn(s))||mn(o)&&(s.nodeName!="BR"||s.cmIgnore)&&this.text.length>r)&&this.lineBreak(),s=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==t&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=$.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Xf(t,i.node,i.offset)?e:0))}}function Xf(n,t,e){for(;;){if(!t||e<ie(t))return!1;if(t==n)return!0;e=Oe(t)+1,t=t.parentNode}}class Ao{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class _f{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:tu(t),a=new Yf(l,t.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=eu(l,this.bounds.from)}else{let l=t.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!As(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!As(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=t.viewport;if((D.ios||D.chrome)&&t.state.selection.main.empty&&a!=h&&(c.from>0||c.to<t.state.doc.length)){let f=Math.min(a,h),u=Math.max(a,h),d=c.from-f,p=c.to-u;(d==0||d==1||f==0)&&(p==0||p==-1||u==t.state.doc.length)&&(a=0,h=t.state.doc.length)}this.newSel=b.single(h,a)}}}function Na(n,t){let e,{newSel:i}=t,s=n.state.selection.main,r=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,a=s.from,h=null;(r===8||D.android&&t.text.length<l-o)&&(a=s.to,h="end");let c=Zf(n.state.doc.sliceString(o,l,di),t.text,a-o,h);c&&(D.chrome&&r==13&&c.toB==c.from+2&&t.text.slice(c.from,c.toB)==di+di&&c.toB--,e={from:o+c.from,to:o+c.toA,insert:V.of(t.text.slice(c.from,c.toB).split(di))})}else i&&(!n.hasFocus&&n.state.facet(le)||i.main.eq(s))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!s.empty&&i&&i.main.empty?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,s.to)}:e&&e.from>=s.from&&e.to<=s.to&&(e.from!=s.from||e.to!=s.to)&&s.to-s.from-(e.to-e.from)<=4?e={from:s.from,to:s.to,insert:n.state.doc.slice(s.from,e.from).append(e.insert).append(n.state.doc.slice(e.to,s.to))}:(D.mac||D.android)&&e&&e.from==e.to&&e.from==s.head-1&&/^\. ?$/.test(e.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:V.of([" "])}):D.chrome&&e&&e.from==e.to&&e.from==s.head&&e.insert.toString()==`
`&&n.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),e={from:s.from,to:s.to,insert:V.of([" "])}),e)return Fa(n,e,i,r);if(i&&!i.main.eq(s)){let o=!1,l="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),l=n.inputState.lastSelectionOrigin),n.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Fa(n,t,e,i=-1){if(D.ios&&n.inputState.flushIOSKey(t))return!0;let s=n.state.selection.main;if(D.android&&(t.to==s.to&&(t.from==s.from||t.from==s.from-1&&n.state.sliceDoc(t.from,s.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&qe(n.contentDOM,"Enter",13)||(t.from==s.from-1&&t.to==s.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>s.head)&&qe(n.contentDOM,"Backspace",8)||t.from==s.from&&t.to==s.to+1&&t.insert.length==0&&qe(n.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=Qf(n,t,e));return n.state.facet(ca).some(a=>a(n,t.from,t.to,r,l))||n.dispatch(l()),!0}function Qf(n,t,e){let i,s=n.state,r=s.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&n.inputState.composing<0){let l=r.from<t.from?s.sliceDoc(r.from,t.from):"",a=r.to>t.to?s.sliceDoc(t.to,r.to):"";i=s.replaceSelection(n.state.toText(l+t.insert.sliceString(0,void 0,n.state.lineBreak)+a))}else{let l=s.changes(t),a=e&&e.main.to<=l.newLength?e.main:void 0;if(s.selection.ranges.length>1&&n.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let h=n.state.sliceDoc(t.from,t.to),c,f=e&&Sa(n,e.main.head);if(f){let p=t.insert.length-(t.to-t.from);c={from:f.from,to:f.to-p}}else c=n.state.doc.lineAt(r.head);let u=r.to-t.to,d=r.to-r.from;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let g=p.to-u,m=g-h.length;if(p.to-p.from!=d||n.state.sliceDoc(m,g)!=h||p.to>=c.from&&p.from<=c.to)return{range:p};let y=s.changes({from:m,to:g,insert:t.insert}),x=p.to-r.to;return{changes:y,range:a?b.range(Math.max(0,a.anchor+x),Math.max(0,a.head+x)):p.map(y)}})}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 Zf(n,t,e,i){let s=Math.min(n.length,t.length),r=0;for(;r<s&&n.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==s&&n.length==t.length)return null;let o=n.length,l=t.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));e-=o+a-r}if(o<r&&n.length<t.length){let a=e<=r&&e>=o?r-e:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=e<=r&&e>=l?r-e:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function tu(n){let t=[];if(n.root.activeElement!=n.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return e&&(t.push(new Ao(e,i)),(s!=e||r!=i)&&t.push(new Ao(s,r))),t}function eu(n,t){if(n.length==0)return null;let e=n[0].pos,i=n.length==2?n[1].pos:e;return e>-1&&i>-1?b.single(e+t,i+t):null}const iu={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Qn=D.ie&&D.ie_version<=11;class nu{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new Hc,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(D.ie&&D.ie_version<=11||D.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&t.constructor.EDIT_CONTEXT===!0&&(this.editContext=new ru(t),t.state.facet(le)&&(t.contentDOM.editContext=this.editContext.editContext)),Qn&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.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(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){t.type=="change"&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(le)?i.root.activeElement!=this.dom:!an(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(D.ie&&D.ie_version<=11||D.android&&D.chrome)&&!i.state.selection.main.empty&&s.focusNode&&yi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=vi(t.root);if(!e)return!1;let i=D.safari&&t.root.nodeType==11&&Nc(this.dom.ownerDocument)==this.dom&&su(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=an(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&qc(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,iu),Qn&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Qn&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(t,e){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&&qe(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,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 t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&an(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new _f(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Na(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),s}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=Mo(e,t.previousSibling||t.target.previousSibling,-1),s=Mo(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(le)!=t.state.facet(le)&&(t.view.contentDOM.editContext=t.state.facet(le)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Mo(n,t,e){for(;t;){let i=$.get(t);if(i&&i.parent==n)return i;let s=t.parentNode;t=s!=n.dom?s:e>0?t.nextSibling:t.previousSibling}return null}function Do(n,t){let e=t.startContainer,i=t.startOffset,s=t.endContainer,r=t.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor);return yi(o.node,o.offset,s,r)&&([e,i,s,r]=[s,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:s,focusOffset:r}}function su(n,t){if(t.getComposedRanges){let s=t.getComposedRanges(n.root)[0];if(s)return Do(n,s)}let e=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),e=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),e?Do(n,e):null}class ru{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});e.addEventListener("textupdate",i=>{let{anchor:s}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:V.of(i.text.split(`
`))};r.from==this.from&&s<this.from?r.from=s:r.to==this.to&&s>this.to&&(r.to=s),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,Fa(t,r,b.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&this.revertPending(t.state))}),e.addEventListener("characterboundsupdate",i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=t.coordsForChar(o);r=a&&new DOMRect(a.left,a.right,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}e.updateCharacterBounds(i.rangeStart,s)}),e.addEventListener("textformatupdate",i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let a=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;s.push(P.mark({attributes:{style:a}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:ga.of(P.set(s))})}),e.addEventListener("compositionstart",()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)}),e.addEventListener("compositionend",()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null}),this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=vi(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,s=this.pendingContextChange;return t.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let c=h.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(h)){s=this.pendingContextChange=null,e+=c;return}else s=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}e+=c}),s&&!i&&this.revertPending(t.state),!i}update(t){!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.to+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),s=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}}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(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(i=>i.forEach(s=>e(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=t.root||zc(t.parent)||document,this.viewState=new ko(t.state||H.create(t)),t.scrollTo&&t.scrollTo.is(qi)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(ci).map(i=>new Jn(i));for(let i of this.plugins)i.update(this);this.observer=new nu(this),this.inputState=new wf(this),this.inputState.ensureHandlers(this.plugins),this.docView=new so(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=t.length==1&&t[0]instanceof Q?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,s,r=this.state;for(let u of t){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;t.some(u=>u.annotation(Ta))?(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(H.phrases)!=this.state.facet(H.phrases))return this.setState(r);s=yn.create(this,r,t),s.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new Ke(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(qi)&&(f=d.value.clip(this.state))}this.viewState.update(s,f),this.bidiCache=bn.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),e=this.docView.update(s),this.state.facet(fi)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Ji)!=s.state.facet(Ji)&&(this.viewState.mustMeasureContent=!0),(e||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!s.empty)for(let u of this.state.facet(Is))try{u(s)}catch(d){Dt(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Na(this,c)&&h.force&&qe(this.contentDOM,h.key,h.keyCode)})}setState(t){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=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new ko(t),this.plugins=t.facet(ci).map(i=>new Jn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new so(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(ci),i=t.state.facet(ci);if(e!=i){let s=[];for(let r of i){let o=e.indexOf(r);if(o<0)s.push(new Jn(r));else{let l=this.plugins[o];l.mustUpdate=t,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=t;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){Dt(this.state,i,"doc view update listener")}}}measure(t=!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,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Kl(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 Dt(this.state,p),Oo}}),f=yn.create(this,this.state,[]),u=!1;f.flags|=a,e?e.flags|=a:e=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f),u&&this.docViewUpdate());for(let d=0;d<h.length;d++)if(c[d]!=Oo)try{let p=h[d];p.write&&p.write(c[d],this)}catch(p){Dt(this.state,p)}if(u&&this.docView.updateSelection(!0),!f.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o;if(p>1||p<-1){s=s+p,i.scrollTop=s/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let l of this.state.facet(Is))l(e)}get themeClasses(){return Hs+" "+(this.state.facet(Ws)?Ea:La)+" "+this.state.facet(Ji)}updateAttrs(){let t=To(this,ma,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(le)?"true":"false",class:"cm-content",style:`${D.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),To(this,dr,e);let i=this.observer.ignore(()=>{let s=Ps(this.contentDOM,this.contentAttrs,e),r=Ps(this.dom,this.editorAttrs,t);return s||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let s of i.effects)if(s.is(O.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(fi);let t=this.state.facet(O.cspNonce);de.mount(this.root,this.styleModules.concat(Jf).reverse(),t?{nonce:t}: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(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Xn(this,t,co(this,t,e,i))}moveByGroup(t,e){return Xn(this,t,co(this,t,e,i=>bf(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return b.cursor(r.side(e,s)+t.from,r.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return yf(this,t,e,i)}moveVertically(t,e,i){return Xn(this,t,xf(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),va(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s),o=r[ce.find(r,t-s.from,-1,e)];return In(i,o.dir==X.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(ua)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>ou)return sa(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||na(r.isolates,i=no(this,t))))return r.order;i||(i=no(this,t));let s=tf(t.text,e,i);return this.bidiCache.push(new bn(t.from,t.to,e,i,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||D.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{zl(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return qi.of(new Ke(typeof t=="number"?b.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return qi.of(new Ke(b.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return ut.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return ut.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=de.newName(),s=[Ji.of(i),fi.of(zs(`.${i}`,t))];return e&&e.dark&&s.push(Ws.of(!0)),s}static baseTheme(t){return ye.lowest(fi.of(zs("."+Hs,t,Ia)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&$.get(i)||$.get(t);return((e=s==null?void 0:s.rootView)===null||e===void 0?void 0:e.view)||null}}O.styleModule=fi;O.inputHandler=ca;O.scrollHandler=pa;O.focusChangeEffect=fa;O.perLineTextDirection=ua;O.exceptionSink=ha;O.updateListener=Is;O.editable=le;O.mouseSelectionStyle=aa;O.dragMovesSelection=la;O.clickAddsSelectionRange=oa;O.decorations=ki;O.outerDecorations=ya;O.atomicRanges=pr;O.bidiIsolatedRanges=ba;O.scrollMargins=xa;O.darkTheme=Ws;O.cspNonce=T.define({combine:n=>n.length?n[0]:""});O.contentAttributes=dr;O.editorAttributes=ma;O.lineWrapping=O.contentAttributes.of({class:"cm-lineWrapping"});O.announce=F.define();const ou=4096,Oo={};class bn{constructor(t,e,i,s,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],s=t.length?t[t.length-1].dir:X.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==s&&!e.touchesRange(o.from,o.to)&&i.push(new bn(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function To(n,t,e){for(let i=n.state.facet(t),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&Ts(o,e)}return e}const lu=D.mac?"mac":D.windows?"win":D.linux?"linux":"key";function au(n,t){const e=n.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<e.length-1;++a){const h=e[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))t=="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 Yi(n,t,e){return t.altKey&&(n="Alt-"+n),t.ctrlKey&&(n="Ctrl-"+n),t.metaKey&&(n="Meta-"+n),e!==!1&&t.shiftKey&&(n="Shift-"+n),n}const hu=ye.default(O.domEventHandlers({keydown(n,t){return Wa(Va(t.state),n,t,"editor")}})),yr=T.define({enables:hu}),Po=new WeakMap;function Va(n){let t=n.facet(yr),e=Po.get(t);return e||Po.set(t,e=uu(t.reduce((i,s)=>i.concat(s),[]))),e}function cu(n,t,e){return Wa(Va(n.state),t,n,e)}let ae=null;const fu=4e3;function uu(n,t=lu){let e=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=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>au(y,t));for(let y=1;y<p.length;y++){let x=p.slice(0,y).join(" ");s(x,!0),d[x]||(d[x]={preventDefault:!0,stopPropagation:!1,run:[v=>{let S=ae={view:v,prefix:x,scope:o};return setTimeout(()=>{ae==S&&(ae=null)},fu),!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=e[h]||(e[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:f}=o;for(let u in c)c[u].run.push(d=>f(d,qs))}let a=o[t]||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 e}let qs=null;function Wa(n,t,e,i){qs=t;let s=Ic(t),r=nt(s,0),o=Bt(r)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;ae&&ae.view==e&&ae.scope==i&&(l=ae.prefix+" ",Ca.indexOf(t.keyCode)<0&&(h=!0,ae=null));let f=new Set,u=m=>{if(m){for(let y of m.run)if(!f.has(y)&&(f.add(y),y(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+Yi(s,t,!o)])?a=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(D.windows&&t.ctrlKey&&t.altKey)&&(p=pe[t.keyCode])&&p!=s?(u(d[l+Yi(p,t,!0)])||t.shiftKey&&(g=Si[t.keyCode])!=s&&g!=p&&u(d[l+Yi(g,t,!1)]))&&(a=!0):o&&t.shiftKey&&u(d[l+Yi(s,t,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&t.stopPropagation(),qs=null,a}class Ei{constructor(t,e,i,s,r){this.className=t,this.left=e,this.top=i,this.width=s,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className!=this.className?!1:(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",this.width!=null&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=Ha(t);return[new Ei(e,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}else return du(t,e,i)}}function Ha(n){let t=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==X.LTR?t.left:t.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:t.top-n.scrollDOM.scrollTop*n.scaleY}}function Bo(n,t,e,i){let s=n.coordsAtPos(t,e*2);if(!s)return i;let r=n.dom.getBoundingClientRect(),o=(s.top+s.bottom)/2,l=n.posAtCoords({x:r.left+1,y:o}),a=n.posAtCoords({x:r.right-1,y:o});return l==null||a==null?i:{from:Math.max(i.from,Math.min(l,a)),to:Math.min(i.to,Math.max(l,a))}}function du(n,t,e){if(e.to<=n.viewport.from||e.from>=n.viewport.to)return[];let i=Math.max(e.from,n.viewport.from),s=Math.min(e.to,n.viewport.to),r=n.textDirection==X.LTR,o=n.contentDOM,l=o.getBoundingClientRect(),a=Ha(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=Fs(n,i),p=Fs(n,s),g=d.type==Ot.Text?d:null,m=p.type==Ot.Text?p:null;if(g&&(n.lineWrapping||d.widgetLineBreaks)&&(g=Bo(n,i,1,g)),m&&(n.lineWrapping||p.widgetLineBreaks)&&(m=Bo(n,s,-1,m)),g&&m&&g.from==m.from&&g.to==m.to)return x(v(e.from,e.to,g));{let w=g?v(e.from,null,g):S(d,!1),A=m?v(null,e.to,m):S(p,!0),C=[];return(g||d).to<(m||p).from-(g&&m?1:0)||d.widgetLineBreaks>1&&w.bottom+n.defaultLineHeight/2<A.top?C.push(y(f,w.bottom,u,A.top)):w.bottom<A.top&&n.elementAtHeight((w.bottom+A.top)/2).type==Ot.Text&&(w.bottom=A.top=(w.bottom+A.top)/2),x(w).concat(C).concat(x(A))}function y(w,A,C,B){return new Ei(t,w-a.left,A-a.top-.01,C-w,B-A+.01)}function x({top:w,bottom:A,horizontal:C}){let B=[];for(let I=0;I<C.length;I+=2)B.push(y(C[I],w,C[I+1],A));return B}function v(w,A,C){let B=1e9,I=-1e9,N=[];function E(W,J,xt,wt,Ct){let Tt=n.coordsAtPos(W,W==C.to?-2:2),Z=n.coordsAtPos(xt,xt==C.from?2:-2);!Tt||!Z||(B=Math.min(Tt.top,Z.top,B),I=Math.max(Tt.bottom,Z.bottom,I),Ct==X.LTR?N.push(r&&J?f:Tt.left,r&&wt?u:Z.right):N.push(!r&&wt?f:Z.left,!r&&J?u:Tt.right))}let R=w??C.from,z=A??C.to;for(let W of n.visibleRanges)if(W.to>R&&W.from<z)for(let J=Math.max(W.from,R),xt=Math.min(W.to,z);;){let wt=n.state.doc.lineAt(J);for(let Ct of n.bidiSpans(wt)){let Tt=Ct.from+wt.from,Z=Ct.to+wt.from;if(Tt>=xt)break;Z>J&&E(Math.max(Tt,J),w==null&&Tt<=R,Math.min(Z,xt),A==null&&Z>=z,Ct.dir)}if(J=wt.to+1,J>=xt)break}return N.length==0&&E(R,w==null,z,A==null,n.textDirection),{top:B,bottom:I,horizontal:N}}function S(w,A){let C=l.top+(A?w.top:w.bottom);return{top:C,bottom:C,horizontal:[]}}}function pu(n,t){return n.constructor==t.constructor&&n.eq(t)}class gu{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(fn)!=t.state.facet(fn)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){this.layer.updateOnDocViewUpdate!==!1&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(fn);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;(t!=this.scaleX||e!=this.scaleY)&&(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some((e,i)=>!pu(e,this.drawn[i]))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let s=e.nextSibling;e.remove(),e=s}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const fn=T.define();function za(n){return[ut.define(t=>new gu(t,n)),fn.of(n)]}const qa=!D.ios,Ci=T.define({combine(n){return Le(n,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})}});function dm(n={}){return[Ci.of(n),mu,yu,bu,da.of(!0)]}function Ka(n){return n.startState.facet(Ci)!=n.state.facet(Ci)}const mu=za({above:!0,markers(n){let{state:t}=n,e=t.facet(Ci),i=[];for(let s of t.selection.ranges){let r=s==t.selection.main;if(s.empty?!r||qa:e.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 Ei.forRange(n,o,l))i.push(a)}}return i},update(n,t){n.transactions.some(i=>i.selection)&&(t.style.animationName=t.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let e=Ka(n);return e&&Ro(n.state,t),n.docChanged||n.selectionSet||e},mount(n,t){Ro(t.state,n)},class:"cm-cursorLayer"});function Ro(n,t){t.style.animationDuration=n.facet(Ci).cursorBlinkRate+"ms"}const yu=za({above:!1,markers(n){return n.state.selection.ranges.map(t=>t.empty?[]:Ei.forRange(n,"cm-selectionBackground",t)).reduce((t,e)=>t.concat(e))},update(n,t){return n.docChanged||n.selectionSet||n.viewportChanged||Ka(n)},class:"cm-selectionLayer"}),Ks={".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"}},".cm-content":{"& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}};qa&&(Ks[".cm-line"].caretColor=Ks[".cm-content"].caretColor="transparent !important");const bu=ye.highest(O.theme(Ks)),$a=F.define({map(n,t){return n==null?null:t.mapPos(n)}}),pi=bt.define({create(){return null},update(n,t){return n!=null&&(n=t.changes.mapPos(n)),t.effects.reduce((e,i)=>i.is($a)?i.value:e,n)}}),xu=ut.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 t;let e=n.state.field(pi);e==null?this.cursor!=null&&((t=this.cursor)===null||t===void 0||t.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(pi)!=e||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,t=n.state.field(pi),e=t!=null&&n.coordsAtPos(t);if(!e)return null;let i=n.scrollDOM.getBoundingClientRect();return{left:e.left-i.left+n.scrollDOM.scrollLeft*n.scaleX,top:e.top-i.top+n.scrollDOM.scrollTop*n.scaleY,height:e.bottom-e.top}}drawCursor(n){if(this.cursor){let{scaleX:t,scaleY:e}=this.view;n?(this.cursor.style.left=n.left/t+"px",this.cursor.style.top=n.top/e+"px",this.cursor.style.height=n.height/e+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(pi)!=n&&this.view.dispatch({effects:$a.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function pm(){return[pi,xu]}function Lo(n,t,e,i,s){t.lastIndex=0;for(let r=n.iterRange(e,i),o=e,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=t.exec(r.value);)s(o+l.index,l)}function wu(n,t){let e=n.visibleRanges;if(e.length==1&&e[0].from==n.viewport.from&&e[0].to==n.viewport.to)return e;let i=[];for(let{from:s,to:r}of e)s=Math.max(n.state.doc.lineAt(s).from,s-t),r=Math.min(n.state.doc.lineAt(r).to,r+t),i.length&&i[i.length-1].to>=s?i[i.length-1].to=r:i.push({from:s,to:r});return i}class Su{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:r,maxLength:o=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,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(t){let e=new De,i=e.add.bind(e);for(let{from:s,to:r}of wu(t,this.maxLength))Lo(t.state.doc,this.regexp,s,r,(o,l)=>this.addMatch(l,t,o,i));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges((r,o,l,a)=>{a>t.view.viewport.from&&l<t.view.viewport.to&&(i=Math.min(l,i),s=Math.max(a,s))}),t.viewportChanged||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let r of t.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,s);if(l>o){let a=t.state.doc.lineAt(o),h=a.to<l?t.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,t,d.index+a.from,p);else Lo(t.state.doc,this.regexp,c,f,(g,m)=>this.addMatch(m,t,g,p));e=e.update({filterFrom:c,filterTo:f,filter:(g,m)=>g<c||m>f,add:u})}}return e}}const $s=/x/.unicode!=null?"gu":"g",vu=new RegExp(`[\0-\b
--Ÿ­؜\u2028\u2029\uFEFF-]`,$s),ku={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 Zn=null;function Cu(){var n;if(Zn==null&&typeof document<"u"&&document.body){let t=document.body.style;Zn=((n=t.tabSize)!==null&&n!==void 0?n:t.MozTabSize)!=null}return Zn||!1}const un=T.define({combine(n){let t=Le(n,{render:null,specialChars:vu,addSpecialChars:null});return(t.replaceTabs=!Cu())&&(t.specialChars=new RegExp(" |"+t.specialChars.source,$s)),t.addSpecialChars&&(t.specialChars=new RegExp(t.specialChars.source+"|"+t.addSpecialChars.source,$s)),t}});function gm(n={}){return[un.of(n),Au()]}let Eo=null;function Au(){return Eo||(Eo=ut.fromClass(class{constructor(n){this.view=n,this.decorations=P.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(un)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new Su({regexp:n.specialChars,decoration:(t,e,i)=>{let{doc:s}=e.state,r=nt(t[0],0);if(r==9){let o=s.lineAt(i),l=e.state.tabSize,a=ti(o.text,l,i-o.from);return P.replace({widget:new Tu((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=P.replace({widget:new Ou(n,r)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let t=n.state.facet(un);n.startState.facet(un)!=t?(this.decorator=this.makeDecorator(t),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const Mu="•";function Du(n){return n>=32?Mu:n==10?"␤":String.fromCharCode(9216+n)}class Ou extends Ee{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=Du(this.code),i=t.state.phrase("Control character")+" "+(ku[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Tu extends Ee{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent=" ",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}class Pu extends Ee{constructor(t){super(),this.content=t}toDOM(){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?t.setAttribute("aria-label","placeholder "+this.content):t.setAttribute("aria-hidden","true"),t}coordsAt(t){let e=t.firstChild?Ge(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=In(e[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 mm(n){return ut.fromClass(class{constructor(t){this.view=t,this.placeholder=n?P.set([P.widget({widget:new Pu(n),side:1}).range(0)]):P.none}get decorations(){return this.view.state.doc.length?P.none:this.placeholder}},{decorations:t=>t.decorations})}const js=2e3;function Bu(n,t,e){let i=Math.min(t.line,e.line),s=Math.max(t.line,e.line),r=[];if(t.off>js||e.off>js||t.col<0||e.col<0){let o=Math.min(t.off,e.off),l=Math.max(t.off,e.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(t.col,e.col),l=Math.max(t.col,e.col);for(let a=i;a<=s;a++){let h=n.doc.line(a),c=vs(h.text,o,n.tabSize,!0);if(c<0)r.push(b.cursor(h.to));else{let f=vs(h.text,l,n.tabSize);r.push(b.range(h.from+c,h.from+f))}}}return r}function Ru(n,t){let e=n.coordsAtPos(n.viewport.from);return e?Math.round(Math.abs((e.left-t)/n.defaultCharacterWidth)):-1}function Io(n,t){let e=n.posAtCoords({x:t.clientX,y:t.clientY},!1),i=n.state.doc.lineAt(e),s=e-i.from,r=s>js?-1:s==i.length?Ru(n,t.clientX):ti(i.text,n.state.tabSize,e-i.from);return{line:i.number,col:r,off:s}}function Lu(n,t){let e=Io(n,t),i=n.state.selection;return e?{update(s){if(s.docChanged){let r=s.changes.mapPos(s.startState.doc.line(e.line).from),o=s.state.doc.lineAt(r);e={line:o.number,col:e.col,off:Math.min(e.off,o.length)},i=i.map(s.changes)}},get(s,r,o){let l=Io(n,s);if(!l)return i;let a=Bu(n.state,e,l);return a.length?o?b.create(a.concat(i.ranges)):b.create(a):i}}:null}function ym(n){let t=e=>e.altKey&&e.button==0;return O.mouseSelectionStyle.of((e,i)=>t(i)?Lu(e,i):null)}const oi="-10000px";class Eu{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(t,e){var i;let s=t.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(t);return!1}let o=[],l=e?[]:null;for(let a=0;a<r.length;a++){let h=r[a],c=-1;if(h){for(let f=0;f<this.tooltips.length;f++){let u=this.tooltips[f];u&&u.create==h.create&&(c=f)}if(c<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let f=o[a]=this.tooltipViews[c];l&&(l[a]=e[c]),f.update&&f.update(t)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return e&&(l.forEach((a,h)=>e[h]=a),e.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}}function Iu(n){let{win:t}=n;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const ts=T.define({combine:n=>{var t,e,i;return{position:D.ios?"absolute":((t=n.find(s=>s.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=n.find(s=>s.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Iu}}}),No=new WeakMap,ja=ut.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=n.state.facet(ts);this.position=t.position,this.parent=t.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new Eu(n,Ua,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.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 t=this.manager.update(n,this.above);t&&this.observeIntersection();let e=t||n.geometryChanged,i=n.state.facet(ts);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;e=!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);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(n,t){let e=n.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),n.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",e.dom.appendChild(s)}return e.dom.style.position=this.position,e.dom.style.top=oi,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var n,t,e;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=this.view.dom.getBoundingClientRect(),t=1,e=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(D.gecko)i=s.offsetParent!=this.container.ownerDocument.body;else if(s.style.top==oi&&s.style.left=="0px"){let r=s.getBoundingClientRect();i=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}}if(i||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(t=s.width/this.parent.offsetWidth,e=s.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=this.view.viewState);return{editor:n,parent:this.parent?this.container.getBoundingClientRect():n,pos:this.manager.tooltips.map((s,r)=>{let o=this.manager.tooltipViews[r];return o.getCoords?o.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet(ts).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(n){var t;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:e,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,f=n.pos[l],u=n.size[l];if(!f||f.bottom<=Math.max(e.top,i.top)||f.top>=Math.min(e.bottom,i.bottom)||f.right<Math.max(e.left,i.left)-.1||f.left>Math.min(e.right,i.right)+.1){c.style.top=oi;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,m=(t=No.get(h))!==null&&t!==void 0?t:u.bottom-u.top,y=h.offset||Fu,x=this.view.textDirection==X.LTR,v=u.width>i.right-i.left?x?i.left:i.right-u.width:x?Math.min(f.left-(d?14:0)+y.x,i.right-g):Math.max(i.left,f.left-g+(d?14:0)-y.x),S=this.above[l];!a.strictSide&&(S?f.top-(u.bottom-u.top)-y.y<i.top:f.bottom+(u.bottom-u.top)+y.y>i.bottom)&&S==i.bottom-f.bottom>f.top-i.top&&(S=this.above[l]=!S);let w=(S?f.top-i.top:i.bottom-f.bottom)-p;if(w<m&&h.resize!==!1){if(w<this.view.defaultLineHeight){c.style.top=oi;continue}No.set(h,m),c.style.height=(m=w)/r+"px"}else c.style.height&&(c.style.height="");let A=S?f.top-m-p-y.y:f.bottom+p+y.y,C=v+g;if(h.overlap!==!0)for(let B of o)B.left<C&&B.right>v&&B.top<A+m&&B.bottom>A&&(A=S?B.top-m-2-p:B.bottom+p+2);if(this.position=="absolute"?(c.style.top=(A-n.parent.top)/r+"px",c.style.left=(v-n.parent.left)/s+"px"):(c.style.top=A/r+"px",c.style.left=v/s+"px"),d){let B=f.left+(x?y.x:-y.x)-(v+14-7);d.style.left=B/s+"px"}h.overlap!==!0&&o.push({left:v,top:A,right:C,bottom:A+m}),c.classList.toggle("cm-tooltip-above",S),c.classList.toggle("cm-tooltip-below",!S),h.positioned&&h.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=oi}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Nu=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"}}}),Fu={x:0,y:0},Ua=T.define({enables:[ja,Nu]});function Ga(n,t){let e=n.plugin(ja);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const Fo=T.define({combine(n){let t,e;for(let i of n)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}});function xn(n,t){let e=n.plugin(Ja),i=e?e.specs.indexOf(t):-1;return i>-1?e.panels[i]:null}const Ja=ut.fromClass(class{constructor(n){this.input=n.state.facet(wn),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(n));let t=n.state.facet(Fo);this.top=new Xi(n,!0,t.topContainer),this.bottom=new Xi(n,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(n){let t=n.state.facet(Fo);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new Xi(n.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new Xi(n.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=n.state.facet(wn);if(e!=this.input){let i=e.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(t=>{let e=t.plugin(n);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class Xi{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,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 e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=Vo(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=Vo(t)}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 t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function Vo(n){let t=n.nextSibling;return n.remove(),t}const wn=T.define({enables:Ja});class Be extends Me{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Be.prototype.elementClass="";Be.prototype.toDOM=void 0;Be.prototype.mapMode=ht.TrackBefore;Be.prototype.startSide=Be.prototype.endSide=-1;Be.prototype.point=!0;const Vu=T.define(),Wu=new class extends Be{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Hu=Vu.compute(["selection"],n=>{let t=[],e=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head).from;s>e&&(e=s,t.push(Wu.range(s)))}return K.of(t)});function bm(){return Hu}const zu=1024;let qu=0;class Rt{constructor(t,e){this.from=t,this.to=e}}class L{constructor(t={}){this.id=qu++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=mt.match(t)),e=>{let i=t(e);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.isolate=new L({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});L.contextHash=new L({perNode:!0});L.lookAhead=new L({perNode:!0});L.mounted=new L({perNode:!0});class Ai{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[L.mounted.id]}}const Ku=Object.create(null);class mt{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):Ku,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),s=new mt(t.name||"",e,t.id,i);if(t.props){for(let r of t.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");e[r[0].id]=r[1]}}return s}prop(t){return this.props[t.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(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(L.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return i=>{for(let s=i.prop(L.group),r=-1;r<(s?s.length:0);r++){let o=e[r<0?i.name:s[r]];if(o)return o}}}}mt.none=new mt("",Object.create(null),0,8);class br{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let s=null;for(let r of t){let o=r(i);o&&(s||(s=Object.assign({},i.props)),s[o[0].id]=o[1])}e.push(s?new mt(i.name,s,i.id,i.flags):i)}return new br(e)}}const _i=new WeakMap,Wo=new WeakMap;var Y;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays"})(Y||(Y={}));class j{constructor(t,e,i,s,r){if(this.type=t,this.children=e,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 t=Ai.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let s=i.toString();s&&(e&&(e+=","),e+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new Sn(this.topNode,t)}cursorAt(t,e=0,i=0){let s=_i.get(this)||this.topNode,r=new Sn(s);return r.moveTo(t,e),_i.set(this,r._tree),r}get topNode(){return new ft(this,0,0,null)}resolve(t,e=0){let i=Mi(_i.get(this)||this.topNode,t,e,!1);return _i.set(this,i),i}resolveInner(t,e=0){let i=Mi(Wo.get(this)||this.topNode,t,e,!0);return Wo.set(this,i),i}resolveStack(t,e=0){return Uu(this,t,e)}iterate(t){let{enter:e,leave:i,from:s=0,to:r=this.length}=t,o=t.mode||0,l=(o&Y.IncludeAnonymous)>0;for(let a=this.cursor(o|Y.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||e(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(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:Sr(mt.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,s)=>new j(this.type,e,i,s,this.propValues),t.makeTree||((e,i,s)=>new j(mt.none,e,i,s)))}static build(t){return Gu(t)}}j.empty=new j(mt.none,[],[],0);class xr{constructor(t,e){this.buffer=t,this.index=e}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 xr(this.buffer,this.index)}}class me{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return mt.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],s=this.set.types[e],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),t+=4,i==t)return r;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return r+"("+o.join(",")+")"}findChild(t,e,i,s,r){let{buffer:o}=this,l=-1;for(let a=t;a!=e&&!(Ya(r,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(t,e,i){let s=this.buffer,r=new Uint16Array(e-t),o=0;for(let l=t,a=0;l<e;){r[a++]=s[l++],r[a++]=s[l++]-i;let h=r[a++]=s[l++]-i;r[a++]=s[l++]-t,o=Math.max(o,h)}return new me(r,o,this.set)}}function Ya(n,t,e,i){switch(n){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function Mi(n,t,e,i){for(var s;n.from==n.to||(e<1?n.from>=t:n.from>t)||(e>-1?n.to<=t:n.to<t);){let o=!i&&n instanceof ft&&n.index<0?null:n.parent;if(!o)return n;n=o}let r=i?0:Y.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof ft&&o.index<0&&((s=l.enter(t,e,r))===null||s===void 0?void 0:s.from)!=o.from&&(n=l);for(;;){let o=n.enter(t,e,r);if(!o)return n;n=o}}class Xa{cursor(t=0){return new Sn(this,t)}getChild(t,e=null,i=null){let s=Ho(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Ho(this,t,e,i)}resolve(t,e=0){return Mi(this,t,e,!1)}resolveInner(t,e=0){return Mi(this,t,e,!0)}matchContext(t){return Us(this,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let s=e.lastChild;if(!s||s.to!=e.to)break;s.type.isError&&s.from==s.to?(i=e,e=s.prevSibling):e=s}return i}get node(){return this}get next(){return this.parent}}class ft extends Xa{constructor(t,e,i,s){super(),this._tree=t,this.from=e,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(t,e,i,s,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=e>0?l.length:-1;t!=h;t+=e){let c=l[t],f=a[t]+o.from;if(Ya(s,i,f,f+c.length)){if(c instanceof me){if(r&Y.ExcludeBuffers)continue;let u=c.findChild(0,c.buffer.length,e,i-f,s);if(u>-1)return new Yt(new $u(o,c,t,f),null,u)}else if(r&Y.IncludeAnonymous||!c.type.isAnonymous||wr(c)){let u;if(!(r&Y.IgnoreMounts)&&(u=Ai.get(c))&&!u.overlay)return new ft(u.tree,f,t,o);let d=new ft(c,f,t,o);return r&Y.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(e<0?c.children.length-1:0,e,i,s)}}}if(r&Y.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<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(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let s;if(!(i&Y.IgnoreOverlays)&&(s=Ai.get(this._tree))&&s.overlay){let r=t-this.from;for(let{from:o,to:l}of s.overlay)if((e>0?o<=r:o<r)&&(e<0?l>=r:l>r))return new ft(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}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}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Ho(n,t,e,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(e!=null){for(let o=!1;!o;)if(o=s.type.is(e),!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(t)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function Us(n,t,e=t.length-1){for(let i=n.parent;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}class $u{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class Yt extends Xa{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(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new Yt(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,i=0){if(i&Y.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new Yt(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new Yt(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new Yt(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1];t.push(i.slice(s,r,o)),e.push(0)}return new j(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function _a(n){if(!n.length)return null;let t=0,e=n[0];for(let r=1;r<n.length;r++){let o=n[r];(o.from>e.from||o.to<e.to)&&(e=o,t=r)}let i=e instanceof ft&&e.index<0?null:e.parent,s=n.slice();return i?s[t]=i:s.splice(t,1),new ju(s,e)}class ju{constructor(t,e){this.heads=t,this.node=e}get next(){return _a(this.heads)}}function Uu(n,t,e){let i=n.resolveInner(t,e),s=null;for(let r=i instanceof ft?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(s||(s=[i])).push(o.resolve(t,e)),r=o}else{let o=Ai.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new ft(o.tree,o.overlay[0].from+r.from,-1,r);(s||(s=[i])).push(Mi(l,t,e,!1))}}return s?_a(s):i}class Sn{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof ft)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return t?t instanceof ft?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-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(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&Y.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Y.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Y.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(e.findChild(s,this.index,-1,0,4))}else{let s=e.buffer[this.index+3];if(s<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>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:e,parent:i}=s)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let r=e+t,o=t<0?-1:i._tree.children.length;r!=o;r+=t){let l=i._tree.children[r];if(this.mode&Y.IncludeAnonymous||l instanceof me||!l.type.isAnonymous||wr(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=t;o;o=o._parent)if(o.index==s){if(s==this.index)return o;e=o,i=r+1;break t}s=this.stack[--r]}for(let s=i;s<this.stack.length;s++)e=new Yt(this.buffer,e,this.stack[s]);return this.bufferNode=new Yt(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let s=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;s&&e&&e(this),s=this.type.isAnonymous,!this.nextSibling();){if(!i)return;this.parent(),i--,s=!0}}}matchContext(t){if(!this.buffer)return Us(this.node,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let s=t.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Us(this.node,t,s);let o=i[e.buffer[this.stack[r]]];if(!o.isAnonymous){if(t[s]&&t[s]!=o.name)return!1;s--}}return!0}}function wr(n){return n.children.some(t=>t instanceof me||!t.type.isAnonymous||wr(t))}function Gu(n){var t;let{buffer:e,nodeSet:i,maxBufferLength:s=zu,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(e)?new xr(e,e.length):e,a=i.types,h=0,c=0;function f(w,A,C,B,I,N){let{id:E,start:R,end:z,size:W}=l,J=c;for(;W<0;)if(l.next(),W==-1){let Z=r[E];C.push(Z),B.push(R-w);return}else if(W==-3){h=E;return}else if(W==-4){c=E;return}else throw new RangeError(`Unrecognized record size: ${W}`);let xt=a[E],wt,Ct,Tt=R-w;if(z-R<=s&&(Ct=m(l.pos-A,I))){let Z=new Uint16Array(Ct.size-Ct.skip),Pt=l.pos-Ct.size,zt=Z.length;for(;l.pos>Pt;)zt=y(Ct.start,Z,zt);wt=new me(Z,z-Ct.start,i),Tt=Ct.start-w}else{let Z=l.pos-W;l.next();let Pt=[],zt=[],xe=E>=o?E:-1,Ie=0,Vi=z;for(;l.pos>Z;)xe>=0&&l.id==xe&&l.size>=0?(l.end<=Vi-s&&(p(Pt,zt,R,Ie,l.end,Vi,xe,J),Ie=Pt.length,Vi=l.end),l.next()):N>2500?u(R,Z,Pt,zt):f(R,Z,Pt,zt,xe,N+1);if(xe>=0&&Ie>0&&Ie<Pt.length&&p(Pt,zt,R,Ie,R,Vi,xe,J),Pt.reverse(),zt.reverse(),xe>-1&&Ie>0){let Vr=d(xt);wt=Sr(xt,Pt,zt,0,Pt.length,0,z-R,Vr,Vr)}else wt=g(xt,Pt,zt,z-R,J-z)}C.push(wt),B.push(Tt)}function u(w,A,C,B){let I=[],N=0,E=-1;for(;l.pos>A;){let{id:R,start:z,end:W,size:J}=l;if(J>4)l.next();else{if(E>-1&&z<E)break;E<0&&(E=W-s),I.push(R,z,W),N++,l.next()}}if(N){let R=new Uint16Array(N*4),z=I[I.length-2];for(let W=I.length-3,J=0;W>=0;W-=3)R[J++]=I[W],R[J++]=I[W+1]-z,R[J++]=I[W+2]-z,R[J++]=J;C.push(new me(R,I[2]-z,i)),B.push(z-w)}}function d(w){return(A,C,B)=>{let I=0,N=A.length-1,E,R;if(N>=0&&(E=A[N])instanceof j){if(!N&&E.type==w&&E.length==B)return E;(R=E.prop(L.lookAhead))&&(I=C[N]+E.length+R)}return g(w,A,C,B,I)}}function p(w,A,C,B,I,N,E,R){let z=[],W=[];for(;w.length>B;)z.push(w.pop()),W.push(A.pop()+C-I);w.push(g(i.types[E],z,W,N-I,R-N)),A.push(I-C)}function g(w,A,C,B,I=0,N){if(h){let E=[L.contextHash,h];N=N?[E].concat(N):[E]}if(I>25){let E=[L.lookAhead,I];N=N?[E].concat(N):[E]}return new j(w,A,C,B,N)}function m(w,A){let C=l.fork(),B=0,I=0,N=0,E=C.end-s,R={size:0,start:0,skip:0};t:for(let z=C.pos-w;C.pos>z;){let W=C.size;if(C.id==A&&W>=0){R.size=B,R.start=I,R.skip=N,N+=4,B+=4,C.next();continue}let J=C.pos-W;if(W<0||J<z||C.start<E)break;let xt=C.id>=o?4:0,wt=C.start;for(C.next();C.pos>J;){if(C.size<0)if(C.size==-3)xt+=4;else break t;else C.id>=o&&(xt+=4);C.next()}I=wt,B+=W,N+=xt}return(A<0||B==w)&&(R.size=B,R.start=I,R.skip=N),R.size>4?R:void 0}function y(w,A,C){let{id:B,start:I,end:N,size:E}=l;if(l.next(),E>=0&&B<o){let R=C;if(E>4){let z=l.pos-(E-4);for(;l.pos>z;)C=y(w,A,C)}A[--C]=R,A[--C]=N-w,A[--C]=I-w,A[--C]=B}else E==-3?h=B:E==-4&&(c=B);return C}let x=[],v=[];for(;l.pos>0;)f(n.start||0,n.bufferStart||0,x,v,-1,0);let S=(t=n.length)!==null&&t!==void 0?t:x.length?v[0]+x[0].length:0;return new j(a[n.topID],x.reverse(),v.reverse(),S)}const zo=new WeakMap;function dn(n,t){if(!n.isAnonymous||t instanceof me||t.type!=n)return 1;let e=zo.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=n||!(i instanceof j)){e=1;break}e+=dn(n,i)}zo.set(t,e)}return e}function Sr(n,t,e,i,s,r,o,l,a){let h=0;for(let p=i;p<s;p++)h+=dn(n,t[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,g,m,y,x){for(let v=m;v<y;){let S=v,w=g[v],A=dn(n,p[v]);for(v++;v<y;v++){let C=dn(n,p[v]);if(A+C>=c)break;A+=C}if(v==S+1){if(A>c){let C=p[S];d(C.children,C.positions,0,C.children.length,g[S]+x);continue}f.push(p[S])}else{let C=g[v-1]+p[v-1].length-w;f.push(Sr(n,p,g,S,v,w,C,null,a))}u.push(w+x-r)}}return d(t,e,i,s,0),(l||a)(f,u,o)}class xm{constructor(){this.map=new WeakMap}setBuffer(t,e,i){let s=this.map.get(t);s||this.map.set(t,s=new Map),s.set(e,i)}getBuffer(t,e){let i=this.map.get(t);return i&&i.get(e)}set(t,e){t instanceof Yt?this.setBuffer(t.context.buffer,t.index,e):t instanceof ft&&this.map.set(t.tree,e)}get(t){return t instanceof Yt?this.getBuffer(t.context.buffer,t.index):t instanceof ft?this.map.get(t.tree):void 0}cursorSet(t,e){t.buffer?this.setBuffer(t.buffer.buffer,t.index,e):this.map.set(t.tree,e)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}}class ee{constructor(t,e,i,s,r=!1,o=!1){this.from=t,this.to=e,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(t,e=[],i=!1){let s=[new ee(0,t.length,t,0,!1,i)];for(let r of e)r.to>t.length&&s.push(r);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],r=1,o=t.length?t[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<e.length?e[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 ee(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&s.push(u),o.to>f)break;o=r<t.length?t[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return s}}class Qa{startParse(t,e,i){return typeof t=="string"&&(t=new Ju(t)),i=i?i.length?i.map(s=>new Rt(s.from,s.to)):[new Rt(0,0)]:[new Rt(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let r=s.advance();if(r)return r}}}class Ju{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}function wm(n){return(t,e,i,s)=>new Xu(t,n,e,i,s)}class qo{constructor(t,e,i,s,r){this.parser=t,this.parse=e,this.overlay=i,this.target=s,this.from=r}}function Ko(n){if(!n.length||n.some(t=>t.from>=t.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(n))}class Yu{constructor(t,e,i,s,r,o,l){this.parser=t,this.predicate=e,this.mounts=i,this.index=s,this.start=r,this.target=o,this.prev=l,this.depth=0,this.ranges=[]}}const Gs=new L({perNode:!0});class Xu{constructor(t,e,i,s,r){this.nest=e,this.input=i,this.fragments=s,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}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 j(i.type,i.children,i.positions,i.length,i.propValues.concat([[Gs,this.stoppedAt]]))),i}let t=this.inner[this.innerDone],e=t.parse.advance();if(e){this.innerDone++;let i=Object.assign(Object.create(null),t.target.props);i[L.mounted.id]=new Ai(e,t.overlay,t.parser),t.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].from<t&&(t=Math.min(t,this.inner[e].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].parse.stopAt(t)}startInner(){let t=new Zu(this.fragments),e=null,i=null,s=new Sn(new ft(this.baseTree,this.ranges[0].from,0,null),Y.IncludeAnonymous|Y.IgnoreMounts);t:for(let r,o;;){let l=!0,a;if(this.stoppedAt!=null&&s.from>=this.stoppedAt)l=!1;else if(t.hasNode(s)){if(e){let h=e.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&&!e.ranges.some(d=>d.from<u&&d.to>f)&&e.ranges.push({from:f,to:u})}}l=!1}else if(i&&(o=_u(i.ranges,s.from,s.to)))l=o!=2;else if(!s.type.isAnonymous&&(r=this.nest(s,this.input))&&(s.from<s.to||!r.overlay)){s.tree||Qu(s);let h=t.findMounts(s.from,r.parser);if(typeof r.overlay=="function")e=new Yu(r.parser,r.overlay,h,this.inner.length,s.from,s.tree,e);else{let c=Uo(this.ranges,r.overlay||(s.from<s.to?[new Rt(s.from,s.to)]:[]));c.length&&Ko(c),(c.length||!r.overlay)&&this.inner.push(new qo(r.parser,c.length?r.parser.startParse(this.input,Go(h,c),c):r.parser.startParse(""),r.overlay?r.overlay.map(f=>new Rt(f.from-s.from,f.to-s.from)):null,s.tree,c.length?c[0].from:s.from)),r.overlay?c.length&&(i={ranges:c,depth:0,prev:i}):l=!1}}else e&&(a=e.predicate(s))&&(a===!0&&(a=new Rt(s.from,s.to)),a.from<a.to&&e.ranges.push(a));if(l&&s.firstChild())e&&e.depth++,i&&i.depth++;else for(;!s.nextSibling();){if(!s.parent())break t;if(e&&!--e.depth){let h=Uo(this.ranges,e.ranges);h.length&&(Ko(h),this.inner.splice(e.index,0,new qo(e.parser,e.parser.startParse(this.input,Go(e.mounts,h),h),e.ranges.map(c=>new Rt(c.from-e.start,c.to-e.start)),e.target,h[0].from))),e=e.prev}i&&!--i.depth&&(i=i.prev)}}}}function _u(n,t,e){for(let i of n){if(i.from>=e)break;if(i.to>t)return i.from<=t&&i.to>=e?2:1}return 0}function $o(n,t,e,i,s,r){if(t<e){let o=n.buffer[t+1];i.push(n.slice(t,e,o)),s.push(o-r)}}function Qu(n){let{node:t}=n,e=[],i=t.context.buffer;do e.push(n.index),n.parent();while(!n.tree);let s=n.tree,r=s.children.indexOf(i),o=s.children[r],l=o.buffer,a=[r];function h(c,f,u,d,p,g){let m=e[g],y=[],x=[];$o(o,c,m,y,x,d);let v=l[m+1],S=l[m+2];a.push(y.length);let w=g?h(m+4,l[m+3],o.set.types[l[m]],v,S-v,g-1):t.toTree();return y.push(w),x.push(v-d),$o(o,l[m+3],f,y,x,d),new j(u,y,x,p)}s.children[r]=h(0,l.length,mt.none,0,o.length,e.length-1);for(let c of a){let f=n.tree.children[c],u=n.tree.positions[c];n.yield(new ft(f,u+n.from,c,n._tree))}}class jo{constructor(t,e){this.offset=e,this.done=!1,this.cursor=t.cursor(Y.IncludeAnonymous|Y.IgnoreMounts)}moveTo(t){let{cursor:e}=this,i=t-this.offset;for(;!this.done&&e.from<i;)e.to>=t&&e.enter(i,1,Y.IgnoreOverlays|Y.ExcludeBuffers)||e.next(!1)||(this.done=!0)}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let e=this.cursor.tree;;){if(e==t.tree)return!0;if(e.children.length&&e.positions[0]==0&&e.children[0]instanceof j)e=e.children[0];else break}return!1}}class Zu{constructor(t){var e;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let i=this.curFrag=t[0];this.curTo=(e=i.tree.prop(Gs))!==null&&e!==void 0?e:i.to,this.inner=new jo(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=(t=e.tree.prop(Gs))!==null&&t!==void 0?t:e.to,this.inner=new jo(e.tree,-e.offset)}}findMounts(t,e){var i;let s=[];if(this.inner){this.inner.cursor.moveTo(t,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==e)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 Uo(n,t){let e=null,i=t;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||(e||(i=e=t.slice()),a.from<o?(e[r]=new Rt(a.from,o),a.to>l&&e.splice(r+1,0,new Rt(l,a.to))):a.to>l?e[r--]=new Rt(l,a.to):e.splice(r--,1))}}return i}function td(n,t,e,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==t.length?1e9:l?t[r].to:t[r].from;if(o!=l){let u=Math.max(a,e),d=Math.min(c,f,i);u<d&&h.push(new Rt(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 Go(n,t){let e=[];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 Rt(u.from+i,u.to+i)),f=td(t,c,a,h);for(let u=0,d=a;;u++){let p=u==f.length,g=p?h:f[u].from;if(g>d&&e.push(new ee(d,g,s.tree,-o,r.from>=d||r.openStart,r.to<=g||r.openEnd)),p)break;d=f[u].to}}else e.push(new ee(a,h,s.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return e}let ed=0;class Ut{constructor(t,e,i){this.set=t,this.base=e,this.modified=i,this.id=ed++}static define(t){if(t!=null&&t.base)throw new Error("Can not derive from a modified tag");let e=new Ut([],null,[]);if(e.set.push(e),t)for(let i of t.set)e.set.push(i);return e}static defineModifier(){let t=new vn;return e=>e.modified.indexOf(t)>-1?e:vn.get(e.base||e,e.modified.concat(t).sort((i,s)=>i.id-s.id))}}let id=0;class vn{constructor(){this.instances=[],this.id=id++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(l=>l.base==t&&nd(e,l.modified));if(i)return i;let s=[],r=new Ut(s,t,e);for(let l of e)l.instances.push(r);let o=sd(e);for(let l of t.set)if(!l.modified.length)for(let a of o)s.push(vn.get(l,a));return r}}function nd(n,t){return n.length==t.length&&n.every((e,i)=>e==t[i])}function sd(n){let t=[[]];for(let e=0;e<n.length;e++)for(let i=0,s=t.length;i<s;i++)t.push(t[i].concat(n[e]));return t.sort((e,i)=>i.length-e.length)}function rd(n){let t=Object.create(null);for(let e in n){let i=n[e];Array.isArray(i)||(i=[i]);for(let s of e.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 kn(i,o,a>0?r.slice(0,a):null);t[h]=c.sort(t[h])}}return Za.add(t)}const Za=new L;class kn{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}kn.empty=new kn([],2,null);function th(n,t){let e=Object.create(null);for(let r of n)if(!Array.isArray(r.tag))e[r.tag.id]=r.class;else for(let o of r.tag)e[o.id]=r.class;let{scope:i,all:s=null}=t||{};return{style:r=>{let o=s;for(let l of r)for(let a of l.set){let h=e[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function od(n,t){let e=null;for(let i of n){let s=i.style(t);s&&(e=e?e+" "+s:s)}return e}function ld(n,t,e,i=0,s=n.length){let r=new ad(i,Array.isArray(t)?t:[t],e);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}class ad{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,r){let{type:o,from:l,to:a}=t;if(l>=i||a<=e)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,c=hd(t)||kn.empty,f=od(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(s+=(s?" ":"")+f)),this.startSpan(Math.max(e,l),h),c.opaque)return;let u=t.tree&&t.tree.prop(L.mounted);if(u&&u.overlay){let d=t.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=t.firstChild();for(let m=0,y=l;;m++){let x=m<u.overlay.length?u.overlay[m]:null,v=x?x.from+l:a,S=Math.max(e,y),w=Math.min(i,v);if(S<w&&g)for(;t.from<w&&(this.highlightRange(t,S,w,s,r),this.startSpan(Math.min(w,t.to),h),!(t.to>=v||!t.nextSibling())););if(!x||v>i)break;y=x.to+l,y>e&&(this.highlightRange(d.cursor(),Math.max(e,x.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),h))}g&&t.parent()}else if(t.firstChild()){u&&(s="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,r),this.startSpan(Math.min(i,t.to),h)}while(t.nextSibling());t.parent()}}}function hd(n){let t=n.type.prop(Za);for(;t&&t.context&&!n.matchContext(t.context);)t=t.next;return t||null}const k=Ut.define,Qi=k(),re=k(),Jo=k(re),Yo=k(re),oe=k(),Zi=k(oe),es=k(oe),jt=k(),we=k(jt),Kt=k(),$t=k(),Js=k(),li=k(Js),tn=k(),M={comment:Qi,lineComment:k(Qi),blockComment:k(Qi),docComment:k(Qi),name:re,variableName:k(re),typeName:Jo,tagName:k(Jo),propertyName:Yo,attributeName:k(Yo),className:k(re),labelName:k(re),namespace:k(re),macroName:k(re),literal:oe,string:Zi,docString:k(Zi),character:k(Zi),attributeValue:k(Zi),number:es,integer:k(es),float:k(es),bool:k(oe),regexp:k(oe),escape:k(oe),color:k(oe),url:k(oe),keyword:Kt,self:k(Kt),null:k(Kt),atom:k(Kt),unit:k(Kt),modifier:k(Kt),operatorKeyword:k(Kt),controlKeyword:k(Kt),definitionKeyword:k(Kt),moduleKeyword:k(Kt),operator:$t,derefOperator:k($t),arithmeticOperator:k($t),logicOperator:k($t),bitwiseOperator:k($t),compareOperator:k($t),updateOperator:k($t),definitionOperator:k($t),typeOperator:k($t),controlOperator:k($t),punctuation:Js,separator:k(Js),bracket:li,angleBracket:k(li),squareBracket:k(li),paren:k(li),brace:k(li),content:jt,heading:we,heading1:k(we),heading2:k(we),heading3:k(we),heading4:k(we),heading5:k(we),heading6:k(we),contentSeparator:k(jt),list:k(jt),quote:k(jt),emphasis:k(jt),strong:k(jt),link:k(jt),monospace:k(jt),strikethrough:k(jt),inserted:k(),deleted:k(),changed:k(),invalid:k(),meta:tn,documentMeta:k(tn),annotation:k(tn),processingInstruction:k(tn),definition:Ut.defineModifier(),constant:Ut.defineModifier(),function:Ut.defineModifier(),standard:Ut.defineModifier(),local:Ut.defineModifier(),special:Ut.defineModifier()};th([{tag:M.link,class:"tok-link"},{tag:M.heading,class:"tok-heading"},{tag:M.emphasis,class:"tok-emphasis"},{tag:M.strong,class:"tok-strong"},{tag:M.keyword,class:"tok-keyword"},{tag:M.atom,class:"tok-atom"},{tag:M.bool,class:"tok-bool"},{tag:M.url,class:"tok-url"},{tag:M.labelName,class:"tok-labelName"},{tag:M.inserted,class:"tok-inserted"},{tag:M.deleted,class:"tok-deleted"},{tag:M.literal,class:"tok-literal"},{tag:M.string,class:"tok-string"},{tag:M.number,class:"tok-number"},{tag:[M.regexp,M.escape,M.special(M.string)],class:"tok-string2"},{tag:M.variableName,class:"tok-variableName"},{tag:M.local(M.variableName),class:"tok-variableName tok-local"},{tag:M.definition(M.variableName),class:"tok-variableName tok-definition"},{tag:M.special(M.variableName),class:"tok-variableName2"},{tag:M.definition(M.propertyName),class:"tok-propertyName tok-definition"},{tag:M.typeName,class:"tok-typeName"},{tag:M.namespace,class:"tok-namespace"},{tag:M.className,class:"tok-className"},{tag:M.macroName,class:"tok-macroName"},{tag:M.propertyName,class:"tok-propertyName"},{tag:M.operator,class:"tok-operator"},{tag:M.comment,class:"tok-comment"},{tag:M.meta,class:"tok-meta"},{tag:M.invalid,class:"tok-invalid"},{tag:M.punctuation,class:"tok-punctuation"}]);var is;const Ce=new L;function eh(n){return T.define({combine:n?t=>t.concat(n):void 0})}const cd=new L;class Lt{constructor(t,e,i=[],s=""){this.data=t,this.name=s,H.prototype.hasOwnProperty("tree")||Object.defineProperty(H.prototype,"tree",{get(){return yt(this)}}),this.parser=e,this.extension=[Qe.of(this),H.languageData.of((r,o,l)=>{let a=Xo(r,o,l),h=a.type.prop(Ce);if(!h)return[];let c=r.facet(h),f=a.type.prop(cd);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(t,e,i=-1){return Xo(t,e,i).type.prop(Ce)==this.data}findRegions(t){let e=t.facet(Qe);if((e==null?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(Ce)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(L.mounted);if(l){if(l.tree.prop(Ce)==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 j&&s(h,r.positions[a]+o)}};return s(yt(t),0),i}get allowsNesting(){return!0}}Lt.setState=F.define();function Xo(n,t,e){let i=n.facet(Qe),s=yt(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(t,e,Y.ExcludeBuffers))r.type.isTop&&(s=r);return s}class Ys extends Lt{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=eh(t.languageData);return new Ys(e,t.parser.configure({props:[Ce.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new Ys(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function yt(n){let t=n.field(Lt.state,!1);return t?t.tree:j.empty}class fd{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let ai=null;class Xe{constructor(t,e,i=[],s,r,o,l,a){this.parser=t,this.state=e,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(t,e,i){return new Xe(t,e,[],j.empty,0,i,[],null)}startParse(){return this.parser.startParse(new fd(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=j.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let s=Date.now()+t;t=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(ee.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<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(ee.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=ai;ai=this;try{return t()}finally{ai=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=_o(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let a=[];if(t.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=ee.applyChanges(i,a),s=j.empty,r=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=t.mapPos(h.from,1),f=t.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new Xe(this.parser,e,i,s,r,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<t.to&&r>t.from&&(this.fragments=_o(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Qa{createParse(e,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=ai;if(a){for(let h of s)a.tempSkipped.push(h);t&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,t]):t)}return this.parsedPos=o,new j(mt.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return ai}}function _o(n,t,e){return ee.applyChanges(n,[{fromA:t,toA:e,fromB:t,toB:e}])}class _e{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new _e(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=Xe.create(t.facet(Qe).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new _e(i)}}Lt.state=bt.define({create:_e.init,update(n,t){for(let e of t.effects)if(e.is(Lt.setState))return e.value;return t.startState.facet(Qe)!=t.state.facet(Qe)?_e.init(t.state):n.apply(t)}});let ih=n=>{let t=setTimeout(()=>n(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(ih=n=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(n,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const ns=typeof navigator<"u"&&(!((is=navigator.scheduling)===null||is===void 0)&&is.isInputPending)?()=>navigator.scheduling.isInputPending():null,ud=ut.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Lt.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Lt.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=ih(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(Lt.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!ns?Math.max(25,t.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>ns&&ns()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-e,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Lt.setState.of(new _e(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>Dt(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Qe=T.define({combine(n){return n.length?n[0]:null},enables:n=>[Lt.state,ud,O.contentAttributes.compute([n],t=>{let e=t.facet(n);return e&&e.name?{"data-language":e.name}:{}})]});class vm{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const nh=T.define(),Fn=T.define({combine:n=>{if(!n.length)return" ";let t=n[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return t}});function Re(n){let t=n.facet(Fn);return t.charCodeAt(0)==9?n.tabSize*t.length:t.length}function Cn(n,t){let e="",i=n.tabSize,s=n.facet(Fn)[0];if(s==" "){for(;t>=i;)e+=" ",t-=i;s=" "}for(let r=0;r<t;r++)e+=s;return e}function sh(n,t){n instanceof H&&(n=new Vn(n));for(let i of n.state.facet(nh)){let s=i(n,t);if(s!==void 0)return s}let e=yt(n.state);return e.length>=t?pd(n,e,t):null}class Vn{constructor(t,e={}){this.state=t,this.options=e,this.unit=Re(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==t?{text:"",from:t}:(e<0?s<t:s<=t)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(t,e);return i.slice(t-s,Math.min(i.length,t+100-s))}column(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.countColumn(i,t-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return ti(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:s}=this.lineAt(t,e),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 dd=new L;function pd(n,t,e){let i=t.resolveStack(e),s=i.node.enterUnfinishedNodesBefore(e);if(s!=i.node){let r=[];for(let o=s;o!=i.node;o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return rh(i,n,e)}function rh(n,t,e){for(let i=n;i;i=i.next){let s=md(i.node);if(s)return s(vr.create(t,e,i))}return 0}function gd(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function md(n){let t=n.type.prop(dd);if(t)return t;let e=n.firstChild,i;if(e&&(i=e.type.prop(L.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>oh(o,!0,1,void 0,r&&!gd(o)?s.from:void 0)}return n.parent==null?yd:null}function yd(){return 0}class vr extends Vn{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new vr(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(bd(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return rh(this.context.next,this.base,this.pos)}}function bd(n,t){for(let e=t;e;e=e.parent)if(n==e)return!0;return!1}function xd(n){let t=n.node,e=t.childAfter(t.from),i=t.lastChild;if(!e)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(e.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=e.to;;){let a=t.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.from<o?e:null;l=a.to}}function km({closing:n,align:t=!0,units:e=1}){return i=>oh(i,t,e,n)}function oh(n,t,e,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=t?xd(n):null;return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*e)}const Cm=n=>n.baseIndent;function Am({except:n,units:t=1}={}){return e=>{let i=n&&n.test(e.textAfter);return e.baseIndent+(i?0:t*e.unit)}}const Mm=new L;function Dm(n){let t=n.firstChild,e=n.lastChild;return t&&t.to<e.from?{from:t.to,to:e.type.isError?n.to:e.from}:null}class Wn{constructor(t,e){this.specs=t;let i;function s(l){let a=de.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof e.all=="string"?e.all:e.all?s(e.all):void 0,o=e.scope;this.scope=o instanceof Lt?l=>l.prop(Ce)==o.data:o?l=>l==o:void 0,this.style=th(t.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new de(i):null,this.themeType=e.themeType}static define(t,e){return new Wn(t,e||{})}}const Xs=T.define(),lh=T.define({combine(n){return n.length?[n[0]]:null}});function ss(n){let t=n.facet(Xs);return t.length?t:n.facet(lh)}function Om(n,t){let e=[Sd],i;return n instanceof Wn&&(n.module&&e.push(O.styleModule.of(n.module)),i=n.themeType),t!=null&&t.fallback?e.push(lh.of(n)):i?e.push(Xs.computeN([O.darkTheme],s=>s.facet(O.darkTheme)==(i=="dark")?[n]:[])):e.push(Xs.of(n)),e}class wd{constructor(t){this.markCache=Object.create(null),this.tree=yt(t.state),this.decorations=this.buildDeco(t,ss(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=yt(t.state),i=ss(t.state),s=i!=ss(t.startState),{viewport:r}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!s&&e.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return P.none;let i=new De;for(let{from:s,to:r}of t.visibleRanges)ld(this.tree,e,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=P.mark({class:a})))},s,r);return i.finish()}}const Sd=ye.high(ut.fromClass(wd,{decorations:n=>n.decorations})),Tm=Wn.define([{tag:M.meta,color:"#404740"},{tag:M.link,textDecoration:"underline"},{tag:M.heading,textDecoration:"underline",fontWeight:"bold"},{tag:M.emphasis,fontStyle:"italic"},{tag:M.strong,fontWeight:"bold"},{tag:M.strikethrough,textDecoration:"line-through"},{tag:M.keyword,color:"#708"},{tag:[M.atom,M.bool,M.url,M.contentSeparator,M.labelName],color:"#219"},{tag:[M.literal,M.inserted],color:"#164"},{tag:[M.string,M.deleted],color:"#a11"},{tag:[M.regexp,M.escape,M.special(M.string)],color:"#e40"},{tag:M.definition(M.variableName),color:"#00f"},{tag:M.local(M.variableName),color:"#30a"},{tag:[M.typeName,M.namespace],color:"#085"},{tag:M.className,color:"#167"},{tag:[M.special(M.variableName),M.macroName],color:"#256"},{tag:M.definition(M.propertyName),color:"#00c"},{tag:M.comment,color:"#940"},{tag:M.invalid,color:"#f00"}]),vd=O.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),ah=1e4,hh="()[]{}",ch=T.define({combine(n){return Le(n,{afterCursor:!0,brackets:hh,maxScanDistance:ah,renderMatch:Ad})}}),kd=P.mark({class:"cm-matchingBracket"}),Cd=P.mark({class:"cm-nonmatchingBracket"});function Ad(n){let t=[],e=n.matched?kd:Cd;return t.push(e.range(n.start.from,n.start.to)),n.end&&t.push(e.range(n.end.from,n.end.to)),t}const Md=bt.define({create(){return P.none},update(n,t){if(!t.docChanged&&!t.selection)return n;let e=[],i=t.state.facet(ch);for(let s of t.state.selection.ranges){if(!s.empty)continue;let r=Xt(t.state,s.head,-1,i)||s.head>0&&Xt(t.state,s.head-1,1,i)||i.afterCursor&&(Xt(t.state,s.head,1,i)||s.head<t.state.doc.length&&Xt(t.state,s.head+1,-1,i));r&&(e=e.concat(i.renderMatch(r,t.state)))}return P.set(e,!0)},provide:n=>O.decorations.from(n)}),Dd=[Md,vd];function Pm(n={}){return[ch.of(n),Dd]}const Od=new L;function _s(n,t,e){let i=n.prop(t<0?L.openedBy:L.closedBy);if(i)return i;if(n.name.length==1){let s=e.indexOf(n.name);if(s>-1&&s%2==(t<0?1:0))return[e[s+t]]}return null}function Qs(n){let t=n.type.prop(Od);return t?t(n.node):n}function Xt(n,t,e,i={}){let s=i.maxScanDistance||ah,r=i.brackets||hh,o=yt(n),l=o.resolveInner(t,e);for(let a=l;a;a=a.parent){let h=_s(a.type,e,r);if(h&&a.from<a.to){let c=Qs(a);if(c&&(e>0?t>=c.from&&t<c.to:t>c.from&&t<=c.to))return Td(n,t,e,a,c,h,r)}}return Pd(n,t,e,o,l.type,s,r)}function Td(n,t,e,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&&(e<0?c.childBefore(i.from):c.childAfter(i.to)))do if(e<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let f=Qs(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(_s(c.type,e,o))h++;else if(_s(c.type,-e,o)){if(h==0){let f=Qs(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(e<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function Pd(n,t,e,i,s,r,o){let l=e<0?n.sliceDoc(t-1,t):n.sliceDoc(t,t+1),a=o.indexOf(l);if(a<0||a%2==0!=e>0)return null;let h={from:e<0?t-1:t,to:e>0?t+1:t},c=n.doc.iterRange(t,e>0?n.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=r;){let d=c.value;e<0&&(u+=d.length);let p=t+u*e;for(let g=e>0?0:d.length-1,m=e>0?d.length:-1;g!=m;g+=e){let y=o.indexOf(d[g]);if(!(y<0||i.resolveInner(p+g,1).type!=s))if(y%2==0==e>0)f++;else{if(f==1)return{start:h,end:{from:p+g,to:p+g+1},matched:y>>1==a>>1};f--}}e>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}function Qo(n,t,e,i=0,s=0){t==null&&(t=n.search(/[^\s\u00a0]/),t==-1&&(t=n.length));let r=s;for(let o=i;o<t;o++)n.charCodeAt(o)==9?r+=e-r%e:r++;return r}class fh{constructor(t,e,i,s){this.string=t,this.tabSize=e,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(t){let e=this.string.charAt(this.pos),i;if(typeof t=="string"?i=e==t:i=e&&(t instanceof RegExp?t.test(e):t(e)),i)return++this.pos,e}eatWhile(t){let e=this.pos;for(;this.eat(t););return this.pos>e}eatSpace(){let t=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>t}skipToEnd(){this.pos=this.string.length}skipTo(t){let e=this.string.indexOf(t,this.pos);if(e>-1)return this.pos=e,!0}backUp(t){this.pos-=t}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=Qo(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var t;return(t=this.overrideIndent)!==null&&t!==void 0?t:Qo(this.string,null,this.tabSize)}match(t,e,i){if(typeof t=="string"){let s=o=>i?o.toLowerCase():o,r=this.string.substr(this.pos,t.length);return s(r)==s(t)?(e!==!1&&(this.pos+=t.length),!0):null}else{let s=this.string.slice(this.pos).match(t);return s&&s.index>0?null:(s&&e!==!1&&(this.pos+=s[0].length),s)}}current(){return this.string.slice(this.start,this.pos)}}function Bd(n){return{name:n.name||"",token:n.token,blankLine:n.blankLine||(()=>{}),startState:n.startState||(()=>!0),copyState:n.copyState||Rd,indent:n.indent||(()=>null),languageData:n.languageData||{},tokenTable:n.tokenTable||Cr}}function Rd(n){if(typeof n!="object")return n;let t={};for(let e in n){let i=n[e];t[e]=i instanceof Array?i.slice():i}return t}const Zo=new WeakMap;class uh extends Lt{constructor(t){let e=eh(t.languageData),i=Bd(t),s,r=new class extends Qa{createParse(o,l,a){return new Ed(s,o,l,a)}};super(e,r,[nh.of((o,l)=>this.getIndent(o,l))],t.name),this.topNode=Fd(e),s=this,this.streamParser=i,this.stateAfter=new L({perNode:!0}),this.tokenTable=t.tokenTable?new mh(i.tokenTable):Nd}static define(t){return new uh(t)}getIndent(t,e){let i=yt(t.state),s=i.resolve(e);for(;s&&s.type!=this.topNode;)s=s.parent;if(!s)return null;let r,{overrideIndentation:o}=t.options;o&&(r=Zo.get(t.state),r!=null&&r<e-1e4&&(r=void 0));let l=kr(this,i,0,s.from,r??e),a,h;if(l?(h=l.state,a=l.pos+1):(h=this.streamParser.startState(t.unit),a=0),e-a>1e4)return null;for(;a<e;){let f=t.state.doc.lineAt(a),u=Math.min(e,f.to);if(f.length){let d=o?o(f.from):-1,p=new fh(f.text,t.state.tabSize,t.unit,d<0?void 0:d);for(;p.pos<u-f.from;)ph(this.streamParser.token,p,h)}else this.streamParser.blankLine(h,t.unit);if(u==e)break;a=f.to+1}let c=t.lineAt(e);return o&&r==null&&Zo.set(t.state,c.from),this.streamParser.indent(h,/^\s*(.*)/.exec(c.text)[1],t)}get allowsNesting(){return!1}}function kr(n,t,e,i,s){let r=e>=i&&e+t.length<=s&&t.prop(n.stateAfter);if(r)return{state:n.streamParser.copyState(r),pos:e+t.length};for(let o=t.children.length-1;o>=0;o--){let l=t.children[o],a=e+t.positions[o],h=l instanceof j&&a<s&&kr(n,l,a,i,s);if(h)return h}return null}function dh(n,t,e,i,s){if(s&&e<=0&&i>=t.length)return t;!s&&t.type==n.topNode&&(s=!0);for(let r=t.children.length-1;r>=0;r--){let o=t.positions[r],l=t.children[r],a;if(o<i&&l instanceof j){if(!(a=dh(n,l,e-o,i-o,s)))break;return s?new j(t.type,t.children.slice(0,r).concat(a),t.positions.slice(0,r+1),o+a.length):a}}return null}function Ld(n,t,e,i){for(let s of t){let r=s.from+(s.openStart?25:0),o=s.to-(s.openEnd?25:0),l=r<=e&&o>e&&kr(n,s.tree,0-s.offset,e,o),a;if(l&&(a=dh(n,s.tree,e+s.offset,l.pos+s.offset,!1)))return{state:l.state,tree:a}}return{state:n.streamParser.startState(i?Re(i):4),tree:j.empty}}class Ed{constructor(t,e,i,s){this.lang=t,this.input=e,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=Xe.get(),o=s[0].from,{state:l,tree:a}=Ld(t,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(Re(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let t=Xe.get(),e=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(e,this.chunkStart+2048);for(t&&(i=Math.min(i,t.viewport.to));this.parsedPos<i;)this.parseLine(t);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=e?this.finish():t&&this.parsedPos>=t.viewport.to?(t.skipUntilInView(this.parsedPos,e),this.finish()):null}stopAt(t){this.stoppedAt=t}lineAfter(t){let e=this.input.chunk(t);if(this.input.lineChunks)e==`
`&&(e="");else{let i=e.indexOf(`
`);i>-1&&(e=e.slice(0,i))}return t+e.length<=this.to?e:e.slice(0,this.to-t)}nextLine(){let t=this.parsedPos,e=this.lineAfter(t),i=t+e.length;for(let s=this.rangeIndex;;){let r=this.ranges[s].to;if(r>=i||(e=e.slice(0,r-(i-e.length)),s++,s==this.ranges.length))break;let o=this.ranges[s].from,l=this.lineAfter(o);e+=l,i=o+l.length}return{line:e,end:i}}skipGapsTo(t,e,i){for(;;){let s=this.ranges[this.rangeIndex].to,r=t+e;if(i>0?s>r:s>=r)break;let o=this.ranges[++this.rangeIndex].from;e+=o-s}return e}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(t,e,i,s,r){if(this.ranges.length>1){r=this.skipGapsTo(e,r,1),e+=r;let o=this.chunk.length;r=this.skipGapsTo(i,r,-1),i+=r,s+=this.chunk.length-o}return this.chunk.push(t,e,i,s),r}parseLine(t){let{line:e,end:i}=this.nextLine(),s=0,{streamParser:r}=this.lang,o=new fh(e,t?t.state.tabSize:4,t?Re(t.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=ph(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 t=j.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Id,topID:0,maxBufferLength:2048,reused:this.chunkReused});t=new j(t.type,t.children,t.positions,t.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(t),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new j(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function ph(n,t,e){t.start=t.pos;for(let i=0;i<10;i++){let s=n(t,e);if(t.pos>t.start)return s}throw new Error("Stream parser failed to advance stream.")}const Cr=Object.create(null),Di=[mt.none],Id=new br(Di),tl=[],el=Object.create(null),gh=Object.create(null);for(let[n,t]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"]])gh[n]=yh(Cr,t);class mh{constructor(t){this.extra=t,this.table=Object.assign(Object.create(null),gh)}resolve(t){return t?this.table[t]||(this.table[t]=yh(this.extra,t)):0}}const Nd=new mh(Cr);function rs(n,t){tl.indexOf(n)>-1||(tl.push(n),console.warn(t))}function yh(n,t){let e=[];for(let l of t.split(" ")){let a=[];for(let h of l.split(".")){let c=n[h]||M[h];c?typeof c=="function"?a.length?a=a.map(c):rs(h,`Modifier ${h} used at start of tag`):a.length?rs(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:rs(h,`Unknown highlighting tag ${h}`)}for(let h of a)e.push(h)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),s=i+" "+e.map(l=>l.id),r=el[s];if(r)return r.id;let o=el[s]=mt.define({id:Di.length,name:i,props:[rd({[i]:e})]});return Di.push(o),o.id}function Fd(n){let t=mt.define({id:Di.length,name:"Document",props:[Ce.add(()=>n)],top:!0});return Di.push(t),t}X.RTL,X.LTR;const Vd=n=>{let{state:t}=n,e=t.doc.lineAt(t.selection.main.from),i=Mr(n.state,e.from);return i.line?Wd(n):i.block?zd(n):!1};function Ar(n,t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let s=n(t,e);return s?(i(e.update(s)),!0):!1}}const Wd=Ar($d,0),Hd=Ar(bh,0),zd=Ar((n,t)=>bh(n,t,Kd(t)),0);function Mr(n,t){let e=n.languageDataAt("commentTokens",t);return e.length?e[0]:{}}const hi=50;function qd(n,{open:t,close:e},i,s){let r=n.sliceDoc(i-hi,i),o=n.sliceDoc(s,s+hi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-t.length,h)==t&&o.slice(a,a+e.length)==e)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let c,f;s-i<=2*hi?c=f=n.sliceDoc(i,s):(c=n.sliceDoc(i,i+hi),f=n.sliceDoc(s-hi,s));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-e.length;return c.slice(u,u+t.length)==t&&f.slice(p,p+e.length)==e?{open:{pos:i+u+t.length,margin:/\s/.test(c.charAt(u+t.length))?1:0},close:{pos:s-d-e.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function Kd(n){let t=[];for(let e of n.selection.ranges){let i=n.doc.lineAt(e.from),s=e.to<=i.to?i:n.doc.lineAt(e.to),r=t.length-1;r>=0&&t[r].to>i.from?t[r].to=s.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return t}function bh(n,t,e=t.selection.ranges){let i=e.map(r=>Mr(t,r.from).block);if(!i.every(r=>r))return null;let s=e.map((r,o)=>qd(t,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:t.changes(e.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 $d(n,t,e=t.selection.ranges){let i=[],s=-1;for(let{from:r,to:o}of e){let l=i.length,a=1e9,h=Mr(t,r).line;if(h){for(let c=r;c<=o;){let f=t.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=t.changes(r);return{changes:o,selection:t.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 Zs=se.define(),jd=se.define(),Ud=T.define(),xh=T.define({combine(n){return Le(n,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,s)=>t(i,s)||e(i,s)})}}),wh=bt.define({create(){return _t.empty},update(n,t){let e=t.state.facet(xh),i=t.annotation(Zs);if(i){let a=kt.fromTransaction(t,i.selection),h=i.side,c=h==0?n.undone:n.done;return a?c=An(c,c.length,e.minDepth,a):c=kh(c,t.startState.selection),new _t(h==0?i.rest:c,h==0?c:i.rest)}let s=t.annotation(jd);if((s=="full"||s=="before")&&(n=n.isolate()),t.annotation(Q.addToHistory)===!1)return t.changes.empty?n:n.addMapping(t.changes.desc);let r=kt.fromTransaction(t),o=t.annotation(Q.time),l=t.annotation(Q.userEvent);return r?n=n.addChanges(r,o,l,e,t):t.selection&&(n=n.addSelection(t.startState.selection,o,l,e.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(t=>t.toJSON()),undone:n.undone.map(t=>t.toJSON())}},fromJSON(n){return new _t(n.done.map(kt.fromJSON),n.undone.map(kt.fromJSON))}});function Bm(n={}){return[wh,xh.of(n),O.domEventHandlers({beforeinput(t,e){let i=t.inputType=="historyUndo"?Sh:t.inputType=="historyRedo"?tr:null;return i?(t.preventDefault(),i(e)):!1}})]}function Hn(n,t){return function({state:e,dispatch:i}){if(!t&&e.readOnly)return!1;let s=e.field(wh,!1);if(!s)return!1;let r=s.pop(n,e,t);return r?(i(r),!0):!1}}const Sh=Hn(0,!1),tr=Hn(1,!1),Gd=Hn(0,!0),Jd=Hn(1,!0);class kt{constructor(t,e,i,s,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(t){return new kt(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(e=this.mapped)===null||e===void 0?void 0:e.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(t){return new kt(t.changes&&et.fromJSON(t.changes),[],t.mapped&&Qt.fromJSON(t.mapped),t.startSelection&&b.fromJSON(t.startSelection),t.selectionsAfter.map(b.fromJSON))}static fromTransaction(t,e){let i=Et;for(let s of t.startState.facet(Ud)){let r=s(t);r.length&&(i=i.concat(r))}return!i.length&&t.changes.empty?null:new kt(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Et)}static selection(t){return new kt(void 0,Et,void 0,void 0,t)}}function An(n,t,e,i){let s=t+1>e+20?t-e-1:0,r=n.slice(s,t);return r.push(i),r}function Yd(n,t){let e=[],i=!1;return n.iterChangedRanges((s,r)=>e.push(s,r)),t.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<e.length;){let h=e[a++],c=e[a++];l>=h&&o<=c&&(i=!0)}}),i}function Xd(n,t){return n.ranges.length==t.ranges.length&&n.ranges.filter((e,i)=>e.empty!=t.ranges[i].empty).length===0}function vh(n,t){return n.length?t.length?n.concat(t):n:t}const Et=[],_d=200;function kh(n,t){if(n.length){let e=n[n.length-1],i=e.selectionsAfter.slice(Math.max(0,e.selectionsAfter.length-_d));return i.length&&i[i.length-1].eq(t)?n:(i.push(t),An(n,n.length-1,1e9,e.setSelAfter(i)))}else return[kt.selection([t])]}function Qd(n){let t=n[n.length-1],e=n.slice();return e[n.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),e}function os(n,t){if(!n.length)return n;let e=n.length,i=Et;for(;e;){let s=Zd(n[e-1],t,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,e);return r[e-1]=s,r}else t=s.mapped,e--,i=s.selectionsAfter}return i.length?[kt.selection(i)]:Et}function Zd(n,t,e){let i=vh(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(t)):Et,e);if(!n.changes)return kt.selection(i);let s=n.changes.map(t),r=t.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new kt(s,F.mapEffects(n.effects,t),o,n.startSelection.map(r),i)}const tp=/^(input\.type|delete)($|\.)/;class _t{constructor(t,e,i=0,s=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new _t(this.done,this.undone):this}addChanges(t,e,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!i||tp.test(i))&&(!l.selectionsAfter.length&&e-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,Yd(l.changes,t.changes))||i=="input.type.compose")?o=An(o,o.length-1,s.minDepth,new kt(t.changes.compose(l.changes),vh(t.effects,l.effects),l.mapped,l.startSelection,Et)):o=An(o,o.length,s.minDepth,t),new _t(o,Et,e,i)}addSelection(t,e,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Et;return r.length>0&&e-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Xd(r[r.length-1],t)?this:new _t(kh(this.done,t),this.undone,e,i)}addMapping(t){return new _t(os(this.done,t),os(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let s=t==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],o=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Zs.of({side:t,rest:Qd(s),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=s.length==1?Et:s.slice(0,s.length-1);return r.mapped&&(l=os(l,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Zs.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}_t.empty=new _t(Et,Et);const Rm=[{key:"Mod-z",run:Sh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:tr,preventDefault:!0},{linux:"Ctrl-Shift-z",run:tr,preventDefault:!0},{key:"Mod-u",run:Gd,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Jd,preventDefault:!0}];function ei(n,t){return b.create(n.ranges.map(t),n.mainIndex)}function Zt(n,t){return n.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function Ht({state:n,dispatch:t},e){let i=ei(n.selection,e);return i.eq(n.selection,!0)?!1:(t(Zt(n,i)),!0)}function zn(n,t){return b.cursor(t?n.to:n.from)}function Ch(n,t){return Ht(n,e=>e.empty?n.moveByChar(e,t):zn(e,t))}function dt(n){return n.textDirectionAt(n.state.selection.main.head)==X.LTR}const Ah=n=>Ch(n,!dt(n)),Mh=n=>Ch(n,dt(n));function Dh(n,t){return Ht(n,e=>e.empty?n.moveByGroup(e,t):zn(e,t))}const ep=n=>Dh(n,!dt(n)),ip=n=>Dh(n,dt(n));function np(n,t,e){if(t.type.prop(e))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(t.from,t.to)))||t.firstChild}function qn(n,t,e){let i=yt(n).resolveInner(t.head),s=e?L.closedBy:L.openedBy;for(let a=t.head;;){let h=e?i.childAfter(a):i.childBefore(a);if(!h)break;np(n,h,s)?i=h:a=e?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=e?Xt(n,i.from,1):Xt(n,i.to,-1))&&o.matched?l=e?o.end.to:o.end.from:l=e?i.to:i.from,b.cursor(l,e?-1:1)}const sp=n=>Ht(n,t=>qn(n.state,t,!dt(n))),rp=n=>Ht(n,t=>qn(n.state,t,dt(n)));function Oh(n,t){return Ht(n,e=>{if(!e.empty)return zn(e,t);let i=n.moveVertically(e,t);return i.head!=e.head?i:n.moveToLineBoundary(e,t)})}const Th=n=>Oh(n,!1),Ph=n=>Oh(n,!0);function Bh(n){let t=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,e=0,i=0,s;if(t){for(let r of n.state.facet(O.scrollMargins)){let o=r(n);o!=null&&o.top&&(e=Math.max(o==null?void 0:o.top,e)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}s=n.scrollDOM.clientHeight-e-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:e,marginBottom:i,selfScroll:t,height:Math.max(n.defaultLineHeight,s-5)}}function Rh(n,t){let e=Bh(n),{state:i}=n,s=ei(i.selection,o=>o.empty?n.moveVertically(o,t,e.height):zn(o,t));if(s.eq(i.selection))return!1;let r;if(e.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+e.marginTop,h=l.bottom-e.marginBottom;o&&o.top>a&&o.bottom<h&&(r=O.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Zt(i,s),{effects:r}),!0}const il=n=>Rh(n,!1),er=n=>Rh(n,!0);function be(n,t,e){let i=n.lineBlockAt(t.head),s=n.moveToLineBoundary(t,e);if(s.head==t.head&&s.head!=(e?i.to:i.from)&&(s=n.moveToLineBoundary(t,e,!1)),!e&&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&&t.head!=i.from+r&&(s=b.cursor(i.from+r))}return s}const op=n=>Ht(n,t=>be(n,t,!0)),lp=n=>Ht(n,t=>be(n,t,!1)),ap=n=>Ht(n,t=>be(n,t,!dt(n))),hp=n=>Ht(n,t=>be(n,t,dt(n))),cp=n=>Ht(n,t=>b.cursor(n.lineBlockAt(t.head).from,1)),fp=n=>Ht(n,t=>b.cursor(n.lineBlockAt(t.head).to,-1));function up(n,t,e){let i=!1,s=ei(n.selection,r=>{let o=Xt(n,r.head,-1)||Xt(n,r.head,1)||r.head>0&&Xt(n,r.head-1,1)||r.head<n.doc.length&&Xt(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 b.cursor(l)});return i?(t(Zt(n,s)),!0):!1}const dp=({state:n,dispatch:t})=>up(n,t);function Ft(n,t){let e=ei(n.state.selection,i=>{let s=t(i);return b.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0)});return e.eq(n.state.selection)?!1:(n.dispatch(Zt(n.state,e)),!0)}function Lh(n,t){return Ft(n,e=>n.moveByChar(e,t))}const Eh=n=>Lh(n,!dt(n)),Ih=n=>Lh(n,dt(n));function Nh(n,t){return Ft(n,e=>n.moveByGroup(e,t))}const pp=n=>Nh(n,!dt(n)),gp=n=>Nh(n,dt(n)),mp=n=>Ft(n,t=>qn(n.state,t,!dt(n))),yp=n=>Ft(n,t=>qn(n.state,t,dt(n)));function Fh(n,t){return Ft(n,e=>n.moveVertically(e,t))}const Vh=n=>Fh(n,!1),Wh=n=>Fh(n,!0);function Hh(n,t){return Ft(n,e=>n.moveVertically(e,t,Bh(n).height))}const nl=n=>Hh(n,!1),sl=n=>Hh(n,!0),bp=n=>Ft(n,t=>be(n,t,!0)),xp=n=>Ft(n,t=>be(n,t,!1)),wp=n=>Ft(n,t=>be(n,t,!dt(n))),Sp=n=>Ft(n,t=>be(n,t,dt(n))),vp=n=>Ft(n,t=>b.cursor(n.lineBlockAt(t.head).from)),kp=n=>Ft(n,t=>b.cursor(n.lineBlockAt(t.head).to)),rl=({state:n,dispatch:t})=>(t(Zt(n,{anchor:0})),!0),ol=({state:n,dispatch:t})=>(t(Zt(n,{anchor:n.doc.length})),!0),ll=({state:n,dispatch:t})=>(t(Zt(n,{anchor:n.selection.main.anchor,head:0})),!0),al=({state:n,dispatch:t})=>(t(Zt(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),Cp=({state:n,dispatch:t})=>(t(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),Ap=({state:n,dispatch:t})=>{let e=Kn(n).map(({from:i,to:s})=>b.range(i,Math.min(s+1,n.doc.length)));return t(n.update({selection:b.create(e),userEvent:"select"})),!0},Mp=({state:n,dispatch:t})=>{let e=ei(n.selection,i=>{var s;let r=yt(n).resolveStack(i.from,1);for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&(!((s=l.parent)===null||s===void 0)&&s.parent))return b.range(l.to,l.from)}return i});return t(Zt(n,e)),!0},Dp=({state:n,dispatch:t})=>{let e=n.selection,i=null;return e.ranges.length>1?i=b.create([e.main]):e.main.empty||(i=b.create([b.cursor(e.main.head)])),i?(t(Zt(n,i)),!0):!1};function Ii(n,t){if(n.state.readOnly)return!1;let e="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=t(r);a<o?(e="delete.backward",a=en(n,a,!1)):a>o&&(e="delete.forward",a=en(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=en(n,o,!1),l=en(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o,o<r.head?-1:1)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:e,effects:e=="delete.selection"?O.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function en(n,t,e){if(n instanceof O)for(let i of n.state.facet(O.atomicRanges).map(s=>s(n)))i.between(t,t,(s,r)=>{s<t&&r>t&&(t=e?r:s)});return t}const zh=(n,t,e)=>Ii(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(e&&!t&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let h=ti(l,r.tabSize),c=h%Re(r)||Re(r);for(let f=0;f<c&&l[l.length-1-f]==" ";f++)s--;a=s}else a=ot(o.text,s-o.from,t,t)+o.from,a==s&&o.number!=(t?r.doc.lines:1)?a+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,s-o.from))&&(a=ot(o.text,a-o.from,!1,!1)+o.from);return a}),ir=n=>zh(n,!1,!0),qh=n=>zh(n,!0,!1),Kh=(n,t)=>Ii(n,e=>{let i=e.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(t?r.to:r.from)){i==e.head&&r.number!=(t?s.doc.lines:1)&&(i+=t?1:-1);break}let a=ot(r.text,i-r.from,t)+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!=e.head)&&(l=c),i=a}return i}),$h=n=>Kh(n,!1),Op=n=>Kh(n,!0),Tp=n=>Ii(n,t=>{let e=n.lineBlockAt(t.head).to;return t.head<e?e:Math.min(n.state.doc.length,t.head+1)}),Pp=n=>Ii(n,t=>{let e=n.moveToLineBoundary(t,!1).head;return t.head>e?e:Math.max(0,t.head-1)}),Bp=n=>Ii(n,t=>{let e=n.moveToLineBoundary(t,!0).head;return t.head<e?e:Math.min(n.state.doc.length,t.head+1)}),Rp=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let e=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:V.of(["",""])},range:b.cursor(i.from)}));return t(n.update(e,{scrollIntoView:!0,userEvent:"input"})),!0},Lp=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let e=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:ot(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:ot(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 e.changes.empty?!1:(t(n.update(e,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Kn(n){let t=[],e=-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)),e>=s.number){let o=t[t.length-1];o.to=r.to,o.ranges.push(i)}else t.push({from:s.from,to:r.to,ranges:[i]});e=r.number+1}return t}function jh(n,t,e){if(n.readOnly)return!1;let i=[],s=[];for(let r of Kn(n)){if(e?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(e?r.to+1:r.from-1),l=o.length+1;if(e){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?(t(n.update({changes:i,scrollIntoView:!0,selection:b.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Ep=({state:n,dispatch:t})=>jh(n,t,!1),Ip=({state:n,dispatch:t})=>jh(n,t,!0);function Uh(n,t,e){if(n.readOnly)return!1;let i=[];for(let s of Kn(n))e?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 t(n.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Np=({state:n,dispatch:t})=>Uh(n,t,!1),Fp=({state:n,dispatch:t})=>Uh(n,t,!0),Vp=n=>{if(n.state.readOnly)return!1;let{state:t}=n,e=t.changes(Kn(t).map(({from:s,to:r})=>(s>0?s--:r<t.doc.length&&r++,{from:s,to:r}))),i=ei(t.selection,s=>{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(e);return n.dispatch({changes:e,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Wp(n,t){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(t-1,t+1)))return{from:t,to:t};let e=yt(n).resolveInner(t),i=e.childBefore(t),s=e.childAfter(t),r;return i&&s&&i.to<=t&&s.from>=t&&(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 Hp=Gh(!1),zp=Gh(!0);function Gh(n){return({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(s=>{let{from:r,to:o}=s,l=t.doc.lineAt(r),a=!n&&r==o&&Wp(t,r);n&&(r=o=(o<=l.to?l:t.doc.lineAt(o)).to);let h=new Vn(t,{simulateBreak:r,simulateDoubleBreak:!!a}),c=sh(h,r);for(c==null&&(c=ti(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.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=["",Cn(t,c)];return a&&f.push(Cn(t,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:V.of(f)},range:b.cursor(r+1+f[1].length)}});return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Dr(n,t){let e=-1;return n.changeByRange(i=>{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>e&&(i.empty||i.to>l.from)&&(t(l,s,i),e=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 qp=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let e=Object.create(null),i=new Vn(n,{overrideIndentation:r=>{let o=e[r];return o??-1}}),s=Dr(n,(r,o,l)=>{let a=sh(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=Cn(n,a);(h!=c||l.from<r.from+h.length)&&(e[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return s.changes.empty||t(n.update(s,{userEvent:"indent"})),!0},Jh=({state:n,dispatch:t})=>n.readOnly?!1:(t(n.update(Dr(n,(e,i)=>{i.push({from:e.from,insert:n.facet(Fn)})}),{userEvent:"input.indent"})),!0),Yh=({state:n,dispatch:t})=>n.readOnly?!1:(t(n.update(Dr(n,(e,i)=>{let s=/^\s*/.exec(e.text)[0];if(!s)return;let r=ti(s,n.tabSize),o=0,l=Cn(n,Math.max(0,r-Re(n)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:e.from+o,to:e.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Kp=n=>(n.setTabFocusMode(),!0),$p=[{key:"Ctrl-b",run:Ah,shift:Eh,preventDefault:!0},{key:"Ctrl-f",run:Mh,shift:Ih},{key:"Ctrl-p",run:Th,shift:Vh},{key:"Ctrl-n",run:Ph,shift:Wh},{key:"Ctrl-a",run:cp,shift:vp},{key:"Ctrl-e",run:fp,shift:kp},{key:"Ctrl-d",run:qh},{key:"Ctrl-h",run:ir},{key:"Ctrl-k",run:Tp},{key:"Ctrl-Alt-h",run:$h},{key:"Ctrl-o",run:Rp},{key:"Ctrl-t",run:Lp},{key:"Ctrl-v",run:er}],jp=[{key:"ArrowLeft",run:Ah,shift:Eh,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:ep,shift:pp,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:ap,shift:wp,preventDefault:!0},{key:"ArrowRight",run:Mh,shift:Ih,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:ip,shift:gp,preventDefault:!0},{mac:"Cmd-ArrowRight",run:hp,shift:Sp,preventDefault:!0},{key:"ArrowUp",run:Th,shift:Vh,preventDefault:!0},{mac:"Cmd-ArrowUp",run:rl,shift:ll},{mac:"Ctrl-ArrowUp",run:il,shift:nl},{key:"ArrowDown",run:Ph,shift:Wh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:ol,shift:al},{mac:"Ctrl-ArrowDown",run:er,shift:sl},{key:"PageUp",run:il,shift:nl},{key:"PageDown",run:er,shift:sl},{key:"Home",run:lp,shift:xp,preventDefault:!0},{key:"Mod-Home",run:rl,shift:ll},{key:"End",run:op,shift:bp,preventDefault:!0},{key:"Mod-End",run:ol,shift:al},{key:"Enter",run:Hp},{key:"Mod-a",run:Cp},{key:"Backspace",run:ir,shift:ir},{key:"Delete",run:qh},{key:"Mod-Backspace",mac:"Alt-Backspace",run:$h},{key:"Mod-Delete",mac:"Alt-Delete",run:Op},{mac:"Mod-Backspace",run:Pp},{mac:"Mod-Delete",run:Bp}].concat($p.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Lm=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:sp,shift:mp},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:rp,shift:yp},{key:"Alt-ArrowUp",run:Ep},{key:"Shift-Alt-ArrowUp",run:Np},{key:"Alt-ArrowDown",run:Ip},{key:"Shift-Alt-ArrowDown",run:Fp},{key:"Escape",run:Dp},{key:"Mod-Enter",run:zp},{key:"Alt-l",mac:"Ctrl-l",run:Ap},{key:"Mod-i",run:Mp,preventDefault:!0},{key:"Mod-[",run:Yh},{key:"Mod-]",run:Jh},{key:"Mod-Alt-\\",run:qp},{key:"Shift-Mod-k",run:Vp},{key:"Shift-Mod-\\",run:dp},{key:"Mod-/",run:Vd},{key:"Alt-A",run:Hd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Kp}].concat(jp),Em={key:"Tab",run:Jh,shift:Yh};function lt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var t=1,e=arguments[1];if(e&&typeof e=="object"&&e.nodeType==null&&!Array.isArray(e)){for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var s=e[i];typeof s=="string"?n.setAttribute(i,s):s!=null&&(n[i]=s)}t++}for(;t<arguments.length;t++)Xh(n,arguments[t]);return n}function Xh(n,t){if(typeof t=="string")n.appendChild(document.createTextNode(t));else if(t!=null)if(t.nodeType!=null)n.appendChild(t);else if(Array.isArray(t))for(var e=0;e<t.length;e++)Xh(n,t[e]);else throw new RangeError("Unsupported child node: "+t)}const hl=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class Ze{constructor(t,e,i=0,s=t.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r(hl(l)):hl,this.query=this.normalize(e)}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 nt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=or(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=Bt(t);let s=this.normalize(e);for(let r=0,o=i;;r++){let l=s.charCodeAt(r),a=this.match(l,o,this.bufferPos+this.bufferStart);if(r==s.length-1){if(a)return this.value=a,this;break}o==i&&r<e.length&&e.charCodeAt(r)==l&&o++}}}match(t,e,i){let s=null;for(let r=0;r<this.matches.length;r+=2){let o=this.matches[r],l=!1;this.query.charCodeAt(o)==t&&(o==this.query.length-1?s={from:this.matches[r+1],to:i}:(this.matches[r]++,l=!0)),l||(this.matches.splice(r,2),r-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?s={from:e,to:i}:this.matches.push(1,e)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Ze.prototype[Symbol.iterator]=function(){return this});const _h={from:-1,to:-1,match:/.*/.exec("")},Or="gm"+(/x/.unicode==null?"":"u");class Qh{constructor(t,e,i,s=0,r=t.length){if(this.text=t,this.to=r,this.curLine="",this.done=!1,this.value=_h,/\\[sWDnr]|\n|\r|\[\^/.test(e))return new Zh(t,e,i,s,r);this.re=new RegExp(e,Or+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=t.iter();let o=t.lineAt(s);this.curLineStart=o.from,this.matchPos=Mn(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),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 t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,s=i+e[0].length;if(this.matchPos=Mn(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,e)))return this.value={from:i,to:s,match:e},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}}const ls=new WeakMap;class $e{constructor(t,e){this.from=t,this.text=e}get to(){return this.from+this.text.length}static get(t,e,i){let s=ls.get(t);if(!s||s.from>=i||s.to<=e){let l=new $e(e,t.sliceString(e,i));return ls.set(t,l),l}if(s.from==e&&s.to==i)return s;let{text:r,from:o}=s;return o>e&&(r=t.sliceString(e,o)+r,o=e),s.to<i&&(r+=t.sliceString(s.to,i)),ls.set(t,new $e(o,r)),new $e(e,r.slice(e-o,i-o))}}class Zh{constructor(t,e,i,s,r){this.text=t,this.to=r,this.done=!1,this.value=_h,this.matchPos=Mn(t,s),this.re=new RegExp(e,Or+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=$e.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let i=this.flat.from+e.index,s=i+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,e)))return this.value={from:i,to:s,match:e},this.matchPos=Mn(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=$e.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Qh.prototype[Symbol.iterator]=Zh.prototype[Symbol.iterator]=function(){return this});function Up(n){try{return new RegExp(n,Or),!0}catch{return!1}}function Mn(n,t){if(t>=n.length)return t;let e=n.lineAt(t),i;for(;t<e.to&&(i=e.text.charCodeAt(t-e.from))>=56320&&i<57344;)t++;return t}function nr(n){let t=String(n.state.doc.lineAt(n.state.selection.main.head).number),e=lt("input",{class:"cm-textfield",name:"line",value:t}),i=lt("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),n.dispatch({effects:Dn.of(!1)}),n.focus()):r.keyCode==13&&(r.preventDefault(),s())},onsubmit:r=>{r.preventDefault(),s()}},lt("label",n.state.phrase("Go to line"),": ",e)," ",lt("button",{class:"cm-button",type:"submit"},n.state.phrase("go")));function s(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!r)return;let{state:o}=n,l=o.doc.lineAt(o.selection.main.head),[,a,h,c,f]=r,u=c?+c.slice(1):0,d=h?+h:l.number;if(h&&f){let m=d/100;a&&(m=m*(a=="-"?-1:1)+l.number/o.doc.lines),d=Math.round(o.doc.lines*m)}else h&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=o.doc.line(Math.max(1,Math.min(o.doc.lines,d))),g=b.cursor(p.from+Math.max(0,Math.min(u,p.length)));n.dispatch({effects:[Dn.of(!1),O.scrollIntoView(g.from,{y:"center"})],selection:g}),n.focus()}return{dom:i}}const Dn=F.define(),cl=bt.define({create(){return!0},update(n,t){for(let e of t.effects)e.is(Dn)&&(n=e.value);return n},provide:n=>wn.from(n,t=>t?nr:null)}),Gp=n=>{let t=xn(n,nr);if(!t){let e=[Dn.of(!0)];n.state.field(cl,!1)==null&&e.push(F.appendConfig.of([cl,Jp])),n.dispatch({effects:e}),t=xn(n,nr)}return t&&t.dom.querySelector("input").select(),!0},Jp=O.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),Yp={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Xp=T.define({combine(n){return Le(n,Yp,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})}});function Im(n){return[eg,tg]}const _p=P.mark({class:"cm-selectionMatch"}),Qp=P.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function fl(n,t,e,i){return(e==0||n(t.sliceDoc(e-1,e))!=G.Word)&&(i==t.doc.length||n(t.sliceDoc(i,i+1))!=G.Word)}function Zp(n,t,e,i){return n(t.sliceDoc(e,e+1))==G.Word&&n(t.sliceDoc(i-1,i))==G.Word}const tg=ut.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 t=n.state.facet(Xp),{state:e}=n,i=e.selection;if(i.ranges.length>1)return P.none;let s=i.main,r,o=null;if(s.empty){if(!t.highlightWordAroundCursor)return P.none;let a=e.wordAt(s.head);if(!a)return P.none;o=e.charCategorizer(s.head),r=e.sliceDoc(a.from,a.to)}else{let a=s.to-s.from;if(a<t.minSelectionLength||a>200)return P.none;if(t.wholeWords){if(r=e.sliceDoc(s.from,s.to),o=e.charCategorizer(s.head),!(fl(o,e,s.from,s.to)&&Zp(o,e,s.from,s.to)))return P.none}else if(r=e.sliceDoc(s.from,s.to),!r)return P.none}let l=[];for(let a of n.visibleRanges){let h=new Ze(e.doc,r,a.from,a.to);for(;!h.next().done;){let{from:c,to:f}=h.value;if((!o||fl(o,e,c,f))&&(s.empty&&c<=s.from&&f>=s.to?l.push(Qp.range(c,f)):(c>=s.to||f<=s.from)&&l.push(_p.range(c,f)),l.length>t.maxMatches))return P.none}}return P.set(l)}},{decorations:n=>n.decorations}),eg=O.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),ig=({state:n,dispatch:t})=>{let{selection:e}=n,i=b.create(e.ranges.map(s=>n.wordAt(s.head)||b.cursor(s.head)),e.mainIndex);return i.eq(e)?!1:(t(n.update({selection:i})),!0)};function ng(n,t){let{main:e,ranges:i}=n.selection,s=n.wordAt(e.head),r=s&&s.from==e.from&&s.to==e.to;for(let o=!1,l=new Ze(n.doc,t,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Ze(n.doc,t,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 sg=({state:n,dispatch:t})=>{let{ranges:e}=n.selection;if(e.some(r=>r.from===r.to))return ig({state:n,dispatch:t});let i=n.sliceDoc(e[0].from,e[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=ng(n,i);return s?(t(n.update({selection:n.selection.addRange(b.range(s.from,s.to),!1),effects:O.scrollIntoView(s.to)})),!0):!1},ii=T.define({combine(n){return Le(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new gg(t),scrollToMatch:t=>O.scrollIntoView(t)})}});class tc{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Up(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(e,i)=>i=="n"?`
`:i=="r"?"\r":i=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new ag(this):new og(this)}getCursor(t,e=0,i){let s=t.doc?t:H.create({doc:t});return i==null&&(i=s.doc.length),this.regexp?Ve(this,s,e,i):Fe(this,s,e,i)}}class ec{constructor(t){this.spec=t}}function Fe(n,t,e,i){return new Ze(t.doc,n.unquoted,e,i,n.caseSensitive?void 0:s=>s.toLowerCase(),n.wholeWord?rg(t.doc,t.charCategorizer(t.selection.main.head)):void 0)}function rg(n,t){return(e,i,s,r)=>((r>e||r+s.length<i)&&(r=Math.max(0,e-2),s=n.sliceString(r,Math.min(n.length,i+2))),(t(On(s,e-r))!=G.Word||t(Tn(s,e-r))!=G.Word)&&(t(Tn(s,i-r))!=G.Word||t(On(s,i-r))!=G.Word))}class og extends ec{constructor(t){super(t)}nextMatch(t,e,i){let s=Fe(this.spec,t,i,t.doc.length).nextOverlapping();return s.done&&(s=Fe(this.spec,t,0,e).nextOverlapping()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=i;;){let r=Math.max(e,s-1e4-this.spec.unquoted.length),o=Fe(this.spec,t,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==e)return null;s-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Fe(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Fe(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ve(n,t,e,i){return new Qh(t.doc,n.search,{ignoreCase:!n.caseSensitive,test:n.wholeWord?lg(t.charCategorizer(t.selection.main.head)):void 0},e,i)}function On(n,t){return n.slice(ot(n,t,!1),t)}function Tn(n,t){return n.slice(t,ot(n,t))}function lg(n){return(t,e,i)=>!i[0].length||(n(On(i.input,i.index))!=G.Word||n(Tn(i.input,i.index))!=G.Word)&&(n(Tn(i.input,i.index+i[0].length))!=G.Word||n(On(i.input,i.index+i[0].length))!=G.Word)}class ag extends ec{nextMatch(t,e,i){let s=Ve(this.spec,t,i,t.doc.length).next();return s.done&&(s=Ve(this.spec,t,0,e).next()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=1;;s++){let r=Math.max(e,i-s*1e4),o=Ve(this.spec,t,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==e||l.from>r+10))return l;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(e,i)=>i=="$"?"$":i=="&"?t.match[0]:i!="0"&&+i<t.match.length?t.match[i]:e)}matchAll(t,e){let i=Ve(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Ve(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const Oi=F.define(),Tr=F.define(),fe=bt.define({create(n){return new as(sr(n).create(),null)},update(n,t){for(let e of t.effects)e.is(Oi)?n=new as(e.value.create(),n.panel):e.is(Tr)&&(n=new as(n.query,e.value?Pr:null));return n},provide:n=>wn.from(n,t=>t.panel)});class as{constructor(t,e){this.query=t,this.panel=e}}const hg=P.mark({class:"cm-searchMatch"}),cg=P.mark({class:"cm-searchMatch cm-searchMatch-selected"}),fg=ut.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(fe))}update(n){let t=n.state.field(fe);(t!=n.startState.field(fe)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:n,panel:t}){if(!t||!n.spec.valid)return P.none;let{view:e}=this,i=new De;for(let s=0,r=e.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(e.state,l,a,(h,c)=>{let f=e.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?cg:hg)})}return i.finish()}},{decorations:n=>n.decorations});function Ni(n){return t=>{let e=t.state.field(fe,!1);return e&&e.query.spec.valid?n(t,e):sc(t)}}const Pn=Ni((n,{query:t})=>{let{to:e}=n.state.selection.main,i=t.nextMatch(n.state,e,e);if(!i)return!1;let s=b.single(i.from,i.to),r=n.state.facet(ii);return n.dispatch({selection:s,effects:[Br(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),nc(n),!0}),Bn=Ni((n,{query:t})=>{let{state:e}=n,{from:i}=e.selection.main,s=t.prevMatch(e,i,i);if(!s)return!1;let r=b.single(s.from,s.to),o=n.state.facet(ii);return n.dispatch({selection:r,effects:[Br(n,s),o.scrollToMatch(r.main,n)],userEvent:"select.search"}),nc(n),!0}),ug=Ni((n,{query:t})=>{let e=t.matchAll(n.state,1e3);return!e||!e.length?!1:(n.dispatch({selection:b.create(e.map(i=>b.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),dg=({state:n,dispatch:t})=>{let e=n.selection;if(e.ranges.length>1||e.main.empty)return!1;let{from:i,to:s}=e.main,r=[],o=0;for(let l=new Ze(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 t(n.update({selection:b.create(r,o),userEvent:"select.search.matches"})),!0},ul=Ni((n,{query:t})=>{let{state:e}=n,{from:i,to:s}=e.selection.main;if(e.readOnly)return!1;let r=t.nextMatch(e,i,i);if(!r)return!1;let o=[],l,a,h=[];if(r.from==i&&r.to==s&&(a=e.toText(t.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=t.nextMatch(e,r.from,r.to),h.push(O.announce.of(e.phrase("replaced match on line $",e.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(e.facet(ii).scrollToMatch(l.main,n))}return n.dispatch({changes:o,selection:l,effects:h,userEvent:"input.replace"}),!0}),pg=Ni((n,{query:t})=>{if(n.state.readOnly)return!1;let e=t.matchAll(n.state,1e9).map(s=>{let{from:r,to:o}=s;return{from:r,to:o,insert:t.getReplacement(s)}});if(!e.length)return!1;let i=n.state.phrase("replaced $ matches",e.length)+".";return n.dispatch({changes:e,effects:O.announce.of(i),userEvent:"input.replace.all"}),!0});function Pr(n){return n.state.facet(ii).createPanel(n)}function sr(n,t){var e,i,s,r,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(t&&!a)return t;let h=n.facet(ii);return new tc({search:((e=t==null?void 0:t.literal)!==null&&e!==void 0?e:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=t==null?void 0:t.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(s=t==null?void 0:t.literal)!==null&&s!==void 0?s:h.literal,regexp:(r=t==null?void 0:t.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=t==null?void 0:t.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function ic(n){let t=xn(n,Pr);return t&&t.dom.querySelector("[main-field]")}function nc(n){let t=ic(n);t&&t==n.root.activeElement&&t.select()}const sc=n=>{let t=n.state.field(fe,!1);if(t&&t.panel){let e=ic(n);if(e&&e!=n.root.activeElement){let i=sr(n.state,t.query.spec);i.valid&&n.dispatch({effects:Oi.of(i)}),e.focus(),e.select()}}else n.dispatch({effects:[Tr.of(!0),t?Oi.of(sr(n.state,t.query.spec)):F.appendConfig.of(yg)]});return!0},rc=n=>{let t=n.state.field(fe,!1);if(!t||!t.panel)return!1;let e=xn(n,Pr);return e&&e.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Tr.of(!1)}),!0},Nm=[{key:"Mod-f",run:sc,scope:"editor search-panel"},{key:"F3",run:Pn,shift:Bn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Pn,shift:Bn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:rc,scope:"editor search-panel"},{key:"Mod-Shift-l",run:dg},{key:"Mod-Alt-g",run:Gp},{key:"Mod-d",run:sg,preventDefault:!0}];class gg{constructor(t){this.view=t;let e=this.query=t.state.field(fe).query.spec;this.commit=this.commit.bind(this),this.searchField=lt("input",{value:e.search,placeholder:At(t,"Find"),"aria-label":At(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=lt("input",{value:e.replace,placeholder:At(t,"Replace"),"aria-label":At(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=lt("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=lt("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=lt("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit});function i(s,r,o){return lt("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=lt("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>Pn(t),[At(t,"next")]),i("prev",()=>Bn(t),[At(t,"previous")]),i("select",()=>ug(t),[At(t,"all")]),lt("label",null,[this.caseField,At(t,"match case")]),lt("label",null,[this.reField,At(t,"regexp")]),lt("label",null,[this.wordField,At(t,"by word")]),...t.state.readOnly?[]:[lt("br"),this.replaceField,i("replace",()=>ul(t),[At(t,"replace")]),i("replaceAll",()=>pg(t),[At(t,"replace all")])],lt("button",{name:"close",onclick:()=>rc(t),"aria-label":At(t,"close"),type:"button"},["×"])])}commit(){let t=new tc({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Oi.of(t)}))}keydown(t){cu(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Bn:Pn)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),ul(this.view))}update(t){for(let e of t.transactions)for(let i of e.effects)i.is(Oi)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(ii).top}}function At(n,t){return n.state.phrase(t)}const nn=30,sn=/[\s\.,:;?!]/;function Br(n,{from:t,to:e}){let i=n.state.doc.lineAt(t),s=n.state.doc.lineAt(e).to,r=Math.max(i.from,t-nn),o=Math.min(s,e+nn),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<nn;a++)if(!sn.test(l[a+1])&&sn.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-nn;a--)if(!sn.test(l[a-1])&&sn.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 mg=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"}}),yg=[fe,ye.low(fg),mg];class oc{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=yt(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),s=e.text.slice(i-e.from,this.pos-e.from),r=s.search(lc(t,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(t,e){t=="abort"&&this.abortListeners&&this.abortListeners.push(e)}}function dl(n){let t=Object.keys(n).join(""),e=/\w/.test(t);return e&&(t=t.replace(/\w/g,"")),`[${e?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function bg(n){let t=Object.create(null),e=Object.create(null);for(let{label:s}of n){t[s[0]]=!0;for(let r=1;r<s.length;r++)e[s[r]]=!0}let i=dl(t)+dl(e)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function xg(n){let t=n.map(s=>typeof s=="string"?{label:s}:s),[e,i]=t.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:bg(t);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:t,validFor:e}:null}}function Fm(n,t){return e=>{for(let i=yt(e.state).resolveInner(e.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return t(e)}}class pl{constructor(t,e,i,s){this.completion=t,this.source=e,this.match=i,this.score=s}}function ue(n){return n.selection.main.from}function lc(n,t){var e;let{source:i}=n,s=t&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(e=n.flags)!==null&&e!==void 0?e:n.ignoreCase?"i":"")}const Rr=se.define();function wg(n,t,e,i){let{main:s}=n.selection,r=e-s.from,o=i-s.from;return Object.assign(Object.assign({},n.changeByRange(l=>l!=s&&e!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(e,i)?{range:l}:{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:t},range:b.cursor(l.from+r+t.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const gl=new WeakMap;function Sg(n){if(!Array.isArray(n))return n;let t=gl.get(n);return t||gl.set(n,t=xg(n)),t}const Rn=F.define(),Ti=F.define();class vg{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e<t.length;){let i=nt(t,e),s=Bt(i);this.chars.push(i);let r=t.slice(e,e+s),o=r.toUpperCase();this.folded.push(nt(o==r?r.toLowerCase():o,0)),e+=s}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:e,folded:i,any:s,precise:r,byWord:o}=this;if(e.length==1){let x=nt(t,0),v=Bt(x),S=v==t.length?0:-100;if(x!=e[0])if(x==i[0])S+=-200;else return null;return this.ret(S,[0,v])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=e.length,h=0;if(l<0){for(let x=0,v=Math.min(t.length,200);x<v&&h<a;){let S=nt(t,x);(S==e[h]||S==i[h])&&(s[h++]=x),x+=Bt(S)}if(h<a)return null}let c=0,f=0,u=!1,d=0,p=-1,g=-1,m=/[a-z]/.test(t),y=!0;for(let x=0,v=Math.min(t.length,200),S=0;x<v&&f<a;){let w=nt(t,x);l<0&&(c<a&&w==e[c]&&(r[c++]=x),d<a&&(w==e[d]||w==i[d]?(d==0&&(p=x),g=x+1,d++):d=0));let A,C=w<255?w>=48&&w<=57||w>=97&&w<=122?2:w>=65&&w<=90?1:0:(A=or(w))!=A.toLowerCase()?1:A!=A.toUpperCase()?2:0;(!x||C==1&&m||S==0&&C!=0)&&(e[f]==w||i[f]==w&&(u=!0)?o[f++]=x:o.length&&(y=!1)),S=C,x+=Bt(w)}return f==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,t):d==a&&p==0?this.ret(-200-t.length+(g==t.length?0:-100),[0,g]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):d==a?this.ret(-900-t.length,[p,g]):f==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,t):e.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,t)}result(t,e,i){let s=[],r=0;for(let o of e){let l=o+(this.astral?Bt(nt(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(t-i.length,s)}}class kg{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let e=t.slice(0,this.pattern.length),i=e==this.pattern?0:e.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,e.length],this.score=i+(t.length==this.pattern.length?0:-100),this)}}const rt=T.define({combine(n){return Le(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Cg,filterStrict:!1,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>ml(t(i),e(i)),optionClass:(t,e)=>i=>ml(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})}});function ml(n,t){return n?t?n+" "+t:n:t}function Cg(n,t,e,i,s,r){let o=n.textDirection==X.RTL,l=o,a=!1,h="top",c,f,u=t.left-s.left,d=s.right-t.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))c=Math.max(s.top,Math.min(e.top,s.bottom-g))-t.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?t.right:s.right-t.left)-30);let x=s.bottom-t.bottom;x>=g||x>t.top?c=e.bottom-t.top:(h="bottom",c=t.bottom-e.top)}let m=(t.bottom-t.top)/r.offsetHeight,y=(t.right-t.left)/r.offsetWidth;return{style:`${h}: ${c/m}px; max-width: ${f/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function Ag(n){let t=n.addToOptions.slice();return n.icons&&t.push({render(e){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),e.type&&i.classList.add(...e.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),t.push({render(e,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=e.displayLabel||e.label,a=0;for(let h=0;h<r.length;){let c=r[h++],f=r[h++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(c,f))),u.className="cm-completionMatchedText",a=f}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(e){if(!e.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=e.detail,i},position:80}),t.sort((e,i)=>e.position-i.position).map(e=>e.render)}function hs(n,t,e){if(n<=e)return{from:0,to:n};if(t<0&&(t=0),t<=n>>1){let s=Math.floor(t/e);return{from:s*e,to:(s+1)*e}}let i=Math.floor((n-t)/e);return{from:n-(i+1)*e,to:n-i*e}}class Mg{constructor(t,e,i){this.view=t,this.stateField=e,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=t.state.field(e),{options:r,selected:o}=s.open,l=t.state.facet(rt);this.optionContent=Ag(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=hs(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=t.state.field(e).open;for(let c=a.target,f;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(f=/-(\d+)$/.exec(c.id))&&+f[1]<h.length){this.applyCompletion(t,h[+f[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let h=t.state.field(this.stateField,!1);h&&h.tooltip&&t.state.facet(rt).closeOnBlur&&a.relatedTarget!=t.contentDOM&&t.dispatch({effects:Ti.of(null)})}),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),s=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=hs(r.length,o,t.state.facet(rt).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((e=s.open)===null||e===void 0?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of e.split(" "))i&&this.dom.classList.add(i);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=hs(e.options.length,e.selected,this.view.state.facet(rt).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.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)==t&&this.addInfoPane(o,i)}).catch(o=>Dt(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",t.nodeType!=null)i.appendChild(t),this.infoDestroy=null;else{let{dom:s,destroy:r}=t;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return e&&Og(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=t.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,e.bottom)-10||s.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(rt).positionInfo(this.view,e,s,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const s=document.createElement("ul");s.id=e,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}=t[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=e+"-"+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,this.view,a);d&&c.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Dg(n,t){return e=>new Mg(e,n,t)}function Og(n,t){let e=n.getBoundingClientRect(),i=t.getBoundingClientRect(),s=e.height/n.offsetHeight;i.top<e.top?n.scrollTop-=(e.top-i.top)/s:i.bottom>e.bottom&&(n.scrollTop+=(i.bottom-e.bottom)/s)}function yl(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function Tg(n,t){let e=[],i=null,s=h=>{e.push(h);let{section:c}=h.completion;if(c){i||(i=[]);let f=typeof c=="string"?c:c.name;i.some(u=>u.name==f)||i.push(typeof c=="string"?{name:f}:c)}},r=t.facet(rt);for(let h of n)if(h.hasResult()){let c=h.result.getMatch;if(h.result.filter===!1)for(let f of h.result.options)s(new pl(f,h.source,c?c(f):[],1e9-e.length));else{let f=t.sliceDoc(h.from,h.to),u,d=r.filterStrict?new kg(f):new vg(f);for(let p of h.result.options)if(u=d.match(p.label)){let g=p.displayLabel?c?c(p,u.matched):[]:u.matched;s(new pl(p,h.source,g,u.score+(p.boost||0)))}}}if(i){let h=Object.create(null),c=0,f=(u,d)=>{var p,g;return((p=u.rank)!==null&&p!==void 0?p:1e9)-((g=d.rank)!==null&&g!==void 0?g:1e9)||(u.name<d.name?-1:1)};for(let u of i.sort(f))c-=1e5,h[u.name]=c;for(let u of e){let{section:d}=u.completion;d&&(u.score+=h[typeof d=="string"?d:d.name])}}let o=[],l=null,a=r.compareCompletions;for(let h of e.sort((c,f)=>f.score-c.score||a(c.completion,f.completion))){let c=h.completion;!l||l.label!=c.label||l.detail!=c.detail||l.type!=null&&c.type!=null&&l.type!=c.type||l.apply!=c.apply||l.boost!=c.boost?o.push(h):yl(h.completion)>yl(l)&&(o[o.length-1]=h),l=h.completion}return o}class We{constructor(t,e,i,s,r,o){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new We(this.options,bl(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,s,r){let o=Tg(t,e);if(!o.length)return s&&t.some(a=>a.state==1)?new We(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let l=e.facet(rt).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 We(o,bl(i,l),{pos:t.reduce((a,h)=>h.hasResult()?Math.min(a,h.from):a,1e8),create:Eg,above:r.aboveCursor},s?s.timestamp:Date.now(),l,!1)}map(t){return new We(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Ln{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Ln(Rg,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:e}=t,i=e.facet(rt),r=(i.override||e.languageDataAt("autocomplete",ue(e)).map(Sg)).map(l=>(this.active.find(h=>h.source==l)||new pt(l,this.active.some(h=>h.state!=0)?1:0)).update(t,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&t.docChanged&&(o=o.map(t.changes)),t.selection||r.some(l=>l.hasResult()&&t.changes.touchesRange(l.from,l.to))||!Pg(r,this.active)?o=We.build(r,e,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 pt(l.source,0):l));for(let l of t.effects)l.is(hc)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new Ln(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Bg}}function Pg(n,t){if(n==t)return!0;for(let e=0,i=0;;){for(;e<n.length&&!n[e].hasResult;)e++;for(;i<t.length&&!t[i].hasResult;)i++;let s=e==n.length,r=i==t.length;if(s||r)return s==r;if(n[e++].result!=t[i++].result)return!1}}const Bg={"aria-autocomplete":"list"};function bl(n,t){let e={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return t>-1&&(e["aria-activedescendant"]=n+"-"+t),e}const Rg=[];function rr(n,t){if(n.isUserEvent("input.complete")){let e=n.annotation(Rr);if(e&&t.activateOnCompletion(e))return"input"}return n.isUserEvent("input.type")?"input":n.isUserEvent("delete.backward")?"delete":null}class pt{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=rr(t,e),s=this;i?s=s.handleUserEvent(t,i,e):t.docChanged?s=s.handleChange(t):t.selection&&s.state!=0&&(s=new pt(s.source,0));for(let r of t.effects)if(r.is(Rn))s=new pt(s.source,1,r.value?ue(t.state):-1);else if(r.is(Ti))s=new pt(s.source,0);else if(r.is(ac))for(let o of r.value)o.source==s.source&&(s=o);return s}handleUserEvent(t,e,i){return e=="delete"||!i.activateOnTyping?this.map(t.changes):new pt(this.source,1)}handleChange(t){return t.changes.touchesRange(ue(t.startState))?new pt(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new pt(this.source,this.state,t.mapPos(this.explicitPos))}}class je extends pt{constructor(t,e,i,s,r){super(t,2,e),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var s;let r=this.result;r.map&&!t.changes.empty&&(r=r.map(r,t.changes));let o=t.changes.mapPos(this.from),l=t.changes.mapPos(this.to,1),a=ue(t.state);if((this.explicitPos<0?a<=o:a<this.from)||a>l||!r||e=="delete"&&ue(t.startState)==this.from)return new pt(this.source,e=="input"&&i.activateOnTyping?1:0);let h=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos);return Lg(r.validFor,t.state,o,l)?new je(this.source,h,r,o,l):r.update&&(r=r.update(r,o,l,new oc(t.state,a,h>=0)))?new je(this.source,h,r,r.from,(s=r.to)!==null&&s!==void 0?s:ue(t.state)):new pt(this.source,1,h)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new pt(this.source,0):this.map(t.changes)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new je(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new pt(this.source,0)}}function Lg(n,t,e,i){if(!n)return!1;let s=t.sliceDoc(e,i);return typeof n=="function"?n(s,e,i,t):lc(n,!0).test(s)}const ac=F.define({map(n,t){return n.map(e=>e.map(t))}}),hc=F.define(),vt=bt.define({create(){return Ln.start()},update(n,t){return n.update(t)},provide:n=>[Ua.from(n,t=>t.tooltip),O.contentAttributes.from(n,t=>t.attrs)]});function Lr(n,t){const e=t.completion.apply||t.completion.label;let i=n.state.field(vt).active.find(s=>s.source==t.source);return i instanceof je?(typeof e=="string"?n.dispatch(Object.assign(Object.assign({},wg(n.state,e,i.from,i.to)),{annotations:Rr.of(t.completion)})):e(n,t.completion,i.from,i.to),!0):!1}const Eg=Dg(vt,Lr);function rn(n,t="option"){return e=>{let i=e.state.field(vt,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<e.state.facet(rt).interactionDelay)return!1;let s=1,r;t=="page"&&(r=Ga(e,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=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),e.dispatch({effects:hc.of(l)}),!0}}const Ig=n=>{let t=n.state.field(vt,!1);return n.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<n.state.facet(rt).interactionDelay?!1:Lr(n,t.open.options[t.open.selected])},Ng=n=>n.state.field(vt,!1)?(n.dispatch({effects:Rn.of(!0)}),!0):!1,Fg=n=>{let t=n.state.field(vt,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(n.dispatch({effects:Ti.of(null)}),!0)};class Vg{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Wg=50,Hg=1e3,zg=ut.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of n.state.field(vt).active)t.state==1&&this.startQuery(t)}update(n){let t=n.state.field(vt),e=n.state.facet(rt);if(!n.selectionSet&&!n.docChanged&&n.startState.field(vt)==t)return;let i=n.transactions.some(r=>(r.selection||r.docChanged)&&!rr(r,e));for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.updates.length+n.transactions.length>Wg&&Date.now()-o.time>Hg){for(let l of o.context.abortListeners)try{l()}catch(a){Dt(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(r=>r.effects.some(o=>o.is(Rn)))&&(this.pendingStart=!0);let s=this.pendingStart?50:e.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(r=>r.state==1&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let r of n.transactions)rr(r,e)=="input"?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,t=n.field(vt);for(let e of t.active)e.state==1&&!this.running.some(i=>i.active.source==e.source)&&this.startQuery(e)}startQuery(n){let{state:t}=this.view,e=ue(t),i=new oc(t,e,n.explicitPos==e),s=new Vg(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:Ti.of(null)}),Dt(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(rt).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],e=this.view.state.facet(rt);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 je(s.active.source,s.active.explicitPos,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:ue(s.updates.length?s.updates[0].startState:this.view.state));for(let l of s.updates)o=o.update(l,e);if(o.hasResult()){t.push(o);continue}}let r=this.view.state.field(vt).active.find(o=>o.source==s.active.source);if(r&&r.state==1)if(s.done==null){let o=new pt(s.active.source,0);for(let l of s.updates)o=o.update(l,e);o.state!=1&&t.push(o)}else this.startQuery(r)}t.length&&this.view.dispatch({effects:ac.of(t)})}},{eventHandlers:{blur(n){let t=this.view.state.field(vt,!1);if(t&&t.tooltip&&this.view.state.facet(rt).closeOnBlur){let e=t.open&&Ga(this.view,t.open.tooltip);(!e||!e.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Ti.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Rn.of(!1)}),20),this.composing=0}}}),qg=typeof navigator=="object"&&/Win/.test(navigator.platform),Kg=ye.highest(O.domEventHandlers({keydown(n,t){let e=t.state.field(vt,!1);if(!e||!e.open||e.open.disabled||e.open.selected<0||n.key.length>1||n.ctrlKey&&!(qg&&n.altKey)||n.metaKey)return!1;let i=e.open.options[e.open.selected],s=e.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(n.key)>-1&&Lr(t,i),!1}})),cc=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 $g{constructor(t,e,i,s){this.field=t,this.line=e,this.from=i,this.to=s}}class Er{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,ht.TrackDel),i=t.mapPos(this.to,1,ht.TrackDel);return e==null||i==null?null:new Er(this.field,e,i)}}class Ir{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],s=[e],r=t.doc.lineAt(e),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+=t.facet(Fn);s.push(e+h.length-c),a=h+a.slice(c)}i.push(a),e+=a.length+1}let l=this.fieldPositions.map(a=>new Er(a.field,s[a.line]+a.from,s[a.line]+a.to));return{text:i,ranges:l}}static parse(t){let e=[],i=[],s=[],r;for(let o of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",h=-1,c=a.replace(/\\[{}]/g,f=>f[1]);for(let f=0;f<e.length;f++)(l!=null?e[f].seq==l:c&&e[f].name==c)&&(h=f);if(h<0){let f=0;for(;f<e.length&&(l==null||e[f].seq!=null&&e[f].seq<l);)f++;e.splice(f,0,{seq:l,name:c}),h=f;for(let u of s)u.field>=h&&u.field++}s.push(new $g(h,i.length,r.index,r.index+c.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,a,h)=>{for(let c of s)c.line==i.length&&c.from>h&&(c.from--,c.to--);return a}),i.push(o)}return new Ir(i,s)}}let jg=P.widget({widget:new class extends Ee{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),Ug=P.mark({class:"cm-snippetField"});class ni{constructor(t,e){this.ranges=t,this.active=e,this.deco=P.set(t.map(i=>(i.from==i.to?jg:Ug).range(i.from,i.to)))}map(t){let e=[];for(let i of this.ranges){let s=i.map(t);if(!s)return null;e.push(s)}return new ni(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}}const Fi=F.define({map(n,t){return n&&n.map(t)}}),Gg=F.define(),Pi=bt.define({create(){return null},update(n,t){for(let e of t.effects){if(e.is(Fi))return e.value;if(e.is(Gg)&&n)return new ni(n.ranges,e.value)}return n&&t.docChanged&&(n=n.map(t.changes)),n&&t.selection&&!n.selectionInsideField(t.selection)&&(n=null),n},provide:n=>O.decorations.from(n,t=>t?t.deco:P.none)});function Nr(n,t){return b.create(n.filter(e=>e.field==t).map(e=>b.range(e.from,e.to)))}function Jg(n){let t=Ir.parse(n);return(e,i,s,r)=>{let{text:o,ranges:l}=t.instantiate(e.state,s),a={changes:{from:s,to:r,insert:V.of(o)},scrollIntoView:!0,annotations:i?[Rr.of(i),Q.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=Nr(l,0)),l.some(h=>h.field>0)){let h=new ni(l,0),c=a.effects=[Fi.of(h)];e.state.field(Pi,!1)===void 0&&c.push(F.appendConfig.of([Pi,Zg,tm,cc]))}e.dispatch(e.state.update(a))}}function fc(n){return({state:t,dispatch:e})=>{let i=t.field(Pi,!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 e(t.update({selection:Nr(i.ranges,s),effects:Fi.of(r?null:new ni(i.ranges,s)),scrollIntoView:!0})),!0}}const Yg=({state:n,dispatch:t})=>n.field(Pi,!1)?(t(n.update({effects:Fi.of(null)})),!0):!1,Xg=fc(1),_g=fc(-1),Qg=[{key:"Tab",run:Xg,shift:_g},{key:"Escape",run:Yg}],xl=T.define({combine(n){return n.length?n[0]:Qg}}),Zg=ye.highest(yr.compute([xl],n=>n.facet(xl)));function Vm(n,t){return Object.assign(Object.assign({},t),{apply:Jg(n)})}const tm=O.domEventHandlers({mousedown(n,t){let e=t.state.field(Pi,!1),i;if(!e||(i=t.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let s=e.ranges.find(r=>r.from<=i&&r.to>=i);return!s||s.field==e.active?!1:(t.dispatch({selection:Nr(e.ranges,s.field),effects:Fi.of(e.ranges.some(r=>r.field>s.field)?new ni(e.ranges,s.field):null),scrollIntoView:!0}),!0)}}),Bi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Ae=F.define({map(n,t){let e=t.mapPos(n,-1,ht.TrackAfter);return e??void 0}}),Fr=new class extends Me{};Fr.startSide=1;Fr.endSide=-1;const uc=bt.define({create(){return K.empty},update(n,t){if(n=n.map(t.changes),t.selection){let e=t.state.doc.lineAt(t.selection.main.head);n=n.update({filter:i=>i>=e.from&&i<=e.to})}for(let e of t.effects)e.is(Ae)&&(n=n.update({add:[Fr.range(e.value,e.value+1)]}));return n}});function Wm(){return[im,uc]}const cs="()[]{}<>";function dc(n){for(let t=0;t<cs.length;t+=2)if(cs.charCodeAt(t)==n)return cs.charAt(t+1);return or(n<128?n:n+1)}function pc(n,t){return n.languageDataAt("closeBrackets",t)[0]||Bi}const em=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),im=O.inputHandler.of((n,t,e,i)=>{if((em?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let s=n.state.selection.main;if(i.length>2||i.length==2&&Bt(nt(i,0))==1||t!=s.from||e!=s.to)return!1;let r=sm(n.state,i);return r?(n.dispatch(r),!0):!1}),nm=({state:n,dispatch:t})=>{if(n.readOnly)return!1;let i=pc(n,n.selection.main.head).brackets||Bi.brackets,s=null,r=n.changeByRange(o=>{if(o.empty){let l=rm(n.doc,o.head);for(let a of i)if(a==l&&$n(n.doc,o.head)==dc(nt(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||t(n.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s},Hm=[{key:"Backspace",run:nm}];function sm(n,t){let e=pc(n,n.selection.main.head),i=e.brackets||Bi.brackets;for(let s of i){let r=dc(nt(s,0));if(t==s)return r==s?am(n,s,i.indexOf(s+s+s)>-1,e):om(n,s,r,e.before||Bi.before);if(t==r&&gc(n,n.selection.main.from))return lm(n,s,r)}return null}function gc(n,t){let e=!1;return n.field(uc).between(0,n.doc.length,i=>{i==t&&(e=!0)}),e}function $n(n,t){let e=n.sliceString(t,t+2);return e.slice(0,Bt(nt(e,0)))}function rm(n,t){let e=n.sliceString(t-2,t);return Bt(nt(e,0))==e.length?e:e.slice(1)}function om(n,t,e,i){let s=null,r=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:e,from:o.to}],effects:Ae.of(o.to+t.length),range:b.range(o.anchor+t.length,o.head+t.length)};let l=$n(n.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:t+e,from:o.head},effects:Ae.of(o.head+t.length),range:b.cursor(o.head+t.length)}:{range:s=o}});return s?null:n.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function lm(n,t,e){let i=null,s=n.changeByRange(r=>r.empty&&$n(n.doc,r.head)==e?{changes:{from:r.head,to:r.head+e.length,insert:e},range:b.cursor(r.head+e.length)}:i={range:r});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function am(n,t,e,i){let s=i.stringPrefixes||Bi.stringPrefixes,r=null,o=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:Ae.of(l.to+t.length),range:b.range(l.anchor+t.length,l.head+t.length)};let a=l.head,h=$n(n.doc,a),c;if(h==t){if(wl(n,a))return{changes:{insert:t+t,from:a},effects:Ae.of(a+t.length),range:b.cursor(a+t.length)};if(gc(n,a)){let u=e&&n.sliceDoc(a,a+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:a,to:a+u.length,insert:u},range:b.cursor(a+u.length)}}}else{if(e&&n.sliceDoc(a-2*t.length,a)==t+t&&(c=Sl(n,a-2*t.length,s))>-1&&wl(n,c))return{changes:{insert:t+t+t+t,from:a},effects:Ae.of(a+t.length),range:b.cursor(a+t.length)};if(n.charCategorizer(a)(h)!=G.Word&&Sl(n,a,s)>-1&&!hm(n,a,t,s))return{changes:{insert:t+t,from:a},effects:Ae.of(a+t.length),range:b.cursor(a+t.length)}}return{range:r=l}});return r?null:n.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function wl(n,t){let e=yt(n).resolveInner(t+1);return e.parent&&e.from==t}function hm(n,t,e,i){let s=yt(n).resolveInner(t,-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+e.length+r)),a=l.indexOf(e);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>e.length+a;){if(n.sliceDoc(c.to-e.length,c.to)==e)return!1;c=c.firstChild}return!0}let h=s.to==t&&s.parent;if(!h)break;s=h}return!1}function Sl(n,t,e){let i=n.charCategorizer(t);if(i(n.sliceDoc(t-1,t))!=G.Word)return t;for(let s of e){let r=t-s.length;if(n.sliceDoc(r,t)==s&&i(n.sliceDoc(r-1,r))!=G.Word)return r}return-1}function zm(n={}){return[Kg,vt,rt.of(n),zg,fm,cc]}const cm=[{key:"Ctrl-Space",run:Ng},{key:"Escape",run:Fg},{key:"ArrowDown",run:rn(!0)},{key:"ArrowUp",run:rn(!1)},{key:"PageDown",run:rn(!0,"page")},{key:"PageUp",run:rn(!1,"page")},{key:"Enter",run:Ig}],fm=ye.highest(yr.computeN([rt],n=>n.facet(rt).defaultKeymap?[cm]:[]));export{wm as A,dd as B,En as C,zu as D,O as E,Am as F,Mm as G,Dm as H,Y as I,vm as J,xm as K,Ys as L,Fm as M,br as N,xg as O,Qa as P,b as Q,Vm as R,uh as S,j as T,Cm as U,km as V,cd as W,eh as X,Od as Y,cm as a,H as b,Hm as c,Lm as d,bm as e,gm as f,Bm as g,Rm as h,dm as i,pm as j,Om as k,Pm as l,Wm as m,Im as n,yr as o,zm as p,mm as q,ym as r,Nm as s,Em as t,Tm as u,yt as v,mt as w,L as x,rd as y,M as z};