pocketbase/ui/dist/assets/index-7-b_i8CL.js

14 lines
338 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(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=Kt(this,e,t);let n=[];return this.decompose(0,e,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(t,this.length,n,1),Ue.from(n,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Kt(this,e,t);let i=[];return this.decompose(e,t,i,0),Ue.from(i,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),n=new ui(this),r=new ui(e);for(let o=t,l=t;;){if(n.next(o),r.next(o),o=0,n.lineBreak!=r.lineBreak||n.done!=r.done||n.value!=r.value)return!1;if(l+=n.value.length,n.done||l>=i)return!0}}iter(e=1){return new ui(this,e)}iterRange(e,t=this.length){return new yl(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new bl(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?V.empty:e.length<=32?new _(e):Ue.from(_.split(e,[]))}}class _ extends V{constructor(e,t=cc(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((t?i:l)>=e)return new fc(n,l,i,o);n=l+1,i++}}decompose(e,t,i,n){let r=e<=0&&t>=this.length?this:new _(Rr(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=i.pop(),l=nn(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(e,t,i){if(!(i instanceof _))return super.replace(e,t,i);[e,t]=Kt(this,e,t);let n=nn(this.text,nn(i.text,Rr(this.text,0,e)),t),r=this.length+i.length-(t-e);return n.length<=32?new _(n,r):Ue.from(_.split(n,[]),r)}sliceString(e,t=this.length,i=`
`){[e,t]=Kt(this,e,t);let n="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(n+=i),e<a&&t>r&&(n+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],n=-1;for(let r of e)i.push(r),n+=r.length+1,i.length==32&&(t.push(new _(i,n)),i=[],n=-1);return n>-1&&t.push(new _(i,n)),t}}class Ue extends V{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,n){for(let r=0;;r++){let o=this.children[r],l=n+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,n);n=l+1,i=a+1}}decompose(e,t,i,n){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=Kt(this,e,t),i.lines<this.lines)for(let n=0,r=0;n<this.children.length;n++){let o=this.children[n],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[n]=a,new Ue(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=`
`){[e,t]=Kt(this,e,t);let n="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(n+=i),e<a&&t>o&&(n+=l.sliceString(e-o,t-o,i)),o=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof Ue))return 0;let i=0,[n,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,r+=t){if(n==o||r==l)return i;let a=this.children[n],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new _(d,t)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],a=0,h=-1,c=[];function f(d){let p;if(d.lines>r&&d instanceof Ue)for(let m of d.children)f(m);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>n&&u(),a+=d.lines,h+=d.length+1,c.push(d))}function u(){a!=0&&(l.push(c.length==1?c[0]:Ue.from(c,h)),h=-1,a=c.length=0)}for(let d of e)f(d);return u(),l.length==1?l[0]:new Ue(l,t)}}V.empty=new _([""],0);function cc(s){let e=-1;for(let t of s)e+=t.length+1;return e}function nn(s,e,t=0,i=1e9){for(let n=0,r=0,o=!0;r<s.length&&n<=i;r++){let l=s[r],a=n+l.length;a>=t&&(a>i&&(l=l.slice(0,i-n)),n<t&&(l=l.slice(t-n)),o?(e[e.length-1]+=l,o=!1):e.push(l)),n=a+1}return e}function Rr(s,e,t){return nn(s,[""],e,t)}class ui{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof _?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,n=this.nodes[i],r=this.offsets[i],o=r>>1,l=n instanceof _?n.text.length:n.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=`
`,this;e--}else if(n instanceof _){let a=n.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof _?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class yl{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new ui(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class bl{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(V.prototype[Symbol.iterator]=function(){return this.iter()},ui.prototype[Symbol.iterator]=yl.prototype[Symbol.iterator]=bl.prototype[Symbol.iterator]=function(){return this});class fc{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}function Kt(s,e,t){return e=Math.max(0,Math.min(s.length,e)),[e,Math.max(e,Math.min(s.length,t))]}let Vt="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(s=>s?parseInt(s,36):1);for(let s=1;s<Vt.length;s++)Vt[s]+=Vt[s-1];function uc(s){for(let e=1;e<Vt.length;e+=2)if(Vt[e]>s)return Vt[e-1]<=s;return!1}function Er(s){return s>=127462&&s<=127487}const Ir=8205;function oe(s,e,t=!0,i=!0){return(t?wl:dc)(s,e,i)}function wl(s,e,t){if(e==s.length)return e;e&&xl(s.charCodeAt(e))&&vl(s.charCodeAt(e-1))&&e--;let i=ne(s,e);for(e+=Be(i);e<s.length;){let n=ne(s,e);if(i==Ir||n==Ir||t&&uc(n))e+=Be(n),i=n;else if(Er(n)){let r=0,o=e-2;for(;o>=0&&Er(ne(s,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function dc(s,e,t){for(;e>0;){let i=wl(s,e-2,t);if(i<e)return i;e--}return 0}function xl(s){return s>=56320&&s<57344}function vl(s){return s>=55296&&s<56320}function ne(s,e){let t=s.charCodeAt(e);if(!vl(t)||e+1==s.length)return t;let i=s.charCodeAt(e+1);return xl(i)?(t-55296<<10)+(i-56320)+65536:t}function nr(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function Be(s){return s<65536?1:2}const hs=/\r\n?|\n/;var he=function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s}(he||(he={}));class _e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(e,t=!1){cs(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new _e(e)}composeDesc(e){return this.empty?e:e.empty?this:kl(this,e)}mapDesc(e,t=!1){return e.empty?this:fs(this,e,t)}mapPos(e,t=-1,i=he.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=n+l;if(a<0){if(h>e)return r+(e-n);r+=l}else{if(i!=he.Simple&&h>=e&&(i==he.TrackDel&&n<e&&h>e||i==he.TrackBefore&&n<e||i==he.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==n||t<0?r:r+a;r+=a}n=h}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return r}touchesRange(e,t=e){for(let i=0,n=0;i<this.sections.length&&n<=t;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=t&&l>=e)return n<e&&l>t?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new _e(e)}static create(e){return new _e(e)}}class te extends _e{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return cs(this,(t,i,n,r,o)=>e=e.replace(n,n+(i-t),o),!1),e}mapDesc(e,t=!1){return fs(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let n=0,r=0;n<t.length;n+=2){let o=t[n],l=t[n+1];if(l>=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;i.length<a;)i.push(V.empty);i.push(o?e.slice(r,r+o):V.empty)}r+=o}return new te(t,i)}compose(e){return this.empty?e:e.empty?this:kl(this,e,!0)}map(e,t=!1){return e.empty?this:fs(this,e,t,!0)}iterChanges(e,t=!1){cs(this,e,t)}get desc(){return _e.create(this.sections)}filter(e){let t=[],i=[],n=[],r=new mi(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);ae(n,c,-1);let f=r.ins==-1?-1:r.off==0?r.ins:0;ae(t,c,f),f>0&&lt(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);ae(t,c,-1),ae(n,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new te(t,i),filtered:_e.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):n==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let n=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!n.length)return;o<t&&ae(n,t-o,-1);let f=new te(n,r);l=l?l.compose(f.map(l)):f,n=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let f of c)h(f);else if(c instanceof te){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:f,to:u=f,insert:d}=c;if(f>u||f<0||u>t)throw new RangeError(`Invalid change range ${f} to ${u} (in doc of length ${t})`);let p=d?typeof d=="string"?V.of(d.split(i||hs)):d:V.empty,m=p.length;if(f==u&&m==0)return;f<o&&a(),f>o&&ae(n,f-o,-1),ae(n,u-f,m),lt(r,n,p),o=u}}return h(e),a(!l),l}static empty(e){return new te(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let n=0;n<e.length;n++){let r=e[n];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<n;)i.push(V.empty);i[n]=V.of(r.slice(1)),t.push(r[0],i[n].length)}}}return new te(t,i)}static createSet(e,t){return new te(e,t)}}function ae(s,e,t,i=!1){if(e==0&&t<=0)return;let n=s.length-2;n>=0&&t<=0&&t==s[n+1]?s[n]+=e:e==0&&s[n]==0?s[n+1]+=t:i?(s[n]+=e,s[n+1]+=t):s.push(e,t)}function lt(s,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(t);else{for(;s.length<i;)s.push(V.empty);s.push(t)}}function cs(s,e,t){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],a=s.sections[o++];if(a<0)n+=l,r+=l;else{let h=n,c=r,f=V.empty;for(;h+=l,c+=a,a&&i&&(f=f.append(i[o-2>>1])),!(t||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],a=s.sections[o++];e(n,h,r,c,f),n=h,r=c}}}function fs(s,e,t,i=!1){let n=[],r=i?[]:null,o=new mi(s),l=new mi(e);for(let a=-1;;)if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);ae(n,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(ae(n,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(ae(n,0,o.ins),r&&lt(r,n,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let f=Math.min(c,l.len);h+=f,c-=f,l.forward(f)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;ae(n,h,a<o.i?o.ins:0),r&&a<o.i&&lt(r,n,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?te.createSet(n,r):_e.create(n);throw new Error("Mismatched change set lengths")}}function kl(s,e,t=!1){let i=[],n=t?[]:null,r=new mi(s),o=new mi(e);for(let l=!1;;){if(r.done&&o.done)return n?te.createSet(i,n):_e.create(i);if(r.ins==0)ae(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)ae(i,0,o.ins,l),n&&lt(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;ae(i,a,c,l),n&&c&&lt(n,i,o.text)}else o.ins==-1?(ae(i,r.off?0:r.len,a,l),n&&lt(n,i,r.textBit(a))):(ae(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&lt(n,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class mi{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?V.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?V.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class xt{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new xt(i,n,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return b.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return b.range(this.anchor,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(e.anchor,e.head)}static create(e,t,i){return new xt(e,t,i)}}class b{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:b.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(e,t=!0){return b.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,b.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(e.ranges.map(t=>xt.fromJSON(t)),e.main)}static single(e,t=e){return new b([b.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let r=e[n];if(r.empty?r.from<=i:r.from<i)return b.normalized(e.slice(),t);i=r.to}return new b(e,t)}static cursor(e,t=0,i,n){return xt.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(e,t,i,n){let r=(i??16777215)<<6|(n==null?7:Math.min(6,n));return t<e?xt.create(t,e,48|r):xt.create(e,t,(t>e?8:0)|r)}static normalized(e,t=0){let i=e[t];e.sort((n,r)=>n.from-r.from),t=e.indexOf(i);for(let n=1;n<e.length;n++){let r=e[n],o=e[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);n<=t&&t--,e.splice(--n,2,r.anchor>r.head?b.range(a,l):b.range(l,a))}}return new b(e,t)}}function Sl(s,e){for(let t of s.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let sr=0;class O{constructor(e,t,i,n,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=sr++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new O(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:rr),!!e.static,e.enables)}of(e){return new sn([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new sn(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new sn(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function rr(s,e){return s==e||s.length==e.length&&s.every((t,i)=>t===e[i])}class sn{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=sr++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let f of this.dependencies)f=="doc"?a=!0:f=="selection"?h=!0:((t=e[f.id])!==null&&t!==void 0?t:1)&1||c.push(e[f.id]);return{create(f){return f.values[o]=i(f),1},update(f,u){if(a&&u.docChanged||h&&(u.docChanged||u.selection)||us(f,c)){let d=i(f);if(l?!Nr(d,f.values[o],n):!n(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 m=un(u,p);if(this.dependencies.every(g=>g instanceof O?u.facet(g)===f.facet(g):g instanceof ye?u.field(g,!1)==f.field(g,!1):!0)||(l?Nr(d=i(f),m,n):n(d=i(f),m)))return f.values[o]=m,0}else d=i(f);return f.values[o]=d,1}}}}function Nr(s,e,t){if(s.length!=e.length)return!1;for(let i=0;i<s.length;i++)if(!t(s[i],e[i]))return!1;return!0}function us(s,e){let t=!1;for(let i of e)di(s,i)&1&&(t=!0);return t}function pc(s,e,t){let i=t.map(a=>s[a.id]),n=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=s[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let f=un(a,i[c]);if(n[c]==2)for(let u of f)h.push(u);else h.push(f)}return e.combine(h)}return{create(a){for(let h of i)di(a,h);return a.values[o]=l(a),1},update(a,h){if(!us(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=us(a,i),f=h.config.facets[e.id],u=h.facet(e);if(f&&!c&&rr(t,f))return a.values[o]=u,0;let d=l(a);return e.compare(d,u)?(a.values[o]=u,0):(a.values[o]=d,1)}}}const Fr=O.define({static:!0});class ye{constructor(e,t,i,n,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(e){let t=new ye(sr++,e.create,e.update,e.compare||((i,n)=>i===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Fr).find(i=>i.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,n)=>{let r=i.values[t],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,n)=>n.config.address[this.id]!=null?(i.values[t]=n.field(this),0):(i.values[t]=this.create(i),1)}}init(e){return[this,Fr.of({field:this,create:e})]}get extension(){return this}}const wt={lowest:4,low:3,default:2,high:1,highest:0};function ti(s){return e=>new Cl(e,s)}const Bt={highest:ti(wt.highest),high:ti(wt.high),default:ti(wt.default),low:ti(wt.low),lowest:ti(wt.lowest)};class Cl{constructor(e,t){this.inner=e,this.prec=t}}class Pn{of(e){return new ds(this,e)}reconfigure(e){return Pn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class ds{constructor(e,t){this.compartment=e,this.inner=t}}class fn{constructor(e,t,i,n,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],r=Object.create(null),o=new Map;for(let u of gc(e,t,o))u instanceof ye?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),a=[],h=[];for(let u of n)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,m=c&&c[u]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,rr(m,d))a.push(i.facet(p));else{let g=p.combine(d.map(y=>y.value));a.push(i&&p.compare(g,i.facet(p))?i.facet(p):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(y=>g.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(g=>pc(g,p,d))}}let f=h.map(u=>u(l));return new fn(e,o,f,l,a,r)}}function gc(s,e,t){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof ds&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof ds){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof Cl)r(o.inner,o.prec);else if(o instanceof ye)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof sn)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,wt.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(s,wt.default),i.reduce((o,l)=>o.concat(l))}function di(s,e){if(e&1)return 2;let t=e>>1,i=s.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[t]=4;let n=s.computeSlot(s,s.config.dynamicSlots[t]);return s.status[t]=2|n}function un(s,e){return e&1?s.config.staticValues[e>>1]:s.values[e>>1]}const Al=O.define(),ps=O.define({combine:s=>s.some(e=>e),static:!0}),Ml=O.define({combine:s=>s.length?s[0]:void 0,static:!0}),Dl=O.define(),Ol=O.define(),Tl=O.define(),Bl=O.define({combine:s=>s.length?s[0]:!1});class nt{constructor(e,t){this.type=e,this.value=t}static define(){return new mc}}class mc{of(e){return new nt(this,e)}}class yc{constructor(e){this.map=e}of(e){return new F(this,e)}}class F{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new F(this.type,t)}is(e){return this.type==e}static define(e={}){return new yc(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let r=n.map(t);r&&i.push(r)}return i}}F.reconfigure=F.define();F.appendConfig=F.define();class Q{constructor(e,t,i,n,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&Sl(i,t.newLength),r.some(l=>l.type==Q.time)||(this.annotations=r.concat(Q.time.of(Date.now())))}static create(e,t,i,n,r,o){return new Q(e,t,i,n,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(Q.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}Q.time=nt.define();Q.userEvent=nt.define();Q.addToHistory=nt.define();Q.remote=nt.define();function bc(s,e){let t=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==e.length||e[n]>=s[i]))r=s[i++],o=s[i++];else if(n<e.length)r=e[n++],o=e[n++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Pl(s,e,t){var i;let n,r,o;return t?(n=e.changes,r=te.empty(e.changes.length),o=s.changes.compose(e.changes)):(n=e.changes.map(s.changes),r=s.changes.mapDesc(e.changes,!0),o=s.changes.compose(n)),{changes:o,selection:e.selection?e.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:F.mapEffects(s.effects,n).concat(F.mapEffects(e.effects,r)),annotations:s.annotations.length?s.annotations.concat(e.annotations):e.annotations,scrollIntoView:s.scrollIntoView||e.scrollIntoView}}function gs(s,e,t){let i=e.selection,n=Wt(e.annotations);return e.userEvent&&(n=n.concat(Q.userEvent.of(e.userEvent))),{changes:e.changes instanceof te?e.changes:te.of(e.changes||[],t,s.facet(Ml)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Wt(e.effects),annotations:n,scrollIntoView:!!e.scrollIntoView}}function Ll(s,e,t){let i=gs(s,e.length?e[0]:{},s.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Pl(i,gs(s,e[r],o?i.changes.newLength:s.doc.length),o)}let n=Q.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return xc(t?wc(n):n)}function wc(s){let e=s.startState,t=!0;for(let n of e.facet(Dl)){let r=n(s);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:bc(t,r))}if(t!==!0){let n,r;if(t===!1)r=s.changes.invertedDesc,n=te.empty(e.doc.length);else{let o=s.changes.filter(t);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=Q.create(e,n,s.selection&&s.selection.map(r),F.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=e.facet(Ol);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof Q?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof Q?s=r[0]:s=Ll(e,Wt(r),!1)}return s}function xc(s){let e=s.startState,t=e.facet(Tl),i=s;for(let n=t.length-1;n>=0;n--){let r=t[n](s);r&&Object.keys(r).length&&(i=Pl(i,gs(e,r,s.changes.newLength),!0))}return i==s?s:Q.create(e,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const vc=[];function Wt(s){return s==null?vc:Array.isArray(s)?s:[s]}var G=function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s}(G||(G={}));const kc=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let ms;try{ms=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Sc(s){if(ms)return ms.test(s);for(let e=0;e<s.length;e++){let t=s[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||kc.test(t)))return!0}return!1}function Cc(s){return e=>{if(!/\S/.test(e))return G.Space;if(Sc(e))return G.Word;for(let t=0;t<s.length;t++)if(e.indexOf(s[t])>-1)return G.Word;return G.Other}}class H{constructor(e,t,i,n,r,o){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)di(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return di(this,i),un(this,i)}update(...e){return Ll(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:n}=t;for(let l of e.effects)l.is(Pn.reconfigure)?(t&&(n=new Map,t.compartments.forEach((a,h)=>n.set(h,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(F.reconfigure)?(t=null,i=l.value):l.is(F.appendConfig)&&(t=null,i=Wt(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=fn.resolve(i,n,this),r=new H(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(ps)?e.newSelection:e.newSelection.asSingle();new H(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:b.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Wt(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(c);let f=n.mapDesc(h,!0);r.push(a.range.map(f)),n=n.compose(c),o=F.mapEffects(o,c).concat(F.mapEffects(Wt(a.effects),f))}return{changes:n,selection:b.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof te?e:te.of(e,this.doc.length,this.facet(H.lineSeparator))}toText(e){return V.of(e.split(this.facet(H.lineSeparator)||hs))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(di(this,t),un(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof ye&&this.config.address[n.id]!=null&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];n.push(o.init(a=>o.spec.fromJSON(l,a)))}}return H.create({doc:e.doc,selection:b.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=fn.resolve(e.extensions||[],new Map),i=e.doc instanceof V?e.doc:V.of((e.doc||"").split(t.staticFacet(H.lineSeparator)||hs)),n=e.selection?e.selection instanceof b?e.selection:b.single(e.selection.anchor,e.selection.head):b.single(0);return Sl(n,i.length),t.staticFacet(ps)||(n=n.asSingle()),new H(t,i,n,t.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(Bl)}phrase(e,...t){for(let i of this.facet(H.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let r of this.facet(Al))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&n.push(o[e]);return n}charCategorizer(e){return Cc(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=oe(t,o,!1);if(r(t.slice(a,o))!=G.Word)break;o=a}for(;l<n;){let a=oe(t,l);if(r(t.slice(l,a))!=G.Word)break;l=a}return o==l?null:b.range(o+i,l+i)}}H.allowMultipleSelections=ps;H.tabSize=O.define({combine:s=>s.length?s[0]:4});H.lineSeparator=Ml;H.readOnly=Bl;H.phrases=O.define({compare(s,e){let t=Object.keys(s),i=Object.keys(e);return t.length==i.length&&t.every(n=>s[n]==e[n])}});H.languageData=Al;H.changeFilter=Dl;H.transactionFilter=Ol;H.transactionExtender=Tl;Pn.reconfigure=F.define();function Pt(s,e,t={}){let i={};for(let n of s)for(let r of Object.keys(n)){let o=n[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let n in e)i[n]===void 0&&(i[n]=e[n]);return i}class Ct{eq(e){return this==e}range(e,t=e){return ys.create(e,t,this)}}Ct.prototype.startSide=Ct.prototype.endSide=0;Ct.prototype.point=!1;Ct.prototype.mapMode=he.TrackDel;let ys=class Rl{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Rl(e,t,i)}};function bs(s,e){return s.from-e.from||s.value.startSide-e.value.startSide}class or{constructor(e,t,i,n){this.from=e,this.to=t,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,n=0){let r=i?this.to:this.from;for(let o=n,l=r.length;;){if(o==l)return o;let a=o+l>>1,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,n){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(n(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],n=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],c=this.from[a]+e,f=this.to[a]+e,u,d;if(c==f){let p=t.mapPos(c,h.startSide,h.mapMode);if(p==null||(u=d=p,h.startSide!=h.endSide&&(d=t.mapPos(c,h.endSide),d<u)))continue}else if(u=t.mapPos(c,h.startSide),d=t.mapPos(f,h.endSide),u>d||u==d&&h.startSide>0&&h.endSide<=0)continue;(d-u||h.endSide-h.startSide)<0||(o<0&&(o=u),h.point&&(l=Math.max(l,d-u)),i.push(h),n.push(u-o),r.push(d-o))}return{mapped:i.length?new or(n,r,i,l):null,pos:o}}}class ${constructor(e,t,i,n){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=n}static create(e,t,i,n){return new $(e,t,i,n)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:n=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(bs)),this.isEmpty)return t.length?$.of(t):this;let l=new El(this,null,-1).goto(0),a=0,h=[],c=new At;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let f=t[a++];c.addInner(f.from,f.to,f.value)||h.push(f)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||n>l.to||r<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value)||h.push(ys.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?$.empty:this.nextLayer.update({add:h,filter:o,filterFrom:n,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)n=Math.max(n,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:c,pos:f}=a.map(l,e);c&&(n=Math.max(n,c.maxPoint),t.push(c),i.push(f))}}let r=this.nextLayer.map(e);return t.length==0?r:new $(i,t,r||$.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return yi.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return yi.from(e).goto(t)}static compare(e,t,i,n,r=-1){let o=e.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),l=t.filter(f=>f.maxPoint>0||!f.isEmpty&&f.maxPoint>=r),a=Vr(o,l,i),h=new ii(o,a,r),c=new ii(l,a,r);i.iterGaps((f,u,d)=>Wr(h,f,c,u,d,n)),i.empty&&i.length==0&&Wr(h,0,c,0,0,n)}static eq(e,t,i=0,n){n==null&&(n=999999999);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Vr(r,o),a=new ii(r,l,0).goto(i),h=new ii(o,l,0).goto(i);for(;;){if(a.to!=h.to||!ws(a.active,h.active)||a.point&&(!h.point||!a.point.eq(h.point)))return!1;if(a.to>n)return!0;a.next(),h.next()}}static spans(e,t,i,n,r=-1){let o=new ii(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),f=o.pointFrom<t?c.length+1:Math.min(c.length,a);n.point(l,h,o.point,c,f,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(n.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new At;for(let n of e instanceof ys?[e]:t?Ac(e):e)i.add(n.from,n.to,n.value);return i.finish()}static join(e){if(!e.length)return $.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let n=e[i];n!=$.empty;n=n.nextLayer)t=new $(n.chunkPos,n.chunk,t,Math.max(n.maxPoint,t.maxPoint));return t}}$.empty=new $([],[],null,-1);function Ac(s){if(s.length>1)for(let e=s[0],t=1;t<s.length;t++){let i=s[t];if(bs(e,i)>0)return s.slice().sort(bs);e=i}return s}$.empty.nextLayer=$.empty;class At{finishChunk(e){this.chunks.push(new or(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new At)).add(e,t,i)}addInner(e,t,i){let n=e-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return n<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner($.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=$.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Vr(s,e,t){let i=new Map;for(let r of s)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let n=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!(t!=null&&t.touchesRange(l,l+r.chunk[o].length))&&n.add(r.chunk[o])}return n}class El{constructor(e,t,i,n=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<e||n.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class yi{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new El(o,t,i,r));return n.length==1?n[0]:new yi(n)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)$n(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)$n(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),$n(this.heap,0)}}}function $n(s,e){for(let t=s[e];;){let i=(e<<1)+1;if(i>=s.length)break;let n=s[i];if(i+1<s.length&&n.compare(s[i+1])>=0&&(n=s[i+1],i++),t.compare(n)<0)break;s[i]=t,s[e]=n,e=i}}class ii{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=yi.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Ni(this.active,e),Ni(this.activeTo,e),Ni(this.activeRank,e),this.minActive=Hr(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||n-this.activeTo[t])>0;)t++;Fi(this.active,t,i),Fi(this.activeTo,t,n),Fi(this.activeRank,t,r),e&&Fi(e,t,this.cursor.from),this.minActive=Hr(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Ni(i,n)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let n=i.length-1;n>=0&&i[n]<e;n--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function Wr(s,e,t,i,n,r){s.goto(e),t.goto(i);let o=i+n,l=i,a=i-e;for(;;){let h=s.to+a-t.to||s.endSide-t.endSide,c=h<0?s.to+a:t.to,f=Math.min(c,o);if(s.point||t.point?s.point&&t.point&&(s.point==t.point||s.point.eq(t.point))&&ws(s.activeForPoint(s.to),t.activeForPoint(t.to))||r.comparePoint(l,f,s.point,t.point):f>l&&!ws(s.active,t.active)&&r.compareRange(l,f,s.active,t.active),c>o)break;l=c,h<=0&&s.next(),h>=0&&t.next()}}function ws(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++)if(s[t]!=e[t]&&!s[t].eq(e[t]))return!1;return!0}function Ni(s,e){for(let t=e,i=s.length-1;t<i;t++)s[t]=s[t+1];s.pop()}function Fi(s,e,t){for(let i=s.length-1;i>=e;i--)s[i+1]=s[i];s[e]=t}function Hr(s,e){let t=-1,i=1e9;for(let n=0;n<e.length;n++)(e[n]-i||s[n].endSide-s[t].endSide)<0&&(t=n,i=e[n]);return t}function _t(s,e,t=s.length){let i=0;for(let n=0;n<t;)s.charCodeAt(n)==9?(i+=e-i%e,n++):(i++,n=oe(s,n));return i}function xs(s,e,t,i){for(let n=0,r=0;;){if(r>=e)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?t-r%t:1,n=oe(s,n)}return i===!0?-1:s.length}const vs="ͼ",zr=typeof Symbol>"u"?"__"+vs:Symbol.for(vs),ks=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),qr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class ut{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(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(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),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(n(d),p,c,u)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||u)&&a.push((i&&!f&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(n(o),e[o],this.rules)}getRules(){return this.rules.join(`
`)}static newName(){let e=qr[zr]||1;return qr[zr]=e+1,vs+e.toString(36)}static mount(e,t,i){let n=e[ks],r=i&&i.nonce;n?r&&n.setNonce(r):n=new Mc(e,r),n.mount(Array.isArray(t)?t:[t])}}let $r=new Map;class Mc{constructor(e,t){let i=e.ownerDocument||e,n=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&n.CSSStyleSheet){let r=$r.get(i);if(r)return e.adoptedStyleSheets=[r.sheet,...e.adoptedStyleSheets],e[ks]=r;this.sheet=new n.CSSStyleSheet,e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets],$r.set(i,this)}else{this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);let r=e.head||e;r.insertBefore(this.styleTag,r.firstChild)}this.modules=[],e[ks]=this}mount(e){let t=this.sheet,i=0,n=0;for(let r=0;r<e.length;r++){let o=e[r],l=this.modules.indexOf(o);if(l<n&&l>-1&&(this.modules.splice(l,1),n--,l=-1),l==-1){if(this.modules.splice(n++,0,o),t)for(let a=0;a<o.rules.length;a++)t.insertRule(o.rules[a],i++)}else{for(;n<l;)i+=this.modules[n++].rules.length;i+=o.rules.length,n++}}if(!t){let r="";for(let o=0;o<this.modules.length;o++)r+=this.modules[o].getRules()+`
`;this.styleTag.textContent=r}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var dt={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:"'"},bi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Dc=typeof navigator<"u"&&/Mac/.test(navigator.platform),Oc=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var se=0;se<10;se++)dt[48+se]=dt[96+se]=String(se);for(var se=1;se<=24;se++)dt[se+111]="F"+se;for(var se=65;se<=90;se++)dt[se]=String.fromCharCode(se+32),bi[se]=String.fromCharCode(se);for(var Kn in dt)bi.hasOwnProperty(Kn)||(bi[Kn]=dt[Kn]);function Tc(s){var e=Dc&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||Oc&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",t=!e&&s.key||(s.shiftKey?bi:dt)[s.keyCode]||s.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function dn(s){let e;return s.nodeType==11?e=s.getSelection?s:s.ownerDocument:e=s,e.getSelection()}function Ss(s,e){return e?s==e||s.contains(e.nodeType!=1?e.parentNode:e):!1}function Bc(s){let e=s.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function rn(s,e){if(!e.anchorNode)return!1;try{return Ss(s,e.anchorNode)}catch{return!1}}function jt(s){return s.nodeType==3?Mt(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function pi(s,e,t,i){return t?Kr(s,e,t,i,-1)||Kr(s,e,t,i,1):!1}function wi(s){for(var e=0;;e++)if(s=s.previousSibling,!s)return e}function Kr(s,e,t,i,n){for(;;){if(s==t&&e==i)return!0;if(e==(n<0?0:et(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;e=wi(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[e+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;e=n<0?et(s):0}else return!1}}function et(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function Ln(s,e){let t=e?s.left:s.right;return{left:t,right:t,top:s.top,bottom:s.bottom}}function Pc(s){return{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function Il(s,e){let t=e.width/s.offsetWidth,i=e.height/s.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-s.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-s.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function Lc(s,e,t,i,n,r,o,l){let a=s.ownerDocument,h=a.defaultView||window;for(let c=s,f=!1;c&&!f;)if(c.nodeType==1){let u,d=c==a.body,p=1,m=1;if(d)u=Pc(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 w=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Il(c,w)),u={left:w.left,right:w.left+c.clientWidth*p,top:w.top,bottom:w.top+c.clientHeight*m}}let g=0,y=0;if(n=="nearest")e.top<u.top?(y=-(u.top-e.top+o),t>0&&e.bottom>u.bottom+y&&(y=e.bottom-u.bottom+y+o)):e.bottom>u.bottom&&(y=e.bottom-u.bottom+o,t<0&&e.top-y<u.top&&(y=-(u.top+y-e.top+o)));else{let w=e.bottom-e.top,S=u.bottom-u.top;y=(n=="center"&&w<=S?e.top+w/2-S/2:n=="start"||n=="center"&&t<0?e.top-o:e.bottom-S+o)-u.top}if(i=="nearest"?e.left<u.left?(g=-(u.left-e.left+r),t>0&&e.right>u.right+g&&(g=e.right-u.right+g+r)):e.right>u.right&&(g=e.right-u.right+r,t<0&&e.left<u.left+g&&(g=-(u.left+g-e.left+r))):g=(i=="center"?e.left+(e.right-e.left)/2-(u.right-u.left)/2:i=="start"==l?e.left-r:e.right-(u.right-u.left)+r)-u.left,g||y)if(d)h.scrollBy(g,y);else{let w=0,S=0;if(y){let v=c.scrollTop;c.scrollTop+=y/m,S=(c.scrollTop-v)*m}if(g){let v=c.scrollLeft;c.scrollLeft+=g/p,w=(c.scrollLeft-v)*p}e={left:e.left-w,top:e.top-S,right:e.right-w,bottom:e.bottom-S},w&&Math.abs(w-g)<1&&(i="nearest"),S&&Math.abs(S-y)<1&&(n="nearest")}if(d)break;c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Rc(s){let e=s.ownerDocument;for(let t=s.parentNode;t&&t!=e.body;)if(t.nodeType==1){if(t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)return t;t=t.assignedSlot||t.parentNode}else if(t.nodeType==11)t=t.host;else break;return null}class Ec{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?et(t):0),i,Math.min(e.focusOffset,i?et(i):0))}set(e,t,i,n){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=n}}let Et=null;function Nl(s){if(s.setActive)return s.setActive();if(Et)return s.focus(Et);let e=[];for(let t=s;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(s.focus(Et==null?{get preventScroll(){return Et={preventScroll:!0},!0}}:void 0),!Et){Et=!1;for(let t=0;t<e.length;){let i=e[t++],n=e[t++],r=e[t++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let jr;function Mt(s,e,t=e){let i=jr||(jr=document.createRange());return i.setEnd(s,t),i.setStart(s,e),i}function Ht(s,e,t){let i={key:e,code:e,keyCode:t,which:t,cancelable:!0},n=new KeyboardEvent("keydown",i);n.synthetic=!0,s.dispatchEvent(n);let r=new KeyboardEvent("keyup",i);return r.synthetic=!0,s.dispatchEvent(r),n.defaultPrevented||r.defaultPrevented}function Ic(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Fl(s){for(;s.attributes.length;)s.removeAttributeNode(s.attributes[0])}function Nc(s,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,et(t));;)if(i){if(t.nodeType!=1)return!1;let n=t.childNodes[i-1];n.contentEditable=="false"?i--:(t=n,i=et(t))}else{if(t==s)return!0;i=wi(t),t=t.parentNode}}function Vl(s){return s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}class ce{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new ce(e.parentNode,wi(e),t)}static after(e,t){return new ce(e.parentNode,wi(e)+1,t)}}const lr=[];class U{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e){let t=this.posAtStart;for(let i of this.children){if(i==e)return t;t+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}sync(e,t){if(this.flags&2){let i=this.dom,n=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=n?n.nextSibling:i.firstChild)){let l=U.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(e,t),o.flags&=-8}if(r=n?n.nextSibling:i.firstChild,t&&!t.written&&t.node==i&&r!=o.dom&&(t.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=Ur(r);else i.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:i.firstChild,r&&t&&t.node==i&&(t.written=!0);r;)r=Ur(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(e,t),i.flags&=-8)}reuseDOM(e){}localPosFromDOM(e,t){let i;if(e==this.dom)i=this.dom.childNodes[t];else{let n=et(e)==0?0:t==0?-1:1;for(;;){let r=e.parentNode;if(r==this.dom)break;n==0&&r.firstChild!=r.lastChild&&(e==r.firstChild?n=-1:n=1),e=r}n<0?i=e:i=e.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!U.get(i);)i=i.nextSibling;if(!i)return this.length;for(let n=0,r=0;;n++){let o=this.children[n];if(o.dom==i)return r;r+=o.length+o.breakAfter}}domBoundsAround(e,t,i=0){let n=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<this.children.length;a++){let f=this.children[a],u=h+f.length;if(h<e&&u>t)return f.domBoundsAround(e,t,h);if(u>=e&&n==-1&&(n=a,r=h),h>t&&f.dom.parentNode==this.dom){o=a,l=c;break}c=u,h=u+f.breakAfter}return{from:r,to:l<0?i+this.length:l,startDOM:(n?this.children[n-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:o<this.children.length&&o>=0?this.children[o].dom:null}}markDirty(e=!1){this.flags|=2,this.markParentsDirty(e)}markParentsDirty(e){for(let t=this.parent;t;t=t.parent){if(e&&(t.flags|=2),t.flags&1)return;t.flags|=1,e=!1}}setParent(e){this.parent!=e&&(this.parent=e,this.flags&7&&this.markParentsDirty(!0))}setDOM(e){this.dom!=e&&(this.dom&&(this.dom.cmView=null),this.dom=e,e.cmView=this)}get rootView(){for(let e=this;;){let t=e.parent;if(!t)return e;e=t}}replaceChildren(e,t,i=lr){this.markDirty();for(let n=e;n<t;n++){let r=this.children[n];r.parent==this&&i.indexOf(r)<0&&r.destroy()}this.children.splice(e,t-e,...i);for(let n=0;n<i.length;n++)i[n].setParent(this)}ignoreMutation(e){return!1}ignoreEvent(e){return!1}childCursor(e=this.length){return new Wl(this.children,e,this.children.length)}childPos(e,t=1){return this.childCursor().findPos(e,t)}toString(){let e=this.constructor.name.replace("View","");return e+(this.children.length?"("+this.children.join()+")":this.length?"["+(e=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(e){return e.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(e,t,i,n,r,o){return!1}become(e){return!1}canReuseDOM(e){return e.constructor==this.constructor&&!((this.flags|e.flags)&8)}getSide(){return 0}destroy(){for(let e of this.children)e.parent==this&&e.destroy();this.parent=null}}U.prototype.breakAfter=0;function Ur(s){let e=s.nextSibling;return s.parentNode.removeChild(s),e}class Wl{constructor(e,t,i){this.children=e,this.pos=t,this.i=i,this.off=0}findPos(e,t=1){for(;;){if(e>this.pos||e==this.pos&&(t>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=e-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Hl(s,e,t,i,n,r,o,l,a){let{children:h}=s,c=h.length?h[e]:null,f=r.length?r[r.length-1]:null,u=f?f.breakAfter:o;if(!(e==i&&c&&!o&&!u&&r.length<2&&c.merge(t,n,r.length?f:null,t==0,l,a))){if(i<h.length){let d=h[i];d&&(n<d.length||d.breakAfter&&(f!=null&&f.breakAfter))?(e==i&&(d=d.split(n),n=0),!u&&f&&d.merge(0,n,f,!0,0,a)?r[r.length-1]=d:((n||d.children.length&&!d.children[0].length)&&d.merge(0,n,null,!1,0,a),r.push(d))):d!=null&&d.breakAfter&&(f?f.breakAfter=1:o=1),i++}for(c&&(c.breakAfter=o,t>0&&(!o&&r.length&&c.merge(t,c.length,r[0],!1,l,0)?c.breakAfter=r.shift().breakAfter:(t<c.length||c.children.length&&c.children[c.children.length-1].length==0)&&c.merge(t,c.length,null,!1,l,0),e++));e<i&&r.length;)if(h[i-1].become(r[r.length-1]))i--,r.pop(),a=r.length?0:l;else if(h[e].become(r[0]))e++,r.shift(),l=r.length?0:a;else break;!r.length&&e&&i<h.length&&!h[e-1].breakAfter&&h[i].merge(0,0,h[e-1],!1,l,a)&&e--,(e<i||r.length)&&s.replaceChildren(e,i,r)}}function zl(s,e,t,i,n,r){let o=s.childCursor(),{i:l,off:a}=o.findPos(t,1),{i:h,off:c}=o.findPos(e,-1),f=e-t;for(let u of i)f+=u.length;s.length+=f,Hl(s,h,c,l,a,i,0,n,r)}let Me=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Cs=typeof document<"u"?document:{documentElement:{style:{}}};const As=/Edge\/(\d+)/.exec(Me.userAgent),ql=/MSIE \d/.test(Me.userAgent),Ms=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Me.userAgent),Rn=!!(ql||Ms||As),Gr=!Rn&&/gecko\/(\d+)/i.test(Me.userAgent),jn=!Rn&&/Chrome\/(\d+)/.exec(Me.userAgent),Jr="webkitFontSmoothing"in Cs.documentElement.style,$l=!Rn&&/Apple Computer/.test(Me.vendor),Yr=$l&&(/Mobile\/\w+/.test(Me.userAgent)||Me.maxTouchPoints>2);var D={mac:Yr||/Mac/.test(Me.platform),windows:/Win/.test(Me.platform),linux:/Linux|X11/.test(Me.platform),ie:Rn,ie_version:ql?Cs.documentMode||6:Ms?+Ms[1]:As?+As[1]:0,gecko:Gr,gecko_version:Gr?+(/Firefox\/(\d+)/.exec(Me.userAgent)||[0,0])[1]:0,chrome:!!jn,chrome_version:jn?+jn[1]:0,ios:Yr,android:/Android\b/.test(Me.userAgent),webkit:Jr,safari:$l,webkit_version:Jr?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:Cs.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const Fc=256;class tt extends U{constructor(e){super(),this.text=e}get length(){return this.text.length}createDOM(e){this.setDOM(e||document.createTextNode(this.text))}sync(e,t){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(t&&t.node==this.dom&&(t.written=!0),this.dom.nodeValue=this.text)}reuseDOM(e){e.nodeType==3&&this.createDOM(e)}merge(e,t,i){return this.flags&8||i&&(!(i instanceof tt)||this.length-(t-e)+i.length>Fc||i.flags&8)?!1:(this.text=this.text.slice(0,e)+(i?i.text:"")+this.text.slice(t),this.markDirty(),!0)}split(e){let t=new tt(this.text.slice(e));return this.text=this.text.slice(0,e),this.markDirty(),t.flags|=this.flags&8,t}localPosFromDOM(e,t){return e==this.dom?t:t?this.text.length:0}domAtPos(e){return new ce(this.dom,e)}domBoundsAround(e,t,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(e,t){return Vc(this.dom,e,t)}}class it extends U{constructor(e,t=[],i=0){super(),this.mark=e,this.children=t,this.length=i;for(let n of t)n.setParent(this)}setAttrs(e){if(Fl(e),this.mark.class&&(e.className=this.mark.class),this.mark.attrs)for(let t in this.mark.attrs)e.setAttribute(t,this.mark.attrs[t]);return e}canReuseDOM(e){return super.canReuseDOM(e)&&!((this.flags|e.flags)&8)}reuseDOM(e){e.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(e),this.flags|=6)}sync(e,t){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(e,t)}merge(e,t,i,n,r,o){return i&&(!(i instanceof it&&i.mark.eq(this.mark))||e&&r<=0||t<this.length&&o<=0)?!1:(zl(this,e,t,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(e){let t=[],i=0,n=-1,r=0;for(let l of this.children){let a=i+l.length;a>e&&t.push(i<e?l.split(e-i):l),n<0&&i>=e&&(n=r),i=a,r++}let o=this.length-e;return this.length=e,n>-1&&(this.children.length=n,this.markDirty()),new it(this.mark,t,o)}domAtPos(e){return Kl(this,e)}coordsAt(e,t){return Ul(this,e,t)}}function Vc(s,e,t){let i=s.nodeValue.length;e>i&&(e=i);let n=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?D.chrome||D.gecko||(e?(n--,o=1):r<i&&(r++,o=-1)):t<0?n--:r<i&&r++;let l=Mt(s,n,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return D.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Ln(a,o<0):a||null}class vt extends U{static create(e,t,i){return new vt(e,t,i)}constructor(e,t,i){super(),this.widget=e,this.length=t,this.side=i,this.prevWidget=null}split(e){let t=vt.create(this.widget,this.length-e,this.side);return this.length-=e,t}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(e,t,i,n,r,o){return i&&(!(i instanceof vt)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}become(e){return e instanceof vt&&e.side==this.side&&this.widget.constructor==e.widget.constructor?(this.widget.compare(e.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get overrideDOMText(){if(this.length==0)return V.empty;let e=this;for(;e.parent;)e=e.parent;let{view:t}=e,i=t&&t.state.doc,n=this.posAtStart;return i?i.slice(n,n+this.length):V.empty}domAtPos(e){return(this.length?e==0:this.side>0)?ce.before(this.dom):ce.after(this.dom,e==this.length)}domBoundsAround(){return null}coordsAt(e,t){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:e>0;for(let l=o?n.length-1:0;r=n[l],!(e>0?l==0:l==n.length-1||r.top<r.bottom);l+=o?-1:1);return Ln(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 Ut extends U{constructor(e){super(),this.side=e}get length(){return 0}merge(){return!1}become(e){return e instanceof Ut&&e.side==this.side}split(){return new Ut(this.side)}sync(){if(!this.dom){let e=document.createElement("img");e.className="cm-widgetBuffer",e.setAttribute("aria-hidden","true"),this.setDOM(e)}}getSide(){return this.side}domAtPos(e){return this.side>0?ce.before(this.dom):ce.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(e){return this.dom.getBoundingClientRect()}get overrideDOMText(){return V.empty}get isHidden(){return!0}}tt.prototype.children=vt.prototype.children=Ut.prototype.children=lr;function Kl(s,e){let t=s.dom,{children:i}=s,n=0;for(let r=0;n<i.length;n++){let o=i[n],l=r+o.length;if(!(l==r&&o.getSide()<=0)){if(e>r&&e<l&&o.dom.parentNode==t)return o.domAtPos(e-r);if(e<=r)break;r=l}}for(let r=n;r>0;r--){let o=i[r-1];if(o.dom.parentNode==t)return o.domAtPos(o.length)}for(let r=n;r<i.length;r++){let o=i[r];if(o.dom.parentNode==t)return o.domAtPos(0)}return new ce(t,0)}function jl(s,e,t){let i,{children:n}=s;t>0&&e instanceof it&&n.length&&(i=n[n.length-1])instanceof it&&i.mark.eq(e.mark)?jl(i,e.children[0],t-1):(n.push(e),e.setParent(s)),s.length+=e.length}function Ul(s,e,t){let i=null,n=-1,r=null,o=-1;function l(h,c){for(let f=0,u=0;f<h.children.length&&u<=c;f++){let d=h.children[f],p=u+d.length;p>=c&&(d.children.length?l(d,c-u):(!r||r.isHidden&&t>0)&&(p>c||u==p&&d.getSide()>0)?(r=d,o=c-u):(u<c||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,n=c-u)),u=p}}l(s,e);let a=(t<0?i:r)||i||r;return a?a.coordsAt(Math.max(0,a==i?n:o),t):Wc(s)}function Wc(s){let e=s.dom.lastChild;if(!e)return s.dom.getBoundingClientRect();let t=jt(e);return t[t.length-1]||null}function Ds(s,e){for(let t in s)t=="class"&&e.class?e.class+=" "+s.class:t=="style"&&e.style?e.style+=";"+s.style:e[t]=s[t];return e}const Xr=Object.create(null);function ar(s,e,t){if(s==e)return!0;s||(s=Xr),e||(e=Xr);let i=Object.keys(s),n=Object.keys(e);if(i.length-(t&&i.indexOf(t)>-1?1:0)!=n.length-(t&&n.indexOf(t)>-1?1:0))return!1;for(let r of i)if(r!=t&&(n.indexOf(r)==-1||s[r]!==e[r]))return!1;return!0}function Os(s,e,t){let i=!1;if(e)for(let n in e)t&&n in t||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(t)for(let n in t)e&&e[n]==t[n]||(i=!0,n=="style"?s.style.cssText=t[n]:s.setAttribute(n,t[n]));return i}function Hc(s){let e=Object.create(null);for(let t=0;t<s.attributes.length;t++){let i=s.attributes[t];e[i.name]=i.value}return e}class ee extends U{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(e,t,i,n,r,o){if(i){if(!(i instanceof ee))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),zl(this,e,t,i?i.children.slice():[],r,o),!0}split(e){let t=new ee;if(t.breakAfter=this.breakAfter,this.length==0)return t;let{i,off:n}=this.childPos(e);n&&(t.append(this.children[i].split(n),0),this.children[i].merge(n,this.children[i].length,null,!1,0,0),i++);for(let r=i;r<this.children.length;r++)t.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=e,t}transferDOM(e){this.dom&&(this.markDirty(),e.setDOM(this.dom),e.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(e){ar(this.attrs,e)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=e)}append(e,t){jl(this,e,t)}addLineDeco(e){let t=e.spec.attributes,i=e.spec.class;t&&(this.attrs=Ds(t,this.attrs||{})),i&&(this.attrs=Ds({class:i},this.attrs||{}))}domAtPos(e){return Kl(this,e)}reuseDOM(e){e.nodeName=="DIV"&&(this.setDOM(e),this.flags|=6)}sync(e,t){var i;this.dom?this.flags&4&&(Fl(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&&(Os(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(e,t);let n=this.dom.lastChild;for(;n&&U.get(n)instanceof it;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=U.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!D.ios||!this.children.some(r=>r instanceof tt))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let e=0,t;for(let i of this.children){if(!(i instanceof tt)||/[^ -~]/.test(i.text))return null;let n=jt(i.dom);if(n.length!=1)return null;e+=n[0].width,t=n[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(e,t){let i=Ul(this,e,t);if(!this.children.length&&i&&this.parent){let{heightOracle:n}=this.parent.view.viewState,r=i.bottom-i.top;if(Math.abs(r-n.lineHeight)<2&&n.textHeight<r){let o=(r-n.textHeight)/2;return{top:i.top+o,bottom:i.bottom-o,left:i.left,right:i.left}}}return i}become(e){return!1}covers(){return!0}static find(e,t){for(let i=0,n=0;i<e.children.length;i++){let r=e.children[i],o=n+r.length;if(o>=t){if(r instanceof ee)return r;if(o>t)break}n=o+r.breakAfter}return null}}class ht extends U{constructor(e,t,i){super(),this.widget=e,this.length=t,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(e,t,i,n,r,o){return i&&(!(i instanceof ht)||!this.widget.compare(i.widget)||e>0&&r<=0||t<this.length&&o<=0)?!1:(this.length=e+(i?i.length:0)+(this.length-t),!0)}domAtPos(e){return e==0?ce.before(this.dom):ce.after(this.dom,e==this.length)}split(e){let t=this.length-e;this.length=e;let i=new ht(this.widget,t,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return lr}sync(e){(!this.dom||!this.widget.updateDOM(this.dom,e))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(e)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):V.empty}domBoundsAround(){return null}become(e){return e instanceof ht&&e.widget.constructor==this.widget.constructor?(e.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=e.widget,this.length=e.length,this.deco=e.deco,this.breakAfter=e.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(e){return this.widget.ignoreEvent(e)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(e,t){return this.widget.coordsAt(this.dom,e,t)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(e){let{startSide:t,endSide:i}=this.deco;return t==i?!1:e<0?t<0:i>0}}class Lt{eq(e){return!1}updateDOM(e,t){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var De=function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s}(De||(De={}));class B extends Ct{constructor(e,t,i,n){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(e){return new Ti(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new pt(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,n;if(e.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=Gl(e,t);i=(r?t?-3e8:-1:5e8)-1,n=(o?t?2e8:1:-6e8)+1}return new pt(e,i,n,t,e.widget||null,!0)}static line(e){return new Bi(e)}static set(e,t=!1){return $.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}B.none=$.empty;class Ti extends B{constructor(e){let{start:t,end:i}=Gl(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.class=e.class||"",this.attrs=e.attributes||null}eq(e){var t,i;return this==e||e instanceof Ti&&this.tagName==e.tagName&&(this.class||((t=this.attrs)===null||t===void 0?void 0:t.class))==(e.class||((i=e.attrs)===null||i===void 0?void 0:i.class))&&ar(this.attrs,e.attrs,"class")}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}Ti.prototype.point=!1;class Bi extends B{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Bi&&this.spec.class==e.spec.class&&ar(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}Bi.prototype.mapMode=he.TrackBefore;Bi.prototype.point=!0;class pt extends B{constructor(e,t,i,n,r,o){super(t,i,r,e),this.block=n,this.isReplace=o,this.mapMode=n?t<=0?he.TrackBefore:he.TrackAfter:he.TrackDel}get type(){return this.startSide!=this.endSide?De.WidgetRange:this.startSide<=0?De.WidgetBefore:De.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof pt&&zc(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}pt.prototype.point=!0;function Gl(s,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=s;return t==null&&(t=s.inclusive),i==null&&(i=s.inclusive),{start:t??e,end:i??e}}function zc(s,e){return s==e||!!(s&&e&&s.compare(e))}function Ts(s,e,t,i=0){let n=t.length-1;n>=0&&t[n]+i>=s?t[n]=Math.max(t[n],e):t.push(s,e)}class gi{constructor(e,t,i,n){this.doc=e,this.pos=t,this.end=i,this.disallowBlockEffectsFor=n,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=e.iter(),this.skip=t}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let e=this.content[this.content.length-1];return!(e.breakAfter||e instanceof ht&&e.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new ee),this.atCursorPos=!0),this.curLine}flushBuffer(e=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Vi(new Ut(-1),e),e.length),this.pendingBuffer=0)}addBlockWidget(e){this.flushBuffer(),this.curLine=null,this.content.push(e)}finish(e){this.pendingBuffer&&e<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(e&&this.content.length&&this.content[this.content.length-1]instanceof ht)&&this.getLine()}buildText(e,t,i){for(;e>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,e--;continue}else this.text=r,this.textOff=0}let n=Math.min(this.text.length-this.textOff,e,512);this.flushBuffer(t.slice(t.length-i)),this.getLine().append(Vi(new tt(this.text.slice(this.textOff,this.textOff+n)),t),i),this.atCursorPos=!0,this.textOff+=n,e-=n,i=0}}span(e,t,i,n){this.buildText(t-e,i,n),this.pos=t,this.openStart<0&&(this.openStart=n)}point(e,t,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof pt){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(t>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=t-e;if(i instanceof pt)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new ht(i.widget||new _r("div"),l,i));else{let a=vt.create(i.widget||new _r("span"),l,l?0:i.startSide),h=this.atCursorPos&&!a.isEditable&&r<=n.length&&(e<t||i.startSide>0),c=!a.isEditable&&(e<t||r>n.length||i.startSide<=0),f=this.getLine();this.pendingBuffer==2&&!h&&!a.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),h&&(f.append(Vi(new Ut(1),n),r),r=n.length+Math.max(0,r-n.length)),f.append(Vi(a,n),r),this.atCursorPos=c,this.pendingBuffer=c?e<t||r>n.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=n.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);l&&(this.textOff+l<=this.text.length?this.textOff+=l:(this.skip+=l-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=t),this.openStart<0&&(this.openStart=r)}static build(e,t,i,n,r){let o=new gi(e,t,i,r);return o.openEnd=$.spans(n,t,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Vi(s,e){for(let t of e)s=new it(t,[s],s.length);return s}class _r extends Lt{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}var X=function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s}(X||(X={}));const Dt=X.LTR,hr=X.RTL;function Jl(s){let e=[];for(let t=0;t<s.length;t++)e.push(1<<+s[t]);return e}const qc=Jl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),$c=Jl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Bs=Object.create(null),ze=[];for(let s of["()","[]","{}"]){let e=s.charCodeAt(0),t=s.charCodeAt(1);Bs[e]=t,Bs[t]=-e}function Yl(s){return s<=247?qc[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?$c[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const Kc=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class at{get dir(){return this.level%2?hr:Dt}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,n){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Xl(s,e){if(s.length!=e.length)return!1;for(let t=0;t<s.length;t++){let i=s[t],n=e[t];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!Xl(i.inner,n.inner))return!1}return!0}const q=[];function jc(s,e,t,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:n;for(let h=o,c=a,f=a;h<l;h++){let u=Yl(s.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<t&&q[d]==8?f==1?1:8:256;for(let m=h;m<d;m++)q[m]=p;h=d-1}else u==8&&f==1&&(q[h]=1);c=u,u&7&&(f=u)}}}function Uc(s,e,t,i,n){let r=n==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,c=o<i.length?i[o].from:t;for(let f=h,u,d,p;f<c;f++)if(d=Bs[u=s.charCodeAt(f)])if(d<0){for(let m=l-3;m>=0;m-=3)if(ze[m+1]==-d){let g=ze[m+2],y=g&2?n:g&4?g&1?r:n:0;y&&(q[f]=q[ze[m]]=y),l=m;break}}else{if(ze.length==189)break;ze[l++]=f,ze[l++]=u,ze[l++]=a}else if((p=q[f])==2||p==1){let m=p==n;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=ze[g+2];if(y&2)break;if(m)ze[g+2]|=2;else{if(y&4)break;ze[g+2]|=4}}}}}function Gc(s,e,t,i){for(let n=0,r=i;n<=t.length;n++){let o=n?t[n-1].to:s,l=n<t.length?t[n].from:e;for(let a=o;a<l;){let h=q[a];if(h==256){let c=a+1;for(;;)if(c==l){if(n==t.length)break;c=t[n++].to,l=n<t.length?t[n].from:e}else if(q[c]==256)c++;else break;let f=r==1,u=(c<e?q[c]:i)==1,d=f==u?f?1:2:i;for(let p=c,m=n,g=m?t[m-1].to:s;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:s),q[--p]=d;a=c}else r=h,a++}}}function Ps(s,e,t,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let a=e,h=0;a<t;){let c=!0,f=!1;if(h==r.length||a<r[h].from){let m=q[a];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(f)break e;let m=r[h];if(!c)for(let g=m.to,y=h+1;;){if(g==t)break e;if(y<r.length&&r[y].from==g)g=r[y++].to;else{if(q[g]==l)break e;break}}if(h++,u)u.push(m);else{m.from>a&&o.push(new at(a,m.from,d));let g=m.direction==Dt!=!(d%2);Ls(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?q[p]!=l:q[p]==l))break;p++}u?Ps(s,a,p,i+1,n,u,o):a<p&&o.push(new at(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let c=!0,f=!1;if(!h||a>r[h-1].to){let m=q[a-1];m!=l&&(c=!1,f=m==16)}let u=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(f)break e;let m=r[--h];if(!c)for(let g=m.from,y=h;;){if(g==e)break e;if(y&&r[y-1].to==g)g=r[--y].from;else{if(q[g-1]==l)break e;break}}if(u)u.push(m);else{m.to<a&&o.push(new at(m.to,a,d));let g=m.direction==Dt!=!(d%2);Ls(s,g?i+1:i,n,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(c?q[p-1]!=l:q[p-1]==l))break;p--}u?Ps(s,p,a,i+1,n,u,o):p<a&&o.push(new at(p,a,d)),a=p}}function Ls(s,e,t,i,n,r,o){let l=e%2?2:1;jc(s,n,r,i,l),Uc(s,n,r,i,l),Gc(n,r,i,l),Ps(s,n,r,e,t,i,o)}function Jc(s,e,t){if(!s)return[new at(0,0,e==hr?1:0)];if(e==Dt&&!t.length&&!Kc.test(s))return _l(s.length);if(t.length)for(;s.length>q.length;)q[q.length]=256;let i=[],n=e==Dt?0:1;return Ls(s,n,n,t,0,s.length,i),i}function _l(s){return[new at(0,s,0)]}let Ql="";function Yc(s,e,t,i,n){var r;let o=i.head-s.from,l=at.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],h=a.side(n,t);if(o==h){let u=l+=n?1:-1;if(u<0||u>=e.length)return null;a=e[l=u],o=a.side(!n,t),h=a.side(n,t)}let c=oe(s.text,o,a.forward(n,t));(c<a.from||c>a.to)&&(c=h),Ql=s.text.slice(Math.min(o,c),Math.max(o,c));let f=l==(n?e.length-1:0)?null:e[l+(n?1:-1)];return f&&c==h&&f.level+(n?0:1)<a.level?b.cursor(f.side(!n,t)+s.from,f.forward(n,t)?1:-1,f.level):b.cursor(c+s.from,a.forward(n,t)?-1:1,a.level)}function Xc(s,e,t){for(let i=e;i<t;i++){let n=Yl(s.charCodeAt(i));if(n==1)return Dt;if(n==2||n==4)return hr}return Dt}const Zl=O.define(),ea=O.define(),ta=O.define(),ia=O.define(),Rs=O.define(),na=O.define(),sa=O.define(),ra=O.define({combine:s=>s.some(e=>e)}),oa=O.define({combine:s=>s.some(e=>e)});class zt{constructor(e,t="nearest",i="nearest",n=5,r=5,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new zt(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new zt(b.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Wi=F.define({map:(s,e)=>s.map(e)});function Ne(s,e,t){let i=s.facet(ia);i.length?i[0](e):window.onerror?window.onerror(String(e),t,void 0,void 0,e):t?console.error(t+":",e):console.error(e)}const En=O.define({combine:s=>s.length?s[0]:!0});let _c=0;const li=O.define();class ue{constructor(e,t,i,n,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(e,t){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=t||{};return new ue(_c++,e,i,n,l=>{let a=[li.of(l)];return o&&a.push(xi.of(h=>{let c=h.plugin(l);return c?o(c):B.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return ue.define(i=>new e(i),t)}}class Un{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(Ne(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(e)}catch(t){Ne(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){Ne(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const la=O.define(),cr=O.define(),xi=O.define(),aa=O.define(),fr=O.define(),ha=O.define();function Qr(s,e){let t=s.state.facet(ha);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(s):r),n=[];return $.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,c=o-e.from,f=n;for(let u=l.length-1;u>=0;u--,a--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Xc(e.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 m={from:h,to:c,direction:d,inner:[]};f.push(m),f=m.inner}}}}),n}const ca=O.define();function fa(s){let e=0,t=0,i=0,n=0;for(let r of s.state.facet(ca)){let o=r(s);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:e,right:t,top:i,bottom:n}}const ai=O.define();class Ee{constructor(e,t,i,n){this.fromA=e,this.toA=t,this.fromB=i,this.toB=n}join(e){return new Ee(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let n=e[t-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let n=0,r=0,o=0,l=0;;n++){let a=n==e.length?null:e[n],h=o-l,c=a?a.fromB:1e9;for(;r<t.length&&t[r]<c;){let f=t[r],u=t[r+1],d=Math.max(l,f),p=Math.min(c,u);if(d<=p&&new Ee(d+h,p+h,d,p).addToSet(i),u>c)break;r+=2}if(!a)return i;new Ee(a.fromA,a.toA,a.fromB,a.toB).addToSet(i),o=a.toA,l=a.toB}}}class pn{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=te.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let n=[];this.changes.iterChangedRanges((r,o,l,a)=>n.push(new Ee(r,o,l,a))),this.changedRanges=n}static create(e,t,i){return new pn(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class Zr extends U{get length(){return this.view.state.doc.length}constructor(e){super(),this.view=e,this.decorations=[],this.dynamicDecorationMap=[],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(e.contentDOM),this.children=[new ee],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ee(0,0,0,e.state.doc.length)],0,null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:h,toA:c})=>c<this.minWidthFrom||h>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0);let n=-1;this.view.inputState.composing>=0&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?n=this.domChanged.newSel.head:!rf(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?Zc(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:h,to:c}=this.hasComposition;i=new Ee(h,c,e.changes.mapPos(h,-1),e.changes.mapPos(c,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(D.ie||D.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),a=nf(o,l,e.changes);return i=Ee.extendWithRanges(i,a),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,e.startState.doc.length,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(e,t,i);let{observer:n}=this.view;n.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:n.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,o),this.flags&=-8,o&&(o.written||n.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 ht&&o.widget instanceof eo&&r.push(o.dom);n.updateGaps(r)}updateChildren(e,t,i){let n=i?i.range.addToSet(e.slice()):e,r=this.childCursor(t);for(let o=n.length-1;;o--){let l=o>=0?n[o]:null;if(!l)break;let{fromA:a,toA:h,fromB:c,toB:f}=l,u,d,p,m;if(i&&i.range.fromB<f&&i.range.toB>c){let v=gi.build(this.view.state.doc,c,i.range.fromB,this.decorations,this.dynamicDecorationMap),x=gi.build(this.view.state.doc,i.range.toB,f,this.decorations,this.dynamicDecorationMap);d=v.breakAtStart,p=v.openStart,m=x.openEnd;let A=this.compositionView(i);x.breakAtStart?A.breakAfter=1:x.content.length&&A.merge(A.length,A.length,x.content[0],!1,x.openStart,0)&&(A.breakAfter=x.content[0].breakAfter,x.content.shift()),v.content.length&&A.merge(0,0,v.content[v.content.length-1],!0,0,v.openEnd)&&v.content.pop(),u=v.content.concat(A).concat(x.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:m}=gi.build(this.view.state.doc,c,f,this.decorations,this.dynamicDecorationMap));let{i:g,off:y}=r.findPos(h,1),{i:w,off:S}=r.findPos(a,-1);Hl(this,w,S,g,y,u,d,p,m)}i&&this.fixCompositionDOM(i)}compositionView(e){let t=new tt(e.text.nodeValue);t.flags|=8;for(let{deco:n}of e.marks)t=new it(n,[t],t.length);let i=new ee;return i.append(t,0),i}fixCompositionDOM(e){let t=(r,o)=>{o.flags|=8|(o.children.some(a=>a.flags&7)?1:0),this.markedForComposition.add(o);let l=U.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(e.range.fromB,1),n=this.children[i.i];t(e.line,n);for(let r=e.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],t(r>=0?e.marks[r].node:e.text,n)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&rn(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||t||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&&Qc(a)){let f=document.createTextNode("");this.view.observer.ignore(()=>a.node.insertBefore(f,a.node.childNodes[a.offset]||null)),a=h=new ce(f,0),o=!0}let c=this.view.observer.selectionRange;(o||!c.focusNode||(!pi(a.node,a.offset,c.anchorNode,c.anchorOffset)||!pi(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)&&sf(c.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let f=dn(this.view.root);if(f)if(l.empty){if(D.gecko){let u=ef(a.node,a.offset);if(u&&u!=3){let d=da(a.node,a.offset,u==1?1:-1);d&&(a=new ce(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 ce(c.anchorNode,c.anchorOffset),this.impreciseHead=h.precise?null:new ce(c.focusNode,c.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&pi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=dn(e.root),{anchorNode:n,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=ee.find(this,t.head);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let f=e.observer.selectionRange;e.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=t.from&&i.collapse(n,r)}moveToLine(e){let t=this.dom,i;if(e.node!=t)return e;for(let n=e.offset;!i&&n<t.childNodes.length;n++){let r=U.get(t.childNodes[n]);r instanceof ee&&(i=r.domAtPos(0))}for(let n=e.offset-1;!i&&n>=0;n--){let r=U.get(t.childNodes[n]);r instanceof ee&&(i=r.domAtPos(r.length))}return i?new ce(i.node,i.offset,!0):e}nearest(e){for(let t=e;t;){let i=U.get(t);if(i&&i.rootView==this)return i;t=t.parentNode}return null}posFromDOM(e,t){let i=this.nearest(e);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(e,t)+i.posAtStart}domAtPos(e){let{i:t,off:i}=this.childCursor().findPos(e,-1);for(;t<this.children.length-1;){let n=this.children[t];if(i<n.length||n instanceof ee)break;t++,i=0}return this.children[t].domAtPos(i)}coordsAt(e,t){let i=null,n=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<e)break;h<=e&&(h<e||l.covers(-1))&&(a>e||l.covers(1))&&(!i||l instanceof ee&&!(i instanceof ee&&t>=0))&&(i=l,n=h),r=h}return i?i.coordsAt(e-n,t):null}coordsForChar(e){let{i:t,off:i}=this.childPos(e,1),n=this.children[t];if(!(n instanceof ee))return null;for(;n.children.length;){let{i:l,off:a}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=a}if(!(n instanceof tt))return null;let r=oe(n.text,i);if(r==i)return null;let o=Mt(n.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let a=o[l];if(l==o.length-1||a.top<a.bottom&&a.left<a.right)return a}return null}measureVisibleLineHeights(e){let t=[],{from:i,to:n}=e,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>n)break;if(h>=i){let d=f.dom.getBoundingClientRect();if(t.push(d.height),o){let p=f.dom.lastChild,m=p?jt(p):[];if(m.length){let g=m[m.length-1],y=a?g.right-d.left:d.right-g.left;y>l&&(l=y,this.minWidth=r,this.minWidthFrom=h,this.minWidthTo=u)}}}h=u+f.breakAfter}return t}textDirectionAt(e){let{i:t}=this.childPos(e,1);return getComputedStyle(this.children[t].dom).direction=="rtl"?X.RTL:X.LTR}measureTextSize(){for(let r of this.children)if(r instanceof ee){let o=r.measureTextSize();if(o)return o}let e=document.createElement("div"),t,i,n;return e.className="cm-line",e.style.width="99999px",e.style.position="absolute",e.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(e);let r=jt(e.firstChild)[0];t=e.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:t,e.remove()}),{lineHeight:t,charWidth:i,textHeight:n}}childCursor(e=this.length){let t=this.children.length;return t&&(e-=this.children[--t].length),new Wl(this.children,e,t)}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,n=0;;n++){let r=n==t.viewports.length?null:t.viewports[n],o=r?r.from-1:this.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(B.replace({widget:new eo(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return B.set(e)}updateDeco(){let e=this.view.state.facet(xi).map((n,r)=>(this.dynamicDecorationMap[r]=typeof n=="function")?n(this.view):n),t=!1,i=this.view.state.facet(aa).map((n,r)=>{let o=typeof n=="function";return o&&(t=!0),o?n(this.view):n});i.length&&(this.dynamicDecorationMap[e.length]=t,e.push($.join(i)));for(let n=e.length;n<e.length+3;n++)this.dynamicDecorationMap[n]=!1;return this.decorations=[...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco]}scrollIntoView(e){if(e.isSnapshot){let h=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=h.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}let{range:t}=e,i=this.coordsAt(t.head,t.empty?t.assoc:t.head>t.anchor?-1:1),n;if(!i)return;!t.empty&&(n=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(i={left:Math.min(i.left,n.left),top:Math.min(i.top,n.top),right:Math.max(i.right,n.right),bottom:Math.max(i.bottom,n.bottom)});let r=fa(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;Lc(this.view.scrollDOM,o,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,l),-l),Math.max(Math.min(e.yMargin,a),-a),this.view.textDirection==X.LTR)}}function Qc(s){return s.node.nodeType==1&&s.node.firstChild&&(s.offset==0||s.node.childNodes[s.offset-1].contentEditable=="false")&&(s.offset==s.node.childNodes.length||s.node.childNodes[s.offset].contentEditable=="false")}class eo extends Lt{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}}function ua(s,e){let t=s.observer.selectionRange,i=t.focusNode&&da(t.focusNode,t.focusOffset,0);if(!i)return null;let n=e-i.offset;return{from:n,to:n+i.node.nodeValue.length,node:i.node}}function Zc(s,e,t){let i=ua(s,t);if(!i)return null;let{node:n,from:r,to:o}=i,l=n.nodeValue;if(/[\n\r]/.test(l)||s.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc,h=new Ee(a.mapPos(r),a.mapPos(o),r,o),c=[];for(let f=n.parentNode;;f=f.parentNode){let u=U.get(f);if(u instanceof it)c.push({node:f,deco:u.mark});else{if(u instanceof ee||f.nodeName=="DIV"&&f.parentNode==s.contentDOM)return{range:h,text:n,marks:c,line:f};if(f!=s.contentDOM)c.push({node:f,deco:new Ti({inclusive:!0,attributes:Hc(f),tagName:f.tagName.toLowerCase()})});else return null}}}function da(s,e,t){if(t<=0)for(let i=s,n=e;;){if(i.nodeType==3)return{node:i,offset:n};if(i.nodeType==1&&n>0)i=i.childNodes[n-1],n=et(i);else break}if(t>=0)for(let i=s,n=e;;){if(i.nodeType==3)return{node:i,offset:n};if(i.nodeType==1&&n<i.childNodes.length&&t>=0)i=i.childNodes[n],n=0;else break}return null}function ef(s,e){return s.nodeType!=1?0:(e&&s.childNodes[e-1].contentEditable=="false"?1:0)|(e<s.childNodes.length&&s.childNodes[e].contentEditable=="false"?2:0)}let tf=class{constructor(){this.changes=[]}compareRange(e,t){Ts(e,t,this.changes)}comparePoint(e,t){Ts(e,t,this.changes)}};function nf(s,e,t){let i=new tf;return $.compare(s,e,t,i),i.changes}function sf(s,e){for(let t=s;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function rf(s,e){let t=!1;return e&&s.iterChangedRanges((i,n)=>{i<e.to&&n>e.from&&(t=!0)}),t}function of(s,e,t=1){let i=s.charCategorizer(e),n=s.doc.lineAt(e),r=e-n.from;if(n.length==0)return b.cursor(e);r==0?t=1:r==n.length&&(t=-1);let o=r,l=r;t<0?o=oe(n.text,r,!1):l=oe(n.text,r);let a=i(n.text.slice(o,l));for(;o>0;){let h=oe(n.text,o,!1);if(i(n.text.slice(h,o))!=a)break;o=h}for(;l<n.length;){let h=oe(n.text,l);if(i(n.text.slice(l,h))!=a)break;l=h}return b.range(o+n.from,l+n.from)}function lf(s,e){return e.left>s?e.left-s:Math.max(0,s-e.right)}function af(s,e){return e.top>s?e.top-s:Math.max(0,s-e.bottom)}function Gn(s,e){return s.top<e.bottom-1&&s.bottom>e.top+1}function to(s,e){return e<s.top?{top:e,left:s.left,right:s.right,bottom:s.bottom}:s}function io(s,e){return e>s.bottom?{top:s.top,left:s.left,right:s.right,bottom:e}:s}function Es(s,e,t){let i,n,r,o,l=!1,a,h,c,f;for(let p=s.firstChild;p;p=p.nextSibling){let m=jt(p);for(let g=0;g<m.length;g++){let y=m[g];n&&Gn(n,y)&&(y=to(io(y,n.bottom),n.top));let w=lf(e,y),S=af(t,y);if(w==0&&S==0)return p.nodeType==3?no(p,e,t):Es(p,e,t);if(!i||o>S||o==S&&r>w){i=p,n=y,r=w,o=S;let v=S?t<y.top?-1:1:w?e<y.left?-1:1:0;l=!v||(v>0?g<m.length-1:g>0)}w==0?t>y.bottom&&(!c||c.bottom<y.bottom)?(a=p,c=y):t<y.top&&(!f||f.top>y.top)&&(h=p,f=y):c&&Gn(c,y)?c=io(c,y.bottom):f&&Gn(f,y)&&(f=to(f,y.top))}}if(c&&c.bottom>=t?(i=a,n=c):f&&f.top<=t&&(i=h,n=f),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,e));if(i.nodeType==3)return no(i,u,t);if(l&&i.contentEditable!="false")return Es(i,u,t);let d=Array.prototype.indexOf.call(s.childNodes,i)+(e>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function no(s,e,t){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;l<i;l++){let a=Mt(s,l,l+1).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(c.top==c.bottom)continue;o||(o=e-c.left);let f=(c.top>t?c.top-t:t-c.bottom)-1;if(c.left-1<=e&&c.right+1>=e&&f<r){let u=e>=(c.left+c.right)/2,d=u;if((D.chrome||D.gecko)&&Mt(s,l).getBoundingClientRect().left==c.right&&(d=!u),f<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=f}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function pa(s,e,t,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,a,{docHeight:h}=s.viewState,{x:c,y:f}=e,u=f-l;if(u<0)return 0;if(u>h)return s.state.doc.length;for(let v=s.viewState.heightOracle.textHeight/2,x=!1;a=s.elementAtHeight(u),a.type!=De.Text;)for(;u=i>0?a.bottom+v:a.top-v,!(u>=0&&u<=h);){if(x)return t?null:0;x=!0,i=-i}f=l+u;let d=a.from;if(d<s.viewport.from)return s.viewport.from==0?0:t?null:so(s,o,a,c,f);if(d>s.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:t?null:so(s,o,a,c,f);let p=s.dom.ownerDocument,m=s.root.elementFromPoint?s.root:p,g=m.elementFromPoint(c,f);g&&!s.contentDOM.contains(g)&&(g=null),g||(c=Math.max(o.left+1,Math.min(o.right-1,c)),g=m.elementFromPoint(c,f),g&&!s.contentDOM.contains(g)&&(g=null));let y,w=-1;if(g&&((n=s.docView.nearest(g))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let v=p.caretPositionFromPoint(c,f);v&&({offsetNode:y,offset:w}=v)}else if(p.caretRangeFromPoint){let v=p.caretRangeFromPoint(c,f);v&&({startContainer:y,startOffset:w}=v,(!s.contentDOM.contains(y)||D.safari&&hf(y,w,c)||D.chrome&&cf(y,w,c))&&(y=void 0))}}if(!y||!s.docView.dom.contains(y)){let v=ee.find(s.docView,d);if(!v)return u>a.top+a.height/2?a.to:a.from;({node:y,offset:w}=Es(v.dom,c,f))}let S=s.docView.nearest(y);if(!S)return null;if(S.isWidget&&((r=S.dom)===null||r===void 0?void 0:r.nodeType)==1){let v=S.dom.getBoundingClientRect();return e.y<v.top||e.y<=v.bottom&&e.x<=(v.left+v.right)/2?S.posAtStart:S.posAtEnd}else return S.localPosFromDOM(y,w)+S.posAtStart}function so(s,e,t,i,n){let r=Math.round((i-e.left)*s.defaultCharacterWidth);if(s.lineWrapping&&t.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,a=Math.floor((n-t.top-(s.defaultLineHeight-l)*.5)/l);r+=a*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(t.from,t.to);return t.from+xs(o,r,s.state.tabSize)}function hf(s,e,t){let i;if(s.nodeType!=3||e!=(i=s.nodeValue.length))return!1;for(let n=s.nextSibling;n;n=n.nextSibling)if(n.nodeType!=1||n.nodeName!="BR")return!1;return Mt(s,i-1,i).getBoundingClientRect().left>t}function cf(s,e,t){if(e!=0)return!1;for(let n=s;;){let r=n.parentNode;if(!r||r.nodeType!=1||r.firstChild!=n)return!1;if(r.classList.contains("cm-line"))break;n=r}let i=s.nodeType==1?s.getBoundingClientRect():Mt(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return t-i.left>5}function Is(s,e){let t=s.lineBlockAt(e);if(Array.isArray(t.type)){for(let i of t.type)if(i.to>e||i.to==e&&(i.to==t.to||i.type==De.Text))return i}return t}function ff(s,e,t,i){let n=Is(s,e.head),r=!i||n.type!=De.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(e.assoc<0&&e.head>n.from?e.head-1:e.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),a=s.posAtCoords({x:t==(l==X.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return b.cursor(a,t?-1:1)}return b.cursor(t?n.to:n.from,t?-1:1)}function ro(s,e,t,i){let n=s.state.doc.lineAt(e.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=e,a=null;;){let h=Yc(n,r,o,l,t),c=Ql;if(!h){if(n.number==(t?s.state.doc.lines:1))return l;c=`
`,n=s.state.doc.line(n.number+(t?1:-1)),r=s.bidiSpans(n),h=s.visualLineSide(n,!t)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function uf(s,e,t){let i=s.state.charCategorizer(e),n=i(t);return r=>{let o=i(r);return n==G.Space&&(n=o),n==o}}function df(s,e,t,i){let n=e.head,r=t?1:-1;if(n==(t?s.state.doc.length:0))return b.cursor(n,e.assoc);let o=e.goalColumn,l,a=s.contentDOM.getBoundingClientRect(),h=s.coordsAtPos(n,e.assoc||-1),c=s.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(a.right-a.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+c}let f=a.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,m=pa(s,{x:f,y:p},!1,r);if(p<a.top||p>a.bottom||(r<0?m<n:m>n)){let g=s.docView.coordsForChar(m),y=!g||p<g.top?-1:1;return b.cursor(m,y,void 0,o)}}}function on(s,e,t){for(;;){let i=0;for(let n of s)n.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function Jn(s,e,t){let i=on(s.state.facet(fr).map(n=>n(s)),t.from,e.head>t.from?-1:1);return i==t.from?t:b.cursor(i,i<t.from?1:-1)}class pf{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,D.safari&&e.contentDOM.addEventListener("input",()=>null),D.gecko&&Bf(e.contentDOM.ownerDocument)}handleEvent(e){!kf(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||this.runHandlers(e.type,e)}runHandlers(e,t){let i=this.handlers[e];if(i){for(let n of i.observers)n(this.view,t);for(let n of i.handlers){if(t.defaultPrevented)break;if(n(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=gf(e),i=this.handlers,n=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&Date.now()<this.lastEscPress+2e3)return!0;if(e.keyCode!=27&&ma.indexOf(e.keyCode)<0&&(this.view.inputState.lastEscPress=0),D.android&&D.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return D.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&((t=ga.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||mf.indexOf(e.key)>-1&&e.ctrlKey&&!e.shiftKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(){let e=this.pendingIOSKey;return e?(this.pendingIOSKey=void 0,Ht(this.view.contentDOM,e.key,e.keyCode)):!1}ignoreDuringComposition(e){return/^key/.test(e.type)?this.composing>0?!0:D.safari&&!D.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function oo(s,e){return(t,i)=>{try{return e.call(s,i,t)}catch(n){Ne(t.state,n)}}}function gf(s){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of s){let n=i.spec;if(n&&n.domEventHandlers)for(let r in n.domEventHandlers){let o=n.domEventHandlers[r];o&&t(r).handlers.push(oo(i.value,o))}if(n&&n.domEventObservers)for(let r in n.domEventObservers){let o=n.domEventObservers[r];o&&t(r).observers.push(oo(i.value,o))}}for(let i in Fe)t(i).handlers.push(Fe[i]);for(let i in Ve)t(i).observers.push(Ve[i]);return e}const ga=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],mf="dthko",ma=[16,17,18,20,91,92,224,225],Hi=6;function zi(s){return Math.max(0,s)*.7+8}function yf(s,e){return Math.max(Math.abs(s.clientX-e.clientX),Math.abs(s.clientY-e.clientY))}class bf{constructor(e,t,i,n){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParent=Rc(e.contentDOM),this.atoms=e.state.facet(fr).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(H.allowMultipleSelections)&&wf(e,t),this.dragging=vf(e,t)&&xa(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){var t;if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&yf(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let i=0,n=0,r=((t=this.scrollParent)===null||t===void 0?void 0:t.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},o=fa(this.view);e.clientX-o.left<=r.left+Hi?i=-zi(r.left-e.clientX):e.clientX+o.right>=r.right-Hi&&(i=zi(e.clientX-r.right)),e.clientY-o.top<=r.top+Hi?n=-zi(r.top-e.clientY):e.clientY+o.bottom>=r.bottom-Hi&&(n=zi(e.clientY-r.bottom)),this.setScrollSpeed(i,n)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(e){let t=null;for(let i=0;i<e.ranges.length;i++){let n=e.ranges[i],r=null;if(n.empty){let o=on(this.atoms,n.from,0);o!=n.from&&(r=b.cursor(o,-1))}else{let o=on(this.atoms,n.from,-1),l=on(this.atoms,n.to,1);(o!=n.from||l!=n.to)&&(r=b.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?b.create(t,e.mainIndex):e}select(e){let{view:t}=this,i=this.skipAtoms(this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function wf(s,e){let t=s.state.facet(Zl);return t.length?t[0](e):D.mac?e.metaKey:e.ctrlKey}function xf(s,e){let t=s.state.facet(ea);return t.length?t[0](e):D.mac?!e.altKey:!e.ctrlKey}function vf(s,e){let{main:t}=s.state.selection;if(t.empty)return!1;let i=dn(s.root);if(!i||i.rangeCount==0)return!0;let n=i.getRangeAt(0).getClientRects();for(let r=0;r<n.length;r++){let o=n[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function kf(s,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=s.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=U.get(t))&&i.ignoreEvent(e))return!1;return!0}const Fe=Object.create(null),Ve=Object.create(null),ya=D.ie&&D.ie_version<15||D.ios&&D.webkit_version<604;function Sf(s){let e=s.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{s.focus(),t.remove(),ba(s,t.value)},50)}function ba(s,e){let{state:t}=s,i,n=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Ns!=null&&t.selection.ranges.every(a=>a.empty)&&Ns==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let f=t.toText((o?r.line(n++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:f},range:b.cursor(h.from+f.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(n++);return{changes:{from:a.from,to:a.to,insert:h.text},range:b.cursor(a.from+h.length)}}):i=t.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Ve.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};Fe.keydown=(s,e)=>(s.inputState.setSelectionOrigin("select"),e.keyCode==27&&(s.inputState.lastEscPress=Date.now()),!1);Ve.touchstart=(s,e)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Ve.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Fe.mousedown=(s,e)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of s.state.facet(ta))if(t=i(s,e),t)break;if(!t&&e.button==0&&(t=Mf(s,e)),t){let i=!s.hasFocus;s.inputState.startMouseSelection(new bf(s,e,t,i)),i&&s.observer.ignore(()=>Nl(s.contentDOM));let n=s.inputState.mouseSelection;if(n)return n.start(e),n.dragging===!1}return!1};function lo(s,e,t,i){if(i==1)return b.cursor(e,t);if(i==2)return of(s.state,e,t);{let n=ee.find(s.docView,e),r=s.state.doc.lineAt(n?n.posAtEnd:e),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,b.range(o,l)}}let wa=(s,e)=>s>=e.top&&s<=e.bottom,ao=(s,e,t)=>wa(e,t)&&s>=t.left&&s<=t.right;function Cf(s,e,t,i){let n=ee.find(s.docView,e);if(!n)return 1;let r=e-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&ao(t,i,o))return-1;let l=n.coordsAt(r,1);return l&&ao(t,i,l)?1:o&&wa(i,o)?-1:1}function ho(s,e){let t=s.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:t,bias:Cf(s,t,e.clientX,e.clientY)}}const Af=D.ie&&D.ie_version<=11;let co=null,fo=0,uo=0;function xa(s){if(!Af)return s.detail;let e=co,t=uo;return co=s,uo=Date.now(),fo=!e||t>Date.now()-400&&Math.abs(e.clientX-s.clientX)<2&&Math.abs(e.clientY-s.clientY)<2?(fo+1)%3:1}function Mf(s,e){let t=ho(s,e),i=xa(e),n=s.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),n=n.map(r.changes))},get(r,o,l){let a=ho(s,r),h,c=lo(s,a.pos,a.bias,i);if(t.pos!=a.pos&&!o){let f=lo(s,t.pos,t.bias,i),u=Math.min(f.from,c.from),d=Math.max(f.to,c.to);c=u<c.from?b.range(u,d):b.range(d,u)}return o?n.replaceRange(n.main.extend(c.from,c.to)):l&&i==1&&n.ranges.length>1&&(h=Df(n,a.pos))?h:l?n.addRange(c):b.create([c])}}}function Df(s,e){for(let t=0;t<s.ranges.length;t++){let{from:i,to:n}=s.ranges[t];if(i<=e&&n>=e)return b.create(s.ranges.slice(0,t).concat(s.ranges.slice(t+1)),s.mainIndex==t?0:s.mainIndex-(s.mainIndex>t?1:0))}return null}Fe.dragstart=(s,e)=>{let{selection:{main:t}}=s.state;if(e.target.draggable){let n=s.docView.nearest(e.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=t.to||o<=t.from)&&(t=b.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",s.state.sliceDoc(t.from,t.to)),e.dataTransfer.effectAllowed="copyMove"),!1};Fe.dragend=s=>(s.inputState.draggedContent=null,!1);function po(s,e,t,i){if(!t)return;let n=s.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&xf(s,e)?{from:r.from,to:r.to}:null,l={from:n,insert:t},a=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:a,selection:{anchor:a.mapPos(n,-1),head:a.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}Fe.drop=(s,e)=>{if(!e.dataTransfer)return!1;if(s.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),n=0,r=()=>{++n==t.length&&po(s,e,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return po(s,e,i,!0),!0}return!1};Fe.paste=(s,e)=>{if(s.state.readOnly)return!0;s.observer.flush();let t=ya?null:e.clipboardData;return t?(ba(s,t.getData("text/plain")||t.getData("text/uri-text")),!0):(Sf(s),!1)};function Of(s,e){let t=s.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function Tf(s){let e=[],t=[],i=!1;for(let n of s.selection.ranges)n.empty||(e.push(s.sliceDoc(n.from,n.to)),t.push(n));if(!e.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(e.push(o.text),t.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:e.join(s.lineBreak),ranges:t,linewise:i}}let Ns=null;Fe.copy=Fe.cut=(s,e)=>{let{text:t,ranges:i,linewise:n}=Tf(s.state);if(!t&&!n)return!1;Ns=n?t:null,e.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=ya?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Of(s,t),!1)};const va=nt.define();function ka(s,e){let t=[];for(let i of s.facet(sa)){let n=i(s,e);n&&t.push(n)}return t?s.update({effects:t,annotations:va.of(!0)}):null}function Sa(s){setTimeout(()=>{let e=s.hasFocus;if(e!=s.inputState.notifiedFocused){let t=ka(s.state,e);t?s.dispatch(t):s.update([])}},10)}Ve.focus=s=>{s.inputState.lastFocusTime=Date.now(),!s.scrollDOM.scrollTop&&(s.inputState.lastScrollTop||s.inputState.lastScrollLeft)&&(s.scrollDOM.scrollTop=s.inputState.lastScrollTop,s.scrollDOM.scrollLeft=s.inputState.lastScrollLeft),Sa(s)};Ve.blur=s=>{s.observer.clearSelectionRange(),Sa(s)};Ve.compositionstart=Ve.compositionupdate=s=>{s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0)};Ve.compositionend=s=>{s.inputState.composing=-1,s.inputState.compositionEndedAt=Date.now(),s.inputState.compositionPendingKey=!0,s.inputState.compositionPendingChange=s.observer.pendingRecords().length>0,s.inputState.compositionFirstChange=null,D.chrome&&D.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50)};Ve.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Fe.beforeinput=(s,e)=>{var t;let i;if(D.chrome&&D.android&&(i=ga.find(n=>n.inputType==e.inputType))&&(s.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let n=((t=window.visualViewport)===null||t===void 0?void 0:t.height)||0;setTimeout(()=>{var r;(((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0)>n+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return!1};const go=new Set;function Bf(s){go.has(s)||(go.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const mo=["pre-wrap","normal","pre-line","break-spaces"];class Pf{constructor(e){this.lineWrapping=e,this.doc=V.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return mo.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let n=e[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(t=!0,this.heightSamples[Math.floor(n*10)]=!0)}return t}refresh(e,t,i,n,r,o){let l=mo.indexOf(e)>-1,a=Math.round(t)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=n,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 Lf{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Ge{constructor(e,t,i,n,r){this.from=e,this.length=t,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?De.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 pt?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Ge(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var j=function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s}(j||(j={}));const ln=.001;class pe{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e,t){this.height!=t&&(Math.abs(this.height-t)>ln&&(e.heightChanged=!0),this.height=t)}replace(e,t,i){return pe.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:f}=n[l],u=r.lineAt(a,j.ByPosNoHeight,i.setDoc(t),0,0),d=u.to>=h?u:r.lineAt(h,j.ByPosNoHeight,i,0,0);for(f+=d.to-h,h=d.to;l>0&&u.from<=n[l-1].toA;)a=n[l-1].fromA,c=n[l-1].fromB,l--,a<u.from&&(u=r.lineAt(a,j.ByPosNoHeight,i,0,0));c+=u.from-a,a=u.from;let p=ur.build(i.setDoc(o),e,c,f);r=r.replace(a,h,p)}return r.updateHeight(i,0)}static empty(){return new Ce(0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,n=0,r=0;for(;;)if(t==i)if(n>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=e[t++];l&&(n+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new Rf(pe.of(e.slice(0,t)),o,pe.of(e.slice(i)))}}pe.prototype.size=1;class Ca extends pe{constructor(e,t,i){super(e,t),this.deco=i}blockAt(e,t,i,n){return new Ge(n,this.length,i,this.height,this.deco||0)}lineAt(e,t,i,n,r){return this.blockAt(0,i,n,r)}forEachLine(e,t,i,n,r,o){e<=r+this.length&&t>=r&&o(this.blockAt(0,i,n,r))}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more&&this.setHeight(e,n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ce extends Ca{constructor(e,t){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(e,t,i,n){return new Ge(n,this.length,i,this.height,this.breaks)}replace(e,t,i){let n=i[0];return i.length==1&&(n instanceof Ce||n instanceof ie&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof ie?n=new Ce(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):pe.of(i)}updateHeight(e,t=0,i=!1,n){return n&&n.from<=t&&n.more?this.setHeight(e,n.heights[n.index++]):(i||this.outdated)&&this.setHeight(e,Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ie extends pe{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,n=e.doc.lineAt(t+this.length).number,r=n-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:n,perLine:o,perChar:l}}blockAt(e,t,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,n);if(t.lineWrapping){let h=n+Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length),c=t.doc.lineAt(h),f=l+c.length*a,u=Math.max(i,e-f/2);return new Ge(c.from,c.length,u,f,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:c,length:f}=t.doc.line(r+h);return new Ge(c,f,i+l*h,l,0)}}lineAt(e,t,i,n,r){if(t==j.ByHeight)return this.blockAt(e,i,n,r);if(t==j.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new Ge(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),c=l+h.length*a,f=h.number-o,u=n+l*f+a*(h.from-r-f);return new Ge(h.from,h.length,Math.max(n,Math.min(u,n+this.height-c)),c,0)}forEachLine(e,t,i,n,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=e,f=n;c<=t;){let u=i.doc.lineAt(c);if(c==e){let p=u.number-l;f+=a*p+h*(e-r-p)}let d=a+h*u.length;o(new Ge(u.from,u.length,f,d,0)),f+=d,c=u.to+1}}replace(e,t,i){let n=this.length-t;if(n>0){let r=i[i.length-1];r instanceof ie?i[i.length-1]=new ie(r.length+n):i.push(null,new ie(n-1))}if(e>0){let r=i[0];r instanceof ie?i[0]=new ie(e+r.length):i.unshift(new ie(e-1),null)}return pe.of(i)}decomposeLeft(e,t){t.push(new ie(e-1),null)}decomposeRight(e,t){t.push(null,new ie(this.length-e-1))}updateHeight(e,t=0,i=!1,n){let r=t+this.length;if(n&&n.from<=t+this.length&&n.more){let o=[],l=Math.max(t,n.from),a=-1;for(n.from>t&&o.push(new ie(n.from-t-1).updateHeight(e,t));l<=r&&n.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let f=n.heights[n.index++];a==-1?a=f:Math.abs(f-a)>=ln&&(a=-2);let u=new Ce(c,f);u.outdated=!1,o.push(u),l+=c+1}l<=r&&o.push(null,new ie(r-l).updateHeight(e,l));let h=pe.of(o);return(a<0||Math.abs(h.height-this.height)>=ln||Math.abs(a-this.heightMetrics(e,t).perLine)>=ln)&&(e.heightChanged=!0),h}else(i||this.outdated)&&(this.setHeight(e,e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class Rf extends pe{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,n){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,n):this.right.blockAt(e,t,r,n+this.left.length+this.break)}lineAt(e,t,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,a=t==j.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,n,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==j.ByPosNoHeight?j.ByPosNoHeight:j.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,n,r).join(h)}forEachLine(e,t,i,n,r,o){let l=n+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,n,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,j.ByPos,i,n,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,n,r,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let n=this.left.length+this.break;if(t<n)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-n,t-n,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&yo(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),yo(r,l)}return pe.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,n=i+this.break;if(e>=n)return this.right.decomposeRight(e-n,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<n&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?pe.of(this.break?[e,null,t]:[e,t]):(this.left=e,this.right=t,this.height=e.height+t.height,this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,n){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return n&&n.from<=t+r.length&&n.more?a=r=r.updateHeight(e,t,i,n):r.updateHeight(e,t,i),n&&n.from<=l+o.length&&n.more?a=o=o.updateHeight(e,l,i,n):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function yo(s,e){let t,i;s[e]==null&&(t=s[e-1])instanceof ie&&(i=s[e+1])instanceof ie&&s.splice(e-1,3,new ie(t.length+1+i.length))}const Ef=5;class ur{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof Ce?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ce(i-this.pos,-1)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new Ca(o,n,i)):(o||r||n>=Ef)&&this.addLineDeco(n,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Ce(this.pos-e,-1)),this.writtenTo=this.pos}blankContent(e,t){let i=new ie(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ce)return e;let t=new Ce(0,-1);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,e),n.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ce)&&!this.isCovered?this.nodes.push(new Ce(0,-1)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let n of this.nodes)n instanceof Ce&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(e,t,i,n){let r=new ur(i,e);return $.spans(t,i,n,r,0),r.finish(i)}}function If(s,e,t){let i=new Nf;return $.compare(s,e,t,i,0),i.changes}class Nf{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,n){(e<t||i&&i.heightRelevant||n&&n.heightRelevant)&&Ts(e,t,this.changes,5)}}function Ff(s,e){let t=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(n.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(n.innerHeight,t.bottom);for(let h=s.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==s.parentNode?u.bottom:Math.min(a,u.bottom)}h=f.position=="absolute"||f.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function Vf(s,e){let t=s.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Yn{constructor(e,t,i){this.from=e,this.to=t,this.size=i}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let n=e[i],r=t[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(e,t){return B.replace({widget:new Wf(this.size*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class Wf extends Lt{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class bo{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!0,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=wo,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=X.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let t=e.facet(cr).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new Pf(t),this.stateDeco=e.facet(xi).filter(i=>typeof i!="function"),this.heightMap=pe.empty().applyChanges(this.stateDeco,V.empty,this.heightOracle.setDoc(e.doc),[new Ee(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=B.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let n=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);e.push(new qi(r,o))}}this.viewports=e.sort((i,n)=>i.from-n.from),this.scaler=this.heightMap.height<=7e6?wo:new qf(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(this.scaler.scale==1?e:hi(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=this.state.facet(xi).filter(c=>typeof c!="function");let n=e.changedRanges,r=Ee.extendWithRanges(n,If(i,this.stateDeco,e?e.changes:te.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=o&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=!e.changes.empty||e.flags&2||a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,this.updateForViewport(),h&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&e.selectionSet&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(oa)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let t=e.contentDOM,i=window.getComputedStyle(t),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?X.RTL:X.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:v,scaleY:x}=Il(t,l);(this.scaleX!=v||this.scaleY!=x)&&(this.scaleX=v,this.scaleY=x,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!=e.scrollDOM.clientWidth&&(n.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Vl(e.scrollDOM);let p=(this.printing?Vf:Ff)(t,this.paddingTop),m=p.top-this.pixelViewport.top,g=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 w=l.width;if((this.contentDOMWidth!=w||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=8),a){let v=e.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(v)&&(o=!0),o||n.lineWrapping&&Math.abs(w-this.contentDOMWidth)>n.charWidth){let{lineHeight:x,charWidth:A,textHeight:C}=e.docView.measureTextSize();o=x>0&&n.refresh(r,x,A,C,w/A,v),o&&(e.docView.minWidth=0,h|=8)}m>0&&g>0?c=Math.max(m,g):m<0&&g<0&&(c=Math.min(m,g)),n.heightChanged=!1;for(let x of this.viewports){let A=x.from==this.viewport.from?v:e.docView.measureVisibleLineHeights(x);this.heightMap=(o?pe.empty().applyChanges(this.stateDeco,V.empty,this.heightOracle,[new Ee(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new Lf(x.from,A))}n.heightChanged&&(h|=2)}let S=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return S&&(this.viewport=this.getViewport(c,this.scrollTarget)),this.updateForViewport(),(h&2||S)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new qi(n.lineAt(o-i*1e3,j.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,j.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),f=n.lineAt(h,j.ByPos,r,0,0),u;t.y=="center"?u=(f.top+f.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?u=f.top:u=f.bottom-c,a=new qi(n.lineAt(u-1e3/2,j.ByHeight,r,0,0).from,n.lineAt(u+c+1e3/2,j.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),n=t.mapPos(e.to,1);return new qi(this.heightMap.lineAt(i,j.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,j.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(e,j.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,j.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||n<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let n of e)t.touchesRange(n.from,n.to)||i.push(new Yn(t.mapPos(n.from),t.mapPos(n.to),n.size));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=X.LTR&&!i)return[];let l=[],a=(h,c,f,u)=>{if(c-h<r)return;let d=this.state.selection.main,p=[d.from];d.empty||p.push(d.to);for(let g of p)if(g>h&&g<c){a(h,g-10,f,u),a(g+10,c,f,u);return}let m=zf(e,g=>g.from>=f.from&&g.to<=f.to&&Math.abs(g.from-h)<r&&Math.abs(g.to-c)<r&&!p.some(y=>g.from<y&&g.to>y));if(!m){if(c<f.to&&t&&i&&t.visibleRanges.some(g=>g.from<=c&&g.to>=c)){let g=t.moveToLineBoundary(b.cursor(c),!1,!0).head;g>h&&(c=g)}m=new Yn(h,c,this.gapSize(f,h,c,u))}l.push(m)};for(let h of this.viewportLines){if(h.length<o)continue;let c=Hf(h.from,h.to,this.stateDeco);if(c.total<o)continue;let f=this.scrollTarget?this.scrollTarget.range.head:null,u,d;if(i){let p=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,g;if(f!=null){let y=Ki(c,f),w=((this.visibleBottom-this.visibleTop)/2+p)/h.height;m=y-w,g=y+w}else m=(this.visibleTop-h.top-p)/h.height,g=(this.visibleBottom-h.top+p)/h.height;u=$i(c,m),d=$i(c,g)}else{let p=c.total*this.heightOracle.charWidth,m=n*this.heightOracle.charWidth,g,y;if(f!=null){let w=Ki(c,f),S=((this.pixelViewport.right-this.pixelViewport.left)/2+m)/p;g=w-S,y=w+S}else g=(this.pixelViewport.left-m)/p,y=(this.pixelViewport.right+m)/p;u=$i(c,g),d=$i(c,y)}u>h.from&&a(h.from,u,h,c),d<h.to&&a(d,h.to,h,c)}return l}gapSize(e,t,i,n){let r=Ki(n,i)-Ki(n,t);return this.heightOracle.lineWrapping?e.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(e){Yn.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=B.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let e=this.stateDeco;this.lineGaps.length&&(e=e.concat(this.lineGapDeco));let t=[];$.spans(e,this.viewport.from,this.viewport.to,{span(n,r){t.push({from:n,to:r})},point(){}},20);let i=t.length!=this.visibleRanges.length||this.visibleRanges.some((n,r)=>n.from!=t[r].from||n.to!=t[r].to);return this.visibleRanges=t,i?4:0}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||hi(this.heightMap.lineAt(e,j.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return hi(this.heightMap.lineAt(this.scaler.fromDOM(e),j.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return hi(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class qi{constructor(e,t){this.from=e,this.to=t}}function Hf(s,e,t){let i=[],n=s,r=0;return $.spans(t,s,e,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<e&&(i.push({from:n,to:e}),r+=e-n),{total:r,ranges:i}}function $i({total:s,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(s*t);for(let n=0;;n++){let{from:r,to:o}=e[n],l=o-r;if(i<=l)return r+i;i-=l}}function Ki(s,e){let t=0;for(let{from:i,to:n}of s.ranges){if(e<=n){t+=e-i;break}t+=n-i}return t/s.total}function zf(s,e){for(let t of s)if(e(t))return t}const wo={toDOM(s){return s},fromDOM(s){return s},scale:1};class qf{constructor(e,t,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,j.ByPos,e,0,0).top,c=t.lineAt(a,j.ByPos,e,0,0).bottom;return n+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(t.height-n);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return n+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,n=r.domBottom}}fromDOM(e){for(let t=0,i=0,n=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-n)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,n=r.domBottom}}}function hi(s,e){if(e.scale==1)return s;let t=e.toDOM(s.top),i=e.toDOM(s.bottom);return new Ge(s.from,s.length,t,i-t,Array.isArray(s._content)?s._content.map(n=>hi(n,e)):s._content)}const ji=O.define({combine:s=>s.join(" ")}),Fs=O.define({combine:s=>s.indexOf(!0)>-1}),Vs=ut.newName(),Aa=ut.newName(),Ma=ut.newName(),Da={"&light":"."+Aa,"&dark":"."+Ma};function Ws(s,e,t){return new ut(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!t||!t[n])throw new RangeError(`Unsupported selector: ${n}`);return t[n]}):s+" "+i}})}const $f=Ws("."+Vs,{"&":{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"}},Da),ci="￿";class Kf{constructor(e,t){this.points=e,this.text="",this.lineSeparator=t.facet(H.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=ci}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let n=e;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==t)break;let l=U.get(n),a=U.get(o);(l&&a?l.breakAfter:(l?l.breakAfter:xo(n))||xo(o)&&(n.nodeName!="BR"||n.cmIgnore)&&this.text.length>r)&&this.lineBreak(),n=o}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){if(e.cmIgnore)return;let t=U.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(jf(e,i.node,i.offset)?t:0))}}function jf(s,e,t){for(;;){if(!e||t<et(e))return!1;if(e==s)return!0;t=wi(e)+1,e=e.parentNode}}function xo(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}class vo{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class Uf{constructor(e,t,i,n){this.typeOver=n,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:o}=e.docView;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=e.docView.domBoundsAround(t,i,0))){let l=r||o?[]:Yf(e),a=new Kf(l,e.state);a.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=a.text,this.newSel=Xf(l,this.bounds.from)}else{let l=e.observer.selectionRange,a=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!Ss(e.contentDOM,l.focusNode)?e.state.selection.main.head:e.docView.posFromDOM(l.focusNode,l.focusOffset),h=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!Ss(e.contentDOM,l.anchorNode)?e.state.selection.main.anchor:e.docView.posFromDOM(l.anchorNode,l.anchorOffset),c=e.viewport;if(D.ios&&e.state.selection.main.empty&&a!=h&&(c.from>0||c.to<e.state.doc.length)){let f=c.from-Math.min(a,h),u=c.to-Math.max(a,h);(f==0||f==1)&&(u==0||u==-1)&&(a=0,h=e.state.doc.length)}this.newSel=b.single(h,a)}}}function Oa(s,e){let t,{newSel:i}=e,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:l}=e.bounds,a=n.from,h=null;(r===8||D.android&&e.text.length<l-o)&&(a=n.to,h="end");let c=Jf(s.state.doc.sliceString(o,l,ci),e.text,a-o,h);c&&(D.chrome&&r==13&&c.toB==c.from+2&&e.text.slice(c.from,c.toB)==ci+ci&&c.toB--,t={from:o+c.from,to:o+c.toA,insert:V.of(e.text.slice(c.from,c.toB).split(ci))})}else i&&(!s.hasFocus&&s.state.facet(En)||i.main.eq(n))&&(i=null);if(!t&&!i)return!1;if(!t&&e.typeOver&&!n.empty&&i&&i.main.empty?t={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,n.to)}:t&&t.from>=n.from&&t.to<=n.to&&(t.from!=n.from||t.to!=n.to)&&n.to-n.from-(t.to-t.from)<=4?t={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,t.from).append(t.insert).append(s.state.doc.slice(t.to,n.to))}:(D.mac||D.android)&&t&&t.from==t.to&&t.from==n.head-1&&/^\. ?$/.test(t.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:V.of([" "])}):D.chrome&&t&&t.from==t.to&&t.from==n.head&&t.insert.toString()==`
`&&s.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),t={from:n.from,to:n.to,insert:V.of([" "])}),t){if(D.ios&&s.inputState.flushIOSKey()||D.android&&(t.from==n.from&&t.to==n.to&&t.insert.length==1&&t.insert.lines==2&&Ht(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||r==8&&t.insert.length<t.to-t.from&&t.to>n.head)&&Ht(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Ht(s.contentDOM,"Delete",46)))return!0;let o=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let l,a=()=>l||(l=Gf(s,t,i));return s.state.facet(na).some(h=>h(s,t.from,t.to,o,a))||s.dispatch(a()),!0}else if(i&&!i.main.eq(n)){let o=!1,l="select";return s.inputState.lastSelectionTime>Date.now()-50&&(s.inputState.lastSelectionOrigin=="select"&&(o=!0),l=s.inputState.lastSelectionOrigin),s.dispatch({selection:i,scrollIntoView:o,userEvent:l}),!0}else return!1}function Gf(s,e,t){let i,n=s.state,r=n.selection.main;if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&s.inputState.composing<0){let l=r.from<e.from?n.sliceDoc(r.from,e.from):"",a=r.to>e.to?n.sliceDoc(e.to,r.to):"";i=n.replaceSelection(s.state.toText(l+e.insert.sliceString(0,void 0,s.state.lineBreak)+a))}else{let l=n.changes(e),a=t&&t.main.to<=l.newLength?t.main:void 0;if(n.selection.ranges.length>1&&s.inputState.composing>=0&&e.to<=r.to&&e.to>=r.to-10){let h=s.state.sliceDoc(e.from,e.to),c,f=t&&ua(s,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);c={from:f.from,to:f.to-p}}else c=s.state.doc.lineAt(r.head);let u=r.to-e.to,d=r.to-r.from;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:a||p.map(l)};let m=p.to-u,g=m-h.length;if(p.to-p.from!=d||s.state.sliceDoc(g,m)!=h||p.to>=c.from&&p.from<=c.to)return{range:p};let y=n.changes({from:g,to:m,insert:e.insert}),w=p.to-r.to;return{changes:y,range:a?b.range(Math.max(0,a.anchor+w),Math.max(0,a.head+w)):p.map(y)}})}else i={changes:l,selection:a&&n.selection.replaceRange(a)}}let o="input.type";return(s.composing||s.inputState.compositionPendingChange&&s.inputState.compositionEndedAt>Date.now()-50)&&(s.inputState.compositionPendingChange=!1,o+=".compose",s.inputState.compositionFirstChange&&(o+=".start",s.inputState.compositionFirstChange=!1)),n.update(i,{userEvent:o,scrollIntoView:!0})}function Jf(s,e,t,i){let n=Math.min(s.length,e.length),r=0;for(;r<n&&s.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==n&&s.length==e.length)return null;let o=s.length,l=e.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&s.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Yf(s){let e=[];if(s.root.activeElement!=s.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return t&&(e.push(new vo(t,i)),(n!=t||r!=i)&&e.push(new vo(n,r))),e}function Xf(s,e){if(s.length==0)return null;let t=s[0].pos,i=s.length==2?s[1].pos:t;return t>-1&&i>-1?b.single(t+e,i+e):null}const _f={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Xn=D.ie&&D.ie_version<=11;class Qf{constructor(e){this.view=e,this.active=!1,this.selectionRange=new Ec,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.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(D.ie&&D.ie_version<=11||D.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),Xn&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(){this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500)}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(En)?i.root.activeElement!=this.dom:!rn(i.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(D.ie&&D.ie_version<=11||D.android&&D.chrome)&&!i.state.selection.main.empty&&n.focusNode&&pi(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=D.safari&&e.root.nodeType==11&&Bc(this.dom.ownerDocument)==this.dom&&Zf(this.view)||dn(e.root);if(!t||this.selectionRange.eq(t))return!1;let i=rn(this.dom,t);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Nc(this.dom,t)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(t),i&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,_f),Xn&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Xn&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let n=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&Ht(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,n=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:n}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),n=this.selectionChanged&&rn(this.dom,this.selectionRange);if(e<0&&!n)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Uf(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,n=Oa(this.view,t);return this.view.state==i&&this.view.update([]),n}readMutation(e){let t=this.view.docView.nearest(e.target);if(!t||t.ignoreMutation(e))return null;if(t.markDirty(e.type=="attributes"),e.type=="attributes"&&(t.flags|=4),e.type=="childList"){let i=ko(t,e.previousSibling||e.target.previousSibling,-1),n=ko(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:n?t.posBefore(n):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let n of this.scrollTargets)n.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 ko(s,e,t){for(;e;){let i=U.get(e);if(i&&i.parent==s)return i;let n=e.parentNode;e=n!=s.dom?n:t>0?e.nextSibling:e.previousSibling}return null}function Zf(s){let e=null;function t(a){a.preventDefault(),a.stopImmediatePropagation(),e=a.getTargetRanges()[0]}if(s.contentDOM.addEventListener("beforeinput",t,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",t,!0),!e)return null;let i=e.startContainer,n=e.startOffset,r=e.endContainer,o=e.endOffset,l=s.docView.domAtPos(s.state.selection.main.anchor);return pi(l.node,l.offset,r,o)&&([i,n,r,o]=[r,o,i,n]),{anchorNode:i,anchorOffset:n,focusNode:r,focusOffset:o}}class T{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(i=>i.forEach(n=>t(n,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Ic(e.parent)||document,this.viewState=new bo(e.state||H.create(e)),e.scrollTo&&e.scrollTo.is(Wi)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(li).map(i=>new Un(i));for(let i of this.plugins)i.update(this);this.observer=new Qf(this),this.inputState=new pf(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Zr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...e){let t=e.length==1&&e[0]instanceof Q?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,n,r=this.state;for(let u of e){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(u=>u.annotation(va))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=ka(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);n=pn.create(this,r,e),n.flags|=l;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let u of e){if(f&&(f=f.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;f=new zt(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Wi)&&(f=d.value.clip(this.state))}this.viewState.update(n,f),this.bidiCache=gn.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),t=this.docView.update(n),this.state.facet(ai)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(ji)!=n.state.facet(ji)&&(this.viewState.mustMeasureContent=!0),(t||i||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),!n.empty)for(let u of this.state.facet(Rs))try{u(n)}catch(d){Ne(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!Oa(this,c)&&h.force&&Ht(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new bo(e),this.plugins=e.facet(li).map(i=>new Un(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Zr(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(li),i=e.state.facet(li);if(t!=i){let n=[];for(let r of i){let o=t.indexOf(r);if(o<0)n.push(new Un(r));else{let l=this.plugins[o];l.mustUpdate=e,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=e;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.scrollDOM,n=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(n-this.viewState.scrollTop)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(Vl(i))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(n);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 Ne(this.state,p),So}}),f=pn.create(this,this.state,[]),u=!1;f.flags|=a,t?t.flags|=a:t=f,this.updateState=2,f.empty||(this.updatePlugins(f),this.inputState.update(f),this.updateAttrs(),u=this.docView.update(f));for(let d=0;d<h.length;d++)if(c[d]!=So)try{let p=h[d];p.write&&p.write(c[d],this)}catch(p){Ne(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){n=n+p,i.scrollTop=n/this.scaleY,o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(Rs))l(t)}get themeClasses(){return Vs+" "+(this.state.facet(Fs)?Ma:Aa)+" "+this.state.facet(ji)}updateAttrs(){let e=Co(this,la,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(En)?"true":"false",class:"cm-content",style:`${D.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Co(this,cr,t);let i=this.observer.ignore(()=>{let n=Os(this.contentDOM,this.contentAttrs,t),r=Os(this.dom,this.editorAttrs,e);return n||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let n of i.effects)if(n.is(T.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(ai);let e=this.state.facet(T.cspNonce);ut.mount(this.root,this.styleModules.concat($f).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.spec!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.spec==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Jn(this,e,ro(this,e,t,i))}moveByGroup(e,t){return Jn(this,e,ro(this,e,t,i=>uf(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),n=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return b.cursor(r.side(t,n)+e.from,r.forward(!t,n)?1:-1)}moveToLineBoundary(e,t,i=!0){return ff(this,e,t,i)}moveVertically(e,t,i){return Jn(this,e,df(this,e,t,i))}domAtPos(e){return this.docView.domAtPos(e)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){return this.readMeasured(),pa(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),o=r[at.find(r,e-n.from,-1,t)];return Ln(i,o.dir==X.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(ra)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>eu)return _l(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||Xl(r.isolates,i=Qr(this,e))))return r.order;i||(i=Qr(this,e));let n=Jc(e.text,t,i);return this.bidiCache.push(new gn(e.from,e.to,t,i,!0,n)),n}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||D.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Nl(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Wi.of(new zt(typeof e=="number"?b.cursor(e):e,t.y,t.x,t.yMargin,t.xMargin))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return Wi.of(new zt(b.cursor(i.from),"start","start",i.top-e,t,!0))}static domEventHandlers(e){return ue.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return ue.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=ut.newName(),n=[ji.of(i),ai.of(Ws(`.${i}`,e))];return t&&t.dark&&n.push(Fs.of(!0)),n}static baseTheme(e){return Bt.lowest(ai.of(Ws("."+Vs,e,Da)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),n=i&&U.get(i)||U.get(e);return((t=n==null?void 0:n.rootView)===null||t===void 0?void 0:t.view)||null}}T.styleModule=ai;T.inputHandler=na;T.focusChangeEffect=sa;T.perLineTextDirection=ra;T.exceptionSink=ia;T.updateListener=Rs;T.editable=En;T.mouseSelectionStyle=ta;T.dragMovesSelection=ea;T.clickAddsSelectionRange=Zl;T.decorations=xi;T.outerDecorations=aa;T.atomicRanges=fr;T.bidiIsolatedRanges=ha;T.scrollMargins=ca;T.darkTheme=Fs;T.cspNonce=O.define({combine:s=>s.length?s[0]:""});T.contentAttributes=cr;T.editorAttributes=la;T.lineWrapping=T.contentAttributes.of({class:"cm-lineWrapping"});T.announce=F.define();const eu=4096,So={};class gn{constructor(e,t,i,n,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],n=e.length?e[e.length-1].dir:X.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==n&&!t.touchesRange(o.from,o.to)&&i.push(new gn(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Co(s,e,t){for(let i=s.state.facet(e),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Ds(o,t)}return t}const tu=D.mac?"mac":D.windows?"win":D.linux?"linux":"key";function iu(s,e){const t=s.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))n=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Ui(s,e,t){return e.altKey&&(s="Alt-"+s),e.ctrlKey&&(s="Ctrl-"+s),e.metaKey&&(s="Meta-"+s),t!==!1&&e.shiftKey&&(s="Shift-"+s),s}const nu=Bt.default(T.domEventHandlers({keydown(s,e){return Ba(Ta(e.state),s,e,"editor")}})),dr=O.define({enables:nu}),Ao=new WeakMap;function Ta(s){let e=s.facet(dr),t=Ao.get(e);return t||Ao.set(e,t=ou(e.reduce((i,n)=>i.concat(n),[]))),t}function su(s,e,t){return Ba(Ta(s.state),e,s,t)}let ot=null;const ru=4e3;function ou(s,e=tu){let t=Object.create(null),i=Object.create(null),n=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var f,u;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>iu(y,e));for(let y=1;y<p.length;y++){let w=p.slice(0,y).join(" ");n(w,!0),d[w]||(d[w]={preventDefault:!0,stopPropagation:!1,run:[S=>{let v=ot={view:S,prefix:w,scope:o};return setTimeout(()=>{ot==v&&(ot=null)},ru),!0}]})}let m=p.join(" ");n(m,!1);let g=d[m]||(d[m]={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&&g.run.push(a),h&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let f in c)c[f].run.push(o.any)}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}function Ba(s,e,t,i){let n=Tc(e),r=ne(n,0),o=Be(r)==n.length&&n!=" ",l="",a=!1,h=!1,c=!1;ot&&ot.view==t&&ot.scope==i&&(l=ot.prefix+" ",ma.indexOf(e.keyCode)<0&&(h=!0,ot=null));let f=new Set,u=g=>{if(g){for(let y of g.run)if(!f.has(y)&&(f.add(y),y(t,e)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),h=!0)}return!1},d=s[i],p,m;return d&&(u(d[l+Ui(n,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(D.windows&&e.ctrlKey&&e.altKey)&&(p=dt[e.keyCode])&&p!=n?(u(d[l+Ui(p,e,!0)])||e.shiftKey&&(m=bi[e.keyCode])!=n&&m!=p&&u(d[l+Ui(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&u(d[l+Ui(n,e,!0)])&&(a=!0),!a&&u(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),a}class Pi{constructor(e,t,i,n,r){this.className=e,this.left=t,this.top=i,this.width=n,this.height=r}draw(){let e=document.createElement("div");return e.className=this.className,this.adjust(e),e}update(e,t){return t.className!=this.className?!1:(this.adjust(e),!0)}adjust(e){e.style.left=this.left+"px",e.style.top=this.top+"px",this.width!=null&&(e.style.width=this.width+"px"),e.style.height=this.height+"px"}eq(e){return this.left==e.left&&this.top==e.top&&this.width==e.width&&this.height==e.height&&this.className==e.className}static forRange(e,t,i){if(i.empty){let n=e.coordsAtPos(i.head,i.assoc||1);if(!n)return[];let r=Pa(e);return[new Pi(t,n.left-r.left,n.top-r.top,null,n.bottom-n.top)]}else return lu(e,t,i)}}function Pa(s){let e=s.scrollDOM.getBoundingClientRect();return{left:(s.textDirection==X.LTR?e.left:e.right-s.scrollDOM.clientWidth*s.scaleX)-s.scrollDOM.scrollLeft*s.scaleX,top:e.top-s.scrollDOM.scrollTop*s.scaleY}}function Mo(s,e,t){let i=b.cursor(e);return{from:Math.max(t.from,s.moveToLineBoundary(i,!1,!0).from),to:Math.min(t.to,s.moveToLineBoundary(i,!0,!0).from),type:De.Text}}function lu(s,e,t){if(t.to<=s.viewport.from||t.from>=s.viewport.to)return[];let i=Math.max(t.from,s.viewport.from),n=Math.min(t.to,s.viewport.to),r=s.textDirection==X.LTR,o=s.contentDOM,l=o.getBoundingClientRect(),a=Pa(s),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=Is(s,i),p=Is(s,n),m=d.type==De.Text?d:null,g=p.type==De.Text?p:null;if(m&&(s.lineWrapping||d.widgetLineBreaks)&&(m=Mo(s,i,m)),g&&(s.lineWrapping||p.widgetLineBreaks)&&(g=Mo(s,n,g)),m&&g&&m.from==g.from)return w(S(t.from,t.to,m));{let x=m?S(t.from,null,m):v(d,!1),A=g?S(null,t.to,g):v(p,!0),C=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&x.bottom+s.defaultLineHeight/2<A.top?C.push(y(f,x.bottom,u,A.top)):x.bottom<A.top&&s.elementAtHeight((x.bottom+A.top)/2).type==De.Text&&(x.bottom=A.top=(x.bottom+A.top)/2),w(x).concat(C).concat(w(A))}function y(x,A,C,P){return new Pi(e,x-a.left,A-a.top-.01,C-x,P-A+.01)}function w({top:x,bottom:A,horizontal:C}){let P=[];for(let I=0;I<C.length;I+=2)P.push(y(C[I],x,C[I+1],A));return P}function S(x,A,C){let P=1e9,I=-1e9,N=[];function E(W,J,be,we,ke){let Oe=s.coordsAtPos(W,W==C.to?-2:2),Z=s.coordsAtPos(be,be==C.from?2:-2);!Oe||!Z||(P=Math.min(Oe.top,Z.top,P),I=Math.max(Oe.bottom,Z.bottom,I),ke==X.LTR?N.push(r&&J?f:Oe.left,r&&we?u:Z.right):N.push(!r&&we?f:Z.left,!r&&J?u:Oe.right))}let L=x??C.from,z=A??C.to;for(let W of s.visibleRanges)if(W.to>L&&W.from<z)for(let J=Math.max(W.from,L),be=Math.min(W.to,z);;){let we=s.state.doc.lineAt(J);for(let ke of s.bidiSpans(we)){let Oe=ke.from+we.from,Z=ke.to+we.from;if(Oe>=be)break;Z>J&&E(Math.max(Oe,J),x==null&&Oe<=L,Math.min(Z,be),A==null&&Z>=z,ke.dir)}if(J=we.to+1,J>=be)break}return N.length==0&&E(L,x==null,z,A==null,s.textDirection),{top:P,bottom:I,horizontal:N}}function v(x,A){let C=l.top+(A?x.top:x.bottom);return{top:C,bottom:C,horizontal:[]}}}function au(s,e){return s.constructor==e.constructor&&s.eq(e)}class hu{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=e.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),t.above&&this.dom.classList.add("cm-layer-above"),t.class&&this.dom.classList.add(t.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(e.state),e.requestMeasure(this.measureReq),t.mount&&t.mount(this.dom,e)}update(e){e.startState.facet(an)!=e.state.facet(an)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}setOrder(e){let t=0,i=e.facet(an);for(;t<i.length&&i[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,i)=>!au(t,this.drawn[i]))){let t=this.dom.firstChild,i=0;for(let n of e)n.update&&t&&n.constructor&&this.drawn[i].constructor&&n.update(t,this.drawn[i])?(t=t.nextSibling,i++):this.dom.insertBefore(n.draw(),t);for(;t;){let n=t.nextSibling;t.remove(),t=n}this.drawn=e}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const an=O.define();function La(s){return[ue.define(e=>new hu(e,s)),an.of(s)]}const Ra=!D.ios,vi=O.define({combine(s){return Pt(s,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function im(s={}){return[vi.of(s),cu,fu,uu,oa.of(!0)]}function Ea(s){return s.startState.facet(vi)!=s.state.facet(vi)}const cu=La({above:!0,markers(s){let{state:e}=s,t=e.facet(vi),i=[];for(let n of e.selection.ranges){let r=n==e.selection.main;if(n.empty?!r||Ra:t.drawRangeCursor){let o=r?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",l=n.empty?n:b.cursor(n.head,n.head>n.anchor?-1:1);for(let a of Pi.forRange(s,o,l))i.push(a)}}return i},update(s,e){s.transactions.some(i=>i.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=Ea(s);return t&&Do(s.state,e),s.docChanged||s.selectionSet||t},mount(s,e){Do(e.state,s)},class:"cm-cursorLayer"});function Do(s,e){e.style.animationDuration=s.facet(vi).cursorBlinkRate+"ms"}const fu=La({above:!1,markers(s){return s.state.selection.ranges.map(e=>e.empty?[]:Pi.forRange(s,"cm-selectionBackground",e)).reduce((e,t)=>e.concat(t))},update(s,e){return s.docChanged||s.selectionSet||s.viewportChanged||Ea(s)},class:"cm-selectionLayer"}),Hs={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};Ra&&(Hs[".cm-line"].caretColor="transparent !important",Hs[".cm-content"]={caretColor:"transparent !important"});const uu=Bt.highest(T.theme(Hs)),Ia=F.define({map(s,e){return s==null?null:e.mapPos(s)}}),fi=ye.define({create(){return null},update(s,e){return s!=null&&(s=e.changes.mapPos(s)),e.effects.reduce((t,i)=>i.is(Ia)?i.value:t,s)}}),du=ue.fromClass(class{constructor(s){this.view=s,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(s){var e;let t=s.state.field(fi);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(s.startState.field(fi)!=t||s.docChanged||s.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:s}=this,e=s.state.field(fi),t=e!=null&&s.coordsAtPos(e);if(!t)return null;let i=s.scrollDOM.getBoundingClientRect();return{left:t.left-i.left+s.scrollDOM.scrollLeft*s.scaleX,top:t.top-i.top+s.scrollDOM.scrollTop*s.scaleY,height:t.bottom-t.top}}drawCursor(s){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;s?(this.cursor.style.left=s.left/e+"px",this.cursor.style.top=s.top/t+"px",this.cursor.style.height=s.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(s){this.view.state.field(fi)!=s&&this.view.dispatch({effects:Ia.of(s)})}},{eventObservers:{dragover(s){this.setDropPos(this.view.posAtCoords({x:s.clientX,y:s.clientY}))},dragleave(s){(s.target==this.view.contentDOM||!this.view.contentDOM.contains(s.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function nm(){return[fi,du]}function Oo(s,e,t,i,n){e.lastIndex=0;for(let r=s.iterRange(t,i),o=t,l;!r.next().done;o+=r.value.length)if(!r.lineBreak)for(;l=e.exec(r.value);)n(o+l.index,l)}function pu(s,e){let t=s.visibleRanges;if(t.length==1&&t[0].from==s.viewport.from&&t[0].to==s.viewport.to)return t;let i=[];for(let{from:n,to:r}of t)n=Math.max(s.state.doc.lineAt(n).from,n-e),r=Math.min(s.state.doc.lineAt(r).to,r+e),i.length&&i[i.length-1].to>=n?i[i.length-1].to=r:i.push({from:n,to:r});return i}class gu{constructor(e){const{regexp:t,decoration:i,decorate:n,boundary:r,maxLength:o=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,n)this.addMatch=(l,a,h,c)=>n(c,h,h+l[0].length,l,a);else if(typeof i=="function")this.addMatch=(l,a,h,c)=>{let f=i(l,a,h);f&&c(h,h+l[0].length,f)};else if(i)this.addMatch=(l,a,h,c)=>c(h,h+l[0].length,i);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=r,this.maxLength=o}createDeco(e){let t=new At,i=t.add.bind(t);for(let{from:n,to:r}of pu(e,this.maxLength))Oo(e.state.doc,this.regexp,n,r,(o,l)=>this.addMatch(l,e,o,i));return t.finish()}updateDeco(e,t){let i=1e9,n=-1;return e.docChanged&&e.changes.iterChanges((r,o,l,a)=>{a>e.view.viewport.from&&l<e.view.viewport.to&&(i=Math.min(l,i),n=Math.max(a,n))}),e.viewportChanged||n-i>1e3?this.createDeco(e.view):n>-1?this.updateRange(e.view,t.map(e.changes),i,n):t}updateRange(e,t,i,n){for(let r of e.visibleRanges){let o=Math.max(r.from,i),l=Math.min(r.to,n);if(l>o){let a=e.state.doc.lineAt(o),h=a.to<l?e.state.doc.lineAt(l):a,c=Math.max(r.from,a.from),f=Math.min(r.to,h.to);if(this.boundary){for(;o>a.from;o--)if(this.boundary.test(a.text[o-1-a.from])){c=o;break}for(;l<h.to;l++)if(this.boundary.test(h.text[l-h.from])){f=l;break}}let u=[],d,p=(m,g,y)=>u.push(y.range(m,g));if(a==h)for(this.regexp.lastIndex=c-a.from;(d=this.regexp.exec(a.text))&&d.index<f-a.from;)this.addMatch(d,e,d.index+a.from,p);else Oo(e.state.doc,this.regexp,c,f,(m,g)=>this.addMatch(g,e,m,p));t=t.update({filterFrom:c,filterTo:f,filter:(m,g)=>m<c||g>f,add:u})}}return t}}const zs=/x/.unicode!=null?"gu":"g",mu=new RegExp(`[\0-\b
--Ÿ­؜\u2028\u2029\uFEFF-]`,zs),yu={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 _n=null;function bu(){var s;if(_n==null&&typeof document<"u"&&document.body){let e=document.body.style;_n=((s=e.tabSize)!==null&&s!==void 0?s:e.MozTabSize)!=null}return _n||!1}const hn=O.define({combine(s){let e=Pt(s,{render:null,specialChars:mu,addSpecialChars:null});return(e.replaceTabs=!bu())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,zs)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,zs)),e}});function sm(s={}){return[hn.of(s),wu()]}let To=null;function wu(){return To||(To=ue.fromClass(class{constructor(s){this.view=s,this.decorations=B.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(s.state.facet(hn)),this.decorations=this.decorator.createDeco(s)}makeDecorator(s){return new gu({regexp:s.specialChars,decoration:(e,t,i)=>{let{doc:n}=t.state,r=ne(e[0],0);if(r==9){let o=n.lineAt(i),l=t.state.tabSize,a=_t(o.text,l,i-o.from);return B.replace({widget:new Su((l-a%l)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[r]||(this.decorationCache[r]=B.replace({widget:new ku(s,r)}))},boundary:s.replaceTabs?void 0:/[^]/})}update(s){let e=s.state.facet(hn);s.startState.facet(hn)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(s.view)):this.decorations=this.decorator.updateDeco(s,this.decorations)}},{decorations:s=>s.decorations}))}const xu="•";function vu(s){return s>=32?xu:s==10?"␤":String.fromCharCode(9216+s)}class ku extends Lt{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=vu(this.code),i=e.state.phrase("Control character")+" "+(yu[this.code]||"0x"+this.code.toString(16)),n=this.options.render&&this.options.render(this.code,i,t);if(n)return n;let r=document.createElement("span");return r.textContent=t,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Su extends Lt{constructor(e){super(),this.width=e}eq(e){return e.width==this.width}toDOM(){let e=document.createElement("span");return e.textContent=" ",e.className="cm-tab",e.style.width=this.width+"px",e}ignoreEvent(){return!1}}class Cu extends Lt{constructor(e){super(),this.content=e}toDOM(){let e=document.createElement("span");return e.className="cm-placeholder",e.style.pointerEvents="none",e.appendChild(typeof this.content=="string"?document.createTextNode(this.content):this.content),typeof this.content=="string"?e.setAttribute("aria-label","placeholder "+this.content):e.setAttribute("aria-hidden","true"),e}coordsAt(e){let t=e.firstChild?jt(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),n=Ln(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return n.bottom-n.top>r*1.5?{left:n.left,right:n.right,top:n.top,bottom:n.top+r}:n}ignoreEvent(){return!1}}function rm(s){return ue.fromClass(class{constructor(e){this.view=e,this.placeholder=s?B.set([B.widget({widget:new Cu(s),side:1}).range(0)]):B.none}get decorations(){return this.view.state.doc.length?B.none:this.placeholder}},{decorations:e=>e.decorations})}const qs=2e3;function Au(s,e,t){let i=Math.min(e.line,t.line),n=Math.max(e.line,t.line),r=[];if(e.off>qs||t.off>qs||e.col<0||t.col<0){let o=Math.min(e.off,t.off),l=Math.max(e.off,t.off);for(let a=i;a<=n;a++){let h=s.doc.line(a);h.length<=l&&r.push(b.range(h.from+o,h.to+l))}}else{let o=Math.min(e.col,t.col),l=Math.max(e.col,t.col);for(let a=i;a<=n;a++){let h=s.doc.line(a),c=xs(h.text,o,s.tabSize,!0);if(c<0)r.push(b.cursor(h.to));else{let f=xs(h.text,l,s.tabSize);r.push(b.range(h.from+c,h.from+f))}}}return r}function Mu(s,e){let t=s.coordsAtPos(s.viewport.from);return t?Math.round(Math.abs((t.left-e)/s.defaultCharacterWidth)):-1}function Bo(s,e){let t=s.posAtCoords({x:e.clientX,y:e.clientY},!1),i=s.state.doc.lineAt(t),n=t-i.from,r=n>qs?-1:n==i.length?Mu(s,e.clientX):_t(i.text,s.state.tabSize,t-i.from);return{line:i.number,col:r,off:n}}function Du(s,e){let t=Bo(s,e),i=s.state.selection;return t?{update(n){if(n.docChanged){let r=n.changes.mapPos(n.startState.doc.line(t.line).from),o=n.state.doc.lineAt(r);t={line:o.number,col:t.col,off:Math.min(t.off,o.length)},i=i.map(n.changes)}},get(n,r,o){let l=Bo(s,n);if(!l)return i;let a=Au(s.state,t,l);return a.length?o?b.create(a.concat(i.ranges)):b.create(a):i}}:null}function om(s){let e=(s==null?void 0:s.eventFilter)||(t=>t.altKey&&t.button==0);return T.mouseSelectionStyle.of((t,i)=>e(i)?Du(t,i):null)}const ni="-10000px";class Ou{constructor(e,t,i,n){this.facet=t,this.createTooltipView=i,this.removeTooltipView=n,this.input=e.state.facet(t),this.tooltips=this.input.filter(r=>r),this.tooltipViews=this.tooltips.map(i)}update(e,t){var i;let n=e.state.facet(this.facet),r=n.filter(a=>a);if(n===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let 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),l&&(l[a]=!!h.above);else{let f=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),f.update&&f.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function Tu(s){let{win:e}=s;return{top:0,left:0,bottom:e.innerHeight,right:e.innerWidth}}const Qn=O.define({combine:s=>{var e,t,i;return{position:D.ios?"absolute":((e=s.find(n=>n.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=s.find(n=>n.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Tu}}}),Po=new WeakMap,Na=ue.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=s.state.facet(Qn);this.position=e.position,this.parent=e.parent,this.classes=s.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 Ou(s,Fa,t=>this.createTooltip(t),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),s.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 s of this.manager.tooltipViews)this.intersectionObserver.observe(s.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(s){s.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(s,this.above);e&&this.observeIntersection();let t=e||s.geometryChanged,i=s.state.facet(Qn);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(s){let e=s.create(this.view);if(e.dom.classList.add("cm-tooltip"),s.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",e.dom.appendChild(t)}return e.dom.style.position=this.position,e.dom.style.top=ni,e.dom.style.left="0px",this.container.appendChild(e.dom),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var s,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(s=i.destroy)===null||s===void 0||s.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=this.view.dom.getBoundingClientRect(),e=1,t=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:n}=this.manager.tooltipViews[0];if(D.gecko)i=n.offsetParent!=this.container.ownerDocument.body;else if(n.style.top==ni&&n.style.left=="0px"){let r=n.getBoundingClientRect();i=Math.abs(r.top+1e4)>1||Math.abs(r.left)>1}}if(i||this.position=="absolute")if(this.parent){let n=this.parent.getBoundingClientRect();n.width&&n.height&&(e=n.width/this.parent.offsetWidth,t=n.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:t}=this.view.viewState);return{editor:s,parent:this.parent?this.container.getBoundingClientRect():s,pos:this.manager.tooltips.map((n,r)=>{let o=this.manager.tooltipViews[r];return o.getCoords?o.getCoords(n.pos):this.view.coordsAtPos(n.pos)}),size:this.manager.tooltipViews.map(({dom:n})=>n.getBoundingClientRect()),space:this.view.state.facet(Qn).tooltipSpace(this.view),scaleX:e,scaleY:t,makeAbsolute:i}}writeMeasure(s){var e;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:t,space:i,scaleX:n,scaleY:r}=s,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=s.pos[l],u=s.size[l];if(!f||f.bottom<=Math.max(t.top,i.top)||f.top>=Math.min(t.bottom,i.bottom)||f.right<Math.max(t.left,i.left)-.1||f.left>Math.min(t.right,i.right)+.1){c.style.top=ni;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=u.right-u.left,g=(e=Po.get(h))!==null&&e!==void 0?e:u.bottom-u.top,y=h.offset||Pu,w=this.view.textDirection==X.LTR,S=u.width>i.right-i.left?w?i.left:i.right-u.width:w?Math.min(f.left-(d?14:0)+y.x,i.right-m):Math.max(i.left,f.left-m+(d?14:0)-y.x),v=this.above[l];!a.strictSide&&(v?f.top-(u.bottom-u.top)-y.y<i.top:f.bottom+(u.bottom-u.top)+y.y>i.bottom)&&v==i.bottom-f.bottom>f.top-i.top&&(v=this.above[l]=!v);let x=(v?f.top-i.top:i.bottom-f.bottom)-p;if(x<g&&h.resize!==!1){if(x<this.view.defaultLineHeight){c.style.top=ni;continue}Po.set(h,g),c.style.height=(g=x)/r+"px"}else c.style.height&&(c.style.height="");let A=v?f.top-g-p-y.y:f.bottom+p+y.y,C=S+m;if(h.overlap!==!0)for(let P of o)P.left<C&&P.right>S&&P.top<A+g&&P.bottom>A&&(A=v?P.top-g-2-p:P.bottom+p+2);if(this.position=="absolute"?(c.style.top=(A-s.parent.top)/r+"px",c.style.left=(S-s.parent.left)/n+"px"):(c.style.top=A/r+"px",c.style.left=S/n+"px"),d){let P=f.left+(w?y.x:-y.x)-(S+14-7);d.style.left=P/n+"px"}h.overlap!==!0&&o.push({left:S,top:A,right:C,bottom:A+g}),c.classList.toggle("cm-tooltip-above",v),c.classList.toggle("cm-tooltip-below",!v),h.positioned&&h.positioned(s.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 s of this.manager.tooltipViews)s.dom.style.top=ni}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Bu=T.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"}}}),Pu={x:0,y:0},Fa=O.define({enables:[Na,Bu]});function Va(s,e){let t=s.plugin(Na);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Lo=O.define({combine(s){let e,t;for(let i of s)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function mn(s,e){let t=s.plugin(Wa),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Wa=ue.fromClass(class{constructor(s){this.input=s.state.facet(yn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(s));let e=s.state.facet(Lo);this.top=new Gi(s,!0,e.topContainer),this.bottom=new Gi(s,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(s){let e=s.state.facet(Lo);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Gi(s.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Gi(s.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=s.state.facet(yn);if(t!=this.input){let i=t.filter(a=>a),n=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(s.view),l.push(c)):(c=this.panels[h],c.update&&c.update(s)),n.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=n,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(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>T.scrollMargins.of(e=>{let t=e.plugin(s);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Gi{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=Ro(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=Ro(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function Ro(s){let e=s.nextSibling;return s.remove(),e}const yn=O.define({enables:Wa});class Ot extends Ct{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Ot.prototype.elementClass="";Ot.prototype.toDOM=void 0;Ot.prototype.mapMode=he.TrackBefore;Ot.prototype.startSide=Ot.prototype.endSide=-1;Ot.prototype.point=!0;const Lu=O.define(),Ru=new class extends Ot{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Eu=Lu.compute(["selection"],s=>{let e=[],t=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.head).from;n>t&&(t=n,e.push(Ru.range(n)))}return $.of(e)});function lm(){return Eu}const Iu=1024;let Nu=0;class Pe{constructor(e,t){this.from=e,this.to=t}}class R{constructor(e={}){this.id=Nu++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=ge.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}R.closedBy=new R({deserialize:s=>s.split(" ")});R.openedBy=new R({deserialize:s=>s.split(" ")});R.group=new R({deserialize:s=>s.split(" ")});R.isolate=new R({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});R.contextHash=new R({perNode:!0});R.lookAhead=new R({perNode:!0});R.mounted=new R({perNode:!0});class ki{constructor(e,t,i){this.tree=e,this.overlay=t,this.parser=i}static get(e){return e&&e.props&&e.props[R.mounted.id]}}const Fu=Object.create(null);class ge{constructor(e,t,i,n=0){this.name=e,this.props=t,this.id=i,this.flags=n}static define(e){let t=e.props&&e.props.length?Object.create(null):Fu,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),n=new ge(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(n)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return n}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(R.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let n of i.split(" "))t[n]=e[i];return i=>{for(let n=i.prop(R.group),r=-1;r<(n?n.length:0);r++){let o=t[r<0?i.name:n[r]];if(o)return o}}}}ge.none=new ge("",Object.create(null),0,8);class pr{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let n=null;for(let r of e){let o=r(i);o&&(n||(n=Object.assign({},i.props)),n[o[0].id]=o[1])}t.push(n?new ge(i.name,n,i.id,i.flags):i)}return new pr(t)}}const Ji=new WeakMap,Eo=new WeakMap;var Y;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays"})(Y||(Y={}));class K{constructor(e,t,i,n,r){if(this.type=e,this.children=t,this.positions=i,this.length=n,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=ki.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let n=i.toString();n&&(t&&(t+=","),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new bn(this.topNode,e)}cursorAt(e,t=0,i=0){let n=Ji.get(this)||this.topNode,r=new bn(n);return r.moveTo(e,t),Ji.set(this,r._tree),r}get topNode(){return new fe(this,0,0,null)}resolve(e,t=0){let i=Si(Ji.get(this)||this.topNode,e,t,!1);return Ji.set(this,i),i}resolveInner(e,t=0){let i=Si(Eo.get(this)||this.topNode,e,t,!0);return Eo.set(this,i),i}resolveStack(e,t=0){return Hu(this,e,t)}iterate(e){let{enter:t,leave:i,from:n=0,to:r=this.length}=e,o=e.mode||0,l=(o&Y.IncludeAnonymous)>0;for(let a=this.cursor(o|Y.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=n&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:yr(ge.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,n)=>new K(this.type,t,i,n,this.propValues),e.makeTree||((t,i,n)=>new K(ge.none,t,i,n)))}static build(e){return zu(e)}}K.empty=new K(ge.none,[],[],0);class gr{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new gr(this.buffer,this.index)}}class gt{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return ge.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],n=this.set.types[t],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,n,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Ha(r,n,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let n=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=n[l++],r[a++]=n[l++]-i;let h=r[a++]=n[l++]-i;r[a++]=n[l++]-e,o=Math.max(o,h)}return new gt(r,o,this.set)}}function Ha(s,e,t,i){switch(s){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Si(s,e,t,i){for(var n;s.from==s.to||(t<1?s.from>=e:s.from>e)||(t>-1?s.to<=e:s.to<e);){let o=!i&&s instanceof fe&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:Y.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof fe&&o.index<0&&((n=l.enter(e,t,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(e,t,r);if(!o)return s;s=o}}class za{cursor(e=0){return new bn(this,e)}getChild(e,t=null,i=null){let n=Io(this,e,t,i);return n.length?n[0]:null}getChildren(e,t=null,i=null){return Io(this,e,t,i)}resolve(e,t=0){return Si(this,e,t,!1)}resolveInner(e,t=0){return Si(this,e,t,!0)}matchContext(e){return $s(this,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let n=t.lastChild;if(!n||n.to!=t.to)break;n.type.isError&&n.from==n.to?(i=t,t=n.prevSibling):t=n}return i}get node(){return this}get next(){return this.parent}}class fe extends za{constructor(e,t,i,n){super(),this._tree=e,this.from=t,this.index=i,this._parent=n}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,n,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],f=a[e]+o.from;if(Ha(n,i,f,f+c.length)){if(c instanceof gt){if(r&Y.ExcludeBuffers)continue;let u=c.findChild(0,c.buffer.length,t,i-f,n);if(u>-1)return new Je(new Vu(o,c,e,f),null,u)}else if(r&Y.IncludeAnonymous||!c.type.isAnonymous||mr(c)){let u;if(!(r&Y.IgnoreMounts)&&(u=ki.get(c))&&!u.overlay)return new fe(u.tree,f,e,o);let d=new fe(c,f,e,o);return r&Y.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(t<0?c.children.length-1:0,t,i,n)}}}if(r&Y.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,i=0){let n;if(!(i&Y.IgnoreOverlays)&&(n=ki.get(this._tree))&&n.overlay){let r=e-this.from;for(let{from:o,to:l}of n.overlay)if((t>0?o<=r:o<r)&&(t<0?l>=r:l>r))return new fe(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Io(s,e,t,i){let n=s.cursor(),r=[];if(!n.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=n.type.is(t),!n.nextSibling())return r}for(;;){if(i!=null&&n.type.is(i))return r;if(n.type.is(e)&&r.push(n.node),!n.nextSibling())return i==null?r:[]}}function $s(s,e,t=e.length-1){for(let i=s.parent;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class Vu{constructor(e,t,i,n){this.parent=e,this.buffer=t,this.index=i,this.start=n}}class Je extends za{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new Je(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,i=0){if(i&Y.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new Je(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new Je(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new Je(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let o=i.buffer[this.index+1];e.push(i.slice(n,r,o)),t.push(0)}return new K(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function qa(s){if(!s.length)return null;let e=0,t=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof fe&&t.index<0?null:t.parent,n=s.slice();return i?n[e]=i:n.splice(e,1),new Wu(n,t)}class Wu{constructor(e,t){this.heads=e,this.node=t}get next(){return qa(this.heads)}}function Hu(s,e,t){let i=s.resolveInner(e,t),n=null;for(let r=i instanceof fe?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(e,t)),r=o}else{let o=ki.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new fe(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(Si(l,e,t,!1))}}return n?qa(n):i}class bn{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof fe)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:n}=this.buffer;return this.type=t||n.set.types[n.buffer[e]],this.from=i+n.buffer[e+1],this.to=i+n.buffer[e+2],!0}yield(e){return e?e instanceof fe?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&Y.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,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 e=this.mode&Y.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(t.findChild(n,this.index,-1,0,4))}else{let n=t.buffer[this.index+3];if(n<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:n}=this;if(n){if(e>0){if(this.index<n.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(n.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=n)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&Y.IncludeAnonymous||l instanceof gt||!l.type.isAnonymous||mr(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==n){if(n==this.index)return o;t=o,i=r+1;break e}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)t=new Je(this.buffer,t,this.stack[n]);return this.bufferNode=new Je(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let n=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;n&&t&&t(this),n=this.type.isAnonymous,!this.nextSibling();){if(!i)return;this.parent(),i--,n=!0}}}matchContext(e){if(!this.buffer)return $s(this.node,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let n=e.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return $s(this.node,e,n);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[n]&&e[n]!=o.name)return!1;n--}}return!0}}function mr(s){return s.children.some(e=>e instanceof gt||!e.type.isAnonymous||mr(e))}function zu(s){var e;let{buffer:t,nodeSet:i,maxBufferLength:n=Iu,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(t)?new gr(t,t.length):t,a=i.types,h=0,c=0;function f(x,A,C,P,I,N){let{id:E,start:L,end:z,size:W}=l,J=c;for(;W<0;)if(l.next(),W==-1){let Z=r[E];C.push(Z),P.push(L-x);return}else if(W==-3){h=E;return}else if(W==-4){c=E;return}else throw new RangeError(`Unrecognized record size: ${W}`);let be=a[E],we,ke,Oe=L-x;if(z-L<=n&&(ke=g(l.pos-A,I))){let Z=new Uint16Array(ke.size-ke.skip),Te=l.pos-ke.size,He=Z.length;for(;l.pos>Te;)He=y(ke.start,Z,He);we=new gt(Z,z-ke.start,i),Oe=ke.start-x}else{let Z=l.pos-W;l.next();let Te=[],He=[],yt=E>=o?E:-1,Rt=0,Ii=z;for(;l.pos>Z;)yt>=0&&l.id==yt&&l.size>=0?(l.end<=Ii-n&&(p(Te,He,L,Rt,l.end,Ii,yt,J),Rt=Te.length,Ii=l.end),l.next()):N>2500?u(L,Z,Te,He):f(L,Z,Te,He,yt,N+1);if(yt>=0&&Rt>0&&Rt<Te.length&&p(Te,He,L,Rt,L,Ii,yt,J),Te.reverse(),He.reverse(),yt>-1&&Rt>0){let Lr=d(be);we=yr(be,Te,He,0,Te.length,0,z-L,Lr,Lr)}else we=m(be,Te,He,z-L,J-z)}C.push(we),P.push(Oe)}function u(x,A,C,P){let I=[],N=0,E=-1;for(;l.pos>A;){let{id:L,start:z,end:W,size:J}=l;if(J>4)l.next();else{if(E>-1&&z<E)break;E<0&&(E=W-n),I.push(L,z,W),N++,l.next()}}if(N){let L=new Uint16Array(N*4),z=I[I.length-2];for(let W=I.length-3,J=0;W>=0;W-=3)L[J++]=I[W],L[J++]=I[W+1]-z,L[J++]=I[W+2]-z,L[J++]=J;C.push(new gt(L,I[2]-z,i)),P.push(z-x)}}function d(x){return(A,C,P)=>{let I=0,N=A.length-1,E,L;if(N>=0&&(E=A[N])instanceof K){if(!N&&E.type==x&&E.length==P)return E;(L=E.prop(R.lookAhead))&&(I=C[N]+E.length+L)}return m(x,A,C,P,I)}}function p(x,A,C,P,I,N,E,L){let z=[],W=[];for(;x.length>P;)z.push(x.pop()),W.push(A.pop()+C-I);x.push(m(i.types[E],z,W,N-I,L-N)),A.push(I-C)}function m(x,A,C,P,I=0,N){if(h){let E=[R.contextHash,h];N=N?[E].concat(N):[E]}if(I>25){let E=[R.lookAhead,I];N=N?[E].concat(N):[E]}return new K(x,A,C,P,N)}function g(x,A){let C=l.fork(),P=0,I=0,N=0,E=C.end-n,L={size:0,start:0,skip:0};e:for(let z=C.pos-x;C.pos>z;){let W=C.size;if(C.id==A&&W>=0){L.size=P,L.start=I,L.skip=N,N+=4,P+=4,C.next();continue}let J=C.pos-W;if(W<0||J<z||C.start<E)break;let be=C.id>=o?4:0,we=C.start;for(C.next();C.pos>J;){if(C.size<0)if(C.size==-3)be+=4;else break e;else C.id>=o&&(be+=4);C.next()}I=we,P+=W,N+=be}return(A<0||P==x)&&(L.size=P,L.start=I,L.skip=N),L.size>4?L:void 0}function y(x,A,C){let{id:P,start:I,end:N,size:E}=l;if(l.next(),E>=0&&P<o){let L=C;if(E>4){let z=l.pos-(E-4);for(;l.pos>z;)C=y(x,A,C)}A[--C]=L,A[--C]=N-x,A[--C]=I-x,A[--C]=P}else E==-3?h=P:E==-4&&(c=P);return C}let w=[],S=[];for(;l.pos>0;)f(s.start||0,s.bufferStart||0,w,S,-1,0);let v=(e=s.length)!==null&&e!==void 0?e:w.length?S[0]+w[0].length:0;return new K(a[s.topID],w.reverse(),S.reverse(),v)}const No=new WeakMap;function cn(s,e){if(!s.isAnonymous||e instanceof gt||e.type!=s)return 1;let t=No.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=s||!(i instanceof K)){t=1;break}t+=cn(s,i)}No.set(e,t)}return t}function yr(s,e,t,i,n,r,o,l,a){let h=0;for(let p=i;p<n;p++)h+=cn(s,e[p]);let c=Math.ceil(h*1.5/8),f=[],u=[];function d(p,m,g,y,w){for(let S=g;S<y;){let v=S,x=m[S],A=cn(s,p[S]);for(S++;S<y;S++){let C=cn(s,p[S]);if(A+C>=c)break;A+=C}if(S==v+1){if(A>c){let C=p[v];d(C.children,C.positions,0,C.children.length,m[v]+w);continue}f.push(p[v])}else{let C=m[S-1]+p[S-1].length-x;f.push(yr(s,p,m,v,S,x,C,null,a))}u.push(x+w-r)}}return d(e,t,i,n,0),(l||a)(f,u,o)}class am{constructor(){this.map=new WeakMap}setBuffer(e,t,i){let n=this.map.get(e);n||this.map.set(e,n=new Map),n.set(t,i)}getBuffer(e,t){let i=this.map.get(e);return i&&i.get(t)}set(e,t){e instanceof Je?this.setBuffer(e.context.buffer,e.index,t):e instanceof fe&&this.map.set(e.tree,t)}get(e){return e instanceof Je?this.getBuffer(e.context.buffer,e.index):e instanceof fe?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Ze{constructor(e,t,i,n,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=n,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let n=[new Ze(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&n.push(r);return n}static applyChanges(e,t,i=128){if(!t.length)return e;let n=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,f=c?c.fromA:1e9;if(f-a>=i)for(;o&&o.from<f;){let u=o;if(a>=u.from||f<=u.to||h){let d=Math.max(u.from,a)-h,p=Math.min(u.to,f)-h;u=d>=p?null:new Ze(d,p,u.tree,u.offset+h,l>0,!!c)}if(u&&n.push(u),o.to>f)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return n}}class $a{startParse(e,t,i){return typeof e=="string"&&(e=new qu(e)),i=i?i.length?i.map(n=>new Pe(n.from,n.to)):[new Pe(0,0)]:[new Pe(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let n=this.startParse(e,t,i);for(;;){let r=n.advance();if(r)return r}}}class qu{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}function hm(s){return(e,t,i,n)=>new Ku(e,s,t,i,n)}class Fo{constructor(e,t,i,n,r){this.parser=e,this.parse=t,this.overlay=i,this.target=n,this.from=r}}function Vo(s){if(!s.length||s.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(s))}class $u{constructor(e,t,i,n,r,o,l){this.parser=e,this.predicate=t,this.mounts=i,this.index=n,this.start=r,this.target=o,this.prev=l,this.depth=0,this.ranges=[]}}const Ks=new R({perNode:!0});class Ku{constructor(e,t,i,n,r){this.nest=t,this.input=i,this.fragments=n,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let i=this.baseParse.advance();if(!i)return null;if(this.baseParse=null,this.baseTree=i,this.startInner(),this.stoppedAt!=null)for(let n of this.inner)n.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let i=this.baseTree;return this.stoppedAt!=null&&(i=new K(i.type,i.children,i.positions,i.length,i.propValues.concat([[Ks,this.stoppedAt]]))),i}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let i=Object.assign(Object.create(null),e.target.props);i[R.mounted.id]=new ki(t,e.overlay,e.parser),e.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new Gu(this.fragments),t=null,i=null,n=new bn(new fe(this.baseTree,this.ranges[0].from,0,null),Y.IncludeAnonymous|Y.IgnoreMounts);e:for(let r,o;;){let l=!0,a;if(this.stoppedAt!=null&&n.from>=this.stoppedAt)l=!1;else if(e.hasNode(n)){if(t){let h=t.mounts.find(c=>c.frag.from<=n.from&&c.frag.to>=n.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>=n.from&&u<=n.to&&!t.ranges.some(d=>d.from<u&&d.to>f)&&t.ranges.push({from:f,to:u})}}l=!1}else if(i&&(o=ju(i.ranges,n.from,n.to)))l=o!=2;else if(!n.type.isAnonymous&&(r=this.nest(n,this.input))&&(n.from<n.to||!r.overlay)){n.tree||Uu(n);let h=e.findMounts(n.from,r.parser);if(typeof r.overlay=="function")t=new $u(r.parser,r.overlay,h,this.inner.length,n.from,n.tree,t);else{let c=zo(this.ranges,r.overlay||(n.from<n.to?[new Pe(n.from,n.to)]:[]));c.length&&Vo(c),(c.length||!r.overlay)&&this.inner.push(new Fo(r.parser,c.length?r.parser.startParse(this.input,qo(h,c),c):r.parser.startParse(""),r.overlay?r.overlay.map(f=>new Pe(f.from-n.from,f.to-n.from)):null,n.tree,c.length?c[0].from:n.from)),r.overlay?c.length&&(i={ranges:c,depth:0,prev:i}):l=!1}}else t&&(a=t.predicate(n))&&(a===!0&&(a=new Pe(n.from,n.to)),a.from<a.to&&t.ranges.push(a));if(l&&n.firstChild())t&&t.depth++,i&&i.depth++;else for(;!n.nextSibling();){if(!n.parent())break e;if(t&&!--t.depth){let h=zo(this.ranges,t.ranges);h.length&&(Vo(h),this.inner.splice(t.index,0,new Fo(t.parser,t.parser.startParse(this.input,qo(t.mounts,h),h),t.ranges.map(c=>new Pe(c.from-t.start,c.to-t.start)),t.target,h[0].from))),t=t.prev}i&&!--i.depth&&(i=i.prev)}}}}function ju(s,e,t){for(let i of s){if(i.from>=t)break;if(i.to>e)return i.from<=e&&i.to>=t?2:1}return 0}function Wo(s,e,t,i,n,r){if(e<t){let o=s.buffer[e+1];i.push(s.slice(e,t,o)),n.push(o-r)}}function Uu(s){let{node:e}=s,t=[],i=e.context.buffer;do t.push(s.index),s.parent();while(!s.tree);let n=s.tree,r=n.children.indexOf(i),o=n.children[r],l=o.buffer,a=[r];function h(c,f,u,d,p,m){let g=t[m],y=[],w=[];Wo(o,c,g,y,w,d);let S=l[g+1],v=l[g+2];a.push(y.length);let x=m?h(g+4,l[g+3],o.set.types[l[g]],S,v-S,m-1):e.toTree();return y.push(x),w.push(S-d),Wo(o,l[g+3],f,y,w,d),new K(u,y,w,p)}n.children[r]=h(0,l.length,ge.none,0,o.length,t.length-1);for(let c of a){let f=s.tree.children[c],u=s.tree.positions[c];s.yield(new fe(f,u+s.from,c,s._tree))}}class Ho{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(Y.IncludeAnonymous|Y.IgnoreMounts)}moveTo(e){let{cursor:t}=this,i=e-this.offset;for(;!this.done&&t.from<i;)t.to>=e&&t.enter(i,1,Y.IgnoreOverlays|Y.ExcludeBuffers)||t.next(!1)||(this.done=!0)}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof K)t=t.children[0];else break}return!1}}class Gu{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let i=this.curFrag=e[0];this.curTo=(t=i.tree.prop(Ks))!==null&&t!==void 0?t:i.to,this.inner=new Ho(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Ks))!==null&&e!==void 0?e:t.to,this.inner=new Ho(t.tree,-t.offset)}}findMounts(e,t){var i;let n=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let r=this.inner.cursor.node;r;r=r.parent){let o=(i=r.tree)===null||i===void 0?void 0:i.prop(R.mounted);if(o&&o.parser==t)for(let l=this.fragI;l<this.fragments.length;l++){let a=this.fragments[l];if(a.from>=r.to)break;a.tree==this.curFrag.tree&&n.push({frag:a,pos:r.from-a.offset,mount:o})}}}return n}}function zo(s,e){let t=null,i=e;for(let n=1,r=0;n<s.length;n++){let o=s[n-1].to,l=s[n].from;for(;r<i.length;r++){let a=i[r];if(a.from>=l)break;a.to<=o||(t||(i=t=e.slice()),a.from<o?(t[r]=new Pe(a.from,o),a.to>l&&t.splice(r+1,0,new Pe(l,a.to))):a.to>l?t[r--]=new Pe(l,a.to):t.splice(r--,1))}}return i}function Ju(s,e,t,i){let n=0,r=0,o=!1,l=!1,a=-1e9,h=[];for(;;){let c=n==s.length?1e9:o?s[n].to:s[n].from,f=r==e.length?1e9:l?e[r].to:e[r].from;if(o!=l){let u=Math.max(a,t),d=Math.min(c,f,i);u<d&&h.push(new Pe(u,d))}if(a=Math.min(c,f),a==1e9)break;c==a&&(o?(o=!1,n++):o=!0),f==a&&(l?(l=!1,r++):l=!0)}return h}function qo(s,e){let t=[];for(let{pos:i,mount:n,frag:r}of s){let o=i+(n.overlay?n.overlay[0].from:0),l=o+n.tree.length,a=Math.max(r.from,o),h=Math.min(r.to,l);if(n.overlay){let c=n.overlay.map(u=>new Pe(u.from+i,u.to+i)),f=Ju(e,c,a,h);for(let u=0,d=a;;u++){let p=u==f.length,m=p?h:f[u].from;if(m>d&&t.push(new Ze(d,m,n.tree,-o,r.from>=d||r.openStart,r.to<=m||r.openEnd)),p)break;d=f[u].to}}else t.push(new Ze(a,h,n.tree,-o,r.from>=o||r.openStart,r.to<=l||r.openEnd))}return t}let Yu=0;class je{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=Yu++}static define(e){if(e!=null&&e.base)throw new Error("Can not derive from a modified tag");let t=new je([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new wn;return t=>t.modified.indexOf(e)>-1?t:wn.get(t.base||t,t.modified.concat(e).sort((i,n)=>i.id-n.id))}}let Xu=0;class wn{constructor(){this.instances=[],this.id=Xu++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&_u(t,l.modified));if(i)return i;let n=[],r=new je(n,e,t);for(let l of t)l.instances.push(r);let o=Qu(t);for(let l of e.set)if(!l.modified.length)for(let a of o)n.push(wn.get(l,a));return r}}function _u(s,e){return s.length==e.length&&s.every((t,i)=>t==e[i])}function Qu(s){let e=[[]];for(let t=0;t<s.length;t++)for(let i=0,n=e.length;i<n;i++)e.push(e[i].concat(s[t]));return e.sort((t,i)=>i.length-t.length)}function Zu(s){let e=Object.create(null);for(let t in s){let i=s[t];Array.isArray(i)||(i=[i]);for(let n of t.split(" "))if(n){let r=[],o=2,l=n;for(let f=0;;){if(l=="..."&&f>0&&f+3==n.length){o=1;break}let u=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!u)throw new RangeError("Invalid path: "+n);if(r.push(u[0]=="*"?"":u[0][0]=='"'?JSON.parse(u[0]):u[0]),f+=u[0].length,f==n.length)break;let d=n[f++];if(f==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(f)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+n);let c=new xn(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return Ka.add(e)}const Ka=new R;class xn{constructor(e,t,i,n){this.tags=e,this.mode=t,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}xn.empty=new xn([],2,null);function ja(s,e){let t=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:n=null}=e||{};return{style:r=>{let o=n;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function ed(s,e){let t=null;for(let i of s){let n=i.style(e);n&&(t=t?t+" "+n:n)}return t}function td(s,e,t,i=0,n=s.length){let r=new id(i,Array.isArray(e)?e:[e],t);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class id{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,n,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=n,c=nd(e)||xn.empty,f=ed(r,c.tags);if(f&&(h&&(h+=" "),h+=f,c.mode==1&&(n+=(n?" ":"")+f)),this.startSpan(Math.max(t,l),h),c.opaque)return;let u=e.tree&&e.tree.prop(R.mounted);if(u&&u.overlay){let d=e.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(u.tree.type)),m=e.firstChild();for(let g=0,y=l;;g++){let w=g<u.overlay.length?u.overlay[g]:null,S=w?w.from+l:a,v=Math.max(t,y),x=Math.min(i,S);if(v<x&&m)for(;e.from<x&&(this.highlightRange(e,v,x,n,r),this.startSpan(Math.min(x,e.to),h),!(e.to>=S||!e.nextSibling())););if(!w||S>i)break;y=w.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,w.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),h))}m&&e.parent()}else if(e.firstChild()){u&&(n="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,n,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}}function nd(s){let e=s.type.prop(Ka);for(;e&&e.context&&!s.matchContext(e.context);)e=e.next;return e||null}const k=je.define,Yi=k(),st=k(),$o=k(st),Ko=k(st),rt=k(),Xi=k(rt),Zn=k(rt),Ke=k(),bt=k(Ke),qe=k(),$e=k(),js=k(),si=k(js),_i=k(),M={comment:Yi,lineComment:k(Yi),blockComment:k(Yi),docComment:k(Yi),name:st,variableName:k(st),typeName:$o,tagName:k($o),propertyName:Ko,attributeName:k(Ko),className:k(st),labelName:k(st),namespace:k(st),macroName:k(st),literal:rt,string:Xi,docString:k(Xi),character:k(Xi),attributeValue:k(Xi),number:Zn,integer:k(Zn),float:k(Zn),bool:k(rt),regexp:k(rt),escape:k(rt),color:k(rt),url:k(rt),keyword:qe,self:k(qe),null:k(qe),atom:k(qe),unit:k(qe),modifier:k(qe),operatorKeyword:k(qe),controlKeyword:k(qe),definitionKeyword:k(qe),moduleKeyword:k(qe),operator:$e,derefOperator:k($e),arithmeticOperator:k($e),logicOperator:k($e),bitwiseOperator:k($e),compareOperator:k($e),updateOperator:k($e),definitionOperator:k($e),typeOperator:k($e),controlOperator:k($e),punctuation:js,separator:k(js),bracket:si,angleBracket:k(si),squareBracket:k(si),paren:k(si),brace:k(si),content:Ke,heading:bt,heading1:k(bt),heading2:k(bt),heading3:k(bt),heading4:k(bt),heading5:k(bt),heading6:k(bt),contentSeparator:k(Ke),list:k(Ke),quote:k(Ke),emphasis:k(Ke),strong:k(Ke),link:k(Ke),monospace:k(Ke),strikethrough:k(Ke),inserted:k(),deleted:k(),changed:k(),invalid:k(),meta:_i,documentMeta:k(_i),annotation:k(_i),processingInstruction:k(_i),definition:je.defineModifier(),constant:je.defineModifier(),function:je.defineModifier(),standard:je.defineModifier(),local:je.defineModifier(),special:je.defineModifier()};ja([{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 es;const kt=new R;function Ua(s){return O.define({combine:s?e=>e.concat(s):void 0})}const sd=new R;class Le{constructor(e,t,i=[],n=""){this.data=e,this.name=n,H.prototype.hasOwnProperty("tree")||Object.defineProperty(H.prototype,"tree",{get(){return me(this)}}),this.parser=t,this.extension=[Yt.of(this),H.languageData.of((r,o,l)=>{let a=jo(r,o,l),h=a.type.prop(kt);if(!h)return[];let c=r.facet(h),f=a.type.prop(sd);if(f){let u=a.resolve(o-a.from,l);for(let d of f)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return jo(e,t,i).type.prop(kt)==this.data}findRegions(e){let t=e.facet(Yt);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(kt)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(R.mounted);if(l){if(l.tree.prop(kt)==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(n(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 K&&n(h,r.positions[a]+o)}};return n(me(e),0),i}get allowsNesting(){return!0}}Le.setState=F.define();function jo(s,e,t){let i=s.facet(Yt),n=me(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(e,t,Y.ExcludeBuffers))r.type.isTop&&(n=r);return n}class Us extends Le{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Ua(e.languageData);return new Us(t,e.parser.configure({props:[kt.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new Us(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function me(s){let e=s.field(Le.state,!1);return e?e.tree:K.empty}class rd{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let ri=null;class Gt{constructor(e,t,i=[],n,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new Gt(e,t,[],K.empty,0,i,[],null)}startParse(){return this.parser.startParse(new rd(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=K.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let n=Date.now()+e;e=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(Ze.addTree(n,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=n,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Ze.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=ri;ri=this;try{return e()}finally{ri=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Uo(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:n,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,f,u)=>a.push({fromA:h,toA:c,fromB:f,toB:u})),i=Ze.applyChanges(i,a),n=K.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),f=e.mapPos(h.to,-1);c<f&&l.push({from:c,to:f})}}}return new Gt(this.parser,t,i,n,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<e.to&&r>e.from&&(this.fragments=Uo(this.fragments,n,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends $a{createParse(t,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let a=ri;if(a){for(let h of n)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new K(ge.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return ri}}function Uo(s,e,t){return Ze.applyChanges(s,[{fromA:e,toA:t,fromB:e,toB:t}])}class Jt{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new Jt(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=Gt.create(e.facet(Yt).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new Jt(i)}}Le.state=ye.define({create:Jt.init,update(s,e){for(let t of e.effects)if(t.is(Le.setState))return t.value;return e.startState.facet(Yt)!=e.state.facet(Yt)?Jt.init(e.state):s.apply(e)}});let Ga=s=>{let e=setTimeout(()=>s(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Ga=s=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(s,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const ts=typeof navigator<"u"&&(!((es=navigator.scheduling)===null||es===void 0)&&es.isInputPending)?()=>navigator.scheduling.isInputPending():null,od=ue.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(Le.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Le.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Ga(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(Le.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!ts?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,a=r.context.work(()=>ts&&ts()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Le.setState.of(new Jt(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Ne(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Yt=O.define({combine(s){return s.length?s[0]:null},enables:s=>[Le.state,od,T.contentAttributes.compute([s],e=>{let t=e.facet(s);return t&&t.name?{"data-language":t.name}:{}})]});class fm{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Ja=O.define(),In=O.define({combine:s=>{if(!s.length)return" ";let e=s[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(s[0]));return e}});function Tt(s){let e=s.facet(In);return e.charCodeAt(0)==9?s.tabSize*e.length:e.length}function vn(s,e){let t="",i=s.tabSize,n=s.facet(In)[0];if(n==" "){for(;e>=i;)t+=" ",e-=i;n=" "}for(let r=0;r<e;r++)t+=n;return t}function Ya(s,e){s instanceof H&&(s=new Nn(s));for(let i of s.state.facet(Ja)){let n=i(s,e);if(n!==void 0)return n}let t=me(s.state);return t.length>=e?ad(s,t,e):null}class Nn{constructor(e,t={}){this.state=e,this.options=t,this.unit=Tt(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==e?{text:"",from:e}:(t<0?n<e:n<=e)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(e,t);return i.slice(e-n,Math.min(i.length,e+100-n))}column(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.countColumn(i,e-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return _t(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:n}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(n);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const ld=new R;function ad(s,e,t){let i=e.resolveStack(t),n=i.node.enterUnfinishedNodesBefore(t);if(n!=i.node){let r=[];for(let o=n;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 Xa(i,s,t)}function Xa(s,e,t){for(let i=s;i;i=i.next){let n=cd(i.node);if(n)return n(br.create(e,t,i))}return 0}function hd(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function cd(s){let e=s.type.prop(ld);if(e)return e;let t=s.firstChild,i;if(t&&(i=t.type.prop(R.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>_a(o,!0,1,void 0,r&&!hd(o)?n.from:void 0)}return s.parent==null?fd:null}function fd(){return 0}class br extends Nn{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new br(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(ud(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return Xa(this.context.next,this.base,this.pos)}}function ud(s,e){for(let t=e;t;t=t.parent)if(s==t)return!0;return!1}function dd(s){let e=s.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let n=s.options.simulateBreak,r=s.state.doc.lineAt(t.from),o=n==null||n<=r.from?r.to:Math.min(r.to,n);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped)return a.from<o?t:null;l=a.to}}function um({closing:s,align:e=!0,units:t=1}){return i=>_a(i,e,t,s)}function _a(s,e,t,i,n){let r=s.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||n==s.pos+o,a=e?dd(s):null;return a?l?s.column(a.from):s.column(a.to):s.baseIndent+(l?0:s.unit*t)}const dm=s=>s.baseIndent;function pm({except:s,units:e=1}={}){return t=>{let i=s&&s.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const gm=new R;function mm(s){let e=s.firstChild,t=s.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?s.to:t.from}:null}class Fn{constructor(e,t){this.specs=e;let i;function n(l){let a=ut.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?n(t.all):void 0,o=t.scope;this.scope=o instanceof Le?l=>l.prop(kt)==o.data:o?l=>l==o:void 0,this.style=ja(e.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new ut(i):null,this.themeType=t.themeType}static define(e,t){return new Fn(e,t||{})}}const Gs=O.define(),Qa=O.define({combine(s){return s.length?[s[0]]:null}});function is(s){let e=s.facet(Gs);return e.length?e:s.facet(Qa)}function ym(s,e){let t=[gd],i;return s instanceof Fn&&(s.module&&t.push(T.styleModule.of(s.module)),i=s.themeType),e!=null&&e.fallback?t.push(Qa.of(s)):i?t.push(Gs.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(i=="dark")?[s]:[])):t.push(Gs.of(s)),t}class pd{constructor(e){this.markCache=Object.create(null),this.tree=me(e.state),this.decorations=this.buildDeco(e,is(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=me(e.state),i=is(e.state),n=i!=is(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!n&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||n)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return B.none;let i=new At;for(let{from:n,to:r}of e.visibleRanges)td(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=B.mark({class:a})))},n,r);return i.finish()}}const gd=Bt.high(ue.fromClass(pd,{decorations:s=>s.decorations})),bm=Fn.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"}]),md=T.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Za=1e4,eh="()[]{}",th=O.define({combine(s){return Pt(s,{afterCursor:!0,brackets:eh,maxScanDistance:Za,renderMatch:wd})}}),yd=B.mark({class:"cm-matchingBracket"}),bd=B.mark({class:"cm-nonmatchingBracket"});function wd(s){let e=[],t=s.matched?yd:bd;return e.push(t.range(s.start.from,s.start.to)),s.end&&e.push(t.range(s.end.from,s.end.to)),e}const xd=ye.define({create(){return B.none},update(s,e){if(!e.docChanged&&!e.selection)return s;let t=[],i=e.state.facet(th);for(let n of e.state.selection.ranges){if(!n.empty)continue;let r=Ye(e.state,n.head,-1,i)||n.head>0&&Ye(e.state,n.head-1,1,i)||i.afterCursor&&(Ye(e.state,n.head,1,i)||n.head<e.state.doc.length&&Ye(e.state,n.head+1,-1,i));r&&(t=t.concat(i.renderMatch(r,e.state)))}return B.set(t,!0)},provide:s=>T.decorations.from(s)}),vd=[xd,md];function wm(s={}){return[th.of(s),vd]}const kd=new R;function Js(s,e,t){let i=s.prop(e<0?R.openedBy:R.closedBy);if(i)return i;if(s.name.length==1){let n=t.indexOf(s.name);if(n>-1&&n%2==(e<0?1:0))return[t[n+e]]}return null}function Ys(s){let e=s.type.prop(kd);return e?e(s.node):s}function Ye(s,e,t,i={}){let n=i.maxScanDistance||Za,r=i.brackets||eh,o=me(s),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=Js(a.type,t,r);if(h&&a.from<a.to){let c=Ys(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return Sd(s,e,t,a,c,h,r)}}return Cd(s,e,t,o,l.type,n,r)}function Sd(s,e,t,i,n,r,o){let l=i.parent,a={from:n.from,to:n.to},h=0,c=l==null?void 0:l.cursor();if(c&&(t<0?c.childBefore(i.from):c.childAfter(i.to)))do if(t<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let f=Ys(c);return{start:a,end:f?{from:f.from,to:f.to}:void 0,matched:!0}}else if(Js(c.type,t,o))h++;else if(Js(c.type,-t,o)){if(h==0){let f=Ys(c);return{start:a,end:f&&f.from<f.to?{from:f.from,to:f.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function Cd(s,e,t,i,n,r,o){let l=t<0?s.sliceDoc(e-1,e):s.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=s.doc.iterRange(e,t>0?s.doc.length:0),f=0;for(let u=0;!c.next().done&&u<=r;){let d=c.value;t<0&&(u+=d.length);let p=e+u*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||i.resolveInner(p+m,1).type!=n))if(y%2==0==t>0)f++;else{if(f==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};f--}}t>0&&(u+=d.length)}return c.done?{start:h,matched:!1}:null}function Go(s,e,t,i=0,n=0){e==null&&(e=s.search(/[^\s\u00a0]/),e==-1&&(e=s.length));let r=n;for(let o=i;o<e;o++)s.charCodeAt(o)==9?r+=t-r%t:r++;return r}class ih{constructor(e,t,i,n){this.string=e,this.tabSize=t,this.indentUnit=i,this.overrideIndent=n,this.pos=0,this.start=0,this.lastColumnPos=0,this.lastColumnValue=0}eol(){return this.pos>=this.string.length}sol(){return this.pos==0}peek(){return this.string.charAt(this.pos)||void 0}next(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)}eat(e){let t=this.string.charAt(this.pos),i;if(typeof e=="string"?i=t==e:i=t&&(e instanceof RegExp?e.test(t):e(t)),i)return++this.pos,t}eatWhile(e){let t=this.pos;for(;this.eat(e););return this.pos>t}eatSpace(){let e=this.pos;for(;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e}skipToEnd(){this.pos=this.string.length}skipTo(e){let t=this.string.indexOf(e,this.pos);if(t>-1)return this.pos=t,!0}backUp(e){this.pos-=e}column(){return this.lastColumnPos<this.start&&(this.lastColumnValue=Go(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue}indentation(){var e;return(e=this.overrideIndent)!==null&&e!==void 0?e:Go(this.string,null,this.tabSize)}match(e,t,i){if(typeof e=="string"){let n=o=>i?o.toLowerCase():o,r=this.string.substr(this.pos,e.length);return n(r)==n(e)?(t!==!1&&(this.pos+=e.length),!0):null}else{let n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}}current(){return this.string.slice(this.start,this.pos)}}function Ad(s){return{name:s.name||"",token:s.token,blankLine:s.blankLine||(()=>{}),startState:s.startState||(()=>!0),copyState:s.copyState||Md,indent:s.indent||(()=>null),languageData:s.languageData||{},tokenTable:s.tokenTable||xr}}function Md(s){if(typeof s!="object")return s;let e={};for(let t in s){let i=s[t];e[t]=i instanceof Array?i.slice():i}return e}const Jo=new WeakMap;class nh extends Le{constructor(e){let t=Ua(e.languageData),i=Ad(e),n,r=new class extends $a{createParse(o,l,a){return new Od(n,o,l,a)}};super(t,r,[Ja.of((o,l)=>this.getIndent(o,l))],e.name),this.topNode=Pd(t),n=this,this.streamParser=i,this.stateAfter=new R({perNode:!0}),this.tokenTable=e.tokenTable?new lh(i.tokenTable):Bd}static define(e){return new nh(e)}getIndent(e,t){let i=me(e.state),n=i.resolve(t);for(;n&&n.type!=this.topNode;)n=n.parent;if(!n)return null;let r,{overrideIndentation:o}=e.options;o&&(r=Jo.get(e.state),r!=null&&r<t-1e4&&(r=void 0));let l=wr(this,i,0,n.from,r??t),a,h;if(l?(h=l.state,a=l.pos+1):(h=this.streamParser.startState(e.unit),a=0),t-a>1e4)return null;for(;a<t;){let f=e.state.doc.lineAt(a),u=Math.min(t,f.to);if(f.length){let d=o?o(f.from):-1,p=new ih(f.text,e.state.tabSize,e.unit,d<0?void 0:d);for(;p.pos<u-f.from;)rh(this.streamParser.token,p,h)}else this.streamParser.blankLine(h,e.unit);if(u==t)break;a=f.to+1}let c=e.lineAt(t);return o&&r==null&&Jo.set(e.state,c.from),this.streamParser.indent(h,/^\s*(.*)/.exec(c.text)[1],e)}get allowsNesting(){return!1}}function wr(s,e,t,i,n){let r=t>=i&&t+e.length<=n&&e.prop(s.stateAfter);if(r)return{state:s.streamParser.copyState(r),pos:t+e.length};for(let o=e.children.length-1;o>=0;o--){let l=e.children[o],a=t+e.positions[o],h=l instanceof K&&a<n&&wr(s,l,a,i,n);if(h)return h}return null}function sh(s,e,t,i,n){if(n&&t<=0&&i>=e.length)return e;!n&&e.type==s.topNode&&(n=!0);for(let r=e.children.length-1;r>=0;r--){let o=e.positions[r],l=e.children[r],a;if(o<i&&l instanceof K){if(!(a=sh(s,l,t-o,i-o,n)))break;return n?new K(e.type,e.children.slice(0,r).concat(a),e.positions.slice(0,r+1),o+a.length):a}}return null}function Dd(s,e,t,i){for(let n of e){let r=n.from+(n.openStart?25:0),o=n.to-(n.openEnd?25:0),l=r<=t&&o>t&&wr(s,n.tree,0-n.offset,t,o),a;if(l&&(a=sh(s,n.tree,t+n.offset,l.pos+n.offset,!1)))return{state:l.state,tree:a}}return{state:s.streamParser.startState(i?Tt(i):4),tree:K.empty}}class Od{constructor(e,t,i,n){this.lang=e,this.input=t,this.fragments=i,this.ranges=n,this.stoppedAt=null,this.chunks=[],this.chunkPos=[],this.chunk=[],this.chunkReused=void 0,this.rangeIndex=0,this.to=n[n.length-1].to;let r=Gt.get(),o=n[0].from,{state:l,tree:a}=Dd(e,i,o,r==null?void 0:r.state);this.state=l,this.parsedPos=this.chunkStart=o+a.length;for(let h=0;h<a.children.length;h++)this.chunks.push(a.children[h]),this.chunkPos.push(a.positions[h]);r&&this.parsedPos<r.viewport.from-1e5&&(this.state=this.lang.streamParser.startState(Tt(r.state)),r.skipUntilInView(this.parsedPos,r.viewport.from),this.parsedPos=r.viewport.from),this.moveRangeIndex()}advance(){let e=Gt.get(),t=this.stoppedAt==null?this.to:Math.min(this.to,this.stoppedAt),i=Math.min(t,this.chunkStart+2048);for(e&&(i=Math.min(i,e.viewport.to));this.parsedPos<i;)this.parseLine(e);return this.chunkStart<this.parsedPos&&this.finishChunk(),this.parsedPos>=t?this.finish():e&&this.parsedPos>=e.viewport.to?(e.skipUntilInView(this.parsedPos,t),this.finish()):null}stopAt(e){this.stoppedAt=e}lineAfter(e){let t=this.input.chunk(e);if(this.input.lineChunks)t==`
`&&(t="");else{let i=t.indexOf(`
`);i>-1&&(t=t.slice(0,i))}return e+t.length<=this.to?t:t.slice(0,this.to-e)}nextLine(){let e=this.parsedPos,t=this.lineAfter(e),i=e+t.length;for(let n=this.rangeIndex;;){let r=this.ranges[n].to;if(r>=i||(t=t.slice(0,r-(i-t.length)),n++,n==this.ranges.length))break;let o=this.ranges[n].from,l=this.lineAfter(o);t+=l,i=o+l.length}return{line:t,end:i}}skipGapsTo(e,t,i){for(;;){let n=this.ranges[this.rangeIndex].to,r=e+t;if(i>0?n>r:n>=r)break;let o=this.ranges[++this.rangeIndex].from;t+=o-n}return t}moveRangeIndex(){for(;this.ranges[this.rangeIndex].to<this.parsedPos;)this.rangeIndex++}emitToken(e,t,i,n,r){if(this.ranges.length>1){r=this.skipGapsTo(t,r,1),t+=r;let o=this.chunk.length;r=this.skipGapsTo(i,r,-1),i+=r,n+=this.chunk.length-o}return this.chunk.push(e,t,i,n),r}parseLine(e){let{line:t,end:i}=this.nextLine(),n=0,{streamParser:r}=this.lang,o=new ih(t,e?e.state.tabSize:4,e?Tt(e.state):2);if(o.eol())r.blankLine(this.state,o.indentUnit);else for(;!o.eol();){let l=rh(r.token,o,this.state);if(l&&(n=this.emitToken(this.lang.tokenTable.resolve(l),this.parsedPos+o.start,this.parsedPos+o.pos,4,n)),o.start>1e4)break}this.parsedPos=i,this.moveRangeIndex(),this.parsedPos<this.to&&this.parsedPos++}finishChunk(){let e=K.build({buffer:this.chunk,start:this.chunkStart,length:this.parsedPos-this.chunkStart,nodeSet:Td,topID:0,maxBufferLength:2048,reused:this.chunkReused});e=new K(e.type,e.children,e.positions,e.length,[[this.lang.stateAfter,this.lang.streamParser.copyState(this.state)]]),this.chunks.push(e),this.chunkPos.push(this.chunkStart-this.ranges[0].from),this.chunk=[],this.chunkReused=void 0,this.chunkStart=this.parsedPos}finish(){return new K(this.lang.topNode,this.chunks,this.chunkPos,this.parsedPos-this.ranges[0].from).balance()}}function rh(s,e,t){e.start=e.pos;for(let i=0;i<10;i++){let n=s(e,t);if(e.pos>e.start)return n}throw new Error("Stream parser failed to advance stream.")}const xr=Object.create(null),Ci=[ge.none],Td=new pr(Ci),Yo=[],Xo=Object.create(null),oh=Object.create(null);for(let[s,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])oh[s]=ah(xr,e);class lh{constructor(e){this.extra=e,this.table=Object.assign(Object.create(null),oh)}resolve(e){return e?this.table[e]||(this.table[e]=ah(this.extra,e)):0}}const Bd=new lh(xr);function ns(s,e){Yo.indexOf(s)>-1||(Yo.push(s),console.warn(e))}function ah(s,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=s[h]||M[h];c?typeof c=="function"?a.length?a=a.map(c):ns(h,`Modifier ${h} used at start of tag`):a.length?ns(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:ns(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),n=i+" "+t.map(l=>l.id),r=Xo[n];if(r)return r.id;let o=Xo[n]=ge.define({id:Ci.length,name:i,props:[Zu({[i]:t})]});return Ci.push(o),o.id}function Pd(s){let e=ge.define({id:Ci.length,name:"Document",props:[kt.add(()=>s)],top:!0});return Ci.push(e),e}X.RTL,X.LTR;const Ld=s=>{let{state:e}=s,t=e.doc.lineAt(e.selection.main.from),i=kr(s.state,t.from);return i.line?Rd(s):i.block?Id(s):!1};function vr(s,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let n=s(e,t);return n?(i(t.update(n)),!0):!1}}const Rd=vr(Vd,0),Ed=vr(hh,0),Id=vr((s,e)=>hh(s,e,Fd(e)),0);function kr(s,e){let t=s.languageDataAt("commentTokens",e);return t.length?t[0]:{}}const oi=50;function Nd(s,{open:e,close:t},i,n){let r=s.sliceDoc(i-oi,i),o=s.sliceDoc(n,n+oi),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:n+a,margin:a&&1}};let c,f;n-i<=2*oi?c=f=s.sliceDoc(i,n):(c=s.sliceDoc(i,i+oi),f=s.sliceDoc(n-oi,n));let u=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(f)[0].length,p=f.length-d-t.length;return c.slice(u,u+e.length)==e&&f.slice(p,p+t.length)==t?{open:{pos:i+u+e.length,margin:/\s/.test(c.charAt(u+e.length))?1:0},close:{pos:n-d-t.length,margin:/\s/.test(f.charAt(p-1))?1:0}}:null}function Fd(s){let e=[];for(let t of s.selection.ranges){let i=s.doc.lineAt(t.from),n=t.to<=i.to?i:s.doc.lineAt(t.to),r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=n.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return e}function hh(s,e,t=e.selection.ranges){let i=t.map(r=>kr(e,r.from).block);if(!i.every(r=>r))return null;let n=t.map((r,o)=>Nd(e,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:e.changes(t.map((r,o)=>n[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(s!=1&&n.some(r=>r)){let r=[];for(let o=0,l;o<n.length;o++)if(l=n[o]){let a=i[o],{open:h,close:c}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function Vd(s,e,t=e.selection.ranges){let i=[],n=-1;for(let{from:r,to:o}of t){let l=i.length,a=1e9,h=kr(e,r).line;if(h){for(let c=r;c<=o;){let f=e.doc.lineAt(c);if(f.from>n&&(r==o||o>f.from)){n=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(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:f}of i)(f||!c)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(s!=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 Xs=nt.define(),Wd=nt.define(),Hd=O.define(),ch=O.define({combine(s){return Pt(s,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,n)=>e(i,n)||t(i,n)})}}),fh=ye.define({create(){return Xe.empty},update(s,e){let t=e.state.facet(ch),i=e.annotation(Xs);if(i){let a=ve.fromTransaction(e,i.selection),h=i.side,c=h==0?s.undone:s.done;return a?c=kn(c,c.length,t.minDepth,a):c=ph(c,e.startState.selection),new Xe(h==0?i.rest:c,h==0?c:i.rest)}let n=e.annotation(Wd);if((n=="full"||n=="before")&&(s=s.isolate()),e.annotation(Q.addToHistory)===!1)return e.changes.empty?s:s.addMapping(e.changes.desc);let r=ve.fromTransaction(e),o=e.annotation(Q.time),l=e.annotation(Q.userEvent);return r?s=s.addChanges(r,o,l,t,e):e.selection&&(s=s.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(e=>e.toJSON()),undone:s.undone.map(e=>e.toJSON())}},fromJSON(s){return new Xe(s.done.map(ve.fromJSON),s.undone.map(ve.fromJSON))}});function xm(s={}){return[fh,ch.of(s),T.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?uh:e.inputType=="historyRedo"?_s:null;return i?(e.preventDefault(),i(t)):!1}})]}function Vn(s,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let n=t.field(fh,!1);if(!n)return!1;let r=n.pop(s,t,e);return r?(i(r),!0):!1}}const uh=Vn(0,!1),_s=Vn(1,!1),zd=Vn(0,!0),qd=Vn(1,!0);class ve{constructor(e,t,i,n,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(e){return new ve(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(e){return new ve(e.changes&&te.fromJSON(e.changes),[],e.mapped&&_e.fromJSON(e.mapped),e.startSelection&&b.fromJSON(e.startSelection),e.selectionsAfter.map(b.fromJSON))}static fromTransaction(e,t){let i=Re;for(let n of e.startState.facet(Hd)){let r=n(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new ve(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Re)}static selection(e){return new ve(void 0,Re,void 0,void 0,e)}}function kn(s,e,t,i){let n=e+1>t+20?e-t-1:0,r=s.slice(n,e);return r.push(i),r}function $d(s,e){let t=[],i=!1;return s.iterChangedRanges((n,r)=>t.push(n,r)),e.iterChangedRanges((n,r,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(i=!0)}}),i}function Kd(s,e){return s.ranges.length==e.ranges.length&&s.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function dh(s,e){return s.length?e.length?s.concat(e):s:e}const Re=[],jd=200;function ph(s,e){if(s.length){let t=s[s.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-jd));return i.length&&i[i.length-1].eq(e)?s:(i.push(e),kn(s,s.length-1,1e9,t.setSelAfter(i)))}else return[ve.selection([e])]}function Ud(s){let e=s[s.length-1],t=s.slice();return t[s.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function ss(s,e){if(!s.length)return s;let t=s.length,i=Re;for(;t;){let n=Gd(s[t-1],e,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,t);return r[t-1]=n,r}else e=n.mapped,t--,i=n.selectionsAfter}return i.length?[ve.selection(i)]:Re}function Gd(s,e,t){let i=dh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(e)):Re,t);if(!s.changes)return ve.selection(i);let n=s.changes.map(e),r=e.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new ve(n,F.mapEffects(s.effects,e),o,s.startSelection.map(r),i)}const Jd=/^(input\.type|delete)($|\.)/;class Xe{constructor(e,t,i=0,n=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Xe(this.done,this.undone):this}addChanges(e,t,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Jd.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,$d(l.changes,e.changes))||i=="input.type.compose")?o=kn(o,o.length-1,n.minDepth,new ve(e.changes.compose(l.changes),dh(e.effects,l.effects),l.mapped,l.startSelection,Re)):o=kn(o,o.length,n.minDepth,e),new Xe(o,Re,t,i)}addSelection(e,t,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Re;return r.length>0&&t-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Kd(r[r.length-1],e)?this:new Xe(ph(this.done,e),this.undone,t,i)}addMapping(e){return new Xe(ss(this.done,e),ss(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let n=e==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||t.selection;if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Xs.of({side:e,rest:Ud(n),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?Re:n.slice(0,n.length-1);return r.mapped&&(l=ss(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Xs.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}Xe.empty=new Xe(Re,Re);const vm=[{key:"Mod-z",run:uh,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:_s,preventDefault:!0},{linux:"Ctrl-Shift-z",run:_s,preventDefault:!0},{key:"Mod-u",run:zd,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:qd,preventDefault:!0}];function Qt(s,e){return b.create(s.ranges.map(e),s.mainIndex)}function Qe(s,e){return s.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function We({state:s,dispatch:e},t){let i=Qt(s.selection,t);return i.eq(s.selection,!0)?!1:(e(Qe(s,i)),!0)}function Wn(s,e){return b.cursor(e?s.to:s.from)}function gh(s,e){return We(s,t=>t.empty?s.moveByChar(t,e):Wn(t,e))}function de(s){return s.textDirectionAt(s.state.selection.main.head)==X.LTR}const mh=s=>gh(s,!de(s)),yh=s=>gh(s,de(s));function bh(s,e){return We(s,t=>t.empty?s.moveByGroup(t,e):Wn(t,e))}const Yd=s=>bh(s,!de(s)),Xd=s=>bh(s,de(s));function _d(s,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(e.from,e.to)))||e.firstChild}function Hn(s,e,t){let i=me(s).resolveInner(e.head),n=t?R.closedBy:R.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;_d(s,h,n)?i=h:a=t?h.to:h.from}let r=i.type.prop(n),o,l;return r&&(o=t?Ye(s,i.from,1):Ye(s,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,b.cursor(l,t?-1:1)}const Qd=s=>We(s,e=>Hn(s.state,e,!de(s))),Zd=s=>We(s,e=>Hn(s.state,e,de(s)));function wh(s,e){return We(s,t=>{if(!t.empty)return Wn(t,e);let i=s.moveVertically(t,e);return i.head!=t.head?i:s.moveToLineBoundary(t,e)})}const xh=s=>wh(s,!1),vh=s=>wh(s,!0);function kh(s){let e=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,t=0,i=0,n;if(e){for(let r of s.state.facet(T.scrollMargins)){let o=r(s);o!=null&&o.top&&(t=Math.max(o==null?void 0:o.top,t)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}n=s.scrollDOM.clientHeight-t-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(s.defaultLineHeight,n-5)}}function Sh(s,e){let t=kh(s),{state:i}=s,n=Qt(i.selection,o=>o.empty?s.moveVertically(o,e,t.height):Wn(o,e));if(n.eq(i.selection))return!1;let r;if(t.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=T.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-a}))}return s.dispatch(Qe(i,n),{effects:r}),!0}const _o=s=>Sh(s,!1),Qs=s=>Sh(s,!0);function mt(s,e,t){let i=s.lineBlockAt(e.head),n=s.moveToLineBoundary(e,t);if(n.head==e.head&&n.head!=(t?i.to:i.from)&&(n=s.moveToLineBoundary(e,t,!1)),!t&&n.head==i.from&&i.length){let r=/^\s*/.exec(s.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(n=b.cursor(i.from+r))}return n}const ep=s=>We(s,e=>mt(s,e,!0)),tp=s=>We(s,e=>mt(s,e,!1)),ip=s=>We(s,e=>mt(s,e,!de(s))),np=s=>We(s,e=>mt(s,e,de(s))),sp=s=>We(s,e=>b.cursor(s.lineBlockAt(e.head).from,1)),rp=s=>We(s,e=>b.cursor(s.lineBlockAt(e.head).to,-1));function op(s,e,t){let i=!1,n=Qt(s.selection,r=>{let o=Ye(s,r.head,-1)||Ye(s,r.head,1)||r.head>0&&Ye(s,r.head-1,1)||r.head<s.doc.length&&Ye(s,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return t?b.range(r.anchor,l):b.cursor(l)});return i?(e(Qe(s,n)),!0):!1}const lp=({state:s,dispatch:e})=>op(s,e,!1);function Ie(s,e){let t=Qt(s.state.selection,i=>{let n=e(i);return b.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)});return t.eq(s.state.selection)?!1:(s.dispatch(Qe(s.state,t)),!0)}function Ch(s,e){return Ie(s,t=>s.moveByChar(t,e))}const Ah=s=>Ch(s,!de(s)),Mh=s=>Ch(s,de(s));function Dh(s,e){return Ie(s,t=>s.moveByGroup(t,e))}const ap=s=>Dh(s,!de(s)),hp=s=>Dh(s,de(s)),cp=s=>Ie(s,e=>Hn(s.state,e,!de(s))),fp=s=>Ie(s,e=>Hn(s.state,e,de(s)));function Oh(s,e){return Ie(s,t=>s.moveVertically(t,e))}const Th=s=>Oh(s,!1),Bh=s=>Oh(s,!0);function Ph(s,e){return Ie(s,t=>s.moveVertically(t,e,kh(s).height))}const Qo=s=>Ph(s,!1),Zo=s=>Ph(s,!0),up=s=>Ie(s,e=>mt(s,e,!0)),dp=s=>Ie(s,e=>mt(s,e,!1)),pp=s=>Ie(s,e=>mt(s,e,!de(s))),gp=s=>Ie(s,e=>mt(s,e,de(s))),mp=s=>Ie(s,e=>b.cursor(s.lineBlockAt(e.head).from)),yp=s=>Ie(s,e=>b.cursor(s.lineBlockAt(e.head).to)),el=({state:s,dispatch:e})=>(e(Qe(s,{anchor:0})),!0),tl=({state:s,dispatch:e})=>(e(Qe(s,{anchor:s.doc.length})),!0),il=({state:s,dispatch:e})=>(e(Qe(s,{anchor:s.selection.main.anchor,head:0})),!0),nl=({state:s,dispatch:e})=>(e(Qe(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),bp=({state:s,dispatch:e})=>(e(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),wp=({state:s,dispatch:e})=>{let t=zn(s).map(({from:i,to:n})=>b.range(i,Math.min(n+1,s.doc.length)));return e(s.update({selection:b.create(t),userEvent:"select"})),!0},xp=({state:s,dispatch:e})=>{let t=Qt(s.selection,i=>{var n;let r=me(s).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)&&(!((n=l.parent)===null||n===void 0)&&n.parent))return b.range(l.to,l.from)}return i});return e(Qe(s,t)),!0},vp=({state:s,dispatch:e})=>{let t=s.selection,i=null;return t.ranges.length>1?i=b.create([t.main]):t.main.empty||(i=b.create([b.cursor(t.main.head)])),i?(e(Qe(s,i)),!0):!1};function Li(s,e){if(s.state.readOnly)return!1;let t="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=Qi(s,a,!1)):a>o&&(t="delete.forward",a=Qi(s,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Qi(s,o,!1),l=Qi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:b.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?T.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Qi(s,e,t){if(s instanceof T)for(let i of s.state.facet(T.atomicRanges).map(n=>n(s)))i.between(e,e,(n,r)=>{n<e&&r>e&&(e=t?r:n)});return e}const Lh=(s,e)=>Li(s,t=>{let i=t.from,{state:n}=s,r=n.doc.lineAt(i),o,l;if(!e&&i>r.from&&i<r.from+200&&!/[^ \t]/.test(o=r.text.slice(0,i-r.from))){if(o[o.length-1]==" ")return i-1;let a=_t(o,n.tabSize),h=a%Tt(n)||Tt(n);for(let c=0;c<h&&o[o.length-1-c]==" ";c++)i--;l=i}else l=oe(r.text,i-r.from,e,e)+r.from,l==i&&r.number!=(e?n.doc.lines:1)?l+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(r.text.slice(l-r.from,i-r.from))&&(l=oe(r.text,l-r.from,!1,!1)+r.from);return l}),Zs=s=>Lh(s,!1),Rh=s=>Lh(s,!0),Eh=(s,e)=>Li(s,t=>{let i=t.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?n.doc.lines:1)&&(i+=e?1:-1);break}let a=oe(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t.head)&&(l=c),i=a}return i}),Ih=s=>Eh(s,!1),kp=s=>Eh(s,!0),Sp=s=>Li(s,e=>{let t=s.lineBlockAt(e.head).to;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),Cp=s=>Li(s,e=>{let t=s.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),Ap=s=>Li(s,e=>{let t=s.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(s.state.doc.length,e.head+1)}),Mp=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:V.of(["",""])},range:b.cursor(i.from)}));return e(s.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},Dp=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=s.changeByRange(i=>{if(!i.empty||i.from==0||i.from==s.doc.length)return{range:i};let n=i.from,r=s.doc.lineAt(n),o=n==r.from?n-1:oe(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:oe(r.text,n-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:s.doc.slice(n,l).append(s.doc.slice(o,n))},range:b.cursor(l)}});return t.changes.empty?!1:(e(s.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function zn(s){let e=[],t=-1;for(let i of s.selection.ranges){let n=s.doc.lineAt(i.from),r=s.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=s.doc.lineAt(i.to-1)),t>=n.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:n.from,to:r.to,ranges:[i]});t=r.number+1}return e}function Nh(s,e,t){if(s.readOnly)return!1;let i=[],n=[];for(let r of zn(s)){if(t?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let a of r.ranges)n.push(b.range(Math.min(s.doc.length,a.anchor+l),Math.min(s.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let a of r.ranges)n.push(b.range(a.anchor-l,a.head-l))}}return i.length?(e(s.update({changes:i,scrollIntoView:!0,selection:b.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Op=({state:s,dispatch:e})=>Nh(s,e,!1),Tp=({state:s,dispatch:e})=>Nh(s,e,!0);function Fh(s,e,t){if(s.readOnly)return!1;let i=[];for(let n of zn(s))t?i.push({from:n.from,insert:s.doc.slice(n.from,n.to)+s.lineBreak}):i.push({from:n.to,insert:s.lineBreak+s.doc.slice(n.from,n.to)});return e(s.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Bp=({state:s,dispatch:e})=>Fh(s,e,!1),Pp=({state:s,dispatch:e})=>Fh(s,e,!0),Lp=s=>{if(s.state.readOnly)return!1;let{state:e}=s,t=e.changes(zn(e).map(({from:n,to:r})=>(n>0?n--:r<e.doc.length&&r++,{from:n,to:r}))),i=Qt(e.selection,n=>s.moveVertically(n,!0)).map(t);return s.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Rp(s,e){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=me(s).resolveInner(e),i=t.childBefore(e),n=t.childAfter(e),r;return i&&n&&i.to<=e&&n.from>=e&&(r=i.type.prop(R.closedBy))&&r.indexOf(n.name)>-1&&s.doc.lineAt(i.to).from==s.doc.lineAt(n.from).from&&!/\S/.test(s.sliceDoc(i.to,n.from))?{from:i.to,to:n.from}:null}const Ep=Vh(!1),Ip=Vh(!0);function Vh(s){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(n=>{let{from:r,to:o}=n,l=e.doc.lineAt(r),a=!s&&r==o&&Rp(e,r);s&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Nn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=Ya(h,r);for(c==null&&(c=_t(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let f=["",vn(e,c)];return a&&f.push(vn(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:V.of(f)},range:b.cursor(r+1+f[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Sr(s,e){let t=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,n,i),t=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:b.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const Np=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let t=Object.create(null),i=new Nn(s,{overrideIndentation:r=>{let o=t[r];return o??-1}}),n=Sr(s,(r,o,l)=>{let a=Ya(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=vn(s,a);(h!=c||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return n.changes.empty||e(s.update(n,{userEvent:"indent"})),!0},Wh=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(Sr(s,(t,i)=>{i.push({from:t.from,insert:s.facet(In)})}),{userEvent:"input.indent"})),!0),Hh=({state:s,dispatch:e})=>s.readOnly?!1:(e(s.update(Sr(s,(t,i)=>{let n=/^\s*/.exec(t.text)[0];if(!n)return;let r=_t(n,s.tabSize),o=0,l=vn(s,Math.max(0,r-Tt(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Fp=[{key:"Ctrl-b",run:mh,shift:Ah,preventDefault:!0},{key:"Ctrl-f",run:yh,shift:Mh},{key:"Ctrl-p",run:xh,shift:Th},{key:"Ctrl-n",run:vh,shift:Bh},{key:"Ctrl-a",run:sp,shift:mp},{key:"Ctrl-e",run:rp,shift:yp},{key:"Ctrl-d",run:Rh},{key:"Ctrl-h",run:Zs},{key:"Ctrl-k",run:Sp},{key:"Ctrl-Alt-h",run:Ih},{key:"Ctrl-o",run:Mp},{key:"Ctrl-t",run:Dp},{key:"Ctrl-v",run:Qs}],Vp=[{key:"ArrowLeft",run:mh,shift:Ah,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Yd,shift:ap,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:ip,shift:pp,preventDefault:!0},{key:"ArrowRight",run:yh,shift:Mh,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Xd,shift:hp,preventDefault:!0},{mac:"Cmd-ArrowRight",run:np,shift:gp,preventDefault:!0},{key:"ArrowUp",run:xh,shift:Th,preventDefault:!0},{mac:"Cmd-ArrowUp",run:el,shift:il},{mac:"Ctrl-ArrowUp",run:_o,shift:Qo},{key:"ArrowDown",run:vh,shift:Bh,preventDefault:!0},{mac:"Cmd-ArrowDown",run:tl,shift:nl},{mac:"Ctrl-ArrowDown",run:Qs,shift:Zo},{key:"PageUp",run:_o,shift:Qo},{key:"PageDown",run:Qs,shift:Zo},{key:"Home",run:tp,shift:dp,preventDefault:!0},{key:"Mod-Home",run:el,shift:il},{key:"End",run:ep,shift:up,preventDefault:!0},{key:"Mod-End",run:tl,shift:nl},{key:"Enter",run:Ep},{key:"Mod-a",run:bp},{key:"Backspace",run:Zs,shift:Zs},{key:"Delete",run:Rh},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Ih},{key:"Mod-Delete",mac:"Alt-Delete",run:kp},{mac:"Mod-Backspace",run:Cp},{mac:"Mod-Delete",run:Ap}].concat(Fp.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),km=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Qd,shift:cp},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Zd,shift:fp},{key:"Alt-ArrowUp",run:Op},{key:"Shift-Alt-ArrowUp",run:Bp},{key:"Alt-ArrowDown",run:Tp},{key:"Shift-Alt-ArrowDown",run:Pp},{key:"Escape",run:vp},{key:"Mod-Enter",run:Ip},{key:"Alt-l",mac:"Ctrl-l",run:wp},{key:"Mod-i",run:xp,preventDefault:!0},{key:"Mod-[",run:Hh},{key:"Mod-]",run:Wh},{key:"Mod-Alt-\\",run:Np},{key:"Shift-Mod-k",run:Lp},{key:"Shift-Mod-\\",run:lp},{key:"Mod-/",run:Ld},{key:"Alt-A",run:Ed}].concat(Vp),Sm={key:"Tab",run:Wh,shift:Hh};function le(){var s=arguments[0];typeof s=="string"&&(s=document.createElement(s));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var n=t[i];typeof n=="string"?s.setAttribute(i,n):n!=null&&(s[i]=n)}e++}for(;e<arguments.length;e++)zh(s,arguments[e]);return s}function zh(s,e){if(typeof e=="string")s.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)s.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)zh(s,e[t]);else throw new RangeError("Unsupported child node: "+e)}const sl=typeof String.prototype.normalize=="function"?s=>s.normalize("NFKD"):s=>s;class Xt{constructor(e,t,i=0,n=e.length,r,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,n),this.bufferStart=i,this.normalize=r?l=>r(sl(l)):sl,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return ne(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=nr(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=Be(e);let n=this.normalize(t);for(let r=0,o=i;;r++){let l=n.charCodeAt(r),a=this.match(l,o);if(r==n.length-1){if(a)return this.value=a,this;break}o==i&&r<t.length&&t.charCodeAt(r)==l&&o++}}}match(e,t){let i=null;for(let n=0;n<this.matches.length;n+=2){let r=this.matches[n],o=!1;this.query.charCodeAt(r)==e&&(r==this.query.length-1?i={from:this.matches[n+1],to:t+1}:(this.matches[n]++,o=!0)),o||(this.matches.splice(n,2),n-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?i={from:t,to:t+1}:this.matches.push(1,t)),i&&this.test&&!this.test(i.from,i.to,this.buffer,this.bufferStart)&&(i=null),i}}typeof Symbol<"u"&&(Xt.prototype[Symbol.iterator]=function(){return this});const qh={from:-1,to:-1,match:/.*/.exec("")},Cr="gm"+(/x/.unicode==null?"":"u");class $h{constructor(e,t,i,n=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=qh,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Kh(e,t,i,n,r);this.re=new RegExp(t,Cr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.iter=e.iter();let o=e.lineAt(n);this.curLineStart=o.from,this.matchPos=Sn(e,n),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,n=i+t[0].length;if(this.matchPos=Sn(this.text,n+(i==n?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<n||i>this.value.to)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const rs=new WeakMap;class qt{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let n=rs.get(e);if(!n||n.from>=i||n.to<=t){let l=new qt(t,e.sliceString(t,i));return rs.set(e,l),l}if(n.from==t&&n.to==i)return n;let{text:r,from:o}=n;return o>t&&(r=e.sliceString(t,o)+r,o=t),n.to<i&&(r+=e.sliceString(n.to,i)),rs.set(e,new qt(o,r)),new qt(t,r.slice(t-o,i-o))}}class Kh{constructor(e,t,i,n,r){this.text=e,this.to=r,this.done=!1,this.value=qh,this.matchPos=Sn(e,n),this.re=new RegExp(t,Cr+(i!=null&&i.ignoreCase?"i":"")),this.test=i==null?void 0:i.test,this.flat=qt.get(e,n,this.chunkEnd(n+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,n=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,n,t)))return this.value={from:i,to:n,match:t},this.matchPos=Sn(this.text,n+(i==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=qt.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&($h.prototype[Symbol.iterator]=Kh.prototype[Symbol.iterator]=function(){return this});function Wp(s){try{return new RegExp(s,Cr),!0}catch{return!1}}function Sn(s,e){if(e>=s.length)return e;let t=s.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}function er(s){let e=String(s.state.doc.lineAt(s.state.selection.main.head).number),t=le("input",{class:"cm-textfield",name:"line",value:e}),i=le("form",{class:"cm-gotoLine",onkeydown:r=>{r.keyCode==27?(r.preventDefault(),s.dispatch({effects:Cn.of(!1)}),s.focus()):r.keyCode==13&&(r.preventDefault(),n())},onsubmit:r=>{r.preventDefault(),n()}},le("label",s.state.phrase("Go to line"),": ",t)," ",le("button",{class:"cm-button",type:"submit"},s.state.phrase("go")));function n(){let r=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!r)return;let{state:o}=s,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 g=d/100;a&&(g=g*(a=="-"?-1:1)+l.number/o.doc.lines),d=Math.round(o.doc.lines*g)}else h&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=o.doc.line(Math.max(1,Math.min(o.doc.lines,d))),m=b.cursor(p.from+Math.max(0,Math.min(u,p.length)));s.dispatch({effects:[Cn.of(!1),T.scrollIntoView(m.from,{y:"center"})],selection:m}),s.focus()}return{dom:i}}const Cn=F.define(),rl=ye.define({create(){return!0},update(s,e){for(let t of e.effects)t.is(Cn)&&(s=t.value);return s},provide:s=>yn.from(s,e=>e?er:null)}),Hp=s=>{let e=mn(s,er);if(!e){let t=[Cn.of(!0)];s.state.field(rl,!1)==null&&t.push(F.appendConfig.of([rl,zp])),s.dispatch({effects:t}),e=mn(s,er)}return e&&e.dom.querySelector("input").select(),!0},zp=T.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),qp={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},jh=O.define({combine(s){return Pt(s,qp,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Cm(s){let e=[Gp,Up];return s&&e.push(jh.of(s)),e}const $p=B.mark({class:"cm-selectionMatch"}),Kp=B.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ol(s,e,t,i){return(t==0||s(e.sliceDoc(t-1,t))!=G.Word)&&(i==e.doc.length||s(e.sliceDoc(i,i+1))!=G.Word)}function jp(s,e,t,i){return s(e.sliceDoc(t,t+1))==G.Word&&s(e.sliceDoc(i-1,i))==G.Word}const Up=ue.fromClass(class{constructor(s){this.decorations=this.getDeco(s)}update(s){(s.selectionSet||s.docChanged||s.viewportChanged)&&(this.decorations=this.getDeco(s.view))}getDeco(s){let e=s.state.facet(jh),{state:t}=s,i=t.selection;if(i.ranges.length>1)return B.none;let n=i.main,r,o=null;if(n.empty){if(!e.highlightWordAroundCursor)return B.none;let a=t.wordAt(n.head);if(!a)return B.none;o=t.charCategorizer(n.head),r=t.sliceDoc(a.from,a.to)}else{let a=n.to-n.from;if(a<e.minSelectionLength||a>200)return B.none;if(e.wholeWords){if(r=t.sliceDoc(n.from,n.to),o=t.charCategorizer(n.head),!(ol(o,t,n.from,n.to)&&jp(o,t,n.from,n.to)))return B.none}else if(r=t.sliceDoc(n.from,n.to).trim(),!r)return B.none}let l=[];for(let a of s.visibleRanges){let h=new Xt(t.doc,r,a.from,a.to);for(;!h.next().done;){let{from:c,to:f}=h.value;if((!o||ol(o,t,c,f))&&(n.empty&&c<=n.from&&f>=n.to?l.push(Kp.range(c,f)):(c>=n.to||f<=n.from)&&l.push($p.range(c,f)),l.length>e.maxMatches))return B.none}}return B.set(l)}},{decorations:s=>s.decorations}),Gp=T.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Jp=({state:s,dispatch:e})=>{let{selection:t}=s,i=b.create(t.ranges.map(n=>s.wordAt(n.head)||b.cursor(n.head)),t.mainIndex);return i.eq(t)?!1:(e(s.update({selection:i})),!0)};function Yp(s,e){let{main:t,ranges:i}=s.selection,n=s.wordAt(t.head),r=n&&n.from==t.from&&n.to==t.to;for(let o=!1,l=new Xt(s.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new Xt(s.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=s.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const Xp=({state:s,dispatch:e})=>{let{ranges:t}=s.selection;if(t.some(r=>r.from===r.to))return Jp({state:s,dispatch:e});let i=s.sliceDoc(t[0].from,t[0].to);if(s.selection.ranges.some(r=>s.sliceDoc(r.from,r.to)!=i))return!1;let n=Yp(s,i);return n?(e(s.update({selection:s.selection.addRange(b.range(n.from,n.to),!1),effects:T.scrollIntoView(n.to)})),!0):!1},Zt=O.define({combine(s){return Pt(s,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new lg(e),scrollToMatch:e=>T.scrollIntoView(e)})}});class Uh{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Wp(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?`
`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new eg(this):new Qp(this)}getCursor(e,t=0,i){let n=e.doc?e:H.create({doc:e});return i==null&&(i=n.doc.length),this.regexp?Nt(this,n,t,i):It(this,n,t,i)}}class Gh{constructor(e){this.spec=e}}function It(s,e,t,i){return new Xt(e.doc,s.unquoted,t,i,s.caseSensitive?void 0:n=>n.toLowerCase(),s.wholeWord?_p(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}function _p(s,e){return(t,i,n,r)=>((r>t||r+n.length<i)&&(r=Math.max(0,t-2),n=s.sliceString(r,Math.min(s.length,i+2))),(e(An(n,t-r))!=G.Word||e(Mn(n,t-r))!=G.Word)&&(e(Mn(n,i-r))!=G.Word||e(An(n,i-r))!=G.Word))}class Qp extends Gh{constructor(e){super(e)}nextMatch(e,t,i){let n=It(this.spec,e,i,e.doc.length).nextOverlapping();return n.done&&(n=It(this.spec,e,0,t).nextOverlapping()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=i;;){let r=Math.max(t,n-1e4-this.spec.unquoted.length),o=It(this.spec,e,r,n),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;n-=1e4}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=It(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=It(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}function Nt(s,e,t,i){return new $h(e.doc,s.search,{ignoreCase:!s.caseSensitive,test:s.wholeWord?Zp(e.charCategorizer(e.selection.main.head)):void 0},t,i)}function An(s,e){return s.slice(oe(s,e,!1),e)}function Mn(s,e){return s.slice(e,oe(s,e))}function Zp(s){return(e,t,i)=>!i[0].length||(s(An(i.input,i.index))!=G.Word||s(Mn(i.input,i.index))!=G.Word)&&(s(Mn(i.input,i.index+i[0].length))!=G.Word||s(An(i.input,i.index+i[0].length))!=G.Word)}class eg extends Gh{nextMatch(e,t,i){let n=Nt(this.spec,e,i,e.doc.length).next();return n.done&&(n=Nt(this.spec,e,0,t).next()),n.done?null:n.value}prevMatchInRange(e,t,i){for(let n=1;;n++){let r=Math.max(t,i-n*1e4),o=Nt(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,(t,i)=>i=="$"?"$":i=="&"?e.match[0]:i!="0"&&+i<e.match.length?e.match[i]:t)}matchAll(e,t){let i=Nt(this.spec,e,0,e.doc.length),n=[];for(;!i.next().done;){if(n.length>=t)return null;n.push(i.value)}return n}highlight(e,t,i,n){let r=Nt(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)n(r.value.from,r.value.to)}}const Ai=F.define(),Ar=F.define(),ct=ye.define({create(s){return new os(tr(s).create(),null)},update(s,e){for(let t of e.effects)t.is(Ai)?s=new os(t.value.create(),s.panel):t.is(Ar)&&(s=new os(s.query,t.value?Mr:null));return s},provide:s=>yn.from(s,e=>e.panel)});class os{constructor(e,t){this.query=e,this.panel=t}}const tg=B.mark({class:"cm-searchMatch"}),ig=B.mark({class:"cm-searchMatch cm-searchMatch-selected"}),ng=ue.fromClass(class{constructor(s){this.view=s,this.decorations=this.highlight(s.state.field(ct))}update(s){let e=s.state.field(ct);(e!=s.startState.field(ct)||s.docChanged||s.selectionSet||s.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:s,panel:e}){if(!e||!s.spec.valid)return B.none;let{view:t}=this,i=new At;for(let n=0,r=t.visibleRanges,o=r.length;n<o;n++){let{from:l,to:a}=r[n];for(;n<o-1&&a>r[n+1].from-2*250;)a=r[++n].to;s.highlight(t.state,l,a,(h,c)=>{let f=t.state.selection.ranges.some(u=>u.from==h&&u.to==c);i.add(h,c,f?ig:tg)})}return i.finish()}},{decorations:s=>s.decorations});function Ri(s){return e=>{let t=e.state.field(ct,!1);return t&&t.query.spec.valid?s(e,t):Xh(e)}}const Dn=Ri((s,{query:e})=>{let{to:t}=s.state.selection.main,i=e.nextMatch(s.state,t,t);if(!i)return!1;let n=b.single(i.from,i.to),r=s.state.facet(Zt);return s.dispatch({selection:n,effects:[Dr(s,i),r.scrollToMatch(n.main,s)],userEvent:"select.search"}),Yh(s),!0}),On=Ri((s,{query:e})=>{let{state:t}=s,{from:i}=t.selection.main,n=e.prevMatch(t,i,i);if(!n)return!1;let r=b.single(n.from,n.to),o=s.state.facet(Zt);return s.dispatch({selection:r,effects:[Dr(s,n),o.scrollToMatch(r.main,s)],userEvent:"select.search"}),Yh(s),!0}),sg=Ri((s,{query:e})=>{let t=e.matchAll(s.state,1e3);return!t||!t.length?!1:(s.dispatch({selection:b.create(t.map(i=>b.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),rg=({state:s,dispatch:e})=>{let t=s.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:n}=t.main,r=[],o=0;for(let l=new Xt(s.doc,s.sliceDoc(i,n));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(b.range(l.value.from,l.value.to))}return e(s.update({selection:b.create(r,o),userEvent:"select.search.matches"})),!0},ll=Ri((s,{query:e})=>{let{state:t}=s,{from:i,to:n}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=[],l,a,h=[];if(r.from==i&&r.to==n&&(a=t.toText(e.getReplacement(r)),o.push({from:r.from,to:r.to,insert:a}),r=e.nextMatch(t,r.from,r.to),h.push(T.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))),r){let c=o.length==0||o[0].from>=r.to?0:r.to-r.from-a.length;l=b.single(r.from-c,r.to-c),h.push(Dr(s,r)),h.push(t.facet(Zt).scrollToMatch(l.main,s))}return s.dispatch({changes:o,selection:l,effects:h,userEvent:"input.replace"}),!0}),og=Ri((s,{query:e})=>{if(s.state.readOnly)return!1;let t=e.matchAll(s.state,1e9).map(n=>{let{from:r,to:o}=n;return{from:r,to:o,insert:e.getReplacement(n)}});if(!t.length)return!1;let i=s.state.phrase("replaced $ matches",t.length)+".";return s.dispatch({changes:t,effects:T.announce.of(i),userEvent:"input.replace.all"}),!0});function Mr(s){return s.state.facet(Zt).createPanel(s)}function tr(s,e){var t,i,n,r,o;let l=s.selection.main,a=l.empty||l.to>l.from+100?"":s.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=s.facet(Zt);return new Uh({search:((t=e==null?void 0:e.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e==null?void 0:e.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(n=e==null?void 0:e.literal)!==null&&n!==void 0?n:h.literal,regexp:(r=e==null?void 0:e.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e==null?void 0:e.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function Jh(s){let e=mn(s,Mr);return e&&e.dom.querySelector("[main-field]")}function Yh(s){let e=Jh(s);e&&e==s.root.activeElement&&e.select()}const Xh=s=>{let e=s.state.field(ct,!1);if(e&&e.panel){let t=Jh(s);if(t&&t!=s.root.activeElement){let i=tr(s.state,e.query.spec);i.valid&&s.dispatch({effects:Ai.of(i)}),t.focus(),t.select()}}else s.dispatch({effects:[Ar.of(!0),e?Ai.of(tr(s.state,e.query.spec)):F.appendConfig.of(hg)]});return!0},_h=s=>{let e=s.state.field(ct,!1);if(!e||!e.panel)return!1;let t=mn(s,Mr);return t&&t.dom.contains(s.root.activeElement)&&s.focus(),s.dispatch({effects:Ar.of(!1)}),!0},Am=[{key:"Mod-f",run:Xh,scope:"editor search-panel"},{key:"F3",run:Dn,shift:On,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Dn,shift:On,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:_h,scope:"editor search-panel"},{key:"Mod-Shift-l",run:rg},{key:"Mod-Alt-g",run:Hp},{key:"Mod-d",run:Xp,preventDefault:!0}];class lg{constructor(e){this.view=e;let t=this.query=e.state.field(ct).query.spec;this.commit=this.commit.bind(this),this.searchField=le("input",{value:t.search,placeholder:Se(e,"Find"),"aria-label":Se(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=le("input",{value:t.replace,placeholder:Se(e,"Replace"),"aria-label":Se(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=le("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=le("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=le("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(n,r,o){return le("button",{class:"cm-button",name:n,onclick:r,type:"button"},o)}this.dom=le("div",{onkeydown:n=>this.keydown(n),class:"cm-search"},[this.searchField,i("next",()=>Dn(e),[Se(e,"next")]),i("prev",()=>On(e),[Se(e,"previous")]),i("select",()=>sg(e),[Se(e,"all")]),le("label",null,[this.caseField,Se(e,"match case")]),le("label",null,[this.reField,Se(e,"regexp")]),le("label",null,[this.wordField,Se(e,"by word")]),...e.state.readOnly?[]:[le("br"),this.replaceField,i("replace",()=>ll(e),[Se(e,"replace")]),i("replaceAll",()=>og(e),[Se(e,"replace all")])],le("button",{name:"close",onclick:()=>_h(e),"aria-label":Se(e,"close"),type:"button"},["×"])])}commit(){let e=new Uh({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Ai.of(e)}))}keydown(e){su(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?On:Dn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),ll(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(Ai)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Zt).top}}function Se(s,e){return s.state.phrase(e)}const Zi=30,en=/[\s\.,:;?!]/;function Dr(s,{from:e,to:t}){let i=s.state.doc.lineAt(e),n=s.state.doc.lineAt(t).to,r=Math.max(i.from,e-Zi),o=Math.min(n,t+Zi),l=s.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<Zi;a++)if(!en.test(l[a+1])&&en.test(l[a])){l=l.slice(a);break}}if(o!=n){for(let a=l.length-1;a>l.length-Zi;a--)if(!en.test(l[a-1])&&en.test(l[a])){l=l.slice(0,a);break}}return T.announce.of(`${s.state.phrase("current match")}. ${l} ${s.state.phrase("on line")} ${i.number}.`)}const ag=T.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"}}),hg=[ct,Bt.low(ng),ag];class Qh{constructor(e,t,i){this.state=e,this.pos=t,this.explicit=i,this.abortListeners=[]}tokenBefore(e){let t=me(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),n=t.text.slice(i-t.from,this.pos-t.from),r=n.search(Zh(e,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t){e=="abort"&&this.abortListeners&&this.abortListeners.push(t)}}function al(s){let e=Object.keys(s).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function cg(s){let e=Object.create(null),t=Object.create(null);for(let{label:n}of s){e[n[0]]=!0;for(let r=1;r<n.length;r++)t[n[r]]=!0}let i=al(e)+al(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function fg(s){let e=s.map(n=>typeof n=="string"?{label:n}:n),[t,i]=e.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:cg(e);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:e,validFor:t}:null}}function Mm(s,e){return t=>{for(let i=me(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(s.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class hl{constructor(e,t,i,n){this.completion=e,this.source=t,this.match=i,this.score=n}}function ft(s){return s.selection.main.from}function Zh(s,e){var t;let{source:i}=s,n=e&&i[0]!="^",r=i[i.length-1]!="$";return!n&&!r?s:new RegExp(`${n?"^":""}(?:${i})${r?"$":""}`,(t=s.flags)!==null&&t!==void 0?t:s.ignoreCase?"i":"")}const ec=nt.define();function ug(s,e,t,i){let{main:n}=s.selection,r=t-n.from,o=i-n.from;return Object.assign(Object.assign({},s.changeByRange(l=>l!=n&&t!=i&&s.sliceDoc(l.from+r,l.from+o)!=s.sliceDoc(t,i)?{range:l}:{changes:{from:l.from+r,to:i==n.from?l.to:l.from+o,insert:e},range:b.cursor(l.from+r+e.length)})),{scrollIntoView:!0,userEvent:"input.complete"})}const cl=new WeakMap;function dg(s){if(!Array.isArray(s))return s;let e=cl.get(s);return e||cl.set(s,e=fg(s)),e}const Tn=F.define(),Mi=F.define();class pg{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=ne(e,t),n=Be(i);this.chars.push(i);let r=e.slice(t,t+n),o=r.toUpperCase();this.folded.push(ne(o==r?r.toLowerCase():o,0)),t+=n}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,!0}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return!1;let{chars:t,folded:i,any:n,precise:r,byWord:o}=this;if(t.length==1){let w=ne(e,0),S=Be(w),v=S==e.length?0:-100;if(w!=t[0])if(w==i[0])v+=-200;else return!1;return this.ret(v,[0,S])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let w=0,S=Math.min(e.length,200);w<S&&h<a;){let v=ne(e,w);(v==t[h]||v==i[h])&&(n[h++]=w),w+=Be(v)}if(h<a)return!1}let c=0,f=0,u=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let w=0,S=Math.min(e.length,200),v=0;w<S&&f<a;){let x=ne(e,w);l<0&&(c<a&&x==t[c]&&(r[c++]=w),d<a&&(x==t[d]||x==i[d]?(d==0&&(p=w),m=w+1,d++):d=0));let A,C=x<255?x>=48&&x<=57||x>=97&&x<=122?2:x>=65&&x<=90?1:0:(A=nr(x))!=A.toLowerCase()?1:A!=A.toUpperCase()?2:0;(!w||C==1&&g||v==0&&C!=0)&&(t[f]==x||i[f]==x&&(u=!0)?o[f++]=w:o.length&&(y=!1)),v=C,w+=Be(x)}return f==a&&o[0]==0&&y?this.result(-100+(u?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):f==a?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,e):t.length==2?!1:this.result((n[0]?-700:0)+-200+-1100,n,e)}result(e,t,i){let n=[],r=0;for(let o of t){let l=o+(this.astral?Be(ne(i,o)):1);r&&n[r-1]==o?n[r-1]=l:(n[r++]=o,n[r++]=l)}return this.ret(e-i.length,n)}}const re=O.define({combine(s){return Pt(s,{activateOnTyping:!0,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:gg,compareCompletions:(e,t)=>e.label.localeCompare(t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>fl(e(i),t(i)),optionClass:(e,t)=>i=>fl(e(i),t(i)),addToOptions:(e,t)=>e.concat(t)})}});function fl(s,e){return s?e?s+" "+e:s:e}function gg(s,e,t,i,n,r){let o=s.textDirection==X.RTL,l=o,a=!1,h="top",c,f,u=e.left-n.left,d=n.right-e.right,p=i.right-i.left,m=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(n.top,Math.min(t.top,n.bottom-m))-e.top,f=Math.min(400,l?u:d);else{a=!0,f=Math.min(400,(o?e.right:n.right-e.left)-30);let w=n.bottom-e.bottom;w>=m||w>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${c/g}px; max-width: ${f/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}function mg(s){let e=s.addToOptions.slice();return s.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(n=>"cm-completionIcon-"+n)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,n,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.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(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function ls(s,e,t){if(s<=t)return{from:0,to:s};if(e<0&&(e=0),e<=s>>1){let n=Math.floor(e/t);return{from:n*t,to:(n+1)*t}}let i=Math.floor((s-e)/t);return{from:s-(i+1)*t,to:s-i*t}}class yg{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let n=e.state.field(t),{options:r,selected:o}=n.open,l=e.state.facet(re);this.optionContent=mg(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=ls(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=e.state.field(t).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(e,h[+f[1]]),a.preventDefault();return}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(re).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Mi.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),n=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=n){let{options:r,selected:o,disabled:l}=i.open;(!n.open||n.open.options!=r)&&(this.range=ls(r.length,o,e.state.facet(re).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=n.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;if((t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=ls(t.options.length,t.selected,this.view.state.facet(re).maxRenderedOptions),this.showOptions(t.options,e.id)),this.updateSelectedOption(t.selected)){this.destroyInfo();let{completion:i}=t.options[t.selected],{info:n}=i;if(!n)return;let r=typeof n=="string"?document.createTextNode(n):n(i);if(!r)return;"then"in r?r.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,i)}).catch(o=>Ne(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:n,destroy:r}=e;i.appendChild(n),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)i.nodeName!="LI"||!i.id?n--:n==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return t&&wg(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:o.innerWidth,bottom:o.innerHeight}}return n.top>Math.min(r.bottom,t.bottom)-10||n.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(re).positionInfo(this.view,t,n,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const n=document.createElement("ul");n.id=t,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let u=typeof h=="string"?h:h.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof h!="string"&&h.header)n.appendChild(h.header(h));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const c=n.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let f=this.optionClass(l);f&&(c.className=f);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function bg(s,e){return t=>new yg(t,s,e)}function wg(s,e){let t=s.getBoundingClientRect(),i=e.getBoundingClientRect(),n=t.height/s.offsetHeight;i.top<t.top?s.scrollTop-=(t.top-i.top)/n:i.bottom>t.bottom&&(s.scrollTop+=(i.bottom-t.bottom)/n)}function ul(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function xg(s,e){let t=[],i=null,n=a=>{t.push(a);let{section:h}=a.completion;if(h){i||(i=[]);let c=typeof h=="string"?h:h.name;i.some(f=>f.name==c)||i.push(typeof h=="string"?{name:c}:h)}};for(let a of s)if(a.hasResult()){let h=a.result.getMatch;if(a.result.filter===!1)for(let c of a.result.options)n(new hl(c,a.source,h?h(c):[],1e9-t.length));else{let c=new pg(e.sliceDoc(a.from,a.to));for(let f of a.result.options)if(c.match(f.label)){let u=f.displayLabel?h?h(f,c.matched):[]:c.matched;n(new hl(f,a.source,u,c.score+(f.boost||0)))}}}if(i){let a=Object.create(null),h=0,c=(f,u)=>{var d,p;return((d=f.rank)!==null&&d!==void 0?d:1e9)-((p=u.rank)!==null&&p!==void 0?p:1e9)||(f.name<u.name?-1:1)};for(let f of i.sort(c))h-=1e5,a[f.name]=h;for(let f of t){let{section:u}=f.completion;u&&(f.score+=a[typeof u=="string"?u:u.name])}}let r=[],o=null,l=e.facet(re).compareCompletions;for(let a of t.sort((h,c)=>c.score-h.score||l(h.completion,c.completion))){let h=a.completion;!o||o.label!=h.label||o.detail!=h.detail||o.type!=null&&h.type!=null&&o.type!=h.type||o.apply!=h.apply||o.boost!=h.boost?r.push(a):ul(a.completion)>ul(o)&&(r[r.length-1]=a),o=a.completion}return r}class Ft{constructor(e,t,i,n,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Ft(this.options,dl(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,n,r){let o=xg(e,t);if(!o.length)return n&&e.some(a=>a.state==1)?new Ft(n.options,n.attrs,n.tooltip,n.timestamp,n.selected,!0):null;let l=t.facet(re).selectOnOpen?0:-1;if(n&&n.selected!=l&&n.selected!=-1){let a=n.options[n.selected].completion;for(let h=0;h<o.length;h++)if(o[h].completion==a){l=h;break}}return new Ft(o,dl(i,l),{pos:e.reduce((a,h)=>h.hasResult()?Math.min(a,h.from):a,1e8),create:Ag,above:r.aboveCursor},n?n.timestamp:Date.now(),l,!1)}map(e){return new Ft(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:e.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Bn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new Bn(Sg,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(re),r=(i.override||t.languageDataAt("autocomplete",ft(t)).map(dg)).map(l=>(this.active.find(h=>h.source==l)||new xe(l,this.active.some(h=>h.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((l,a)=>l==this.active[a])&&(r=this.active);let o=this.open;o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(l=>l.hasResult()&&e.changes.touchesRange(l.from,l.to))||!vg(r,this.active)?o=Ft.build(r,t,this.id,o,i):o&&o.disabled&&!r.some(l=>l.state==1)&&(o=null),!o&&r.every(l=>l.state!=1)&&r.some(l=>l.hasResult())&&(r=r.map(l=>l.hasResult()?new xe(l.source,0):l));for(let l of e.effects)l.is(ic)&&(o=o&&o.setSelected(l.value,this.id));return r==this.active&&o==this.open?this:new Bn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:kg}}function vg(s,e){if(s==e)return!0;for(let t=0,i=0;;){for(;t<s.length&&!s[t].hasResult;)t++;for(;i<e.length&&!e[i].hasResult;)i++;let n=t==s.length,r=i==e.length;if(n||r)return n==r;if(s[t++].result!=e[i++].result)return!1}}const kg={"aria-autocomplete":"list"};function dl(s,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return e>-1&&(t["aria-activedescendant"]=s+"-"+e),t}const Sg=[];function ir(s){return s.isUserEvent("input.type")?"input":s.isUserEvent("delete.backward")?"delete":null}class xe{constructor(e,t,i=-1){this.source=e,this.state=t,this.explicitPos=i}hasResult(){return!1}update(e,t){let i=ir(e),n=this;i?n=n.handleUserEvent(e,i,t):e.docChanged?n=n.handleChange(e):e.selection&&n.state!=0&&(n=new xe(n.source,0));for(let r of e.effects)if(r.is(Tn))n=new xe(n.source,1,r.value?ft(e.state):-1);else if(r.is(Mi))n=new xe(n.source,0);else if(r.is(tc))for(let o of r.value)o.source==n.source&&(n=o);return n}handleUserEvent(e,t,i){return t=="delete"||!i.activateOnTyping?this.map(e.changes):new xe(this.source,1)}handleChange(e){return e.changes.touchesRange(ft(e.startState))?new xe(this.source,0):this.map(e.changes)}map(e){return e.empty||this.explicitPos<0?this:new xe(this.source,this.state,e.mapPos(this.explicitPos))}}class $t extends xe{constructor(e,t,i,n,r){super(e,2,t),this.result=i,this.from=n,this.to=r}hasResult(){return!0}handleUserEvent(e,t,i){var n;let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=ft(e.state);if((this.explicitPos<0?l<=r:l<this.from)||l>o||t=="delete"&&ft(e.startState)==this.from)return new xe(this.source,t=="input"&&i.activateOnTyping?1:0);let a=this.explicitPos<0?-1:e.changes.mapPos(this.explicitPos),h;return Cg(this.result.validFor,e.state,r,o)?new $t(this.source,a,this.result,r,o):this.result.update&&(h=this.result.update(this.result,r,o,new Qh(e.state,l,a>=0)))?new $t(this.source,a,h,h.from,(n=h.to)!==null&&n!==void 0?n:ft(e.state)):new xe(this.source,1,a)}handleChange(e){return e.changes.touchesRange(this.from,this.to)?new xe(this.source,0):this.map(e.changes)}map(e){return e.empty?this:new $t(this.source,this.explicitPos<0?-1:e.mapPos(this.explicitPos),this.result,e.mapPos(this.from),e.mapPos(this.to,1))}}function Cg(s,e,t,i){if(!s)return!1;let n=e.sliceDoc(t,i);return typeof s=="function"?s(n,t,i,e):Zh(s,!0).test(n)}const tc=F.define({map(s,e){return s.map(t=>t.map(e))}}),ic=F.define(),Ae=ye.define({create(){return Bn.start()},update(s,e){return s.update(e)},provide:s=>[Fa.from(s,e=>e.tooltip),T.contentAttributes.from(s,e=>e.attrs)]});function nc(s,e){const t=e.completion.apply||e.completion.label;let i=s.state.field(Ae).active.find(n=>n.source==e.source);return i instanceof $t?(typeof t=="string"?s.dispatch(Object.assign(Object.assign({},ug(s.state,t,i.from,i.to)),{annotations:ec.of(e.completion)})):t(s,e.completion,i.from,i.to),!0):!1}const Ag=bg(Ae,nc);function tn(s,e="option"){return t=>{let i=t.state.field(Ae,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(re).interactionDelay)return!1;let n=1,r;e=="page"&&(r=Va(t,i.open.tooltip))&&(n=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+n*(s?1:-1):s?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:ic.of(l)}),!0}}const Mg=s=>{let e=s.state.field(Ae,!1);return s.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<s.state.facet(re).interactionDelay?!1:nc(s,e.open.options[e.open.selected])},Dg=s=>s.state.field(Ae,!1)?(s.dispatch({effects:Tn.of(!0)}),!0):!1,Og=s=>{let e=s.state.field(Ae,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(s.dispatch({effects:Mi.of(null)}),!0)};class Tg{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Bg=50,Pg=1e3,Lg=ue.fromClass(class{constructor(s){this.view=s,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of s.state.field(Ae).active)e.state==1&&this.startQuery(e)}update(s){let e=s.state.field(Ae);if(!s.selectionSet&&!s.docChanged&&s.startState.field(Ae)==e)return;let t=s.transactions.some(n=>(n.selection||n.docChanged)&&!ir(n));for(let n=0;n<this.running.length;n++){let r=this.running[n];if(t||r.updates.length+s.transactions.length>Bg&&Date.now()-r.time>Pg){for(let o of r.context.abortListeners)try{o()}catch(l){Ne(this.view.state,l)}r.context.abortListeners=null,this.running.splice(n--,1)}else r.updates.push(...s.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),s.transactions.some(n=>n.effects.some(r=>r.is(Tn)))&&(this.pendingStart=!0);let i=this.pendingStart?50:s.state.facet(re).activateOnTypingDelay;if(this.debounceUpdate=e.active.some(n=>n.state==1&&!this.running.some(r=>r.active.source==n.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let n of s.transactions)ir(n)=="input"?this.composing=2:this.composing==2&&n.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:s}=this.view,e=s.field(Ae);for(let t of e.active)t.state==1&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t)}startQuery(s){let{state:e}=this.view,t=ft(e),i=new Qh(e,t,s.explicitPos==t),n=new Tg(s,i);this.running.push(n),Promise.resolve(s.source(i)).then(r=>{n.context.aborted||(n.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Mi.of(null)}),Ne(this.view.state,r)})}scheduleAccept(){this.running.every(s=>s.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(re).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(re);for(let i=0;i<this.running.length;i++){let n=this.running[i];if(n.done===void 0)continue;if(this.running.splice(i--,1),n.done){let o=new $t(n.active.source,n.active.explicitPos,n.done,n.done.from,(s=n.done.to)!==null&&s!==void 0?s:ft(n.updates.length?n.updates[0].startState:this.view.state));for(let l of n.updates)o=o.update(l,t);if(o.hasResult()){e.push(o);continue}}let r=this.view.state.field(Ae).active.find(o=>o.source==n.active.source);if(r&&r.state==1)if(n.done==null){let o=new xe(n.active.source,0);for(let l of n.updates)o=o.update(l,t);o.state!=1&&e.push(o)}else this.startQuery(r)}e.length&&this.view.dispatch({effects:tc.of(e)})}},{eventHandlers:{blur(s){let e=this.view.state.field(Ae,!1);if(e&&e.tooltip&&this.view.state.facet(re).closeOnBlur){let t=e.open&&Va(this.view,e.open.tooltip);(!t||!t.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Mi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:Tn.of(!1)}),20),this.composing=0}}}),sc=T.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 Rg{constructor(e,t,i,n){this.field=e,this.line=t,this.from=i,this.to=n}}class Or{constructor(e,t,i){this.field=e,this.from=t,this.to=i}map(e){let t=e.mapPos(this.from,-1,he.TrackDel),i=e.mapPos(this.to,1,he.TrackDel);return t==null||i==null?null:new Or(this.field,t,i)}}class Tr{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let i=[],n=[t],r=e.doc.lineAt(t),o=/^\s*/.exec(r.text)[0];for(let a of this.lines){if(i.length){let h=o,c=/^\t*/.exec(a)[0].length;for(let f=0;f<c;f++)h+=e.facet(In);n.push(t+h.length-c),a=h+a.slice(c)}i.push(a),t+=a.length+1}let l=this.fieldPositions.map(a=>new Or(a.field,n[a.line]+a.from,n[a.line]+a.to));return{text:i,ranges:l}}static parse(e){let t=[],i=[],n=[],r;for(let o of e.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(o);){let l=r[1]?+r[1]:null,a=r[2]||r[3]||"",h=-1;for(let c=0;c<t.length;c++)(l!=null?t[c].seq==l:a&&t[c].name==a)&&(h=c);if(h<0){let c=0;for(;c<t.length&&(l==null||t[c].seq!=null&&t[c].seq<l);)c++;t.splice(c,0,{seq:l,name:a}),h=c;for(let f of n)f.field>=h&&f.field++}n.push(new Rg(h,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+a+o.slice(r.index+r[0].length)}for(let l;l=/\\([{}])/.exec(o);){o=o.slice(0,l.index)+l[1]+o.slice(l.index+l[0].length);for(let a of n)a.line==i.length&&a.from>l.index&&(a.from--,a.to--)}i.push(o)}return new Tr(i,n)}}let Eg=B.widget({widget:new class extends Lt{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),Ig=B.mark({class:"cm-snippetField"});class ei{constructor(e,t){this.ranges=e,this.active=t,this.deco=B.set(e.map(i=>(i.from==i.to?Eg:Ig).range(i.from,i.to)))}map(e){let t=[];for(let i of this.ranges){let n=i.map(e);if(!n)return null;t.push(n)}return new ei(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(i=>i.field==this.active&&i.from<=t.from&&i.to>=t.to))}}const Ei=F.define({map(s,e){return s&&s.map(e)}}),Ng=F.define(),Di=ye.define({create(){return null},update(s,e){for(let t of e.effects){if(t.is(Ei))return t.value;if(t.is(Ng)&&s)return new ei(s.ranges,t.value)}return s&&e.docChanged&&(s=s.map(e.changes)),s&&e.selection&&!s.selectionInsideField(e.selection)&&(s=null),s},provide:s=>T.decorations.from(s,e=>e?e.deco:B.none)});function Br(s,e){return b.create(s.filter(t=>t.field==e).map(t=>b.range(t.from,t.to)))}function Fg(s){let e=Tr.parse(s);return(t,i,n,r)=>{let{text:o,ranges:l}=e.instantiate(t.state,n),a={changes:{from:n,to:r,insert:V.of(o)},scrollIntoView:!0,annotations:i?[ec.of(i),Q.userEvent.of("input.complete")]:void 0};if(l.length&&(a.selection=Br(l,0)),l.some(h=>h.field>0)){let h=new ei(l,0),c=a.effects=[Ei.of(h)];t.state.field(Di,!1)===void 0&&c.push(F.appendConfig.of([Di,qg,$g,sc]))}t.dispatch(t.state.update(a))}}function rc(s){return({state:e,dispatch:t})=>{let i=e.field(Di,!1);if(!i||s<0&&i.active==0)return!1;let n=i.active+s,r=s>0&&!i.ranges.some(o=>o.field==n+s);return t(e.update({selection:Br(i.ranges,n),effects:Ei.of(r?null:new ei(i.ranges,n)),scrollIntoView:!0})),!0}}const Vg=({state:s,dispatch:e})=>s.field(Di,!1)?(e(s.update({effects:Ei.of(null)})),!0):!1,Wg=rc(1),Hg=rc(-1),zg=[{key:"Tab",run:Wg,shift:Hg},{key:"Escape",run:Vg}],pl=O.define({combine(s){return s.length?s[0]:zg}}),qg=Bt.highest(dr.compute([pl],s=>s.facet(pl)));function Dm(s,e){return Object.assign(Object.assign({},e),{apply:Fg(s)})}const $g=T.domEventHandlers({mousedown(s,e){let t=e.state.field(Di,!1),i;if(!t||(i=e.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=t.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==t.active?!1:(e.dispatch({selection:Br(t.ranges,n.field),effects:Ei.of(t.ranges.some(r=>r.field>n.field)?new ei(t.ranges,n.field):null),scrollIntoView:!0}),!0)}}),Oi={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},St=F.define({map(s,e){let t=e.mapPos(s,-1,he.TrackAfter);return t??void 0}}),Pr=new class extends Ct{};Pr.startSide=1;Pr.endSide=-1;const oc=ye.define({create(){return $.empty},update(s,e){if(s=s.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);s=s.update({filter:i=>i>=t.from&&i<=t.to})}for(let t of e.effects)t.is(St)&&(s=s.update({add:[Pr.range(t.value,t.value+1)]}));return s}});function Om(){return[jg,oc]}const as="()[]{}<>";function lc(s){for(let e=0;e<as.length;e+=2)if(as.charCodeAt(e)==s)return as.charAt(e+1);return nr(s<128?s:s+1)}function ac(s,e){return s.languageDataAt("closeBrackets",e)[0]||Oi}const Kg=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),jg=T.inputHandler.of((s,e,t,i)=>{if((Kg?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&Be(ne(i,0))==1||e!=n.from||t!=n.to)return!1;let r=Gg(s.state,i);return r?(s.dispatch(r),!0):!1}),Ug=({state:s,dispatch:e})=>{if(s.readOnly)return!1;let i=ac(s,s.selection.main.head).brackets||Oi.brackets,n=null,r=s.changeByRange(o=>{if(o.empty){let l=Jg(s.doc,o.head);for(let a of i)if(a==l&&qn(s.doc,o.head)==lc(ne(a,0)))return{changes:{from:o.head-a.length,to:o.head+a.length},range:b.cursor(o.head-a.length)}}return{range:n=o}});return n||e(s.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!n},Tm=[{key:"Backspace",run:Ug}];function Gg(s,e){let t=ac(s,s.selection.main.head),i=t.brackets||Oi.brackets;for(let n of i){let r=lc(ne(n,0));if(e==n)return r==n?_g(s,n,i.indexOf(n+n+n)>-1,t):Yg(s,n,r,t.before||Oi.before);if(e==r&&hc(s,s.selection.main.from))return Xg(s,n,r)}return null}function hc(s,e){let t=!1;return s.field(oc).between(0,s.doc.length,i=>{i==e&&(t=!0)}),t}function qn(s,e){let t=s.sliceString(e,e+2);return t.slice(0,Be(ne(t,0)))}function Jg(s,e){let t=s.sliceString(e-2,e);return Be(ne(t,0))==t.length?t:t.slice(1)}function Yg(s,e,t,i){let n=null,r=s.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:t,from:o.to}],effects:St.of(o.to+e.length),range:b.range(o.anchor+e.length,o.head+e.length)};let l=qn(s.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:e+t,from:o.head},effects:St.of(o.head+e.length),range:b.cursor(o.head+e.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Xg(s,e,t){let i=null,n=s.changeByRange(r=>r.empty&&qn(s.doc,r.head)==t?{changes:{from:r.head,to:r.head+t.length,insert:t},range:b.cursor(r.head+t.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function _g(s,e,t,i){let n=i.stringPrefixes||Oi.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:e,from:l.to}],effects:St.of(l.to+e.length),range:b.range(l.anchor+e.length,l.head+e.length)};let a=l.head,h=qn(s.doc,a),c;if(h==e){if(gl(s,a))return{changes:{insert:e+e,from:a},effects:St.of(a+e.length),range:b.cursor(a+e.length)};if(hc(s,a)){let u=t&&s.sliceDoc(a,a+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:a,to:a+u.length,insert:u},range:b.cursor(a+u.length)}}}else{if(t&&s.sliceDoc(a-2*e.length,a)==e+e&&(c=ml(s,a-2*e.length,n))>-1&&gl(s,c))return{changes:{insert:e+e+e+e,from:a},effects:St.of(a+e.length),range:b.cursor(a+e.length)};if(s.charCategorizer(a)(h)!=G.Word&&ml(s,a,n)>-1&&!Qg(s,a,e,n))return{changes:{insert:e+e,from:a},effects:St.of(a+e.length),range:b.cursor(a+e.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function gl(s,e){let t=me(s).resolveInner(e+1);return t.parent&&t.from==e}function Qg(s,e,t,i){let n=me(s).resolveInner(e,-1),r=i.reduce((o,l)=>Math.max(o,l.length),0);for(let o=0;o<5;o++){let l=s.sliceDoc(n.from,Math.min(n.to,n.from+t.length+r)),a=l.indexOf(t);if(!a||a>-1&&i.indexOf(l.slice(0,a))>-1){let c=n.firstChild;for(;c&&c.from==n.from&&c.to-c.from>t.length+a;){if(s.sliceDoc(c.to-t.length,c.to)==t)return!1;c=c.firstChild}return!0}let h=n.to==e&&n.parent;if(!h)break;n=h}return!1}function ml(s,e,t){let i=s.charCategorizer(e);if(i(s.sliceDoc(e-1,e))!=G.Word)return e;for(let n of t){let r=e-n.length;if(s.sliceDoc(r,e)==n&&i(s.sliceDoc(r-1,r))!=G.Word)return r}return-1}function Bm(s={}){return[Ae,re.of(s),Lg,em,sc]}const Zg=[{key:"Ctrl-Space",run:Dg},{key:"Escape",run:Og},{key:"ArrowDown",run:tn(!0)},{key:"ArrowUp",run:tn(!1)},{key:"PageDown",run:tn(!0,"page")},{key:"PageUp",run:tn(!1,"page")},{key:"Enter",run:Mg}],em=Bt.highest(dr.computeN([re],s=>s.facet(re).defaultKeymap?[Zg]:[]));export{hm as A,ld as B,Pn as C,Iu as D,T as E,pm as F,gm as G,mm as H,Y as I,fm as J,am as K,Us as L,Mm as M,pr as N,fg as O,$a as P,b as Q,Dm as R,nh as S,K as T,dm as U,um as V,sd as W,Ua as X,kd as Y,Zg as a,H as b,Tm as c,km as d,lm as e,sm as f,xm as g,vm as h,im as i,nm as j,ym as k,wm as l,Om as m,Cm as n,dr as o,Bm as p,rm as q,om as r,Am as s,Sm as t,bm as u,me as v,ge as w,R as x,Zu as y,M as z};