@oroinc/codemirror-expression-editor 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +10 -10
  2. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- let ls=[],ol=[];(()=>{let s="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(t=>t?parseInt(t,36):1);for(let t=0,e=0;t<s.length;t++)(t%2?ol:ls).push(e=e+s[t])})();function Da(s){if(s<768)return!1;for(let t=0,e=ls.length;;){let i=t+e>>1;if(s<ls[i])e=i;else if(s>=ol[i])t=i+1;else return!0;if(t==e)return!1}}function Mr(s){return s>=127462&&s<=127487}const Tr=8205;function Ba(s,t,e=!0,i=!0){return(e?ll:Ra)(s,t,i)}function ll(s,t,e){if(t==s.length)return t;t&&hl(s.charCodeAt(t))&&al(s.charCodeAt(t-1))&&t--;let i=$n(s,t);for(t+=Pr(i);t<s.length;){let n=$n(s,t);if(i==Tr||n==Tr||e&&Da(n))t+=Pr(n),i=n;else if(Mr(n)){let r=0,o=t-2;for(;o>=0&&Mr($n(s,o));)r++,o-=2;if(r%2==0)break;t+=2}else break}return t}function Ra(s,t,e){for(;t>0;){let i=ll(s,t-2,e);if(i<t)return i;t--}return 0}function $n(s,t){let e=s.charCodeAt(t);if(!al(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return hl(i)?(e-55296<<10)+(i-56320)+65536:e}function hl(s){return s>=56320&&s<57344}function al(s){return s>=55296&&s<56320}function Pr(s){return s<65536?1:2}class L{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=Fe(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),Ht.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=Fe(this,t,e);let i=[];return this.decompose(t,e,i,0),Ht.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=new li(this),r=new li(t);for(let o=e,l=e;;){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(t=1){return new li(this,t)}iterRange(t,e=this.length){return new fl(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new cl(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?L.empty:t.length<=32?new j(t):Ht.from(j.split(t,[]))}}class j extends L{constructor(t,e=Ea(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((e?i:l)>=t)return new La(n,l,i,o);n=l+1,i++}}decompose(t,e,i,n){let r=t<=0&&e>=this.length?this:new j(Dr(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(n&1){let o=i.pop(),l=Xi(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new j(l,o.length+r.length));else{let h=l.length>>1;i.push(new j(l.slice(0,h)),new j(l.slice(h)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof j))return super.replace(t,e,i);[t,e]=Fe(this,t,e);let n=Xi(this.text,Xi(i.text,Dr(this.text,0,t)),e),r=this.length+i.length-(e-t);return n.length<=32?new j(n,r):Ht.from(j.split(n,[]),r)}sliceString(t,e=this.length,i=`
2
- `){[t,e]=Fe(this,t,e);let n="";for(let r=0,o=0;r<=e&&o<this.text.length;o++){let l=this.text[o],h=r+l.length;r>t&&o&&(n+=i),t<h&&e>r&&(n+=l.slice(Math.max(0,t-r),e-r)),r=h+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let r of t)i.push(r),n+=r.length+1,i.length==32&&(e.push(new j(i,n)),i=[],n=-1);return n>-1&&e.push(new j(i,n)),e}}class Ht extends L{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,n){for(let r=0;;r++){let o=this.children[r],l=n+o.length,h=i+o.lines-1;if((e?h:l)>=t)return o.lineInner(t,e,i,n);n=l+1,i=h+1}}decompose(t,e,i,n){for(let r=0,o=0;o<=e&&r<this.children.length;r++){let l=this.children[r],h=o+l.length;if(t<=h&&e>=o){let f=n&((o<=t?1:0)|(h>=e?2:0));o>=t&&h<=e&&!f?i.push(l):l.decompose(t-o,e-o,i,f)}o=h+1}}replace(t,e,i){if([t,e]=Fe(this,t,e),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(t>=r&&e<=l){let h=o.replace(t-r,e-r,i),f=this.lines-o.lines+h.lines;if(h.lines<f>>4&&h.lines>f>>6){let a=this.children.slice();return a[n]=h,new Ht(a,this.length-(e-t)+i.length)}return super.replace(r,l,h)}r=l+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
3
- `){[t,e]=Fe(this,t,e);let n="";for(let r=0,o=0;r<this.children.length&&o<=e;r++){let l=this.children[r],h=o+l.length;o>t&&r&&(n+=i),t<h&&e>o&&(n+=l.sliceString(t-o,e-o,i)),o=h+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof Ht))return 0;let i=0,[n,r,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,r+=e){if(n==o||r==l)return i;let h=this.children[n],f=t.children[r];if(h!=f)return i+h.scanIdentical(f,e);i+=h.length+1}}static from(t,e=t.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let d of t)i+=d.lines;if(i<32){let d=[];for(let p of t)p.flatten(d);return new j(d,e)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],h=0,f=-1,a=[];function c(d){let p;if(d.lines>r&&d instanceof Ht)for(let g of d.children)c(g);else d.lines>o&&(h>o||!h)?(u(),l.push(d)):d instanceof j&&h&&(p=a[a.length-1])instanceof j&&d.lines+p.lines<=32?(h+=d.lines,f+=d.length+1,a[a.length-1]=new j(p.text.concat(d.text),p.length+1+d.length)):(h+d.lines>n&&u(),h+=d.lines,f+=d.length+1,a.push(d))}function u(){h!=0&&(l.push(a.length==1?a[0]:Ht.from(a,f)),f=-1,h=a.length=0)}for(let d of t)c(d);return u(),l.length==1?l[0]:new Ht(l,e)}}L.empty=new j([""],0);function Ea(s){let t=-1;for(let e of s)t+=e.length+1;return t}function Xi(s,t,e=0,i=1e9){for(let n=0,r=0,o=!0;r<s.length&&n<=i;r++){let l=s[r],h=n+l.length;h>=e&&(h>i&&(l=l.slice(0,i-n)),n<e&&(l=l.slice(e-n)),o?(t[t.length-1]+=l,o=!1):t.push(l)),n=h+1}return t}function Dr(s,t,e){return Xi(s,[""],t,e)}class li{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof j?t.text.length:t.children.length)<<1]}nextInner(t,e){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 j?n.text.length:n.children.length;if(o==(e>0?l:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
4
- `,this;t--}else if(n instanceof j){let h=n.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,h.length>Math.max(0,t))return this.value=t==0?h:e>0?h.slice(t):h.slice(0,h.length-t),this;t-=h.length}else{let h=n.children[o+(e<0?-1:0)];t>h.length?(t-=h.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(e>0?1:(h instanceof j?h.text.length:h.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class fl{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new li(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class cl{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(L.prototype[Symbol.iterator]=function(){return this.iter()},li.prototype[Symbol.iterator]=fl.prototype[Symbol.iterator]=cl.prototype[Symbol.iterator]=function(){return this});class La{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function Fe(s,t,e){return t=Math.max(0,Math.min(s.length,t)),[t,Math.max(t,Math.min(s.length,e))]}function ht(s,t,e=!0,i=!0){return Ba(s,t,e,i)}function Ia(s){return s>=56320&&s<57344}function Na(s){return s>=55296&&s<56320}function Vt(s,t){let e=s.charCodeAt(t);if(!Na(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return Ia(i)?(e-55296<<10)+(i-56320)+65536:e}function ul(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function ne(s){return s<65536?1:2}const hs=/\r\n?|\n/;var nt=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(nt||(nt={}));class Kt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,n=0;e<this.sections.length;){let r=this.sections[e++],o=this.sections[e++];o<0?(t(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(t,e=!1){as(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],n=this.sections[e++];n<0?t.push(i,n):t.push(n,i)}return new Kt(t)}composeDesc(t){return this.empty?t:t.empty?this:dl(this,t)}mapDesc(t,e=!1){return t.empty?this:fs(this,t,e)}mapPos(t,e=-1,i=nt.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],f=n+l;if(h<0){if(f>t)return r+(t-n);r+=l}else{if(i!=nt.Simple&&f>=t&&(i==nt.TrackDel&&n<t&&f>t||i==nt.TrackBefore&&n<t||i==nt.TrackAfter&&f>t))return null;if(f>t||f==t&&e<0&&!l)return t==n||e<0?r:r+h;r+=h}n=f}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return r}touchesRange(t,e=t){for(let i=0,n=0;i<this.sections.length&&n<=e;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=e&&l>=t)return n<t&&l>e?"cover":!0;n=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],n=this.sections[e++];t+=(t?" ":"")+i+(n>=0?":"+n:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Kt(t)}static create(t){return new Kt(t)}}class _ extends Kt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return as(this,(e,i,n,r,o)=>t=t.replace(n,n+(i-e),o),!1),t}mapDesc(t,e=!1){return fs(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,r=0;n<e.length;n+=2){let o=e[n],l=e[n+1];if(l>=0){e[n]=l,e[n+1]=o;let h=n>>1;for(;i.length<h;)i.push(L.empty);i.push(o?t.slice(r,r+o):L.empty)}r+=o}return new _(e,i)}compose(t){return this.empty?t:t.empty?this:dl(this,t,!0)}map(t,e=!1){return t.empty?this:fs(this,t,e,!0)}iterChanges(t,e=!1){as(this,t,e)}get desc(){return Kt.create(this.sections)}filter(t){let e=[],i=[],n=[],r=new ui(this);t:for(let o=0,l=0;;){let h=o==t.length?1e9:t[o++];for(;l<h||l==h&&r.len==0;){if(r.done)break t;let a=Math.min(r.len,h-l);st(n,a,-1);let c=r.ins==-1?-1:r.off==0?r.ins:0;st(e,a,c),c>0&&oe(i,e,r.text),r.forward(a),l+=a}let f=t[o++];for(;l<f;){if(r.done)break t;let a=Math.min(r.len,f-l);st(e,a,-1),st(n,a,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(a),l+=a}}return{changes:new _(e,i),filtered:Kt.create(n)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],n=this.sections[e+1];n<0?t.push(i):n==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let n=[],r=[],o=0,l=null;function h(a=!1){if(!a&&!n.length)return;o<e&&st(n,e-o,-1);let c=new _(n,r);l=l?l.compose(c.map(l)):c,n=[],r=[],o=0}function f(a){if(Array.isArray(a))for(let c of a)f(c);else if(a instanceof _){if(a.length!=e)throw new RangeError(`Mismatched change set length (got ${a.length}, expected ${e})`);h(),l=l?l.compose(a.map(l)):a}else{let{from:c,to:u=c,insert:d}=a;if(c>u||c<0||u>e)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${e})`);let p=d?typeof d=="string"?L.of(d.split(i||hs)):d:L.empty,g=p.length;if(c==u&&g==0)return;c<o&&h(),c>o&&st(n,c-o,-1),st(n,u-c,g),oe(r,n,p),o=u}}return f(t),h(!l),l}static empty(t){return new _(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;n<t.length;n++){let r=t[n];if(typeof r=="number")e.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)e.push(r[0],0);else{for(;i.length<n;)i.push(L.empty);i[n]=L.of(r.slice(1)),e.push(r[0],i[n].length)}}}return new _(e,i)}static createSet(t,e){return new _(t,e)}}function st(s,t,e,i=!1){if(t==0&&e<=0)return;let n=s.length-2;n>=0&&e<=0&&e==s[n+1]?s[n]+=t:n>=0&&t==0&&s[n]==0?s[n+1]+=e:i?(s[n]+=t,s[n+1]+=e):s.push(t,e)}function oe(s,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(e);else{for(;s.length<i;)s.push(L.empty);s.push(e)}}function as(s,t,e){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],h=s.sections[o++];if(h<0)n+=l,r+=l;else{let f=n,a=r,c=L.empty;for(;f+=l,a+=h,h&&i&&(c=c.append(i[o-2>>1])),!(e||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],h=s.sections[o++];t(n,f,r,a,c),n=f,r=a}}}function fs(s,t,e,i=!1){let n=[],r=i?[]:null,o=new ui(s),l=new ui(t);for(let h=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let f=Math.min(o.len,l.len);st(n,f,-1),o.forward(f),l.forward(f)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!e))){let f=l.len;for(st(n,l.ins,-1);f;){let a=Math.min(o.len,f);o.ins>=0&&h<o.i&&o.len<=a&&(st(n,0,o.ins),r&&oe(r,n,o.text),h=o.i),o.forward(a),f-=a}l.next()}else if(o.ins>=0){let f=0,a=o.len;for(;a;)if(l.ins==-1){let c=Math.min(a,l.len);f+=c,a-=c,l.forward(c)}else if(l.ins==0&&l.len<a)a-=l.len,l.next();else break;st(n,f,h<o.i?o.ins:0),r&&h<o.i&&oe(r,n,o.text),h=o.i,o.forward(o.len-a)}else{if(o.done&&l.done)return r?_.createSet(n,r):Kt.create(n);throw new Error("Mismatched change set lengths")}}}function dl(s,t,e=!1){let i=[],n=e?[]:null,r=new ui(s),o=new ui(t);for(let l=!1;;){if(r.done&&o.done)return n?_.createSet(i,n):Kt.create(i);if(r.ins==0)st(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)st(i,0,o.ins,l),n&&oe(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(r.len2,o.len),f=i.length;if(r.ins==-1){let a=o.ins==-1?-1:o.off?0:o.ins;st(i,h,a,l),n&&a&&oe(n,i,o.text)}else o.ins==-1?(st(i,r.off?0:r.len,h,l),n&&oe(n,i,r.textBit(h))):(st(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&oe(n,i,o.text));l=(r.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>f),r.forward2(h),o.forward(h)}}}}class ui{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?L.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?L.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class xe{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new xe(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return b.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return b.range(this.anchor,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return b.range(t.anchor,t.head)}static create(t,e,i){return new xe(t,e,i)}}class b{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:b.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new b([this.main],0)}addRange(t,e=!0){return b.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,b.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new b(t.ranges.map(e=>xe.fromJSON(e)),t.main)}static single(t,e=t){return new b([b.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<t.length;n++){let r=t[n];if(r.empty?r.from<=i:r.from<i)return b.normalized(t.slice(),e);i=r.to}return new b(t,e)}static cursor(t,e=0,i,n){return xe.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(t,e,i,n){let r=(i??16777215)<<6|(n==null?7:Math.min(6,n));return e<t?xe.create(e,t,48|r):xe.create(t,e,(e>t?8:0)|r)}static normalized(t,e=0){let i=t[e];t.sort((n,r)=>n.from-r.from),e=t.indexOf(i);for(let n=1;n<t.length;n++){let r=t[n],o=t[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,h=Math.max(r.to,o.to);n<=e&&e--,t.splice(--n,2,r.anchor>r.head?b.range(h,l):b.range(l,h))}}return new b(t,e)}}function pl(s,t){for(let e of s.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}let Gs=0;class P{constructor(t,e,i,n,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=Gs++,this.default=t([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(t={}){return new P(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:Xs),!!t.static,t.enables)}of(t){return new _i([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new _i(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new _i(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}}function Xs(s,t){return s==t||s.length==t.length&&s.every((e,i)=>e===t[i])}class _i{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=Gs++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,r=this.id,o=t[r]>>1,l=this.type==2,h=!1,f=!1,a=[];for(let c of this.dependencies)c=="doc"?h=!0:c=="selection"?f=!0:(((e=t[c.id])!==null&&e!==void 0?e:1)&1)==0&&a.push(t[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(h&&u.docChanged||f&&(u.docChanged||u.selection)||cs(c,a)){let d=i(c);if(l?!Br(d,c.values[o],n):!n(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[r];if(p!=null){let g=on(u,p);if(this.dependencies.every(m=>m instanceof P?u.facet(m)===c.facet(m):m instanceof ct?u.field(m,!1)==c.field(m,!1):!0)||(l?Br(d=i(c),g,n):n(d=i(c),g)))return c.values[o]=g,0}else d=i(c);return c.values[o]=d,1}}}}function Br(s,t,e){if(s.length!=t.length)return!1;for(let i=0;i<s.length;i++)if(!e(s[i],t[i]))return!1;return!0}function cs(s,t){let e=!1;for(let i of t)hi(s,i)&1&&(e=!0);return e}function Fa(s,t,e){let i=e.map(h=>s[h.id]),n=e.map(h=>h.type),r=i.filter(h=>!(h&1)),o=s[t.id]>>1;function l(h){let f=[];for(let a=0;a<i.length;a++){let c=on(h,i[a]);if(n[a]==2)for(let u of c)f.push(u);else f.push(c)}return t.combine(f)}return{create(h){for(let f of i)hi(h,f);return h.values[o]=l(h),1},update(h,f){if(!cs(h,r))return 0;let a=l(h);return t.compare(a,h.values[o])?0:(h.values[o]=a,1)},reconfigure(h,f){let a=cs(h,i),c=f.config.facets[t.id],u=f.facet(t);if(c&&!a&&Xs(e,c))return h.values[o]=u,0;let d=l(h);return t.compare(d,u)?(h.values[o]=u,0):(h.values[o]=d,1)}}}const Ti=P.define({static:!0});class ct{constructor(t,e,i,n,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(t){let e=new ct(Gs++,t.create,t.update,t.compare||((i,n)=>i===n),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(Ti).find(i=>i.field==this);return((e==null?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,n)=>{let r=i.values[e],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[e]=o,1)},reconfigure:(i,n)=>{let r=i.facet(Ti),o=n.facet(Ti),l;return(l=r.find(h=>h.field==this))&&l!=o.find(h=>h.field==this)?(i.values[e]=l.create(i),1):n.config.address[this.id]!=null?(i.values[e]=n.field(this),0):(i.values[e]=this.create(i),1)}}}init(t){return[this,Ti.of({field:this,create:t})]}get extension(){return this}}const be={lowest:4,low:3,default:2,high:1,highest:0};function _e(s){return t=>new gl(t,s)}const Qe={highest:_e(be.highest),high:_e(be.high),default:_e(be.default),low:_e(be.low),lowest:_e(be.lowest)};class gl{constructor(t,e){this.inner=t,this.prec=e}}class Tn{of(t){return new us(this,t)}reconfigure(t){return Tn.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class us{constructor(t,e){this.compartment=t,this.inner=e}}class rn{constructor(t,e,i,n,r,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let n=[],r=Object.create(null),o=new Map;for(let u of Va(t,e,o))u instanceof ct?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),h=[],f=[];for(let u of n)l[u.id]=f.length<<1,f.push(d=>u.slot(d));let a=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=a&&a[u]||[];if(d.every(m=>m.type==0))if(l[p.id]=h.length<<1|1,Xs(g,d))h.push(i.facet(p));else{let m=p.combine(d.map(y=>y.value));h.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=h.length<<1|1,h.push(m.value)):(l[m.id]=f.length<<1,f.push(y=>m.dynamicSlot(y)));l[p.id]=f.length<<1,f.push(m=>Fa(m,p,d))}}let c=f.map(u=>u(l));return new rn(t,o,c,l,h,r)}}function Va(s,t,e){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let h=n.get(o);if(h!=null){if(h<=l)return;let f=i[h].indexOf(o);f>-1&&i[h].splice(f,1),o instanceof us&&e.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let f of o)r(f,l);else if(o instanceof us){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let f=t.get(o.compartment)||o.inner;e.set(o.compartment,f),r(f,l)}else if(o instanceof gl)r(o.inner,o.prec);else if(o instanceof ct)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof _i)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,be.default);else{let f=o.extension;if(!f)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(f,l)}}return r(s,be.default),i.reduce((o,l)=>o.concat(l))}function hi(s,t){if(t&1)return 2;let e=t>>1,i=s.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[e]=4;let n=s.computeSlot(s,s.config.dynamicSlots[e]);return s.status[e]=2|n}function on(s,t){return t&1?s.config.staticValues[t>>1]:s.values[t>>1]}const ml=P.define(),ds=P.define({combine:s=>s.some(t=>t),static:!0}),yl=P.define({combine:s=>s.length?s[0]:void 0,static:!0}),bl=P.define(),wl=P.define(),xl=P.define(),kl=P.define({combine:s=>s.length?s[0]:!1});class Zt{constructor(t,e){this.type=t,this.value=e}static define(){return new Ha}}class Ha{of(t){return new Zt(this,t)}}class za{constructor(t){this.map=t}of(t){return new R(this,t)}}class R{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new R(this.type,e)}is(t){return this.type==t}static define(t={}){return new za(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let r=n.map(e);r&&i.push(r)}return i}}R.reconfigure=R.define();R.appendConfig=R.define();class G{constructor(t,e,i,n,r,o){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&pl(i,e.newLength),r.some(l=>l.type==G.time)||(this.annotations=r.concat(G.time.of(Date.now())))}static create(t,e,i,n,r,o){return new G(t,e,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(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(G.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}}G.time=Zt.define();G.userEvent=Zt.define();G.addToHistory=Zt.define();G.remote=Zt.define();function Wa(s,t){let e=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==t.length||t[n]>=s[i]))r=s[i++],o=s[i++];else if(n<t.length)r=t[n++],o=t[n++];else return e;!e.length||e[e.length-1]<r?e.push(r,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function vl(s,t,e){var i;let n,r,o;return e?(n=t.changes,r=_.empty(t.changes.length),o=s.changes.compose(t.changes)):(n=t.changes.map(s.changes),r=s.changes.mapDesc(t.changes,!0),o=s.changes.compose(n)),{changes:o,selection:t.selection?t.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:R.mapEffects(s.effects,n).concat(R.mapEffects(t.effects,r)),annotations:s.annotations.length?s.annotations.concat(t.annotations):t.annotations,scrollIntoView:s.scrollIntoView||t.scrollIntoView}}function ps(s,t,e){let i=t.selection,n=Re(t.annotations);return t.userEvent&&(n=n.concat(G.userEvent.of(t.userEvent))),{changes:t.changes instanceof _?t.changes:_.of(t.changes||[],e,s.facet(yl)),selection:i&&(i instanceof b?i:b.single(i.anchor,i.head)),effects:Re(t.effects),annotations:n,scrollIntoView:!!t.scrollIntoView}}function Sl(s,t,e){let i=ps(s,t.length?t[0]:{},s.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let r=1;r<t.length;r++){t[r].filter===!1&&(e=!1);let o=!!t[r].sequential;i=vl(i,ps(s,t[r],o?i.changes.newLength:s.doc.length),o)}let n=G.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return qa(e?$a(n):n)}function $a(s){let t=s.startState,e=!0;for(let n of t.facet(bl)){let r=n(s);if(r===!1){e=!1;break}Array.isArray(r)&&(e=e===!0?r:Wa(e,r))}if(e!==!0){let n,r;if(e===!1)r=s.changes.invertedDesc,n=_.empty(t.doc.length);else{let o=s.changes.filter(e);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=G.create(t,n,s.selection&&s.selection.map(r),R.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=t.facet(wl);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof G?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof G?s=r[0]:s=Sl(t,Re(r),!1)}return s}function qa(s){let t=s.startState,e=t.facet(xl),i=s;for(let n=e.length-1;n>=0;n--){let r=e[n](s);r&&Object.keys(r).length&&(i=vl(i,ps(t,r,s.changes.newLength),!0))}return i==s?s:G.create(t,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const Ua=[];function Re(s){return s==null?Ua:Array.isArray(s)?s:[s]}var kt=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(kt||(kt={}));const Ka=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let gs;try{gs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function ja(s){if(gs)return gs.test(s);for(let t=0;t<s.length;t++){let e=s[t];if(/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||Ka.test(e)))return!0}return!1}function Qa(s){return t=>{if(!/\S/.test(t))return kt.Space;if(ja(t))return kt.Word;for(let e=0;e<s.length;e++)if(t.indexOf(s[e])>-1)return kt.Word;return kt.Other}}class F{constructor(t,e,i,n,r,o){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)hi(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return hi(this,i),on(this,i)}update(...t){return Sl(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:n}=e;for(let l of t.effects)l.is(Tn.reconfigure)?(e&&(n=new Map,e.compartments.forEach((h,f)=>n.set(f,h)),e=null),n.set(l.value.compartment,l.value.extension)):l.is(R.reconfigure)?(e=null,i=l.value):l.is(R.appendConfig)&&(e=null,i=Re(i).concat(l.value));let r;e?r=t.startState.values.slice():(e=rn.resolve(i,n,this),r=new F(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(h,f)=>f.reconfigure(h,this),null).values);let o=t.startState.facet(ds)?t.newSelection:t.newSelection.asSingle();new F(e,t.newDoc,o,r,(l,h)=>h.update(l,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:b.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Re(i.effects);for(let l=1;l<e.ranges.length;l++){let h=t(e.ranges[l]),f=this.changes(h.changes),a=f.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(a);let c=n.mapDesc(f,!0);r.push(h.range.map(c)),n=n.compose(a),o=R.mapEffects(o,a).concat(R.mapEffects(Re(h.effects),c))}return{changes:n,selection:b.create(r,e.mainIndex),effects:o}}changes(t=[]){return t instanceof _?t:_.of(t,this.doc.length,this.facet(F.lineSeparator))}toText(t){return L.of(t.split(this.facet(F.lineSeparator)||hs))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(hi(this,e),on(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let n=t[i];n instanceof ct&&this.config.address[n.id]!=null&&(e[i]=n.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(t,r)){let o=i[r],l=t[r];n.push(o.init(h=>o.spec.fromJSON(l,h)))}}return F.create({doc:t.doc,selection:b.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=rn.resolve(t.extensions||[],new Map),i=t.doc instanceof L?t.doc:L.of((t.doc||"").split(e.staticFacet(F.lineSeparator)||hs)),n=t.selection?t.selection instanceof b?t.selection:b.single(t.selection.anchor,t.selection.head):b.single(0);return pl(n,i.length),e.staticFacet(ds)||(n=n.asSingle()),new F(e,i,n,e.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(F.tabSize)}get lineBreak(){return this.facet(F.lineSeparator)||`
5
- `}get readOnly(){return this.facet(kl)}phrase(t,...e){for(let i of this.facet(F.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>e.length?i:e[r-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let r of this.facet(ml))for(let o of r(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&n.push(o[t]);return n}charCategorizer(t){return Qa(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),r=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let h=ht(e,o,!1);if(r(e.slice(h,o))!=kt.Word)break;o=h}for(;l<n;){let h=ht(e,l);if(r(e.slice(l,h))!=kt.Word)break;l=h}return o==l?null:b.range(o+i,l+i)}}F.allowMultipleSelections=ds;F.tabSize=P.define({combine:s=>s.length?s[0]:4});F.lineSeparator=yl;F.readOnly=kl;F.phrases=P.define({compare(s,t){let e=Object.keys(s),i=Object.keys(t);return e.length==i.length&&e.every(n=>s[n]==t[n])}});F.languageData=ml;F.changeFilter=bl;F.transactionFilter=wl;F.transactionExtender=xl;Tn.reconfigure=R.define();function Pn(s,t,e={}){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(e,r))i[r]=e[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let n in t)i[n]===void 0&&(i[n]=t[n]);return i}class Ce{eq(t){return this==t}range(t,e=t){return ms.create(t,e,this)}}Ce.prototype.startSide=Ce.prototype.endSide=0;Ce.prototype.point=!1;Ce.prototype.mapMode=nt.TrackDel;let ms=class Cl{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new Cl(t,e,i)}};function ys(s,t){return s.from-t.from||s.value.startSide-t.value.startSide}class _s{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let r=i?this.to:this.from;for(let o=n,l=r.length;;){if(o==l)return o;let h=o+l>>1,f=r[h]-t||(i?this.value[h].endSide:this.value[h].startSide)-e;if(h==o)return f>=0?o:l;f>=0?l=h:o=h+1}}between(t,e,i,n){for(let r=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(n(this.from[r]+t,this.to[r]+t,this.value[r])===!1)return!1}map(t,e){let i=[],n=[],r=[],o=-1,l=-1;for(let h=0;h<this.value.length;h++){let f=this.value[h],a=this.from[h]+t,c=this.to[h]+t,u,d;if(a==c){let p=e.mapPos(a,f.startSide,f.mapMode);if(p==null||(u=d=p,f.startSide!=f.endSide&&(d=e.mapPos(a,f.endSide),d<u)))continue}else if(u=e.mapPos(a,f.startSide),d=e.mapPos(c,f.endSide),u>d||u==d&&f.startSide>0&&f.endSide<=0)continue;(d-u||f.endSide-f.startSide)<0||(o<0&&(o=u),f.point&&(l=Math.max(l,d-u)),i.push(f),n.push(u-o),r.push(d-o))}return{mapped:i.length?new _s(n,r,i,l):null,pos:o}}}class H{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new H(t,e,i,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:n=0,filterTo:r=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(ys)),this.isEmpty)return e.length?H.of(e):this;let l=new Ol(this,null,-1).goto(0),h=0,f=[],a=new Ve;for(;l.value||h<e.length;)if(h<e.length&&(l.from-e[h].from||l.startSide-e[h].value.startSide)>=0){let c=e[h++];a.addInner(c.from,c.to,c.value)||f.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==e.length||this.chunkEnd(l.chunkIndex)<e[h].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&a.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))&&(a.addInner(l.from,l.to,l.value)||f.push(ms.create(l.from,l.to,l.value))),l.next());return a.finishInner(this.nextLayer.isEmpty&&!f.length?H.empty:this.nextLayer.update({add:f,filter:o,filterFrom:n,filterTo:r}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],h=this.chunk[o],f=t.touchesRange(l,l+h.length);if(f===!1)n=Math.max(n,h.maxPoint),e.push(h),i.push(t.mapPos(l));else if(f===!0){let{mapped:a,pos:c}=h.map(l,t);a&&(n=Math.max(n,a.maxPoint),e.push(a),i.push(c))}}let r=this.nextLayer.map(t);return e.length==0?r:new H(i,e,r||H.empty,n)}between(t,e,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(e>=r&&t<=r+o.length&&o.between(r,t-r,e-r,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return di.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return di.from(t).goto(e)}static compare(t,e,i,n,r=-1){let o=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),l=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),h=Rr(o,l,i),f=new Je(o,h,r),a=new Je(l,h,r);i.iterGaps((c,u,d)=>Er(f,c,a,u,d,n)),i.empty&&i.length==0&&Er(f,0,a,0,0,n)}static eq(t,e,i=0,n){n==null&&(n=999999999);let r=t.filter(a=>!a.isEmpty&&e.indexOf(a)<0),o=e.filter(a=>!a.isEmpty&&t.indexOf(a)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Rr(r,o),h=new Je(r,l,0).goto(i),f=new Je(o,l,0).goto(i);for(;;){if(h.to!=f.to||!bs(h.active,f.active)||h.point&&(!f.point||!h.point.eq(f.point)))return!1;if(h.to>n)return!0;h.next(),f.next()}}static spans(t,e,i,n,r=-1){let o=new Je(t,null,r).goto(e),l=e,h=o.openStart;for(;;){let f=Math.min(o.to,i);if(o.point){let a=o.activeForPoint(o.to),c=o.pointFrom<e?a.length+1:o.point.startSide<0?a.length:Math.min(a.length,h);n.point(l,f,o.point,a,c,o.pointRank),h=Math.min(o.openEnd(f),a.length)}else f>l&&(n.span(l,f,o.active,h),h=o.openEnd(f));if(o.to>i)return h+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(t,e=!1){let i=new Ve;for(let n of t instanceof ms?[t]:e?Ya(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return H.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=H.empty;n=n.nextLayer)e=new H(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}H.empty=new H([],[],null,-1);function Ya(s){if(s.length>1)for(let t=s[0],e=1;e<s.length;e++){let i=s[e];if(ys(t,i)>0)return s.slice().sort(ys);t=i}return s}H.empty.nextLayer=H.empty;class Ve{finishChunk(t){this.chunks.push(new _s(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new Ve)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-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=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(H.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=H.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Rr(s,t,e){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 t)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(e?e.mapPos(l):l)==r.chunkPos[o]&&!(e!=null&&e.touchesRange(l,l+r.chunk[o].length))&&n.add(r.chunk[o])}return n}class Ol{constructor(t,e,i,n=0){this.layer=t,this.skip=e,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(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<t||n.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class di{constructor(t){this.heap=t}static from(t,e=null,i=-1){let n=[];for(let r=0;r<t.length;r++)for(let o=t[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new Ol(o,e,i,r));return n.length==1?n[0]:new di(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)qn(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)qn(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),qn(this.heap,0)}}}function qn(s,t){for(let e=s[t];;){let i=(t<<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++),e.compare(n)<0)break;s[i]=e,s[t]=n,t=i}}class Je{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=di.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Pi(this.active,t),Pi(this.activeTo,t),Pi(this.activeRank,t),this.minActive=Lr(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:r}=this.cursor;for(;e<this.activeRank.length&&(r-this.activeRank[e]||n-this.activeTo[e])>0;)e++;Di(this.active,e,i),Di(this.activeTo,e,n),Di(this.activeRank,e,r),t&&Di(t,e,this.cursor.from),this.minActive=Lr(this.active,this.activeTo)}next(){let t=this.to,e=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]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Pi(i,n)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let n=i.length-1;n>=0&&i[n]<t;n--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function Er(s,t,e,i,n,r){s.goto(t),e.goto(i);let o=i+n,l=i,h=i-t;for(;;){let f=s.to+h-e.to,a=f||s.endSide-e.endSide,c=a<0?s.to+h:e.to,u=Math.min(c,o);if(s.point||e.point?s.point&&e.point&&(s.point==e.point||s.point.eq(e.point))&&bs(s.activeForPoint(s.to),e.activeForPoint(e.to))||r.comparePoint(l,u,s.point,e.point):u>l&&!bs(s.active,e.active)&&r.compareRange(l,u,s.active,e.active),c>o)break;(f||s.openEnd!=e.openEnd)&&r.boundChange&&r.boundChange(c),l=c,a<=0&&s.next(),a>=0&&e.next()}}function bs(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++)if(s[e]!=t[e]&&!s[e].eq(t[e]))return!1;return!0}function Pi(s,t){for(let e=t,i=s.length-1;e<i;e++)s[e]=s[e+1];s.pop()}function Di(s,t,e){for(let i=s.length-1;i>=t;i--)s[i+1]=s[i];s[t]=e}function Lr(s,t){let e=-1,i=1e9;for(let n=0;n<t.length;n++)(t[n]-i||s[n].endSide-s[e].endSide)<0&&(e=n,i=t[n]);return e}function Dn(s,t,e=s.length){let i=0;for(let n=0;n<e&&n<s.length;)s.charCodeAt(n)==9?(i+=t-i%t,n++):(i++,n=ht(s,n));return i}function Ga(s,t,e,i){for(let n=0,r=0;;){if(r>=t)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?e-r%e:1,n=ht(s,n)}return s.length}const ws="ͼ",Ir=typeof Symbol>"u"?"__"+ws:Symbol.for(ws),xs=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Nr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class fe{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,h,f){let a=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return h.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(n(d),p,a,u)}else p!=null&&a.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(a.length||u)&&h.push((i&&!c&&!f?o.map(i):o).join(", ")+" {"+a.join(" ")+"}")}for(let o in t)r(n(o),t[o],this.rules)}getRules(){return this.rules.join(`
6
- `)}static newName(){let t=Nr[Ir]||1;return Nr[Ir]=t+1,ws+t.toString(36)}static mount(t,e,i){let n=t[xs],r=i&&i.nonce;n?r&&n.setNonce(r):n=new Xa(t,r),n.mount(Array.isArray(e)?e:[e],t)}}let Fr=new Map;class Xa{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let r=Fr.get(i);if(r)return t[xs]=r;this.sheet=new n.CSSStyleSheet,Fr.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[xs]=this}mount(t,e){let i=this.sheet,n=0,r=0;for(let o=0;o<t.length;o++){let l=t[o],h=this.modules.indexOf(l);if(h<r&&h>-1&&(this.modules.splice(h,1),r--,h=-1),h==-1){if(this.modules.splice(r++,0,l),i)for(let f=0;f<l.rules.length;f++)i.insertRule(l.rules[f],n++)}else{for(;r<h;)n+=this.modules[r++].rules.length;n+=l.rules.length,r++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let o="";for(let h=0;h<this.modules.length;h++)o+=this.modules[h].getRules()+`
7
- `;this.styleTag.textContent=o;let l=e.head||e;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}var ce={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:"'"},pi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},_a=typeof navigator<"u"&&/Mac/.test(navigator.platform),Ja=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var it=0;it<10;it++)ce[48+it]=ce[96+it]=String(it);for(var it=1;it<=24;it++)ce[it+111]="F"+it;for(var it=65;it<=90;it++)ce[it]=String.fromCharCode(it+32),pi[it]=String.fromCharCode(it);for(var Un in ce)pi.hasOwnProperty(Un)||(pi[Un]=ce[Un]);function Za(s){var t=_a&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||Ja&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",e=!t&&s.key||(s.shiftKey?pi:ce)[s.keyCode]||s.key||"Unidentified";return e=="Esc"&&(e="Escape"),e=="Del"&&(e="Delete"),e=="Left"&&(e="ArrowLeft"),e=="Up"&&(e="ArrowUp"),e=="Right"&&(e="ArrowRight"),e=="Down"&&(e="ArrowDown"),e}function gi(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function ks(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function Ji(s,t){if(!t.anchorNode)return!1;try{return ks(s,t.anchorNode)}catch{return!1}}function mi(s){return s.nodeType==3?Ae(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function ai(s,t,e,i){return e?Vr(s,t,e,i,-1)||Vr(s,t,e,i,1):!1}function Oe(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function ln(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Vr(s,t,e,i,n){for(;;){if(s==e&&t==i)return!0;if(t==(n<0?0:Qt(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;t=Oe(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[t+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;t=n<0?Qt(s):0}else return!1}}function Qt(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function Bn(s,t){let e=t?s.left:s.right;return{left:e,right:e,top:s.top,bottom:s.bottom}}function tf(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function Al(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function ef(s,t,e,i,n,r,o,l){let h=s.ownerDocument,f=h.defaultView||window;for(let a=s,c=!1;a&&!c;)if(a.nodeType==1){let u,d=a==h.body,p=1,g=1;if(d)u=tf(f);else{if(/^(fixed|sticky)$/.test(getComputedStyle(a).position)&&(c=!0),a.scrollHeight<=a.clientHeight&&a.scrollWidth<=a.clientWidth){a=a.assignedSlot||a.parentNode;continue}let w=a.getBoundingClientRect();({scaleX:p,scaleY:g}=Al(a,w)),u={left:w.left,right:w.left+a.clientWidth*p,top:w.top,bottom:w.top+a.clientHeight*g}}let m=0,y=0;if(n=="nearest")t.top<u.top?(y=-(u.top-t.top+o),e>0&&t.bottom>u.bottom+y&&(y=t.bottom-u.bottom+y+o)):t.bottom>u.bottom&&(y=t.bottom-u.bottom+o,e<0&&t.top-y<u.top&&(y=-(u.top+y-t.top+o)));else{let w=t.bottom-t.top,x=u.bottom-u.top;y=(n=="center"&&w<=x?t.top+w/2-x/2:n=="start"||n=="center"&&e<0?t.top-o:t.bottom-x+o)-u.top}if(i=="nearest"?t.left<u.left?(m=-(u.left-t.left+r),e>0&&t.right>u.right+m&&(m=t.right-u.right+m+r)):t.right>u.right&&(m=t.right-u.right+r,e<0&&t.left<u.left+m&&(m=-(u.left+m-t.left+r))):m=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-r:t.right-(u.right-u.left)+r)-u.left,m||y)if(d)f.scrollBy(m,y);else{let w=0,x=0;if(y){let k=a.scrollTop;a.scrollTop+=y/g,x=(a.scrollTop-k)*g}if(m){let k=a.scrollLeft;a.scrollLeft+=m/p,w=(a.scrollLeft-k)*p}t={left:t.left-w,top:t.top-x,right:t.right-w,bottom:t.bottom-x},w&&Math.abs(w-m)<1&&(i="nearest"),x&&Math.abs(x-y)<1&&(n="nearest")}if(d)break;a=a.assignedSlot||a.parentNode}else if(a.nodeType==11)a=a.host;else break}function nf(s){let t=s.ownerDocument,e,i;for(let n=s.parentNode;n&&!(n==t.body||e&&i);)if(n.nodeType==1)!i&&n.scrollHeight>n.clientHeight&&(i=n),!e&&n.scrollWidth>n.clientWidth&&(e=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:e,y:i}}class sf{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?Qt(e):0),i,Math.min(t.focusOffset,i?Qt(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let Pe=null;function Ml(s){if(s.setActive)return s.setActive();if(Pe)return s.focus(Pe);let t=[];for(let e=s;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(s.focus(Pe==null?{get preventScroll(){return Pe={preventScroll:!0},!0}}:void 0),!Pe){Pe=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Hr;function Ae(s,t,e=t){let i=Hr||(Hr=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function Ee(s,t,e,i){let n={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function rf(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Tl(s){for(;s.attributes.length;)s.removeAttributeNode(s.attributes[0])}function of(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,Qt(e));;)if(i){if(e.nodeType!=1)return!1;let n=e.childNodes[i-1];n.contentEditable=="false"?i--:(e=n,i=Qt(e))}else{if(e==s)return!0;i=Oe(e),e=e.parentNode}}function Pl(s){return s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function Dl(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=Qt(e)}else if(e.parentNode&&!ln(e))i=Oe(e),e=e.parentNode;else return null}}function Bl(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!ln(e))i=Oe(e)+1,e=e.parentNode;else return null}}class ot{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new ot(t.parentNode,Oe(t),e)}static after(t,e){return new ot(t.parentNode,Oe(t)+1,e)}}const Js=[];class z{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,n=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=n?n.nextSibling:i.firstChild)){let l=z.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=n?n.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=zr(r);else i.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=zr(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let n=Qt(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;n==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?n=-1:n=1),t=r}n<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!z.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(t,e,i=0){let n=-1,r=-1,o=-1,l=-1;for(let h=0,f=i,a=i;h<this.children.length;h++){let c=this.children[h],u=f+c.length;if(f<t&&u>e)return c.domBoundsAround(t,e,f);if(u>=t&&n==-1&&(n=h,r=f),f>e&&c.dom.parentNode==this.dom){o=h,l=a;break}a=u,f=u+c.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(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=Js){this.markDirty();for(let n=t;n<e;n++){let r=this.children[n];r.parent==this&&i.indexOf(r)<0&&r.destroy()}i.length<250?this.children.splice(t,e-t,...i):this.children=[].concat(this.children.slice(0,t),i,this.children.slice(e));for(let n=0;n<i.length;n++)i[n].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new Rl(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,n,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}z.prototype.breakAfter=0;function zr(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}class Rl{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function El(s,t,e,i,n,r,o,l,h){let{children:f}=s,a=f.length?f[t]:null,c=r.length?r[r.length-1]:null,u=c?c.breakAfter:o;if(!(t==i&&a&&!o&&!u&&r.length<2&&a.merge(e,n,r.length?c:null,e==0,l,h))){if(i<f.length){let d=f[i];d&&(n<d.length||d.breakAfter&&(c!=null&&c.breakAfter))?(t==i&&(d=d.split(n),n=0),!u&&c&&d.merge(0,n,c,!0,0,h)?r[r.length-1]=d:((n||d.children.length&&!d.children[0].length)&&d.merge(0,n,null,!1,0,h),r.push(d))):d!=null&&d.breakAfter&&(c?c.breakAfter=1:o=1),i++}for(a&&(a.breakAfter=o,e>0&&(!o&&r.length&&a.merge(e,a.length,r[0],!1,l,0)?a.breakAfter=r.shift().breakAfter:(e<a.length||a.children.length&&a.children[a.children.length-1].length==0)&&a.merge(e,a.length,null,!1,l,0),t++));t<i&&r.length;)if(f[i-1].become(r[r.length-1]))i--,r.pop(),h=r.length?0:l;else if(f[t].become(r[0]))t++,r.shift(),l=r.length?0:h;else break;!r.length&&t&&i<f.length&&!f[t-1].breakAfter&&f[i].merge(0,0,f[t-1],!1,l,h)&&t--,(t<i||r.length)&&s.replaceChildren(t,i,r)}}function Ll(s,t,e,i,n,r){let o=s.childCursor(),{i:l,off:h}=o.findPos(e,1),{i:f,off:a}=o.findPos(t,-1),c=t-e;for(let u of i)c+=u.length;s.length+=c,El(s,f,a,l,h,i,0,n,r)}let ut=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},vs=typeof document<"u"?document:{documentElement:{style:{}}};const Ss=/Edge\/(\d+)/.exec(ut.userAgent),Il=/MSIE \d/.test(ut.userAgent),Cs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ut.userAgent),Rn=!!(Il||Cs||Ss),Wr=!Rn&&/gecko\/(\d+)/i.test(ut.userAgent),Kn=!Rn&&/Chrome\/(\d+)/.exec(ut.userAgent),lf="webkitFontSmoothing"in vs.documentElement.style,Nl=!Rn&&/Apple Computer/.test(ut.vendor),$r=Nl&&(/Mobile\/\w+/.test(ut.userAgent)||ut.maxTouchPoints>2);var O={mac:$r||/Mac/.test(ut.platform),windows:/Win/.test(ut.platform),linux:/Linux|X11/.test(ut.platform),ie:Rn,ie_version:Il?vs.documentMode||6:Cs?+Cs[1]:Ss?+Ss[1]:0,gecko:Wr,gecko_version:Wr?+(/Firefox\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,chrome:!!Kn,chrome_version:Kn?+Kn[1]:0,ios:$r,android:/Android\b/.test(ut.userAgent),safari:Nl,webkit_version:lf?+(/\bAppleWebKit\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,tabSize:vs.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const hf=256;class Dt extends z{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof Dt)||this.length-(e-t)+i.length>hf||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Dt(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new ot(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return af(this.dom,t,e)}}class Jt extends z{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let n of e)n.setParent(this)}setAttrs(t){if(Tl(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,r,o){return i&&(!(i instanceof Jt&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(Ll(this,t,e,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,n=-1,r=0;for(let l of this.children){let h=i+l.length;h>t&&e.push(i<t?l.split(t-i):l),n<0&&i>=t&&(n=r),i=h,r++}let o=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Jt(this.mark,e,o)}domAtPos(t){return Fl(this,t)}coordsAt(t,e){return Hl(this,t,e)}}function af(s,t,e){let i=s.nodeValue.length;t>i&&(t=i);let n=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?O.chrome||O.gecko||(t?(n--,o=1):r<i&&(r++,o=-1)):e<0?n--:r<i&&r++;let l=Ae(s,n,r).getClientRects();if(!l.length)return null;let h=l[(o?o<0:e>=0)?0:l.length-1];return O.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,f=>f.width)||h),o?Bn(h,o<0):h||null}class le extends z{static create(t,e,i){return new le(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=le.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,r,o){return i&&(!(i instanceof le)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof le&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return L.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,n=this.posAtStart;return i?i.slice(n,n+this.length):L.empty}domAtPos(t){return(this.length?t==0:this.side>0)?ot.before(this.dom):ot.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?n.length-1:0;r=n[l],!(t>0?l==0:l==n.length-1||r.top<r.bottom);l+=o?-1:1);return Bn(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 He extends z{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof He&&t.side==this.side}split(){return new He(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?ot.before(this.dom):ot.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return L.empty}get isHidden(){return!0}}Dt.prototype.children=le.prototype.children=He.prototype.children=Js;function Fl(s,t){let e=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(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=n;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=n;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new ot(e,0)}function Vl(s,t,e){let i,{children:n}=s;e>0&&t instanceof Jt&&n.length&&(i=n[n.length-1])instanceof Jt&&i.mark.eq(t.mark)?Vl(i,t.children[0],e-1):(n.push(t),t.setParent(s)),s.length+=t.length}function Hl(s,t,e){let i=null,n=-1,r=null,o=-1;function l(f,a){for(let c=0,u=0;c<f.children.length&&u<=a;c++){let d=f.children[c],p=u+d.length;p>=a&&(d.children.length?l(d,a-u):(!r||r.isHidden&&e>0)&&(p>a||u==p&&d.getSide()>0)?(r=d,o=a-u):(u<a||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,n=a-u)),u=p}}l(s,t);let h=(e<0?i:r)||i||r;return h?h.coordsAt(Math.max(0,h==i?n:o),e):ff(s)}function ff(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=mi(t);return e[e.length-1]||null}function Os(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}const qr=Object.create(null);function hn(s,t,e){if(s==t)return!0;s||(s=qr),t||(t=qr);let i=Object.keys(s),n=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=n.length-(e&&n.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(n.indexOf(r)==-1||s[r]!==t[r]))return!1;return!0}function As(s,t,e){let i=!1;if(t)for(let n in t)e&&n in e||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(i=!0,n=="style"?s.style.cssText=e[n]:s.setAttribute(n,e[n]));return i}function cf(s){let t=Object.create(null);for(let e=0;e<s.attributes.length;e++){let i=s.attributes[e];t[i.name]=i.value}return t}class ki{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var jt=(function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s})(jt||(jt={}));class N extends Ce{constructor(t,e,i,n){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(t){return new vi(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new ue(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,n;if(t.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=zl(t,e);i=(r?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new ue(t,i,n,e,t.widget||null,!0)}static line(t){return new Si(t)}static set(t,e=!1){return H.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}N.none=H.empty;class vi extends N{constructor(t){let{start:e,end:i}=zl(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof vi&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&hn(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}vi.prototype.point=!1;class Si extends N{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Si&&this.spec.class==t.spec.class&&hn(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Si.prototype.mapMode=nt.TrackBefore;Si.prototype.point=!0;class ue extends N{constructor(t,e,i,n,r,o){super(e,i,r,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?nt.TrackBefore:nt.TrackAfter:nt.TrackDel}get type(){return this.startSide!=this.endSide?jt.WidgetRange:this.startSide<=0?jt.WidgetBefore:jt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof ue&&uf(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}ue.prototype.point=!0;function zl(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function uf(s,t){return s==t||!!(s&&t&&s.compare(t))}function Ms(s,t,e,i=0){let n=e.length-1;n>=0&&e[n]+i>=s?e[n]=Math.max(e[n],t):e.push(s,t)}class Y extends z{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,r,o){if(i){if(!(i instanceof Y))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Ll(this,t,e,i?i.children.slice():[],r,o),!0}split(t){let e=new Y;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:n}=this.childPos(t);n&&(e.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++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){hn(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Vl(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Os(e,this.attrs||{})),i&&(this.attrs=Os({class:i},this.attrs||{}))}domAtPos(t){return Fl(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(Tl(this.dom),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0):(this.setDOM(document.createElement("div")),this.dom.className="cm-line",this.prevAttrs=this.attrs?null:void 0),this.prevAttrs!==void 0&&(As(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&z.get(n)instanceof Jt;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=z.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!O.ios||!this.children.some(r=>r instanceof Dt))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof Dt)||/[^ -~]/.test(i.text))return null;let n=mi(i.dom);if(n.length!=1)return null;t+=n[0].width,e=n[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=Hl(this,t,e);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(t){return t instanceof Y&&this.children.length==0&&t.children.length==0&&hn(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,n=0;i<t.children.length;i++){let r=t.children[i],o=n+r.length;if(o>=e){if(r instanceof Y)return r;if(o>e)break}n=o+r.breakAfter}return null}}class _t extends z{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,r,o){return i&&(!(i instanceof _t)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?ot.before(this.dom):ot.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new _t(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Js}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):L.empty}domBoundsAround(){return null}become(t){return t instanceof _t&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);return i||(this.widget instanceof Ts?null:Bn(this.dom.getBoundingClientRect(),this.length?t==0:e<=0))}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}}class Ts extends ki{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class fi{constructor(t,e,i,n){this.doc=t,this.pos=e,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=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof _t&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new Y),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Bi(new He(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof _t)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Bi(new Dt(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ue){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof ue)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new _t(i.widget||ze.block,l,i));else{let h=le.create(i.widget||ze.inline,l,l?0:i.startSide),f=this.atCursorPos&&!h.isEditable&&r<=n.length&&(t<e||i.startSide>0),a=!h.isEditable&&(t<e||r>n.length||i.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!f&&!h.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),f&&(c.append(Bi(new He(1),n),r),r=n.length+Math.max(0,r-n.length)),c.append(Bi(h,n),r),this.atCursorPos=a,this.pendingBuffer=a?t<e||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=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,n,r){let o=new fi(t,e,i,r);return o.openEnd=H.spans(n,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Bi(s,t){for(let e of t)s=new Jt(e,[s],s.length);return s}class ze extends ki{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}ze.inline=new ze("span");ze.block=new ze("div");var Q=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(Q||(Q={}));const Me=Q.LTR,Zs=Q.RTL;function Wl(s){let t=[];for(let e=0;e<s.length;e++)t.push(1<<+s[e]);return t}const df=Wl("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),pf=Wl("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ps=Object.create(null),Lt=[];for(let s of["()","[]","{}"]){let t=s.charCodeAt(0),e=s.charCodeAt(1);Ps[t]=e,Ps[e]=-t}function $l(s){return s<=247?df[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?pf[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const gf=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class he{get dir(){return this.level%2?Zs:Me}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,n){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function ql(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++){let i=s[e],n=t[e];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!ql(i.inner,n.inner))return!1}return!0}const V=[];function mf(s,t,e,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,h=r?256:n;for(let f=o,a=h,c=h;f<l;f++){let u=$l(s.charCodeAt(f));u==512?u=a:u==8&&c==4&&(u=16),V[f]=u==4?2:u,u&7&&(c=u),a=u}for(let f=o,a=h,c=h;f<l;f++){let u=V[f];if(u==128)f<l-1&&a==V[f+1]&&a&24?u=V[f]=a:V[f]=256;else if(u==64){let d=f+1;for(;d<l&&V[d]==64;)d++;let p=f&&a==8||d<e&&V[d]==8?c==1?1:8:256;for(let g=f;g<d;g++)V[g]=p;f=d-1}else u==8&&c==1&&(V[f]=1);a=u,u&7&&(c=u)}}}function yf(s,t,e,i,n){let r=n==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let f=o?i[o-1].to:t,a=o<i.length?i[o].from:e;for(let c=f,u,d,p;c<a;c++)if(d=Ps[u=s.charCodeAt(c)])if(d<0){for(let g=l-3;g>=0;g-=3)if(Lt[g+1]==-d){let m=Lt[g+2],y=m&2?n:m&4?m&1?r:n:0;y&&(V[c]=V[Lt[g]]=y),l=g;break}}else{if(Lt.length==189)break;Lt[l++]=c,Lt[l++]=u,Lt[l++]=h}else if((p=V[c])==2||p==1){let g=p==n;h=g?0:1;for(let m=l-3;m>=0;m-=3){let y=Lt[m+2];if(y&2)break;if(g)Lt[m+2]|=2;else{if(y&4)break;Lt[m+2]|=4}}}}}function bf(s,t,e,i){for(let n=0,r=i;n<=e.length;n++){let o=n?e[n-1].to:s,l=n<e.length?e[n].from:t;for(let h=o;h<l;){let f=V[h];if(f==256){let a=h+1;for(;;)if(a==l){if(n==e.length)break;a=e[n++].to,l=n<e.length?e[n].from:t}else if(V[a]==256)a++;else break;let c=r==1,u=(a<t?V[a]:i)==1,d=c==u?c?1:2:i;for(let p=a,g=n,m=g?e[g-1].to:s;p>h;)p==m&&(p=e[--g].from,m=g?e[g-1].to:s),V[--p]=d;h=a}else r=f,h++}}}function Ds(s,t,e,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let h=t,f=0;h<e;){let a=!0,c=!1;if(f==r.length||h<r[f].from){let g=V[h];g!=l&&(a=!1,c=g==16)}let u=!a&&l==1?[]:null,d=a?i:i+1,p=h;t:for(;;)if(f<r.length&&p==r[f].from){if(c)break t;let g=r[f];if(!a)for(let m=g.to,y=f+1;;){if(m==e)break t;if(y<r.length&&r[y].from==m)m=r[y++].to;else{if(V[m]==l)break t;break}}if(f++,u)u.push(g);else{g.from>h&&o.push(new he(h,g.from,d));let m=g.direction==Me!=!(d%2);Bs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==e||(a?V[p]!=l:V[p]==l))break;p++}u?Ds(s,h,p,i+1,n,u,o):h<p&&o.push(new he(h,p,d)),h=p}else for(let h=e,f=r.length;h>t;){let a=!0,c=!1;if(!f||h>r[f-1].to){let g=V[h-1];g!=l&&(a=!1,c=g==16)}let u=!a&&l==1?[]:null,d=a?i:i+1,p=h;t:for(;;)if(f&&p==r[f-1].to){if(c)break t;let g=r[--f];if(!a)for(let m=g.from,y=f;;){if(m==t)break t;if(y&&r[y-1].to==m)m=r[--y].from;else{if(V[m-1]==l)break t;break}}if(u)u.push(g);else{g.to<h&&o.push(new he(g.to,h,d));let m=g.direction==Me!=!(d%2);Bs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==t||(a?V[p-1]!=l:V[p-1]==l))break;p--}u?Ds(s,p,h,i+1,n,u,o):p<h&&o.push(new he(p,h,d)),h=p}}function Bs(s,t,e,i,n,r,o){let l=t%2?2:1;mf(s,n,r,i,l),yf(s,n,r,i,l),bf(n,r,i,l),Ds(s,n,r,t,e,i,o)}function wf(s,t,e){if(!s)return[new he(0,0,t==Zs?1:0)];if(t==Me&&!e.length&&!gf.test(s))return Ul(s.length);if(e.length)for(;s.length>V.length;)V[V.length]=256;let i=[],n=t==Me?0:1;return Bs(s,n,n,e,0,s.length,i),i}function Ul(s){return[new he(0,s,0)]}let Kl="";function xf(s,t,e,i,n){var r;let o=i.head-s.from,l=he.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),h=t[l],f=h.side(n,e);if(o==f){let u=l+=n?1:-1;if(u<0||u>=t.length)return null;h=t[l=u],o=h.side(!n,e),f=h.side(n,e)}let a=ht(s.text,o,h.forward(n,e));(a<h.from||a>h.to)&&(a=f),Kl=s.text.slice(Math.min(o,a),Math.max(o,a));let c=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];return c&&a==f&&c.level+(n?0:1)<h.level?b.cursor(c.side(!n,e)+s.from,c.forward(n,e)?1:-1,c.level):b.cursor(a+s.from,h.forward(n,e)?-1:1,h.level)}function kf(s,t,e){for(let i=t;i<e;i++){let n=$l(s.charCodeAt(i));if(n==1)return Me;if(n==2||n==4)return Zs}return Me}const jl=P.define(),Ql=P.define(),Yl=P.define(),Gl=P.define(),Rs=P.define(),Xl=P.define(),_l=P.define(),tr=P.define(),er=P.define(),Jl=P.define({combine:s=>s.some(t=>t)}),vf=P.define({combine:s=>s.some(t=>t)}),Zl=P.define();class Le{constructor(t,e="nearest",i="nearest",n=5,r=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new Le(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Le(b.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ri=R.define({map:(s,t)=>s.map(t)}),th=R.define();function at(s,t,e){let i=s.facet(Gl);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const se=P.define({combine:s=>s.length?s[0]:!0});let Sf=0;const ni=P.define();class At{constructor(t,e,i,n,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=e||{};return new At(Sf++,t,i,n,l=>{let h=[ni.of(l)];return o&&h.push(yi.of(f=>{let a=f.plugin(l);return a?o(a):N.none})),r&&h.push(r(l)),h})}static fromClass(t,e){return At.define(i=>new t(i),e)}}class jn{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(at(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){at(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){at(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const eh=P.define(),ir=P.define(),yi=P.define(),ih=P.define(),nr=P.define(),nh=P.define();function Ur(s,t){let e=s.state.facet(nh);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(s):r),n=[];return H.spans(i,t.from,t.to,{point(){},span(r,o,l,h){let f=r-t.from,a=o-t.from,c=n;for(let u=l.length-1;u>=0;u--,h--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=kf(t.text,f,a)),h>0&&c.length&&(p=c[c.length-1]).to==f&&p.direction==d)p.to=a,c=p.inner;else{let g={from:f,to:a,direction:d,inner:[]};c.push(g),c=g.inner}}}}),n}const sh=P.define();function rh(s){let t=0,e=0,i=0,n=0;for(let r of s.state.facet(sh)){let o=r(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:i,bottom:n}}const si=P.define();class Ct{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new Ct(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let n=0,r=0,o=0,l=0;;n++){let h=n==t.length?null:t[n],f=o-l,a=h?h.fromB:1e9;for(;r<e.length&&e[r]<a;){let c=e[r],u=e[r+1],d=Math.max(l,c),p=Math.min(a,u);if(d<=p&&new Ct(d+f,p+f,d,p).addToSet(i),u>a)break;r+=2}if(!h)return i;new Ct(h.fromA,h.toA,h.fromB,h.toB).addToSet(i),o=h.toA,l=h.toB}}}class an{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=_.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,h)=>n.push(new Ct(r,o,l,h))),this.changedRanges=n}static create(t,e,i){return new an(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class Kr extends z{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=N.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new Y],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ct(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:a})=>a<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!Df(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let r=n>-1?Of(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:f,to:a}=this.hasComposition;i=new Ct(f,a,t.changes.mapPos(f,-1),t.changes.mapPos(a,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(O.ie||O.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),h=Tf(o,l,t.changes);return i=Ct.extendWithRanges(i,h),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer: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=O.chrome||O.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 _t&&o.widget instanceof Ts&&r.push(o.dom);n.updateGaps(r)}updateChildren(t,e,i){let n=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let o=n.length-1;;o--){let l=o>=0?n[o]:null;if(!l)break;let{fromA:h,toA:f,fromB:a,toB:c}=l,u,d,p,g;if(i&&i.range.fromB<c&&i.range.toB>a){let k=fi.build(this.view.state.doc,a,i.range.fromB,this.decorations,this.dynamicDecorationMap),S=fi.build(this.view.state.doc,i.range.toB,c,this.decorations,this.dynamicDecorationMap);d=k.breakAtStart,p=k.openStart,g=S.openEnd;let A=this.compositionView(i);S.breakAtStart?A.breakAfter=1:S.content.length&&A.merge(A.length,A.length,S.content[0],!1,S.openStart,0)&&(A.breakAfter=S.content[0].breakAfter,S.content.shift()),k.content.length&&A.merge(0,0,k.content[k.content.length-1],!0,0,k.openEnd)&&k.content.pop(),u=k.content.concat(A).concat(S.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=fi.build(this.view.state.doc,a,c,this.decorations,this.dynamicDecorationMap));let{i:m,off:y}=r.findPos(f,1),{i:w,off:x}=r.findPos(h,-1);El(this,w,x,m,y,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(th)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new Dt(t.text.nodeValue);e.flags|=8;for(let{deco:n}of t.marks)e=new Jt(n,[e],e.length);let i=new Y;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8|(o.children.some(h=>h.flags&7)?1:0),this.markedForComposition.add(o);let l=z.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let r=t.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],e(r>=0?t.marks[r].node:t.text,n)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&Ji(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,h=this.moveToLine(this.domAtPos(l.anchor)),f=l.empty?h:this.moveToLine(this.domAtPos(l.head));if(O.gecko&&l.empty&&!this.hasComposition&&Cf(h)){let c=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(c,h.node.childNodes[h.offset]||null)),h=f=new ot(c,0),o=!0}let a=this.view.observer.selectionRange;(o||!a.focusNode||(!ai(h.node,h.offset,a.anchorNode,a.anchorOffset)||!ai(f.node,f.offset,a.focusNode,a.focusOffset))&&!this.suppressWidgetCursorChange(a,l))&&(this.view.observer.ignore(()=>{O.android&&O.chrome&&this.dom.contains(a.focusNode)&&Pf(a.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let c=gi(this.view.root);if(c)if(l.empty){if(O.gecko){let u=Af(h.node,h.offset);if(u&&u!=3){let d=(u==1?Dl:Bl)(h.node,h.offset);d&&(h=new ot(d.node,d.offset))}}c.collapse(h.node,h.offset),l.bidiLevel!=null&&c.caretBidiLevel!==void 0&&(c.caretBidiLevel=l.bidiLevel)}else if(c.extend){c.collapse(h.node,h.offset);try{c.extend(f.node,f.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([h,f]=[f,h]),u.setEnd(f.node,f.offset),u.setStart(h.node,h.offset),c.removeAllRanges(),c.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(h,f)),this.impreciseAnchor=h.precise?null:new ot(a.anchorNode,a.anchorOffset),this.impreciseHead=f.precise?null:new ot(a.focusNode,a.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&ai(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=gi(t.root),{anchorNode:n,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=Y.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let h=this.coordsAt(e.head,-1),f=this.coordsAt(e.head,1);if(!h||!f||h.bottom>f.top)return;let a=this.domAtPos(e.head+e.assoc);i.collapse(a.node,a.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let n=t.offset;!i&&n<e.childNodes.length;n++){let r=z.get(e.childNodes[n]);r instanceof Y&&(i=r.domAtPos(0))}for(let n=t.offset-1;!i&&n>=0;n--){let r=z.get(e.childNodes[n]);r instanceof Y&&(i=r.domAtPos(r.length))}return i?new ot(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=z.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let n=this.children[e];if(i<n.length||n instanceof Y)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,n=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],h=r-l.breakAfter,f=h-l.length;if(h<t)break;if(f<=t&&(f<t||l.covers(-1))&&(h>t||l.covers(1))&&(!i||l instanceof Y&&!(i instanceof Y&&e>=0)))i=l,n=f;else if(i&&f==t&&h==t&&l instanceof _t&&Math.abs(e)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=f}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof Y))return null;for(;n.children.length;){let{i:l,off:h}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=h}if(!(n instanceof Dt))return null;let r=ht(n.text,i);if(r==i)return null;let o=Ae(n.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let h=o[l];if(l==o.length-1||h.top<h.bottom&&h.left<h.right)return h}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:n}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==Q.LTR;for(let f=0,a=0;a<this.children.length;a++){let c=this.children[a],u=f+c.length;if(u>n)break;if(f>=i){let d=c.dom.getBoundingClientRect();if(e.push(d.height),o){let p=c.dom.lastChild,g=p?mi(p):[];if(g.length){let m=g[g.length-1],y=h?m.right-d.left:d.right-m.left;y>l&&(l=y,this.minWidth=r,this.minWidthFrom=f,this.minWidthTo=u)}}}f=u+c.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?Q.RTL:Q.LTR}measureTextSize(){for(let r of this.children)if(r instanceof Y){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,n;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let r=mi(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new Rl(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let r=n==e.viewports.length?null:e.viewports[n],o=r?r.from-1:this.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(N.replace({widget:new Ts(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return N.set(t)}updateDeco(){let t=1,e=this.view.state.facet(yi).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(ih).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(H.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let f=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=f.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let f of this.view.state.facet(Zl))try{if(f(this.view,t.range,t))return!0}catch(a){at(this.view.state,a,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),n;if(!i)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.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=rh(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:h}=this.view.scrollDOM;ef(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,h),-h),this.view.textDirection==Q.LTR)}}function Cf(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")}function oh(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=Dl(e.focusNode,e.focusOffset),n=Bl(e.focusNode,e.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=z.get(n.node);if(!l||l instanceof Dt&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let h=z.get(i.node);!h||h instanceof Dt&&h.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Of(s,t,e){let i=oh(s,e);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 h=t.invertedDesc,f=new Ct(h.mapPos(r),h.mapPos(o),r,o),a=[];for(let c=n.parentNode;;c=c.parentNode){let u=z.get(c);if(u instanceof Jt)a.push({node:c,deco:u.mark});else{if(u instanceof Y||c.nodeName=="DIV"&&c.parentNode==s.contentDOM)return{range:f,text:n,marks:a,line:c};if(c!=s.contentDOM)a.push({node:c,deco:new vi({inclusive:!0,attributes:cf(c),tagName:c.tagName.toLowerCase()})});else return null}}}function Af(s,t){return s.nodeType!=1?0:(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t<s.childNodes.length&&s.childNodes[t].contentEditable=="false"?2:0)}let Mf=class{constructor(){this.changes=[]}compareRange(t,e){Ms(t,e,this.changes)}comparePoint(t,e){Ms(t,e,this.changes)}};function Tf(s,t,e){let i=new Mf;return H.compare(s,t,e,i),i.changes}function Pf(s,t){for(let e=s;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Df(s,t){let e=!1;return t&&s.iterChangedRanges((i,n)=>{i<t.to&&n>t.from&&(e=!0)}),e}function Bf(s,t,e=1){let i=s.charCategorizer(t),n=s.doc.lineAt(t),r=t-n.from;if(n.length==0)return b.cursor(t);r==0?e=1:r==n.length&&(e=-1);let o=r,l=r;e<0?o=ht(n.text,r,!1):l=ht(n.text,r);let h=i(n.text.slice(o,l));for(;o>0;){let f=ht(n.text,o,!1);if(i(n.text.slice(f,o))!=h)break;o=f}for(;l<n.length;){let f=ht(n.text,l);if(i(n.text.slice(l,f))!=h)break;l=f}return b.range(o+n.from,l+n.from)}function Rf(s,t){return t.left>s?t.left-s:Math.max(0,s-t.right)}function Ef(s,t){return t.top>s?t.top-s:Math.max(0,s-t.bottom)}function Qn(s,t){return s.top<t.bottom-1&&s.bottom>t.top+1}function jr(s,t){return t<s.top?{top:t,left:s.left,right:s.right,bottom:s.bottom}:s}function Qr(s,t){return t>s.bottom?{top:s.top,left:s.left,right:s.right,bottom:t}:s}function Es(s,t,e){let i,n,r,o,l=!1,h,f,a,c;for(let p=s.firstChild;p;p=p.nextSibling){let g=mi(p);for(let m=0;m<g.length;m++){let y=g[m];n&&Qn(n,y)&&(y=jr(Qr(y,n.bottom),n.top));let w=Rf(t,y),x=Ef(e,y);if(w==0&&x==0)return p.nodeType==3?Yr(p,t,e):Es(p,t,e);if(!i||o>x||o==x&&r>w){i=p,n=y,r=w,o=x;let k=x?e<y.top?-1:1:w?t<y.left?-1:1:0;l=!k||(k>0?m<g.length-1:m>0)}w==0?e>y.bottom&&(!a||a.bottom<y.bottom)?(h=p,a=y):e<y.top&&(!c||c.top>y.top)&&(f=p,c=y):a&&Qn(a,y)?a=Qr(a,y.bottom):c&&Qn(c,y)&&(c=jr(c,y.top))}}if(a&&a.bottom>=e?(i=h,n=a):c&&c.top<=e&&(i=f,n=c),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,t));if(i.nodeType==3)return Yr(i,u,e);if(l&&i.contentEditable!="false")return Es(i,u,e);let d=Array.prototype.indexOf.call(s.childNodes,i)+(t>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function Yr(s,t,e){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;l<i;l++){let h=Ae(s,l,l+1).getClientRects();for(let f=0;f<h.length;f++){let a=h[f];if(a.top==a.bottom)continue;o||(o=t-a.left);let c=(a.top>e?a.top-e:e-a.bottom)-1;if(a.left-1<=t&&a.right+1>=t&&c<r){let u=t>=(a.left+a.right)/2,d=u;if((O.chrome||O.gecko)&&Ae(s,l).getBoundingClientRect().left==a.right&&(d=!u),c<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=c}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function lh(s,t,e,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,h,{docHeight:f}=s.viewState,{x:a,y:c}=t,u=c-l;if(u<0)return 0;if(u>f)return s.state.doc.length;for(let k=s.viewState.heightOracle.textHeight/2,S=!1;h=s.elementAtHeight(u),h.type!=jt.Text;)for(;u=i>0?h.bottom+k:h.top-k,!(u>=0&&u<=f);){if(S)return e?null:0;S=!0,i=-i}c=l+u;let d=h.from;if(d<s.viewport.from)return s.viewport.from==0?0:e?null:Gr(s,o,h,a,c);if(d>s.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:e?null:Gr(s,o,h,a,c);let p=s.dom.ownerDocument,g=s.root.elementFromPoint?s.root:p,m=g.elementFromPoint(a,c);m&&!s.contentDOM.contains(m)&&(m=null),m||(a=Math.max(o.left+1,Math.min(o.right-1,a)),m=g.elementFromPoint(a,c),m&&!s.contentDOM.contains(m)&&(m=null));let y,w=-1;if(m&&((n=s.docView.nearest(m))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let k=p.caretPositionFromPoint(a,c);k&&({offsetNode:y,offset:w}=k)}else if(p.caretRangeFromPoint){let k=p.caretRangeFromPoint(a,c);k&&({startContainer:y,startOffset:w}=k,(!s.contentDOM.contains(y)||O.safari&&Lf(y,w,a)||O.chrome&&If(y,w,a))&&(y=void 0))}y&&(w=Math.min(Qt(y),w))}if(!y||!s.docView.dom.contains(y)){let k=Y.find(s.docView,d);if(!k)return u>h.top+h.height/2?h.to:h.from;({node:y,offset:w}=Es(k.dom,a,c))}let x=s.docView.nearest(y);if(!x)return null;if(x.isWidget&&((r=x.dom)===null||r===void 0?void 0:r.nodeType)==1){let k=x.dom.getBoundingClientRect();return t.y<k.top||t.y<=k.bottom&&t.x<=(k.left+k.right)/2?x.posAtStart:x.posAtEnd}else return x.localPosFromDOM(y,w)+x.posAtStart}function Gr(s,t,e,i,n){let r=Math.round((i-t.left)*s.defaultCharacterWidth);if(s.lineWrapping&&e.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,h=Math.floor((n-e.top-(s.defaultLineHeight-l)*.5)/l);r+=h*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+Ga(o,r,s.state.tabSize)}function Lf(s,t,e){let i;if(s.nodeType!=3||t!=(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 Ae(s,i-1,i).getBoundingClientRect().left>e}function If(s,t,e){if(t!=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():Ae(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function Nf(s,t){let e=s.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==jt.Text))return i}return e}function Ff(s,t,e,i){let n=Nf(s,t.head),r=!i||n.type!=jt.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),h=s.posAtCoords({x:e==(l==Q.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(h!=null)return b.cursor(h,e?-1:1)}return b.cursor(e?n.to:n.from,e?-1:1)}function Xr(s,t,e,i){let n=s.state.doc.lineAt(t.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=t,h=null;;){let f=xf(n,r,o,l,e),a=Kl;if(!f){if(n.number==(e?s.state.doc.lines:1))return l;a=`
8
- `,n=s.state.doc.line(n.number+(e?1:-1)),r=s.bidiSpans(n),f=s.visualLineSide(n,!e)}if(h){if(!h(a))return l}else{if(!i)return f;h=i(a)}l=f}}function Vf(s,t,e){let i=s.state.charCategorizer(t),n=i(e);return r=>{let o=i(r);return n==kt.Space&&(n=o),n==o}}function Hf(s,t,e,i){let n=t.head,r=e?1:-1;if(n==(e?s.state.doc.length:0))return b.cursor(n,t.assoc);let o=t.goalColumn,l,h=s.contentDOM.getBoundingClientRect(),f=s.coordsAtPos(n,t.assoc||-1),a=s.documentTop;if(f)o==null&&(o=f.left-h.left),l=r<0?f.top:f.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(h.right-h.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+a}let c=h.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=lh(s,{x:c,y:p},!1,r);if(p<h.top||p>h.bottom||(r<0?g<n:g>n)){let m=s.docView.coordsForChar(g),y=!m||p<m.top?-1:1;return b.cursor(g,y,void 0,o)}}}function Zi(s,t,e){for(;;){let i=0;for(let n of s)n.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let h=i||e||(t-r<o-t?-1:1);t=h<0?r:o,i=h}});if(!i)return t}}function Yn(s,t,e){let i=Zi(s.state.facet(nr).map(n=>n(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:b.cursor(i,i<e.from?1:-1)}const ri="￿";class zf{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(F.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=ri}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==e)break;let l=z.get(n),h=z.get(o);(l&&h?l.breakAfter:(l?l.breakAfter:ln(n))||ln(o)&&(n.nodeName!="BR"||n.cmIgnore)&&this.text.length>r)&&this.lineBreak(),n=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==t&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=z.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(Wf(t,i.node,i.offset)?e:0))}}function Wf(s,t,e){for(;;){if(!t||e<Qt(t))return!1;if(t==s)return!0;e=Oe(t)+1,t=t.parentNode}}class _r{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class $f{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:Kf(t),h=new zf(l,t.state);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=jf(l,this.bounds.from)}else{let l=t.observer.selectionRange,h=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!ks(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),f=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!ks(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),a=t.viewport;if((O.ios||O.chrome)&&t.state.selection.main.empty&&h!=f&&(a.from>0||a.to<t.state.doc.length)){let c=Math.min(h,f),u=Math.max(h,f),d=a.from-c,p=a.to-u;(d==0||d==1||c==0)&&(p==0||p==-1||u==t.state.doc.length)&&(h=0,f=t.state.doc.length)}this.newSel=b.single(f,h)}}}function hh(s,t){let e,{newSel:i}=t,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,h=n.from,f=null;(r===8||O.android&&t.text.length<l-o)&&(h=n.to,f="end");let a=Uf(s.state.doc.sliceString(o,l,ri),t.text,h-o,f);a&&(O.chrome&&r==13&&a.toB==a.from+2&&t.text.slice(a.from,a.toB)==ri+ri&&a.toB--,e={from:o+a.from,to:o+a.toA,insert:L.of(t.text.slice(a.from,a.toB).split(ri))})}else i&&(!s.hasFocus&&s.state.facet(se)||i.main.eq(n))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!n.empty&&i&&i.main.empty?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,n.to)}:e&&e.from>=n.from&&e.to<=n.to&&(e.from!=n.from||e.to!=n.to)&&n.to-n.from-(e.to-e.from)<=4?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,e.from).append(e.insert).append(s.state.doc.slice(e.to,n.to))}:(O.mac||O.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=b.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:L.of([" "])}):O.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`
9
- `&&s.lineWrapping&&(i&&(i=b.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:L.of([" "])}),e)return sr(s,e,i,r);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 sr(s,t,e,i=-1){if(O.ios&&s.inputState.flushIOSKey(t))return!0;let n=s.state.selection.main;if(O.android&&(t.to==n.to&&(t.from==n.from||t.from==n.from-1&&s.state.sliceDoc(t.from,n.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Ee(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>n.head)&&Ee(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Ee(s.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=qf(s,t,e));return s.state.facet(Xl).some(h=>h(s,t.from,t.to,r,l))||s.dispatch(l()),!0}function qf(s,t,e){let i,n=s.state,r=n.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&s.inputState.composing<0){let l=r.from<t.from?n.sliceDoc(r.from,t.from):"",h=r.to>t.to?n.sliceDoc(t.to,r.to):"";i=n.replaceSelection(s.state.toText(l+t.insert.sliceString(0,void 0,s.state.lineBreak)+h))}else{let l=n.changes(t),h=e&&e.main.to<=l.newLength?e.main:void 0;if(n.selection.ranges.length>1&&s.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let f=s.state.sliceDoc(t.from,t.to),a,c=e&&oh(s,e.main.head);if(c){let p=t.insert.length-(t.to-t.from);a={from:c.from,to:c.to-p}}else a=s.state.doc.lineAt(r.head);let u=r.to-t.to,d=r.to-r.from;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:h||p.map(l)};let g=p.to-u,m=g-f.length;if(p.to-p.from!=d||s.state.sliceDoc(m,g)!=f||p.to>=a.from&&p.from<=a.to)return{range:p};let y=n.changes({from:m,to:g,insert:t.insert}),w=p.to-r.to;return{changes:y,range:h?b.range(Math.max(0,h.anchor+w),Math.max(0,h.head+w)):p.map(y)}})}else i={changes:l,selection:h&&n.selection.replaceRange(h)}}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 Uf(s,t,e,i){let n=Math.min(s.length,t.length),r=0;for(;r<n&&s.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==n&&s.length==t.length)return null;let o=s.length,l=t.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,r-Math.min(o,l));e-=o+h-r}if(o<r&&s.length<t.length){let h=e<=r&&e>=o?r-e:0;r-=h,l=r+(l-o),o=r}else if(l<r){let h=e<=r&&e>=l?r-e:0;r-=h,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function Kf(s){let t=[];if(s.root.activeElement!=s.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return e&&(t.push(new _r(e,i)),(n!=e||r!=i)&&t.push(new _r(n,r))),t}function jf(s,t){if(s.length==0)return null;let e=s[0].pos,i=s.length==2?s[1].pos:e;return e>-1&&i>-1?b.single(e+t,i+t):null}class Qf{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,O.safari&&t.contentDOM.addEventListener("input",()=>null),O.gecko&&ac(t.contentDOM.ownerDocument)}handleEvent(t){!ec(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let n of i.observers)n(this.view,e);for(let n of i.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Yf(t),i=this.handlers,n=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&fh.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),O.android&&O.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return O.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=ah.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||Gf.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,Ee(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:O.safari&&!O.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Jr(s,t){return(e,i)=>{try{return t.call(s,i,e)}catch(n){at(e.state,n)}}}function Yf(s){let t=Object.create(null);function e(i){return t[i]||(t[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&&e(r).handlers.push(Jr(i.value,o))}if(n&&n.domEventObservers)for(let r in n.domEventObservers){let o=n.domEventObservers[r];o&&e(r).observers.push(Jr(i.value,o))}}for(let i in Bt)e(i).handlers.push(Bt[i]);for(let i in Mt)e(i).observers.push(Mt[i]);return t}const ah=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Gf="dthko",fh=[16,17,18,20,91,92,224,225],Ei=6;function Li(s){return Math.max(0,s)*.7+8}function Xf(s,t){return Math.max(Math.abs(s.clientX-t.clientX),Math.abs(s.clientY-t.clientY))}class _f{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=nf(t.contentDOM),this.atoms=t.state.facet(nr).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(F.allowMultipleSelections)&&Jf(t,e),this.dragging=tc(t,e)&&dh(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Xf(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=rh(this.view);t.clientX-h.left<=n+Ei?e=-Li(n-t.clientX):t.clientX+h.right>=o-Ei&&(e=Li(t.clientX-o)),t.clientY-h.top<=r+Ei?i=-Li(r-t.clientY):t.clientY+h.bottom>=l-Ei&&(i=Li(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let n=t.ranges[i],r=null;if(n.empty){let o=Zi(this.atoms,n.from,0);o!=n.from&&(r=b.cursor(o,-1))}else{let o=Zi(this.atoms,n.from,-1),l=Zi(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&&(e||(e=t.ranges.slice()),e[i]=r)}return e?b.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Jf(s,t){let e=s.state.facet(jl);return e.length?e[0](t):O.mac?t.metaKey:t.ctrlKey}function Zf(s,t){let e=s.state.facet(Ql);return e.length?e[0](t):O.mac?!t.altKey:!t.ctrlKey}function tc(s,t){let{main:e}=s.state.selection;if(e.empty)return!1;let i=gi(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<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function ec(s,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=s.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=z.get(e))&&i.ignoreEvent(t))return!1;return!0}const Bt=Object.create(null),Mt=Object.create(null),ch=O.ie&&O.ie_version<15||O.ios&&O.webkit_version<604;function ic(s){let t=s.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{s.focus(),e.remove(),uh(s,e.value)},50)}function En(s,t,e){for(let i of s.facet(t))e=i(e,s);return e}function uh(s,t){t=En(s.state,tr,t);let{state:e}=s,i,n=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(Ls!=null&&e.selection.ranges.every(h=>h.empty)&&Ls==r.toString()){let h=-1;i=e.changeByRange(f=>{let a=e.doc.lineAt(f.from);if(a.from==h)return{range:f};h=a.from;let c=e.toText((o?r.line(n++).text:t)+e.lineBreak);return{changes:{from:a.from,insert:c},range:b.cursor(f.from+c.length)}})}else o?i=e.changeByRange(h=>{let f=r.line(n++);return{changes:{from:h.from,to:h.to,insert:f.text},range:b.cursor(h.from+f.length)}}):i=e.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Mt.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};Bt.keydown=(s,t)=>(s.inputState.setSelectionOrigin("select"),t.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);Mt.touchstart=(s,t)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Mt.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Bt.mousedown=(s,t)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of s.state.facet(Yl))if(e=i(s,t),e)break;if(!e&&t.button==0&&(e=rc(s,t)),e){let i=!s.hasFocus;s.inputState.startMouseSelection(new _f(s,t,e,i)),i&&s.observer.ignore(()=>{Ml(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}return!1};function Zr(s,t,e,i){if(i==1)return b.cursor(t,e);if(i==2)return Bf(s.state,t,e);{let n=Y.find(s.docView,t),r=s.state.doc.lineAt(n?n.posAtEnd:t),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 to=(s,t,e)=>t>=e.top&&t<=e.bottom&&s>=e.left&&s<=e.right;function nc(s,t,e,i){let n=Y.find(s.docView,t);if(!n)return 1;let r=t-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&to(e,i,o))return-1;let l=n.coordsAt(r,1);return l&&to(e,i,l)?1:o&&o.bottom>=i?-1:1}function eo(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:nc(s,e,t.clientX,t.clientY)}}const sc=O.ie&&O.ie_version<=11;let io=null,no=0,so=0;function dh(s){if(!sc)return s.detail;let t=io,e=so;return io=s,so=Date.now(),no=!t||e>Date.now()-400&&Math.abs(t.clientX-s.clientX)<2&&Math.abs(t.clientY-s.clientY)<2?(no+1)%3:1}function rc(s,t){let e=eo(s,t),i=dh(t),n=s.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),n=n.map(r.changes))},get(r,o,l){let h=eo(s,r),f,a=Zr(s,h.pos,h.bias,i);if(e.pos!=h.pos&&!o){let c=Zr(s,e.pos,e.bias,i),u=Math.min(c.from,a.from),d=Math.max(c.to,a.to);a=u<a.from?b.range(u,d):b.range(d,u)}return o?n.replaceRange(n.main.extend(a.from,a.to)):l&&i==1&&n.ranges.length>1&&(f=oc(n,h.pos))?f:l?n.addRange(a):b.create([a])}}}function oc(s,t){for(let e=0;e<s.ranges.length;e++){let{from:i,to:n}=s.ranges[e];if(i<=t&&n>=t)return b.create(s.ranges.slice(0,e).concat(s.ranges.slice(e+1)),s.mainIndex==e?0:s.mainIndex-(s.mainIndex>e?1:0))}return null}Bt.dragstart=(s,t)=>{let{selection:{main:e}}=s.state;if(t.target.draggable){let n=s.docView.nearest(t.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=e.to||o<=e.from)&&(e=b.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",En(s.state,er,s.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};Bt.dragend=s=>(s.inputState.draggedContent=null,!1);function ro(s,t,e,i){if(e=En(s.state,tr,e),!e)return;let n=s.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&Zf(s,t)?{from:r.from,to:r.to}:null,l={from:n,insert:e},h=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:h,selection:{anchor:h.mapPos(n,-1),head:h.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}Bt.drop=(s,t)=>{if(!t.dataTransfer)return!1;if(s.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),n=0,r=()=>{++n==e.length&&ro(s,t,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return ro(s,t,i,!0),!0}return!1};Bt.paste=(s,t)=>{if(s.state.readOnly)return!0;s.observer.flush();let e=ch?null:t.clipboardData;return e?(uh(s,e.getData("text/plain")||e.getData("text/uri-list")),!0):(ic(s),!1)};function lc(s,t){let e=s.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function hc(s){let t=[],e=[],i=!1;for(let n of s.selection.ranges)n.empty||(t.push(s.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:En(s,er,t.join(s.lineBreak)),ranges:e,linewise:i}}let Ls=null;Bt.copy=Bt.cut=(s,t)=>{let{text:e,ranges:i,linewise:n}=hc(s.state);if(!e&&!n)return!1;Ls=n?e:null,t.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=ch?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(lc(s,e),!1)};const ph=Zt.define();function gh(s,t){let e=[];for(let i of s.facet(_l)){let n=i(s,t);n&&e.push(n)}return e?s.update({effects:e,annotations:ph.of(!0)}):null}function mh(s){setTimeout(()=>{let t=s.hasFocus;if(t!=s.inputState.notifiedFocused){let e=gh(s.state,t);e?s.dispatch(e):s.update([])}},10)}Mt.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),mh(s)};Mt.blur=s=>{s.observer.clearSelectionRange(),mh(s)};Mt.compositionstart=Mt.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};Mt.compositionend=s=>{s.observer.editContext||(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,O.chrome&&O.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};Mt.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Bt.beforeinput=(s,t)=>{var e,i;if(t.inputType=="insertReplacementText"&&s.observer.editContext){let r=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(r&&o.length){let l=o[0],h=s.posAtDOM(l.startContainer,l.startOffset),f=s.posAtDOM(l.endContainer,l.endOffset);return sr(s,{from:h,to:f,insert:s.state.toText(r)},null),!0}}let n;if(O.chrome&&O.android&&(n=ah.find(r=>r.inputType==t.inputType))&&(s.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return O.ios&&t.inputType=="deleteContentForward"&&s.observer.flushSoon(),O.safari&&t.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>Mt.compositionend(s,t),20),!1};const oo=new Set;function ac(s){oo.has(s)||(oo.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const lo=["pre-wrap","normal","pre-line","break-spaces"];let We=!1;function ho(){We=!1}class fc{constructor(t){this.lineWrapping=t,this.doc=L.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return lo.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let n=t[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(e=!0,this.heightSamples[Math.floor(n*10)]=!0)}return e}refresh(t,e,i,n,r,o){let l=lo.indexOf(t)>-1,h=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=r,h){this.heightSamples={};for(let f=0;f<o.length;f++){let a=o[f];a<0?f++:this.heightSamples[Math.floor(a*10)]=!0}}return h}}class cc{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class zt{constructor(t,e,i,n,r){this.from=t,this.length=e,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?jt.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 ue?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new zt(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var $=(function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s})($||($={}));const tn=.001;class ft{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>tn&&(We=!0),this.height=t)}replace(t,e,i){return ft.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:h,toA:f,fromB:a,toB:c}=n[l],u=r.lineAt(h,$.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=f?u:r.lineAt(f,$.ByPosNoHeight,i,0,0);for(c+=d.to-f,f=d.to;l>0&&u.from<=n[l-1].toA;)h=n[l-1].fromA,a=n[l-1].fromB,l--,h<u.from&&(u=r.lineAt(h,$.ByPosNoHeight,i,0,0));a+=u.from-h,h=u.from;let p=rr.build(i.setDoc(o),t,a,c);r=fn(r,r.replace(h,f,p))}return r.updateHeight(i,0)}static empty(){return new yt(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,n=0,r=0;for(;;)if(e==i)if(n>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=t[e++];l&&(n+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new uc(ft.of(t.slice(0,e)),o,ft.of(t.slice(i)))}}function fn(s,t){return s==t?s:(s.constructor!=t.constructor&&(We=!0),t)}ft.prototype.size=1;class yh extends ft{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,n){return new zt(n,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,n,r){return this.blockAt(0,i,n,r)}forEachLine(t,e,i,n,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,n,r))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class yt extends yh{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new zt(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return i.length==1&&(n instanceof yt||n instanceof et&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof et?n=new yt(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):ft.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class et extends ft{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,r=n-i+1,o,l=0;if(t.lineWrapping){let h=Math.min(this.height,t.lineHeight*r);o=h/r,this.length>r+1&&(l=(this.height-h)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:n,perLine:o,perChar:l}}blockAt(t,e,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(e,n);if(e.lineWrapping){let f=n+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),a=e.doc.lineAt(f),c=l+a.length*h,u=Math.max(i,t-c/2);return new zt(a.from,a.length,u,c,0)}else{let f=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:a,length:c}=e.doc.line(r+f);return new zt(a,c,i+l*f,l,0)}}lineAt(t,e,i,n,r){if(e==$.ByHeight)return this.blockAt(t,i,n,r);if(e==$.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new zt(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,r),f=i.doc.lineAt(t),a=l+f.length*h,c=f.number-o,u=n+l*c+h*(f.from-r-c);return new zt(f.from,f.length,Math.max(n,Math.min(u,n+this.height-a)),a,0)}forEachLine(t,e,i,n,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:h,perChar:f}=this.heightMetrics(i,r);for(let a=t,c=n;a<=e;){let u=i.doc.lineAt(a);if(a==t){let p=u.number-l;c+=h*p+f*(t-r-p)}let d=h+f*u.length;o(new zt(u.from,u.length,c,d,0)),c+=d,a=u.to+1}}replace(t,e,i){let n=this.length-e;if(n>0){let r=i[i.length-1];r instanceof et?i[i.length-1]=new et(r.length+n):i.push(null,new et(n-1))}if(t>0){let r=i[0];r instanceof et?i[0]=new et(t+r.length):i.unshift(new et(t-1),null)}return ft.of(i)}decomposeLeft(t,e){e.push(new et(t-1),null)}decomposeRight(t,e){e.push(null,new et(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let r=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),h=-1;for(n.from>e&&o.push(new et(n.from-e-1).updateHeight(t,e));l<=r&&n.more;){let a=t.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++];h==-1?h=c:Math.abs(c-h)>=tn&&(h=-2);let u=new yt(a,c);u.outdated=!1,o.push(u),l+=a+1}l<=r&&o.push(null,new et(r-l).updateHeight(t,l));let f=ft.of(o);return(h<0||Math.abs(f.height-this.height)>=tn||Math.abs(h-this.heightMetrics(t,e).perLine)>=tn)&&(We=!0),fn(this,f)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class uc extends ft{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,n){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,n):this.right.blockAt(t,e,r,n+this.left.length+this.break)}lineAt(t,e,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,h=e==$.ByHeight?t<o:t<l,f=h?this.left.lineAt(t,e,i,n,r):this.right.lineAt(t,e,i,o,l);if(this.break||(h?f.to<l:f.from>l))return f;let a=e==$.ByPosNoHeight?$.ByPosNoHeight:$.ByPos;return h?f.join(this.right.lineAt(l,a,i,o,l)):this.left.lineAt(l,a,i,n,r).join(f)}forEachLine(t,e,i,n,r,o){let l=n+this.left.height,h=r+this.left.length+this.break;if(this.break)t<h&&this.left.forEachLine(t,e,i,n,r,o),e>=h&&this.right.forEachLine(t,e,i,l,h,o);else{let f=this.lineAt(h,$.ByPos,i,n,r);t<f.from&&this.left.forEachLine(t,f.from-1,i,n,r,o),f.to>=t&&f.from<=e&&o(f),e>f.to&&this.right.forEachLine(f.to+1,e,i,l,h,o)}}replace(t,e,i){let n=this.left.length+this.break;if(e<n)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&ao(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),ao(r,l)}return ft.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<n&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?ft.of(this.break?[t,null,e]:[t,e]):(this.left=fn(this.left,t),this.right=fn(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:r,right:o}=this,l=e+r.length+this.break,h=null;return n&&n.from<=e+r.length&&n.more?h=r=r.updateHeight(t,e,i,n):r.updateHeight(t,e,i),n&&n.from<=l+o.length&&n.more?h=o=o.updateHeight(t,l,i,n):o.updateHeight(t,l,i),h?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function ao(s,t){let e,i;s[t]==null&&(e=s[t-1])instanceof et&&(i=s[t+1])instanceof et&&s.splice(t-1,3,new et(e.length+1+i.length))}const dc=5;class rr{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof yt?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new yt(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new yh(o,n,i)):(o||r||n>=dc)&&this.addLineDeco(n,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new yt(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new et(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof yt)return t;let e=new yt(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof yt)&&!this.isCovered?this.nodes.push(new yt(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let n of this.nodes)n instanceof yt&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(t,e,i,n){let r=new rr(i,t);return H.spans(e,i,n,r,0),r.finish(i)}}function pc(s,t,e){let i=new gc;return H.compare(s,t,e,i,0),i.changes}class gc{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,n){(t<e||i&&i.heightRelevant||n&&n.heightRelevant)&&Ms(t,e,this.changes,5)}}function mc(s,t){let e=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(n.innerWidth,e.right),l=Math.max(0,e.top),h=Math.min(n.innerHeight,e.bottom);for(let f=s.parentNode;f&&f!=i.body;)if(f.nodeType==1){let a=f,c=window.getComputedStyle(a);if((a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth)&&c.overflow!="visible"){let u=a.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),h=Math.min(f==s.parentNode?n.innerHeight:h,u.bottom)}f=c.position=="absolute"||c.position=="fixed"?a.offsetParent:a.parentNode}else if(f.nodeType==11)f=f.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,h)-(e.top+t)}}function yc(s,t){let e=s.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class Gn{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let n=t[i],r=e[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(t,e){return N.replace({widget:new bc(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class bc extends ki{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class fo{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=co,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=Q.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(ir).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new fc(e),this.stateDeco=t.facet(yi).filter(i=>typeof i!="function"),this.heightMap=ft.empty().applyChanges(this.stateDeco,L.empty,this.heightOracle.setDoc(t.doc),[new Ct(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=N.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);t.push(new Ii(r,o))}}return this.viewports=t.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?co:new or(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(oi(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(yi).filter(a=>typeof a!="function");let n=t.changedRanges,r=Ct.extendWithRanges(n,pc(i,this.stateDeco,t?t.changes:_.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);ho(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||We)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let h=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<h.from||e.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let f=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,t.flags|=this.updateForViewport(),(f||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(vf)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?Q.RTL:Q.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let f=0,a=0;if(l.width&&l.height){let{scaleX:k,scaleY:S}=Al(e,l);(k>.005&&Math.abs(this.scaleX-k)>.005||S>.005&&Math.abs(this.scaleY-S)>.005)&&(this.scaleX=k,this.scaleY=S,f|=8,o=h=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,f|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,f|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Pl(t.scrollDOM);let p=(this.printing?yc:mc)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(h=!0)),!this.inView&&!this.scrollTarget)return 0;let w=l.width;if((this.contentDOMWidth!=w||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,f|=8),h){let k=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(k)&&(o=!0),o||n.lineWrapping&&Math.abs(w-this.contentDOMWidth)>n.charWidth){let{lineHeight:S,charWidth:A,textHeight:M}=t.docView.measureTextSize();o=S>0&&n.refresh(r,S,A,M,w/A,k),o&&(t.docView.minWidth=0,f|=8)}g>0&&m>0?a=Math.max(g,m):g<0&&m<0&&(a=Math.min(g,m)),ho();for(let S of this.viewports){let A=S.from==this.viewport.from?k:t.docView.measureVisibleLineHeights(S);this.heightMap=(o?ft.empty().applyChanges(this.stateDeco,L.empty,this.heightOracle,[new Ct(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new cc(S.from,A))}We&&(f|=2)}let x=!this.viewportIsAppropriate(this.viewport,a)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return x&&(f&2&&(f|=this.updateScaler()),this.viewport=this.getViewport(a,this.scrollTarget),f|=this.updateForViewport()),(f&2||x)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),f|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),f}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new Ii(n.lineAt(o-i*1e3,$.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,$.ByHeight,r,0,0).to);if(e){let{head:f}=e.range;if(f<h.from||f>h.to){let a=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(f,$.ByPos,r,0,0),u;e.y=="center"?u=(c.top+c.bottom)/2-a/2:e.y=="start"||e.y=="nearest"&&f<h.from?u=c.top:u=c.bottom-a,h=new Ii(n.lineAt(u-1e3/2,$.ByHeight,r,0,0).from,n.lineAt(u+a+1e3/2,$.ByHeight,r,0,0).to)}}return h}mapViewport(t,e){let i=e.mapPos(t.from,-1),n=e.mapPos(t.to,1);return new Ii(this.heightMap.lineAt(i,$.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,$.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,$.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||n<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let n of t)e.touchesRange(n.from,n.to)||i.push(new Gn(e.mapPos(n.from),e.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=Q.LTR&&!i)return[];let l=[],h=(a,c,u,d)=>{if(c-a<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let y of g)if(y>a&&y<c){h(a,y-10,u,d),h(y+10,c,u,d);return}let m=xc(t,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-a)<r&&Math.abs(y.to-c)<r&&!g.some(w=>y.from<w&&y.to>w));if(!m){if(c<u.to&&e&&i&&e.visibleRanges.some(x=>x.from<=c&&x.to>=c)){let x=e.moveToLineBoundary(b.cursor(c),!1,!0).head;x>a&&(c=x)}let y=this.gapSize(u,a,c,d),w=i||y<2e6?y:2e6;m=new Gn(a,c,y,w)}l.push(m)},f=a=>{if(a.length<o||a.type!=jt.Text)return;let c=wc(a.from,a.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,y;if(u!=null){let w=Fi(c,u),x=((this.visibleBottom-this.visibleTop)/2+g)/a.height;m=w-x,y=w+x}else m=(this.visibleTop-a.top-g)/a.height,y=(this.visibleBottom-a.top+g)/a.height;d=Ni(c,m),p=Ni(c,y)}else{let g=c.total*this.heightOracle.charWidth,m=n*this.heightOracle.charWidth,y=0;if(g>2e6)for(let A of t)A.from>=a.from&&A.from<a.to&&A.size!=A.displaySize&&A.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=A.size-A.displaySize);let w=this.pixelViewport.left+y,x=this.pixelViewport.right+y,k,S;if(u!=null){let A=Fi(c,u),M=((x-w)/2+m)/g;k=A-M,S=A+M}else k=(w-m)/g,S=(x+m)/g;d=Ni(c,k),p=Ni(c,S)}d>a.from&&h(a.from,d,a,c),p<a.to&&h(p,a.to,a,c)};for(let a of this.viewportLines)Array.isArray(a.type)?a.type.forEach(f):f(a);return l}gapSize(t,e,i,n){let r=Fi(n,i)-Fi(n,e);return this.heightOracle.lineWrapping?t.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(t){Gn.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=N.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];H.spans(t,this.viewport.from,this.viewport.to,{span(n,r){e.push({from:n,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((n,r)=>n.from!=e[r].from||n.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||oi(this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||oi(this.heightMap.lineAt(this.scaler.fromDOM(t),$.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return oi(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Ii{constructor(t,e){this.from=t,this.to=e}}function wc(s,t,e){let i=[],n=s,r=0;return H.spans(e,s,t,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<t&&(i.push({from:n,to:t}),r+=t-n),{total:r,ranges:i}}function Ni({total:s,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(s*e);for(let n=0;;n++){let{from:r,to:o}=t[n],l=o-r;if(i<=l)return r+i;i-=l}}function Fi(s,t){let e=0;for(let{from:i,to:n}of s.ranges){if(t<=n){e+=t-i;break}e+=n-i}return e/s.total}function xc(s,t){for(let e of s)if(t(e))return e}const co={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};class or{constructor(t,e,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let f=e.lineAt(l,$.ByPos,t,0,0).top,a=e.lineAt(h,$.ByPos,t,0,0).bottom;return n+=a-f,{from:l,to:h,top:f,bottom:a,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.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(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return n+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,n=r.domBottom}}fromDOM(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-n)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,n=r.domBottom}}eq(t){return t instanceof or?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function oi(s,t){if(t.scale==1)return s;let e=t.toDOM(s.top),i=t.toDOM(s.bottom);return new zt(s.from,s.length,e,i-e,Array.isArray(s._content)?s._content.map(n=>oi(n,t)):s._content)}const Vi=P.define({combine:s=>s.join(" ")}),Is=P.define({combine:s=>s.indexOf(!0)>-1}),Ns=fe.newName(),bh=fe.newName(),wh=fe.newName(),xh={"&light":"."+bh,"&dark":"."+wh};function Fs(s,t,e){return new fe(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):s+" "+i}})}const kc=Fs("."+Ns,{"&":{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,overflowAnchor:"none"},".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:"#ddd"},".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,zIndex:300},"&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":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".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"}},xh),vc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Xn=O.ie&&O.ie_version<=11;class Sc{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new sf,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(O.ie&&O.ie_version<=11||O.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&t.constructor.EDIT_CONTEXT!==!1&&!(O.chrome&&O.chrome_version<126)&&(this.editContext=new Oc(t),t.state.facet(se)&&(t.contentDOM.editContext=this.editContext.editContext)),Xn&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(se)?i.root.activeElement!=this.dom:!Ji(this.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(O.ie&&O.ie_version<=11||O.android&&O.chrome)&&!i.state.selection.main.empty&&n.focusNode&&ai(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=gi(t.root);if(!e)return!1;let i=O.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&Cc(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=Ji(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&of(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,vc),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(t,e){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&&Ee(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Ji(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new $f(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=hh(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=uo(e,t.previousSibling||t.target.previousSibling,-1),n=uo(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(se)!=t.state.facet(se)&&(t.view.contentDOM.editContext=t.state.facet(se)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let 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),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function uo(s,t,e){for(;t;){let i=z.get(t);if(i&&i.parent==s)return i;let n=t.parentNode;t=n!=s.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function po(s,t){let e=t.startContainer,i=t.startOffset,n=t.endContainer,r=t.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor);return ai(o.node,o.offset,n,r)&&([e,i,n,r]=[n,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}}function Cc(s,t){if(t.getComposedRanges){let n=t.getComposedRanges(s.root)[0];if(n)return po(s,n)}let e=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),e=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),e?po(s,e):null}class Oc{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:n}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:L.of(i.text.split(`
10
- `))};r.from==this.from&&n<this.from?r.from=n:r.to==this.to&&n>this.to&&(r.to=n),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,t.state.readOnly||sr(t,r,b.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)))},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let h=t.coordsForChar(o);r=h&&new DOMRect(h.left,h.top,h.right-h.left,h.bottom-h.top)||r||new DOMRect,n.push(r)}e.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let h=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;n.push(N.mark({attributes:{style:h}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:th.of(N.set(n))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=gi(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((r,o,l,h,f)=>{if(i)return;let a=f.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(f)){n=this.pendingContextChange=null,e+=a,this.to+=a;return}else n=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=a,this.to+=a;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+f.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),f.toString()),this.to+=a}e+=a}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange;!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}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(t={}){var 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),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(n=>n.forEach(r=>i(r,this)))||(n=>this.update(n)),this.dispatch=this.dispatch.bind(this),this._root=t.root||rf(t.parent)||document,this.viewState=new fo(t.state||F.create(t)),t.scrollTo&&t.scrollTo.is(Ri)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(ni).map(n=>new jn(n));for(let n of this.plugins)n.update(this);this.observer=new Sc(this),this.inputState=new Qf(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Kr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=t.length==1&&t[0]instanceof G?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,n,r=this.state;for(let u of t){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,h=null;t.some(u=>u.annotation(ph))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,h=gh(r,o),h||(l=1));let f=this.observer.delayedAndroidKey,a=null;if(f?(this.observer.clearDelayedAndroidKey(),a=this.observer.readChange(),(a&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(a=null)):this.observer.clear(),r.facet(F.phrases)!=this.state.facet(F.phrases))return this.setState(r);n=an.create(this,r,t),n.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;c=new Le(d.empty?d:b.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Ri)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=cn.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(si)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Vi)!=n.state.facet(Vi)&&(this.viewState.mustMeasureContent=!0),(e||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Rs))try{u(n)}catch(d){at(this.state,d,"update listener")}(h||a)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),a&&!hh(this,a)&&f.force&&Ee(this.contentDOM,f.key,f.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new fo(t),this.plugins=t.facet(ni).map(i=>new jn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Kr(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(ni),i=t.state.facet(ni);if(e!=i){let n=[];for(let r of i){let o=e.indexOf(r);if(o<0)n.push(new jn(r));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){at(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,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(Pl(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 h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let f=[];h&4||([this.measureRequests,f]=[f,this.measureRequests]);let a=f.map(d=>{try{return d.read(this)}catch(p){return at(this.state,p),go}}),c=an.create(this,this.state,[]),u=!1;c.flags|=h,e?e.flags|=h:e=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<f.length;d++)if(a[d]!=go)try{let p=f[d];p.write&&p.write(a[d],this)}catch(p){at(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.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(e&&!e.empty)for(let l of this.state.facet(Rs))l(e)}get themeClasses(){return Ns+" "+(this.state.facet(Is)?wh:bh)+" "+this.state.facet(Vi)}updateAttrs(){let t=mo(this,eh,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(se)?"true":"false",class:"cm-content",style:`${O.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),mo(this,ir,e);let i=this.observer.ignore(()=>{let n=As(this.contentDOM,this.contentAttrs,e),r=As(this.dom,this.editorAttrs,t);return n||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let n of i.effects)if(n.is(T.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(si);let t=this.state.facet(T.cspNonce);fe.mount(this.root,this.styleModules.concat(kc).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Yn(this,t,Xr(this,t,e,i))}moveByGroup(t,e){return Yn(this,t,Xr(this,t,e,i=>Vf(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return b.cursor(r.side(e,n)+t.from,r.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return Ff(this,t,e,i)}moveVertically(t,e,i){return Yn(this,t,Hf(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),lh(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(t),r=this.bidiSpans(n),o=r[he.find(r,t-n.from,-1,e)];return Bn(i,o.dir==Q.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Jl)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Ac)return Ul(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||ql(r.isolates,i=Ur(this,t))))return r.order;i||(i=Ur(this,t));let n=wf(t.text,e,i);return this.bidiCache.push(new cn(t.from,t.to,e,i,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||O.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Ml(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Ri.of(new Le(typeof t=="number"?b.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Ri.of(new Le(b.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return At.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return At.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=fe.newName(),n=[Vi.of(i),si.of(Fs(`.${i}`,t))];return e&&e.dark&&n.push(Is.of(!0)),n}static baseTheme(t){return Qe.lowest(si.of(Fs("."+Ns,t,xh)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&z.get(i)||z.get(t);return((e=n==null?void 0:n.rootView)===null||e===void 0?void 0:e.view)||null}}T.styleModule=si;T.inputHandler=Xl;T.clipboardInputFilter=tr;T.clipboardOutputFilter=er;T.scrollHandler=Zl;T.focusChangeEffect=_l;T.perLineTextDirection=Jl;T.exceptionSink=Gl;T.updateListener=Rs;T.editable=se;T.mouseSelectionStyle=Yl;T.dragMovesSelection=Ql;T.clickAddsSelectionRange=jl;T.decorations=yi;T.outerDecorations=ih;T.atomicRanges=nr;T.bidiIsolatedRanges=nh;T.scrollMargins=sh;T.darkTheme=Is;T.cspNonce=P.define({combine:s=>s.length?s[0]:""});T.contentAttributes=ir;T.editorAttributes=eh;T.lineWrapping=T.contentAttributes.of({class:"cm-lineWrapping"});T.announce=R.define();const Ac=4096,go={};class cn{constructor(t,e,i,n,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:Q.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==n&&!e.touchesRange(o.from,o.to)&&i.push(new cn(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function mo(s,t,e){for(let i=s.state.facet(t),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Os(o,e)}return e}const Mc=O.mac?"mac":O.windows?"win":O.linux?"linux":"key";function Tc(s,t){const e=s.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let h=0;h<e.length-1;++h){const f=e[h];if(/^(cmd|meta|m)$/i.test(f))l=!0;else if(/^a(lt)?$/i.test(f))n=!0;else if(/^(c|ctrl|control)$/i.test(f))r=!0;else if(/^s(hift)?$/i.test(f))o=!0;else if(/^mod$/i.test(f))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+f)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function Hi(s,t,e){return t.altKey&&(s="Alt-"+s),t.ctrlKey&&(s="Ctrl-"+s),t.metaKey&&(s="Meta-"+s),e!==!1&&t.shiftKey&&(s="Shift-"+s),s}const Pc=Qe.default(T.domEventHandlers({keydown(s,t){return Ec(Dc(t.state),s,t,"editor")}})),Ln=P.define({enables:Pc}),yo=new WeakMap;function Dc(s){let t=s.facet(Ln),e=yo.get(t);return e||yo.set(t,e=Rc(t.reduce((i,n)=>i.concat(n),[]))),e}let re=null;const Bc=4e3;function Rc(s,t=Mc){let e=Object.create(null),i=Object.create(null),n=(o,l)=>{let h=i[o];if(h==null)i[o]=l;else if(h!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,h,f,a)=>{var c,u;let d=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>Tc(y,t));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:[x=>{let k=re={view:x,prefix:w,scope:o};return setTimeout(()=>{re==k&&(re=null)},Bc),!0}]})}let g=p.join(" ");n(g,!1);let m=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});h&&m.run.push(h),f&&(m.preventDefault=!0),a&&(m.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let f of l){let a=e[f]||(e[f]=Object.create(null));a._any||(a._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in a)a[u].run.push(d=>c(d,Vs))}let h=o[t]||o.key;if(h)for(let f of l)r(f,h,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(f,"Shift-"+h,o.shift,o.preventDefault,o.stopPropagation)}return e}let Vs=null;function Ec(s,t,e,i){Vs=t;let n=Za(t),r=Vt(n,0),o=ne(r)==n.length&&n!=" ",l="",h=!1,f=!1,a=!1;re&&re.view==e&&re.scope==i&&(l=re.prefix+" ",fh.indexOf(t.keyCode)<0&&(f=!0,re=null));let c=new Set,u=m=>{if(m){for(let y of m.run)if(!c.has(y)&&(c.add(y),y(e)))return m.stopPropagation&&(a=!0),!0;m.preventDefault&&(m.stopPropagation&&(a=!0),f=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+Hi(n,t,!o)])?h=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(O.windows&&t.ctrlKey&&t.altKey)&&(p=ce[t.keyCode])&&p!=n?(u(d[l+Hi(p,t,!0)])||t.shiftKey&&(g=pi[t.keyCode])!=n&&g!=p&&u(d[l+Hi(g,t,!1)]))&&(h=!0):o&&t.shiftKey&&u(d[l+Hi(n,t,!0)])&&(h=!0),!h&&u(d._any)&&(h=!0)),f&&(h=!0),h&&a&&t.stopPropagation(),Vs=null,h}const Lc=!O.ios,bo={".cm-line":{},".cm-content":{}};Lc&&(bo[".cm-line"].caretColor=bo[".cm-content"].caretColor="transparent !important");const Ze="-10000px";class kh{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(t,e){var i;let n=t.state.facet(this.facet),r=n.filter(h=>h);if(n===this.input){for(let h of this.tooltipViews)h.update&&h.update(t);return!1}let o=[],l=e?[]:null;for(let h=0;h<r.length;h++){let f=r[h],a=-1;if(f){for(let c=0;c<this.tooltips.length;c++){let u=this.tooltips[c];u&&u.create==f.create&&(a=c)}if(a<0)o[h]=this.createTooltipView(f,h?o[h-1]:null),l&&(l[h]=!!f.above);else{let c=o[h]=this.tooltipViews[a];l&&(l[h]=e[a]),c.update&&c.update(t)}}}for(let h of this.tooltipViews)o.indexOf(h)<0&&(this.removeTooltipView(h),(i=h.destroy)===null||i===void 0||i.call(h));return e&&(l.forEach((h,f)=>e[f]=h),e.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function Ic(s={}){return en.of(s)}function Nc(s){let{win:t}=s;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const en=P.define({combine:s=>{var t,e,i;return{position:O.ios?"absolute":((t=s.find(n=>n.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=s.find(n=>n.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Nc}}}),wo=new WeakMap,lr=At.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=s.state.facet(en);this.position=t.position,this.parent=t.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 kh(s,$e,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),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 t=this.manager.update(s,this.above);t&&this.observeIntersection();let e=t||s.geometryChanged,i=s.state.facet(en);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(s,t){let e=s.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),s.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let n=document.createElement("div");n.className="cm-tooltip-arrow",e.dom.appendChild(n)}return e.dom.style.position=this.position,e.dom.style.top=Ze,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var s,t,e;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(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=this.view.dom.getBoundingClientRect(),t=1,e=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:n}=this.manager.tooltipViews[0];if(O.gecko)i=n.offsetParent!=this.container.ownerDocument.body;else if(n.style.top==Ze&&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&&(t=n.width/this.parent.offsetWidth,e=n.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=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(en).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(s){var t;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:e,space:i,scaleX:n,scaleY:r}=s,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let h=this.manager.tooltips[l],f=this.manager.tooltipViews[l],{dom:a}=f,c=s.pos[l],u=s.size[l];if(!c||c.bottom<=Math.max(e.top,i.top)||c.top>=Math.min(e.bottom,i.bottom)||c.right<Math.max(e.left,i.left)-.1||c.left>Math.min(e.right,i.right)+.1){a.style.top=Ze;continue}let d=h.arrow?f.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,m=(t=wo.get(f))!==null&&t!==void 0?t:u.bottom-u.top,y=f.offset||Vc,w=this.view.textDirection==Q.LTR,x=u.width>i.right-i.left?w?i.left:i.right-u.width:w?Math.max(i.left,Math.min(c.left-(d?14:0)+y.x,i.right-g)):Math.min(Math.max(i.left,c.left-g+(d?14:0)-y.x),i.right-g),k=this.above[l];!h.strictSide&&(k?c.top-(u.bottom-u.top)-y.y<i.top:c.bottom+(u.bottom-u.top)+y.y>i.bottom)&&k==i.bottom-c.bottom>c.top-i.top&&(k=this.above[l]=!k);let S=(k?c.top-i.top:i.bottom-c.bottom)-p;if(S<m&&f.resize!==!1){if(S<this.view.defaultLineHeight){a.style.top=Ze;continue}wo.set(f,m),a.style.height=(m=S)/r+"px"}else a.style.height&&(a.style.height="");let A=k?c.top-m-p-y.y:c.bottom+p+y.y,M=x+g;if(f.overlap!==!0)for(let I of o)I.left<M&&I.right>x&&I.top<A+m&&I.bottom>A&&(A=k?I.top-m-2-p:I.bottom+p+2);if(this.position=="absolute"?(a.style.top=(A-s.parent.top)/r+"px",a.style.left=(x-s.parent.left)/n+"px"):(a.style.top=A/r+"px",a.style.left=x/n+"px"),d){let I=c.left+(w?y.x:-y.x)-(x+14-7);d.style.left=I/n+"px"}f.overlap!==!0&&o.push({left:x,top:A,right:M,bottom:A+m}),a.classList.toggle("cm-tooltip-above",k),a.classList.toggle("cm-tooltip-below",!k),f.positioned&&f.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=Ze}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Fc=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:"14px",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"}}}),Vc={x:0,y:0},$e=P.define({enables:[lr,Fc]}),un=P.define({combine:s=>s.reduce((t,e)=>t.concat(e),[])});class In{static create(t){return new In(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new kh(t,un,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(n!==void 0){if(e===void 0)e=n;else if(e!==n)return}}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Hc=$e.compute([un],s=>{let t=s.facet(un);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:In.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class zc{constructor(t,e,i,n,r){this.view=t,this.source=e,this.field=i,this.setHover=n,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this,i=t.docView.nearest(e.target);if(!i)return;let n,r=1;if(i instanceof le)n=i.posAtStart;else{if(n=t.posAtCoords(e),n==null)return;let l=t.coordsAtPos(n);if(!l||e.y<l.top||e.y>l.bottom||e.x<l.left-t.defaultCharacterWidth||e.x>l.right+t.defaultCharacterWidth)return;let h=t.bidiSpans(t.state.doc.lineAt(n)).find(a=>a.from<=n&&a.to>=n),f=h&&h.dir==Q.RTL?-1:1;r=e.x<l.left?-f:f}let o=this.source(t,n,r);if(o!=null&&o.then){let l=this.pending={pos:n};o.then(h=>{this.pending==l&&(this.pending=null,h&&!(Array.isArray(h)&&!h.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(h)?h:[h])}))},h=>at(t.state,h,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(lr),e=t?t.manager.tooltips.findIndex(i=>i.create==In.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&r&&!Wc(r.dom,t)||this.pending){let{pos:o}=n[0]||this.pending,l=(i=(e=n[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!$c(this.view,o,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const zi=4;function Wc(s,t){let{left:e,right:i,top:n,bottom:r}=s.getBoundingClientRect(),o;if(o=s.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();n=Math.min(l.top,n),r=Math.max(l.bottom,r)}return t.clientX>=e-zi&&t.clientX<=i+zi&&t.clientY>=n-zi&&t.clientY<=r+zi}function $c(s,t,e,i,n,r){let o=s.scrollDOM.getBoundingClientRect(),l=s.documentTop+s.documentPadding.top+s.contentHeight;if(o.left>i||o.right<i||o.top>n||Math.min(o.bottom,l)<n)return!1;let h=s.posAtCoords({x:i,y:n},!1);return h>=t&&h<=e}function qc(s,t={}){let e=R.define(),i=ct.define({create(){return[]},update(n,r){if(n.length&&(t.hideOnChange&&(r.docChanged||r.selection)?n=[]:t.hideOn&&(n=n.filter(o=>!t.hideOn(r,o))),r.docChanged)){let o=[];for(let l of n){let h=r.changes.mapPos(l.pos,-1,nt.TrackDel);if(h!=null){let f=Object.assign(Object.create(null),l);f.pos=h,f.end!=null&&(f.end=r.changes.mapPos(f.end)),o.push(f)}}n=o}for(let o of r.effects)o.is(e)&&(n=o.value),o.is(Uc)&&(n=[]);return n},provide:n=>un.from(n)});return{active:i,extension:[i,At.define(n=>new zc(n,s,i,e,t.hoverTime||300)),Hc]}}function vh(s,t){let e=s.plugin(lr);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const Uc=R.define(),xo=P.define({combine(s){let t,e;for(let i of s)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}}),Kc=At.fromClass(class{constructor(s){this.input=s.state.facet(Hs),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(s));let t=s.state.facet(xo);this.top=new Wi(s,!0,t.topContainer),this.bottom=new Wi(s,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(s){let t=s.state.facet(xo);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new Wi(s.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new Wi(s.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=s.state.facet(Hs);if(e!=this.input){let i=e.filter(h=>h),n=[],r=[],o=[],l=[];for(let h of i){let f=this.specs.indexOf(h),a;f<0?(a=h(s.view),l.push(a)):(a=this.panels[f],a.update&&a.update(s)),n.push(a),(a.top?r:o).push(a)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let h of l)h.dom.classList.add("cm-panel"),h.mount&&h.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>T.scrollMargins.of(t=>{let e=t.plugin(s);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class Wi{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=ko(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=ko(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function ko(s){let t=s.nextSibling;return s.remove(),t}const Hs=P.define({enables:Kc});class qe extends Ce{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}qe.prototype.elementClass="";qe.prototype.toDOM=void 0;qe.prototype.mapMode=nt.TrackBefore;qe.prototype.startSide=qe.prototype.endSide=-1;qe.prototype.point=!0;const Sh=1024;let jc=0;class _n{constructor(t,e){this.from=t,this.to=e}}class B{constructor(t={}){this.id=jc++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=pt.match(t)),e=>{let i=t(e);return i===void 0?null:[this,i]}}}B.closedBy=new B({deserialize:s=>s.split(" ")});B.openedBy=new B({deserialize:s=>s.split(" ")});B.group=new B({deserialize:s=>s.split(" ")});B.isolate=new B({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});B.contextHash=new B({perNode:!0});B.lookAhead=new B({perNode:!0});B.mounted=new B({perNode:!0});class dn{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[B.mounted.id]}}const Qc=Object.create(null);class pt{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):Qc,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),n=new pt(t.name||"",e,t.id,i);if(t.props){for(let r of t.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");e[r[0].id]=r[1]}}return n}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(B.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let n of i.split(" "))e[n]=t[i];return i=>{for(let n=i.prop(B.group),r=-1;r<(n?n.length:0);r++){let o=e[r<0?i.name:n[r]];if(o)return o}}}}pt.none=new pt("",Object.create(null),0,8);class hr{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let n=null;for(let r of t){let o=r(i);o&&(n||(n=Object.assign({},i.props)),n[o[0].id]=o[1])}e.push(n?new pt(i.name,n,i.id,i.flags):i)}return new hr(e)}}const $i=new WeakMap,vo=new WeakMap;var J;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays"})(J||(J={}));class X{constructor(t,e,i,n,r){if(this.type=t,this.children=e,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 t=dn.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let n=i.toString();n&&(e&&(e+=","),e+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new Ws(this.topNode,t)}cursorAt(t,e=0,i=0){let n=$i.get(this)||this.topNode,r=new Ws(n);return r.moveTo(t,e),$i.set(this,r._tree),r}get topNode(){return new Ot(this,0,0,null)}resolve(t,e=0){let i=bi($i.get(this)||this.topNode,t,e,!1);return $i.set(this,i),i}resolveInner(t,e=0){let i=bi(vo.get(this)||this.topNode,t,e,!0);return vo.set(this,i),i}resolveStack(t,e=0){return Xc(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:r=this.length}=t,o=t.mode||0,l=(o&J.IncludeAnonymous)>0;for(let h=this.cursor(o|J.IncludeAnonymous);;){let f=!1;if(h.from<=r&&h.to>=n&&(!l&&h.type.isAnonymous||e(h)!==!1)){if(h.firstChild())continue;f=!0}for(;f&&i&&(l||!h.type.isAnonymous)&&i(h),!h.nextSibling();){if(!h.parent())return;f=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:cr(pt.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,n)=>new X(this.type,e,i,n,this.propValues),t.makeTree||((e,i,n)=>new X(pt.none,e,i,n)))}static build(t){return _c(t)}}X.empty=new X(pt.none,[],[],0);class ar{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new ar(this.buffer,this.index)}}class de{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return pt.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],n=this.set.types[e],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),t+=4,i==t)return r;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return r+"("+o.join(",")+")"}findChild(t,e,i,n,r){let{buffer:o}=this,l=-1;for(let h=t;h!=e&&!(Ch(r,n,o[h+1],o[h+2])&&(l=h,i>0));h=o[h+3]);return l}slice(t,e,i){let n=this.buffer,r=new Uint16Array(e-t),o=0;for(let l=t,h=0;l<e;){r[h++]=n[l++],r[h++]=n[l++]-i;let f=r[h++]=n[l++]-i;r[h++]=n[l++]-t,o=Math.max(o,f)}return new de(r,o,this.set)}}function Ch(s,t,e,i){switch(s){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function bi(s,t,e,i){for(var n;s.from==s.to||(e<1?s.from>=t:s.from>t)||(e>-1?s.to<=t:s.to<t);){let o=!i&&s instanceof Ot&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:J.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof Ot&&o.index<0&&((n=l.enter(t,e,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(t,e,r);if(!o)return s;s=o}}class Oh{cursor(t=0){return new Ws(this,t)}getChild(t,e=null,i=null){let n=So(this,t,e,i);return n.length?n[0]:null}getChildren(t,e=null,i=null){return So(this,t,e,i)}resolve(t,e=0){return bi(this,t,e,!1)}resolveInner(t,e=0){return bi(this,t,e,!0)}matchContext(t){return zs(this.parent,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let n=e.lastChild;if(!n||n.to!=e.to)break;n.type.isError&&n.from==n.to?(i=e,e=n.prevSibling):e=n}return i}get node(){return this}get next(){return this.parent}}class Ot extends Oh{constructor(t,e,i,n){super(),this._tree=t,this.from=e,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(t,e,i,n,r=0){for(let o=this;;){for(let{children:l,positions:h}=o._tree,f=e>0?l.length:-1;t!=f;t+=e){let a=l[t],c=h[t]+o.from;if(Ch(n,i,c,c+a.length)){if(a instanceof de){if(r&J.ExcludeBuffers)continue;let u=a.findChild(0,a.buffer.length,e,i-c,n);if(u>-1)return new ae(new Yc(o,a,t,c),null,u)}else if(r&J.IncludeAnonymous||!a.type.isAnonymous||fr(a)){let u;if(!(r&J.IgnoreMounts)&&(u=dn.get(a))&&!u.overlay)return new Ot(u.tree,c,t,o);let d=new Ot(a,c,t,o);return r&J.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(e<0?a.children.length-1:0,e,i,n)}}}if(r&J.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let n;if(!(i&J.IgnoreOverlays)&&(n=dn.get(this._tree))&&n.overlay){let r=t-this.from;for(let{from:o,to:l}of n.overlay)if((e>0?o<=r:o<r)&&(e<0?l>=r:l>r))return new Ot(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function So(s,t,e,i){let n=s.cursor(),r=[];if(!n.firstChild())return r;if(e!=null){for(let o=!1;!o;)if(o=n.type.is(e),!n.nextSibling())return r}for(;;){if(i!=null&&n.type.is(i))return r;if(n.type.is(t)&&r.push(n.node),!n.nextSibling())return i==null?r:[]}}function zs(s,t,e=t.length-1){for(let i=s;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}class Yc{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class ae extends Oh{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new ae(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}enter(t,e,i=0){if(i&J.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new ae(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new ae(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new ae(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let o=i.buffer[this.index+1];t.push(i.slice(n,r,o)),e.push(0)}return new X(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Ah(s){if(!s.length)return null;let t=0,e=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>e.from||o.to<e.to)&&(e=o,t=r)}let i=e instanceof Ot&&e.index<0?null:e.parent,n=s.slice();return i?n[t]=i:n.splice(t,1),new Gc(n,e)}class Gc{constructor(t,e){this.heads=t,this.node=e}get next(){return Ah(this.heads)}}function Xc(s,t,e){let i=s.resolveInner(t,e),n=null;for(let r=i instanceof Ot?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(t,e)),r=o}else{let o=dn.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new Ot(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(bi(l,t,e,!1))}}return n?Ah(n):i}class Ws{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof Ot)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:n}=this.buffer;return this.type=e||n.set.types[n.buffer[t]],this.from=i+n.buffer[t+1],this.to=i+n.buffer[t+2],!0}yield(t){return t?t instanceof Ot?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&J.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&J.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&J.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(e.findChild(n,this.index,-1,0,4))}else{let n=e.buffer[this.index+3];if(n<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:n}=this;if(n){if(t>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:e,parent:i}=n)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let r=e+t,o=t<0?-1:i._tree.children.length;r!=o;r+=t){let l=i._tree.children[r];if(this.mode&J.IncludeAnonymous||l instanceof de||!l.type.isAnonymous||fr(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=t;o;o=o._parent)if(o.index==n){if(n==this.index)return o;e=o,i=r+1;break t}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)e=new ae(this.buffer,e,this.stack[n]);return this.bufferNode=new ae(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let n=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&e&&e(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(t){if(!this.buffer)return zs(this.node.parent,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let n=t.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return zs(this._tree,t,n);let o=i[e.buffer[this.stack[r]]];if(!o.isAnonymous){if(t[n]&&t[n]!=o.name)return!1;n--}}return!0}}function fr(s){return s.children.some(t=>t instanceof de||!t.type.isAnonymous||fr(t))}function _c(s){var t;let{buffer:e,nodeSet:i,maxBufferLength:n=Sh,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(e)?new ar(e,e.length):e,h=i.types,f=0,a=0;function c(S,A,M,I,W,K){let{id:E,start:D,end:q,size:U}=l,tt=a,te=f;for(;U<0;)if(l.next(),U==-1){let Gt=r[E];M.push(Gt),I.push(D-S);return}else if(U==-3){f=E;return}else if(U==-4){a=E;return}else throw new RangeError(`Unrecognized record size: ${U}`);let Xe=h[E],Ai,ge,Or=D-S;if(q-D<=n&&(ge=m(l.pos-A,W))){let Gt=new Uint16Array(ge.size-ge.skip),wt=l.pos-ge.size,Et=Gt.length;for(;l.pos>wt;)Et=y(ge.start,Gt,Et);Ai=new de(Gt,q-ge.start,i),Or=ge.start-S}else{let Gt=l.pos-U;l.next();let wt=[],Et=[],me=E>=o?E:-1,Te=0,Mi=q;for(;l.pos>Gt;)me>=0&&l.id==me&&l.size>=0?(l.end<=Mi-n&&(p(wt,Et,D,Te,l.end,Mi,me,tt,te),Te=wt.length,Mi=l.end),l.next()):K>2500?u(D,Gt,wt,Et):c(D,Gt,wt,Et,me,K+1);if(me>=0&&Te>0&&Te<wt.length&&p(wt,Et,D,Te,D,Mi,me,tt,te),wt.reverse(),Et.reverse(),me>-1&&Te>0){let Ar=d(Xe,te);Ai=cr(Xe,wt,Et,0,wt.length,0,q-D,Ar,Ar)}else Ai=g(Xe,wt,Et,q-D,tt-q,te)}M.push(Ai),I.push(Or)}function u(S,A,M,I){let W=[],K=0,E=-1;for(;l.pos>A;){let{id:D,start:q,end:U,size:tt}=l;if(tt>4)l.next();else{if(E>-1&&q<E)break;E<0&&(E=U-n),W.push(D,q,U),K++,l.next()}}if(K){let D=new Uint16Array(K*4),q=W[W.length-2];for(let U=W.length-3,tt=0;U>=0;U-=3)D[tt++]=W[U],D[tt++]=W[U+1]-q,D[tt++]=W[U+2]-q,D[tt++]=tt;M.push(new de(D,W[2]-q,i)),I.push(q-S)}}function d(S,A){return(M,I,W)=>{let K=0,E=M.length-1,D,q;if(E>=0&&(D=M[E])instanceof X){if(!E&&D.type==S&&D.length==W)return D;(q=D.prop(B.lookAhead))&&(K=I[E]+D.length+q)}return g(S,M,I,W,K,A)}}function p(S,A,M,I,W,K,E,D,q){let U=[],tt=[];for(;S.length>I;)U.push(S.pop()),tt.push(A.pop()+M-W);S.push(g(i.types[E],U,tt,K-W,D-K,q)),A.push(W-M)}function g(S,A,M,I,W,K,E){if(K){let D=[B.contextHash,K];E=E?[D].concat(E):[D]}if(W>25){let D=[B.lookAhead,W];E=E?[D].concat(E):[D]}return new X(S,A,M,I,E)}function m(S,A){let M=l.fork(),I=0,W=0,K=0,E=M.end-n,D={size:0,start:0,skip:0};t:for(let q=M.pos-S;M.pos>q;){let U=M.size;if(M.id==A&&U>=0){D.size=I,D.start=W,D.skip=K,K+=4,I+=4,M.next();continue}let tt=M.pos-U;if(U<0||tt<q||M.start<E)break;let te=M.id>=o?4:0,Xe=M.start;for(M.next();M.pos>tt;){if(M.size<0)if(M.size==-3)te+=4;else break t;else M.id>=o&&(te+=4);M.next()}W=Xe,I+=U,K+=te}return(A<0||I==S)&&(D.size=I,D.start=W,D.skip=K),D.size>4?D:void 0}function y(S,A,M){let{id:I,start:W,end:K,size:E}=l;if(l.next(),E>=0&&I<o){let D=M;if(E>4){let q=l.pos-(E-4);for(;l.pos>q;)M=y(S,A,M)}A[--M]=D,A[--M]=K-S,A[--M]=W-S,A[--M]=I}else E==-3?f=I:E==-4&&(a=I);return M}let w=[],x=[];for(;l.pos>0;)c(s.start||0,s.bufferStart||0,w,x,-1,0);let k=(t=s.length)!==null&&t!==void 0?t:w.length?x[0]+w[0].length:0;return new X(h[s.topID],w.reverse(),x.reverse(),k)}const Co=new WeakMap;function nn(s,t){if(!s.isAnonymous||t instanceof de||t.type!=s)return 1;let e=Co.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=s||!(i instanceof X)){e=1;break}e+=nn(s,i)}Co.set(t,e)}return e}function cr(s,t,e,i,n,r,o,l,h){let f=0;for(let p=i;p<n;p++)f+=nn(s,t[p]);let a=Math.ceil(f*1.5/8),c=[],u=[];function d(p,g,m,y,w){for(let x=m;x<y;){let k=x,S=g[x],A=nn(s,p[x]);for(x++;x<y;x++){let M=nn(s,p[x]);if(A+M>=a)break;A+=M}if(x==k+1){if(A>a){let M=p[k];d(M.children,M.positions,0,M.children.length,g[k]+w);continue}c.push(p[k])}else{let M=g[x-1]+p[x-1].length-S;c.push(cr(s,p,g,k,x,S,M,null,h))}u.push(S+w-r)}}return d(t,e,i,n,0),(l||h)(c,u,o)}class ve{constructor(t,e,i,n,r=!1,o=!1){this.from=t,this.to=e,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(t,e=[],i=!1){let n=[new ve(0,t.length,t,0,!1,i)];for(let r of e)r.to>t.length&&n.push(r);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],r=1,o=t.length?t[0]:null;for(let l=0,h=0,f=0;;l++){let a=l<e.length?e[l]:null,c=a?a.fromA:1e9;if(c-h>=i)for(;o&&o.from<c;){let u=o;if(h>=u.from||c<=u.to||f){let d=Math.max(u.from,h)-f,p=Math.min(u.to,c)-f;u=d>=p?null:new ve(d,p,u.tree,u.offset+f,l>0,!!a)}if(u&&n.push(u),o.to>c)break;o=r<t.length?t[r++]:null}if(!a)break;h=a.toA,f=a.toA-a.toB}return n}}class Mh{startParse(t,e,i){return typeof t=="string"&&(t=new Jc(t)),i=i?i.length?i.map(n=>new _n(n.from,n.to)):[new _n(0,0)]:[new _n(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let r=n.advance();if(r)return r}}}class Jc{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new B({perNode:!0});let Zc=0;class xt{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=Zc++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i=typeof t=="string"?t:"?";if(t instanceof xt&&(e=t),e!=null&&e.base)throw new Error("Can not derive from a modified tag");let n=new xt(i,[],null,[]);if(n.set.push(n),e)for(let r of e.set)n.set.push(r);return n}static defineModifier(t){let e=new pn(t);return i=>i.modified.indexOf(e)>-1?i:pn.get(i.base||i,i.modified.concat(e).sort((n,r)=>n.id-r.id))}}let tu=0;class pn{constructor(t){this.name=t,this.instances=[],this.id=tu++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(l=>l.base==t&&eu(e,l.modified));if(i)return i;let n=[],r=new xt(t.name,n,t,e);for(let l of e)l.instances.push(r);let o=iu(e);for(let l of t.set)if(!l.modified.length)for(let h of o)n.push(pn.get(l,h));return r}}function eu(s,t){return s.length==t.length&&s.every((e,i)=>e==t[i])}function iu(s){let t=[[]];for(let e=0;e<s.length;e++)for(let i=0,n=t.length;i<n;i++)t.push(t[i].concat(s[e]));return t.sort((e,i)=>i.length-e.length)}function Th(s){let t=Object.create(null);for(let e in s){let i=s[e];Array.isArray(i)||(i=[i]);for(let n of e.split(" "))if(n){let r=[],o=2,l=n;for(let c=0;;){if(l=="..."&&c>0&&c+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]),c+=u[0].length,c==n.length)break;let d=n[c++];if(c==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(c)}let h=r.length-1,f=r[h];if(!f)throw new RangeError("Invalid path: "+n);let a=new gn(i,o,h>0?r.slice(0,h):null);t[f]=a.sort(t[f])}}return Ph.add(t)}const Ph=new B;class gn{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}gn.empty=new gn([],2,null);function Dh(s,t){let e=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))e[r.tag.id]=r.class;else for(let o of r.tag)e[o.id]=r.class;let{scope:i,all:n=null}=t||{};return{style:r=>{let o=n;for(let l of r)for(let h of l.set){let f=e[h.id];if(f){o=o?o+" "+f:f;break}}return o},scope:i}}function nu(s,t){let e=null;for(let i of s){let n=i.style(t);n&&(e=e?e+" "+n:n)}return e}function su(s,t,e,i=0,n=s.length){let r=new ru(i,Array.isArray(t)?t:[t],e);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class ru{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,n,r){let{type:o,from:l,to:h}=t;if(l>=i||h<=e)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let f=n,a=ou(t)||gn.empty,c=nu(r,a.tags);if(c&&(f&&(f+=" "),f+=c,a.mode==1&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,l),f),a.opaque)return;let u=t.tree&&t.tree.prop(B.mounted);if(u&&u.overlay){let d=t.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=t.firstChild();for(let m=0,y=l;;m++){let w=m<u.overlay.length?u.overlay[m]:null,x=w?w.from+l:h,k=Math.max(e,y),S=Math.min(i,x);if(k<S&&g)for(;t.from<S&&(this.highlightRange(t,k,S,n,r),this.startSpan(Math.min(S,t.to),f),!(t.to>=x||!t.nextSibling())););if(!w||x>i)break;y=w.to+l,y>e&&(this.highlightRange(d.cursor(),Math.max(e,w.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),f))}g&&t.parent()}else if(t.firstChild()){u&&(n="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,r),this.startSpan(Math.min(i,t.to),f)}while(t.nextSibling());t.parent()}}}function ou(s){let t=s.type.prop(Ph);for(;t&&t.context&&!s.matchContext(t.context);)t=t.next;return t||null}const v=xt.define,qi=v(),ee=v(),Oo=v(ee),Ao=v(ee),ie=v(),Ui=v(ie),Jn=v(ie),Ft=v(),ye=v(Ft),It=v(),Nt=v(),$s=v(),ti=v($s),Ki=v(),C={comment:qi,lineComment:v(qi),blockComment:v(qi),docComment:v(qi),name:ee,variableName:v(ee),typeName:Oo,tagName:v(Oo),propertyName:Ao,attributeName:v(Ao),className:v(ee),labelName:v(ee),namespace:v(ee),macroName:v(ee),literal:ie,string:Ui,docString:v(Ui),character:v(Ui),attributeValue:v(Ui),number:Jn,integer:v(Jn),float:v(Jn),bool:v(ie),regexp:v(ie),escape:v(ie),color:v(ie),url:v(ie),keyword:It,self:v(It),null:v(It),atom:v(It),unit:v(It),modifier:v(It),operatorKeyword:v(It),controlKeyword:v(It),definitionKeyword:v(It),moduleKeyword:v(It),operator:Nt,derefOperator:v(Nt),arithmeticOperator:v(Nt),logicOperator:v(Nt),bitwiseOperator:v(Nt),compareOperator:v(Nt),updateOperator:v(Nt),definitionOperator:v(Nt),typeOperator:v(Nt),controlOperator:v(Nt),punctuation:$s,separator:v($s),bracket:ti,angleBracket:v(ti),squareBracket:v(ti),paren:v(ti),brace:v(ti),content:Ft,heading:ye,heading1:v(ye),heading2:v(ye),heading3:v(ye),heading4:v(ye),heading5:v(ye),heading6:v(ye),contentSeparator:v(Ft),list:v(Ft),quote:v(Ft),emphasis:v(Ft),strong:v(Ft),link:v(Ft),monospace:v(Ft),strikethrough:v(Ft),inserted:v(),deleted:v(),changed:v(),invalid:v(),meta:Ki,documentMeta:v(Ki),annotation:v(Ki),processingInstruction:v(Ki),definition:xt.defineModifier("definition"),constant:xt.defineModifier("constant"),function:xt.defineModifier("function"),standard:xt.defineModifier("standard"),local:xt.defineModifier("local"),special:xt.defineModifier("special")};for(let s in C){let t=C[s];t instanceof xt&&(t.name=s)}Dh([{tag:C.link,class:"tok-link"},{tag:C.heading,class:"tok-heading"},{tag:C.emphasis,class:"tok-emphasis"},{tag:C.strong,class:"tok-strong"},{tag:C.keyword,class:"tok-keyword"},{tag:C.atom,class:"tok-atom"},{tag:C.bool,class:"tok-bool"},{tag:C.url,class:"tok-url"},{tag:C.labelName,class:"tok-labelName"},{tag:C.inserted,class:"tok-inserted"},{tag:C.deleted,class:"tok-deleted"},{tag:C.literal,class:"tok-literal"},{tag:C.string,class:"tok-string"},{tag:C.number,class:"tok-number"},{tag:[C.regexp,C.escape,C.special(C.string)],class:"tok-string2"},{tag:C.variableName,class:"tok-variableName"},{tag:C.local(C.variableName),class:"tok-variableName tok-local"},{tag:C.definition(C.variableName),class:"tok-variableName tok-definition"},{tag:C.special(C.variableName),class:"tok-variableName2"},{tag:C.definition(C.propertyName),class:"tok-propertyName tok-definition"},{tag:C.typeName,class:"tok-typeName"},{tag:C.namespace,class:"tok-namespace"},{tag:C.className,class:"tok-className"},{tag:C.macroName,class:"tok-macroName"},{tag:C.propertyName,class:"tok-propertyName"},{tag:C.operator,class:"tok-operator"},{tag:C.comment,class:"tok-comment"},{tag:C.meta,class:"tok-meta"},{tag:C.invalid,class:"tok-invalid"},{tag:C.punctuation,class:"tok-punctuation"}]);var Zn;const De=new B;function lu(s){return P.define({combine:s?t=>t.concat(s):void 0})}const hu=new B;class Pt{constructor(t,e,i=[],n=""){this.data=t,this.name=n,F.prototype.hasOwnProperty("tree")||Object.defineProperty(F.prototype,"tree",{get(){return gt(this)}}),this.parser=e,this.extension=[Ke.of(this),F.languageData.of((r,o,l)=>{let h=Mo(r,o,l),f=h.type.prop(De);if(!f)return[];let a=r.facet(f),c=h.type.prop(hu);if(c){let u=h.resolve(o-h.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(a)}}return a})].concat(i)}isActiveAt(t,e,i=-1){return Mo(t,e,i).type.prop(De)==this.data}findRegions(t){let e=t.facet(Ke);if((e==null?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(De)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(B.mounted);if(l){if(l.tree.prop(De)==this.data){if(l.overlay)for(let h of l.overlay)i.push({from:h.from+o,to:h.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let h=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>h)return}}for(let h=0;h<r.children.length;h++){let f=r.children[h];f instanceof X&&n(f,r.positions[h]+o)}};return n(gt(t),0),i}get allowsNesting(){return!0}}Pt.setState=R.define();function Mo(s,t,e){let i=s.facet(Ke),n=gt(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(t,e,J.ExcludeBuffers))r.type.isTop&&(n=r);return n}class mn extends Pt{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=lu(t.languageData);return new mn(e,t.parser.configure({props:[De.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new mn(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function gt(s){let t=s.field(Pt.state,!1);return t?t.tree:X.empty}class au{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let ei=null;class yn{constructor(t,e,i=[],n,r,o,l,h){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=h,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new yn(t,e,[],X.empty,0,i,[],null)}startParse(){return this.parser.startParse(new au(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=X.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let n=Date.now()+t;t=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(ve.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<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(ve.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=ei;ei=this;try{return t()}finally{ei=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=To(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let h=[];if(t.iterChangedRanges((f,a,c,u)=>h.push({fromA:f,toA:a,fromB:c,toB:u})),i=ve.applyChanges(i,h),n=X.empty,r=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let f of this.skipped){let a=t.mapPos(f.from,1),c=t.mapPos(f.to,-1);a<c&&l.push({from:a,to:c})}}}return new yn(this.parser,e,i,n,r,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<t.to&&r>t.from&&(this.fragments=To(this.fragments,n,r),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Mh{createParse(e,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let h=ei;if(h){for(let f of n)h.tempSkipped.push(f);t&&(h.scheduleOn=h.scheduleOn?Promise.all([h.scheduleOn,t]):t)}return this.parsedPos=o,new X(pt.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return ei}}function To(s,t,e){return ve.applyChanges(s,[{fromA:t,toA:e,fromB:t,toB:e}])}class Ue{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Ue(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=yn.create(t.facet(Ke).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Ue(i)}}Pt.state=ct.define({create:Ue.init,update(s,t){for(let e of t.effects)if(e.is(Pt.setState))return e.value;return t.startState.facet(Ke)!=t.state.facet(Ke)?Ue.init(t.state):s.apply(t)}});let Bh=s=>{let t=setTimeout(()=>s(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(Bh=s=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(s,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const ts=typeof navigator<"u"&&(!((Zn=navigator.scheduling)===null||Zn===void 0)&&Zn.isInputPending)?()=>navigator.scheduling.isInputPending():null,fu=At.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Pt.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Pt.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=Bh(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(Pt.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!ts?Math.max(25,t.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,h=r.context.work(()=>ts&&ts()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-e,(h||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Pt.setState.of(new Ue(r.context))})),this.chunkBudget>0&&!(h&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>at(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Ke=P.define({combine(s){return s.length?s[0]:null},enables:s=>[Pt.state,fu,T.contentAttributes.compute([s],t=>{let e=t.facet(s);return e&&e.name?{"data-language":e.name}:{}})]});class cu{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const uu=P.define(),Nn=P.define({combine:s=>{if(!s.length)return" ";let t=s[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(s[0]));return t}});function bn(s){let t=s.facet(Nn);return t.charCodeAt(0)==9?s.tabSize*t.length:t.length}function wn(s,t){let e="",i=s.tabSize,n=s.facet(Nn)[0];if(n==" "){for(;t>=i;)e+=" ",t-=i;n=" "}for(let r=0;r<t;r++)e+=n;return e}function Rh(s,t){s instanceof F&&(s=new Fn(s));for(let i of s.state.facet(uu)){let n=i(s,t);if(n!==void 0)return n}let e=gt(s.state);return e.length>=t?pu(s,e,t):null}class Fn{constructor(t,e={}){this.state=t,this.options=e,this.unit=bn(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==t?{text:"",from:t}:(e<0?n<t:n<=t)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(t,e);return i.slice(t-n,Math.min(i.length,t+100-n))}column(t,e=1){let{text:i,from:n}=this.lineAt(t,e),r=this.countColumn(i,t-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return Dn(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),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 du=new B;function pu(s,t,e){let i=t.resolveStack(e),n=t.resolveInner(e,-1).resolve(e,0).enterUnfinishedNodesBefore(e);if(n!=i.node){let r=[];for(let o=n;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return Eh(i,s,e)}function Eh(s,t,e){for(let i=s;i;i=i.next){let n=mu(i.node);if(n)return n(ur.create(t,e,i))}return 0}function gu(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function mu(s){let t=s.type.prop(du);if(t)return t;let e=s.firstChild,i;if(e&&(i=e.type.prop(B.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>xu(o,!0,1,void 0,r&&!gu(o)?n.from:void 0)}return s.parent==null?yu:null}function yu(){return 0}class ur extends Fn{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new ur(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(bu(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return Eh(this.context.next,this.base,this.pos)}}function bu(s,t){for(let e=t;e;e=e.parent)if(s==e)return!0;return!1}function wu(s){let t=s.node,e=t.childAfter(t.from),i=t.lastChild;if(!e)return null;let n=s.options.simulateBreak,r=s.state.doc.lineAt(e.from),o=n==null||n<=r.from?r.to:Math.min(r.to,n);for(let l=e.to;;){let h=t.childAfter(l);if(!h||h==i)return null;if(!h.type.isSkipped){if(h.from>=o)return null;let f=/^ */.exec(r.text.slice(e.to-r.from))[0].length;return{from:e.from,to:e.to+f}}l=h.to}}function xu(s,t,e,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,h=wu(s);return h?l?s.column(h.from):s.column(h.to):s.baseIndent+(l?0:s.unit*e)}class Vn{constructor(t,e){this.specs=t;let i;function n(l){let h=fe.newName();return(i||(i=Object.create(null)))["."+h]=l,h}const r=typeof e.all=="string"?e.all:e.all?n(e.all):void 0,o=e.scope;this.scope=o instanceof Pt?l=>l.prop(De)==o.data:o?l=>l==o:void 0,this.style=Dh(t.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new fe(i):null,this.themeType=e.themeType}static define(t,e){return new Vn(t,e||{})}}const qs=P.define(),ku=P.define({combine(s){return s.length?[s[0]]:null}});function es(s){let t=s.facet(qs);return t.length?t:s.facet(ku)}function vu(s,t){let e=[Cu],i;return s instanceof Vn&&(s.module&&e.push(T.styleModule.of(s.module)),i=s.themeType),i?e.push(qs.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(i=="dark")?[s]:[])):e.push(qs.of(s)),e}class Su{constructor(t){this.markCache=Object.create(null),this.tree=gt(t.state),this.decorations=this.buildDeco(t,es(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=gt(t.state),i=es(t.state),n=i!=es(t.startState),{viewport:r}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!n&&e.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return N.none;let i=new Ve;for(let{from:n,to:r}of t.visibleRanges)su(this.tree,e,(o,l,h)=>{i.add(o,l,this.markCache[h]||(this.markCache[h]=N.mark({class:h})))},n,r);return i.finish()}}const Cu=Qe.high(At.fromClass(Su,{decorations:s=>s.decorations})),Ou=T.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Lh=1e4,Ih="()[]{}",Nh=P.define({combine(s){return Pn(s,{afterCursor:!0,brackets:Ih,maxScanDistance:Lh,renderMatch:Tu})}}),Au=N.mark({class:"cm-matchingBracket"}),Mu=N.mark({class:"cm-nonmatchingBracket"});function Tu(s){let t=[],e=s.matched?Au:Mu;return t.push(e.range(s.start.from,s.start.to)),s.end&&t.push(e.range(s.end.from,s.end.to)),t}const Pu=ct.define({create(){return N.none},update(s,t){if(!t.docChanged&&!t.selection)return s;let e=[],i=t.state.facet(Nh);for(let n of t.state.selection.ranges){if(!n.empty)continue;let r=$t(t.state,n.head,-1,i)||n.head>0&&$t(t.state,n.head-1,1,i)||i.afterCursor&&($t(t.state,n.head,1,i)||n.head<t.state.doc.length&&$t(t.state,n.head+1,-1,i));r&&(e=e.concat(i.renderMatch(r,t.state)))}return N.set(e,!0)},provide:s=>T.decorations.from(s)}),Du=[Pu,Ou];function Bu(s={}){return[Nh.of(s),Du]}const Ru=new B;function Us(s,t,e){let i=s.prop(t<0?B.openedBy:B.closedBy);if(i)return i;if(s.name.length==1){let n=e.indexOf(s.name);if(n>-1&&n%2==(t<0?1:0))return[e[n+t]]}return null}function Ks(s){let t=s.type.prop(Ru);return t?t(s.node):s}function $t(s,t,e,i={}){let n=i.maxScanDistance||Lh,r=i.brackets||Ih,o=gt(s),l=o.resolveInner(t,e);for(let h=l;h;h=h.parent){let f=Us(h.type,e,r);if(f&&h.from<h.to){let a=Ks(h);if(a&&(e>0?t>=a.from&&t<a.to:t>a.from&&t<=a.to))return Eu(s,t,e,h,a,f,r)}}return Lu(s,t,e,o,l.type,n,r)}function Eu(s,t,e,i,n,r,o){let l=i.parent,h={from:n.from,to:n.to},f=0,a=l==null?void 0:l.cursor();if(a&&(e<0?a.childBefore(i.from):a.childAfter(i.to)))do if(e<0?a.to<=i.from:a.from>=i.to){if(f==0&&r.indexOf(a.type.name)>-1&&a.from<a.to){let c=Ks(a);return{start:h,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(Us(a.type,e,o))f++;else if(Us(a.type,-e,o)){if(f==0){let c=Ks(a);return{start:h,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}f--}}while(e<0?a.prevSibling():a.nextSibling());return{start:h,matched:!1}}function Lu(s,t,e,i,n,r,o){let l=e<0?s.sliceDoc(t-1,t):s.sliceDoc(t,t+1),h=o.indexOf(l);if(h<0||h%2==0!=e>0)return null;let f={from:e<0?t-1:t,to:e>0?t+1:t},a=s.doc.iterRange(t,e>0?s.doc.length:0),c=0;for(let u=0;!a.next().done&&u<=r;){let d=a.value;e<0&&(u+=d.length);let p=t+u*e;for(let g=e>0?0:d.length-1,m=e>0?d.length:-1;g!=m;g+=e){let y=o.indexOf(d[g]);if(!(y<0||i.resolveInner(p+g,1).type!=n))if(y%2==0==e>0)c++;else{if(c==1)return{start:f,end:{from:p+g,to:p+g+1},matched:y>>1==h>>1};c--}}e>0&&(u+=d.length)}return a.done?{start:f,matched:!1}:null}const Iu=Object.create(null),Po=[pt.none],Do=[],Bo=Object.create(null),Nu=Object.create(null);for(let[s,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Nu[s]=Fu(Iu,t);function is(s,t){Do.indexOf(s)>-1||(Do.push(s),console.warn(t))}function Fu(s,t){let e=[];for(let l of t.split(" ")){let h=[];for(let f of l.split(".")){let a=s[f]||C[f];a?typeof a=="function"?h.length?h=h.map(a):is(f,`Modifier ${f} used at start of tag`):h.length?is(f,`Tag ${f} used as modifier`):h=Array.isArray(a)?a:[a]:is(f,`Unknown highlighting tag ${f}`)}for(let f of h)e.push(f)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),n=i+" "+e.map(l=>l.id),r=Bo[n];if(r)return r.id;let o=Bo[n]=pt.define({id:Po.length,name:i,props:[Th({[i]:e})]});return Po.push(o),o.id}Q.RTL,Q.LTR;class Fh{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=gt(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),n=e.text.slice(i-e.from,this.pos-e.from),r=n.search(Vh(t,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(t,e,i){t=="abort"&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Ro(s){let t=Object.keys(s).join(""),e=/\w/.test(t);return e&&(t=t.replace(/\w/g,"")),`[${e?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function Vu(s){let t=Object.create(null),e=Object.create(null);for(let{label:n}of s){t[n[0]]=!0;for(let r=1;r<n.length;r++)e[n[r]]=!0}let i=Ro(t)+Ro(e)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Hu(s){let t=s.map(n=>typeof n=="string"?{label:n}:n),[e,i]=t.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:Vu(t);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:t,validFor:e}:null}}class Eo{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function Se(s){return s.selection.main.from}function Vh(s,t){var e;let{source:i}=s,n=t&&i[0]!="^",r=i[i.length-1]!="$";return!n&&!r?s:new RegExp(`${n?"^":""}(?:${i})${r?"$":""}`,(e=s.flags)!==null&&e!==void 0?e:s.ignoreCase?"i":"")}const dr=Zt.define();function zu(s,t,e,i){let{main:n}=s.selection,r=e-n.from,o=i-n.from;return Object.assign(Object.assign({},s.changeByRange(l=>{if(l!=n&&e!=i&&s.sliceDoc(l.from+r,l.from+o)!=s.sliceDoc(e,i))return{range:l};let h=s.toText(t);return{changes:{from:l.from+r,to:i==n.from?l.to:l.from+o,insert:h},range:b.cursor(l.from+r+h.length)}})),{scrollIntoView:!0,userEvent:"input.complete"})}const Lo=new WeakMap;function Wu(s){if(!Array.isArray(s))return s;let t=Lo.get(s);return t||Lo.set(s,t=Hu(s)),t}const xn=R.define(),wi=R.define();class $u{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e<t.length;){let i=Vt(t,e),n=ne(i);this.chars.push(i);let r=t.slice(e,e+n),o=r.toUpperCase();this.folded.push(Vt(o==r?r.toLowerCase():o,0)),e+=n}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:e,folded:i,any:n,precise:r,byWord:o}=this;if(e.length==1){let w=Vt(t,0),x=ne(w),k=x==t.length?0:-100;if(w!=e[0])if(w==i[0])k+=-200;else return null;return this.ret(k,[0,x])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let h=e.length,f=0;if(l<0){for(let w=0,x=Math.min(t.length,200);w<x&&f<h;){let k=Vt(t,w);(k==e[f]||k==i[f])&&(n[f++]=w),w+=ne(k)}if(f<h)return null}let a=0,c=0,u=!1,d=0,p=-1,g=-1,m=/[a-z]/.test(t),y=!0;for(let w=0,x=Math.min(t.length,200),k=0;w<x&&c<h;){let S=Vt(t,w);l<0&&(a<h&&S==e[a]&&(r[a++]=w),d<h&&(S==e[d]||S==i[d]?(d==0&&(p=w),g=w+1,d++):d=0));let A,M=S<255?S>=48&&S<=57||S>=97&&S<=122?2:S>=65&&S<=90?1:0:(A=ul(S))!=A.toLowerCase()?1:A!=A.toUpperCase()?2:0;(!w||M==1&&m||k==0&&M!=0)&&(e[c]==S||i[c]==S&&(u=!0)?o[c++]=w:o.length&&(y=!1)),k=M,w+=ne(S)}return c==h&&o[0]==0&&y?this.result(-100+(u?-200:0),o,t):d==h&&p==0?this.ret(-200-t.length+(g==t.length?0:-100),[0,g]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):d==h?this.ret(-900-t.length,[p,g]):c==h?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,t):e.length==2?null:this.result((n[0]?-700:0)+-200+-1100,n,t)}result(t,e,i){let n=[],r=0;for(let o of e){let l=o+(this.astral?ne(Vt(i,o)):1);r&&n[r-1]==o?n[r-1]=l:(n[r++]=o,n[r++]=l)}return this.ret(t-i.length,n)}}class qu{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let e=t.slice(0,this.pattern.length),i=e==this.pattern?0:e.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,e.length],this.score=i+(t.length==this.pattern.length?0:-100),this)}}const Z=P.define({combine(s){return Pn(s,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Uu,filterStrict:!1,compareCompletions:(t,e)=>t.label.localeCompare(e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>Io(t(i),e(i)),optionClass:(t,e)=>i=>Io(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})}});function Io(s,t){return s?t?s+" "+t:s:t}function Uu(s,t,e,i,n,r){let o=s.textDirection==Q.RTL,l=o,h=!1,f="top",a,c,u=t.left-n.left,d=n.right-t.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))a=Math.max(n.top,Math.min(e.top,n.bottom-g))-t.top,c=Math.min(400,l?u:d);else{h=!0,c=Math.min(400,(o?t.right:n.right-t.left)-30);let w=n.bottom-t.bottom;w>=g||w>t.top?a=e.bottom-t.top:(f="bottom",a=t.bottom-e.top)}let m=(t.bottom-t.top)/r.offsetHeight,y=(t.right-t.left)/r.offsetWidth;return{style:`${f}: ${a/m}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(h?o?"left-narrow":"right-narrow":l?"left":"right")}}function Ku(s){let t=s.addToOptions.slice();return s.icons&&t.push({render(e){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),e.type&&i.classList.add(...e.type.split(/\s+/g).map(n=>"cm-completionIcon-"+n)),i.setAttribute("aria-hidden","true"),i},position:20}),t.push({render(e,i,n,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=e.displayLabel||e.label,h=0;for(let f=0;f<r.length;){let a=r[f++],c=r[f++];a>h&&o.appendChild(document.createTextNode(l.slice(h,a)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(a,c))),u.className="cm-completionMatchedText",h=c}return h<l.length&&o.appendChild(document.createTextNode(l.slice(h))),o},position:50},{render(e){if(!e.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=e.detail,i},position:80}),t.sort((e,i)=>e.position-i.position).map(e=>e.render)}function ns(s,t,e){if(s<=e)return{from:0,to:s};if(t<0&&(t=0),t<=s>>1){let n=Math.floor(t/e);return{from:n*e,to:(n+1)*e}}let i=Math.floor((s-t)/e);return{from:s-(i+1)*e,to:s-i*e}}class ju{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:h=>this.placeInfo(h),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:r,selected:o}=n.open,l=t.state.facet(Z);this.optionContent=Ku(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=ns(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",h=>{let{options:f}=t.state.field(e).open;for(let a=h.target,c;a&&a!=this.dom;a=a.parentNode)if(a.nodeName=="LI"&&(c=/-(\d+)$/.exec(a.id))&&+c[1]<f.length){this.applyCompletion(t,f[+c[1]]),h.preventDefault();return}}),this.dom.addEventListener("focusout",h=>{let f=t.state.field(this.stateField,!1);f&&f.tooltip&&t.state.facet(Z).closeOnBlur&&h.relatedTarget!=t.contentDOM&&t.dispatch({effects:wi.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:r,selected:o,disabled:l}=i.open;(!n.open||n.open.options!=r)&&(this.range=ns(r.length,o,t.state.facet(Z).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((e=n.open)===null||e===void 0?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of e.split(" "))i&&this.dom.classList.add(i);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;if((e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=ns(e.options.length,e.selected,this.view.state.facet(Z).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.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)==t&&this.addInfoPane(o,i)}).catch(o=>at(this.view.state,o,"completion info")):this.addInfoPane(r,i)}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",t.nodeType!=null)i.appendChild(t),this.infoDestroy=null;else{let{dom:n,destroy:r}=t;i.appendChild(n),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)i.nodeName!="LI"||!i.id?n--:n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected");return e&&Yu(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return n.top>Math.min(r.bottom,e.bottom)-10||n.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(Z).positionInfo(this.view,e,n,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const n=document.createElement("ul");n.id=e,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",o=>{o.target==n&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:h}=t[o],{section:f}=l;if(f){let u=typeof f=="string"?f:f.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof f!="string"&&f.header)n.appendChild(f.header(f));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const a=n.appendChild(document.createElement("li"));a.id=e+"-"+o,a.setAttribute("role","option");let c=this.optionClass(l);c&&(a.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,h);d&&a.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Qu(s,t){return e=>new ju(e,s,t)}function Yu(s,t){let e=s.getBoundingClientRect(),i=t.getBoundingClientRect(),n=e.height/s.offsetHeight;i.top<e.top?s.scrollTop-=(e.top-i.top)/n:i.bottom>e.bottom&&(s.scrollTop+=(i.bottom-e.bottom)/n)}function No(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function Gu(s,t){let e=[],i=null,n=f=>{e.push(f);let{section:a}=f.completion;if(a){i||(i=[]);let c=typeof a=="string"?a:a.name;i.some(u=>u.name==c)||i.push(typeof a=="string"?{name:c}:a)}},r=t.facet(Z);for(let f of s)if(f.hasResult()){let a=f.result.getMatch;if(f.result.filter===!1)for(let c of f.result.options)n(new Eo(c,f.source,a?a(c):[],1e9-e.length));else{let c=t.sliceDoc(f.from,f.to),u,d=r.filterStrict?new qu(c):new $u(c);for(let p of f.result.options)if(u=d.match(p.label)){let g=p.displayLabel?a?a(p,u.matched):[]:u.matched;n(new Eo(p,f.source,g,u.score+(p.boost||0)))}}}if(i){let f=Object.create(null),a=0,c=(u,d)=>{var p,g;return((p=u.rank)!==null&&p!==void 0?p:1e9)-((g=d.rank)!==null&&g!==void 0?g:1e9)||(u.name<d.name?-1:1)};for(let u of i.sort(c))a-=1e5,f[u.name]=a;for(let u of e){let{section:d}=u.completion;d&&(u.score+=f[typeof d=="string"?d:d.name])}}let o=[],l=null,h=r.compareCompletions;for(let f of e.sort((a,c)=>c.score-a.score||h(a.completion,c.completion))){let a=f.completion;!l||l.label!=a.label||l.detail!=a.detail||l.type!=null&&a.type!=null&&l.type!=a.type||l.apply!=a.apply||l.boost!=a.boost?o.push(f):No(f.completion)>No(l)&&(o[o.length-1]=f),l=f.completion}return o}class Be{constructor(t,e,i,n,r,o){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=o}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Be(this.options,Fo(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,r,o){if(n&&!o&&t.some(f=>f.isPending))return n.setDisabled();let l=Gu(t,e);if(!l.length)return n&&t.some(f=>f.isPending)?n.setDisabled():null;let h=e.facet(Z).selectOnOpen?0:-1;if(n&&n.selected!=h&&n.selected!=-1){let f=n.options[n.selected].completion;for(let a=0;a<l.length;a++)if(l[a].completion==f){h=a;break}}return new Be(l,Fo(i,h),{pos:t.reduce((f,a)=>a.hasResult()?Math.min(f,a.from):f,1e8),create:ed,above:r.aboveCursor},n?n.timestamp:Date.now(),h,!1)}map(t){return new Be(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}setDisabled(){return new Be(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class kn{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new kn(Zu,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:e}=t,i=e.facet(Z),r=(i.override||e.languageDataAt("autocomplete",Se(e)).map(Wu)).map(h=>(this.active.find(a=>a.source==h)||new vt(h,this.active.some(a=>a.state!=0)?1:0)).update(t,i));r.length==this.active.length&&r.every((h,f)=>h==this.active[f])&&(r=this.active);let o=this.open,l=t.effects.some(h=>h.is(pr));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||r.some(h=>h.hasResult()&&t.changes.touchesRange(h.from,h.to))||!Xu(r,this.active)||l?o=Be.build(r,e,this.id,o,i,l):o&&o.disabled&&!r.some(h=>h.isPending)&&(o=null),!o&&r.every(h=>!h.isPending)&&r.some(h=>h.hasResult())&&(r=r.map(h=>h.hasResult()?new vt(h.source,0):h));for(let h of t.effects)h.is(zh)&&(o=o&&o.setSelected(h.value,this.id));return r==this.active&&o==this.open?this:new kn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?_u:Ju}}function Xu(s,t){if(s==t)return!0;for(let e=0,i=0;;){for(;e<s.length&&!s[e].hasResult();)e++;for(;i<t.length&&!t[i].hasResult();)i++;let n=e==s.length,r=i==t.length;if(n||r)return n==r;if(s[e++].result!=t[i++].result)return!1}}const _u={"aria-autocomplete":"list"},Ju={};function Fo(s,t){let e={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return t>-1&&(e["aria-activedescendant"]=s+"-"+t),e}const Zu=[];function Hh(s,t){if(s.isUserEvent("input.complete")){let i=s.annotation(dr);if(i&&t.activateOnCompletion(i))return 12}let e=s.isUserEvent("input.type");return e&&t.activateOnTyping?5:e?1:s.isUserEvent("delete.backward")?2:s.selection?8:s.docChanged?16:0}class vt{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(t,e){let i=Hh(t,e),n=this;(i&8||i&16&&this.touches(t))&&(n=new vt(n.source,0)),i&4&&n.state==0&&(n=new vt(this.source,1)),n=n.updateFor(t,i);for(let r of t.effects)if(r.is(xn))n=new vt(n.source,1,r.value);else if(r.is(wi))n=new vt(n.source,0);else if(r.is(pr))for(let o of r.value)o.source==n.source&&(n=o);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(Se(t.state))}}class Ie extends vt{constructor(t,e,i,n,r,o){super(t,3,e),this.limit=i,this.result=n,this.from=r,this.to=o}hasResult(){return!0}updateFor(t,e){var i;if(!(e&3))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let r=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=Se(t.state);if(l>o||!n||e&2&&(Se(t.startState)==this.from||l<this.limit))return new vt(this.source,e&4?1:0);let h=t.changes.mapPos(this.limit);return td(n.validFor,t.state,r,o)?new Ie(this.source,this.explicit,h,n,r,o):n.update&&(n=n.update(n,r,o,new Fh(t.state,l,!1)))?new Ie(this.source,this.explicit,h,n,n.from,(i=n.to)!==null&&i!==void 0?i:Se(t.state)):new vt(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new Ie(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new vt(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function td(s,t,e,i){if(!s)return!1;let n=t.sliceDoc(e,i);return typeof s=="function"?s(n,e,i,t):Vh(s,!0).test(n)}const pr=R.define({map(s,t){return s.map(e=>e.map(t))}}),zh=R.define(),rt=ct.define({create(){return kn.start()},update(s,t){return s.update(t)},provide:s=>[$e.from(s,t=>t.tooltip),T.contentAttributes.from(s,t=>t.attrs)]});function gr(s,t){const e=t.completion.apply||t.completion.label;let i=s.state.field(rt).active.find(n=>n.source==t.source);return i instanceof Ie?(typeof e=="string"?s.dispatch(Object.assign(Object.assign({},zu(s.state,e,i.from,i.to)),{annotations:dr.of(t.completion)})):e(s,t.completion,i.from,i.to),!0):!1}const ed=Qu(rt,gr);function ji(s,t="option"){return e=>{let i=e.state.field(rt,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<e.state.facet(Z).interactionDelay)return!1;let n=1,r;t=="page"&&(r=vh(e,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=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),e.dispatch({effects:zh.of(l)}),!0}}const id=s=>{let t=s.state.field(rt,!1);return s.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<s.state.facet(Z).interactionDelay?!1:gr(s,t.open.options[t.open.selected])},ci=s=>s.state.field(rt,!1)?(s.dispatch({effects:xn.of(!0)}),!0):!1,nd=s=>{let t=s.state.field(rt,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(s.dispatch({effects:wi.of(null)}),!0)};class sd{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const rd=50,od=1e3,ld=At.fromClass(class{constructor(s){this.view=s,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of s.state.field(rt).active)t.isPending&&this.startQuery(t)}update(s){let t=s.state.field(rt),e=s.state.facet(Z);if(!s.selectionSet&&!s.docChanged&&s.startState.field(rt)==t)return;let i=s.transactions.some(r=>{let o=Hh(r,e);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&s.docChanged||o.updates.length+s.transactions.length>rd&&Date.now()-o.time>od){for(let l of o.context.abortListeners)try{l()}catch(h){at(this.view.state,h)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...s.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),s.transactions.some(r=>r.effects.some(o=>o.is(xn)))&&(this.pendingStart=!0);let n=this.pendingStart?50:e.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(r=>r.isPending&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),n):-1,this.composing!=0)for(let r of s.transactions)r.isUserEvent("input.type")?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:s}=this.view,t=s.field(rt);for(let e of t.active)e.isPending&&!this.running.some(i=>i.active.source==e.source)&&this.startQuery(e);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Z).updateSyncTime))}startQuery(s){let{state:t}=this.view,e=Se(t),i=new Fh(t,e,s.explicit,this.view),n=new sd(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:wi.of(null)}),at(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(Z).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],e=this.view.state.facet(Z),i=this.view.state.field(rt);for(let n=0;n<this.running.length;n++){let r=this.running[n];if(r.done===void 0)continue;if(this.running.splice(n--,1),r.done){let l=Se(r.updates.length?r.updates[0].startState:this.view.state),h=Math.min(l,r.done.from+(r.active.explicit?0:1)),f=new Ie(r.active.source,r.active.explicit,h,r.done,r.done.from,(s=r.done.to)!==null&&s!==void 0?s:l);for(let a of r.updates)f=f.update(a,e);if(f.hasResult()){t.push(f);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new vt(r.active.source,0);for(let h of r.updates)l=l.update(h,e);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:pr.of(t)})}},{eventHandlers:{blur(s){let t=this.view.state.field(rt,!1);if(t&&t.tooltip&&this.view.state.facet(Z).closeOnBlur){let e=t.open&&vh(this.view,t.open.tooltip);(!e||!e.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:wi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:xn.of(!1)}),20),this.composing=0}}}),hd=typeof navigator=="object"&&/Win/.test(navigator.platform),ad=Qe.highest(T.domEventHandlers({keydown(s,t){let e=t.state.field(rt,!1);if(!e||!e.open||e.open.disabled||e.open.selected<0||s.key.length>1||s.ctrlKey&&!(hd&&s.altKey)||s.metaKey)return!1;let i=e.open.options[e.open.selected],n=e.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||n.result.commitCharacters;return r&&r.indexOf(s.key)>-1&&gr(t,i),!1}})),Wh=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",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class fd{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}}class mr{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,nt.TrackDel),i=t.mapPos(this.to,1,nt.TrackDel);return e==null||i==null?null:new mr(this.field,e,i)}}class yr{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],r=t.doc.lineAt(e),o=/^\s*/.exec(r.text)[0];for(let h of this.lines){if(i.length){let f=o,a=/^\t*/.exec(h)[0].length;for(let c=0;c<a;c++)f+=t.facet(Nn);n.push(e+f.length-a),h=f+h.slice(a)}i.push(h),e+=h.length+1}let l=this.fieldPositions.map(h=>new mr(h.field,n[h.line]+h.from,n[h.line]+h.to));return{text:i,ranges:l}}static parse(t){let e=[],i=[],n=[],r;for(let o of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^}]*))?|((?:\\[{}]|[^}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,h=r[2]||r[3]||"",f=-1,a=h.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c<e.length;c++)(l!=null?e[c].seq==l:a&&e[c].name==a)&&(f=c);if(f<0){let c=0;for(;c<e.length&&(l==null||e[c].seq!=null&&e[c].seq<l);)c++;e.splice(c,0,{seq:l,name:a}),f=c;for(let u of n)u.field>=f&&u.field++}n.push(new fd(f,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+h+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,h,f)=>{for(let a of n)a.line==i.length&&a.from>f&&(a.from--,a.to--);return h}),i.push(o)}return new yr(i,n)}}let cd=N.widget({widget:new class extends ki{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),ud=N.mark({class:"cm-snippetField"});class Ye{constructor(t,e){this.ranges=t,this.active=e,this.deco=N.set(t.map(i=>(i.from==i.to?cd:ud).range(i.from,i.to)))}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new Ye(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}}const Ci=R.define({map(s,t){return s&&s.map(t)}}),dd=R.define(),xi=ct.define({create(){return null},update(s,t){for(let e of t.effects){if(e.is(Ci))return e.value;if(e.is(dd)&&s)return new Ye(s.ranges,e.value)}return s&&t.docChanged&&(s=s.map(t.changes)),s&&t.selection&&!s.selectionInsideField(t.selection)&&(s=null),s},provide:s=>T.decorations.from(s,t=>t?t.deco:N.none)});function br(s,t){return b.create(s.filter(e=>e.field==t).map(e=>b.range(e.from,e.to)))}function pd(s){let t=yr.parse(s);return(e,i,n,r)=>{let{text:o,ranges:l}=t.instantiate(e.state,n),{main:h}=e.state.selection,f={changes:{from:n,to:r==h.from?h.to:r,insert:L.of(o)},scrollIntoView:!0,annotations:i?[dr.of(i),G.userEvent.of("input.complete")]:void 0};if(l.length&&(f.selection=br(l,0)),l.some(a=>a.field>0)){let a=new Ye(l,0),c=f.effects=[Ci.of(a)];e.state.field(xi,!1)===void 0&&c.push(R.appendConfig.of([xi,wd,xd,Wh]))}e.dispatch(e.state.update(f))}}function $h(s){return({state:t,dispatch:e})=>{let i=t.field(xi,!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 e(t.update({selection:br(i.ranges,n),effects:Ci.of(r?null:new Ye(i.ranges,n)),scrollIntoView:!0})),!0}}const gd=({state:s,dispatch:t})=>s.field(xi,!1)?(t(s.update({effects:Ci.of(null)})),!0):!1,md=$h(1),yd=$h(-1),bd=[{key:"Tab",run:md,shift:yd},{key:"Escape",run:gd}],Vo=P.define({combine(s){return s.length?s[0]:bd}}),wd=Qe.highest(Ln.compute([Vo],s=>s.facet(Vo))),xd=T.domEventHandlers({mousedown(s,t){let e=t.state.field(xi,!1),i;if(!e||(i=t.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=e.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==e.active?!1:(t.dispatch({selection:br(e.ranges,n.field),effects:Ci.of(e.ranges.some(r=>r.field>n.field)?new Ye(e.ranges,n.field):null),scrollIntoView:!0}),!0)}}),vn={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},ke=R.define({map(s,t){let e=t.mapPos(s,-1,nt.TrackAfter);return e??void 0}}),wr=new class extends Ce{};wr.startSide=1;wr.endSide=-1;const qh=ct.define({create(){return H.empty},update(s,t){if(s=s.map(t.changes),t.selection){let e=t.state.doc.lineAt(t.selection.main.head);s=s.update({filter:i=>i>=e.from&&i<=e.to})}for(let e of t.effects)e.is(ke)&&(s=s.update({add:[wr.range(e.value,e.value+1)]}));return s}});function kd(){return[Od,qh]}const ss="()[]{}<>«»»«[]{}";function vd(s){for(let t=0;t<ss.length;t+=2)if(ss.charCodeAt(t)==s)return ss.charAt(t+1);return ul(s<128?s:s+1)}function Sd(s,t){return s.languageDataAt("closeBrackets",t)[0]||vn}const Cd=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Od=T.inputHandler.of((s,t,e,i)=>{if((Cd?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&ne(Vt(i,0))==1||t!=n.from||e!=n.to)return!1;let r=Ad(s.state,i);return r?(s.dispatch(r),!0):!1});function Ad(s,t){let e=Sd(s,s.selection.main.head),i=e.brackets||vn.brackets;for(let n of i){let r=vd(Vt(n,0));if(t==n)return r==n?Pd(s,n,i.indexOf(n+n+n)>-1,e):Md(s,n,r,e.before||vn.before);if(t==r&&Uh(s,s.selection.main.from))return Td(s,n,r)}return null}function Uh(s,t){let e=!1;return s.field(qh).between(0,s.doc.length,i=>{i==t&&(e=!0)}),e}function xr(s,t){let e=s.sliceString(t,t+2);return e.slice(0,ne(Vt(e,0)))}function Md(s,t,e,i){let n=null,r=s.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:e,from:o.to}],effects:ke.of(o.to+t.length),range:b.range(o.anchor+t.length,o.head+t.length)};let l=xr(s.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:t+e,from:o.head},effects:ke.of(o.head+t.length),range:b.cursor(o.head+t.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Td(s,t,e){let i=null,n=s.changeByRange(r=>r.empty&&xr(s.doc,r.head)==e?{changes:{from:r.head,to:r.head+e.length,insert:e},range:b.cursor(r.head+e.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function Pd(s,t,e,i){let n=i.stringPrefixes||vn.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:ke.of(l.to+t.length),range:b.range(l.anchor+t.length,l.head+t.length)};let h=l.head,f=xr(s.doc,h),a;if(f==t){if(Ho(s,h))return{changes:{insert:t+t,from:h},effects:ke.of(h+t.length),range:b.cursor(h+t.length)};if(Uh(s,h)){let u=e&&s.sliceDoc(h,h+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:h,to:h+u.length,insert:u},range:b.cursor(h+u.length)}}}else{if(e&&s.sliceDoc(h-2*t.length,h)==t+t&&(a=zo(s,h-2*t.length,n))>-1&&Ho(s,a))return{changes:{insert:t+t+t+t,from:h},effects:ke.of(h+t.length),range:b.cursor(h+t.length)};if(s.charCategorizer(h)(f)!=kt.Word&&zo(s,h,n)>-1&&!Dd(s,h,t,n))return{changes:{insert:t+t,from:h},effects:ke.of(h+t.length),range:b.cursor(h+t.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Ho(s,t){let e=gt(s).resolveInner(t+1);return e.parent&&e.from==t}function Dd(s,t,e,i){let n=gt(s).resolveInner(t,-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+e.length+r)),h=l.indexOf(e);if(!h||h>-1&&i.indexOf(l.slice(0,h))>-1){let a=n.firstChild;for(;a&&a.from==n.from&&a.to-a.from>e.length+h;){if(s.sliceDoc(a.to-e.length,a.to)==e)return!1;a=a.firstChild}return!0}let f=n.to==t&&n.parent;if(!f)break;n=f}return!1}function zo(s,t,e){let i=s.charCategorizer(t);if(i(s.sliceDoc(t-1,t))!=kt.Word)return t;for(let n of e){let r=t-n.length;if(s.sliceDoc(r,t)==n&&i(s.sliceDoc(r-1,r))!=kt.Word)return r}return-1}function Bd(s={}){return[ad,rt,Z.of(s),ld,Ed,Wh]}const Rd=[{key:"Ctrl-Space",run:ci},{mac:"Alt-`",run:ci},{key:"Escape",run:nd},{key:"ArrowDown",run:ji(!0)},{key:"ArrowUp",run:ji(!1)},{key:"PageDown",run:ji(!0,"page")},{key:"PageUp",run:ji(!1,"page")},{key:"Enter",run:id}],Ed=Qe.highest(Ln.computeN([Z],s=>s.facet(Z).defaultKeymap?[Rd]:[]));function Pg(s){let t=s.field(rt,!1);return t&&t.active.some(e=>e.isPending)?"pending":t&&t.active.some(e=>e.state!=0)?"active":null}const Wo=new WeakMap;function Dg(s){var t;let e=(t=s.field(rt,!1))===null||t===void 0?void 0:t.open;if(!e||e.disabled)return[];let i=Wo.get(e.options);return i||Wo.set(e.options,i=e.options.map(n=>n.completion)),i}const Ld=s=>{let{state:t}=s,e=t.doc.lineAt(t.selection.main.from),i=vr(s.state,e.from);return i.line?Id(s):i.block?Fd(s):!1};function kr(s,t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=s(t,e);return n?(i(e.update(n)),!0):!1}}const Id=kr(zd,0),Nd=kr(Kh,0),Fd=kr((s,t)=>Kh(s,t,Hd(t)),0);function vr(s,t){let e=s.languageDataAt("commentTokens",t,1);return e.length?e[0]:{}}const ii=50;function Vd(s,{open:t,close:e},i,n){let r=s.sliceDoc(i-ii,i),o=s.sliceDoc(n,n+ii),l=/\s*$/.exec(r)[0].length,h=/^\s*/.exec(o)[0].length,f=r.length-l;if(r.slice(f-t.length,f)==t&&o.slice(h,h+e.length)==e)return{open:{pos:i-l,margin:l&&1},close:{pos:n+h,margin:h&&1}};let a,c;n-i<=2*ii?a=c=s.sliceDoc(i,n):(a=s.sliceDoc(i,i+ii),c=s.sliceDoc(n-ii,n));let u=/^\s*/.exec(a)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-e.length;return a.slice(u,u+t.length)==t&&c.slice(p,p+e.length)==e?{open:{pos:i+u+t.length,margin:/\s/.test(a.charAt(u+t.length))?1:0},close:{pos:n-d-e.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function Hd(s){let t=[];for(let e of s.selection.ranges){let i=s.doc.lineAt(e.from),n=e.to<=i.to?i:s.doc.lineAt(e.to);n.from>i.from&&n.from==e.to&&(n=e.to==i.to+1?i:s.doc.lineAt(e.to-1));let r=t.length-1;r>=0&&t[r].to>i.from?t[r].to=n.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return t}function Kh(s,t,e=t.selection.ranges){let i=e.map(r=>vr(t,r.from).block);if(!i.every(r=>r))return null;let n=e.map((r,o)=>Vd(t,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:t.changes(e.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 h=i[o],{open:f,close:a}=l;r.push({from:f.pos-h.open.length,to:f.pos+f.margin},{from:a.pos-a.margin,to:a.pos+h.close.length})}return{changes:r}}return null}function zd(s,t,e=t.selection.ranges){let i=[],n=-1;for(let{from:r,to:o}of e){let l=i.length,h=1e9,f=vr(t,r).line;if(f){for(let a=r;a<=o;){let c=t.doc.lineAt(a);if(c.from>n&&(r==o||o>c.from)){n=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+f.length)==f?u:-1;u<c.text.length&&u<h&&(h=u),i.push({line:c,comment:p,token:f,indent:u,empty:d,single:!1})}a=c.to+1}if(h<1e9)for(let a=l;a<i.length;a++)i[a].indent<i[a].line.text.length&&(i[a].indent=h);i.length==l+1&&(i[l].single=!0)}}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:h,indent:f,empty:a,single:c}of i)(c||!a)&&r.push({from:l.from+f,insert:h+" "});let o=t.changes(r);return{changes:o,selection:t.selection.map(o,1)}}else if(s!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:h}of i)if(l>=0){let f=o.from+l,a=f+h.length;o.text[a-o.from]==" "&&a++,r.push({from:f,to:a})}return{changes:r}}return null}const js=Zt.define(),Wd=Zt.define(),$d=P.define(),jh=P.define({combine(s){return Pn(s,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}}),Qh=ct.define({create(){return qt.empty},update(s,t){let e=t.state.facet(jh),i=t.annotation(js);if(i){let h=dt.fromTransaction(t,i.selection),f=i.side,a=f==0?s.undone:s.done;return h?a=Sn(a,a.length,e.minDepth,h):a=Xh(a,t.startState.selection),new qt(f==0?i.rest:a,f==0?a:i.rest)}let n=t.annotation(Wd);if((n=="full"||n=="before")&&(s=s.isolate()),t.annotation(G.addToHistory)===!1)return t.changes.empty?s:s.addMapping(t.changes.desc);let r=dt.fromTransaction(t),o=t.annotation(G.time),l=t.annotation(G.userEvent);return r?s=s.addChanges(r,o,l,e,t):t.selection&&(s=s.addSelection(t.startState.selection,o,l,e.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(t=>t.toJSON()),undone:s.undone.map(t=>t.toJSON())}},fromJSON(s){return new qt(s.done.map(dt.fromJSON),s.undone.map(dt.fromJSON))}});function qd(s={}){return[Qh,jh.of(s),T.domEventHandlers({beforeinput(t,e){let i=t.inputType=="historyUndo"?Ud:t.inputType=="historyRedo"?Kd:null;return i?(t.preventDefault(),i(e)):!1}})]}function Yh(s,t){return function({state:e,dispatch:i}){if(!t&&e.readOnly)return!1;let n=e.field(Qh,!1);if(!n)return!1;let r=n.pop(s,e,t);return r?(i(r),!0):!1}}const Ud=Yh(0,!1),Kd=Yh(1,!1);class dt{constructor(t,e,i,n,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(t){return new dt(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(e=this.mapped)===null||e===void 0?void 0:e.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(t){return new dt(t.changes&&_.fromJSON(t.changes),[],t.mapped&&Kt.fromJSON(t.mapped),t.startSelection&&b.fromJSON(t.startSelection),t.selectionsAfter.map(b.fromJSON))}static fromTransaction(t,e){let i=St;for(let n of t.startState.facet($d)){let r=n(t);r.length&&(i=i.concat(r))}return!i.length&&t.changes.empty?null:new dt(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,St)}static selection(t){return new dt(void 0,St,void 0,void 0,t)}}function Sn(s,t,e,i){let n=t+1>e+20?t-e-1:0,r=s.slice(n,t);return r.push(i),r}function jd(s,t){let e=[],i=!1;return s.iterChangedRanges((n,r)=>e.push(n,r)),t.iterChangedRanges((n,r,o,l)=>{for(let h=0;h<e.length;){let f=e[h++],a=e[h++];l>=f&&o<=a&&(i=!0)}}),i}function Qd(s,t){return s.ranges.length==t.ranges.length&&s.ranges.filter((e,i)=>e.empty!=t.ranges[i].empty).length===0}function Gh(s,t){return s.length?t.length?s.concat(t):s:t}const St=[],Yd=200;function Xh(s,t){if(s.length){let e=s[s.length-1],i=e.selectionsAfter.slice(Math.max(0,e.selectionsAfter.length-Yd));return i.length&&i[i.length-1].eq(t)?s:(i.push(t),Sn(s,s.length-1,1e9,e.setSelAfter(i)))}else return[dt.selection([t])]}function Gd(s){let t=s[s.length-1],e=s.slice();return e[s.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),e}function rs(s,t){if(!s.length)return s;let e=s.length,i=St;for(;e;){let n=Xd(s[e-1],t,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,e);return r[e-1]=n,r}else t=n.mapped,e--,i=n.selectionsAfter}return i.length?[dt.selection(i)]:St}function Xd(s,t,e){let i=Gh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(t)):St,e);if(!s.changes)return dt.selection(i);let n=s.changes.map(t),r=t.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new dt(n,R.mapEffects(s.effects,t),o,s.startSelection.map(r),i)}const _d=/^(input\.type|delete)($|\.)/;class qt{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new qt(this.done,this.undone):this}addChanges(t,e,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!i||_d.test(i))&&(!l.selectionsAfter.length&&e-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,jd(l.changes,t.changes))||i=="input.type.compose")?o=Sn(o,o.length-1,n.minDepth,new dt(t.changes.compose(l.changes),Gh(R.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,St)):o=Sn(o,o.length,n.minDepth,t),new qt(o,St,e,i)}addSelection(t,e,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:St;return r.length>0&&e-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Qd(r[r.length-1],t)?this:new qt(Xh(this.done,t),this.undone,e,i)}addMapping(t){return new qt(rs(this.done,t),rs(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=t==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:js.of({side:t,rest:Gd(n),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?St:n.slice(0,n.length-1);return r.mapped&&(l=rs(l,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:js.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}qt.empty=new qt(St,St);function Ge(s,t){return b.create(s.ranges.map(t),s.mainIndex)}function Yt(s,t){return s.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function Rt({state:s,dispatch:t},e){let i=Ge(s.selection,e);return i.eq(s.selection,!0)?!1:(t(Yt(s,i)),!0)}function Hn(s,t){return b.cursor(t?s.to:s.from)}function _h(s,t){return Rt(s,e=>e.empty?s.moveByChar(e,t):Hn(e,t))}function lt(s){return s.textDirectionAt(s.state.selection.main.head)==Q.LTR}const Jh=s=>_h(s,!lt(s)),Zh=s=>_h(s,lt(s));function ta(s,t){return Rt(s,e=>e.empty?s.moveByGroup(e,t):Hn(e,t))}const Jd=s=>ta(s,!lt(s)),Zd=s=>ta(s,lt(s));function tp(s,t,e){if(t.type.prop(e))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(t.from,t.to)))||t.firstChild}function zn(s,t,e){let i=gt(s).resolveInner(t.head),n=e?B.closedBy:B.openedBy;for(let h=t.head;;){let f=e?i.childAfter(h):i.childBefore(h);if(!f)break;tp(s,f,n)?i=f:h=e?f.to:f.from}let r=i.type.prop(n),o,l;return r&&(o=e?$t(s,i.from,1):$t(s,i.to,-1))&&o.matched?l=e?o.end.to:o.end.from:l=e?i.to:i.from,b.cursor(l,e?-1:1)}const ep=s=>Rt(s,t=>zn(s.state,t,!lt(s))),ip=s=>Rt(s,t=>zn(s.state,t,lt(s)));function ea(s,t){return Rt(s,e=>{if(!e.empty)return Hn(e,t);let i=s.moveVertically(e,t);return i.head!=e.head?i:s.moveToLineBoundary(e,t)})}const ia=s=>ea(s,!1),na=s=>ea(s,!0);function sa(s){let t=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,e=0,i=0,n;if(t){for(let r of s.state.facet(T.scrollMargins)){let o=r(s);o!=null&&o.top&&(e=Math.max(o==null?void 0:o.top,e)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}n=s.scrollDOM.clientHeight-e-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:e,marginBottom:i,selfScroll:t,height:Math.max(s.defaultLineHeight,n-5)}}function ra(s,t){let e=sa(s),{state:i}=s,n=Ge(i.selection,o=>o.empty?s.moveVertically(o,t,e.height):Hn(o,t));if(n.eq(i.selection))return!1;let r;if(e.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),h=l.top+e.marginTop,f=l.bottom-e.marginBottom;o&&o.top>h&&o.bottom<f&&(r=T.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-h}))}return s.dispatch(Yt(i,n),{effects:r}),!0}const $o=s=>ra(s,!1),Qs=s=>ra(s,!0);function pe(s,t,e){let i=s.lineBlockAt(t.head),n=s.moveToLineBoundary(t,e);if(n.head==t.head&&n.head!=(e?i.to:i.from)&&(n=s.moveToLineBoundary(t,e,!1)),!e&&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&&t.head!=i.from+r&&(n=b.cursor(i.from+r))}return n}const np=s=>Rt(s,t=>pe(s,t,!0)),sp=s=>Rt(s,t=>pe(s,t,!1)),rp=s=>Rt(s,t=>pe(s,t,!lt(s))),op=s=>Rt(s,t=>pe(s,t,lt(s))),lp=s=>Rt(s,t=>b.cursor(s.lineBlockAt(t.head).from,1)),hp=s=>Rt(s,t=>b.cursor(s.lineBlockAt(t.head).to,-1));function ap(s,t,e){let i=!1,n=Ge(s.selection,r=>{let o=$t(s,r.head,-1)||$t(s,r.head,1)||r.head>0&&$t(s,r.head-1,1)||r.head<s.doc.length&&$t(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 b.cursor(l)});return i?(t(Yt(s,n)),!0):!1}const fp=({state:s,dispatch:t})=>ap(s,t);function Tt(s,t){let e=Ge(s.state.selection,i=>{let n=t(i);return b.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)});return e.eq(s.state.selection)?!1:(s.dispatch(Yt(s.state,e)),!0)}function oa(s,t){return Tt(s,e=>s.moveByChar(e,t))}const la=s=>oa(s,!lt(s)),ha=s=>oa(s,lt(s));function aa(s,t){return Tt(s,e=>s.moveByGroup(e,t))}const cp=s=>aa(s,!lt(s)),up=s=>aa(s,lt(s)),dp=s=>Tt(s,t=>zn(s.state,t,!lt(s))),pp=s=>Tt(s,t=>zn(s.state,t,lt(s)));function fa(s,t){return Tt(s,e=>s.moveVertically(e,t))}const ca=s=>fa(s,!1),ua=s=>fa(s,!0);function da(s,t){return Tt(s,e=>s.moveVertically(e,t,sa(s).height))}const qo=s=>da(s,!1),Uo=s=>da(s,!0),gp=s=>Tt(s,t=>pe(s,t,!0)),mp=s=>Tt(s,t=>pe(s,t,!1)),yp=s=>Tt(s,t=>pe(s,t,!lt(s))),bp=s=>Tt(s,t=>pe(s,t,lt(s))),wp=s=>Tt(s,t=>b.cursor(s.lineBlockAt(t.head).from)),xp=s=>Tt(s,t=>b.cursor(s.lineBlockAt(t.head).to)),Ko=({state:s,dispatch:t})=>(t(Yt(s,{anchor:0})),!0),jo=({state:s,dispatch:t})=>(t(Yt(s,{anchor:s.doc.length})),!0),Qo=({state:s,dispatch:t})=>(t(Yt(s,{anchor:s.selection.main.anchor,head:0})),!0),Yo=({state:s,dispatch:t})=>(t(Yt(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),kp=({state:s,dispatch:t})=>(t(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),vp=({state:s,dispatch:t})=>{let e=Wn(s).map(({from:i,to:n})=>b.range(i,Math.min(n+1,s.doc.length)));return t(s.update({selection:b.create(e),userEvent:"select"})),!0},Sp=({state:s,dispatch:t})=>{let e=Ge(s.selection,i=>{let n=gt(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return b.range(l.to,l.from)}return i});return e.eq(s.selection)?!1:(t(Yt(s,e)),!0)},Cp=({state:s,dispatch:t})=>{let e=s.selection,i=null;return e.ranges.length>1?i=b.create([e.main]):e.main.empty||(i=b.create([b.cursor(e.main.head)])),i?(t(Yt(s,i)),!0):!1};function Oi(s,t){if(s.state.readOnly)return!1;let e="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let h=t(r);h<o?(e="delete.backward",h=Qi(s,h,!1)):h>o&&(e="delete.forward",h=Qi(s,h,!0)),o=Math.min(o,h),l=Math.max(l,h)}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:e,effects:e=="delete.selection"?T.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Qi(s,t,e){if(s instanceof T)for(let i of s.state.facet(T.atomicRanges).map(n=>n(s)))i.between(t,t,(n,r)=>{n<t&&r>t&&(t=e?r:n)});return t}const pa=(s,t,e)=>Oi(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,h;if(e&&!t&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let f=Dn(l,r.tabSize),a=f%bn(r)||bn(r);for(let c=0;c<a&&l[l.length-1-c]==" ";c++)n--;h=n}else h=ht(o.text,n-o.from,t,t)+o.from,h==n&&o.number!=(t?r.doc.lines:1)?h+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(h-o.from,n-o.from))&&(h=ht(o.text,h-o.from,!1,!1)+o.from);return h}),Ys=s=>pa(s,!1,!0),ga=s=>pa(s,!0,!1),ma=(s,t)=>Oi(s,e=>{let i=e.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(t?r.to:r.from)){i==e.head&&r.number!=(t?n.doc.lines:1)&&(i+=t?1:-1);break}let h=ht(r.text,i-r.from,t)+r.from,f=r.text.slice(Math.min(i,h)-r.from,Math.max(i,h)-r.from),a=o(f);if(l!=null&&a!=l)break;(f!=" "||i!=e.head)&&(l=a),i=h}return i}),ya=s=>ma(s,!1),Op=s=>ma(s,!0),Ap=s=>Oi(s,t=>{let e=s.lineBlockAt(t.head).to;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),Mp=s=>Oi(s,t=>{let e=s.moveToLineBoundary(t,!1).head;return t.head>e?e:Math.max(0,t.head-1)}),Tp=s=>Oi(s,t=>{let e=s.moveToLineBoundary(t,!0).head;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),Pp=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:L.of(["",""])},range:b.cursor(i.from)}));return t(s.update(e,{scrollIntoView:!0,userEvent:"input"})),!0},Dp=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=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:ht(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:ht(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 e.changes.empty?!1:(t(s.update(e,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Wn(s){let t=[],e=-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)),e>=n.number){let o=t[t.length-1];o.to=r.to,o.ranges.push(i)}else t.push({from:n.from,to:r.to,ranges:[i]});e=r.number+1}return t}function ba(s,t,e){if(s.readOnly)return!1;let i=[],n=[];for(let r of Wn(s)){if(e?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(e?r.to+1:r.from-1),l=o.length+1;if(e){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let h of r.ranges)n.push(b.range(Math.min(s.doc.length,h.anchor+l),Math.min(s.doc.length,h.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let h of r.ranges)n.push(b.range(h.anchor-l,h.head-l))}}return i.length?(t(s.update({changes:i,scrollIntoView:!0,selection:b.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Bp=({state:s,dispatch:t})=>ba(s,t,!1),Rp=({state:s,dispatch:t})=>ba(s,t,!0);function wa(s,t,e){if(s.readOnly)return!1;let i=[];for(let n of Wn(s))e?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 t(s.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Ep=({state:s,dispatch:t})=>wa(s,t,!1),Lp=({state:s,dispatch:t})=>wa(s,t,!0),Ip=s=>{if(s.state.readOnly)return!1;let{state:t}=s,e=t.changes(Wn(t).map(({from:n,to:r})=>(n>0?n--:r<t.doc.length&&r++,{from:n,to:r}))),i=Ge(t.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(e);return s.dispatch({changes:e,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Np(s,t){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(t-1,t+1)))return{from:t,to:t};let e=gt(s).resolveInner(t),i=e.childBefore(t),n=e.childAfter(t),r;return i&&n&&i.to<=t&&n.from>=t&&(r=i.type.prop(B.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 Go=xa(!1),Fp=xa(!0);function xa(s){return({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(n=>{let{from:r,to:o}=n,l=t.doc.lineAt(r),h=!s&&r==o&&Np(t,r);s&&(r=o=(o<=l.to?l:t.doc.lineAt(o)).to);let f=new Fn(t,{simulateBreak:r,simulateDoubleBreak:!!h}),a=Rh(f,r);for(a==null&&(a=Dn(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;h?{from:r,to:o}=h:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",wn(t,a)];return h&&c.push(wn(t,f.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:L.of(c)},range:b.cursor(r+1+c[1].length)}});return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Sr(s,t){let e=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>e&&(i.empty||i.to>l.from)&&(t(l,n,i),e=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 Vp=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=Object.create(null),i=new Fn(s,{overrideIndentation:r=>{let o=e[r];return o??-1}}),n=Sr(s,(r,o,l)=>{let h=Rh(i,r.from);if(h==null)return;/\S/.test(r.text)||(h=0);let f=/^\s*/.exec(r.text)[0],a=wn(s,h);(f!=a||l.from<r.from+f.length)&&(e[r.from]=h,o.push({from:r.from,to:r.from+f.length,insert:a}))});return n.changes.empty||t(s.update(n,{userEvent:"indent"})),!0},ka=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Sr(s,(e,i)=>{i.push({from:e.from,insert:s.facet(Nn)})}),{userEvent:"input.indent"})),!0),va=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Sr(s,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let r=Dn(n,s.tabSize),o=0,l=wn(s,Math.max(0,r-bn(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:e.from+o,to:e.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Hp=s=>(s.setTabFocusMode(),!0),zp=[{key:"Ctrl-b",run:Jh,shift:la,preventDefault:!0},{key:"Ctrl-f",run:Zh,shift:ha},{key:"Ctrl-p",run:ia,shift:ca},{key:"Ctrl-n",run:na,shift:ua},{key:"Ctrl-a",run:lp,shift:wp},{key:"Ctrl-e",run:hp,shift:xp},{key:"Ctrl-d",run:ga},{key:"Ctrl-h",run:Ys},{key:"Ctrl-k",run:Ap},{key:"Ctrl-Alt-h",run:ya},{key:"Ctrl-o",run:Pp},{key:"Ctrl-t",run:Dp},{key:"Ctrl-v",run:Qs}],Wp=[{key:"ArrowLeft",run:Jh,shift:la,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Jd,shift:cp,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:rp,shift:yp,preventDefault:!0},{key:"ArrowRight",run:Zh,shift:ha,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Zd,shift:up,preventDefault:!0},{mac:"Cmd-ArrowRight",run:op,shift:bp,preventDefault:!0},{key:"ArrowUp",run:ia,shift:ca,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ko,shift:Qo},{mac:"Ctrl-ArrowUp",run:$o,shift:qo},{key:"ArrowDown",run:na,shift:ua,preventDefault:!0},{mac:"Cmd-ArrowDown",run:jo,shift:Yo},{mac:"Ctrl-ArrowDown",run:Qs,shift:Uo},{key:"PageUp",run:$o,shift:qo},{key:"PageDown",run:Qs,shift:Uo},{key:"Home",run:sp,shift:mp,preventDefault:!0},{key:"Mod-Home",run:Ko,shift:Qo},{key:"End",run:np,shift:gp,preventDefault:!0},{key:"Mod-End",run:jo,shift:Yo},{key:"Enter",run:Go,shift:Go},{key:"Mod-a",run:kp},{key:"Backspace",run:Ys,shift:Ys},{key:"Delete",run:ga},{key:"Mod-Backspace",mac:"Alt-Backspace",run:ya},{key:"Mod-Delete",mac:"Alt-Delete",run:Op},{mac:"Mod-Backspace",run:Mp},{mac:"Mod-Delete",run:Tp}].concat(zp.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),$p=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:ep,shift:dp},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:ip,shift:pp},{key:"Alt-ArrowUp",run:Bp},{key:"Shift-Alt-ArrowUp",run:Ep},{key:"Alt-ArrowDown",run:Rp},{key:"Shift-Alt-ArrowDown",run:Lp},{key:"Escape",run:Cp},{key:"Mod-Enter",run:Fp},{key:"Alt-l",mac:"Ctrl-l",run:vp},{key:"Mod-i",run:Sp,preventDefault:!0},{key:"Mod-[",run:va},{key:"Mod-]",run:ka},{key:"Mod-Alt-\\",run:Vp},{key:"Shift-Mod-k",run:Ip},{key:"Shift-Mod-\\",run:fp},{key:"Mod-/",run:Ld},{key:"Alt-A",run:Nd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Hp}].concat(Wp),qp={key:"Tab",run:ka,shift:va};function Up({util:s,dataSource:t,getDataSourceCallback:e}){const i=n=>{const r=s.unNormalizePropertyNamesExpression(n.doc.toString());return typeof e!="function"?[]:n.selection.ranges.map(o=>({...s.getAutocompleteData(r,o.to),range:o})).filter(({dataSourceKey:o,itemsType:l})=>l==="datasource"&&o&&o in t).map(({range:o,dataSourceKey:l,dataSourceValue:h})=>({pos:o.head,above:!0,arrow:!1,create:()=>{const f=e(l,h),a=document.createElement("div");return f&&(f.$widget.appendTo(a),setTimeout(()=>{f.$widget.trigger("content:changed")})),a.className="cm-tooltip-control",{dom:a}}}))};return[ct.define({create:i,update(n,r){return!r.docChanged&&!r.selection?n:i(r.state)},provide:n=>$e.computeN([n],r=>r.field(n))})]}const Kp=Th({Operator:C.operator,LiteralOperator:C.operator,GroupOperator:C.operator,Dot:C.punctuation,BracketOpen:C.bracket,BracketClose:C.bracket,"()":C.bracket,EntityName:C.variableName,PropertyName:C.propertyName,String:C.string,Number:C.integer,FunctionName:C.literal,Boolean:C.bool}),jp=Vn.define([{tag:C.name,class:"cm-tag-name"},{tag:C.variableName,class:"cm-tag-name"},{tag:C.propertyName,class:"cm-tag-property-name"},{tag:C.literal,class:"cm-tag-literal"},{tag:C.string,class:"cm-tag-string"},{tag:C.integer,class:"cm-tag-number"},{tag:C.unit,class:"cm-tag-literal"},{tag:C.null,class:"cm-tag-literal"},{tag:C.keyword,class:"cm-tag-punctuation"},{tag:C.punctuation,class:"cm-tag-punctuation"},{tag:C.derefOperator,class:"cm-tag-punctuation"},{tag:C.bracket,class:"cm-tag-punctuation"},{tag:C.operator,class:"cm-tag-operator"},{tag:C.bool,class:"cm-tag-boolean"}],{all:{class:"cm-tag-common"}});var Xo={};class Cn{constructor(t,e,i,n,r,o,l,h,f,a=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=n,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=h,this.curContext=f,this.lookAhead=a,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let n=t.parser.context;return new Cn(t,[],e,i,i,0,[],0,n?new _o(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,n=t&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25;o&&this.setLookAhead(this.pos);let l=r.dynamicPrecedence(n);if(l&&(this.score+=l),i==0){this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(n,this.reducePos);return}let h=this.stack.length-(i-1)*3-(t&262144?6:0),f=h?this.stack[h-2]:this.p.ranges[0].from,a=this.reducePos-f;a>=2e3&&!(!((e=this.p.parser.nodeSet.types[n])===null||e===void 0)&&e.isAnonymous)&&(f==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=a):this.p.lastBigReductionSize<a&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=f,this.p.lastBigReductionSize=a));let c=h?this.stack[h-1]:0,u=this.bufferBase+this.buffer.length-c;if(n<r.minRepeatTerm||t&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,f,d,u+4,!0)}if(t&262144)this.state=this.stack[h];else{let d=this.stack[h-3];this.state=r.getGoto(d,n,!0)}for(;this.stack.length>h;)this.stack.pop();this.reduceContext(n,f)}storeNode(t,e,i,n=4,r=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(e==i)return;if(o.buffer[l-2]>=e){o.buffer[l-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(t,e,i,n);else{let o=this.buffer.length;if(o>0&&this.buffer[o-4]!=0){let l=!1;for(let h=o;h>0&&this.buffer[h-2]>i;h-=4)if(this.buffer[h-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,n>4&&(n-=4)}this.buffer[o]=t,this.buffer[o+1]=e,this.buffer[o+2]=i,this.buffer[o+3]=n}}shift(t,e,i,n){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let r=t,{parser:o}=this.p;(n>this.pos||e<=o.maxNode)&&(this.pos=n,o.stateFlag(r,1)||(this.reducePos=n)),this.pushState(r,i),this.shiftContext(e,i),e<=o.maxNode&&this.buffer.push(e,i,n,4)}else this.pos=n,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,n,4)}apply(t,e,i,n){t&65536?this.reduce(t):this.shift(t,e,i,n)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let n=this.pos;this.reducePos=this.pos=n+t.length,this.pushState(e,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),n=t.bufferBase+e;for(;t&&n==t.bufferBase;)t=t.parent;return new Cn(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new Qp(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let n=[];for(let r=0,o;r<e.length;r+=2)(o=e[r+1])!=this.state&&this.p.parser.hasAction(o,t)&&n.push(e[r],o);if(this.stack.length<120)for(let r=0;n.length<8&&r<e.length;r+=2){let o=e[r+1];n.some((l,h)=>h&1&&l==o)||n.push(e[r],o)}e=n}let i=[];for(let n=0;n<e.length&&i.length<4;n+=2){let r=e[n+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(e[n],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,n=e&65535,r=this.stack.length-i*3;if(r<0||t.getGoto(this.stack[r],n,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;e=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(n,r)=>{if(!e.includes(n))return e.push(n),t.allActions(n,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let h=o&65535,f=this.stack.length-l*3;if(f>=0&&t.getGoto(this.stack[f],h,!1)>=0)return l<<19|65536|h}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new _o(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){t>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=t)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class _o{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class Qp{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,i=t>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let n=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=n}}class On{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new On(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}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]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new On(this.stack,this.pos,this.index)}}function Yi(s,t=Uint16Array){if(typeof s!="string")return s;let e=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let o=s.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let h=o-32;if(h>=46&&(h-=46,l=!0),r+=h,l)break;r*=46}e?e[n++]=r:e=new t(r)}return e}class sn{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const Jo=new sn;class Yp{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=Jo,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,n=this.rangeIndex,r=this.pos+t;for(;r<i.from;){if(!n)return null;let o=this.ranges[--n];r-=i.from-o.to,i=o}for(;e<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let o=this.ranges[++n];r+=o.from-i.to,i=o}return r}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,i,n;if(e>=0&&e<this.chunk.length)i=this.pos+t,n=this.chunk.charCodeAt(e);else{let r=this.resolveOffset(t,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)n=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),n=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),n}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=i}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=Jo,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let n of this.ranges){if(n.from>=e)break;n.to>t&&(i+=this.input.read(Math.max(n.from,t),Math.min(n.to,e)))}return i}}class Ne{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;Gp(this.data,t,e,this.id,i.data,i.tokenPrecTable)}}Ne.prototype.contextual=Ne.prototype.fallback=Ne.prototype.extend=!1;Ne.prototype.fallback=Ne.prototype.extend=!1;function Gp(s,t,e,i,n,r){let o=0,l=1<<i,{dialect:h}=e.p.parser;t:for(;(l&s[o])!=0;){let f=s[o+1];for(let d=o+3;d<f;d+=2)if((s[d+1]&l)>0){let p=s[d];if(h.allows(p)&&(t.token.value==-1||t.token.value==p||Xp(p,t.token.value,n,r))){t.acceptToken(p);break}}let a=t.next,c=0,u=s[o+2];if(t.next<0&&u>c&&s[f+u*3-3]==65535){o=s[f+u*3-1];continue t}for(;c<u;){let d=c+u>>1,p=f+d+(d<<1),g=s[p],m=s[p+1]||65536;if(a<g)u=d;else if(a>=m)c=d+1;else{o=s[p+2],t.advance();continue t}}break}}function Zo(s,t,e){for(let i=t,n;(n=s[i])!=65535;i++)if(n==e)return i-t;return-1}function Xp(s,t,e,i){let n=Zo(e,i,t);return n<0||Zo(e,i,s)<n}const mt=typeof process<"u"&&Xo&&/\bparse\b/.test(Xo.LOG);let os=null;function tl(s,t,e){let i=s.cursor(J.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(s.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:s.length}}class _p{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?tl(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?tl(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let i=this.trees[e],n=this.index[e];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],o=this.start[e]+i.positions[n];if(o>t)return this.nextStart=o,null;if(r instanceof X){if(o==t){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let h=r.prop(B.lookAhead);if(!h||l+h<this.fragment.to)return r}}this.index[e]++,o+r.length>=Math.max(this.safeFrom,t)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[e]++,this.nextStart=o+r.length}}}class Jp{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(i=>new sn)}getActions(t){let e=0,i=null,{parser:n}=t.p,{tokenizers:r}=n,o=n.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let f=0;f<r.length;f++){if((1<<f&o)==0)continue;let a=r[f],c=this.tokens[f];if(!(i&&!a.fallback)&&((a.contextual||c.start!=t.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,a,t),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let u=e;if(c.extended>-1&&(e=this.addActions(t,c.extended,c.end,e)),e=this.addActions(t,c.value,c.end,e),!a.extend&&(i=c,e>u))break}}for(;this.actions.length>e;)this.actions.pop();return h&&t.setLookAhead(h),!i&&t.pos==this.stream.end&&(i=new sn,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new sn,{pos:i,p:n}=t;return e.start=i,e.end=Math.min(i+1,n.stream.end),e.value=i==n.stream.end?n.parser.eofTerm:0,e}updateCachedToken(t,e,i){let n=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(n,t),i),t.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==t.value){let l=r.specializers[o](this.stream.read(t.start,t.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?t.value=l>>1:t.extended=l>>1;break}}}else t.value=0,t.end=this.stream.clipPos(n+1)}putAction(t,e,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==t)return n;return this.actions[n++]=t,this.actions[n++]=e,this.actions[n++]=i,n}addActions(t,e,i,n){let{state:r}=t,{parser:o}=t.p,{data:l}=o;for(let h=0;h<2;h++)for(let f=o.stateSlot(r,h?2:1);;f+=3){if(l[f]==65535)if(l[f+1]==1)f=Xt(l,f+2);else{n==0&&l[f+1]==2&&(n=this.putAction(Xt(l,f+2),e,i,n));break}l[f]==e&&(n=this.putAction(Xt(l,f+1),e,i,n))}return n}}class Zp{constructor(t,e,i,n){this.parser=t,this.input=e,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Yp(e,n),this.tokens=new Jp(t,this.stream),this.topTerm=t.top[1];let{from:r}=n[0];this.stacks=[Cn.start(this,t.top[0],r)],this.fragments=i.length&&this.stream.end-r>t.bufferLength*4?new _p(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,i=this.stacks=[],n,r;if(this.bigReductionCount>300&&t.length==1){let[o]=t;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<t.length;o++){let l=t[o];for(;;){if(this.tokens.mainToken=null,l.pos>e)i.push(l);else{if(this.advanceStack(l,i,t))continue;{n||(n=[],r=[]),n.push(l);let h=this.tokens.getMainToken(l);r.push(h.value,h.end)}}break}}if(!i.length){let o=n&&eg(n);if(o)return mt&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw mt&&n&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&n){let o=this.stoppedAt!=null&&n[0].pos>this.stoppedAt?n[0]:this.runRecovery(n,r,i);if(o)return mt&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,h)=>h.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>e)&&this.recovering--}else if(i.length>1){t:for(let o=0;o<i.length-1;o++){let l=i[o];for(let h=o+1;h<i.length;h++){let f=i[h];if(l.sameState(f)||l.buffer.length>500&&f.buffer.length>500)if((l.score-f.score||l.buffer.length-f.buffer.length)>0)i.splice(h--,1);else{i.splice(o--,1);continue t}}}i.length>12&&i.splice(12,i.length-12)}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,i){let n=t.pos,{parser:r}=this,o=mt?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let f=t.curContext&&t.curContext.tracker.strict,a=f?t.curContext.hash:0;for(let c=this.fragments.nodeAt(n);c;){let u=this.parser.nodeSet.types[c.type.id]==c.type?r.getGoto(t.state,c.type.id):-1;if(u>-1&&c.length&&(!f||(c.prop(B.contextHash)||0)==a))return t.useNode(c,u),mt&&console.log(o+this.stackID(t)+` (via reuse of ${r.getName(c.type.id)})`),!0;if(!(c instanceof X)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof X&&c.positions[0]==0)c=d;else break}}let l=r.stateSlot(t.state,4);if(l>0)return t.reduce(l),mt&&console.log(o+this.stackID(t)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let h=this.tokens.getActions(t);for(let f=0;f<h.length;){let a=h[f++],c=h[f++],u=h[f++],d=f==h.length||!i,p=d?t:t.split(),g=this.tokens.mainToken;if(p.apply(a,c,g?g.start:p.pos,u),mt&&console.log(o+this.stackID(p)+` (via ${(a&65536)==0?"shift":`reduce of ${r.getName(a&65535)}`} for ${r.getName(c)} @ ${n}${p==t?"":", split"})`),d)return!0;p.pos>n?e.push(p):i.push(p)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return el(t,e),!0}}runRecovery(t,e,i){let n=null,r=!1;for(let o=0;o<t.length;o++){let l=t[o],h=e[o<<1],f=e[(o<<1)+1],a=mt?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),mt&&console.log(a+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=a;for(let d=0;c.forceReduce()&&d<10&&(mt&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)mt&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))mt&&console.log(a+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(f==l.pos&&(f++,h=0),l.recoverByDelete(h,f),mt&&console.log(a+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),el(l,i)):(!n||n.score<l.score)&&(n=l)}return n}stackToTree(t){return t.close(),X.build({buffer:On.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(os||(os=new WeakMap)).get(t);return e||os.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function el(s,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==s.pos&&i.sameState(s)){t[e].score<s.score&&(t[e]=s);return}}t.push(s)}class tg{constructor(t,e,i){this.source=t,this.flags=e,this.disabled=i}allows(t){return!this.disabled||this.disabled[t]==0}}class An extends Mh{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let l=0;l<t.repeatNodeCount;l++)e.push("");let i=Object.keys(t.topRules).map(l=>t.topRules[l][1]),n=[];for(let l=0;l<e.length;l++)n.push([]);function r(l,h,f){n[l].push([h,h.deserialize(String(f))])}if(t.nodeProps)for(let l of t.nodeProps){let h=l[0];typeof h=="string"&&(h=B[h]);for(let f=1;f<l.length;){let a=l[f++];if(a>=0)r(a,h,l[f++]);else{let c=l[f+-a];for(let u=-a;u>0;u--)r(l[f++],h,c);f++}}}this.nodeSet=new hr(e.map((l,h)=>pt.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:n[h],top:i.indexOf(h)>-1,error:h==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(h)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=Sh;let o=Yi(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(il),this.states=Yi(t.states,Uint32Array),this.data=Yi(t.stateData),this.goto=Yi(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new Ne(o,l):l),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let n=new Zp(this,t,e,i);for(let r of this.wrappers)n=r(n,t,e,i);return n}getGoto(t,e,i=!1){let n=this.goto;if(e>=n[0])return-1;for(let r=n[e+1];;){let o=n[r++],l=o&1,h=n[r++];if(l&&i)return h;for(let f=r+(o>>1);r<f;r++)if(n[r]==t)return h;if(l)return-1}}hasAction(t,e){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(t,n?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=Xt(i,r+2)];else{if(i[r+1]==2)return Xt(i,r+2);break}if(o==e||o==0)return Xt(i,r+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),n=i?e(i):void 0;for(let r=this.stateSlot(t,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=Xt(this.data,r+2);else break;n=e(Xt(this.data,r+1))}return n}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=Xt(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];e.some((r,o)=>o&1&&r==n)||e.push(this.data[i],n)}}return e}configure(t){let e=Object.assign(Object.create(An.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let n=t.tokenizers.find(r=>r.from==i);return n?n.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=t.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return e.specializers[n]=il(o),o})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let r of t.split(" ")){let o=e.indexOf(r);o>=0&&(i[o]=!0)}let n=null;for(let r=0;r<e.length;r++)if(!i[r])for(let o=this.dialects[e[r]],l;(l=this.data[o++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[l]=1;return new tg(t,i,n)}static deserialize(t){return new An(t)}}function Xt(s,t){return s[t]|s[t+1]<<16}function eg(s){let t=null;for(let e of s){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function il(s){if(s.external){let t=s.extend?1:0;return(e,i)=>s.external(e,i)<<1|t}return s.get}const ig={__proto__:null,true:40,false:42,in:48,not:50,matches:52,or:56,and:58},ng=An.deserialize({version:14,states:"(WQYQPOOOOQO'#C_'#C_O!uQPO'#CdO!|QPO'#CaO#[QPO'#C`O#aQPO'#CiOOQO'#DY'#DYOOQO'#Da'#DaOOQO'#C^'#C^O#iQPO'#CzO#pQPO'#C}OOQO'#DX'#DXOOQO'#DO'#DOQYQPOOOOQO'#Cs'#CsOOQO'#Cw'#CwOOQO'#Ce'#CeOOQO'#DP'#DPO#wQPO'#D]O$gQPO'#DQO$qQPO'#D]O$yQPO,59OOOQO,58{,58{O%OQQO'#DRO%TQPO,58zO&hQSO,59TOOQO,59T,59TOOQO,59f,59fO&rQPO,59fOOQO,59i,59iO&yQPO,59iOOQO-E6|-E6|OOQO-E6}-E6}O'QQPO,59wO'YQPO,59lOOQO-E7O-E7OOOQO1G.j1G.jOOQO'#Ch'#ChOOQO,59m,59mOOQO-E7P-E7PO'dQPO'#D_O$OQPO'#D_OOQO'#Cl'#ClO'lQPO1G.oOOQO1G/Q1G/QOOQO1G/T1G/TO'qQSO'#DSO(OQPO,59yO(OQPO,59yOOQO7+$Z7+$ZOOQO,59n,59nO$OQPO,59nOOQO-E7Q-E7QO(WQPO1G/eOOQO1G/Y1G/Y",stateData:"(`~OyOSzOS~OVQO_XObUOcUOdUOeUOfVOh^Oi^Oj^Ol_Om_OpYO}PO!ORO~OVQOYcObUOcUOdUOeUO}PO!ORO~OU!PP~P!ZOVQOZTX_^X}^X~OZgO~O_iO}PO~OakO~PYOomO~PYOU!PX~P!ZOVQObUOcUOdUOeUO}PO!ORO~OUtXYtX~P$OOYcOU!PX~OUtO~O!QuO~OZgOVSa_SabSacSadSaeSafSahSaiSajSalSamSapSawSa}Sa!OSaUSaYSaaSaoSa~O!SyOa!RP~P$OOa|O~PYOo}O~PYOYcOU!Pa~OUtaYta~P$OOY!OOa!RX~Oa!RO~O!S!TOYvXavX~P$OOY!OOa!Ra~OY!OOa!Ri~O",goto:"&s!UPP!V!_!r#SPP#d#wPP#}!r$QP$bPPPPPP$ePPP!VPP!VPP!V$m${%V%a%gPPPP%q%yPP&eP&hP&k]ZOXY]lnlUOQXY]bcilnry!O!TRjTmUOQXY]bcilnry!O!TmSOQXY]bcilnry!O!TlUOQXY]bcilnry!O!TRfRXaQbcrRvgmTOQXY]bcilnry!O!TR{i]VOXY]lnQ]OQlXQnYVo]lnQbQSpbrRrcQdQQqbTsdqQhSRwhQ!PxS!U!P!VR!V!Q][OXY]ln[WOXY]lnW`QbcrQxiQ!QyQ!S!OR!W!TReQRzi]WOXY]ln",nodeNames:"⚠ SymfonyExpression GroupNode EmptyBrackets Entity EntityName SquareBracketClose SquareBracketOpen Array ArrayItem Comma Dot PropertyName Function FunctionName BracketOpen ArgList BracketClose String Number Boolean Boolean Operator LiteralOperator LiteralOperator LiteralOperator LiteralOperator GroupNode GroupOperator GroupOperator BracketGroup BraceClose BraceOpen BracesGroup",maxTerm:51,nodeProps:[["openedBy",6,"SquareBracketOpen",17,"BracketOpen",31,"BraceOpen"],["closedBy",7,"SquareBracketClose",15,"BracketClose",32,"BraceClose"]],skippedNodes:[0],repeatNodeCount:5,tokenData:"*o~RwXY#lYZ$aZ[#l]^$apq#lqr$frs$quv$lwx&ixy([yz(iz{$l{|$l|}(n}!O$l!O!P(s!P!Q$l!Q![)W![!])`!^!_)y!_!`*R!`!a)y!c!})`!}#O*Z#O#P)`#P#Q*`#R#S)`#T#o)`#o#p*e#q#r*j$f$g#l#BY#BZ#l$IS$I_#l$I|$I}$a$I}$JO$a$JT$JU#l$KV$KW#l&FU&FV#l?HT?HU#l~#qYy~XY#lZ[#lpq#l$f$g#l#BY#BZ#l$IS$I_#l$JT$JU#l$KV$KW#l&FU&FV#l?HT?HU#l~$fOz~~$iP!_!`$l~$qOf~~$vWb~OY$qZr$qrs%`s#O$q#O#P%e#P;'S$q;'S;=`&c<%lO$q~%eOb~~%hRO;'S$q;'S;=`%q;=`O$q~%vXb~OY$qZr$qrs%`s#O$q#O#P%e#P;'S$q;'S;=`&c;=`<%l$q<%lO$q~&fP;=`<%l$q~&nWb~OY&iZw&iwx%`x#O&i#O#P'W#P;'S&i;'S;=`(U<%lO&i~'ZRO;'S&i;'S;=`'d;=`O&i~'iXb~OY&iZw&iwx%`x#O&i#O#P'W#P;'S&i;'S;=`(U;=`<%l&i<%lO&i~(XP;=`<%l&i~(aP_~yz(d~(iO}~~(nOa~~(sOY~T(xPZP!O!P({S)OP!O!P)RS)WO!SS~)]Pc~!Q![)WV)gU!OT!QQ!Q![)`![!])`!c!})`#O#P)`#R#S)`#T#o)`~*OPf~!_!`$l~*WPf~!_!`)y~*`OV~~*eOU~~*jOp~~*oOo~",tokenizers:[0,1,2],topRules:{SymfonyExpression:[0,1]},specialized:[{term:46,get:s=>ig[s]||-1}],tokenPrec:0}),sg={"=":"= #{1}","==":"== #{1}","!=":"!= #{1}",">=":">= #{1}",">":"> #{1}","<=":"<= #{1}","<":"< #{1}","*":"* #{1}","/":"/ #{1}","%":"% #{1}","+":"+ #{1}","-":"- #{1}",and:"and #{1}",or:"or #{1}",in:"in [#{1}]","not in":"not in [#{1}]",matches:"matches containsRegExp(#{1})","does not match":"not matches containsRegExp(#{1})","()":"(#{1})","is empty":"#{1} == 0","is not empty":"#{1} != 0",between:"#{1} >= #{2} and #{3} <= #{4}","not between":"#{1} < #{2} and #{3} > #{4}",yes:"#{1} == true",no:"#{1} == false"},rg=(s,t=!1,e={})=>{let i=sg[s.trim()];return i||(i=s,e.isCollection&&(i+="[#{1}]"),e.hasChildren!==void 0&&(i+=e.hasChildren?".":" "),i+=i.includes("#{1}")?"#{2}":"#{1}"),t&&(i=` ${i}`),pd(i)},og=({items:s},t={})=>Object.entries(s).sort().map(([e,{hasChildren:i,normalizedName:n,isCollection:r}])=>{const o=n||e;return{label:o+(i?"…":""),apply:rg(o,!1,{hasChildren:i,isCollection:r}),detail:t.operatorsDetailMap[e]}}),lg=(s,t={},e)=>{const i=gt(e.state).resolveInner(e.pos,-1),n=og(s.getAutocompleteData(e.state.doc.lineAt(e.pos).text,e.pos),t),{text:r}=e.matchBefore(/\s*/),o=i.from<e.pos&&i.to>e.pos,l=i.name==="Dot"||r===" "?e.pos:i.from;if(n.length)return{from:l,to:o?i.to:null,options:n}},hg=ng.configure({props:[Kp]}),Sa=mn.define({name:"symfony-expression-lang",parser:hg}),ag=(s,t={})=>Sa.data.of({autocomplete:lg.bind(null,s,t)});function fg(s,t={operatorsDetailMap:[]}){return new cu(Sa,[ag(s,t)])}const cg=P.define(),ug=cg.compute([$e],s=>{const t=s.facet($e).filter(e=>e)||[];return t.forEach(e=>e.arrow=!1),t}),dg=({util:s,interactionDelay:t=75,maxRenderedOptions:e=20,dataSource:i={},getDataSourceCallback:n,operatorsDetailMap:r={}})=>[fg(s,{operatorsDetailMap:r}),Ln.of([qp,$p,{key:"Alt-ArrowDown",run:ci}]),Bd({icons:!1,interactionDelay:t,maxRenderedOptions:e,compareCompletions(o,l){return o-l}}),T.lineWrapping,T.editorAttributes.of({class:"expression-editor"}),vu(jp),T.updateListener.of(o=>{[2,4,6].includes(o.flags)&&setTimeout(()=>ci(o.view))}),T.domEventHandlers({focusin(o,l){setTimeout(()=>ci(l))}}),Ic({position:"fixed",parent:document.body}),kd(),Bu(),qd(),ug,Up({util:s,dataSource:i,getDataSourceCallback:n})];function Wt(){var s=arguments[0];typeof s=="string"&&(s=document.createElement(s));var t=1,e=arguments[1];if(e&&typeof e=="object"&&e.nodeType==null&&!Array.isArray(e)){for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var n=e[i];typeof n=="string"?s.setAttribute(i,n):n!=null&&(s[i]=n)}t++}for(;t<arguments.length;t++)Ca(s,arguments[t]);return s}function Ca(s,t){if(typeof t=="string")s.appendChild(document.createTextNode(t));else if(t!=null)if(t.nodeType!=null)s.appendChild(t);else if(Array.isArray(t))for(var e=0;e<t.length;e++)Ca(s,t[e]);else throw new RangeError("Unsupported child node: "+t)}class nl{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class we{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(Ut).markerFilter;n&&(t=n(t,i));let r=t.slice().sort((a,c)=>a.from-c.from||a.to-c.to),o=new Ve,l=[],h=0;for(let a=0;;){let c=a==r.length?null:r[a];if(!c&&!l.length)break;let u,d;for(l.length?(u=h,d=l.reduce((g,m)=>Math.min(g,m.to),c&&c.from>u?c.from:1e8)):(u=c.from,d=c.to,l.push(c),a++);a<r.length;){let g=r[a];if(g.from==u&&(g.to>g.from||g.to==u))l.push(g),a++,d=Math.min(g.to,d);else{d=Math.min(g.from,d);break}}let p=Ag(l);if(l.some(g=>g.from==g.to||g.from==g.to-1&&i.doc.lineAt(g.from).to==g.from))o.add(u,u,N.widget({widget:new vg(p),diagnostics:l.slice()}));else{let g=l.reduce((m,y)=>y.markClass?m+" "+y.markClass:m,"");o.add(u,d,N.mark({class:"cm-lintRange cm-lintRange-"+p+g,diagnostics:l.slice(),inclusiveEnd:l.some(m=>m.to>d)}))}h=d;for(let g=0;g<l.length;g++)l[g].to<=h&&l.splice(g--,1)}let f=o.finish();return new we(f,e,je(f))}}function je(s,t=null,e=0){let i=null;return s.between(e,1e9,(n,r,{spec:o})=>{if(!(t&&o.diagnostics.indexOf(t)<0))if(!i)i=new nl(n,r,t||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new nl(i.from,r,i.diagnostic)}}),i}function pg(s,t){let e=t.pos,i=t.end||e,n=s.state.facet(Ut).hideOn(s,e,i);if(n!=null)return n;let r=s.startState.doc.lineAt(t.pos);return!!(s.effects.some(o=>o.is(Cr))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function gg(s,t){return s.field(bt,!1)?t:t.concat(R.appendConfig.of(Pa))}function mg(s,t){return{effects:gg(s,[Cr.of(t)])}}const Cr=R.define(),Oa=R.define(),Aa=R.define(),bt=ct.define({create(){return new we(N.none,null,null)},update(s,t){if(t.docChanged&&s.diagnostics.size){let e=s.diagnostics.map(t.changes),i=null,n=s.panel;if(s.selected){let r=t.changes.mapPos(s.selected.from,1);i=je(e,s.selected.diagnostic,r)||je(e,null,r)}!e.size&&n&&t.state.facet(Ut).autoPanel&&(n=null),s=new we(e,n,i)}for(let e of t.effects)if(e.is(Cr)){let i=t.state.facet(Ut).autoPanel?e.value.length?Mn.open:null:s.panel;s=we.init(e.value,i,t.state)}else e.is(Oa)?s=new we(s.diagnostics,e.value?Mn.open:null,s.selected):e.is(Aa)&&(s=new we(s.diagnostics,s.panel,e.value));return s},provide:s=>[Hs.from(s,t=>t.panel),T.decorations.from(s,t=>t.diagnostics)]});function Bg(s){let t=s.field(bt,!1);return t?t.diagnostics.size:0}const yg=N.mark({class:"cm-lintRange cm-lintRange-active"});function bg(s,t,e){let{diagnostics:i}=s.state.field(bt),n,r=-1,o=-1;i.between(t-(e<0?1:0),t+(e>0?1:0),(h,f,{spec:a})=>{if(t>=h&&t<=f&&(h==f||(t>h||e>0)&&(t<f||e<0)))return n=a.diagnostics,r=h,o=f,!1});let l=s.state.facet(Ut).tooltipFilter;return n&&l&&(n=l(n,s.state)),n?{pos:r,end:o,above:s.state.doc.lineAt(r).to<o,create(){return{dom:wg(s,n)}}}:null}function wg(s,t){return Wt("ul",{class:"cm-tooltip-lint"},t.map(e=>Ta(s,e,!1)))}const sl=s=>{let t=s.state.field(bt,!1);return!t||!t.panel?!1:(s.dispatch({effects:Oa.of(!1)}),!0)},xg=At.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:t}=s.state.facet(Ut);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:t}=this.view,{sources:e}=t.facet(Ut);e.length&&kg(e.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==t.doc&&this.view.dispatch(mg(this.view.state,i.reduce((n,r)=>n.concat(r))))},i=>{at(this.view.state,i)})}}update(s){let t=s.state.facet(Ut);(s.docChanged||t!=s.startState.facet(Ut)||t.needsRefresh&&t.needsRefresh(s))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function kg(s,t,e){let i=[],n=-1;for(let r of s)r.then(o=>{i.push(o),clearTimeout(n),i.length==s.length?t(i):n=setTimeout(()=>t(i),200)},e)}const Ut=P.define({combine(s){return Object.assign({sources:s.map(t=>t.source).filter(t=>t!=null)},Pn(s.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e}))}});function Rg(s,t={}){return[Ut.of({source:s,config:t}),xg,Pa]}function Ma(s){let t=[];if(s)t:for(let{name:e}of s){for(let i=0;i<e.length;i++){let n=e[i];if(/[a-zA-Z]/.test(n)&&!t.some(r=>r.toLowerCase()==n.toLowerCase())){t.push(n);continue t}}t.push("")}return t}function Ta(s,t,e){var i;let n=e?Ma(t.actions):[];return Wt("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},Wt("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(s):t.message),(i=t.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,h=u=>{if(u.preventDefault(),l)return;l=!0;let d=je(s.state.field(bt).diagnostics,t);d&&r.apply(s,d.from,d.to)},{name:f}=r,a=n[o]?f.indexOf(n[o]):-1,c=a<0?f:[f.slice(0,a),Wt("u",f.slice(a,a+1)),f.slice(a+1)];return Wt("button",{type:"button",class:"cm-diagnosticAction",onclick:h,onmousedown:h,"aria-label":` Action: ${f}${a<0?"":` (access key "${n[o]})"`}.`},c)}),t.source&&Wt("div",{class:"cm-diagnosticSource"},t.source))}class vg extends ki{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return Wt("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class rl{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=Ta(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Mn{constructor(t){this.view=t,this.items=[];let e=n=>{if(n.keyCode==27)sl(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=Ma(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==n.keyCode){let h=je(this.view.state.field(bt).diagnostics,r);h&&r.actions[l].apply(t,h.from,h.to)}}else return;n.preventDefault()},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=Wt("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e,onclick:i}),this.dom=Wt("div",{class:"cm-panel-lint"},this.list,Wt("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>sl(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(bt).selected;if(!t)return-1;for(let e=0;e<this.items.length;e++)if(this.items[e].diagnostic==t.diagnostic)return e;return-1}update(){let{diagnostics:t,selected:e}=this.view.state.field(bt),i=0,n=!1,r=null,o=new Set;for(t.between(0,this.view.state.doc.length,(l,h,{spec:f})=>{for(let a of f.diagnostics){if(o.has(a))continue;o.add(a);let c=-1,u;for(let d=i;d<this.items.length;d++)if(this.items[d].diagnostic==a){c=d;break}c<0?(u=new rl(this.view,a),this.items.splice(i,0,u),n=!0):(u=this.items[c],c>i&&(this.items.splice(i,c-i),n=!0)),e&&u.diagnostic==e.diagnostic?u.dom.hasAttribute("aria-selected")||(u.dom.setAttribute("aria-selected","true"),r=u):u.dom.hasAttribute("aria-selected")&&u.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new rl(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:h})=>{let f=h.height/this.list.offsetHeight;l.top<h.top?this.list.scrollTop-=(h.top-l.top)/f:l.bottom>h.bottom&&(this.list.scrollTop+=(l.bottom-h.bottom)/f)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let t=this.list.firstChild;function e(){let i=t;t=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=this.view.state.field(bt),i=je(e.diagnostics,this.items[t].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:Aa.of(i)})}static open(t){return new Mn(t)}}function Sg(s,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(s)}</svg>')`}function Gi(s){return Sg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Cg=T.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Gi("#d11")},".cm-lintRange-warning":{backgroundImage:Gi("orange")},".cm-lintRange-info":{backgroundImage:Gi("#999")},".cm-lintRange-hint":{backgroundImage:Gi("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function Og(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function Ag(s){let t="hint",e=1;for(let i of s){let n=Og(i.severity);n>e&&(e=n,t=i.severity)}return t}const Pa=[bt,T.decorations.compute([bt],s=>{let{selected:t,panel:e}=s.field(bt);return!t||!e||t.from==t.to?N.none:N.set([yg.range(t.from,t.to)])}),qc(bg,{hideOn:pg}),Cg];function Eg(s,t){let e=s.field(bt,!1);if(e&&e.diagnostics.size){let i=[],n=[],r=-1;for(let o=H.iter([e.diagnostics]);;o.next()){for(let l=0;l<i.length;l++)(!o.value||o.value.spec.diagnostics.indexOf(i[l])<0)&&(t(i[l],n[l],r),i.splice(l,1),n.splice(l--,1));if(!o.value)break;for(let l of o.value.spec.diagnostics)i.indexOf(l)<0&&(i.push(l),n.push(o.from));r=o.to}}}const Lg=(s,t={doc:null,extensions:[],extensionsOptions:{}})=>{if(!s)throw new Error("Element is required to create editor");if(t.doc===void 0)throw new Error("Document content is required to create editor");const e=F.create({doc:t.doc,extensions:[...dg(t.extensionsOptions),...t.extensions]}),i=new T({state:e,parent:s});return{editorState:e,editorView:i}};export{F as EditorState,T as EditorView,sg as OPERATORS_SNIPPET_TEMPLATES,ct as StateField,id as acceptCompletion,Pg as completionStatus,Lg as createEditor,Dg as currentCompletions,Bg as diagnosticCount,Eg as forEachDiagnostic,rg as getResolvedSnippetByName,Rg as linter,ji as moveCompletionSelection,Hs as showPanel,pd as snippet,ci as startCompletion,gt as syntaxTree};
1
+ let ls=[],ll=[];(()=>{let s="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(t=>t?parseInt(t,36):1);for(let t=0,e=0;t<s.length;t++)(t%2?ll:ls).push(e=e+s[t])})();function Ra(s){if(s<768)return!1;for(let t=0,e=ls.length;;){let i=t+e>>1;if(s<ls[i])e=i;else if(s>=ll[i])t=i+1;else return!0;if(t==e)return!1}}function Mr(s){return s>=127462&&s<=127487}const Tr=8205;function Ea(s,t,e=!0,i=!0){return(e?hl:La)(s,t,i)}function hl(s,t,e){if(t==s.length)return t;t&&al(s.charCodeAt(t))&&fl(s.charCodeAt(t-1))&&t--;let i=$n(s,t);for(t+=Pr(i);t<s.length;){let n=$n(s,t);if(i==Tr||n==Tr||e&&Ra(n))t+=Pr(n),i=n;else if(Mr(n)){let r=0,o=t-2;for(;o>=0&&Mr($n(s,o));)r++,o-=2;if(r%2==0)break;t+=2}else break}return t}function La(s,t,e){for(;t>0;){let i=hl(s,t-2,e);if(i<t)return i;t--}return 0}function $n(s,t){let e=s.charCodeAt(t);if(!fl(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return al(i)?(e-55296<<10)+(i-56320)+65536:e}function al(s){return s>=56320&&s<57344}function fl(s){return s>=55296&&s<56320}function Pr(s){return s<65536?1:2}class L{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=Ve(this,t,e);let n=[];return this.decompose(0,t,n,2),i.length&&i.decompose(0,i.length,n,3),this.decompose(e,this.length,n,1),zt.from(n,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=Ve(this,t,e);let i=[];return this.decompose(t,e,i,0),zt.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),n=new hi(this),r=new hi(t);for(let o=e,l=e;;){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(t=1){return new hi(this,t)}iterRange(t,e=this.length){return new cl(this,t,e)}iterLines(t,e){let i;if(t==null)i=this.iter();else{e==null&&(e=this.lines+1);let n=this.line(t).from;i=this.iterRange(n,Math.max(n,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new ul(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(t){if(t.length==0)throw new RangeError("A document must have at least one line");return t.length==1&&!t[0]?L.empty:t.length<=32?new Q(t):zt.from(Q.split(t,[]))}}class Q extends L{constructor(t,e=Ia(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,n){for(let r=0;;r++){let o=this.text[r],l=n+o.length;if((e?i:l)>=t)return new Na(n,l,i,o);n=l+1,i++}}decompose(t,e,i,n){let r=t<=0&&e>=this.length?this:new Q(Dr(this.text,t,e),Math.min(e,this.length)-Math.max(0,t));if(n&1){let o=i.pop(),l=_i(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new Q(l,o.length+r.length));else{let h=l.length>>1;i.push(new Q(l.slice(0,h)),new Q(l.slice(h)))}}else i.push(r)}replace(t,e,i){if(!(i instanceof Q))return super.replace(t,e,i);[t,e]=Ve(this,t,e);let n=_i(this.text,_i(i.text,Dr(this.text,0,t)),e),r=this.length+i.length-(e-t);return n.length<=32?new Q(n,r):zt.from(Q.split(n,[]),r)}sliceString(t,e=this.length,i=`
2
+ `){[t,e]=Ve(this,t,e);let n="";for(let r=0,o=0;r<=e&&o<this.text.length;o++){let l=this.text[o],h=r+l.length;r>t&&o&&(n+=i),t<h&&e>r&&(n+=l.slice(Math.max(0,t-r),e-r)),r=h+1}return n}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,e){let i=[],n=-1;for(let r of t)i.push(r),n+=r.length+1,i.length==32&&(e.push(new Q(i,n)),i=[],n=-1);return n>-1&&e.push(new Q(i,n)),e}}class zt extends L{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let i of t)this.lines+=i.lines}lineInner(t,e,i,n){for(let r=0;;r++){let o=this.children[r],l=n+o.length,h=i+o.lines-1;if((e?h:l)>=t)return o.lineInner(t,e,i,n);n=l+1,i=h+1}}decompose(t,e,i,n){for(let r=0,o=0;o<=e&&r<this.children.length;r++){let l=this.children[r],h=o+l.length;if(t<=h&&e>=o){let f=n&((o<=t?1:0)|(h>=e?2:0));o>=t&&h<=e&&!f?i.push(l):l.decompose(t-o,e-o,i,f)}o=h+1}}replace(t,e,i){if([t,e]=Ve(this,t,e),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(t>=r&&e<=l){let h=o.replace(t-r,e-r,i),f=this.lines-o.lines+h.lines;if(h.lines<f>>4&&h.lines>f>>6){let a=this.children.slice();return a[n]=h,new zt(a,this.length-(e-t)+i.length)}return super.replace(r,l,h)}r=l+1}return super.replace(t,e,i)}sliceString(t,e=this.length,i=`
3
+ `){[t,e]=Ve(this,t,e);let n="";for(let r=0,o=0;r<this.children.length&&o<=e;r++){let l=this.children[r],h=o+l.length;o>t&&r&&(n+=i),t<h&&e>o&&(n+=l.sliceString(t-o,e-o,i)),o=h+1}return n}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof zt))return 0;let i=0,[n,r,o,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;n+=e,r+=e){if(n==o||r==l)return i;let h=this.children[n],f=t.children[r];if(h!=f)return i+h.scanIdentical(f,e);i+=h.length+1}}static from(t,e=t.reduce((i,n)=>i+n.length+1,-1)){let i=0;for(let d of t)i+=d.lines;if(i<32){let d=[];for(let p of t)p.flatten(d);return new Q(d,e)}let n=Math.max(32,i>>5),r=n<<1,o=n>>1,l=[],h=0,f=-1,a=[];function c(d){let p;if(d.lines>r&&d instanceof zt)for(let g of d.children)c(g);else d.lines>o&&(h>o||!h)?(u(),l.push(d)):d instanceof Q&&h&&(p=a[a.length-1])instanceof Q&&d.lines+p.lines<=32?(h+=d.lines,f+=d.length+1,a[a.length-1]=new Q(p.text.concat(d.text),p.length+1+d.length)):(h+d.lines>n&&u(),h+=d.lines,f+=d.length+1,a.push(d))}function u(){h!=0&&(l.push(a.length==1?a[0]:zt.from(a,f)),f=-1,h=a.length=0)}for(let d of t)c(d);return u(),l.length==1?l[0]:new zt(l,e)}}L.empty=new Q([""],0);function Ia(s){let t=-1;for(let e of s)t+=e.length+1;return t}function _i(s,t,e=0,i=1e9){for(let n=0,r=0,o=!0;r<s.length&&n<=i;r++){let l=s[r],h=n+l.length;h>=e&&(h>i&&(l=l.slice(0,i-n)),n<e&&(l=l.slice(e-n)),o?(t[t.length-1]+=l,o=!1):t.push(l)),n=h+1}return t}function Dr(s,t,e){return _i(s,[""],t,e)}class hi{constructor(t,e=1){this.dir=e,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[e>0?1:(t instanceof Q?t.text.length:t.children.length)<<1]}nextInner(t,e){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 Q?n.text.length:n.children.length;if(o==(e>0?l:0)){if(i==0)return this.done=!0,this.value="",this;e>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(e>0?0:1)){if(this.offsets[i]+=e,t==0)return this.lineBreak=!0,this.value=`
4
+ `,this;t--}else if(n instanceof Q){let h=n.text[o+(e<0?-1:0)];if(this.offsets[i]+=e,h.length>Math.max(0,t))return this.value=t==0?h:e>0?h.slice(t):h.slice(0,h.length-t),this;t-=h.length}else{let h=n.children[o+(e<0?-1:0)];t>h.length?(t-=h.length,this.offsets[i]+=e):(e<0&&this.offsets[i]--,this.nodes.push(h),this.offsets.push(e>0?1:(h instanceof Q?h.text.length:h.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class cl{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new hi(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:n}=this.cursor.next(t);return this.pos+=(n.length+t)*e,this.value=n.length<=i?n:e<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class ul{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:n}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(L.prototype[Symbol.iterator]=function(){return this.iter()},hi.prototype[Symbol.iterator]=cl.prototype[Symbol.iterator]=ul.prototype[Symbol.iterator]=function(){return this});class Na{constructor(t,e,i,n){this.from=t,this.to=e,this.number=i,this.text=n}get length(){return this.to-this.from}}function Ve(s,t,e){return t=Math.max(0,Math.min(s.length,t)),[t,Math.max(t,Math.min(s.length,e))]}function ht(s,t,e=!0,i=!0){return Ea(s,t,e,i)}function Fa(s){return s>=56320&&s<57344}function Va(s){return s>=55296&&s<56320}function Ht(s,t){let e=s.charCodeAt(t);if(!Va(e)||t+1==s.length)return e;let i=s.charCodeAt(t+1);return Fa(i)?(e-55296<<10)+(i-56320)+65536:e}function dl(s){return s<=65535?String.fromCharCode(s):(s-=65536,String.fromCharCode((s>>10)+55296,(s&1023)+56320))}function ne(s){return s<65536?1:2}const hs=/\r\n?|\n/;var nt=(function(s){return s[s.Simple=0]="Simple",s[s.TrackDel=1]="TrackDel",s[s.TrackBefore=2]="TrackBefore",s[s.TrackAfter=3]="TrackAfter",s})(nt||(nt={}));class Qt{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;e<this.sections.length;e+=2)t+=this.sections[e];return t}get newLength(){let t=0;for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e+1];t+=i<0?this.sections[e]:i}return t}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,n=0;e<this.sections.length;){let r=this.sections[e++],o=this.sections[e++];o<0?(t(i,n,r),n+=r):n+=o,i+=r}}iterChangedRanges(t,e=!1){as(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],n=this.sections[e++];n<0?t.push(i,n):t.push(n,i)}return new Qt(t)}composeDesc(t){return this.empty?t:t.empty?this:pl(this,t)}mapDesc(t,e=!1){return t.empty?this:fs(this,t,e)}mapPos(t,e=-1,i=nt.Simple){let n=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],h=this.sections[o++],f=n+l;if(h<0){if(f>t)return r+(t-n);r+=l}else{if(i!=nt.Simple&&f>=t&&(i==nt.TrackDel&&n<t&&f>t||i==nt.TrackBefore&&n<t||i==nt.TrackAfter&&f>t))return null;if(f>t||f==t&&e<0&&!l)return t==n||e<0?r:r+h;r+=h}n=f}if(t>n)throw new RangeError(`Position ${t} is out of range for changeset of length ${n}`);return r}touchesRange(t,e=t){for(let i=0,n=0;i<this.sections.length&&n<=e;){let r=this.sections[i++],o=this.sections[i++],l=n+r;if(o>=0&&n<=e&&l>=t)return n<t&&l>e?"cover":!0;n=l}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],n=this.sections[e++];t+=(t?" ":"")+i+(n>=0?":"+n:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new Qt(t)}static create(t){return new Qt(t)}}class _ extends Qt{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return as(this,(e,i,n,r,o)=>t=t.replace(n,n+(i-e),o),!1),t}mapDesc(t,e=!1){return fs(this,t,e,!0)}invert(t){let e=this.sections.slice(),i=[];for(let n=0,r=0;n<e.length;n+=2){let o=e[n],l=e[n+1];if(l>=0){e[n]=l,e[n+1]=o;let h=n>>1;for(;i.length<h;)i.push(L.empty);i.push(o?t.slice(r,r+o):L.empty)}r+=o}return new _(e,i)}compose(t){return this.empty?t:t.empty?this:pl(this,t,!0)}map(t,e=!1){return t.empty?this:fs(this,t,e,!0)}iterChanges(t,e=!1){as(this,t,e)}get desc(){return Qt.create(this.sections)}filter(t){let e=[],i=[],n=[],r=new ui(this);t:for(let o=0,l=0;;){let h=o==t.length?1e9:t[o++];for(;l<h||l==h&&r.len==0;){if(r.done)break t;let a=Math.min(r.len,h-l);st(n,a,-1);let c=r.ins==-1?-1:r.off==0?r.ins:0;st(e,a,c),c>0&&oe(i,e,r.text),r.forward(a),l+=a}let f=t[o++];for(;l<f;){if(r.done)break t;let a=Math.min(r.len,f-l);st(e,a,-1),st(n,a,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(a),l+=a}}return{changes:new _(e,i),filtered:Qt.create(n)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],n=this.sections[e+1];n<0?t.push(i):n==0?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(t,e,i){let n=[],r=[],o=0,l=null;function h(a=!1){if(!a&&!n.length)return;o<e&&st(n,e-o,-1);let c=new _(n,r);l=l?l.compose(c.map(l)):c,n=[],r=[],o=0}function f(a){if(Array.isArray(a))for(let c of a)f(c);else if(a instanceof _){if(a.length!=e)throw new RangeError(`Mismatched change set length (got ${a.length}, expected ${e})`);h(),l=l?l.compose(a.map(l)):a}else{let{from:c,to:u=c,insert:d}=a;if(c>u||c<0||u>e)throw new RangeError(`Invalid change range ${c} to ${u} (in doc of length ${e})`);let p=d?typeof d=="string"?L.of(d.split(i||hs)):d:L.empty,g=p.length;if(c==u&&g==0)return;c<o&&h(),c>o&&st(n,c-o,-1),st(n,u-c,g),oe(r,n,p),o=u}}return f(t),h(!l),l}static empty(t){return new _(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let e=[],i=[];for(let n=0;n<t.length;n++){let r=t[n];if(typeof r=="number")e.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)e.push(r[0],0);else{for(;i.length<n;)i.push(L.empty);i[n]=L.of(r.slice(1)),e.push(r[0],i[n].length)}}}return new _(e,i)}static createSet(t,e){return new _(t,e)}}function st(s,t,e,i=!1){if(t==0&&e<=0)return;let n=s.length-2;n>=0&&e<=0&&e==s[n+1]?s[n]+=t:n>=0&&t==0&&s[n]==0?s[n+1]+=e:i?(s[n]+=t,s[n+1]+=e):s.push(t,e)}function oe(s,t,e){if(e.length==0)return;let i=t.length-2>>1;if(i<s.length)s[s.length-1]=s[s.length-1].append(e);else{for(;s.length<i;)s.push(L.empty);s.push(e)}}function as(s,t,e){let i=s.inserted;for(let n=0,r=0,o=0;o<s.sections.length;){let l=s.sections[o++],h=s.sections[o++];if(h<0)n+=l,r+=l;else{let f=n,a=r,c=L.empty;for(;f+=l,a+=h,h&&i&&(c=c.append(i[o-2>>1])),!(e||o==s.sections.length||s.sections[o+1]<0);)l=s.sections[o++],h=s.sections[o++];t(n,f,r,a,c),n=f,r=a}}}function fs(s,t,e,i=!1){let n=[],r=i?[]:null,o=new ui(s),l=new ui(t);for(let h=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let f=Math.min(o.len,l.len);st(n,f,-1),o.forward(f),l.forward(f)}else if(l.ins>=0&&(o.ins<0||h==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!e))){let f=l.len;for(st(n,l.ins,-1);f;){let a=Math.min(o.len,f);o.ins>=0&&h<o.i&&o.len<=a&&(st(n,0,o.ins),r&&oe(r,n,o.text),h=o.i),o.forward(a),f-=a}l.next()}else if(o.ins>=0){let f=0,a=o.len;for(;a;)if(l.ins==-1){let c=Math.min(a,l.len);f+=c,a-=c,l.forward(c)}else if(l.ins==0&&l.len<a)a-=l.len,l.next();else break;st(n,f,h<o.i?o.ins:0),r&&h<o.i&&oe(r,n,o.text),h=o.i,o.forward(o.len-a)}else{if(o.done&&l.done)return r?_.createSet(n,r):Qt.create(n);throw new Error("Mismatched change set lengths")}}}function pl(s,t,e=!1){let i=[],n=e?[]:null,r=new ui(s),o=new ui(t);for(let l=!1;;){if(r.done&&o.done)return n?_.createSet(i,n):Qt.create(i);if(r.ins==0)st(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)st(i,0,o.ins,l),n&&oe(n,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let h=Math.min(r.len2,o.len),f=i.length;if(r.ins==-1){let a=o.ins==-1?-1:o.off?0:o.ins;st(i,h,a,l),n&&a&&oe(n,i,o.text)}else o.ins==-1?(st(i,r.off?0:r.len,h,l),n&&oe(n,i,r.textBit(h))):(st(i,r.off?0:r.len,o.off?0:o.ins,l),n&&!o.off&&oe(n,i,o.text));l=(r.ins>h||o.ins>=0&&o.len>h)&&(l||i.length>f),r.forward2(h),o.forward(h)}}}}class ui{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i<t.length?(this.len=t[this.i++],this.ins=t[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,e=this.i-2>>1;return e>=t.length?L.empty:t[e]}textBit(t){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length&&!t?L.empty:e[i].slice(this.off,t==null?void 0:this.off+t)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){this.ins==-1?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class we{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let t=this.flags&7;return t==7?null:t}get goalColumn(){let t=this.flags>>6;return t==16777215?void 0:t}map(t,e=-1){let i,n;return this.empty?i=n=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),n=t.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new we(i,n,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return w.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return w.range(this.anchor,i)}eq(t,e=!1){return this.anchor==t.anchor&&this.head==t.head&&(!e||!this.empty||this.assoc==t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return w.range(t.anchor,t.head)}static create(t,e,i){return new we(t,e,i)}}class w{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:w.create(this.ranges.map(i=>i.map(t,e)),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(t.ranges[i],e))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new w([this.main],0)}addRange(t,e=!0){return w.create([t].concat(this.ranges),e?0:this.mainIndex+1)}replaceRange(t,e=this.mainIndex){let i=this.ranges.slice();return i[e]=t,w.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(t=>t.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!="number"||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new w(t.ranges.map(e=>we.fromJSON(e)),t.main)}static single(t,e=t){return new w([w.range(t,e)],0)}static create(t,e=0){if(t.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<t.length;n++){let r=t[n];if(r.empty?r.from<=i:r.from<i)return w.normalized(t.slice(),e);i=r.to}return new w(t,e)}static cursor(t,e=0,i,n){return we.create(t,t,(e==0?0:e<0?8:16)|(i==null?7:Math.min(6,i))|(n??16777215)<<6)}static range(t,e,i,n){let r=(i??16777215)<<6|(n==null?7:Math.min(6,n));return e<t?we.create(e,t,48|r):we.create(t,e,(e>t?8:0)|r)}static normalized(t,e=0){let i=t[e];t.sort((n,r)=>n.from-r.from),e=t.indexOf(i);for(let n=1;n<t.length;n++){let r=t[n],o=t[n-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,h=Math.max(r.to,o.to);n<=e&&e--,t.splice(--n,2,r.anchor>r.head?w.range(h,l):w.range(l,h))}}return new w(t,e)}}function gl(s,t){for(let e of s.ranges)if(e.to>t)throw new RangeError("Selection points outside of document")}let Gs=0;class P{constructor(t,e,i,n,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=n,this.id=Gs++,this.default=t([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(t={}){return new P(t.combine||(e=>e),t.compareInput||((e,i)=>e===i),t.compare||(t.combine?(e,i)=>e===i:Xs),!!t.static,t.enables)}of(t){return new Ji([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ji(t,this,2,e)}from(t,e){return e||(e=i=>i),this.compute([t],i=>e(i.field(t)))}}function Xs(s,t){return s==t||s.length==t.length&&s.every((e,i)=>e===t[i])}class Ji{constructor(t,e,i,n){this.dependencies=t,this.facet=e,this.type=i,this.value=n,this.id=Gs++}dynamicSlot(t){var e;let i=this.value,n=this.facet.compareInput,r=this.id,o=t[r]>>1,l=this.type==2,h=!1,f=!1,a=[];for(let c of this.dependencies)c=="doc"?h=!0:c=="selection"?f=!0:(((e=t[c.id])!==null&&e!==void 0?e:1)&1)==0&&a.push(t[c.id]);return{create(c){return c.values[o]=i(c),1},update(c,u){if(h&&u.docChanged||f&&(u.docChanged||u.selection)||cs(c,a)){let d=i(c);if(l?!Br(d,c.values[o],n):!n(d,c.values[o]))return c.values[o]=d,1}return 0},reconfigure:(c,u)=>{let d,p=u.config.address[r];if(p!=null){let g=ln(u,p);if(this.dependencies.every(m=>m instanceof P?u.facet(m)===c.facet(m):m instanceof ct?u.field(m,!1)==c.field(m,!1):!0)||(l?Br(d=i(c),g,n):n(d=i(c),g)))return c.values[o]=g,0}else d=i(c);return c.values[o]=d,1}}}}function Br(s,t,e){if(s.length!=t.length)return!1;for(let i=0;i<s.length;i++)if(!e(s[i],t[i]))return!1;return!0}function cs(s,t){let e=!1;for(let i of t)ai(s,i)&1&&(e=!0);return e}function Ha(s,t,e){let i=e.map(h=>s[h.id]),n=e.map(h=>h.type),r=i.filter(h=>!(h&1)),o=s[t.id]>>1;function l(h){let f=[];for(let a=0;a<i.length;a++){let c=ln(h,i[a]);if(n[a]==2)for(let u of c)f.push(u);else f.push(c)}return t.combine(f)}return{create(h){for(let f of i)ai(h,f);return h.values[o]=l(h),1},update(h,f){if(!cs(h,r))return 0;let a=l(h);return t.compare(a,h.values[o])?0:(h.values[o]=a,1)},reconfigure(h,f){let a=cs(h,i),c=f.config.facets[t.id],u=f.facet(t);if(c&&!a&&Xs(e,c))return h.values[o]=u,0;let d=l(h);return t.compare(d,u)?(h.values[o]=u,0):(h.values[o]=d,1)}}}const Pi=P.define({static:!0});class ct{constructor(t,e,i,n,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=n,this.spec=r,this.provides=void 0}static define(t){let e=new ct(Gs++,t.create,t.update,t.compare||((i,n)=>i===n),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(Pi).find(i=>i.field==this);return((e==null?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:i=>(i.values[e]=this.create(i),1),update:(i,n)=>{let r=i.values[e],o=this.updateF(r,n);return this.compareF(r,o)?0:(i.values[e]=o,1)},reconfigure:(i,n)=>{let r=i.facet(Pi),o=n.facet(Pi),l;return(l=r.find(h=>h.field==this))&&l!=o.find(h=>h.field==this)?(i.values[e]=l.create(i),1):n.config.address[this.id]!=null?(i.values[e]=n.field(this),0):(i.values[e]=this.create(i),1)}}}init(t){return[this,Pi.of({field:this,create:t})]}get extension(){return this}}const be={lowest:4,low:3,default:2,high:1,highest:0};function Je(s){return t=>new ml(t,s)}const Ye={highest:Je(be.highest),high:Je(be.high),default:Je(be.default),low:Je(be.low),lowest:Je(be.lowest)};class ml{constructor(t,e){this.inner=t,this.prec=e}}class Tn{of(t){return new us(this,t)}reconfigure(t){return Tn.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class us{constructor(t,e){this.compartment=t,this.inner=e}}class on{constructor(t,e,i,n,r,o){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=n,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return e==null?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let n=[],r=Object.create(null),o=new Map;for(let u of za(t,e,o))u instanceof ct?n.push(u):(r[u.facet.id]||(r[u.facet.id]=[])).push(u);let l=Object.create(null),h=[],f=[];for(let u of n)l[u.id]=f.length<<1,f.push(d=>u.slot(d));let a=i==null?void 0:i.config.facets;for(let u in r){let d=r[u],p=d[0].facet,g=a&&a[u]||[];if(d.every(m=>m.type==0))if(l[p.id]=h.length<<1|1,Xs(g,d))h.push(i.facet(p));else{let m=p.combine(d.map(y=>y.value));h.push(i&&p.compare(m,i.facet(p))?i.facet(p):m)}else{for(let m of d)m.type==0?(l[m.id]=h.length<<1|1,h.push(m.value)):(l[m.id]=f.length<<1,f.push(y=>m.dynamicSlot(y)));l[p.id]=f.length<<1,f.push(m=>Ha(m,p,d))}}let c=f.map(u=>u(l));return new on(t,o,c,l,h,r)}}function za(s,t,e){let i=[[],[],[],[],[]],n=new Map;function r(o,l){let h=n.get(o);if(h!=null){if(h<=l)return;let f=i[h].indexOf(o);f>-1&&i[h].splice(f,1),o instanceof us&&e.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let f of o)r(f,l);else if(o instanceof us){if(e.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let f=t.get(o.compartment)||o.inner;e.set(o.compartment,f),r(f,l)}else if(o instanceof ml)r(o.inner,o.prec);else if(o instanceof ct)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Ji)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,be.default);else{let f=o.extension;if(!f)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(f,l)}}return r(s,be.default),i.reduce((o,l)=>o.concat(l))}function ai(s,t){if(t&1)return 2;let e=t>>1,i=s.status[e];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;s.status[e]=4;let n=s.computeSlot(s,s.config.dynamicSlots[e]);return s.status[e]=2|n}function ln(s,t){return t&1?s.config.staticValues[t>>1]:s.values[t>>1]}const yl=P.define(),ds=P.define({combine:s=>s.some(t=>t),static:!0}),bl=P.define({combine:s=>s.length?s[0]:void 0,static:!0}),xl=P.define(),wl=P.define(),kl=P.define(),vl=P.define({combine:s=>s.length?s[0]:!1});class Zt{constructor(t,e){this.type=t,this.value=e}static define(){return new Wa}}class Wa{of(t){return new Zt(this,t)}}class $a{constructor(t){this.map=t}of(t){return new R(this,t)}}class R{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return e===void 0?void 0:e==this.value?this:new R(this.type,e)}is(t){return this.type==t}static define(t={}){return new $a(t.map||(e=>e))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let n of t){let r=n.map(e);r&&i.push(r)}return i}}R.reconfigure=R.define();R.appendConfig=R.define();class G{constructor(t,e,i,n,r,o){this.startState=t,this.changes=e,this.selection=i,this.effects=n,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&gl(i,e.newLength),r.some(l=>l.type==G.time)||(this.annotations=r.concat(G.time.of(Date.now())))}static create(t,e,i,n,r,o){return new G(t,e,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(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(G.userEvent);return!!(e&&(e==t||e.length>t.length&&e.slice(0,t.length)==t&&e[t.length]=="."))}}G.time=Zt.define();G.userEvent=Zt.define();G.addToHistory=Zt.define();G.remote=Zt.define();function qa(s,t){let e=[];for(let i=0,n=0;;){let r,o;if(i<s.length&&(n==t.length||t[n]>=s[i]))r=s[i++],o=s[i++];else if(n<t.length)r=t[n++],o=t[n++];else return e;!e.length||e[e.length-1]<r?e.push(r,o):e[e.length-1]<o&&(e[e.length-1]=o)}}function Sl(s,t,e){var i;let n,r,o;return e?(n=t.changes,r=_.empty(t.changes.length),o=s.changes.compose(t.changes)):(n=t.changes.map(s.changes),r=s.changes.mapDesc(t.changes,!0),o=s.changes.compose(n)),{changes:o,selection:t.selection?t.selection.map(r):(i=s.selection)===null||i===void 0?void 0:i.map(n),effects:R.mapEffects(s.effects,n).concat(R.mapEffects(t.effects,r)),annotations:s.annotations.length?s.annotations.concat(t.annotations):t.annotations,scrollIntoView:s.scrollIntoView||t.scrollIntoView}}function ps(s,t,e){let i=t.selection,n=Re(t.annotations);return t.userEvent&&(n=n.concat(G.userEvent.of(t.userEvent))),{changes:t.changes instanceof _?t.changes:_.of(t.changes||[],e,s.facet(bl)),selection:i&&(i instanceof w?i:w.single(i.anchor,i.head)),effects:Re(t.effects),annotations:n,scrollIntoView:!!t.scrollIntoView}}function Cl(s,t,e){let i=ps(s,t.length?t[0]:{},s.doc.length);t.length&&t[0].filter===!1&&(e=!1);for(let r=1;r<t.length;r++){t[r].filter===!1&&(e=!1);let o=!!t[r].sequential;i=Sl(i,ps(s,t[r],o?i.changes.newLength:s.doc.length),o)}let n=G.create(s,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return Ka(e?Ua(n):n)}function Ua(s){let t=s.startState,e=!0;for(let n of t.facet(xl)){let r=n(s);if(r===!1){e=!1;break}Array.isArray(r)&&(e=e===!0?r:qa(e,r))}if(e!==!0){let n,r;if(e===!1)r=s.changes.invertedDesc,n=_.empty(t.doc.length);else{let o=s.changes.filter(e);n=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}s=G.create(t,n,s.selection&&s.selection.map(r),R.mapEffects(s.effects,r),s.annotations,s.scrollIntoView)}let i=t.facet(wl);for(let n=i.length-1;n>=0;n--){let r=i[n](s);r instanceof G?s=r:Array.isArray(r)&&r.length==1&&r[0]instanceof G?s=r[0]:s=Cl(t,Re(r),!1)}return s}function Ka(s){let t=s.startState,e=t.facet(kl),i=s;for(let n=e.length-1;n>=0;n--){let r=e[n](s);r&&Object.keys(r).length&&(i=Sl(i,ps(t,r,s.changes.newLength),!0))}return i==s?s:G.create(t,s.changes,s.selection,i.effects,i.annotations,i.scrollIntoView)}const Qa=[];function Re(s){return s==null?Qa:Array.isArray(s)?s:[s]}var kt=(function(s){return s[s.Word=0]="Word",s[s.Space=1]="Space",s[s.Other=2]="Other",s})(kt||(kt={}));const ja=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let gs;try{gs=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function Ya(s){if(gs)return gs.test(s);for(let t=0;t<s.length;t++){let e=s[t];if(/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||ja.test(e)))return!0}return!1}function Ga(s){return t=>{if(!/\S/.test(t))return kt.Space;if(Ya(t))return kt.Word;for(let e=0;e<s.length;e++)if(t.indexOf(s[e])>-1)return kt.Word;return kt.Other}}class F{constructor(t,e,i,n,r,o){this.config=t,this.doc=e,this.selection=i,this.values=n,this.status=t.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)ai(this,l<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(i==null){if(e)throw new RangeError("Field is not present in this state");return}return ai(this,i),ln(this,i)}update(...t){return Cl(this,t,!0)}applyTransaction(t){let e=this.config,{base:i,compartments:n}=e;for(let l of t.effects)l.is(Tn.reconfigure)?(e&&(n=new Map,e.compartments.forEach((h,f)=>n.set(f,h)),e=null),n.set(l.value.compartment,l.value.extension)):l.is(R.reconfigure)?(e=null,i=l.value):l.is(R.appendConfig)&&(e=null,i=Re(i).concat(l.value));let r;e?r=t.startState.values.slice():(e=on.resolve(i,n,this),r=new F(e,this.doc,this.selection,e.dynamicSlots.map(()=>null),(h,f)=>f.reconfigure(h,this),null).values);let o=t.startState.facet(ds)?t.newSelection:t.newSelection.asSingle();new F(e,t.newDoc,o,r,(l,h)=>h.update(l,t),t)}replaceSelection(t){return typeof t=="string"&&(t=this.toText(t)),this.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t},range:w.cursor(e.from+t.length)}))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),n=this.changes(i.changes),r=[i.range],o=Re(i.effects);for(let l=1;l<e.ranges.length;l++){let h=t(e.ranges[l]),f=this.changes(h.changes),a=f.map(n);for(let u=0;u<l;u++)r[u]=r[u].map(a);let c=n.mapDesc(f,!0);r.push(h.range.map(c)),n=n.compose(a),o=R.mapEffects(o,a).concat(R.mapEffects(Re(h.effects),c))}return{changes:n,selection:w.create(r,e.mainIndex),effects:o}}changes(t=[]){return t instanceof _?t:_.of(t,this.doc.length,this.facet(F.lineSeparator))}toText(t){return L.of(t.split(this.facet(F.lineSeparator)||hs))}sliceDoc(t=0,e=this.doc.length){return this.doc.sliceString(t,e,this.lineBreak)}facet(t){let e=this.config.address[t.id];return e==null?t.default:(ai(this,e),ln(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let n=t[i];n instanceof ct&&this.config.address[n.id]!=null&&(e[i]=n.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||typeof t.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(t,r)){let o=i[r],l=t[r];n.push(o.init(h=>o.spec.fromJSON(l,h)))}}return F.create({doc:t.doc,selection:w.fromJSON(t.selection),extensions:e.extensions?n.concat([e.extensions]):n})}static create(t={}){let e=on.resolve(t.extensions||[],new Map),i=t.doc instanceof L?t.doc:L.of((t.doc||"").split(e.staticFacet(F.lineSeparator)||hs)),n=t.selection?t.selection instanceof w?t.selection:w.single(t.selection.anchor,t.selection.head):w.single(0);return gl(n,i.length),e.staticFacet(ds)||(n=n.asSingle()),new F(e,i,n,e.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(F.tabSize)}get lineBreak(){return this.facet(F.lineSeparator)||`
5
+ `}get readOnly(){return this.facet(vl)}phrase(t,...e){for(let i of this.facet(F.phrases))if(Object.prototype.hasOwnProperty.call(i,t)){t=i[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,(i,n)=>{if(n=="$")return"$";let r=+(n||1);return!r||r>e.length?i:e[r-1]})),t}languageDataAt(t,e,i=-1){let n=[];for(let r of this.facet(yl))for(let o of r(this,e,i))Object.prototype.hasOwnProperty.call(o,t)&&n.push(o[t]);return n}charCategorizer(t){return Ga(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:n}=this.doc.lineAt(t),r=this.charCategorizer(t),o=t-i,l=t-i;for(;o>0;){let h=ht(e,o,!1);if(r(e.slice(h,o))!=kt.Word)break;o=h}for(;l<n;){let h=ht(e,l);if(r(e.slice(l,h))!=kt.Word)break;l=h}return o==l?null:w.range(o+i,l+i)}}F.allowMultipleSelections=ds;F.tabSize=P.define({combine:s=>s.length?s[0]:4});F.lineSeparator=bl;F.readOnly=vl;F.phrases=P.define({compare(s,t){let e=Object.keys(s),i=Object.keys(t);return e.length==i.length&&e.every(n=>s[n]==t[n])}});F.languageData=yl;F.changeFilter=xl;F.transactionFilter=wl;F.transactionExtender=kl;Tn.reconfigure=R.define();function Pn(s,t,e={}){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(e,r))i[r]=e[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let n in t)i[n]===void 0&&(i[n]=t[n]);return i}class Ce{eq(t){return this==t}range(t,e=t){return ms.create(t,e,this)}}Ce.prototype.startSide=Ce.prototype.endSide=0;Ce.prototype.point=!1;Ce.prototype.mapMode=nt.TrackDel;let ms=class Ol{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(t,e,i){return new Ol(t,e,i)}};function ys(s,t){return s.from-t.from||s.value.startSide-t.value.startSide}class _s{constructor(t,e,i,n){this.from=t,this.to=e,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,n=0){let r=i?this.to:this.from;for(let o=n,l=r.length;;){if(o==l)return o;let h=o+l>>1,f=r[h]-t||(i?this.value[h].endSide:this.value[h].startSide)-e;if(h==o)return f>=0?o:l;f>=0?l=h:o=h+1}}between(t,e,i,n){for(let r=this.findIndex(e,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(n(this.from[r]+t,this.to[r]+t,this.value[r])===!1)return!1}map(t,e){let i=[],n=[],r=[],o=-1,l=-1;for(let h=0;h<this.value.length;h++){let f=this.value[h],a=this.from[h]+t,c=this.to[h]+t,u,d;if(a==c){let p=e.mapPos(a,f.startSide,f.mapMode);if(p==null||(u=d=p,f.startSide!=f.endSide&&(d=e.mapPos(a,f.endSide),d<u)))continue}else if(u=e.mapPos(a,f.startSide),d=e.mapPos(c,f.endSide),u>d||u==d&&f.startSide>0&&f.endSide<=0)continue;(d-u||f.endSide-f.startSide)<0||(o<0&&(o=u),f.point&&(l=Math.max(l,d-u)),i.push(f),n.push(u-o),r.push(d-o))}return{mapped:i.length?new _s(n,r,i,l):null,pos:o}}}class H{constructor(t,e,i,n){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=n}static create(t,e,i,n){return new H(t,e,i,n)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:n=0,filterTo:r=this.length}=t,o=t.filter;if(e.length==0&&!o)return this;if(i&&(e=e.slice().sort(ys)),this.isEmpty)return e.length?H.of(e):this;let l=new Al(this,null,-1).goto(0),h=0,f=[],a=new He;for(;l.value||h<e.length;)if(h<e.length&&(l.from-e[h].from||l.startSide-e[h].value.startSide)>=0){let c=e[h++];a.addInner(c.from,c.to,c.value)||f.push(c)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(h==e.length||this.chunkEnd(l.chunkIndex)<e[h].from)&&(!o||n>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&a.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))&&(a.addInner(l.from,l.to,l.value)||f.push(ms.create(l.from,l.to,l.value))),l.next());return a.finishInner(this.nextLayer.isEmpty&&!f.length?H.empty:this.nextLayer.update({add:f,filter:o,filterFrom:n,filterTo:r}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],n=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],h=this.chunk[o],f=t.touchesRange(l,l+h.length);if(f===!1)n=Math.max(n,h.maxPoint),e.push(h),i.push(t.mapPos(l));else if(f===!0){let{mapped:a,pos:c}=h.map(l,t);a&&(n=Math.max(n,a.maxPoint),e.push(a),i.push(c))}}let r=this.nextLayer.map(t);return e.length==0?r:new H(i,e,r||H.empty,n)}between(t,e,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let r=this.chunkPos[n],o=this.chunk[n];if(e>=r&&t<=r+o.length&&o.between(r,t-r,e-r,i)===!1)return}this.nextLayer.between(t,e,i)}}iter(t=0){return di.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return di.from(t).goto(e)}static compare(t,e,i,n,r=-1){let o=t.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),l=e.filter(c=>c.maxPoint>0||!c.isEmpty&&c.maxPoint>=r),h=Rr(o,l,i),f=new Ze(o,h,r),a=new Ze(l,h,r);i.iterGaps((c,u,d)=>Er(f,c,a,u,d,n)),i.empty&&i.length==0&&Er(f,0,a,0,0,n)}static eq(t,e,i=0,n){n==null&&(n=999999999);let r=t.filter(a=>!a.isEmpty&&e.indexOf(a)<0),o=e.filter(a=>!a.isEmpty&&t.indexOf(a)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=Rr(r,o),h=new Ze(r,l,0).goto(i),f=new Ze(o,l,0).goto(i);for(;;){if(h.to!=f.to||!bs(h.active,f.active)||h.point&&(!f.point||!h.point.eq(f.point)))return!1;if(h.to>n)return!0;h.next(),f.next()}}static spans(t,e,i,n,r=-1){let o=new Ze(t,null,r).goto(e),l=e,h=o.openStart;for(;;){let f=Math.min(o.to,i);if(o.point){let a=o.activeForPoint(o.to),c=o.pointFrom<e?a.length+1:o.point.startSide<0?a.length:Math.min(a.length,h);n.point(l,f,o.point,a,c,o.pointRank),h=Math.min(o.openEnd(f),a.length)}else f>l&&(n.span(l,f,o.active,h),h=o.openEnd(f));if(o.to>i)return h+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(t,e=!1){let i=new He;for(let n of t instanceof ms?[t]:e?Xa(t):t)i.add(n.from,n.to,n.value);return i.finish()}static join(t){if(!t.length)return H.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let n=t[i];n!=H.empty;n=n.nextLayer)e=new H(n.chunkPos,n.chunk,e,Math.max(n.maxPoint,e.maxPoint));return e}}H.empty=new H([],[],null,-1);function Xa(s){if(s.length>1)for(let t=s[0],e=1;e<s.length;e++){let i=s[e];if(ys(t,i)>0)return s.slice().sort(ys);t=i}return s}H.empty.nextLayer=H.empty;class He{finishChunk(t){this.chunks.push(new _s(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,i){this.addInner(t,e,i)||(this.nextLayer||(this.nextLayer=new He)).add(t,e,i)}addInner(t,e,i){let n=t-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(t-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=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=i,this.lastFrom=t,this.lastTo=e,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let i=e.value.length-1;return this.last=e.value[i],this.lastFrom=e.from[i]+t,this.lastTo=e.to[i]+t,!0}finish(){return this.finishInner(H.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return t;let e=H.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Rr(s,t,e){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 t)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(e?e.mapPos(l):l)==r.chunkPos[o]&&!(e!=null&&e.touchesRange(l,l+r.chunk[o].length))&&n.add(r.chunk[o])}return n}class Al{constructor(t,e,i,n=0){this.layer=t,this.skip=e,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(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let n=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(n)||this.layer.chunkEnd(this.chunkIndex)<t||n.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let t=this.layer.chunkPos[this.chunkIndex],e=this.layer.chunk[this.chunkIndex],i=t+e.from[this.rangeIndex];if(this.from=i,this.to=t+e.to[this.rangeIndex],this.value=e.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=t}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(t){return this.from-t.from||this.startSide-t.startSide||this.rank-t.rank||this.to-t.to||this.endSide-t.endSide}}class di{constructor(t){this.heap=t}static from(t,e=null,i=-1){let n=[];for(let r=0;r<t.length;r++)for(let o=t[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&n.push(new Al(o,e,i,r));return n.length==1?n[0]:new di(n)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let i=this.heap.length>>1;i>=0;i--)qn(this.heap,i);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let i=this.heap.length>>1;i>=0;i--)qn(this.heap,i);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),qn(this.heap,0)}}}function qn(s,t){for(let e=s[t];;){let i=(t<<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++),e.compare(n)<0)break;s[i]=e,s[t]=n,t=i}}class Ze{constructor(t,e,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=di.from(t,e,i)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){Di(this.active,t),Di(this.activeTo,t),Di(this.activeRank,t),this.minActive=Lr(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:n,rank:r}=this.cursor;for(;e<this.activeRank.length&&(r-this.activeRank[e]||n-this.activeTo[e])>0;)e++;Bi(this.active,e,i),Bi(this.activeTo,e,n),Bi(this.activeRank,e,r),t&&Bi(t,e,this.cursor.from),this.minActive=Lr(this.active,this.activeTo)}next(){let t=this.to,e=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]>t){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Di(i,n)}else if(this.cursor.value)if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let n=i.length-1;n>=0&&i[n]<t;n--)this.openStart++}}activeForPoint(t){if(!this.active.length)return this.active;let e=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>t||this.activeTo[i]==t&&this.active[i].endSide>=this.point.endSide)&&e.push(this.active[i]);return e.reverse()}openEnd(t){let e=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>t;i--)e++;return e}}function Er(s,t,e,i,n,r){s.goto(t),e.goto(i);let o=i+n,l=i,h=i-t;for(;;){let f=s.to+h-e.to,a=f||s.endSide-e.endSide,c=a<0?s.to+h:e.to,u=Math.min(c,o);if(s.point||e.point?s.point&&e.point&&(s.point==e.point||s.point.eq(e.point))&&bs(s.activeForPoint(s.to),e.activeForPoint(e.to))||r.comparePoint(l,u,s.point,e.point):u>l&&!bs(s.active,e.active)&&r.compareRange(l,u,s.active,e.active),c>o)break;(f||s.openEnd!=e.openEnd)&&r.boundChange&&r.boundChange(c),l=c,a<=0&&s.next(),a>=0&&e.next()}}function bs(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++)if(s[e]!=t[e]&&!s[e].eq(t[e]))return!1;return!0}function Di(s,t){for(let e=t,i=s.length-1;e<i;e++)s[e]=s[e+1];s.pop()}function Bi(s,t,e){for(let i=s.length-1;i>=t;i--)s[i+1]=s[i];s[t]=e}function Lr(s,t){let e=-1,i=1e9;for(let n=0;n<t.length;n++)(t[n]-i||s[n].endSide-s[e].endSide)<0&&(e=n,i=t[n]);return e}function Dn(s,t,e=s.length){let i=0;for(let n=0;n<e&&n<s.length;)s.charCodeAt(n)==9?(i+=t-i%t,n++):(i++,n=ht(s,n));return i}function _a(s,t,e,i){for(let n=0,r=0;;){if(r>=t)return n;if(n==s.length)break;r+=s.charCodeAt(n)==9?e-r%e:1,n=ht(s,n)}return s.length}const xs="ͼ",Ir=typeof Symbol>"u"?"__"+xs:Symbol.for(xs),ws=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Nr=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class fe{constructor(t,e){this.rules=[];let{finish:i}=e||{};function n(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,h,f){let a=[],c=/^@(\w+)\b/.exec(o[0]),u=c&&c[1]=="keyframes";if(c&&l==null)return h.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(g=>o.map(m=>g.replace(/&/,m))).reduce((g,m)=>g.concat(m)),p,h);else if(p&&typeof p=="object"){if(!c)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(n(d),p,a,u)}else p!=null&&a.push(d.replace(/_.*/,"").replace(/[A-Z]/g,g=>"-"+g.toLowerCase())+": "+p+";")}(a.length||u)&&h.push((i&&!c&&!f?o.map(i):o).join(", ")+" {"+a.join(" ")+"}")}for(let o in t)r(n(o),t[o],this.rules)}getRules(){return this.rules.join(`
6
+ `)}static newName(){let t=Nr[Ir]||1;return Nr[Ir]=t+1,xs+t.toString(36)}static mount(t,e,i){let n=t[ws],r=i&&i.nonce;n?r&&n.setNonce(r):n=new Ja(t,r),n.mount(Array.isArray(e)?e:[e],t)}}let Fr=new Map;class Ja{constructor(t,e){let i=t.ownerDocument||t,n=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&n.CSSStyleSheet){let r=Fr.get(i);if(r)return t[ws]=r;this.sheet=new n.CSSStyleSheet,Fr.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[ws]=this}mount(t,e){let i=this.sheet,n=0,r=0;for(let o=0;o<t.length;o++){let l=t[o],h=this.modules.indexOf(l);if(h<r&&h>-1&&(this.modules.splice(h,1),r--,h=-1),h==-1){if(this.modules.splice(r++,0,l),i)for(let f=0;f<l.rules.length;f++)i.insertRule(l.rules[f],n++)}else{for(;r<h;)n+=this.modules[r++].rules.length;n+=l.rules.length,r++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let o="";for(let h=0;h<this.modules.length;h++)o+=this.modules[h].getRules()+`
7
+ `;this.styleTag.textContent=o;let l=e.head||e;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}var ce={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:"'"},pi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Za=typeof navigator<"u"&&/Mac/.test(navigator.platform),tf=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var it=0;it<10;it++)ce[48+it]=ce[96+it]=String(it);for(var it=1;it<=24;it++)ce[it+111]="F"+it;for(var it=65;it<=90;it++)ce[it]=String.fromCharCode(it+32),pi[it]=String.fromCharCode(it);for(var Un in ce)pi.hasOwnProperty(Un)||(pi[Un]=ce[Un]);function ef(s){var t=Za&&s.metaKey&&s.shiftKey&&!s.ctrlKey&&!s.altKey||tf&&s.shiftKey&&s.key&&s.key.length==1||s.key=="Unidentified",e=!t&&s.key||(s.shiftKey?pi:ce)[s.keyCode]||s.key||"Unidentified";return e=="Esc"&&(e="Escape"),e=="Del"&&(e="Delete"),e=="Left"&&(e="ArrowLeft"),e=="Up"&&(e="ArrowUp"),e=="Right"&&(e="ArrowRight"),e=="Down"&&(e="ArrowDown"),e}function gi(s){let t;return s.nodeType==11?t=s.getSelection?s:s.ownerDocument:t=s,t.getSelection()}function ks(s,t){return t?s==t||s.contains(t.nodeType!=1?t.parentNode:t):!1}function Zi(s,t){if(!t.anchorNode)return!1;try{return ks(s,t.anchorNode)}catch{return!1}}function mi(s){return s.nodeType==3?Ae(s,0,s.nodeValue.length).getClientRects():s.nodeType==1?s.getClientRects():[]}function fi(s,t,e,i){return e?Vr(s,t,e,i,-1)||Vr(s,t,e,i,1):!1}function Oe(s){for(var t=0;;t++)if(s=s.previousSibling,!s)return t}function hn(s){return s.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(s.nodeName)}function Vr(s,t,e,i,n){for(;;){if(s==e&&t==i)return!0;if(t==(n<0?0:Yt(s))){if(s.nodeName=="DIV")return!1;let r=s.parentNode;if(!r||r.nodeType!=1)return!1;t=Oe(s)+(n<0?0:1),s=r}else if(s.nodeType==1){if(s=s.childNodes[t+(n<0?-1:0)],s.nodeType==1&&s.contentEditable=="false")return!1;t=n<0?Yt(s):0}else return!1}}function Yt(s){return s.nodeType==3?s.nodeValue.length:s.childNodes.length}function Bn(s,t){let e=t?s.left:s.right;return{left:e,right:e,top:s.top,bottom:s.bottom}}function nf(s){let t=s.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:s.innerWidth,top:0,bottom:s.innerHeight}}function Ml(s,t){let e=t.width/s.offsetWidth,i=t.height/s.offsetHeight;return(e>.995&&e<1.005||!isFinite(e)||Math.abs(t.width-s.offsetWidth)<1)&&(e=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(t.height-s.offsetHeight)<1)&&(i=1),{scaleX:e,scaleY:i}}function sf(s,t,e,i,n,r,o,l){let h=s.ownerDocument,f=h.defaultView||window;for(let a=s,c=!1;a&&!c;)if(a.nodeType==1){let u,d=a==h.body,p=1,g=1;if(d)u=nf(f);else{if(/^(fixed|sticky)$/.test(getComputedStyle(a).position)&&(c=!0),a.scrollHeight<=a.clientHeight&&a.scrollWidth<=a.clientWidth){a=a.assignedSlot||a.parentNode;continue}let x=a.getBoundingClientRect();({scaleX:p,scaleY:g}=Ml(a,x)),u={left:x.left,right:x.left+a.clientWidth*p,top:x.top,bottom:x.top+a.clientHeight*g}}let m=0,y=0;if(n=="nearest")t.top<u.top?(y=-(u.top-t.top+o),e>0&&t.bottom>u.bottom+y&&(y=t.bottom-u.bottom+y+o)):t.bottom>u.bottom&&(y=t.bottom-u.bottom+o,e<0&&t.top-y<u.top&&(y=-(u.top+y-t.top+o)));else{let x=t.bottom-t.top,b=u.bottom-u.top;y=(n=="center"&&x<=b?t.top+x/2-b/2:n=="start"||n=="center"&&e<0?t.top-o:t.bottom-b+o)-u.top}if(i=="nearest"?t.left<u.left?(m=-(u.left-t.left+r),e>0&&t.right>u.right+m&&(m=t.right-u.right+m+r)):t.right>u.right&&(m=t.right-u.right+r,e<0&&t.left<u.left+m&&(m=-(u.left+m-t.left+r))):m=(i=="center"?t.left+(t.right-t.left)/2-(u.right-u.left)/2:i=="start"==l?t.left-r:t.right-(u.right-u.left)+r)-u.left,m||y)if(d)f.scrollBy(m,y);else{let x=0,b=0;if(y){let k=a.scrollTop;a.scrollTop+=y/g,b=(a.scrollTop-k)*g}if(m){let k=a.scrollLeft;a.scrollLeft+=m/p,x=(a.scrollLeft-k)*p}t={left:t.left-x,top:t.top-b,right:t.right-x,bottom:t.bottom-b},x&&Math.abs(x-m)<1&&(i="nearest"),b&&Math.abs(b-y)<1&&(n="nearest")}if(d)break;a=a.assignedSlot||a.parentNode}else if(a.nodeType==11)a=a.host;else break}function rf(s){let t=s.ownerDocument,e,i;for(let n=s.parentNode;n&&!(n==t.body||e&&i);)if(n.nodeType==1)!i&&n.scrollHeight>n.clientHeight&&(i=n),!e&&n.scrollWidth>n.clientWidth&&(e=n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;return{x:e,y:i}}class of{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(t){return this.anchorNode==t.anchorNode&&this.anchorOffset==t.anchorOffset&&this.focusNode==t.focusNode&&this.focusOffset==t.focusOffset}setRange(t){let{anchorNode:e,focusNode:i}=t;this.set(e,Math.min(t.anchorOffset,e?Yt(e):0),i,Math.min(t.focusOffset,i?Yt(i):0))}set(t,e,i,n){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=n}}let Pe=null;function Tl(s){if(s.setActive)return s.setActive();if(Pe)return s.focus(Pe);let t=[];for(let e=s;e&&(t.push(e,e.scrollTop,e.scrollLeft),e!=e.ownerDocument);e=e.parentNode);if(s.focus(Pe==null?{get preventScroll(){return Pe={preventScroll:!0},!0}}:void 0),!Pe){Pe=!1;for(let e=0;e<t.length;){let i=t[e++],n=t[e++],r=t[e++];i.scrollTop!=n&&(i.scrollTop=n),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Hr;function Ae(s,t,e=t){let i=Hr||(Hr=document.createRange());return i.setEnd(s,e),i.setStart(s,t),i}function Ee(s,t,e,i){let n={key:t,code:t,keyCode:e,which:e,cancelable:!0};i&&({altKey:n.altKey,ctrlKey:n.ctrlKey,shiftKey:n.shiftKey,metaKey:n.metaKey}=i);let r=new KeyboardEvent("keydown",n);r.synthetic=!0,s.dispatchEvent(r);let o=new KeyboardEvent("keyup",n);return o.synthetic=!0,s.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function lf(s){for(;s;){if(s&&(s.nodeType==9||s.nodeType==11&&s.host))return s;s=s.assignedSlot||s.parentNode}return null}function Pl(s){for(;s.attributes.length;)s.removeAttributeNode(s.attributes[0])}function hf(s,t){let e=t.focusNode,i=t.focusOffset;if(!e||t.anchorNode!=e||t.anchorOffset!=i)return!1;for(i=Math.min(i,Yt(e));;)if(i){if(e.nodeType!=1)return!1;let n=e.childNodes[i-1];n.contentEditable=="false"?i--:(e=n,i=Yt(e))}else{if(e==s)return!0;i=Oe(e),e=e.parentNode}}function Dl(s){return s.scrollTop>Math.max(1,s.scrollHeight-s.clientHeight-4)}function Bl(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i>0)return{node:e,offset:i};if(e.nodeType==1&&i>0){if(e.contentEditable=="false")return null;e=e.childNodes[i-1],i=Yt(e)}else if(e.parentNode&&!hn(e))i=Oe(e),e=e.parentNode;else return null}}function Rl(s,t){for(let e=s,i=t;;){if(e.nodeType==3&&i<e.nodeValue.length)return{node:e,offset:i};if(e.nodeType==1&&i<e.childNodes.length){if(e.contentEditable=="false")return null;e=e.childNodes[i],i=0}else if(e.parentNode&&!hn(e))i=Oe(e)+1,e=e.parentNode;else return null}}class ot{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new ot(t.parentNode,Oe(t),e)}static after(t,e){return new ot(t.parentNode,Oe(t)+1,e)}}const Js=[];class z{constructor(){this.parent=null,this.dom=null,this.flags=2}get overrideDOMText(){return null}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(t){let e=this.posAtStart;for(let i of this.children){if(i==t)return e;e+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(t){return this.posBefore(t)+t.length}sync(t,e){if(this.flags&2){let i=this.dom,n=null,r;for(let o of this.children){if(o.flags&7){if(!o.dom&&(r=n?n.nextSibling:i.firstChild)){let l=z.get(r);(!l||!l.parent&&l.canReuseDOM(o))&&o.reuseDOM(r)}o.sync(t,e),o.flags&=-8}if(r=n?n.nextSibling:i.firstChild,e&&!e.written&&e.node==i&&r!=o.dom&&(e.written=!0),o.dom.parentNode==i)for(;r&&r!=o.dom;)r=zr(r);else i.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:i.firstChild,r&&e&&e.node==i&&(e.written=!0);r;)r=zr(r)}else if(this.flags&1)for(let i of this.children)i.flags&7&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let n=Yt(t)==0?0:e==0?-1:1;for(;;){let r=t.parentNode;if(r==this.dom)break;n==0&&r.firstChild!=r.lastChild&&(t==r.firstChild?n=-1:n=1),t=r}n<0?i=t:i=t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!z.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(t,e,i=0){let n=-1,r=-1,o=-1,l=-1;for(let h=0,f=i,a=i;h<this.children.length;h++){let c=this.children[h],u=f+c.length;if(f<t&&u>e)return c.domBoundsAround(t,e,f);if(u>=t&&n==-1&&(n=h,r=f),f>e&&c.dom.parentNode==this.dom){o=h,l=a;break}a=u,f=u+c.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(t=!1){this.flags|=2,this.markParentsDirty(t)}markParentsDirty(t){for(let e=this.parent;e;e=e.parent){if(t&&(e.flags|=2),e.flags&1)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,this.flags&7&&this.markParentsDirty(!0))}setDOM(t){this.dom!=t&&(this.dom&&(this.dom.cmView=null),this.dom=t,t.cmView=this)}get rootView(){for(let t=this;;){let e=t.parent;if(!e)return t;t=e}}replaceChildren(t,e,i=Js){this.markDirty();for(let n=t;n<e;n++){let r=this.children[n];r.parent==this&&i.indexOf(r)<0&&r.destroy()}i.length<250?this.children.splice(t,e-t,...i):this.children=[].concat(this.children.slice(0,t),i,this.children.slice(e));for(let n=0;n<i.length;n++)i[n].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new El(this.children,t,this.children.length)}childPos(t,e=1){return this.childCursor().findPos(t,e)}toString(){let t=this.constructor.name.replace("View","");return t+(this.children.length?"("+this.children.join()+")":this.length?"["+(t=="Text"?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,n,r,o){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!((this.flags|t.flags)&8)}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}z.prototype.breakAfter=0;function zr(s){let t=s.nextSibling;return s.parentNode.removeChild(s),t}class El{constructor(t,e,i){this.children=t,this.pos=e,this.i=i,this.off=0}findPos(t,e=1){for(;;){if(t>this.pos||t==this.pos&&(e>0||this.i==0||this.children[this.i-1].breakAfter))return this.off=t-this.pos,this;let i=this.children[--this.i];this.pos-=i.length+i.breakAfter}}}function Ll(s,t,e,i,n,r,o,l,h){let{children:f}=s,a=f.length?f[t]:null,c=r.length?r[r.length-1]:null,u=c?c.breakAfter:o;if(!(t==i&&a&&!o&&!u&&r.length<2&&a.merge(e,n,r.length?c:null,e==0,l,h))){if(i<f.length){let d=f[i];d&&(n<d.length||d.breakAfter&&(c!=null&&c.breakAfter))?(t==i&&(d=d.split(n),n=0),!u&&c&&d.merge(0,n,c,!0,0,h)?r[r.length-1]=d:((n||d.children.length&&!d.children[0].length)&&d.merge(0,n,null,!1,0,h),r.push(d))):d!=null&&d.breakAfter&&(c?c.breakAfter=1:o=1),i++}for(a&&(a.breakAfter=o,e>0&&(!o&&r.length&&a.merge(e,a.length,r[0],!1,l,0)?a.breakAfter=r.shift().breakAfter:(e<a.length||a.children.length&&a.children[a.children.length-1].length==0)&&a.merge(e,a.length,null,!1,l,0),t++));t<i&&r.length;)if(f[i-1].become(r[r.length-1]))i--,r.pop(),h=r.length?0:l;else if(f[t].become(r[0]))t++,r.shift(),l=r.length?0:h;else break;!r.length&&t&&i<f.length&&!f[t-1].breakAfter&&f[i].merge(0,0,f[t-1],!1,l,h)&&t--,(t<i||r.length)&&s.replaceChildren(t,i,r)}}function Il(s,t,e,i,n,r){let o=s.childCursor(),{i:l,off:h}=o.findPos(e,1),{i:f,off:a}=o.findPos(t,-1),c=t-e;for(let u of i)c+=u.length;s.length+=c,Ll(s,f,a,l,h,i,0,n,r)}let ut=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},vs=typeof document<"u"?document:{documentElement:{style:{}}};const Ss=/Edge\/(\d+)/.exec(ut.userAgent),Nl=/MSIE \d/.test(ut.userAgent),Cs=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(ut.userAgent),Rn=!!(Nl||Cs||Ss),Wr=!Rn&&/gecko\/(\d+)/i.test(ut.userAgent),Kn=!Rn&&/Chrome\/(\d+)/.exec(ut.userAgent),af="webkitFontSmoothing"in vs.documentElement.style,Fl=!Rn&&/Apple Computer/.test(ut.vendor),$r=Fl&&(/Mobile\/\w+/.test(ut.userAgent)||ut.maxTouchPoints>2);var O={mac:$r||/Mac/.test(ut.platform),windows:/Win/.test(ut.platform),linux:/Linux|X11/.test(ut.platform),ie:Rn,ie_version:Nl?vs.documentMode||6:Cs?+Cs[1]:Ss?+Ss[1]:0,gecko:Wr,gecko_version:Wr?+(/Firefox\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,chrome:!!Kn,chrome_version:Kn?+Kn[1]:0,ios:$r,android:/Android\b/.test(ut.userAgent),safari:Fl,webkit_version:af?+(/\bAppleWebKit\/(\d+)/.exec(ut.userAgent)||[0,0])[1]:0,tabSize:vs.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};const ff=256;class Dt extends z{constructor(t){super(),this.text=t}get length(){return this.text.length}createDOM(t){this.setDOM(t||document.createTextNode(this.text))}sync(t,e){this.dom||this.createDOM(),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text)}reuseDOM(t){t.nodeType==3&&this.createDOM(t)}merge(t,e,i){return this.flags&8||i&&(!(i instanceof Dt)||this.length-(e-t)+i.length>ff||i.flags&8)?!1:(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Dt(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=this.flags&8,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new ot(this.dom,t)}domBoundsAround(t,e,i){return{from:i,to:i+this.length,startDOM:this.dom,endDOM:this.dom.nextSibling}}coordsAt(t,e){return cf(this.dom,t,e)}}class Jt extends z{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let n of e)n.setParent(this)}setAttrs(t){if(Pl(t),this.mark.class&&(t.className=this.mark.class),this.mark.attrs)for(let e in this.mark.attrs)t.setAttribute(e,this.mark.attrs[e]);return t}canReuseDOM(t){return super.canReuseDOM(t)&&!((this.flags|t.flags)&8)}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?this.flags&4&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,n,r,o){return i&&(!(i instanceof Jt&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&o<=0)?!1:(Il(this,t,e,i?i.children.slice():[],r-1,o-1),this.markDirty(),!0)}split(t){let e=[],i=0,n=-1,r=0;for(let l of this.children){let h=i+l.length;h>t&&e.push(i<t?l.split(t-i):l),n<0&&i>=t&&(n=r),i=h,r++}let o=this.length-t;return this.length=t,n>-1&&(this.children.length=n,this.markDirty()),new Jt(this.mark,e,o)}domAtPos(t){return Vl(this,t)}coordsAt(t,e){return zl(this,t,e)}}function cf(s,t,e){let i=s.nodeValue.length;t>i&&(t=i);let n=t,r=t,o=0;t==0&&e<0||t==i&&e>=0?O.chrome||O.gecko||(t?(n--,o=1):r<i&&(r++,o=-1)):e<0?n--:r<i&&r++;let l=Ae(s,n,r).getClientRects();if(!l.length)return null;let h=l[(o?o<0:e>=0)?0:l.length-1];return O.safari&&!o&&h.width==0&&(h=Array.prototype.find.call(l,f=>f.width)||h),o?Bn(h,o<0):h||null}class le extends z{static create(t,e,i){return new le(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=le.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,n,r,o){return i&&(!(i instanceof le)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof le&&t.side==this.side&&this.widget.constructor==t.widget.constructor?(this.widget.compare(t.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(this.length==0)return L.empty;let t=this;for(;t.parent;)t=t.parent;let{view:e}=t,i=e&&e.state.doc,n=this.posAtStart;return i?i.slice(n,n+this.length):L.empty}domAtPos(t){return(this.length?t==0:this.side>0)?ot.before(this.dom):ot.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let n=this.dom.getClientRects(),r=null;if(!n.length)return null;let o=this.side?this.side<0:t>0;for(let l=o?n.length-1:0;r=n[l],!(t>0?l==0:l==n.length-1||r.top<r.bottom);l+=o?-1:1);return Bn(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 ze extends z{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof ze&&t.side==this.side}split(){return new ze(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?ot.before(this.dom):ot.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return L.empty}get isHidden(){return!0}}Dt.prototype.children=le.prototype.children=ze.prototype.children=Js;function Vl(s,t){let e=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(t>r&&t<l&&o.dom.parentNode==e)return o.domAtPos(t-r);if(t<=r)break;r=l}}for(let r=n;r>0;r--){let o=i[r-1];if(o.dom.parentNode==e)return o.domAtPos(o.length)}for(let r=n;r<i.length;r++){let o=i[r];if(o.dom.parentNode==e)return o.domAtPos(0)}return new ot(e,0)}function Hl(s,t,e){let i,{children:n}=s;e>0&&t instanceof Jt&&n.length&&(i=n[n.length-1])instanceof Jt&&i.mark.eq(t.mark)?Hl(i,t.children[0],e-1):(n.push(t),t.setParent(s)),s.length+=t.length}function zl(s,t,e){let i=null,n=-1,r=null,o=-1;function l(f,a){for(let c=0,u=0;c<f.children.length&&u<=a;c++){let d=f.children[c],p=u+d.length;p>=a&&(d.children.length?l(d,a-u):(!r||r.isHidden&&e>0)&&(p>a||u==p&&d.getSide()>0)?(r=d,o=a-u):(u<a||u==p&&d.getSide()<0&&!d.isHidden)&&(i=d,n=a-u)),u=p}}l(s,t);let h=(e<0?i:r)||i||r;return h?h.coordsAt(Math.max(0,h==i?n:o),e):uf(s)}function uf(s){let t=s.dom.lastChild;if(!t)return s.dom.getBoundingClientRect();let e=mi(t);return e[e.length-1]||null}function Os(s,t){for(let e in s)e=="class"&&t.class?t.class+=" "+s.class:e=="style"&&t.style?t.style+=";"+s.style:t[e]=s[e];return t}const qr=Object.create(null);function an(s,t,e){if(s==t)return!0;s||(s=qr),t||(t=qr);let i=Object.keys(s),n=Object.keys(t);if(i.length-(e&&i.indexOf(e)>-1?1:0)!=n.length-(e&&n.indexOf(e)>-1?1:0))return!1;for(let r of i)if(r!=e&&(n.indexOf(r)==-1||s[r]!==t[r]))return!1;return!0}function As(s,t,e){let i=!1;if(t)for(let n in t)e&&n in e||(i=!0,n=="style"?s.style.cssText="":s.removeAttribute(n));if(e)for(let n in e)t&&t[n]==e[n]||(i=!0,n=="style"?s.style.cssText=e[n]:s.setAttribute(n,e[n]));return i}function df(s){let t=Object.create(null);for(let e=0;e<s.attributes.length;e++){let i=s.attributes[e];t[i.name]=i.value}return t}class vi{eq(t){return!1}updateDOM(t,e){return!1}compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(t){return!0}coordsAt(t,e,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(t){}}var jt=(function(s){return s[s.Text=0]="Text",s[s.WidgetBefore=1]="WidgetBefore",s[s.WidgetAfter=2]="WidgetAfter",s[s.WidgetRange=3]="WidgetRange",s})(jt||(jt={}));class N extends Ce{constructor(t,e,i,n){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=n}get heightRelevant(){return!1}static mark(t){return new Si(t)}static widget(t){let e=Math.max(-1e4,Math.min(1e4,t.side||0)),i=!!t.block;return e+=i&&!t.inlineOrder?e>0?3e8:-4e8:e>0?1e8:-1e8,new ue(t,e,e,i,t.widget||null,!1)}static replace(t){let e=!!t.block,i,n;if(t.isBlockGap)i=-5e8,n=4e8;else{let{start:r,end:o}=Wl(t,e);i=(r?e?-3e8:-1:5e8)-1,n=(o?e?2e8:1:-6e8)+1}return new ue(t,i,n,e,t.widget||null,!0)}static line(t){return new Ci(t)}static set(t,e=!1){return H.of(t,e)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}N.none=H.empty;class Si extends N{constructor(t){let{start:e,end:i}=Wl(t);super(e?-1:5e8,i?1:-6e8,null,t),this.tagName=t.tagName||"span",this.class=t.class||"",this.attrs=t.attributes||null}eq(t){var e,i;return this==t||t instanceof Si&&this.tagName==t.tagName&&(this.class||((e=this.attrs)===null||e===void 0?void 0:e.class))==(t.class||((i=t.attrs)===null||i===void 0?void 0:i.class))&&an(this.attrs,t.attrs,"class")}range(t,e=t){if(t>=e)throw new RangeError("Mark decorations may not be empty");return super.range(t,e)}}Si.prototype.point=!1;class Ci extends N{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof Ci&&this.spec.class==t.spec.class&&an(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}Ci.prototype.mapMode=nt.TrackBefore;Ci.prototype.point=!0;class ue extends N{constructor(t,e,i,n,r,o){super(e,i,r,t),this.block=n,this.isReplace=o,this.mapMode=n?e<=0?nt.TrackBefore:nt.TrackAfter:nt.TrackDel}get type(){return this.startSide!=this.endSide?jt.WidgetRange:this.startSide<=0?jt.WidgetBefore:jt.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof ue&&pf(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(t,e=t){if(this.isReplace&&(t>e||t==e&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&e!=t)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(t,e)}}ue.prototype.point=!0;function Wl(s,t=!1){let{inclusiveStart:e,inclusiveEnd:i}=s;return e==null&&(e=s.inclusive),i==null&&(i=s.inclusive),{start:e??t,end:i??t}}function pf(s,t){return s==t||!!(s&&t&&s.compare(t))}function Ms(s,t,e,i=0){let n=e.length-1;n>=0&&e[n]+i>=s?e[n]=Math.max(e[n],t):e.push(s,t)}class Y extends z{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,n,r,o){if(i){if(!(i instanceof Y))return!1;this.dom||i.transferDOM(this)}return n&&this.setDeco(i?i.attrs:null),Il(this,t,e,i?i.children.slice():[],r,o),!0}split(t){let e=new Y;if(e.breakAfter=this.breakAfter,this.length==0)return e;let{i,off:n}=this.childPos(t);n&&(e.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++)e.append(this.children[r],0);for(;i>0&&this.children[i-1].length==0;)this.children[--i].destroy();return this.children.length=i,this.markDirty(),this.length=t,e}transferDOM(t){this.dom&&(this.markDirty(),t.setDOM(this.dom),t.prevAttrs=this.prevAttrs===void 0?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){an(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Hl(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Os(e,this.attrs||{})),i&&(this.attrs=Os({class:i},this.attrs||{}))}domAtPos(t){return Vl(this,t)}reuseDOM(t){t.nodeName=="DIV"&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?this.flags&4&&(Pl(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&&(As(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let n=this.dom.lastChild;for(;n&&z.get(n)instanceof Jt;)n=n.lastChild;if(!n||!this.length||n.nodeName!="BR"&&((i=z.get(n))===null||i===void 0?void 0:i.isEditable)==!1&&(!O.ios||!this.children.some(r=>r instanceof Dt))){let r=document.createElement("BR");r.cmIgnore=!0,this.dom.appendChild(r)}}measureTextSize(){if(this.children.length==0||this.length>20)return null;let t=0,e;for(let i of this.children){if(!(i instanceof Dt)||/[^ -~]/.test(i.text))return null;let n=mi(i.dom);if(n.length!=1)return null;t+=n[0].width,e=n[0].height}return t?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:t/this.length,textHeight:e}:null}coordsAt(t,e){let i=zl(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle: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(t){return t instanceof Y&&this.children.length==0&&t.children.length==0&&an(this.attrs,t.attrs)&&this.breakAfter==t.breakAfter}covers(){return!0}static find(t,e){for(let i=0,n=0;i<t.children.length;i++){let r=t.children[i],o=n+r.length;if(o>=e){if(r instanceof Y)return r;if(o>e)break}n=o+r.breakAfter}return null}}class _t extends z{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,n,r,o){return i&&(!(i instanceof _t)||!this.widget.compare(i.widget)||t>0&&r<=0||e<this.length&&o<=0)?!1:(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return t==0?ot.before(this.dom):ot.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new _t(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Js}sync(t){(!this.dom||!this.widget.updateDOM(this.dom,t))&&(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}get overrideDOMText(){return this.parent?this.parent.view.state.doc.slice(this.posAtStart,this.posAtEnd):L.empty}domBoundsAround(){return null}become(t){return t instanceof _t&&t.widget.constructor==this.widget.constructor?(t.widget.compare(this.widget)||this.markDirty(!0),this.dom&&!this.prevWidget&&(this.prevWidget=this.widget),this.widget=t.widget,this.length=t.length,this.deco=t.deco,this.breakAfter=t.breakAfter,!0):!1}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);return i||(this.widget instanceof Ts?null:Bn(this.dom.getBoundingClientRect(),this.length?t==0:e<=0))}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e==i?!1:t<0?e<0:i>0}}class Ts extends vi{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}class ci{constructor(t,e,i,n){this.doc=t,this.pos=e,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=t.iter(),this.skip=e}posCovered(){if(this.content.length==0)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof _t&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new Y),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(Ri(new ze(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,!this.posCovered()&&!(t&&this.content.length&&this.content[this.content.length-1]instanceof _t)&&this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:r,lineBreak:o,done:l}=this.cursor.next(this.skip);if(this.skip=0,l)throw new Error("Ran out of text content when drawing inline views");if(o){this.posCovered()||this.getLine(),this.content.length?this.content[this.content.length-1].breakAfter=1:this.breakAtStart=1,this.flushBuffer(),this.curLine=null,this.atCursorPos=!0,t--;continue}else this.text=r,this.textOff=0}let n=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(Ri(new Dt(this.text.slice(this.textOff,this.textOff+n)),e),i),this.atCursorPos=!0,this.textOff+=n,t-=n,i=0}}span(t,e,i,n){this.buildText(e-t,i,n),this.pos=e,this.openStart<0&&(this.openStart=n)}point(t,e,i,n,r,o){if(this.disallowBlockEffectsFor[o]&&i instanceof ue){if(i.block)throw new RangeError("Block decorations may not be specified via plugins");if(e>this.doc.lineAt(this.pos).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}let l=e-t;if(i instanceof ue)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new _t(i.widget||We.block,l,i));else{let h=le.create(i.widget||We.inline,l,l?0:i.startSide),f=this.atCursorPos&&!h.isEditable&&r<=n.length&&(t<e||i.startSide>0),a=!h.isEditable&&(t<e||r>n.length||i.startSide<=0),c=this.getLine();this.pendingBuffer==2&&!f&&!h.isEditable&&(this.pendingBuffer=0),this.flushBuffer(n),f&&(c.append(Ri(new ze(1),n),r),r=n.length+Math.max(0,r-n.length)),c.append(Ri(h,n),r),this.atCursorPos=a,this.pendingBuffer=a?t<e||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=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,n,r){let o=new ci(t,e,i,r);return o.openEnd=H.spans(n,e,i,o),o.openStart<0&&(o.openStart=o.openEnd),o.finish(o.openEnd),o}}function Ri(s,t){for(let e of t)s=new Jt(e,[s],s.length);return s}class We extends vi{constructor(t){super(),this.tag=t}eq(t){return t.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(t){return t.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}We.inline=new We("span");We.block=new We("div");var j=(function(s){return s[s.LTR=0]="LTR",s[s.RTL=1]="RTL",s})(j||(j={}));const Me=j.LTR,Zs=j.RTL;function $l(s){let t=[];for(let e=0;e<s.length;e++)t.push(1<<+s[e]);return t}const gf=$l("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),mf=$l("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ps=Object.create(null),It=[];for(let s of["()","[]","{}"]){let t=s.charCodeAt(0),e=s.charCodeAt(1);Ps[t]=e,Ps[e]=-t}function ql(s){return s<=247?gf[s]:1424<=s&&s<=1524?2:1536<=s&&s<=1785?mf[s-1536]:1774<=s&&s<=2220?4:8192<=s&&s<=8204?256:64336<=s&&s<=65023?4:1}const yf=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class he{get dir(){return this.level%2?Zs:Me}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,n){let r=-1;for(let o=0;o<t.length;o++){let l=t[o];if(l.from<=e&&l.to>=e){if(l.level==i)return o;(r<0||(n!=0?n<0?l.from<e:l.to>e:t[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function Ul(s,t){if(s.length!=t.length)return!1;for(let e=0;e<s.length;e++){let i=s[e],n=t[e];if(i.from!=n.from||i.to!=n.to||i.direction!=n.direction||!Ul(i.inner,n.inner))return!1}return!0}const V=[];function bf(s,t,e,i,n){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:t,l=r<i.length?i[r].from:e,h=r?256:n;for(let f=o,a=h,c=h;f<l;f++){let u=ql(s.charCodeAt(f));u==512?u=a:u==8&&c==4&&(u=16),V[f]=u==4?2:u,u&7&&(c=u),a=u}for(let f=o,a=h,c=h;f<l;f++){let u=V[f];if(u==128)f<l-1&&a==V[f+1]&&a&24?u=V[f]=a:V[f]=256;else if(u==64){let d=f+1;for(;d<l&&V[d]==64;)d++;let p=f&&a==8||d<e&&V[d]==8?c==1?1:8:256;for(let g=f;g<d;g++)V[g]=p;f=d-1}else u==8&&c==1&&(V[f]=1);a=u,u&7&&(c=u)}}}function xf(s,t,e,i,n){let r=n==1?2:1;for(let o=0,l=0,h=0;o<=i.length;o++){let f=o?i[o-1].to:t,a=o<i.length?i[o].from:e;for(let c=f,u,d,p;c<a;c++)if(d=Ps[u=s.charCodeAt(c)])if(d<0){for(let g=l-3;g>=0;g-=3)if(It[g+1]==-d){let m=It[g+2],y=m&2?n:m&4?m&1?r:n:0;y&&(V[c]=V[It[g]]=y),l=g;break}}else{if(It.length==189)break;It[l++]=c,It[l++]=u,It[l++]=h}else if((p=V[c])==2||p==1){let g=p==n;h=g?0:1;for(let m=l-3;m>=0;m-=3){let y=It[m+2];if(y&2)break;if(g)It[m+2]|=2;else{if(y&4)break;It[m+2]|=4}}}}}function wf(s,t,e,i){for(let n=0,r=i;n<=e.length;n++){let o=n?e[n-1].to:s,l=n<e.length?e[n].from:t;for(let h=o;h<l;){let f=V[h];if(f==256){let a=h+1;for(;;)if(a==l){if(n==e.length)break;a=e[n++].to,l=n<e.length?e[n].from:t}else if(V[a]==256)a++;else break;let c=r==1,u=(a<t?V[a]:i)==1,d=c==u?c?1:2:i;for(let p=a,g=n,m=g?e[g-1].to:s;p>h;)p==m&&(p=e[--g].from,m=g?e[g-1].to:s),V[--p]=d;h=a}else r=f,h++}}}function Ds(s,t,e,i,n,r,o){let l=i%2?2:1;if(i%2==n%2)for(let h=t,f=0;h<e;){let a=!0,c=!1;if(f==r.length||h<r[f].from){let g=V[h];g!=l&&(a=!1,c=g==16)}let u=!a&&l==1?[]:null,d=a?i:i+1,p=h;t:for(;;)if(f<r.length&&p==r[f].from){if(c)break t;let g=r[f];if(!a)for(let m=g.to,y=f+1;;){if(m==e)break t;if(y<r.length&&r[y].from==m)m=r[y++].to;else{if(V[m]==l)break t;break}}if(f++,u)u.push(g);else{g.from>h&&o.push(new he(h,g.from,d));let m=g.direction==Me!=!(d%2);Bs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.to}p=g.to}else{if(p==e||(a?V[p]!=l:V[p]==l))break;p++}u?Ds(s,h,p,i+1,n,u,o):h<p&&o.push(new he(h,p,d)),h=p}else for(let h=e,f=r.length;h>t;){let a=!0,c=!1;if(!f||h>r[f-1].to){let g=V[h-1];g!=l&&(a=!1,c=g==16)}let u=!a&&l==1?[]:null,d=a?i:i+1,p=h;t:for(;;)if(f&&p==r[f-1].to){if(c)break t;let g=r[--f];if(!a)for(let m=g.from,y=f;;){if(m==t)break t;if(y&&r[y-1].to==m)m=r[--y].from;else{if(V[m-1]==l)break t;break}}if(u)u.push(g);else{g.to<h&&o.push(new he(g.to,h,d));let m=g.direction==Me!=!(d%2);Bs(s,m?i+1:i,n,g.inner,g.from,g.to,o),h=g.from}p=g.from}else{if(p==t||(a?V[p-1]!=l:V[p-1]==l))break;p--}u?Ds(s,p,h,i+1,n,u,o):p<h&&o.push(new he(p,h,d)),h=p}}function Bs(s,t,e,i,n,r,o){let l=t%2?2:1;bf(s,n,r,i,l),xf(s,n,r,i,l),wf(n,r,i,l),Ds(s,n,r,t,e,i,o)}function kf(s,t,e){if(!s)return[new he(0,0,t==Zs?1:0)];if(t==Me&&!e.length&&!yf.test(s))return Kl(s.length);if(e.length)for(;s.length>V.length;)V[V.length]=256;let i=[],n=t==Me?0:1;return Bs(s,n,n,e,0,s.length,i),i}function Kl(s){return[new he(0,s,0)]}let Ql="";function vf(s,t,e,i,n){var r;let o=i.head-s.from,l=he.find(t,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),h=t[l],f=h.side(n,e);if(o==f){let u=l+=n?1:-1;if(u<0||u>=t.length)return null;h=t[l=u],o=h.side(!n,e),f=h.side(n,e)}let a=ht(s.text,o,h.forward(n,e));(a<h.from||a>h.to)&&(a=f),Ql=s.text.slice(Math.min(o,a),Math.max(o,a));let c=l==(n?t.length-1:0)?null:t[l+(n?1:-1)];return c&&a==f&&c.level+(n?0:1)<h.level?w.cursor(c.side(!n,e)+s.from,c.forward(n,e)?1:-1,c.level):w.cursor(a+s.from,h.forward(n,e)?-1:1,h.level)}function Sf(s,t,e){for(let i=t;i<e;i++){let n=ql(s.charCodeAt(i));if(n==1)return Me;if(n==2||n==4)return Zs}return Me}const jl=P.define(),Yl=P.define(),Gl=P.define(),Xl=P.define(),Rs=P.define(),_l=P.define(),Jl=P.define(),tr=P.define(),er=P.define(),Zl=P.define({combine:s=>s.some(t=>t)}),Cf=P.define({combine:s=>s.some(t=>t)}),th=P.define();class Le{constructor(t,e="nearest",i="nearest",n=5,r=5,o=!1){this.range=t,this.y=e,this.x=i,this.yMargin=n,this.xMargin=r,this.isSnapshot=o}map(t){return t.empty?this:new Le(this.range.map(t),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(t){return this.range.to<=t.doc.length?this:new Le(w.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const Ei=R.define({map:(s,t)=>s.map(t)}),eh=R.define();function at(s,t,e){let i=s.facet(Xl);i.length?i[0](t):window.onerror?window.onerror(String(t),e,void 0,void 0,t):e?console.error(e+":",t):console.error(t)}const se=P.define({combine:s=>s.length?s[0]:!0});let Of=0;const si=P.define();class At{constructor(t,e,i,n,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=n,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:n,provide:r,decorations:o}=e||{};return new At(Of++,t,i,n,l=>{let h=[si.of(l)];return o&&h.push(yi.of(f=>{let a=f.plugin(l);return a?o(a):N.none})),r&&h.push(r(l)),h})}static fromClass(t,e){return At.define(i=>new t(i),e)}}class Qn{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(i){if(at(e.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){at(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(!((e=this.value)===null||e===void 0)&&e.destroy)try{this.value.destroy()}catch(i){at(t.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const ih=P.define(),ir=P.define(),yi=P.define(),nh=P.define(),nr=P.define(),sh=P.define();function Ur(s,t){let e=s.state.facet(sh);if(!e.length)return e;let i=e.map(r=>r instanceof Function?r(s):r),n=[];return H.spans(i,t.from,t.to,{point(){},span(r,o,l,h){let f=r-t.from,a=o-t.from,c=n;for(let u=l.length-1;u>=0;u--,h--){let d=l[u].spec.bidiIsolate,p;if(d==null&&(d=Sf(t.text,f,a)),h>0&&c.length&&(p=c[c.length-1]).to==f&&p.direction==d)p.to=a,c=p.inner;else{let g={from:f,to:a,direction:d,inner:[]};c.push(g),c=g.inner}}}}),n}const rh=P.define();function oh(s){let t=0,e=0,i=0,n=0;for(let r of s.state.facet(rh)){let o=r(s);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(e=Math.max(e,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(n=Math.max(n,o.bottom)))}return{left:t,right:e,top:i,bottom:n}}const ri=P.define();class Ct{constructor(t,e,i,n){this.fromA=t,this.toA=e,this.fromB=i,this.toB=n}join(t){return new Ct(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let n=t[e-1];if(!(n.fromA>i.toA)){if(n.toA<i.fromA)break;i=i.join(n),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(e.length==0)return t;let i=[];for(let n=0,r=0,o=0,l=0;;n++){let h=n==t.length?null:t[n],f=o-l,a=h?h.fromB:1e9;for(;r<e.length&&e[r]<a;){let c=e[r],u=e[r+1],d=Math.max(l,c),p=Math.min(a,u);if(d<=p&&new Ct(d+f,p+f,d,p).addToSet(i),u>a)break;r+=2}if(!h)return i;new Ct(h.fromA,h.toA,h.fromB,h.toB).addToSet(i),o=h.toA,l=h.toB}}}class fn{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=_.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,h)=>n.push(new Ct(r,o,l,h))),this.changedRanges=n}static create(t,e,i){return new fn(t,e,i)}get viewportChanged(){return(this.flags&4)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&10)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(t=>t.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}class Kr extends z{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,this.editContextFormatting=N.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.setDOM(t.contentDOM),this.children=[new Y],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new Ct(0,0,0,t.state.doc.length)],0,null)}update(t){var e;let i=t.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:f,toA:a})=>a<this.minWidthFrom||f>this.minWidthTo)?(this.minWidthFrom=t.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=t.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(t);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((e=this.domChanged)===null||e===void 0)&&e.newSel?n=this.domChanged.newSel.head:!Rf(t.changes,this.hasComposition)&&!t.selectionSet&&(n=t.state.selection.main.head));let r=n>-1?Mf(this.view,t.changes,n):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:f,to:a}=this.hasComposition;i=new Ct(f,a,t.changes.mapPos(f,-1),t.changes.mapPos(a,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(O.ie||O.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.updateDeco(),h=Df(o,l,t.changes);return i=Ct.extendWithRanges(i,h),!(this.flags&7)&&i.length==0?!1:(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer: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=O.chrome||O.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 _t&&o.widget instanceof Ts&&r.push(o.dom);n.updateGaps(r)}updateChildren(t,e,i){let n=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let o=n.length-1;;o--){let l=o>=0?n[o]:null;if(!l)break;let{fromA:h,toA:f,fromB:a,toB:c}=l,u,d,p,g;if(i&&i.range.fromB<c&&i.range.toB>a){let k=ci.build(this.view.state.doc,a,i.range.fromB,this.decorations,this.dynamicDecorationMap),v=ci.build(this.view.state.doc,i.range.toB,c,this.decorations,this.dynamicDecorationMap);d=k.breakAtStart,p=k.openStart,g=v.openEnd;let M=this.compositionView(i);v.breakAtStart?M.breakAfter=1:v.content.length&&M.merge(M.length,M.length,v.content[0],!1,v.openStart,0)&&(M.breakAfter=v.content[0].breakAfter,v.content.shift()),k.content.length&&M.merge(0,0,k.content[k.content.length-1],!0,0,k.openEnd)&&k.content.pop(),u=k.content.concat(M).concat(v.content)}else({content:u,breakAtStart:d,openStart:p,openEnd:g}=ci.build(this.view.state.doc,a,c,this.decorations,this.dynamicDecorationMap));let{i:m,off:y}=r.findPos(f,1),{i:x,off:b}=r.findPos(h,-1);Ll(this,x,b,m,y,u,d,p,g)}i&&this.fixCompositionDOM(i)}updateEditContextFormatting(t){this.editContextFormatting=this.editContextFormatting.map(t.changes);for(let e of t.transactions)for(let i of e.effects)i.is(eh)&&(this.editContextFormatting=i.value)}compositionView(t){let e=new Dt(t.text.nodeValue);e.flags|=8;for(let{deco:n}of t.marks)e=new Jt(n,[e],e.length);let i=new Y;return i.append(e,0),i}fixCompositionDOM(t){let e=(r,o)=>{o.flags|=8|(o.children.some(h=>h.flags&7)?1:0),this.markedForComposition.add(o);let l=z.get(r);l&&l!=o&&(l.dom=null),o.setDOM(r)},i=this.childPos(t.range.fromB,1),n=this.children[i.i];e(t.line,n);for(let r=t.marks.length-1;r>=-1;r--)i=n.childPos(i.off,1),n=n.children[i.i],e(r>=0?t.marks[r].node:t.text,n)}updateSelection(t=!1,e=!1){(t||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let i=this.view.root.activeElement,n=i==this.dom,r=!n&&Zi(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(n||e||r))return;let o=this.forceSelection;this.forceSelection=!1;let l=this.view.state.selection.main,h=this.moveToLine(this.domAtPos(l.anchor)),f=l.empty?h:this.moveToLine(this.domAtPos(l.head));if(O.gecko&&l.empty&&!this.hasComposition&&Af(h)){let c=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(c,h.node.childNodes[h.offset]||null)),h=f=new ot(c,0),o=!0}let a=this.view.observer.selectionRange;(o||!a.focusNode||(!fi(h.node,h.offset,a.anchorNode,a.anchorOffset)||!fi(f.node,f.offset,a.focusNode,a.focusOffset))&&!this.suppressWidgetCursorChange(a,l))&&(this.view.observer.ignore(()=>{O.android&&O.chrome&&this.dom.contains(a.focusNode)&&Bf(a.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let c=gi(this.view.root);if(c)if(l.empty){if(O.gecko){let u=Tf(h.node,h.offset);if(u&&u!=3){let d=(u==1?Bl:Rl)(h.node,h.offset);d&&(h=new ot(d.node,d.offset))}}c.collapse(h.node,h.offset),l.bidiLevel!=null&&c.caretBidiLevel!==void 0&&(c.caretBidiLevel=l.bidiLevel)}else if(c.extend){c.collapse(h.node,h.offset);try{c.extend(f.node,f.offset)}catch{}}else{let u=document.createRange();l.anchor>l.head&&([h,f]=[f,h]),u.setEnd(f.node,f.offset),u.setStart(h.node,h.offset),c.removeAllRanges(),c.addRange(u)}r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(h,f)),this.impreciseAnchor=h.precise?null:new ot(a.anchorNode,a.anchorOffset),this.impreciseHead=f.precise?null:new ot(a.focusNode,a.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&fi(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)&&this.posFromDOM(t.focusNode,t.focusOffset)==e.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:t}=this,e=t.state.selection.main,i=gi(t.root),{anchorNode:n,anchorOffset:r}=t.observer.selectionRange;if(!i||!e.empty||!e.assoc||!i.modify)return;let o=Y.find(this,e.head);if(!o)return;let l=o.posAtStart;if(e.head==l||e.head==l+o.length)return;let h=this.coordsAt(e.head,-1),f=this.coordsAt(e.head,1);if(!h||!f||h.bottom>f.top)return;let a=this.domAtPos(e.head+e.assoc);i.collapse(a.node,a.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let c=t.observer.selectionRange;t.docView.posFromDOM(c.anchorNode,c.anchorOffset)!=e.from&&i.collapse(n,r)}moveToLine(t){let e=this.dom,i;if(t.node!=e)return t;for(let n=t.offset;!i&&n<e.childNodes.length;n++){let r=z.get(e.childNodes[n]);r instanceof Y&&(i=r.domAtPos(0))}for(let n=t.offset-1;!i&&n>=0;n--){let r=z.get(e.childNodes[n]);r instanceof Y&&(i=r.domAtPos(r.length))}return i?new ot(i.node,i.offset,!0):t}nearest(t){for(let e=t;e;){let i=z.get(e);if(i&&i.rootView==this)return i;e=e.parentNode}return null}posFromDOM(t,e){let i=this.nearest(t);if(!i)throw new RangeError("Trying to find position for a DOM position outside of the document");return i.localPosFromDOM(t,e)+i.posAtStart}domAtPos(t){let{i:e,off:i}=this.childCursor().findPos(t,-1);for(;e<this.children.length-1;){let n=this.children[e];if(i<n.length||n instanceof Y)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,n=0;for(let r=this.length,o=this.children.length-1;o>=0;o--){let l=this.children[o],h=r-l.breakAfter,f=h-l.length;if(h<t)break;if(f<=t&&(f<t||l.covers(-1))&&(h>t||l.covers(1))&&(!i||l instanceof Y&&!(i instanceof Y&&e>=0)))i=l,n=f;else if(i&&f==t&&h==t&&l instanceof _t&&Math.abs(e)<2){if(l.deco.startSide<0)break;o&&(i=null)}r=f}return i?i.coordsAt(t-n,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),n=this.children[e];if(!(n instanceof Y))return null;for(;n.children.length;){let{i:l,off:h}=n.childPos(i,1);for(;;l++){if(l==n.children.length)return null;if((n=n.children[l]).length)break}i=h}if(!(n instanceof Dt))return null;let r=ht(n.text,i);if(r==i)return null;let o=Ae(n.dom,i,r).getClientRects();for(let l=0;l<o.length;l++){let h=o[l];if(l==o.length-1||h.top<h.bottom&&h.left<h.right)return h}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:n}=t,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,h=this.view.textDirection==j.LTR;for(let f=0,a=0;a<this.children.length;a++){let c=this.children[a],u=f+c.length;if(u>n)break;if(f>=i){let d=c.dom.getBoundingClientRect();if(e.push(d.height),o){let p=c.dom.lastChild,g=p?mi(p):[];if(g.length){let m=g[g.length-1],y=h?m.right-d.left:d.right-m.left;y>l&&(l=y,this.minWidth=r,this.minWidthFrom=f,this.minWidthTo=u)}}}f=u+c.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return getComputedStyle(this.children[e].dom).direction=="rtl"?j.RTL:j.LTR}measureTextSize(){for(let r of this.children)if(r instanceof Y){let o=r.measureTextSize();if(o)return o}let t=document.createElement("div"),e,i,n;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.dom.appendChild(t);let r=mi(t.firstChild)[0];e=t.getBoundingClientRect().height,i=r?r.width/27:7,n=r?r.height:e,t.remove()}),{lineHeight:e,charWidth:i,textHeight:n}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new El(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,n=0;;n++){let r=n==e.viewports.length?null:e.viewports[n],o=r?r.from-1:this.length;if(o>i){let l=(e.lineBlockAt(o).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(N.replace({widget:new Ts(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;i=r.to+1}return N.set(t)}updateDeco(){let t=1,e=this.view.state.facet(yi).map(r=>(this.dynamicDecorationMap[t++]=typeof r=="function")?r(this.view):r),i=!1,n=this.view.state.facet(nh).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(n.length&&(this.dynamicDecorationMap[t++]=i,e.push(H.join(n))),this.decorations=[this.editContextFormatting,...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let f=this.view.viewState.lineBlockAt(t.range.head);this.view.scrollDOM.scrollTop=f.top-t.yMargin,this.view.scrollDOM.scrollLeft=t.xMargin;return}for(let f of this.view.state.facet(th))try{if(f(this.view,t.range,t))return!0}catch(a){at(this.view.state,a,"scroll handler")}let{range:e}=t,i=this.coordsAt(e.head,e.empty?e.assoc:e.head>e.anchor?-1:1),n;if(!i)return;!e.empty&&(n=this.coordsAt(e.anchor,e.anchor>e.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=oh(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:h}=this.view.scrollDOM;sf(this.view.scrollDOM,o,e.head<e.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,l),-l),Math.max(Math.min(t.yMargin,h),-h),this.view.textDirection==j.LTR)}}function Af(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")}function lh(s,t){let e=s.observer.selectionRange;if(!e.focusNode)return null;let i=Bl(e.focusNode,e.focusOffset),n=Rl(e.focusNode,e.focusOffset),r=i||n;if(n&&i&&n.node!=i.node){let l=z.get(n.node);if(!l||l instanceof Dt&&l.text!=n.node.nodeValue)r=n;else if(s.docView.lastCompositionAfterCursor){let h=z.get(i.node);!h||h instanceof Dt&&h.text!=i.node.nodeValue||(r=n)}}if(s.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=t-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Mf(s,t,e){let i=lh(s,e);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 h=t.invertedDesc,f=new Ct(h.mapPos(r),h.mapPos(o),r,o),a=[];for(let c=n.parentNode;;c=c.parentNode){let u=z.get(c);if(u instanceof Jt)a.push({node:c,deco:u.mark});else{if(u instanceof Y||c.nodeName=="DIV"&&c.parentNode==s.contentDOM)return{range:f,text:n,marks:a,line:c};if(c!=s.contentDOM)a.push({node:c,deco:new Si({inclusive:!0,attributes:df(c),tagName:c.tagName.toLowerCase()})});else return null}}}function Tf(s,t){return s.nodeType!=1?0:(t&&s.childNodes[t-1].contentEditable=="false"?1:0)|(t<s.childNodes.length&&s.childNodes[t].contentEditable=="false"?2:0)}let Pf=class{constructor(){this.changes=[]}compareRange(t,e){Ms(t,e,this.changes)}comparePoint(t,e){Ms(t,e,this.changes)}};function Df(s,t,e){let i=new Pf;return H.compare(s,t,e,i),i.changes}function Bf(s,t){for(let e=s;e&&e!=t;e=e.assignedSlot||e.parentNode)if(e.nodeType==1&&e.contentEditable=="false")return!0;return!1}function Rf(s,t){let e=!1;return t&&s.iterChangedRanges((i,n)=>{i<t.to&&n>t.from&&(e=!0)}),e}function Ef(s,t,e=1){let i=s.charCategorizer(t),n=s.doc.lineAt(t),r=t-n.from;if(n.length==0)return w.cursor(t);r==0?e=1:r==n.length&&(e=-1);let o=r,l=r;e<0?o=ht(n.text,r,!1):l=ht(n.text,r);let h=i(n.text.slice(o,l));for(;o>0;){let f=ht(n.text,o,!1);if(i(n.text.slice(f,o))!=h)break;o=f}for(;l<n.length;){let f=ht(n.text,l);if(i(n.text.slice(l,f))!=h)break;l=f}return w.range(o+n.from,l+n.from)}function Lf(s,t){return t.left>s?t.left-s:Math.max(0,s-t.right)}function If(s,t){return t.top>s?t.top-s:Math.max(0,s-t.bottom)}function jn(s,t){return s.top<t.bottom-1&&s.bottom>t.top+1}function Qr(s,t){return t<s.top?{top:t,left:s.left,right:s.right,bottom:s.bottom}:s}function jr(s,t){return t>s.bottom?{top:s.top,left:s.left,right:s.right,bottom:t}:s}function Es(s,t,e){let i,n,r,o,l=!1,h,f,a,c;for(let p=s.firstChild;p;p=p.nextSibling){let g=mi(p);for(let m=0;m<g.length;m++){let y=g[m];n&&jn(n,y)&&(y=Qr(jr(y,n.bottom),n.top));let x=Lf(t,y),b=If(e,y);if(x==0&&b==0)return p.nodeType==3?Yr(p,t,e):Es(p,t,e);if(!i||o>b||o==b&&r>x){i=p,n=y,r=x,o=b;let k=b?e<y.top?-1:1:x?t<y.left?-1:1:0;l=!k||(k>0?m<g.length-1:m>0)}x==0?e>y.bottom&&(!a||a.bottom<y.bottom)?(h=p,a=y):e<y.top&&(!c||c.top>y.top)&&(f=p,c=y):a&&jn(a,y)?a=jr(a,y.bottom):c&&jn(c,y)&&(c=Qr(c,y.top))}}if(a&&a.bottom>=e?(i=h,n=a):c&&c.top<=e&&(i=f,n=c),!i)return{node:s,offset:0};let u=Math.max(n.left,Math.min(n.right,t));if(i.nodeType==3)return Yr(i,u,e);if(l&&i.contentEditable!="false")return Es(i,u,e);let d=Array.prototype.indexOf.call(s.childNodes,i)+(t>=(n.left+n.right)/2?1:0);return{node:s,offset:d}}function Yr(s,t,e){let i=s.nodeValue.length,n=-1,r=1e9,o=0;for(let l=0;l<i;l++){let h=Ae(s,l,l+1).getClientRects();for(let f=0;f<h.length;f++){let a=h[f];if(a.top==a.bottom)continue;o||(o=t-a.left);let c=(a.top>e?a.top-e:e-a.bottom)-1;if(a.left-1<=t&&a.right+1>=t&&c<r){let u=t>=(a.left+a.right)/2,d=u;if((O.chrome||O.gecko)&&Ae(s,l).getBoundingClientRect().left==a.right&&(d=!u),c<=0)return{node:s,offset:l+(d?1:0)};n=l+(d?1:0),r=c}}}return{node:s,offset:n>-1?n:o>0?s.nodeValue.length:0}}function hh(s,t,e,i=-1){var n,r;let o=s.contentDOM.getBoundingClientRect(),l=o.top+s.viewState.paddingTop,h,{docHeight:f}=s.viewState,{x:a,y:c}=t,u=c-l;if(u<0)return 0;if(u>f)return s.state.doc.length;for(let k=s.viewState.heightOracle.textHeight/2,v=!1;h=s.elementAtHeight(u),h.type!=jt.Text;)for(;u=i>0?h.bottom+k:h.top-k,!(u>=0&&u<=f);){if(v)return e?null:0;v=!0,i=-i}c=l+u;let d=h.from;if(d<s.viewport.from)return s.viewport.from==0?0:e?null:Gr(s,o,h,a,c);if(d>s.viewport.to)return s.viewport.to==s.state.doc.length?s.state.doc.length:e?null:Gr(s,o,h,a,c);let p=s.dom.ownerDocument,g=s.root.elementFromPoint?s.root:p,m=g.elementFromPoint(a,c);m&&!s.contentDOM.contains(m)&&(m=null),m||(a=Math.max(o.left+1,Math.min(o.right-1,a)),m=g.elementFromPoint(a,c),m&&!s.contentDOM.contains(m)&&(m=null));let y,x=-1;if(m&&((n=s.docView.nearest(m))===null||n===void 0?void 0:n.isEditable)!=!1){if(p.caretPositionFromPoint){let k=p.caretPositionFromPoint(a,c);k&&({offsetNode:y,offset:x}=k)}else if(p.caretRangeFromPoint){let k=p.caretRangeFromPoint(a,c);k&&({startContainer:y,startOffset:x}=k,(!s.contentDOM.contains(y)||O.safari&&Nf(y,x,a)||O.chrome&&Ff(y,x,a))&&(y=void 0))}y&&(x=Math.min(Yt(y),x))}if(!y||!s.docView.dom.contains(y)){let k=Y.find(s.docView,d);if(!k)return u>h.top+h.height/2?h.to:h.from;({node:y,offset:x}=Es(k.dom,a,c))}let b=s.docView.nearest(y);if(!b)return null;if(b.isWidget&&((r=b.dom)===null||r===void 0?void 0:r.nodeType)==1){let k=b.dom.getBoundingClientRect();return t.y<k.top||t.y<=k.bottom&&t.x<=(k.left+k.right)/2?b.posAtStart:b.posAtEnd}else return b.localPosFromDOM(y,x)+b.posAtStart}function Gr(s,t,e,i,n){let r=Math.round((i-t.left)*s.defaultCharacterWidth);if(s.lineWrapping&&e.height>s.defaultLineHeight*1.5){let l=s.viewState.heightOracle.textHeight,h=Math.floor((n-e.top-(s.defaultLineHeight-l)*.5)/l);r+=h*s.viewState.heightOracle.lineLength}let o=s.state.sliceDoc(e.from,e.to);return e.from+_a(o,r,s.state.tabSize)}function Nf(s,t,e){let i;if(s.nodeType!=3||t!=(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 Ae(s,i-1,i).getBoundingClientRect().left>e}function Ff(s,t,e){if(t!=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():Ae(s,0,Math.max(s.nodeValue.length,1)).getBoundingClientRect();return e-i.left>5}function Vf(s,t){let e=s.lineBlockAt(t);if(Array.isArray(e.type)){for(let i of e.type)if(i.to>t||i.to==t&&(i.to==e.to||i.type==jt.Text))return i}return e}function Hf(s,t,e,i){let n=Vf(s,t.head),r=!i||n.type!=jt.Text||!(s.lineWrapping||n.widgetLineBreaks)?null:s.coordsAtPos(t.assoc<0&&t.head>n.from?t.head-1:t.head);if(r){let o=s.dom.getBoundingClientRect(),l=s.textDirectionAt(n.from),h=s.posAtCoords({x:e==(l==j.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(h!=null)return w.cursor(h,e?-1:1)}return w.cursor(e?n.to:n.from,e?-1:1)}function Xr(s,t,e,i){let n=s.state.doc.lineAt(t.head),r=s.bidiSpans(n),o=s.textDirectionAt(n.from);for(let l=t,h=null;;){let f=vf(n,r,o,l,e),a=Ql;if(!f){if(n.number==(e?s.state.doc.lines:1))return l;a=`
8
+ `,n=s.state.doc.line(n.number+(e?1:-1)),r=s.bidiSpans(n),f=s.visualLineSide(n,!e)}if(h){if(!h(a))return l}else{if(!i)return f;h=i(a)}l=f}}function zf(s,t,e){let i=s.state.charCategorizer(t),n=i(e);return r=>{let o=i(r);return n==kt.Space&&(n=o),n==o}}function Wf(s,t,e,i){let n=t.head,r=e?1:-1;if(n==(e?s.state.doc.length:0))return w.cursor(n,t.assoc);let o=t.goalColumn,l,h=s.contentDOM.getBoundingClientRect(),f=s.coordsAtPos(n,t.assoc||-1),a=s.documentTop;if(f)o==null&&(o=f.left-h.left),l=r<0?f.top:f.bottom;else{let d=s.viewState.lineBlockAt(n);o==null&&(o=Math.min(h.right-h.left,s.defaultCharacterWidth*(n-d.from))),l=(r<0?d.top:d.bottom)+a}let c=h.left+o,u=i??s.viewState.heightOracle.textHeight>>1;for(let d=0;;d+=10){let p=l+(u+d)*r,g=hh(s,{x:c,y:p},!1,r);if(p<h.top||p>h.bottom||(r<0?g<n:g>n)){let m=s.docView.coordsForChar(g),y=!m||p<m.top?-1:1;return w.cursor(g,y,void 0,o)}}}function tn(s,t,e){for(;;){let i=0;for(let n of s)n.between(t-1,t+1,(r,o,l)=>{if(t>r&&t<o){let h=i||e||(t-r<o-t?-1:1);t=h<0?r:o,i=h}});if(!i)return t}}function Yn(s,t,e){let i=tn(s.state.facet(nr).map(n=>n(s)),e.from,t.head>e.from?-1:1);return i==e.from?e:w.cursor(i,i<e.from?1:-1)}const oi="￿";class $f{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(F.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=oi}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let n=t;;){this.findPointBefore(i,n);let r=this.text.length;this.readNode(n);let o=n.nextSibling;if(o==e)break;let l=z.get(n),h=z.get(o);(l&&h?l.breakAfter:(l?l.breakAfter:hn(n))||hn(o)&&(n.nodeName!="BR"||n.cmIgnore)&&this.text.length>r)&&this.lineBreak(),n=o}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,n=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=e.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=n.exec(e))&&(r=l.index,o=l[0].length),this.append(e.slice(i,r<0?e.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let h of this.points)h.node==t&&h.pos>this.text.length&&(h.pos-=o-1);i=r+o}}readNode(t){if(t.cmIgnore)return;let e=z.get(t),i=e&&e.overrideDOMText;if(i!=null){this.findPointInside(t,i.length);for(let n=i.iter();!n.next().done;)n.lineBreak?this.lineBreak():this.append(n.value)}else t.nodeType==3?this.readTextNode(t):t.nodeName=="BR"?t.nextSibling&&this.lineBreak():t.nodeType==1&&this.readRange(t.firstChild,null)}findPointBefore(t,e){for(let i of this.points)i.node==t&&t.childNodes[i.offset]==e&&(i.pos=this.text.length)}findPointInside(t,e){for(let i of this.points)(t.nodeType==3?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(qf(t,i.node,i.offset)?e:0))}}function qf(s,t,e){for(;;){if(!t||e<Yt(t))return!1;if(t==s)return!0;e=Oe(t)+1,t=t.parentNode}}class _r{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class Uf{constructor(t,e,i,n){this.typeOver=n,this.bounds=null,this.text="",this.domChanged=e>-1;let{impreciseHead:r,impreciseAnchor:o}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let l=r||o?[]:jf(t),h=new $f(l,t.state);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=Yf(l,this.bounds.from)}else{let l=t.observer.selectionRange,h=r&&r.node==l.focusNode&&r.offset==l.focusOffset||!ks(t.contentDOM,l.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(l.focusNode,l.focusOffset),f=o&&o.node==l.anchorNode&&o.offset==l.anchorOffset||!ks(t.contentDOM,l.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(l.anchorNode,l.anchorOffset),a=t.viewport;if((O.ios||O.chrome)&&t.state.selection.main.empty&&h!=f&&(a.from>0||a.to<t.state.doc.length)){let c=Math.min(h,f),u=Math.max(h,f),d=a.from-c,p=a.to-u;(d==0||d==1||c==0)&&(p==0||p==-1||u==t.state.doc.length)&&(h=0,f=t.state.doc.length)}this.newSel=w.single(f,h)}}}function ah(s,t){let e,{newSel:i}=t,n=s.state.selection.main,r=s.inputState.lastKeyTime>Date.now()-100?s.inputState.lastKeyCode:-1;if(t.bounds){let{from:o,to:l}=t.bounds,h=n.from,f=null;(r===8||O.android&&t.text.length<l-o)&&(h=n.to,f="end");let a=Qf(s.state.doc.sliceString(o,l,oi),t.text,h-o,f);a&&(O.chrome&&r==13&&a.toB==a.from+2&&t.text.slice(a.from,a.toB)==oi+oi&&a.toB--,e={from:o+a.from,to:o+a.toA,insert:L.of(t.text.slice(a.from,a.toB).split(oi))})}else i&&(!s.hasFocus&&s.state.facet(se)||i.main.eq(n))&&(i=null);if(!e&&!i)return!1;if(!e&&t.typeOver&&!n.empty&&i&&i.main.empty?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,n.to)}:e&&e.from>=n.from&&e.to<=n.to&&(e.from!=n.from||e.to!=n.to)&&n.to-n.from-(e.to-e.from)<=4?e={from:n.from,to:n.to,insert:s.state.doc.slice(n.from,e.from).append(e.insert).append(s.state.doc.slice(e.to,n.to))}:(O.mac||O.android)&&e&&e.from==e.to&&e.from==n.head-1&&/^\. ?$/.test(e.insert.toString())&&s.contentDOM.getAttribute("autocorrect")=="off"?(i&&e.insert.length==2&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:L.of([" "])}):O.chrome&&e&&e.from==e.to&&e.from==n.head&&e.insert.toString()==`
9
+ `&&s.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),e={from:n.from,to:n.to,insert:L.of([" "])}),e)return sr(s,e,i,r);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 sr(s,t,e,i=-1){if(O.ios&&s.inputState.flushIOSKey(t))return!0;let n=s.state.selection.main;if(O.android&&(t.to==n.to&&(t.from==n.from||t.from==n.from-1&&s.state.sliceDoc(t.from,n.from)==" ")&&t.insert.length==1&&t.insert.lines==2&&Ee(s.contentDOM,"Enter",13)||(t.from==n.from-1&&t.to==n.to&&t.insert.length==0||i==8&&t.insert.length<t.to-t.from&&t.to>n.head)&&Ee(s.contentDOM,"Backspace",8)||t.from==n.from&&t.to==n.to+1&&t.insert.length==0&&Ee(s.contentDOM,"Delete",46)))return!0;let r=t.insert.toString();s.inputState.composing>=0&&s.inputState.composing++;let o,l=()=>o||(o=Kf(s,t,e));return s.state.facet(_l).some(h=>h(s,t.from,t.to,r,l))||s.dispatch(l()),!0}function Kf(s,t,e){let i,n=s.state,r=n.selection.main;if(t.from>=r.from&&t.to<=r.to&&t.to-t.from>=(r.to-r.from)/3&&(!e||e.main.empty&&e.main.from==t.from+t.insert.length)&&s.inputState.composing<0){let l=r.from<t.from?n.sliceDoc(r.from,t.from):"",h=r.to>t.to?n.sliceDoc(t.to,r.to):"";i=n.replaceSelection(s.state.toText(l+t.insert.sliceString(0,void 0,s.state.lineBreak)+h))}else{let l=n.changes(t),h=e&&e.main.to<=l.newLength?e.main:void 0;if(n.selection.ranges.length>1&&s.inputState.composing>=0&&t.to<=r.to&&t.to>=r.to-10){let f=s.state.sliceDoc(t.from,t.to),a,c=e&&lh(s,e.main.head);if(c){let p=t.insert.length-(t.to-t.from);a={from:c.from,to:c.to-p}}else a=s.state.doc.lineAt(r.head);let u=r.to-t.to,d=r.to-r.from;i=n.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:l,range:h||p.map(l)};let g=p.to-u,m=g-f.length;if(p.to-p.from!=d||s.state.sliceDoc(m,g)!=f||p.to>=a.from&&p.from<=a.to)return{range:p};let y=n.changes({from:m,to:g,insert:t.insert}),x=p.to-r.to;return{changes:y,range:h?w.range(Math.max(0,h.anchor+x),Math.max(0,h.head+x)):p.map(y)}})}else i={changes:l,selection:h&&n.selection.replaceRange(h)}}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 Qf(s,t,e,i){let n=Math.min(s.length,t.length),r=0;for(;r<n&&s.charCodeAt(r)==t.charCodeAt(r);)r++;if(r==n&&s.length==t.length)return null;let o=s.length,l=t.length;for(;o>0&&l>0&&s.charCodeAt(o-1)==t.charCodeAt(l-1);)o--,l--;if(i=="end"){let h=Math.max(0,r-Math.min(o,l));e-=o+h-r}if(o<r&&s.length<t.length){let h=e<=r&&e>=o?r-e:0;r-=h,l=r+(l-o),o=r}else if(l<r){let h=e<=r&&e>=l?r-e:0;r-=h,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function jf(s){let t=[];if(s.root.activeElement!=s.contentDOM)return t;let{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=s.observer.selectionRange;return e&&(t.push(new _r(e,i)),(n!=e||r!=i)&&t.push(new _r(n,r))),t}function Yf(s,t){if(s.length==0)return null;let e=s[0].pos,i=s.length==2?s[1].pos:e;return e>-1&&i>-1?w.single(e+t,i+t):null}class Gf{setSelectionOrigin(t){this.lastSelectionOrigin=t,this.lastSelectionTime=Date.now()}constructor(t){this.view=t,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,O.safari&&t.contentDOM.addEventListener("input",()=>null),O.gecko&&cc(t.contentDOM.ownerDocument)}handleEvent(t){!nc(this.view,t)||this.ignoreDuringComposition(t)||t.type=="keydown"&&this.keydown(t)||this.runHandlers(t.type,t)}runHandlers(t,e){let i=this.handlers[t];if(i){for(let n of i.observers)n(this.view,e);for(let n of i.handlers){if(e.defaultPrevented)break;if(n(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Xf(t),i=this.handlers,n=this.view.contentDOM;for(let r in e)if(r!="scroll"){let o=!e[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(n.removeEventListener(r,this.handleEvent),l=null),l||n.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!e[r]&&n.removeEventListener(r,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),t.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&t.keyCode!=27&&ch.indexOf(t.keyCode)<0&&(this.tabFocusMode=-1),O.android&&O.chrome&&!t.synthetic&&(t.keyCode==13||t.keyCode==8))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return O.ios&&!t.synthetic&&!t.altKey&&!t.metaKey&&((e=fh.find(i=>i.keyCode==t.keyCode))&&!t.ctrlKey||_f.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(this.pendingIOSKey=e||t,setTimeout(()=>this.flushIOSKey(),250),!0):(t.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(t){let e=this.pendingIOSKey;return!e||e.key=="Enter"&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString())?!1:(this.pendingIOSKey=void 0,Ee(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0))}ignoreDuringComposition(t){return/^key/.test(t.type)?this.composing>0?!0:O.safari&&!O.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1:!1}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}update(t){this.view.observer.update(t),this.mouseSelection&&this.mouseSelection.update(t),this.draggedContent&&t.docChanged&&(this.draggedContent=this.draggedContent.map(t.changes)),t.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Jr(s,t){return(e,i)=>{try{return t.call(s,i,e)}catch(n){at(e.state,n)}}}function Xf(s){let t=Object.create(null);function e(i){return t[i]||(t[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&&e(r).handlers.push(Jr(i.value,o))}if(n&&n.domEventObservers)for(let r in n.domEventObservers){let o=n.domEventObservers[r];o&&e(r).observers.push(Jr(i.value,o))}}for(let i in Bt)e(i).handlers.push(Bt[i]);for(let i in Mt)e(i).observers.push(Mt[i]);return t}const fh=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],_f="dthko",ch=[16,17,18,20,91,92,224,225],Li=6;function Ii(s){return Math.max(0,s)*.7+8}function Jf(s,t){return Math.max(Math.abs(s.clientX-t.clientX),Math.abs(s.clientY-t.clientY))}class Zf{constructor(t,e,i,n){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=n,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParents=rf(t.contentDOM),this.atoms=t.state.facet(nr).map(o=>o(t));let r=t.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=e.shiftKey,this.multiple=t.state.facet(F.allowMultipleSelections)&&tc(t,e),this.dragging=ic(t,e)&&ph(e)==1?null:!1}start(t){this.dragging===!1&&this.select(t)}move(t){if(t.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Jf(this.startEvent,t)<10)return;this.select(this.lastEvent=t);let e=0,i=0,n=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:n,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let h=oh(this.view);t.clientX-h.left<=n+Li?e=-Ii(n-t.clientX):t.clientX+h.right>=o-Li&&(e=Ii(t.clientX-o)),t.clientY-h.top<=r+Li?i=-Ii(r-t.clientY):t.clientY+h.bottom>=l-Li&&(i=Ii(t.clientY-l)),this.setScrollSpeed(e,i)}up(t){this.dragging==null&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:t,y:e}=this.scrollSpeed;t&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=t,t=0),e&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=e,e=0),(t||e)&&this.view.win.scrollBy(t,e),this.dragging===!1&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let n=t.ranges[i],r=null;if(n.empty){let o=tn(this.atoms,n.from,0);o!=n.from&&(r=w.cursor(o,-1))}else{let o=tn(this.atoms,n.from,-1),l=tn(this.atoms,n.to,1);(o!=n.from||l!=n.to)&&(r=w.range(n.from==n.anchor?o:l,n.from==n.head?o:l))}r&&(e||(e=t.ranges.slice()),e[i]=r)}return e?w.create(e,t.mainIndex):t}select(t){let{view:e}=this,i=this.skipAtoms(this.style.get(t,this.extend,this.multiple));(this.mustSelect||!i.eq(e.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){t.transactions.some(e=>e.isUserEvent("input.type"))?this.destroy():this.style.update(t)&&setTimeout(()=>this.select(this.lastEvent),20)}}function tc(s,t){let e=s.state.facet(jl);return e.length?e[0](t):O.mac?t.metaKey:t.ctrlKey}function ec(s,t){let e=s.state.facet(Yl);return e.length?e[0](t):O.mac?!t.altKey:!t.ctrlKey}function ic(s,t){let{main:e}=s.state.selection;if(e.empty)return!1;let i=gi(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<=t.clientX&&o.right>=t.clientX&&o.top<=t.clientY&&o.bottom>=t.clientY)return!0}return!1}function nc(s,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let e=t.target,i;e!=s.contentDOM;e=e.parentNode)if(!e||e.nodeType==11||(i=z.get(e))&&i.ignoreEvent(t))return!1;return!0}const Bt=Object.create(null),Mt=Object.create(null),uh=O.ie&&O.ie_version<15||O.ios&&O.webkit_version<604;function sc(s){let t=s.dom.parentNode;if(!t)return;let e=t.appendChild(document.createElement("textarea"));e.style.cssText="position: fixed; left: -10000px; top: 10px",e.focus(),setTimeout(()=>{s.focus(),e.remove(),dh(s,e.value)},50)}function En(s,t,e){for(let i of s.facet(t))e=i(e,s);return e}function dh(s,t){t=En(s.state,tr,t);let{state:e}=s,i,n=1,r=e.toText(t),o=r.lines==e.selection.ranges.length;if(Ls!=null&&e.selection.ranges.every(h=>h.empty)&&Ls==r.toString()){let h=-1;i=e.changeByRange(f=>{let a=e.doc.lineAt(f.from);if(a.from==h)return{range:f};h=a.from;let c=e.toText((o?r.line(n++).text:t)+e.lineBreak);return{changes:{from:a.from,insert:c},range:w.cursor(f.from+c.length)}})}else o?i=e.changeByRange(h=>{let f=r.line(n++);return{changes:{from:h.from,to:h.to,insert:f.text},range:w.cursor(h.from+f.length)}}):i=e.replaceSelection(r);s.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}Mt.scroll=s=>{s.inputState.lastScrollTop=s.scrollDOM.scrollTop,s.inputState.lastScrollLeft=s.scrollDOM.scrollLeft};Bt.keydown=(s,t)=>(s.inputState.setSelectionOrigin("select"),t.keyCode==27&&s.inputState.tabFocusMode!=0&&(s.inputState.tabFocusMode=Date.now()+2e3),!1);Mt.touchstart=(s,t)=>{s.inputState.lastTouchTime=Date.now(),s.inputState.setSelectionOrigin("select.pointer")};Mt.touchmove=s=>{s.inputState.setSelectionOrigin("select.pointer")};Bt.mousedown=(s,t)=>{if(s.observer.flush(),s.inputState.lastTouchTime>Date.now()-2e3)return!1;let e=null;for(let i of s.state.facet(Gl))if(e=i(s,t),e)break;if(!e&&t.button==0&&(e=lc(s,t)),e){let i=!s.hasFocus;s.inputState.startMouseSelection(new Zf(s,t,e,i)),i&&s.observer.ignore(()=>{Tl(s.contentDOM);let r=s.root.activeElement;r&&!r.contains(s.contentDOM)&&r.blur()});let n=s.inputState.mouseSelection;if(n)return n.start(t),n.dragging===!1}return!1};function Zr(s,t,e,i){if(i==1)return w.cursor(t,e);if(i==2)return Ef(s.state,t,e);{let n=Y.find(s.docView,t),r=s.state.doc.lineAt(n?n.posAtEnd:t),o=n?n.posAtStart:r.from,l=n?n.posAtEnd:r.to;return l<s.state.doc.length&&l==r.to&&l++,w.range(o,l)}}let to=(s,t,e)=>t>=e.top&&t<=e.bottom&&s>=e.left&&s<=e.right;function rc(s,t,e,i){let n=Y.find(s.docView,t);if(!n)return 1;let r=t-n.posAtStart;if(r==0)return 1;if(r==n.length)return-1;let o=n.coordsAt(r,-1);if(o&&to(e,i,o))return-1;let l=n.coordsAt(r,1);return l&&to(e,i,l)?1:o&&o.bottom>=i?-1:1}function eo(s,t){let e=s.posAtCoords({x:t.clientX,y:t.clientY},!1);return{pos:e,bias:rc(s,e,t.clientX,t.clientY)}}const oc=O.ie&&O.ie_version<=11;let io=null,no=0,so=0;function ph(s){if(!oc)return s.detail;let t=io,e=so;return io=s,so=Date.now(),no=!t||e>Date.now()-400&&Math.abs(t.clientX-s.clientX)<2&&Math.abs(t.clientY-s.clientY)<2?(no+1)%3:1}function lc(s,t){let e=eo(s,t),i=ph(t),n=s.state.selection;return{update(r){r.docChanged&&(e.pos=r.changes.mapPos(e.pos),n=n.map(r.changes))},get(r,o,l){let h=eo(s,r),f,a=Zr(s,h.pos,h.bias,i);if(e.pos!=h.pos&&!o){let c=Zr(s,e.pos,e.bias,i),u=Math.min(c.from,a.from),d=Math.max(c.to,a.to);a=u<a.from?w.range(u,d):w.range(d,u)}return o?n.replaceRange(n.main.extend(a.from,a.to)):l&&i==1&&n.ranges.length>1&&(f=hc(n,h.pos))?f:l?n.addRange(a):w.create([a])}}}function hc(s,t){for(let e=0;e<s.ranges.length;e++){let{from:i,to:n}=s.ranges[e];if(i<=t&&n>=t)return w.create(s.ranges.slice(0,e).concat(s.ranges.slice(e+1)),s.mainIndex==e?0:s.mainIndex-(s.mainIndex>e?1:0))}return null}Bt.dragstart=(s,t)=>{let{selection:{main:e}}=s.state;if(t.target.draggable){let n=s.docView.nearest(t.target);if(n&&n.isWidget){let r=n.posAtStart,o=r+n.length;(r>=e.to||o<=e.from)&&(e=w.range(r,o))}}let{inputState:i}=s;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=e,t.dataTransfer&&(t.dataTransfer.setData("Text",En(s.state,er,s.state.sliceDoc(e.from,e.to))),t.dataTransfer.effectAllowed="copyMove"),!1};Bt.dragend=s=>(s.inputState.draggedContent=null,!1);function ro(s,t,e,i){if(e=En(s.state,tr,e),!e)return;let n=s.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:r}=s.inputState,o=i&&r&&ec(s,t)?{from:r.from,to:r.to}:null,l={from:n,insert:e},h=s.state.changes(o?[o,l]:l);s.focus(),s.dispatch({changes:h,selection:{anchor:h.mapPos(n,-1),head:h.mapPos(n,1)},userEvent:o?"move.drop":"input.drop"}),s.inputState.draggedContent=null}Bt.drop=(s,t)=>{if(!t.dataTransfer)return!1;if(s.state.readOnly)return!0;let e=t.dataTransfer.files;if(e&&e.length){let i=Array(e.length),n=0,r=()=>{++n==e.length&&ro(s,t,i.filter(o=>o!=null).join(s.state.lineBreak),!1)};for(let o=0;o<e.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(e[o])}return!0}else{let i=t.dataTransfer.getData("Text");if(i)return ro(s,t,i,!0),!0}return!1};Bt.paste=(s,t)=>{if(s.state.readOnly)return!0;s.observer.flush();let e=uh?null:t.clipboardData;return e?(dh(s,e.getData("text/plain")||e.getData("text/uri-list")),!0):(sc(s),!1)};function ac(s,t){let e=s.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=t,i.focus(),i.selectionEnd=t.length,i.selectionStart=0,setTimeout(()=>{i.remove(),s.focus()},50)}function fc(s){let t=[],e=[],i=!1;for(let n of s.selection.ranges)n.empty||(t.push(s.sliceDoc(n.from,n.to)),e.push(n));if(!t.length){let n=-1;for(let{from:r}of s.selection.ranges){let o=s.doc.lineAt(r);o.number>n&&(t.push(o.text),e.push({from:o.from,to:Math.min(s.doc.length,o.to+1)})),n=o.number}i=!0}return{text:En(s,er,t.join(s.lineBreak)),ranges:e,linewise:i}}let Ls=null;Bt.copy=Bt.cut=(s,t)=>{let{text:e,ranges:i,linewise:n}=fc(s.state);if(!e&&!n)return!1;Ls=n?e:null,t.type=="cut"&&!s.state.readOnly&&s.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=uh?null:t.clipboardData;return r?(r.clearData(),r.setData("text/plain",e),!0):(ac(s,e),!1)};const gh=Zt.define();function mh(s,t){let e=[];for(let i of s.facet(Jl)){let n=i(s,t);n&&e.push(n)}return e?s.update({effects:e,annotations:gh.of(!0)}):null}function yh(s){setTimeout(()=>{let t=s.hasFocus;if(t!=s.inputState.notifiedFocused){let e=mh(s.state,t);e?s.dispatch(e):s.update([])}},10)}Mt.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),yh(s)};Mt.blur=s=>{s.observer.clearSelectionRange(),yh(s)};Mt.compositionstart=Mt.compositionupdate=s=>{s.observer.editContext||(s.inputState.compositionFirstChange==null&&(s.inputState.compositionFirstChange=!0),s.inputState.composing<0&&(s.inputState.composing=0))};Mt.compositionend=s=>{s.observer.editContext||(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,O.chrome&&O.android?s.observer.flushSoon():s.inputState.compositionPendingChange?Promise.resolve().then(()=>s.observer.flush()):setTimeout(()=>{s.inputState.composing<0&&s.docView.hasComposition&&s.update([])},50))};Mt.contextmenu=s=>{s.inputState.lastContextMenu=Date.now()};Bt.beforeinput=(s,t)=>{var e,i;if(t.inputType=="insertReplacementText"&&s.observer.editContext){let r=(e=t.dataTransfer)===null||e===void 0?void 0:e.getData("text/plain"),o=t.getTargetRanges();if(r&&o.length){let l=o[0],h=s.posAtDOM(l.startContainer,l.startOffset),f=s.posAtDOM(l.endContainer,l.endOffset);return sr(s,{from:h,to:f,insert:s.state.toText(r)},null),!0}}let n;if(O.chrome&&O.android&&(n=fh.find(r=>r.inputType==t.inputType))&&(s.observer.delayAndroidKey(n.key,n.keyCode),n.key=="Backspace"||n.key=="Delete")){let r=((i=window.visualViewport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&s.hasFocus&&(s.contentDOM.blur(),s.focus())},100)}return O.ios&&t.inputType=="deleteContentForward"&&s.observer.flushSoon(),O.safari&&t.inputType=="insertText"&&s.inputState.composing>=0&&setTimeout(()=>Mt.compositionend(s,t),20),!1};const oo=new Set;function cc(s){oo.has(s)||(oo.add(s),s.addEventListener("copy",()=>{}),s.addEventListener("cut",()=>{}))}const lo=["pre-wrap","normal","pre-line","break-spaces"];let $e=!1;function ho(){$e=!1}class uc{constructor(t){this.lineWrapping=t,this.doc=L.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){return this.lineWrapping?(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return lo.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let n=t[i];n<0?i++:this.heightSamples[Math.floor(n*10)]||(e=!0,this.heightSamples[Math.floor(n*10)]=!0)}return e}refresh(t,e,i,n,r,o){let l=lo.indexOf(t)>-1,h=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=l;if(this.lineWrapping=l,this.lineHeight=e,this.charWidth=i,this.textHeight=n,this.lineLength=r,h){this.heightSamples={};for(let f=0;f<o.length;f++){let a=o[f];a<0?f++:this.heightSamples[Math.floor(a*10)]=!0}}return h}}class dc{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class Wt{constructor(t,e,i,n,r){this.from=t,this.length=e,this.top=i,this.height=n,this._content=r}get type(){return typeof this._content=="number"?jt.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 ue?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new Wt(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var $=(function(s){return s[s.ByPos=0]="ByPos",s[s.ByHeight=1]="ByHeight",s[s.ByPosNoHeight=2]="ByPosNoHeight",s})($||($={}));const en=.001;class ft{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(t){this.flags=(t?2:0)|this.flags&-3}setHeight(t){this.height!=t&&(Math.abs(this.height-t)>en&&($e=!0),this.height=t)}replace(t,e,i){return ft.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,n){let r=this,o=i.doc;for(let l=n.length-1;l>=0;l--){let{fromA:h,toA:f,fromB:a,toB:c}=n[l],u=r.lineAt(h,$.ByPosNoHeight,i.setDoc(e),0,0),d=u.to>=f?u:r.lineAt(f,$.ByPosNoHeight,i,0,0);for(c+=d.to-f,f=d.to;l>0&&u.from<=n[l-1].toA;)h=n[l-1].fromA,a=n[l-1].fromB,l--,h<u.from&&(u=r.lineAt(h,$.ByPosNoHeight,i,0,0));a+=u.from-h,h=u.from;let p=rr.build(i.setDoc(o),t,a,c);r=cn(r,r.replace(h,f,p))}return r.updateHeight(i,0)}static empty(){return new yt(0,0)}static of(t){if(t.length==1)return t[0];let e=0,i=t.length,n=0,r=0;for(;;)if(e==i)if(n>r*2){let l=t[e-1];l.break?t.splice(--e,1,l.left,null,l.right):t.splice(--e,1,l.left,l.right),i+=1+l.break,n-=l.size}else if(r>n*2){let l=t[i];l.break?t.splice(i,1,l.left,null,l.right):t.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(n<r){let l=t[e++];l&&(n+=l.size)}else{let l=t[--i];l&&(r+=l.size)}let o=0;return t[e-1]==null?(o=1,e--):t[e]==null&&(o=1,i++),new pc(ft.of(t.slice(0,e)),o,ft.of(t.slice(i)))}}function cn(s,t){return s==t?s:(s.constructor!=t.constructor&&($e=!0),t)}ft.prototype.size=1;class bh extends ft{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,n){return new Wt(n,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,n,r){return this.blockAt(0,i,n,r)}forEachLine(t,e,i,n,r,o){t<=r+this.length&&e>=r&&o(this.blockAt(0,i,n,r))}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more&&this.setHeight(n.heights[n.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class yt extends bh{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,n){return new Wt(n,this.length,i,this.height,this.breaks)}replace(t,e,i){let n=i[0];return i.length==1&&(n instanceof yt||n instanceof et&&n.flags&4)&&Math.abs(this.length-n.length)<10?(n instanceof et?n=new yt(n.length,this.height):n.height=this.height,this.outdated||(n.outdated=!1),n):ft.of(i)}updateHeight(t,e=0,i=!1,n){return n&&n.from<=e&&n.more?this.setHeight(n.heights[n.index++]):(i||this.outdated)&&this.setHeight(Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class et extends ft{constructor(t){super(t,0)}heightMetrics(t,e){let i=t.doc.lineAt(e).number,n=t.doc.lineAt(e+this.length).number,r=n-i+1,o,l=0;if(t.lineWrapping){let h=Math.min(this.height,t.lineHeight*r);o=h/r,this.length>r+1&&(l=(this.height-h)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:n,perLine:o,perChar:l}}blockAt(t,e,i,n){let{firstLine:r,lastLine:o,perLine:l,perChar:h}=this.heightMetrics(e,n);if(e.lineWrapping){let f=n+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),a=e.doc.lineAt(f),c=l+a.length*h,u=Math.max(i,t-c/2);return new Wt(a.from,a.length,u,c,0)}else{let f=Math.max(0,Math.min(o-r,Math.floor((t-i)/l))),{from:a,length:c}=e.doc.line(r+f);return new Wt(a,c,i+l*f,l,0)}}lineAt(t,e,i,n,r){if(e==$.ByHeight)return this.blockAt(t,i,n,r);if(e==$.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(t);return new Wt(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:h}=this.heightMetrics(i,r),f=i.doc.lineAt(t),a=l+f.length*h,c=f.number-o,u=n+l*c+h*(f.from-r-c);return new Wt(f.from,f.length,Math.max(n,Math.min(u,n+this.height-a)),a,0)}forEachLine(t,e,i,n,r,o){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:l,perLine:h,perChar:f}=this.heightMetrics(i,r);for(let a=t,c=n;a<=e;){let u=i.doc.lineAt(a);if(a==t){let p=u.number-l;c+=h*p+f*(t-r-p)}let d=h+f*u.length;o(new Wt(u.from,u.length,c,d,0)),c+=d,a=u.to+1}}replace(t,e,i){let n=this.length-e;if(n>0){let r=i[i.length-1];r instanceof et?i[i.length-1]=new et(r.length+n):i.push(null,new et(n-1))}if(t>0){let r=i[0];r instanceof et?i[0]=new et(t+r.length):i.unshift(new et(t-1),null)}return ft.of(i)}decomposeLeft(t,e){e.push(new et(t-1),null)}decomposeRight(t,e){e.push(null,new et(this.length-t-1))}updateHeight(t,e=0,i=!1,n){let r=e+this.length;if(n&&n.from<=e+this.length&&n.more){let o=[],l=Math.max(e,n.from),h=-1;for(n.from>e&&o.push(new et(n.from-e-1).updateHeight(t,e));l<=r&&n.more;){let a=t.doc.lineAt(l).length;o.length&&o.push(null);let c=n.heights[n.index++];h==-1?h=c:Math.abs(c-h)>=en&&(h=-2);let u=new yt(a,c);u.outdated=!1,o.push(u),l+=a+1}l<=r&&o.push(null,new et(r-l).updateHeight(t,l));let f=ft.of(o);return(h<0||Math.abs(f.height-this.height)>=en||Math.abs(h-this.heightMetrics(t,e).perLine)>=en)&&($e=!0),cn(this,f)}else(i||this.outdated)&&(this.setHeight(t.heightForGap(e,e+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class pc extends ft{constructor(t,e,i){super(t.length+e+i.length,t.height+i.height,e|(t.outdated||i.outdated?2:0)),this.left=t,this.right=i,this.size=t.size+i.size}get break(){return this.flags&1}blockAt(t,e,i,n){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,n):this.right.blockAt(t,e,r,n+this.left.length+this.break)}lineAt(t,e,i,n,r){let o=n+this.left.height,l=r+this.left.length+this.break,h=e==$.ByHeight?t<o:t<l,f=h?this.left.lineAt(t,e,i,n,r):this.right.lineAt(t,e,i,o,l);if(this.break||(h?f.to<l:f.from>l))return f;let a=e==$.ByPosNoHeight?$.ByPosNoHeight:$.ByPos;return h?f.join(this.right.lineAt(l,a,i,o,l)):this.left.lineAt(l,a,i,n,r).join(f)}forEachLine(t,e,i,n,r,o){let l=n+this.left.height,h=r+this.left.length+this.break;if(this.break)t<h&&this.left.forEachLine(t,e,i,n,r,o),e>=h&&this.right.forEachLine(t,e,i,l,h,o);else{let f=this.lineAt(h,$.ByPos,i,n,r);t<f.from&&this.left.forEachLine(t,f.from-1,i,n,r,o),f.to>=t&&f.from<=e&&o(f),e>f.to&&this.right.forEachLine(f.to+1,e,i,l,h,o)}}replace(t,e,i){let n=this.left.length+this.break;if(e<n)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-n,e-n,i));let r=[];t>0&&this.decomposeLeft(t,r);let o=r.length;for(let l of i)r.push(l);if(t>0&&ao(r,o-1),e<this.length){let l=r.length;this.decomposeRight(e,r),ao(r,l)}return ft.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,n=i+this.break;if(t>=n)return this.right.decomposeRight(t-n,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<n&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?ft.of(this.break?[t,null,e]:[t,e]):(this.left=cn(this.left,t),this.right=cn(this.right,e),this.setHeight(t.height+e.height),this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,n){let{left:r,right:o}=this,l=e+r.length+this.break,h=null;return n&&n.from<=e+r.length&&n.more?h=r=r.updateHeight(t,e,i,n):r.updateHeight(t,e,i),n&&n.from<=l+o.length&&n.more?h=o=o.updateHeight(t,l,i,n):o.updateHeight(t,l,i),h?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function ao(s,t){let e,i;s[t]==null&&(e=s[t-1])instanceof et&&(i=s[t+1])instanceof et&&s.splice(t-1,3,new et(e.length+1+i.length))}const gc=5;class rr{constructor(t,e){this.pos=t,this.oracle=e,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=t}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(t,e){if(this.lineStart>-1){let i=Math.min(e,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof yt?n.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new yt(i-this.pos,-1)),this.writtenTo=i,e>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let n=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;n<0&&(n=this.oracle.lineHeight);let o=e-t;i.block?this.addBlock(new bh(o,n,i)):(o||r||n>=gc)&&this.addLineDeco(n,r,o)}else e>t&&this.span(t,e);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:t,to:e}=this.oracle.doc.lineAt(this.pos);this.lineStart=t,this.lineEnd=e,this.writtenTo<t&&((this.writtenTo<t-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new yt(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new et(e-t);return this.oracle.doc.lineAt(t).to==e&&(i.flags|=4),i}ensureLine(){this.enterLine();let t=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(t instanceof yt)return t;let e=new yt(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let n=this.ensureLine();n.length+=i,n.collapsed+=i,n.widgetHeight=Math.max(n.widgetHeight,t),n.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(e instanceof yt)&&!this.isCovered?this.nodes.push(new yt(0,-1)):(this.writtenTo<this.pos||e==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=t;for(let n of this.nodes)n instanceof yt&&n.updateHeight(this.oracle,i),i+=n?n.length:1;return this.nodes}static build(t,e,i,n){let r=new rr(i,t);return H.spans(e,i,n,r,0),r.finish(i)}}function mc(s,t,e){let i=new yc;return H.compare(s,t,e,i,0),i.changes}class yc{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,n){(t<e||i&&i.heightRelevant||n&&n.heightRelevant)&&Ms(t,e,this.changes,5)}}function bc(s,t){let e=s.getBoundingClientRect(),i=s.ownerDocument,n=i.defaultView||window,r=Math.max(0,e.left),o=Math.min(n.innerWidth,e.right),l=Math.max(0,e.top),h=Math.min(n.innerHeight,e.bottom);for(let f=s.parentNode;f&&f!=i.body;)if(f.nodeType==1){let a=f,c=window.getComputedStyle(a);if((a.scrollHeight>a.clientHeight||a.scrollWidth>a.clientWidth)&&c.overflow!="visible"){let u=a.getBoundingClientRect();r=Math.max(r,u.left),o=Math.min(o,u.right),l=Math.max(l,u.top),h=Math.min(f==s.parentNode?n.innerHeight:h,u.bottom)}f=c.position=="absolute"||c.position=="fixed"?a.offsetParent:a.parentNode}else if(f.nodeType==11)f=f.host;else break;return{left:r-e.left,right:Math.max(r,o)-e.left,top:l-(e.top+t),bottom:Math.max(l,h)-(e.top+t)}}function xc(s,t){let e=s.getBoundingClientRect();return{left:0,right:e.right-e.left,top:t,bottom:e.bottom-(e.top+t)}}class Gn{constructor(t,e,i,n){this.from=t,this.to=e,this.size=i,this.displaySize=n}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let n=t[i],r=e[i];if(n.from!=r.from||n.to!=r.to||n.size!=r.size)return!1}return!0}draw(t,e){return N.replace({widget:new wc(this.displaySize*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class wc extends vi{constructor(t,e){super(),this.size=t,this.vertical=e}eq(t){return t.size==this.size&&t.vertical==this.vertical}toDOM(){let t=document.createElement("div");return this.vertical?t.style.height=this.size+"px":(t.style.width=this.size+"px",t.style.height="2px",t.style.display="inline-block"),t}get estimatedHeight(){return this.vertical?this.size:-1}}class fo{constructor(t){this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=co,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=j.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let e=t.facet(ir).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new uc(e),this.stateDeco=t.facet(yi).filter(i=>typeof i!="function"),this.heightMap=ft.empty().applyChanges(this.stateDeco,L.empty,this.heightOracle.setDoc(t.doc),[new Ct(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=N.set(this.lineGaps.map(i=>i.draw(this,!1))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let n=i?e.head:e.anchor;if(!t.some(({from:r,to:o})=>n>=r&&n<=o)){let{from:r,to:o}=this.lineBlockAt(n);t.push(new Ni(r,o))}}return this.viewports=t.sort((i,n)=>i.from-n.from),this.updateScaler()}updateScaler(){let t=this.scaler;return this.scaler=this.heightMap.height<=7e6?co:new or(this.heightOracle,this.heightMap,this.viewports),t.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,t=>{this.viewportLines.push(li(t,this.scaler))})}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(yi).filter(a=>typeof a!="function");let n=t.changedRanges,r=Ct.extendWithRanges(n,mc(i,this.stateDeco,t?t.changes:_.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);ho(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||$e)&&(t.flags|=2),l?(this.scrollAnchorPos=t.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let h=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<h.from||e.range.head>h.to)||!this.viewportIsAppropriate(h))&&(h=this.getViewport(0,e));let f=h.from!=this.viewport.from||h.to!=this.viewport.to;this.viewport=h,t.flags|=this.updateForViewport(),(f||!t.changes.empty||t.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,t.changes))),t.flags|=this.computeVisibleRanges(),e&&(this.scrollTarget=e),!this.mustEnforceCursorAssoc&&t.selectionSet&&t.view.lineWrapping&&t.state.selection.main.empty&&t.state.selection.main.assoc&&!t.state.facet(Cf)&&(this.mustEnforceCursorAssoc=!0)}measure(t){let e=t.contentDOM,i=window.getComputedStyle(e),n=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?j.RTL:j.LTR;let o=this.heightOracle.mustRefreshForWrapping(r),l=e.getBoundingClientRect(),h=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let f=0,a=0;if(l.width&&l.height){let{scaleX:k,scaleY:v}=Ml(e,l);(k>.005&&Math.abs(this.scaleX-k)>.005||v>.005&&Math.abs(this.scaleY-v)>.005)&&(this.scaleX=k,this.scaleY=v,f|=8,o=h=!0)}let c=(parseInt(i.paddingTop)||0)*this.scaleY,u=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=c||this.paddingBottom!=u)&&(this.paddingTop=c,this.paddingBottom=u,f|=10),this.editorWidth!=t.scrollDOM.clientWidth&&(n.lineWrapping&&(h=!0),this.editorWidth=t.scrollDOM.clientWidth,f|=8);let d=t.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=Dl(t.scrollDOM);let p=(this.printing?xc:bc)(e,this.paddingTop),g=p.top-this.pixelViewport.top,m=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let y=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(y!=this.inView&&(this.inView=y,y&&(h=!0)),!this.inView&&!this.scrollTarget)return 0;let x=l.width;if((this.contentDOMWidth!=x||this.editorHeight!=t.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=t.scrollDOM.clientHeight,f|=8),h){let k=t.docView.measureVisibleLineHeights(this.viewport);if(n.mustRefreshForHeights(k)&&(o=!0),o||n.lineWrapping&&Math.abs(x-this.contentDOMWidth)>n.charWidth){let{lineHeight:v,charWidth:M,textHeight:A}=t.docView.measureTextSize();o=v>0&&n.refresh(r,v,M,A,x/M,k),o&&(t.docView.minWidth=0,f|=8)}g>0&&m>0?a=Math.max(g,m):g<0&&m<0&&(a=Math.min(g,m)),ho();for(let v of this.viewports){let M=v.from==this.viewport.from?k:t.docView.measureVisibleLineHeights(v);this.heightMap=(o?ft.empty().applyChanges(this.stateDeco,L.empty,this.heightOracle,[new Ct(0,0,0,t.state.doc.length)]):this.heightMap).updateHeight(n,0,o,new dc(v.from,M))}$e&&(f|=2)}let b=!this.viewportIsAppropriate(this.viewport,a)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return b&&(f&2&&(f|=this.updateScaler()),this.viewport=this.getViewport(a,this.scrollTarget),f|=this.updateForViewport()),(f&2||b)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,t)),f|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,t.docView.enforceCursorAssoc()),f}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),n=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,h=new Ni(n.lineAt(o-i*1e3,$.ByHeight,r,0,0).from,n.lineAt(l+(1-i)*1e3,$.ByHeight,r,0,0).to);if(e){let{head:f}=e.range;if(f<h.from||f>h.to){let a=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),c=n.lineAt(f,$.ByPos,r,0,0),u;e.y=="center"?u=(c.top+c.bottom)/2-a/2:e.y=="start"||e.y=="nearest"&&f<h.from?u=c.top:u=c.bottom-a,h=new Ni(n.lineAt(u-1e3/2,$.ByHeight,r,0,0).from,n.lineAt(u+a+1e3/2,$.ByHeight,r,0,0).to)}}return h}mapViewport(t,e){let i=e.mapPos(t.from,-1),n=e.mapPos(t.to,1);return new Ni(this.heightMap.lineAt(i,$.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(n,$.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:n}=this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,$.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(t==0||n<=o-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&n>o-2*1e3&&r<l+2*1e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let n of t)e.touchesRange(n.from,n.to)||i.push(new Gn(e.mapPos(n.from),e.mapPos(n.to),n.size,n.displaySize));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,n=i?1e4:2e3,r=n>>1,o=n<<1;if(this.defaultTextDirection!=j.LTR&&!i)return[];let l=[],h=(a,c,u,d)=>{if(c-a<r)return;let p=this.state.selection.main,g=[p.from];p.empty||g.push(p.to);for(let y of g)if(y>a&&y<c){h(a,y-10,u,d),h(y+10,c,u,d);return}let m=vc(t,y=>y.from>=u.from&&y.to<=u.to&&Math.abs(y.from-a)<r&&Math.abs(y.to-c)<r&&!g.some(x=>y.from<x&&y.to>x));if(!m){if(c<u.to&&e&&i&&e.visibleRanges.some(b=>b.from<=c&&b.to>=c)){let b=e.moveToLineBoundary(w.cursor(c),!1,!0).head;b>a&&(c=b)}let y=this.gapSize(u,a,c,d),x=i||y<2e6?y:2e6;m=new Gn(a,c,y,x)}l.push(m)},f=a=>{if(a.length<o||a.type!=jt.Text)return;let c=kc(a.from,a.to,this.stateDeco);if(c.total<o)return;let u=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let g=n/this.heightOracle.lineLength*this.heightOracle.lineHeight,m,y;if(u!=null){let x=Vi(c,u),b=((this.visibleBottom-this.visibleTop)/2+g)/a.height;m=x-b,y=x+b}else m=(this.visibleTop-a.top-g)/a.height,y=(this.visibleBottom-a.top+g)/a.height;d=Fi(c,m),p=Fi(c,y)}else{let g=c.total*this.heightOracle.charWidth,m=n*this.heightOracle.charWidth,y=0;if(g>2e6)for(let M of t)M.from>=a.from&&M.from<a.to&&M.size!=M.displaySize&&M.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=M.size-M.displaySize);let x=this.pixelViewport.left+y,b=this.pixelViewport.right+y,k,v;if(u!=null){let M=Vi(c,u),A=((b-x)/2+m)/g;k=M-A,v=M+A}else k=(x-m)/g,v=(b+m)/g;d=Fi(c,k),p=Fi(c,v)}d>a.from&&h(a.from,d,a,c),p<a.to&&h(p,a.to,a,c)};for(let a of this.viewportLines)Array.isArray(a.type)?a.type.forEach(f):f(a);return l}gapSize(t,e,i,n){let r=Vi(n,i)-Vi(n,e);return this.heightOracle.lineWrapping?t.height*r:n.total*this.heightOracle.charWidth*r}updateLineGaps(t){Gn.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=N.set(t.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];H.spans(t,this.viewport.from,this.viewport.to,{span(n,r){e.push({from:n,to:r})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some((n,r)=>n.from!=e[r].from||n.to!=e[r].to);return this.visibleRanges=e,i?4:0}lineBlockAt(t){return t>=this.viewport.from&&t<=this.viewport.to&&this.viewportLines.find(e=>e.from<=t&&e.to>=t)||li(this.heightMap.lineAt(t,$.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return t>=this.viewportLines[0].top&&t<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(e=>e.top<=t&&e.bottom>=t)||li(this.heightMap.lineAt(this.scaler.fromDOM(t),$.ByHeight,this.heightOracle,0,0),this.scaler)}scrollAnchorAt(t){let e=this.lineBlockAtHeight(t+8);return e.from>=this.viewport.from||this.viewportLines[0].top-t>200?e:this.viewportLines[0]}elementAtHeight(t){return li(this.heightMap.blockAt(this.scaler.fromDOM(t),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class Ni{constructor(t,e){this.from=t,this.to=e}}function kc(s,t,e){let i=[],n=s,r=0;return H.spans(e,s,t,{span(){},point(o,l){o>n&&(i.push({from:n,to:o}),r+=o-n),n=l}},20),n<t&&(i.push({from:n,to:t}),r+=t-n),{total:r,ranges:i}}function Fi({total:s,ranges:t},e){if(e<=0)return t[0].from;if(e>=1)return t[t.length-1].to;let i=Math.floor(s*e);for(let n=0;;n++){let{from:r,to:o}=t[n],l=o-r;if(i<=l)return r+i;i-=l}}function Vi(s,t){let e=0;for(let{from:i,to:n}of s.ranges){if(t<=n){e+=t-i;break}e+=n-i}return e/s.total}function vc(s,t){for(let e of s)if(t(e))return e}const co={toDOM(s){return s},fromDOM(s){return s},scale:1,eq(s){return s==this}};class or{constructor(t,e,i){let n=0,r=0,o=0;this.viewports=i.map(({from:l,to:h})=>{let f=e.lineAt(l,$.ByPos,t,0,0).top,a=e.lineAt(h,$.ByPos,t,0,0).bottom;return n+=a-f,{from:l,to:h,top:f,bottom:a,domTop:0,domBottom:0}}),this.scale=(7e6-n)/(e.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(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return n+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,n=r.domBottom}}fromDOM(t){for(let e=0,i=0,n=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-n)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,n=r.domBottom}}eq(t){return t instanceof or?this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,i)=>e.from==t.viewports[i].from&&e.to==t.viewports[i].to):!1}}function li(s,t){if(t.scale==1)return s;let e=t.toDOM(s.top),i=t.toDOM(s.bottom);return new Wt(s.from,s.length,e,i-e,Array.isArray(s._content)?s._content.map(n=>li(n,t)):s._content)}const Hi=P.define({combine:s=>s.join(" ")}),Is=P.define({combine:s=>s.indexOf(!0)>-1}),Ns=fe.newName(),xh=fe.newName(),wh=fe.newName(),kh={"&light":"."+xh,"&dark":"."+wh};function Fs(s,t,e){return new fe(t,{finish(i){return/&/.test(i)?i.replace(/&\w*/,n=>{if(n=="&")return s;if(!e||!e[n])throw new RangeError(`Unsupported selector: ${n}`);return e[n]}):s+" "+i}})}const Sc=Fs("."+Ns,{"&":{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,overflowAnchor:"none"},".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:"#ddd"},".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,zIndex:300},"&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":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".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"}},kh),Cc={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Xn=O.ie&&O.ie_version<=11;class Oc{constructor(t){this.view=t,this.active=!1,this.editContext=null,this.selectionRange=new of,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=t.contentDOM,this.observer=new MutationObserver(e=>{for(let i of e)this.queue.push(i);(O.ie&&O.ie_version<=11||O.ios&&t.composing)&&e.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&t.constructor.EDIT_CONTEXT!==!1&&!(O.chrome&&O.chrome_version<126)&&(this.editContext=new Mc(t),t.state.facet(se)&&(t.contentDOM.editContext=this.editContext.editContext)),Xn&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var e;((e=this.view.docView)===null||e===void 0?void 0:e.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(t){(t.type=="change"||!t.type)&&!t.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(t){if(this.gapIntersection&&(t.length!=this.gaps.length||this.gaps.some((e,i)=>e!=t[i]))){this.gapIntersection.disconnect();for(let e of t)this.gapIntersection.observe(e);this.gaps=t}}onSelectionChange(t){let e=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,n=this.selectionRange;if(i.state.facet(se)?i.root.activeElement!=this.dom:!Zi(this.dom,n))return;let r=n.anchorNode&&i.docView.nearest(n.anchorNode);if(r&&r.ignoreEvent(t)){e||(this.selectionChanged=!1);return}(O.ie&&O.ie_version<=11||O.android&&O.chrome)&&!i.state.selection.main.empty&&n.focusNode&&fi(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=gi(t.root);if(!e)return!1;let i=O.safari&&t.root.nodeType==11&&t.root.activeElement==this.dom&&Ac(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let n=Zi(this.dom,i);return n&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&hf(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),n&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(i.nodeType==1)!e&&t<this.scrollTargets.length&&this.scrollTargets[t]==i?t++:e||(e=this.scrollTargets.slice(0,t)),e&&e.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=e)i.addEventListener("scroll",this.onScroll)}}ignore(t){if(!this.active)return t();try{return this.stop(),t()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,Cc),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(t,e){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&&Ee(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(n)}(!this.delayedAndroidKey||t=="Enter")&&(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,n=!1;for(let r of t){let o=this.readMutation(r);o&&(o.typeOver&&(n=!0),e==-1?{from:e,to:i}=o:(e=Math.min(o.from,e),i=Math.max(o.to,i)))}return{from:e,to:i,typeOver:n}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),n=this.selectionChanged&&Zi(this.dom,this.selectionRange);if(t<0&&!n)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new Uf(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,n=ah(this.view,e);return this.view.state==i&&(e.domChanged||e.newSel&&!e.newSel.main.eq(this.view.state.selection.main))&&this.view.update([]),n}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty(t.type=="attributes"),t.type=="attributes"&&(e.flags|=4),t.type=="childList"){let i=uo(e,t.previousSibling||t.target.previousSibling,-1),n=uo(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:n?e.posBefore(n):e.posAtEnd,typeOver:!1}}else return t.type=="characterData"?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}update(t){this.editContext&&(this.editContext.update(t),t.startState.facet(se)!=t.state.facet(se)&&(t.view.contentDOM.editContext=t.state.facet(se)?this.editContext.editContext:null))}destroy(){var t,e,i;this.stop(),(t=this.intersection)===null||t===void 0||t.disconnect(),(e=this.gapIntersection)===null||e===void 0||e.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let 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),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function uo(s,t,e){for(;t;){let i=z.get(t);if(i&&i.parent==s)return i;let n=t.parentNode;t=n!=s.dom?n:e>0?t.nextSibling:t.previousSibling}return null}function po(s,t){let e=t.startContainer,i=t.startOffset,n=t.endContainer,r=t.endOffset,o=s.docView.domAtPos(s.state.selection.main.anchor);return fi(o.node,o.offset,n,r)&&([e,i,n,r]=[n,r,e,i]),{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}}function Ac(s,t){if(t.getComposedRanges){let n=t.getComposedRanges(s.root)[0];if(n)return po(s,n)}let e=null;function i(n){n.preventDefault(),n.stopImmediatePropagation(),e=n.getTargetRanges()[0]}return s.contentDOM.addEventListener("beforeinput",i,!0),s.dom.ownerDocument.execCommand("indent"),s.contentDOM.removeEventListener("beforeinput",i,!0),e?po(s,e):null}class Mc{constructor(t){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.resetRange(t.state);let e=this.editContext=new window.EditContext({text:t.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,t.state.selection.main.anchor))),selectionEnd:this.toContextPos(t.state.selection.main.head)});this.handlers.textupdate=i=>{let{anchor:n}=t.state.selection.main,r={from:this.toEditorPos(i.updateRangeStart),to:this.toEditorPos(i.updateRangeEnd),insert:L.of(i.text.split(`
10
+ `))};r.from==this.from&&n<this.from?r.from=n:r.to==this.to&&n>this.to&&(r.to=n),!(r.from==r.to&&!r.insert.length)&&(this.pendingContextChange=r,t.state.readOnly||sr(t,r,w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd))),this.pendingContextChange&&(this.revertPending(t.state),this.setSelection(t.state)))},this.handlers.characterboundsupdate=i=>{let n=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let h=t.coordsForChar(o);r=h&&new DOMRect(h.left,h.top,h.right-h.left,h.bottom-h.top)||r||new DOMRect,n.push(r)}e.updateCharacterBounds(i.rangeStart,n)},this.handlers.textformatupdate=i=>{let n=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(o!="None"&&l!="None"){let h=`text-decoration: underline ${o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${l=="Thin"?1:2}px`;n.push(N.mark({attributes:{style:h}}).range(this.toEditorPos(r.rangeStart),this.toEditorPos(r.rangeEnd)))}}t.dispatch({effects:eh.of(N.set(n))})},this.handlers.compositionstart=()=>{t.inputState.composing<0&&(t.inputState.composing=0,t.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{t.inputState.composing=-1,t.inputState.compositionFirstChange=null};for(let i in this.handlers)e.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let n=gi(i.root);n&&n.rangeCount&&this.editContext.updateSelectionBounds(n.getRangeAt(0).getBoundingClientRect())}}}applyEdits(t){let e=0,i=!1,n=this.pendingContextChange;return t.changes.iterChanges((r,o,l,h,f)=>{if(i)return;let a=f.length-(o-r);if(n&&o>=n.to)if(n.from==r&&n.to==o&&n.insert.eq(f)){n=this.pendingContextChange=null,e+=a,this.to+=a;return}else n=null,this.revertPending(t.state);if(r+=e,o+=e,o<=this.from)this.from+=a,this.to+=a;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+f.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),f.toString()),this.to+=a}e+=a}),n&&!i&&this.revertPending(t.state),!i}update(t){let e=this.pendingContextChange;!this.applyEdits(t)||!this.rangeIsValid(t.state)?(this.pendingContextChange=null,this.resetRange(t.state),this.editContext.updateText(0,this.editContext.text.length,t.state.doc.sliceString(this.from,this.to)),this.setSelection(t.state)):(t.docChanged||t.selectionSet||e)&&this.setSelection(t.state),(t.geometryChanged||t.docChanged||t.selectionSet)&&t.view.requestMeasure(this.measureReq)}resetRange(t){let{head:e}=t.selection.main;this.from=Math.max(0,e-1e4),this.to=Math.min(t.doc.length,e+1e4)}revertPending(t){let e=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(e.from),this.toContextPos(e.from+e.insert.length),t.doc.sliceString(e.from,e.to))}setSelection(t){let{main:e}=t.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,e.anchor))),n=this.toContextPos(e.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=n)&&this.editContext.updateSelection(i,n)}rangeIsValid(t){let{head:e}=t.selection.main;return!(this.from>0&&e-this.from<500||this.to<t.doc.length&&this.to-e<500||this.to-this.from>1e4*3)}toEditorPos(t){return t+this.from}toContextPos(t){return t-this.from}destroy(){for(let t in this.handlers)this.editContext.removeEventListener(t,this.handlers[t])}}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(t={}){var 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),t.parent&&t.parent.appendChild(this.dom);let{dispatch:i}=t;this.dispatchTransactions=t.dispatchTransactions||i&&(n=>n.forEach(r=>i(r,this)))||(n=>this.update(n)),this.dispatch=this.dispatch.bind(this),this._root=t.root||lf(t.parent)||document,this.viewState=new fo(t.state||F.create(t)),t.scrollTo&&t.scrollTo.is(Ei)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(si).map(n=>new Qn(n));for(let n of this.plugins)n.update(this);this.observer=new Oc(this),this.inputState=new Gf(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Kr(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((e=document.fonts)===null||e===void 0)&&e.ready&&document.fonts.ready.then(()=>this.requestMeasure())}dispatch(...t){let e=t.length==1&&t[0]instanceof G?t:t.length==1&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e=!1,i=!1,n,r=this.state;for(let u of t){if(u.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=u.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,h=null;t.some(u=>u.annotation(gh))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,h=mh(r,o),h||(l=1));let f=this.observer.delayedAndroidKey,a=null;if(f?(this.observer.clearDelayedAndroidKey(),a=this.observer.readChange(),(a&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(a=null)):this.observer.clear(),r.facet(F.phrases)!=this.state.facet(F.phrases))return this.setState(r);n=fn.create(this,r,t),n.flags|=l;let c=this.viewState.scrollTarget;try{this.updateState=2;for(let u of t){if(c&&(c=c.map(u.changes)),u.scrollIntoView){let{main:d}=u.state.selection;c=new Le(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1))}for(let d of u.effects)d.is(Ei)&&(c=d.value.clip(this.state))}this.viewState.update(n,c),this.bidiCache=un.update(this.bidiCache,n.changes),n.empty||(this.updatePlugins(n),this.inputState.update(n)),e=this.docView.update(n),this.state.facet(ri)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(e,t.some(u=>u.isUserEvent("select.pointer")))}finally{this.updateState=0}if(n.startState.facet(Hi)!=n.state.facet(Hi)&&(this.viewState.mustMeasureContent=!0),(e||i||c||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),e&&this.docViewUpdate(),!n.empty)for(let u of this.state.facet(Rs))try{u(n)}catch(d){at(this.state,d,"update listener")}(h||a)&&Promise.resolve().then(()=>{h&&this.state==h.startState&&this.dispatch(h),a&&!ah(this,a)&&f.force&&Ee(this.contentDOM,f.key,f.keyCode)})}setState(t){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=t;return}this.updateState=2;let e=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new fo(t),this.plugins=t.facet(si).map(i=>new Qn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Kr(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}e&&this.focus(),this.requestMeasure()}updatePlugins(t){let e=t.startState.facet(si),i=t.state.facet(si);if(e!=i){let n=[];for(let r of i){let o=e.indexOf(r);if(o<0)n.push(new Qn(r));else{let l=this.plugins[o];l.mustUpdate=t,n.push(l)}}for(let r of this.plugins)r.mustUpdate!=t&&r.destroy(this);this.plugins=n,this.pluginMap.clear()}else for(let n of this.plugins)n.mustUpdate=t;for(let n=0;n<this.plugins.length;n++)this.plugins[n].update(this);e!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let t of this.plugins){let e=t.value;if(e&&e.docViewUpdate)try{e.docViewUpdate(this)}catch(i){at(this.state,i,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,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(Dl(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 h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let f=[];h&4||([this.measureRequests,f]=[f,this.measureRequests]);let a=f.map(d=>{try{return d.read(this)}catch(p){return at(this.state,p),go}}),c=fn.create(this,this.state,[]),u=!1;c.flags|=h,e?e.flags|=h:e=c,this.updateState=2,c.empty||(this.updatePlugins(c),this.inputState.update(c),this.updateAttrs(),u=this.docView.update(c),u&&this.docViewUpdate());for(let d=0;d<f.length;d++)if(a[d]!=go)try{let p=f[d];p.write&&p.write(a[d],this)}catch(p){at(this.state,p)}if(u&&this.docView.updateSelection(!0),!c.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(e&&!e.empty)for(let l of this.state.facet(Rs))l(e)}get themeClasses(){return Ns+" "+(this.state.facet(Is)?wh:xh)+" "+this.state.facet(Hi)}updateAttrs(){let t=mo(this,ih,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(se)?"true":"false",class:"cm-content",style:`${O.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),mo(this,ir,e);let i=this.observer.ignore(()=>{let n=As(this.contentDOM,this.contentAttrs,e),r=As(this.dom,this.editorAttrs,t);return n||r});return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let n of i.effects)if(n.is(T.announce)){e&&(this.announceDOM.textContent=""),e=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=n.value}}mountStyles(){this.styleModules=this.state.facet(ri);let t=this.state.facet(T.cspNonce);fe.mount(this.root,this.styleModules.concat(Sc).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(t){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),t){if(this.measureRequests.indexOf(t)>-1)return;if(t.key!=null){for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key){this.measureRequests[e]=t;return}}this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(e===void 0||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find(i=>i.spec==t)||null),e&&e.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(t){return this.readMeasured(),this.viewState.elementAtHeight(t)}lineBlockAtHeight(t){return this.readMeasured(),this.viewState.lineBlockAtHeight(t)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(t){return this.viewState.lineBlockAt(t)}get contentHeight(){return this.viewState.contentHeight}moveByChar(t,e,i){return Yn(this,t,Xr(this,t,e,i))}moveByGroup(t,e){return Yn(this,t,Xr(this,t,e,i=>zf(this,t.head,i)))}visualLineSide(t,e){let i=this.bidiSpans(t),n=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return w.cursor(r.side(e,n)+t.from,r.forward(!e,n)?1:-1)}moveToLineBoundary(t,e,i=!0){return Hf(this,t,e,i)}moveVertically(t,e,i){return Yn(this,t,Wf(this,t,e,i))}domAtPos(t){return this.docView.domAtPos(t)}posAtDOM(t,e=0){return this.docView.posFromDOM(t,e)}posAtCoords(t,e=!0){return this.readMeasured(),hh(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let n=this.state.doc.lineAt(t),r=this.bidiSpans(n),o=r[he.find(r,t-n.from,-1,e)];return Bn(i,o.dir==j.LTR==e>0)}coordsForChar(t){return this.readMeasured(),this.docView.coordsForChar(t)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(t){return!this.state.facet(Zl)||t<this.viewport.from||t>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(t))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(t){if(t.length>Tc)return Kl(t.length);let e=this.textDirectionAt(t.from),i;for(let r of this.bidiCache)if(r.from==t.from&&r.dir==e&&(r.fresh||Ul(r.isolates,i=Ur(this,t))))return r.order;i||(i=Ur(this,t));let n=kf(t.text,e,i);return this.bidiCache.push(new un(t.from,t.to,e,i,!0,n)),n}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||O.safari&&((t=this.inputState)===null||t===void 0?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Tl(this.contentDOM),this.docView.updateSelection()})}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((t.nodeType==9?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return Ei.of(new Le(typeof t=="number"?w.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return Ei.of(new Le(w.cursor(i.from),"start","start",i.top-t,e,!0))}setTabFocusMode(t){t==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof t=="boolean"?this.inputState.tabFocusMode=t?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+t)}static domEventHandlers(t){return At.define(()=>({}),{eventHandlers:t})}static domEventObservers(t){return At.define(()=>({}),{eventObservers:t})}static theme(t,e){let i=fe.newName(),n=[Hi.of(i),ri.of(Fs(`.${i}`,t))];return e&&e.dark&&n.push(Is.of(!0)),n}static baseTheme(t){return Ye.lowest(ri.of(Fs("."+Ns,t,kh)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),n=i&&z.get(i)||z.get(t);return((e=n==null?void 0:n.rootView)===null||e===void 0?void 0:e.view)||null}}T.styleModule=ri;T.inputHandler=_l;T.clipboardInputFilter=tr;T.clipboardOutputFilter=er;T.scrollHandler=th;T.focusChangeEffect=Jl;T.perLineTextDirection=Zl;T.exceptionSink=Xl;T.updateListener=Rs;T.editable=se;T.mouseSelectionStyle=Gl;T.dragMovesSelection=Yl;T.clickAddsSelectionRange=jl;T.decorations=yi;T.outerDecorations=nh;T.atomicRanges=nr;T.bidiIsolatedRanges=sh;T.scrollMargins=rh;T.darkTheme=Is;T.cspNonce=P.define({combine:s=>s.length?s[0]:""});T.contentAttributes=ir;T.editorAttributes=ih;T.lineWrapping=T.contentAttributes.of({class:"cm-lineWrapping"});T.announce=R.define();const Tc=4096,go={};class un{constructor(t,e,i,n,r,o){this.from=t,this.to=e,this.dir=i,this.isolates=n,this.fresh=r,this.order=o}static update(t,e){if(e.empty&&!t.some(r=>r.fresh))return t;let i=[],n=t.length?t[t.length-1].dir:j.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let o=t[r];o.dir==n&&!e.touchesRange(o.from,o.to)&&i.push(new un(e.mapPos(o.from,1),e.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function mo(s,t,e){for(let i=s.state.facet(t),n=i.length-1;n>=0;n--){let r=i[n],o=typeof r=="function"?r(s):r;o&&Os(o,e)}return e}const Pc=O.mac?"mac":O.windows?"win":O.linux?"linux":"key";function Dc(s,t){const e=s.split(/-(?!$)/);let i=e[e.length-1];i=="Space"&&(i=" ");let n,r,o,l;for(let h=0;h<e.length-1;++h){const f=e[h];if(/^(cmd|meta|m)$/i.test(f))l=!0;else if(/^a(lt)?$/i.test(f))n=!0;else if(/^(c|ctrl|control)$/i.test(f))r=!0;else if(/^s(hift)?$/i.test(f))o=!0;else if(/^mod$/i.test(f))t=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+f)}return n&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function zi(s,t,e){return t.altKey&&(s="Alt-"+s),t.ctrlKey&&(s="Ctrl-"+s),t.metaKey&&(s="Meta-"+s),e!==!1&&t.shiftKey&&(s="Shift-"+s),s}const Bc=Ye.default(T.domEventHandlers({keydown(s,t){return Ic(Rc(t.state),s,t,"editor")}})),Ln=P.define({enables:Bc}),yo=new WeakMap;function Rc(s){let t=s.facet(Ln),e=yo.get(t);return e||yo.set(t,e=Lc(t.reduce((i,n)=>i.concat(n),[]))),e}let re=null;const Ec=4e3;function Lc(s,t=Pc){let e=Object.create(null),i=Object.create(null),n=(o,l)=>{let h=i[o];if(h==null)i[o]=l;else if(h!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,h,f,a)=>{var c,u;let d=e[o]||(e[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>Dc(y,t));for(let y=1;y<p.length;y++){let x=p.slice(0,y).join(" ");n(x,!0),d[x]||(d[x]={preventDefault:!0,stopPropagation:!1,run:[b=>{let k=re={view:b,prefix:x,scope:o};return setTimeout(()=>{re==k&&(re=null)},Ec),!0}]})}let g=p.join(" ");n(g,!1);let m=d[g]||(d[g]={preventDefault:!1,stopPropagation:!1,run:((u=(c=d._any)===null||c===void 0?void 0:c.run)===null||u===void 0?void 0:u.slice())||[]});h&&m.run.push(h),f&&(m.preventDefault=!0),a&&(m.stopPropagation=!0)};for(let o of s){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let f of l){let a=e[f]||(e[f]=Object.create(null));a._any||(a._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:c}=o;for(let u in a)a[u].run.push(d=>c(d,Vs))}let h=o[t]||o.key;if(h)for(let f of l)r(f,h,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(f,"Shift-"+h,o.shift,o.preventDefault,o.stopPropagation)}return e}let Vs=null;function Ic(s,t,e,i){Vs=t;let n=ef(t),r=Ht(n,0),o=ne(r)==n.length&&n!=" ",l="",h=!1,f=!1,a=!1;re&&re.view==e&&re.scope==i&&(l=re.prefix+" ",ch.indexOf(t.keyCode)<0&&(f=!0,re=null));let c=new Set,u=m=>{if(m){for(let y of m.run)if(!c.has(y)&&(c.add(y),y(e)))return m.stopPropagation&&(a=!0),!0;m.preventDefault&&(m.stopPropagation&&(a=!0),f=!0)}return!1},d=s[i],p,g;return d&&(u(d[l+zi(n,t,!o)])?h=!0:o&&(t.altKey||t.metaKey||t.ctrlKey)&&!(O.windows&&t.ctrlKey&&t.altKey)&&(p=ce[t.keyCode])&&p!=n?(u(d[l+zi(p,t,!0)])||t.shiftKey&&(g=pi[t.keyCode])!=n&&g!=p&&u(d[l+zi(g,t,!1)]))&&(h=!0):o&&t.shiftKey&&u(d[l+zi(n,t,!0)])&&(h=!0),!h&&u(d._any)&&(h=!0)),f&&(h=!0),h&&a&&t.stopPropagation(),Vs=null,h}const Nc=!O.ios,bo={".cm-line":{},".cm-content":{}};Nc&&(bo[".cm-line"].caretColor=bo[".cm-content"].caretColor="transparent !important");const ti="-10000px";class vh{constructor(t,e,i,n){this.facet=e,this.createTooltipView=i,this.removeTooltipView=n,this.input=t.state.facet(e),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(t,e){var i;let n=t.state.facet(this.facet),r=n.filter(h=>h);if(n===this.input){for(let h of this.tooltipViews)h.update&&h.update(t);return!1}let o=[],l=e?[]:null;for(let h=0;h<r.length;h++){let f=r[h],a=-1;if(f){for(let c=0;c<this.tooltips.length;c++){let u=this.tooltips[c];u&&u.create==f.create&&(a=c)}if(a<0)o[h]=this.createTooltipView(f,h?o[h-1]:null),l&&(l[h]=!!f.above);else{let c=o[h]=this.tooltipViews[a];l&&(l[h]=e[a]),c.update&&c.update(t)}}}for(let h of this.tooltipViews)o.indexOf(h)<0&&(this.removeTooltipView(h),(i=h.destroy)===null||i===void 0||i.call(h));return e&&(l.forEach((h,f)=>e[f]=h),e.length=l.length),this.input=n,this.tooltips=r,this.tooltipViews=o,!0}}function Fc(s={}){return nn.of(s)}function Vc(s){let{win:t}=s;return{top:0,left:0,bottom:t.innerHeight,right:t.innerWidth}}const nn=P.define({combine:s=>{var t,e,i;return{position:O.ios?"absolute":((t=s.find(n=>n.position))===null||t===void 0?void 0:t.position)||"fixed",parent:((e=s.find(n=>n.parent))===null||e===void 0?void 0:e.parent)||null,tooltipSpace:((i=s.find(n=>n.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||Vc}}}),xo=new WeakMap,lr=At.fromClass(class{constructor(s){this.view=s,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let t=s.state.facet(nn);this.position=t.position,this.parent=t.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 vh(s,qe,(e,i)=>this.createTooltip(e,i),e=>{this.resizeObserver&&this.resizeObserver.unobserve(e.dom),e.dom.remove()}),this.above=this.manager.tooltips.map(e=>!!e.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(e=>{Date.now()>this.lastTransaction-50&&e.length>0&&e[e.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),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 t=this.manager.update(s,this.above);t&&this.observeIntersection();let e=t||s.geometryChanged,i=s.state.facet(nn);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let n of this.manager.tooltipViews)n.dom.style.position=this.position;e=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let n of this.manager.tooltipViews)this.container.appendChild(n.dom);e=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);e&&this.maybeMeasure()}createTooltip(s,t){let e=s.create(this.view),i=t?t.dom:null;if(e.dom.classList.add("cm-tooltip"),s.arrow&&!e.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let n=document.createElement("div");n.className="cm-tooltip-arrow",e.dom.appendChild(n)}return e.dom.style.position=this.position,e.dom.style.top=ti,e.dom.style.left="0px",this.container.insertBefore(e.dom,i),e.mount&&e.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(e.dom),e}destroy(){var s,t,e;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(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.intersectionObserver)===null||e===void 0||e.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let s=this.view.dom.getBoundingClientRect(),t=1,e=1,i=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:n}=this.manager.tooltipViews[0];if(O.gecko)i=n.offsetParent!=this.container.ownerDocument.body;else if(n.style.top==ti&&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&&(t=n.width/this.parent.offsetWidth,e=n.height/this.parent.offsetHeight)}else({scaleX:t,scaleY:e}=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(nn).tooltipSpace(this.view),scaleX:t,scaleY:e,makeAbsolute:i}}writeMeasure(s){var t;if(s.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{editor:e,space:i,scaleX:n,scaleY:r}=s,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let h=this.manager.tooltips[l],f=this.manager.tooltipViews[l],{dom:a}=f,c=s.pos[l],u=s.size[l];if(!c||c.bottom<=Math.max(e.top,i.top)||c.top>=Math.min(e.bottom,i.bottom)||c.right<Math.max(e.left,i.left)-.1||c.left>Math.min(e.right,i.right)+.1){a.style.top=ti;continue}let d=h.arrow?f.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,g=u.right-u.left,m=(t=xo.get(f))!==null&&t!==void 0?t:u.bottom-u.top,y=f.offset||zc,x=this.view.textDirection==j.LTR,b=u.width>i.right-i.left?x?i.left:i.right-u.width:x?Math.max(i.left,Math.min(c.left-(d?14:0)+y.x,i.right-g)):Math.min(Math.max(i.left,c.left-g+(d?14:0)-y.x),i.right-g),k=this.above[l];!h.strictSide&&(k?c.top-(u.bottom-u.top)-y.y<i.top:c.bottom+(u.bottom-u.top)+y.y>i.bottom)&&k==i.bottom-c.bottom>c.top-i.top&&(k=this.above[l]=!k);let v=(k?c.top-i.top:i.bottom-c.bottom)-p;if(v<m&&f.resize!==!1){if(v<this.view.defaultLineHeight){a.style.top=ti;continue}xo.set(f,m),a.style.height=(m=v)/r+"px"}else a.style.height&&(a.style.height="");let M=k?c.top-m-p-y.y:c.bottom+p+y.y,A=b+g;if(f.overlap!==!0)for(let I of o)I.left<A&&I.right>b&&I.top<M+m&&I.bottom>M&&(M=k?I.top-m-2-p:I.bottom+p+2);if(this.position=="absolute"?(a.style.top=(M-s.parent.top)/r+"px",a.style.left=(b-s.parent.left)/n+"px"):(a.style.top=M/r+"px",a.style.left=b/n+"px"),d){let I=c.left+(x?y.x:-y.x)-(b+14-7);d.style.left=I/n+"px"}f.overlap!==!0&&o.push({left:b,top:M,right:A,bottom:M+m}),a.classList.toggle("cm-tooltip-above",k),a.classList.toggle("cm-tooltip-below",!k),f.positioned&&f.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=ti}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Hc=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:"14px",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"}}}),zc={x:0,y:0},qe=P.define({enables:[lr,Hc]}),dn=P.define({combine:s=>s.reduce((t,e)=>t.concat(e),[])});class In{static create(t){return new In(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new vh(t,dn,(e,i)=>this.createHostedView(e,i),e=>e.dom.remove())}createHostedView(t,e){let i=t.create(this.view);return i.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(i.dom,e?e.dom.nextSibling:this.dom.firstChild),this.mounted&&i.mount&&i.mount(this.view),i}mount(t){for(let e of this.manager.tooltipViews)e.mount&&e.mount(t);this.mounted=!0}positioned(t){for(let e of this.manager.tooltipViews)e.positioned&&e.positioned(t)}update(t){this.manager.update(t)}destroy(){var t;for(let e of this.manager.tooltipViews)(t=e.destroy)===null||t===void 0||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let n=i[t];if(n!==void 0){if(e===void 0)e=n;else if(e!==n)return}}return e}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const Wc=qe.compute([dn],s=>{let t=s.facet(dn);return t.length===0?null:{pos:Math.min(...t.map(e=>e.pos)),end:Math.max(...t.map(e=>{var i;return(i=e.end)!==null&&i!==void 0?i:e.pos})),create:In.create,above:t[0].above,arrow:t.some(e=>e.arrow)}});class $c{constructor(t,e,i,n,r){this.view=t,this.source=e,this.field=i,this.setHover=n,this.hoverTime=r,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:t.dom,time:0},this.checkHover=this.checkHover.bind(this),t.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),t.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let t=Date.now()-this.lastMove.time;t<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-t):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:t,lastMove:e}=this,i=t.docView.nearest(e.target);if(!i)return;let n,r=1;if(i instanceof le)n=i.posAtStart;else{if(n=t.posAtCoords(e),n==null)return;let l=t.coordsAtPos(n);if(!l||e.y<l.top||e.y>l.bottom||e.x<l.left-t.defaultCharacterWidth||e.x>l.right+t.defaultCharacterWidth)return;let h=t.bidiSpans(t.state.doc.lineAt(n)).find(a=>a.from<=n&&a.to>=n),f=h&&h.dir==j.RTL?-1:1;r=e.x<l.left?-f:f}let o=this.source(t,n,r);if(o!=null&&o.then){let l=this.pending={pos:n};o.then(h=>{this.pending==l&&(this.pending=null,h&&!(Array.isArray(h)&&!h.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(h)?h:[h])}))},h=>at(t.state,h,"hover tooltip"))}else o&&!(Array.isArray(o)&&!o.length)&&t.dispatch({effects:this.setHover.of(Array.isArray(o)?o:[o])})}get tooltip(){let t=this.view.plugin(lr),e=t?t.manager.tooltips.findIndex(i=>i.create==In.create):-1;return e>-1?t.manager.tooltipViews[e]:null}mousemove(t){var e,i;this.lastMove={x:t.clientX,y:t.clientY,target:t.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:n,tooltip:r}=this;if(n.length&&r&&!qc(r.dom,t)||this.pending){let{pos:o}=n[0]||this.pending,l=(i=(e=n[0])===null||e===void 0?void 0:e.end)!==null&&i!==void 0?i:o;(o==l?this.view.posAtCoords(this.lastMove)!=o:!Uc(this.view,o,l,t.clientX,t.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(t){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:e}=this;if(e.length){let{tooltip:i}=this;i&&i.dom.contains(t.relatedTarget)?this.watchTooltipLeave(i.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(t){let e=i=>{t.removeEventListener("mouseleave",e),this.active.length&&!this.view.dom.contains(i.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};t.addEventListener("mouseleave",e)}destroy(){clearTimeout(this.hoverTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const Wi=4;function qc(s,t){let{left:e,right:i,top:n,bottom:r}=s.getBoundingClientRect(),o;if(o=s.querySelector(".cm-tooltip-arrow")){let l=o.getBoundingClientRect();n=Math.min(l.top,n),r=Math.max(l.bottom,r)}return t.clientX>=e-Wi&&t.clientX<=i+Wi&&t.clientY>=n-Wi&&t.clientY<=r+Wi}function Uc(s,t,e,i,n,r){let o=s.scrollDOM.getBoundingClientRect(),l=s.documentTop+s.documentPadding.top+s.contentHeight;if(o.left>i||o.right<i||o.top>n||Math.min(o.bottom,l)<n)return!1;let h=s.posAtCoords({x:i,y:n},!1);return h>=t&&h<=e}function Kc(s,t={}){let e=R.define(),i=ct.define({create(){return[]},update(n,r){if(n.length&&(t.hideOnChange&&(r.docChanged||r.selection)?n=[]:t.hideOn&&(n=n.filter(o=>!t.hideOn(r,o))),r.docChanged)){let o=[];for(let l of n){let h=r.changes.mapPos(l.pos,-1,nt.TrackDel);if(h!=null){let f=Object.assign(Object.create(null),l);f.pos=h,f.end!=null&&(f.end=r.changes.mapPos(f.end)),o.push(f)}}n=o}for(let o of r.effects)o.is(e)&&(n=o.value),o.is(Qc)&&(n=[]);return n},provide:n=>dn.from(n)});return{active:i,extension:[i,At.define(n=>new $c(n,s,i,e,t.hoverTime||300)),Wc]}}function Sh(s,t){let e=s.plugin(lr);if(!e)return null;let i=e.manager.tooltips.indexOf(t);return i<0?null:e.manager.tooltipViews[i]}const Qc=R.define(),wo=P.define({combine(s){let t,e;for(let i of s)t=t||i.topContainer,e=e||i.bottomContainer;return{topContainer:t,bottomContainer:e}}}),jc=At.fromClass(class{constructor(s){this.input=s.state.facet(Hs),this.specs=this.input.filter(e=>e),this.panels=this.specs.map(e=>e(s));let t=s.state.facet(wo);this.top=new $i(s,!0,t.topContainer),this.bottom=new $i(s,!1,t.bottomContainer),this.top.sync(this.panels.filter(e=>e.top)),this.bottom.sync(this.panels.filter(e=>!e.top));for(let e of this.panels)e.dom.classList.add("cm-panel"),e.mount&&e.mount()}update(s){let t=s.state.facet(wo);this.top.container!=t.topContainer&&(this.top.sync([]),this.top=new $i(s.view,!0,t.topContainer)),this.bottom.container!=t.bottomContainer&&(this.bottom.sync([]),this.bottom=new $i(s.view,!1,t.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let e=s.state.facet(Hs);if(e!=this.input){let i=e.filter(h=>h),n=[],r=[],o=[],l=[];for(let h of i){let f=this.specs.indexOf(h),a;f<0?(a=h(s.view),l.push(a)):(a=this.panels[f],a.update&&a.update(s)),n.push(a),(a.top?r:o).push(a)}this.specs=i,this.panels=n,this.top.sync(r),this.bottom.sync(o);for(let h of l)h.dom.classList.add("cm-panel"),h.mount&&h.mount()}else for(let i of this.panels)i.update&&i.update(s)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:s=>T.scrollMargins.of(t=>{let e=t.plugin(s);return e&&{top:e.top.scrollMargin(),bottom:e.bottom.scrollMargin()}})});class $i{constructor(t,e,i){this.view=t,this.top=e,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(t){for(let e of this.panels)e.destroy&&t.indexOf(e)<0&&e.destroy();this.panels=t,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let e=this.container||this.view.dom;e.insertBefore(this.dom,this.top?e.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=ko(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=ko(t)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let t of this.classes.split(" "))t&&this.container.classList.remove(t);for(let t of(this.classes=this.view.themeClasses).split(" "))t&&this.container.classList.add(t)}}}function ko(s){let t=s.nextSibling;return s.remove(),t}const Hs=P.define({enables:jc});class Ue extends Ce{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}Ue.prototype.elementClass="";Ue.prototype.toDOM=void 0;Ue.prototype.mapMode=nt.TrackBefore;Ue.prototype.startSide=Ue.prototype.endSide=-1;Ue.prototype.point=!0;const Ch=1024;let Yc=0;class _n{constructor(t,e){this.from=t,this.to=e}}class B{constructor(t={}){this.id=Yc++,this.perNode=!!t.perNode,this.deserialize=t.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=t.combine||null}add(t){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof t!="function"&&(t=pt.match(t)),e=>{let i=t(e);return i===void 0?null:[this,i]}}}B.closedBy=new B({deserialize:s=>s.split(" ")});B.openedBy=new B({deserialize:s=>s.split(" ")});B.group=new B({deserialize:s=>s.split(" ")});B.isolate=new B({deserialize:s=>{if(s&&s!="rtl"&&s!="ltr"&&s!="auto")throw new RangeError("Invalid value for isolate: "+s);return s||"auto"}});B.contextHash=new B({perNode:!0});B.lookAhead=new B({perNode:!0});B.mounted=new B({perNode:!0});class pn{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[B.mounted.id]}}const Gc=Object.create(null);class pt{constructor(t,e,i,n=0){this.name=t,this.props=e,this.id=i,this.flags=n}static define(t){let e=t.props&&t.props.length?Object.create(null):Gc,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),n=new pt(t.name||"",e,t.id,i);if(t.props){for(let r of t.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");e[r[0].id]=r[1]}}return n}prop(t){return this.props[t.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(t){if(typeof t=="string"){if(this.name==t)return!0;let e=this.prop(B.group);return e?e.indexOf(t)>-1:!1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let n of i.split(" "))e[n]=t[i];return i=>{for(let n=i.prop(B.group),r=-1;r<(n?n.length:0);r++){let o=e[r<0?i.name:n[r]];if(o)return o}}}}pt.none=new pt("",Object.create(null),0,8);class hr{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let n=null;for(let r of t){let o=r(i);if(o){n||(n=Object.assign({},i.props));let l=o[1],h=o[0];h.combine&&h.id in n&&(l=h.combine(n[h.id],l)),n[h.id]=l}}e.push(n?new pt(i.name,n,i.id,i.flags):i)}return new hr(e)}}const qi=new WeakMap,vo=new WeakMap;var J;(function(s){s[s.ExcludeBuffers=1]="ExcludeBuffers",s[s.IncludeAnonymous=2]="IncludeAnonymous",s[s.IgnoreMounts=4]="IgnoreMounts",s[s.IgnoreOverlays=8]="IgnoreOverlays"})(J||(J={}));class X{constructor(t,e,i,n,r){if(this.type=t,this.children=e,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 t=pn.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let i of this.children){let n=i.toString();n&&(e&&(e+=","),e+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(e.length?"("+e+")":""):e}cursor(t=0){return new Ws(this.topNode,t)}cursorAt(t,e=0,i=0){let n=qi.get(this)||this.topNode,r=new Ws(n);return r.moveTo(t,e),qi.set(this,r._tree),r}get topNode(){return new Ot(this,0,0,null)}resolve(t,e=0){let i=bi(qi.get(this)||this.topNode,t,e,!1);return qi.set(this,i),i}resolveInner(t,e=0){let i=bi(vo.get(this)||this.topNode,t,e,!0);return vo.set(this,i),i}resolveStack(t,e=0){return Jc(this,t,e)}iterate(t){let{enter:e,leave:i,from:n=0,to:r=this.length}=t,o=t.mode||0,l=(o&J.IncludeAnonymous)>0;for(let h=this.cursor(o|J.IncludeAnonymous);;){let f=!1;if(h.from<=r&&h.to>=n&&(!l&&h.type.isAnonymous||e(h)!==!1)){if(h.firstChild())continue;f=!0}for(;f&&i&&(l||!h.type.isAnonymous)&&i(h),!h.nextSibling();){if(!h.parent())return;f=!0}}}prop(t){return t.perNode?this.props?this.props[t.id]:void 0:this.type.prop(t)}get propValues(){let t=[];if(this.props)for(let e in this.props)t.push([+e,this.props[e]]);return t}balance(t={}){return this.children.length<=8?this:cr(pt.none,this.children,this.positions,0,this.children.length,0,this.length,(e,i,n)=>new X(this.type,e,i,n,this.propValues),t.makeTree||((e,i,n)=>new X(pt.none,e,i,n)))}static build(t){return Zc(t)}}X.empty=new X(pt.none,[],[],0);class ar{constructor(t,e){this.buffer=t,this.index=e}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new ar(this.buffer,this.index)}}class de{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return pt.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],n=this.set.types[e],r=n.name;if(/\W/.test(r)&&!n.isError&&(r=JSON.stringify(r)),t+=4,i==t)return r;let o=[];for(;t<i;)o.push(this.childString(t)),t=this.buffer[t+3];return r+"("+o.join(",")+")"}findChild(t,e,i,n,r){let{buffer:o}=this,l=-1;for(let h=t;h!=e&&!(Oh(r,n,o[h+1],o[h+2])&&(l=h,i>0));h=o[h+3]);return l}slice(t,e,i){let n=this.buffer,r=new Uint16Array(e-t),o=0;for(let l=t,h=0;l<e;){r[h++]=n[l++],r[h++]=n[l++]-i;let f=r[h++]=n[l++]-i;r[h++]=n[l++]-t,o=Math.max(o,f)}return new de(r,o,this.set)}}function Oh(s,t,e,i){switch(s){case-2:return e<t;case-1:return i>=t&&e<t;case 0:return e<t&&i>t;case 1:return e<=t&&i>t;case 2:return i>t;case 4:return!0}}function bi(s,t,e,i){for(var n;s.from==s.to||(e<1?s.from>=t:s.from>t)||(e>-1?s.to<=t:s.to<t);){let o=!i&&s instanceof Ot&&s.index<0?null:s.parent;if(!o)return s;s=o}let r=i?0:J.IgnoreOverlays;if(i)for(let o=s,l=o.parent;l;o=l,l=o.parent)o instanceof Ot&&o.index<0&&((n=l.enter(t,e,r))===null||n===void 0?void 0:n.from)!=o.from&&(s=l);for(;;){let o=s.enter(t,e,r);if(!o)return s;s=o}}class Ah{cursor(t=0){return new Ws(this,t)}getChild(t,e=null,i=null){let n=So(this,t,e,i);return n.length?n[0]:null}getChildren(t,e=null,i=null){return So(this,t,e,i)}resolve(t,e=0){return bi(this,t,e,!1)}resolveInner(t,e=0){return bi(this,t,e,!0)}matchContext(t){return zs(this.parent,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let n=e.lastChild;if(!n||n.to!=e.to)break;n.type.isError&&n.from==n.to?(i=e,e=n.prevSibling):e=n}return i}get node(){return this}get next(){return this.parent}}class Ot extends Ah{constructor(t,e,i,n){super(),this._tree=t,this.from=e,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(t,e,i,n,r=0){for(let o=this;;){for(let{children:l,positions:h}=o._tree,f=e>0?l.length:-1;t!=f;t+=e){let a=l[t],c=h[t]+o.from;if(Oh(n,i,c,c+a.length)){if(a instanceof de){if(r&J.ExcludeBuffers)continue;let u=a.findChild(0,a.buffer.length,e,i-c,n);if(u>-1)return new ae(new Xc(o,a,t,c),null,u)}else if(r&J.IncludeAnonymous||!a.type.isAnonymous||fr(a)){let u;if(!(r&J.IgnoreMounts)&&(u=pn.get(a))&&!u.overlay)return new Ot(u.tree,c,t,o);let d=new Ot(a,c,t,o);return r&J.IncludeAnonymous||!d.type.isAnonymous?d:d.nextChild(e<0?a.children.length-1:0,e,i,n)}}}if(r&J.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?t=o.index+e:t=e<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}prop(t){return this._tree.prop(t)}enter(t,e,i=0){let n;if(!(i&J.IgnoreOverlays)&&(n=pn.get(this._tree))&&n.overlay){let r=t-this.from;for(let{from:o,to:l}of n.overlay)if((e>0?o<=r:o<r)&&(e<0?l>=r:l>r))return new Ot(n.tree,n.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function So(s,t,e,i){let n=s.cursor(),r=[];if(!n.firstChild())return r;if(e!=null){for(let o=!1;!o;)if(o=n.type.is(e),!n.nextSibling())return r}for(;;){if(i!=null&&n.type.is(i))return r;if(n.type.is(t)&&r.push(n.node),!n.nextSibling())return i==null?r:[]}}function zs(s,t,e=t.length-1){for(let i=s;e>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(t[e]&&t[e]!=i.name)return!1;e--}}return!0}class Xc{constructor(t,e,i,n){this.parent=t,this.buffer=e,this.index=i,this.start=n}}class ae extends Ah{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new ae(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(t){return this.child(1,t,2)}childBefore(t){return this.child(-1,t,-2)}prop(t){return this.type.prop(t)}enter(t,e,i=0){if(i&J.ExcludeBuffers)return null;let{buffer:n}=this.context,r=n.findChild(this.index+4,n.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new ae(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(t){return this._parent?null:this.context.parent.nextChild(this.context.index+t,t,0,4)}get nextSibling(){let{buffer:t}=this.context,e=t.buffer[this.index+3];return e<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new ae(this.context,this._parent,e):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,e=this._parent?this._parent.index+4:0;return this.index==e?this.externalSibling(-1):new ae(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,n=this.index+4,r=i.buffer[this.index+3];if(r>n){let o=i.buffer[this.index+1];t.push(i.slice(n,r,o)),e.push(0)}return new X(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Mh(s){if(!s.length)return null;let t=0,e=s[0];for(let r=1;r<s.length;r++){let o=s[r];(o.from>e.from||o.to<e.to)&&(e=o,t=r)}let i=e instanceof Ot&&e.index<0?null:e.parent,n=s.slice();return i?n[t]=i:n.splice(t,1),new _c(n,e)}class _c{constructor(t,e){this.heads=t,this.node=e}get next(){return Mh(this.heads)}}function Jc(s,t,e){let i=s.resolveInner(t,e),n=null;for(let r=i instanceof Ot?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(n||(n=[i])).push(o.resolve(t,e)),r=o}else{let o=pn.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=t&&o.overlay[o.overlay.length-1].to>=t){let l=new Ot(o.tree,o.overlay[0].from+r.from,-1,r);(n||(n=[i])).push(bi(l,t,e,!1))}}return n?Mh(n):i}class Ws{get name(){return this.type.name}constructor(t,e=0){if(this.mode=e,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,t instanceof Ot)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let i=t._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=t,this.yieldBuf(t.index)}}yieldNode(t){return t?(this._tree=t,this.type=t.type,this.from=t.from,this.to=t.to,!0):!1}yieldBuf(t,e){this.index=t;let{start:i,buffer:n}=this.buffer;return this.type=e||n.set.types[n.buffer[t]],this.from=i+n.buffer[t+1],this.to=i+n.buffer[t+2],!0}yield(t){return t?t instanceof Ot?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:n}=this.buffer,r=n.findChild(this.index+4,n.buffer[this.index+3],t,e-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(t){return this.enterChild(1,t,2)}childBefore(t){return this.enterChild(-1,t,-2)}enter(t,e,i=this.mode){return this.buffer?i&J.ExcludeBuffers?!1:this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&J.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&J.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(t)}sibling(t){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+t,t,0,4,this.mode)):!1;let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let n=i<0?0:this.stack[i]+4;if(this.index!=n)return this.yieldBuf(e.findChild(n,this.index,-1,0,4))}else{let n=e.buffer[this.index+3];if(n<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(n)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:n}=this;if(n){if(t>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:e,parent:i}=n)}else({index:e,_parent:i}=this._tree);for(;i;{index:e,_parent:i}=i)if(e>-1)for(let r=e+t,o=t<0?-1:i._tree.children.length;r!=o;r+=t){let l=i._tree.children[r];if(this.mode&J.IncludeAnonymous||l instanceof de||!l.type.isAnonymous||fr(l))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let n=this.index,r=this.stack.length;r>=0;){for(let o=t;o;o=o._parent)if(o.index==n){if(n==this.index)return o;e=o,i=r+1;break t}n=this.stack[--r]}for(let n=i;n<this.stack.length;n++)e=new ae(this.buffer,e,this.stack[n]);return this.bufferNode=new ae(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let n=!1;if(this.type.isAnonymous||t(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(n=!0)}for(;;){if(n&&e&&e(this),n=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,n=!0}}}matchContext(t){if(!this.buffer)return zs(this.node.parent,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let n=t.length-1,r=this.stack.length-1;n>=0;r--){if(r<0)return zs(this._tree,t,n);let o=i[e.buffer[this.stack[r]]];if(!o.isAnonymous){if(t[n]&&t[n]!=o.name)return!1;n--}}return!0}}function fr(s){return s.children.some(t=>t instanceof de||!t.type.isAnonymous||fr(t))}function Zc(s){var t;let{buffer:e,nodeSet:i,maxBufferLength:n=Ch,reused:r=[],minRepeatType:o=i.types.length}=s,l=Array.isArray(e)?new ar(e,e.length):e,h=i.types,f=0,a=0;function c(v,M,A,I,W,K){let{id:E,start:D,end:q,size:U}=l,tt=a,te=f;if(U<0)if(l.next(),U==-1){let Gt=r[E];A.push(Gt),I.push(D-v);return}else if(U==-3){f=E;return}else if(U==-4){a=E;return}else throw new RangeError(`Unrecognized record size: ${U}`);let _e=h[E],Mi,ge,Or=D-v;if(q-D<=n&&(ge=m(l.pos-M,W))){let Gt=new Uint16Array(ge.size-ge.skip),xt=l.pos-ge.size,Lt=Gt.length;for(;l.pos>xt;)Lt=y(ge.start,Gt,Lt);Mi=new de(Gt,q-ge.start,i),Or=ge.start-v}else{let Gt=l.pos-U;l.next();let xt=[],Lt=[],me=E>=o?E:-1,Te=0,Ti=q;for(;l.pos>Gt;)me>=0&&l.id==me&&l.size>=0?(l.end<=Ti-n&&(p(xt,Lt,D,Te,l.end,Ti,me,tt,te),Te=xt.length,Ti=l.end),l.next()):K>2500?u(D,Gt,xt,Lt):c(D,Gt,xt,Lt,me,K+1);if(me>=0&&Te>0&&Te<xt.length&&p(xt,Lt,D,Te,D,Ti,me,tt,te),xt.reverse(),Lt.reverse(),me>-1&&Te>0){let Ar=d(_e,te);Mi=cr(_e,xt,Lt,0,xt.length,0,q-D,Ar,Ar)}else Mi=g(_e,xt,Lt,q-D,tt-q,te)}A.push(Mi),I.push(Or)}function u(v,M,A,I){let W=[],K=0,E=-1;for(;l.pos>M;){let{id:D,start:q,end:U,size:tt}=l;if(tt>4)l.next();else{if(E>-1&&q<E)break;E<0&&(E=U-n),W.push(D,q,U),K++,l.next()}}if(K){let D=new Uint16Array(K*4),q=W[W.length-2];for(let U=W.length-3,tt=0;U>=0;U-=3)D[tt++]=W[U],D[tt++]=W[U+1]-q,D[tt++]=W[U+2]-q,D[tt++]=tt;A.push(new de(D,W[2]-q,i)),I.push(q-v)}}function d(v,M){return(A,I,W)=>{let K=0,E=A.length-1,D,q;if(E>=0&&(D=A[E])instanceof X){if(!E&&D.type==v&&D.length==W)return D;(q=D.prop(B.lookAhead))&&(K=I[E]+D.length+q)}return g(v,A,I,W,K,M)}}function p(v,M,A,I,W,K,E,D,q){let U=[],tt=[];for(;v.length>I;)U.push(v.pop()),tt.push(M.pop()+A-W);v.push(g(i.types[E],U,tt,K-W,D-K,q)),M.push(W-A)}function g(v,M,A,I,W,K,E){if(K){let D=[B.contextHash,K];E=E?[D].concat(E):[D]}if(W>25){let D=[B.lookAhead,W];E=E?[D].concat(E):[D]}return new X(v,M,A,I,E)}function m(v,M){let A=l.fork(),I=0,W=0,K=0,E=A.end-n,D={size:0,start:0,skip:0};t:for(let q=A.pos-v;A.pos>q;){let U=A.size;if(A.id==M&&U>=0){D.size=I,D.start=W,D.skip=K,K+=4,I+=4,A.next();continue}let tt=A.pos-U;if(U<0||tt<q||A.start<E)break;let te=A.id>=o?4:0,_e=A.start;for(A.next();A.pos>tt;){if(A.size<0)if(A.size==-3||A.size==-4)te+=4;else break t;else A.id>=o&&(te+=4);A.next()}W=_e,I+=U,K+=te}return(M<0||I==v)&&(D.size=I,D.start=W,D.skip=K),D.size>4?D:void 0}function y(v,M,A){let{id:I,start:W,end:K,size:E}=l;if(l.next(),E>=0&&I<o){let D=A;if(E>4){let q=l.pos-(E-4);for(;l.pos>q;)A=y(v,M,A)}M[--A]=D,M[--A]=K-v,M[--A]=W-v,M[--A]=I}else E==-3?f=I:E==-4&&(a=I);return A}let x=[],b=[];for(;l.pos>0;)c(s.start||0,s.bufferStart||0,x,b,-1,0);let k=(t=s.length)!==null&&t!==void 0?t:x.length?b[0]+x[0].length:0;return new X(h[s.topID],x.reverse(),b.reverse(),k)}const Co=new WeakMap;function sn(s,t){if(!s.isAnonymous||t instanceof de||t.type!=s)return 1;let e=Co.get(t);if(e==null){e=1;for(let i of t.children){if(i.type!=s||!(i instanceof X)){e=1;break}e+=sn(s,i)}Co.set(t,e)}return e}function cr(s,t,e,i,n,r,o,l,h){let f=0;for(let p=i;p<n;p++)f+=sn(s,t[p]);let a=Math.ceil(f*1.5/8),c=[],u=[];function d(p,g,m,y,x){for(let b=m;b<y;){let k=b,v=g[b],M=sn(s,p[b]);for(b++;b<y;b++){let A=sn(s,p[b]);if(M+A>=a)break;M+=A}if(b==k+1){if(M>a){let A=p[k];d(A.children,A.positions,0,A.children.length,g[k]+x);continue}c.push(p[k])}else{let A=g[b-1]+p[b-1].length-v;c.push(cr(s,p,g,k,b,v,A,null,h))}u.push(v+x-r)}}return d(t,e,i,n,0),(l||h)(c,u,o)}class ve{constructor(t,e,i,n,r=!1,o=!1){this.from=t,this.to=e,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(t,e=[],i=!1){let n=[new ve(0,t.length,t,0,!1,i)];for(let r of e)r.to>t.length&&n.push(r);return n}static applyChanges(t,e,i=128){if(!e.length)return t;let n=[],r=1,o=t.length?t[0]:null;for(let l=0,h=0,f=0;;l++){let a=l<e.length?e[l]:null,c=a?a.fromA:1e9;if(c-h>=i)for(;o&&o.from<c;){let u=o;if(h>=u.from||c<=u.to||f){let d=Math.max(u.from,h)-f,p=Math.min(u.to,c)-f;u=d>=p?null:new ve(d,p,u.tree,u.offset+f,l>0,!!a)}if(u&&n.push(u),o.to>c)break;o=r<t.length?t[r++]:null}if(!a)break;h=a.toA,f=a.toA-a.toB}return n}}class Th{startParse(t,e,i){return typeof t=="string"&&(t=new tu(t)),i=i?i.length?i.map(n=>new _n(n.from,n.to)):[new _n(0,0)]:[new _n(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let n=this.startParse(t,e,i);for(;;){let r=n.advance();if(r)return r}}}class tu{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}new B({perNode:!0});let eu=0;class wt{constructor(t,e,i,n){this.name=t,this.set=e,this.base=i,this.modified=n,this.id=eu++}toString(){let{name:t}=this;for(let e of this.modified)e.name&&(t=`${e.name}(${t})`);return t}static define(t,e){let i=typeof t=="string"?t:"?";if(t instanceof wt&&(e=t),e!=null&&e.base)throw new Error("Can not derive from a modified tag");let n=new wt(i,[],null,[]);if(n.set.push(n),e)for(let r of e.set)n.set.push(r);return n}static defineModifier(t){let e=new gn(t);return i=>i.modified.indexOf(e)>-1?i:gn.get(i.base||i,i.modified.concat(e).sort((n,r)=>n.id-r.id))}}let iu=0;class gn{constructor(t){this.name=t,this.instances=[],this.id=iu++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find(l=>l.base==t&&nu(e,l.modified));if(i)return i;let n=[],r=new wt(t.name,n,t,e);for(let l of e)l.instances.push(r);let o=su(e);for(let l of t.set)if(!l.modified.length)for(let h of o)n.push(gn.get(l,h));return r}}function nu(s,t){return s.length==t.length&&s.every((e,i)=>e==t[i])}function su(s){let t=[[]];for(let e=0;e<s.length;e++)for(let i=0,n=t.length;i<n;i++)t.push(t[i].concat(s[e]));return t.sort((e,i)=>i.length-e.length)}function Ph(s){let t=Object.create(null);for(let e in s){let i=s[e];Array.isArray(i)||(i=[i]);for(let n of e.split(" "))if(n){let r=[],o=2,l=n;for(let c=0;;){if(l=="..."&&c>0&&c+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]),c+=u[0].length,c==n.length)break;let d=n[c++];if(c==n.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+n);l=n.slice(c)}let h=r.length-1,f=r[h];if(!f)throw new RangeError("Invalid path: "+n);let a=new xi(i,o,h>0?r.slice(0,h):null);t[f]=a.sort(t[f])}}return Dh.add(t)}const Dh=new B({combine(s,t){let e,i,n;for(;s||t;){if(!s||t&&s.depth>=t.depth?(n=t,t=t.next):(n=s,s=s.next),e&&e.mode==n.mode&&!n.context&&!e.context)continue;let r=new xi(n.tags,n.mode,n.context);e?e.next=r:i=r,e=r}return i}});class xi{constructor(t,e,i,n){this.tags=t,this.mode=e,this.context=i,this.next=n}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(t){return!t||t.depth<this.depth?(this.next=t,this):(t.next=this.sort(t.next),t)}get depth(){return this.context?this.context.length:0}}xi.empty=new xi([],2,null);function Bh(s,t){let e=Object.create(null);for(let r of s)if(!Array.isArray(r.tag))e[r.tag.id]=r.class;else for(let o of r.tag)e[o.id]=r.class;let{scope:i,all:n=null}=t||{};return{style:r=>{let o=n;for(let l of r)for(let h of l.set){let f=e[h.id];if(f){o=o?o+" "+f:f;break}}return o},scope:i}}function ru(s,t){let e=null;for(let i of s){let n=i.style(t);n&&(e=e?e+" "+n:n)}return e}function ou(s,t,e,i=0,n=s.length){let r=new lu(i,Array.isArray(t)?t:[t],e);r.highlightRange(s.cursor(),i,n,"",r.highlighters),r.flush(n)}class lu{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,n,r){let{type:o,from:l,to:h}=t;if(l>=i||h<=e)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let f=n,a=hu(t)||xi.empty,c=ru(r,a.tags);if(c&&(f&&(f+=" "),f+=c,a.mode==1&&(n+=(n?" ":"")+c)),this.startSpan(Math.max(e,l),f),a.opaque)return;let u=t.tree&&t.tree.prop(B.mounted);if(u&&u.overlay){let d=t.node.enter(u.overlay[0].from+l,1),p=this.highlighters.filter(m=>!m.scope||m.scope(u.tree.type)),g=t.firstChild();for(let m=0,y=l;;m++){let x=m<u.overlay.length?u.overlay[m]:null,b=x?x.from+l:h,k=Math.max(e,y),v=Math.min(i,b);if(k<v&&g)for(;t.from<v&&(this.highlightRange(t,k,v,n,r),this.startSpan(Math.min(v,t.to),f),!(t.to>=b||!t.nextSibling())););if(!x||b>i)break;y=x.to+l,y>e&&(this.highlightRange(d.cursor(),Math.max(e,x.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),f))}g&&t.parent()}else if(t.firstChild()){u&&(n="");do if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,n,r),this.startSpan(Math.min(i,t.to),f)}while(t.nextSibling());t.parent()}}}function hu(s){let t=s.type.prop(Dh);for(;t&&t.context&&!s.matchContext(t.context);)t=t.next;return t||null}const S=wt.define,Ui=S(),ee=S(),Oo=S(ee),Ao=S(ee),ie=S(),Ki=S(ie),Jn=S(ie),Vt=S(),ye=S(Vt),Nt=S(),Ft=S(),$s=S(),ei=S($s),Qi=S(),C={comment:Ui,lineComment:S(Ui),blockComment:S(Ui),docComment:S(Ui),name:ee,variableName:S(ee),typeName:Oo,tagName:S(Oo),propertyName:Ao,attributeName:S(Ao),className:S(ee),labelName:S(ee),namespace:S(ee),macroName:S(ee),literal:ie,string:Ki,docString:S(Ki),character:S(Ki),attributeValue:S(Ki),number:Jn,integer:S(Jn),float:S(Jn),bool:S(ie),regexp:S(ie),escape:S(ie),color:S(ie),url:S(ie),keyword:Nt,self:S(Nt),null:S(Nt),atom:S(Nt),unit:S(Nt),modifier:S(Nt),operatorKeyword:S(Nt),controlKeyword:S(Nt),definitionKeyword:S(Nt),moduleKeyword:S(Nt),operator:Ft,derefOperator:S(Ft),arithmeticOperator:S(Ft),logicOperator:S(Ft),bitwiseOperator:S(Ft),compareOperator:S(Ft),updateOperator:S(Ft),definitionOperator:S(Ft),typeOperator:S(Ft),controlOperator:S(Ft),punctuation:$s,separator:S($s),bracket:ei,angleBracket:S(ei),squareBracket:S(ei),paren:S(ei),brace:S(ei),content:Vt,heading:ye,heading1:S(ye),heading2:S(ye),heading3:S(ye),heading4:S(ye),heading5:S(ye),heading6:S(ye),contentSeparator:S(Vt),list:S(Vt),quote:S(Vt),emphasis:S(Vt),strong:S(Vt),link:S(Vt),monospace:S(Vt),strikethrough:S(Vt),inserted:S(),deleted:S(),changed:S(),invalid:S(),meta:Qi,documentMeta:S(Qi),annotation:S(Qi),processingInstruction:S(Qi),definition:wt.defineModifier("definition"),constant:wt.defineModifier("constant"),function:wt.defineModifier("function"),standard:wt.defineModifier("standard"),local:wt.defineModifier("local"),special:wt.defineModifier("special")};for(let s in C){let t=C[s];t instanceof wt&&(t.name=s)}Bh([{tag:C.link,class:"tok-link"},{tag:C.heading,class:"tok-heading"},{tag:C.emphasis,class:"tok-emphasis"},{tag:C.strong,class:"tok-strong"},{tag:C.keyword,class:"tok-keyword"},{tag:C.atom,class:"tok-atom"},{tag:C.bool,class:"tok-bool"},{tag:C.url,class:"tok-url"},{tag:C.labelName,class:"tok-labelName"},{tag:C.inserted,class:"tok-inserted"},{tag:C.deleted,class:"tok-deleted"},{tag:C.literal,class:"tok-literal"},{tag:C.string,class:"tok-string"},{tag:C.number,class:"tok-number"},{tag:[C.regexp,C.escape,C.special(C.string)],class:"tok-string2"},{tag:C.variableName,class:"tok-variableName"},{tag:C.local(C.variableName),class:"tok-variableName tok-local"},{tag:C.definition(C.variableName),class:"tok-variableName tok-definition"},{tag:C.special(C.variableName),class:"tok-variableName2"},{tag:C.definition(C.propertyName),class:"tok-propertyName tok-definition"},{tag:C.typeName,class:"tok-typeName"},{tag:C.namespace,class:"tok-namespace"},{tag:C.className,class:"tok-className"},{tag:C.macroName,class:"tok-macroName"},{tag:C.propertyName,class:"tok-propertyName"},{tag:C.operator,class:"tok-operator"},{tag:C.comment,class:"tok-comment"},{tag:C.meta,class:"tok-meta"},{tag:C.invalid,class:"tok-invalid"},{tag:C.punctuation,class:"tok-punctuation"}]);var Zn;const De=new B;function au(s){return P.define({combine:s?t=>t.concat(s):void 0})}const fu=new B;class Pt{constructor(t,e,i=[],n=""){this.data=t,this.name=n,F.prototype.hasOwnProperty("tree")||Object.defineProperty(F.prototype,"tree",{get(){return gt(this)}}),this.parser=e,this.extension=[Qe.of(this),F.languageData.of((r,o,l)=>{let h=Mo(r,o,l),f=h.type.prop(De);if(!f)return[];let a=r.facet(f),c=h.type.prop(fu);if(c){let u=h.resolve(o-h.from,l);for(let d of c)if(d.test(u,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(a)}}return a})].concat(i)}isActiveAt(t,e,i=-1){return Mo(t,e,i).type.prop(De)==this.data}findRegions(t){let e=t.facet(Qe);if((e==null?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],n=(r,o)=>{if(r.prop(De)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(B.mounted);if(l){if(l.tree.prop(De)==this.data){if(l.overlay)for(let h of l.overlay)i.push({from:h.from+o,to:h.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let h=i.length;if(n(l.tree,l.overlay[0].from+o),i.length>h)return}}for(let h=0;h<r.children.length;h++){let f=r.children[h];f instanceof X&&n(f,r.positions[h]+o)}};return n(gt(t),0),i}get allowsNesting(){return!0}}Pt.setState=R.define();function Mo(s,t,e){let i=s.facet(Qe),n=gt(s).topNode;if(!i||i.allowsNesting)for(let r=n;r;r=r.enter(t,e,J.ExcludeBuffers))r.type.isTop&&(n=r);return n}class mn extends Pt{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=au(t.languageData);return new mn(e,t.parser.configure({props:[De.add(i=>i.isTop?e:void 0)]}),t.name)}configure(t,e){return new mn(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function gt(s){let t=s.field(Pt.state,!1);return t?t.tree:X.empty}class cu{constructor(t){this.doc=t,this.cursorPos=0,this.string="",this.cursor=t.iter()}get length(){return this.doc.length}syncTo(t){return this.string=this.cursor.next(t-this.cursorPos).value,this.cursorPos=t+this.string.length,this.cursorPos-this.string.length}chunk(t){return this.syncTo(t),this.string}get lineChunks(){return!0}read(t,e){let i=this.cursorPos-this.string.length;return t<i||e>=this.cursorPos?this.doc.sliceString(t,e):this.string.slice(t-i,e-i)}}let ii=null;class yn{constructor(t,e,i=[],n,r,o,l,h){this.parser=t,this.state=e,this.fragments=i,this.tree=n,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=h,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new yn(t,e,[],X.empty,0,i,[],null)}startParse(){return this.parser.startParse(new cu(this.state.doc),this.fragments)}work(t,e){return e!=null&&e>=this.state.doc.length&&(e=void 0),this.tree!=X.empty&&this.isDone(e??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof t=="number"){let n=Date.now()+t;t=()=>Date.now()>n}for(this.parse||(this.parse=this.startParse()),e!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let n=this.parse.advance();if(n)if(this.fragments=this.withoutTempSkipped(ve.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<(e??this.state.doc.length))this.parse=this.startParse();else return!0;if(t())return!1}})}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&this.parse.stopAt(t),this.withContext(()=>{for(;!(e=this.parse.advance()););}),this.treeLen=t,this.tree=e,this.fragments=this.withoutTempSkipped(ve.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=ii;ii=this;try{return t()}finally{ii=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=To(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:n,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!t.empty){let h=[];if(t.iterChangedRanges((f,a,c,u)=>h.push({fromA:f,toA:a,fromB:c,toB:u})),i=ve.applyChanges(i,h),n=X.empty,r=0,o={from:t.mapPos(o.from,-1),to:t.mapPos(o.to,1)},this.skipped.length){l=[];for(let f of this.skipped){let a=t.mapPos(f.from,1),c=t.mapPos(f.to,-1);a<c&&l.push({from:a,to:c})}}}return new yn(this.parser,e,i,n,r,o,l,this.scheduleOn)}updateViewport(t){if(this.viewport.from==t.from&&this.viewport.to==t.to)return!1;this.viewport=t;let e=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:n,to:r}=this.skipped[i];n<t.to&&r>t.from&&(this.fragments=To(this.fragments,n,r),this.skipped.splice(i--,1))}return this.skipped.length>=e?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(t,e){this.skipped.push({from:t,to:e})}static getSkippingParser(t){return new class extends Th{createParse(e,i,n){let r=n[0].from,o=n[n.length-1].to;return{parsedPos:r,advance(){let h=ii;if(h){for(let f of n)h.tempSkipped.push(f);t&&(h.scheduleOn=h.scheduleOn?Promise.all([h.scheduleOn,t]):t)}return this.parsedPos=o,new X(pt.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&e[0].from==0&&e[0].to>=t}static get(){return ii}}function To(s,t,e){return ve.applyChanges(s,[{fromA:t,toA:e,fromB:t,toB:e}])}class Ke{constructor(t){this.context=t,this.tree=t.tree}apply(t){if(!t.docChanged&&this.tree==this.context.tree)return this;let e=this.context.changes(t.changes,t.state),i=this.context.treeLen==t.startState.doc.length?void 0:Math.max(t.changes.mapPos(this.context.treeLen),e.viewport.to);return e.work(20,i)||e.takeTree(),new Ke(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=yn.create(t.facet(Qe).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new Ke(i)}}Pt.state=ct.define({create:Ke.init,update(s,t){for(let e of t.effects)if(e.is(Pt.setState))return e.value;return t.startState.facet(Qe)!=t.state.facet(Qe)?Ke.init(t.state):s.apply(t)}});let Rh=s=>{let t=setTimeout(()=>s(),500);return()=>clearTimeout(t)};typeof requestIdleCallback<"u"&&(Rh=s=>{let t=-1,e=setTimeout(()=>{t=requestIdleCallback(s,{timeout:400})},100);return()=>t<0?clearTimeout(e):cancelIdleCallback(t)});const ts=typeof navigator<"u"&&(!((Zn=navigator.scheduling)===null||Zn===void 0)&&Zn.isInputPending)?()=>navigator.scheduling.isInputPending():null,uu=At.fromClass(class{constructor(t){this.view=t,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(t){let e=this.view.state.field(Pt.state).context;(e.updateViewport(t.view.viewport)||this.view.viewport.to>e.treeLen)&&this.scheduleWork(),(t.docChanged||t.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(e)}scheduleWork(){if(this.working)return;let{state:t}=this.view,e=t.field(Pt.state);(e.tree!=e.context.tree||!e.context.isDone(t.doc.length))&&(this.working=Rh(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:n}}=this.view,r=i.field(Pt.state);if(r.tree==r.context.tree&&r.context.isDone(n+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,t&&!ts?Math.max(25,t.timeRemaining()-5):1e9),l=r.context.treeLen<n&&i.doc.length>n+1e3,h=r.context.work(()=>ts&&ts()||Date.now()>o,n+(l?0:1e5));this.chunkBudget-=Date.now()-e,(h||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:Pt.setState.of(new Ke(r.context))})),this.chunkBudget>0&&!(h&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then(()=>this.scheduleWork()).catch(e=>at(this.view.state,e)).then(()=>this.workScheduled--),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),Qe=P.define({combine(s){return s.length?s[0]:null},enables:s=>[Pt.state,uu,T.contentAttributes.compute([s],t=>{let e=t.facet(s);return e&&e.name?{"data-language":e.name}:{}})]});class du{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const pu=P.define(),Nn=P.define({combine:s=>{if(!s.length)return" ";let t=s[0];if(!t||/\S/.test(t)||Array.from(t).some(e=>e!=t[0]))throw new Error("Invalid indent unit: "+JSON.stringify(s[0]));return t}});function bn(s){let t=s.facet(Nn);return t.charCodeAt(0)==9?s.tabSize*t.length:t.length}function xn(s,t){let e="",i=s.tabSize,n=s.facet(Nn)[0];if(n==" "){for(;t>=i;)e+=" ",t-=i;n=" "}for(let r=0;r<t;r++)e+=n;return e}function Eh(s,t){s instanceof F&&(s=new Fn(s));for(let i of s.state.facet(pu)){let n=i(s,t);if(n!==void 0)return n}let e=gt(s.state);return e.length>=t?mu(s,e,t):null}class Fn{constructor(t,e={}){this.state=t,this.options=e,this.unit=bn(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:n,simulateDoubleBreak:r}=this.options;return n!=null&&n>=i.from&&n<=i.to?r&&n==t?{text:"",from:t}:(e<0?n<t:n<=t)?{text:i.text.slice(n-i.from),from:n}:{text:i.text.slice(0,n-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:n}=this.lineAt(t,e);return i.slice(t-n,Math.min(i.length,t+100-n))}column(t,e=1){let{text:i,from:n}=this.lineAt(t,e),r=this.countColumn(i,t-n),o=this.options.overrideIndentation?this.options.overrideIndentation(n):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return Dn(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:n}=this.lineAt(t,e),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 gu=new B;function mu(s,t,e){let i=t.resolveStack(e),n=t.resolveInner(e,-1).resolve(e,0).enterUnfinishedNodesBefore(e);if(n!=i.node){let r=[];for(let o=n;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return Lh(i,s,e)}function Lh(s,t,e){for(let i=s;i;i=i.next){let n=bu(i.node);if(n)return n(ur.create(t,e,i))}return 0}function yu(s){return s.pos==s.options.simulateBreak&&s.options.simulateDoubleBreak}function bu(s){let t=s.type.prop(gu);if(t)return t;let e=s.firstChild,i;if(e&&(i=e.type.prop(B.closedBy))){let n=s.lastChild,r=n&&i.indexOf(n.name)>-1;return o=>vu(o,!0,1,void 0,r&&!yu(o)?n.from:void 0)}return s.parent==null?xu:null}function xu(){return 0}class ur extends Fn{constructor(t,e,i){super(t.state,t.options),this.base=t,this.pos=e,this.context=i}get node(){return this.context.node}static create(t,e,i){return new ur(t,e,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(t){let e=this.state.doc.lineAt(t.from);for(;;){let i=t.resolve(e.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(wu(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return Lh(this.context.next,this.base,this.pos)}}function wu(s,t){for(let e=t;e;e=e.parent)if(s==e)return!0;return!1}function ku(s){let t=s.node,e=t.childAfter(t.from),i=t.lastChild;if(!e)return null;let n=s.options.simulateBreak,r=s.state.doc.lineAt(e.from),o=n==null||n<=r.from?r.to:Math.min(r.to,n);for(let l=e.to;;){let h=t.childAfter(l);if(!h||h==i)return null;if(!h.type.isSkipped){if(h.from>=o)return null;let f=/^ */.exec(r.text.slice(e.to-r.from))[0].length;return{from:e.from,to:e.to+f}}l=h.to}}function vu(s,t,e,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,h=ku(s);return h?l?s.column(h.from):s.column(h.to):s.baseIndent+(l?0:s.unit*e)}class Vn{constructor(t,e){this.specs=t;let i;function n(l){let h=fe.newName();return(i||(i=Object.create(null)))["."+h]=l,h}const r=typeof e.all=="string"?e.all:e.all?n(e.all):void 0,o=e.scope;this.scope=o instanceof Pt?l=>l.prop(De)==o.data:o?l=>l==o:void 0,this.style=Bh(t.map(l=>({tag:l.tag,class:l.class||n(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new fe(i):null,this.themeType=e.themeType}static define(t,e){return new Vn(t,e||{})}}const qs=P.define(),Su=P.define({combine(s){return s.length?[s[0]]:null}});function es(s){let t=s.facet(qs);return t.length?t:s.facet(Su)}function Cu(s,t){let e=[Au],i;return s instanceof Vn&&(s.module&&e.push(T.styleModule.of(s.module)),i=s.themeType),i?e.push(qs.computeN([T.darkTheme],n=>n.facet(T.darkTheme)==(i=="dark")?[s]:[])):e.push(qs.of(s)),e}class Ou{constructor(t){this.markCache=Object.create(null),this.tree=gt(t.state),this.decorations=this.buildDeco(t,es(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=gt(t.state),i=es(t.state),n=i!=es(t.startState),{viewport:r}=t.view,o=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!n&&e.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=o):(e!=this.tree||t.viewportChanged||n)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return N.none;let i=new He;for(let{from:n,to:r}of t.visibleRanges)ou(this.tree,e,(o,l,h)=>{i.add(o,l,this.markCache[h]||(this.markCache[h]=N.mark({class:h})))},n,r);return i.finish()}}const Au=Ye.high(At.fromClass(Ou,{decorations:s=>s.decorations})),Mu=T.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),Ih=1e4,Nh="()[]{}",Fh=P.define({combine(s){return Pn(s,{afterCursor:!0,brackets:Nh,maxScanDistance:Ih,renderMatch:Du})}}),Tu=N.mark({class:"cm-matchingBracket"}),Pu=N.mark({class:"cm-nonmatchingBracket"});function Du(s){let t=[],e=s.matched?Tu:Pu;return t.push(e.range(s.start.from,s.start.to)),s.end&&t.push(e.range(s.end.from,s.end.to)),t}const Bu=ct.define({create(){return N.none},update(s,t){if(!t.docChanged&&!t.selection)return s;let e=[],i=t.state.facet(Fh);for(let n of t.state.selection.ranges){if(!n.empty)continue;let r=qt(t.state,n.head,-1,i)||n.head>0&&qt(t.state,n.head-1,1,i)||i.afterCursor&&(qt(t.state,n.head,1,i)||n.head<t.state.doc.length&&qt(t.state,n.head+1,-1,i));r&&(e=e.concat(i.renderMatch(r,t.state)))}return N.set(e,!0)},provide:s=>T.decorations.from(s)}),Ru=[Bu,Mu];function Eu(s={}){return[Fh.of(s),Ru]}const Lu=new B;function Us(s,t,e){let i=s.prop(t<0?B.openedBy:B.closedBy);if(i)return i;if(s.name.length==1){let n=e.indexOf(s.name);if(n>-1&&n%2==(t<0?1:0))return[e[n+t]]}return null}function Ks(s){let t=s.type.prop(Lu);return t?t(s.node):s}function qt(s,t,e,i={}){let n=i.maxScanDistance||Ih,r=i.brackets||Nh,o=gt(s),l=o.resolveInner(t,e);for(let h=l;h;h=h.parent){let f=Us(h.type,e,r);if(f&&h.from<h.to){let a=Ks(h);if(a&&(e>0?t>=a.from&&t<a.to:t>a.from&&t<=a.to))return Iu(s,t,e,h,a,f,r)}}return Nu(s,t,e,o,l.type,n,r)}function Iu(s,t,e,i,n,r,o){let l=i.parent,h={from:n.from,to:n.to},f=0,a=l==null?void 0:l.cursor();if(a&&(e<0?a.childBefore(i.from):a.childAfter(i.to)))do if(e<0?a.to<=i.from:a.from>=i.to){if(f==0&&r.indexOf(a.type.name)>-1&&a.from<a.to){let c=Ks(a);return{start:h,end:c?{from:c.from,to:c.to}:void 0,matched:!0}}else if(Us(a.type,e,o))f++;else if(Us(a.type,-e,o)){if(f==0){let c=Ks(a);return{start:h,end:c&&c.from<c.to?{from:c.from,to:c.to}:void 0,matched:!1}}f--}}while(e<0?a.prevSibling():a.nextSibling());return{start:h,matched:!1}}function Nu(s,t,e,i,n,r,o){let l=e<0?s.sliceDoc(t-1,t):s.sliceDoc(t,t+1),h=o.indexOf(l);if(h<0||h%2==0!=e>0)return null;let f={from:e<0?t-1:t,to:e>0?t+1:t},a=s.doc.iterRange(t,e>0?s.doc.length:0),c=0;for(let u=0;!a.next().done&&u<=r;){let d=a.value;e<0&&(u+=d.length);let p=t+u*e;for(let g=e>0?0:d.length-1,m=e>0?d.length:-1;g!=m;g+=e){let y=o.indexOf(d[g]);if(!(y<0||i.resolveInner(p+g,1).type!=n))if(y%2==0==e>0)c++;else{if(c==1)return{start:f,end:{from:p+g,to:p+g+1},matched:y>>1==h>>1};c--}}e>0&&(u+=d.length)}return a.done?{start:f,matched:!1}:null}const Fu=Object.create(null),Po=[pt.none],Do=[],Bo=Object.create(null),Vu=Object.create(null);for(let[s,t]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Vu[s]=Hu(Fu,t);function is(s,t){Do.indexOf(s)>-1||(Do.push(s),console.warn(t))}function Hu(s,t){let e=[];for(let l of t.split(" ")){let h=[];for(let f of l.split(".")){let a=s[f]||C[f];a?typeof a=="function"?h.length?h=h.map(a):is(f,`Modifier ${f} used at start of tag`):h.length?is(f,`Tag ${f} used as modifier`):h=Array.isArray(a)?a:[a]:is(f,`Unknown highlighting tag ${f}`)}for(let f of h)e.push(f)}if(!e.length)return 0;let i=t.replace(/ /g,"_"),n=i+" "+e.map(l=>l.id),r=Bo[n];if(r)return r.id;let o=Bo[n]=pt.define({id:Po.length,name:i,props:[Ph({[i]:e})]});return Po.push(o),o.id}j.RTL,j.LTR;class Vh{constructor(t,e,i,n){this.state=t,this.pos=e,this.explicit=i,this.view=n,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(t){let e=gt(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),n=e.text.slice(i-e.from,this.pos-e.from),r=n.search(Hh(t,!1));return r<0?null:{from:i+r,to:this.pos,text:n.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(t,e,i){t=="abort"&&this.abortListeners&&(this.abortListeners.push(e),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Ro(s){let t=Object.keys(s).join(""),e=/\w/.test(t);return e&&(t=t.replace(/\w/g,"")),`[${e?"\\w":""}${t.replace(/[^\w\s]/g,"\\$&")}]`}function zu(s){let t=Object.create(null),e=Object.create(null);for(let{label:n}of s){t[n[0]]=!0;for(let r=1;r<n.length;r++)e[n[r]]=!0}let i=Ro(t)+Ro(e)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function Wu(s){let t=s.map(n=>typeof n=="string"?{label:n}:n),[e,i]=t.every(n=>/^\w+$/.test(n.label))?[/\w*$/,/\w+$/]:zu(t);return n=>{let r=n.matchBefore(i);return r||n.explicit?{from:r?r.from:n.pos,options:t,validFor:e}:null}}class Eo{constructor(t,e,i,n){this.completion=t,this.source=e,this.match=i,this.score=n}}function Se(s){return s.selection.main.from}function Hh(s,t){var e;let{source:i}=s,n=t&&i[0]!="^",r=i[i.length-1]!="$";return!n&&!r?s:new RegExp(`${n?"^":""}(?:${i})${r?"$":""}`,(e=s.flags)!==null&&e!==void 0?e:s.ignoreCase?"i":"")}const dr=Zt.define();function $u(s,t,e,i){let{main:n}=s.selection,r=e-n.from,o=i-n.from;return{...s.changeByRange(l=>{if(l!=n&&e!=i&&s.sliceDoc(l.from+r,l.from+o)!=s.sliceDoc(e,i))return{range:l};let h=s.toText(t);return{changes:{from:l.from+r,to:i==n.from?l.to:l.from+o,insert:h},range:w.cursor(l.from+r+h.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Lo=new WeakMap;function qu(s){if(!Array.isArray(s))return s;let t=Lo.get(s);return t||Lo.set(s,t=Wu(s)),t}const wn=R.define(),wi=R.define();class Uu{constructor(t){this.pattern=t,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let e=0;e<t.length;){let i=Ht(t,e),n=ne(i);this.chars.push(i);let r=t.slice(e,e+n),o=r.toUpperCase();this.folded.push(Ht(o==r?r.toLowerCase():o,0)),e+=n}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(t){if(this.pattern.length==0)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:e,folded:i,any:n,precise:r,byWord:o}=this;if(e.length==1){let x=Ht(t,0),b=ne(x),k=b==t.length?0:-100;if(x!=e[0])if(x==i[0])k+=-200;else return null;return this.ret(k,[0,b])}let l=t.indexOf(this.pattern);if(l==0)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let h=e.length,f=0;if(l<0){for(let x=0,b=Math.min(t.length,200);x<b&&f<h;){let k=Ht(t,x);(k==e[f]||k==i[f])&&(n[f++]=x),x+=ne(k)}if(f<h)return null}let a=0,c=0,u=!1,d=0,p=-1,g=-1,m=/[a-z]/.test(t),y=!0;for(let x=0,b=Math.min(t.length,200),k=0;x<b&&c<h;){let v=Ht(t,x);l<0&&(a<h&&v==e[a]&&(r[a++]=x),d<h&&(v==e[d]||v==i[d]?(d==0&&(p=x),g=x+1,d++):d=0));let M,A=v<255?v>=48&&v<=57||v>=97&&v<=122?2:v>=65&&v<=90?1:0:(M=dl(v))!=M.toLowerCase()?1:M!=M.toUpperCase()?2:0;(!x||A==1&&m||k==0&&A!=0)&&(e[c]==v||i[c]==v&&(u=!0)?o[c++]=x:o.length&&(y=!1)),k=A,x+=ne(v)}return c==h&&o[0]==0&&y?this.result(-100+(u?-200:0),o,t):d==h&&p==0?this.ret(-200-t.length+(g==t.length?0:-100),[0,g]):l>-1?this.ret(-700-t.length,[l,l+this.pattern.length]):d==h?this.ret(-900-t.length,[p,g]):c==h?this.result(-100+(u?-200:0)+-700+(y?0:-1100),o,t):e.length==2?null:this.result((n[0]?-700:0)+-200+-1100,n,t)}result(t,e,i){let n=[],r=0;for(let o of e){let l=o+(this.astral?ne(Ht(i,o)):1);r&&n[r-1]==o?n[r-1]=l:(n[r++]=o,n[r++]=l)}return this.ret(t-i.length,n)}}class Ku{constructor(t){this.pattern=t,this.matched=[],this.score=0,this.folded=t.toLowerCase()}match(t){if(t.length<this.pattern.length)return null;let e=t.slice(0,this.pattern.length),i=e==this.pattern?0:e.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,e.length],this.score=i+(t.length==this.pattern.length?0:-100),this)}}const Z=P.define({combine(s){return Pn(s,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Qu,filterStrict:!1,compareCompletions:(t,e)=>(t.sortText||t.label).localeCompare(e.sortText||e.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(t,e)=>t&&e,closeOnBlur:(t,e)=>t&&e,icons:(t,e)=>t&&e,tooltipClass:(t,e)=>i=>Io(t(i),e(i)),optionClass:(t,e)=>i=>Io(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})}});function Io(s,t){return s?t?s+" "+t:s:t}function Qu(s,t,e,i,n,r){let o=s.textDirection==j.RTL,l=o,h=!1,f="top",a,c,u=t.left-n.left,d=n.right-t.right,p=i.right-i.left,g=i.bottom-i.top;if(l&&u<Math.min(p,d)?l=!1:!l&&d<Math.min(p,u)&&(l=!0),p<=(l?u:d))a=Math.max(n.top,Math.min(e.top,n.bottom-g))-t.top,c=Math.min(400,l?u:d);else{h=!0,c=Math.min(400,(o?t.right:n.right-t.left)-30);let x=n.bottom-t.bottom;x>=g||x>t.top?a=e.bottom-t.top:(f="bottom",a=t.bottom-e.top)}let m=(t.bottom-t.top)/r.offsetHeight,y=(t.right-t.left)/r.offsetWidth;return{style:`${f}: ${a/m}px; max-width: ${c/y}px`,class:"cm-completionInfo-"+(h?o?"left-narrow":"right-narrow":l?"left":"right")}}function ju(s){let t=s.addToOptions.slice();return s.icons&&t.push({render(e){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),e.type&&i.classList.add(...e.type.split(/\s+/g).map(n=>"cm-completionIcon-"+n)),i.setAttribute("aria-hidden","true"),i},position:20}),t.push({render(e,i,n,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=e.displayLabel||e.label,h=0;for(let f=0;f<r.length;){let a=r[f++],c=r[f++];a>h&&o.appendChild(document.createTextNode(l.slice(h,a)));let u=o.appendChild(document.createElement("span"));u.appendChild(document.createTextNode(l.slice(a,c))),u.className="cm-completionMatchedText",h=c}return h<l.length&&o.appendChild(document.createTextNode(l.slice(h))),o},position:50},{render(e){if(!e.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=e.detail,i},position:80}),t.sort((e,i)=>e.position-i.position).map(e=>e.render)}function ns(s,t,e){if(s<=e)return{from:0,to:s};if(t<0&&(t=0),t<=s>>1){let n=Math.floor(t/e);return{from:n*e,to:(n+1)*e}}let i=Math.floor((s-t)/e);return{from:s-(i+1)*e,to:s-i*e}}class Yu{constructor(t,e,i){this.view=t,this.stateField=e,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:h=>this.placeInfo(h),key:this},this.space=null,this.currentClass="";let n=t.state.field(e),{options:r,selected:o}=n.open,l=t.state.facet(Z);this.optionContent=ju(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=ns(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",h=>{let{options:f}=t.state.field(e).open;for(let a=h.target,c;a&&a!=this.dom;a=a.parentNode)if(a.nodeName=="LI"&&(c=/-(\d+)$/.exec(a.id))&&+c[1]<f.length){this.applyCompletion(t,f[+c[1]]),h.preventDefault();return}}),this.dom.addEventListener("focusout",h=>{let f=t.state.field(this.stateField,!1);f&&f.tooltip&&t.state.facet(Z).closeOnBlur&&h.relatedTarget!=t.contentDOM&&t.dispatch({effects:wi.of(null)})}),this.showOptions(r,n.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(t){var e;let i=t.state.field(this.stateField),n=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=n){let{options:r,selected:o,disabled:l}=i.open;(!n.open||n.open.options!=r)&&(this.range=ns(r.length,o,t.state.facet(Z).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((e=n.open)===null||e===void 0?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of e.split(" "))i&&this.dom.classList.add(i);this.currentClass=e}}positioned(t){this.space=t,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let t=this.view.state.field(this.stateField),e=t.open;(e.selected>-1&&e.selected<this.range.from||e.selected>=this.range.to)&&(this.range=ns(e.options.length,e.selected,this.view.state.facet(Z).maxRenderedOptions),this.showOptions(e.options,t.id));let i=this.updateSelectedOption(e.selected);if(i){this.destroyInfo();let{completion:n}=e.options[e.selected],{info:r}=n;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(n);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(l,n)}).catch(l=>at(this.view.state,l,"completion info")):(this.addInfoPane(o,n),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(t,e){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),t.nodeType!=null)i.appendChild(t),this.infoDestroy=null;else{let{dom:n,destroy:r}=t;i.appendChild(n),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,n=this.range.from;i;i=i.nextSibling,n++)i.nodeName!="LI"||!i.id?n--:n==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return e&&Xu(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),n=t.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return n.top>Math.min(r.bottom,e.bottom)-10||n.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(Z).positionInfo(this.view,e,n,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const n=document.createElement("ul");n.id=e,n.setAttribute("role","listbox"),n.setAttribute("aria-expanded","true"),n.setAttribute("aria-label",this.view.state.phrase("Completions")),n.addEventListener("mousedown",o=>{o.target==n&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:h}=t[o],{section:f}=l;if(f){let u=typeof f=="string"?f:f.name;if(u!=r&&(o>i.from||i.from==0))if(r=u,typeof f!="string"&&f.header)n.appendChild(f.header(f));else{let d=n.appendChild(document.createElement("completion-section"));d.textContent=u}}const a=n.appendChild(document.createElement("li"));a.id=e+"-"+o,a.setAttribute("role","option");let c=this.optionClass(l);c&&(a.className=c);for(let u of this.optionContent){let d=u(l,this.view.state,this.view,h);d&&a.appendChild(d)}}return i.from&&n.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&n.classList.add("cm-completionListIncompleteBottom"),n}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Gu(s,t){return e=>new Yu(e,s,t)}function Xu(s,t){let e=s.getBoundingClientRect(),i=t.getBoundingClientRect(),n=e.height/s.offsetHeight;i.top<e.top?s.scrollTop-=(e.top-i.top)/n:i.bottom>e.bottom&&(s.scrollTop+=(i.bottom-e.bottom)/n)}function No(s){return(s.boost||0)*100+(s.apply?10:0)+(s.info?5:0)+(s.type?1:0)}function _u(s,t){let e=[],i=null,n=null,r=a=>{e.push(a);let{section:c}=a.completion;if(c){i||(i=[]);let u=typeof c=="string"?c:c.name;i.some(d=>d.name==u)||i.push(typeof c=="string"?{name:u}:c)}},o=t.facet(Z);for(let a of s)if(a.hasResult()){let c=a.result.getMatch;if(a.result.filter===!1)for(let u of a.result.options)r(new Eo(u,a.source,c?c(u):[],1e9-e.length));else{let u=t.sliceDoc(a.from,a.to),d,p=o.filterStrict?new Ku(u):new Uu(u);for(let g of a.result.options)if(d=p.match(g.label)){let m=g.displayLabel?c?c(g,d.matched):[]:d.matched,y=d.score+(g.boost||0);if(r(new Eo(g,a.source,m,y)),typeof g.section=="object"&&g.section.rank==="dynamic"){let{name:x}=g.section;n||(n=Object.create(null)),n[x]=Math.max(y,n[x]||-1e9)}}}}if(i){let a=Object.create(null),c=0,u=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?n[p.name]-n[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(u))c-=1e5,a[d.name]=c;for(let d of e){let{section:p}=d.completion;p&&(d.score+=a[typeof p=="string"?p:p.name])}}let l=[],h=null,f=o.compareCompletions;for(let a of e.sort((c,u)=>u.score-c.score||f(c.completion,u.completion))){let c=a.completion;!h||h.label!=c.label||h.detail!=c.detail||h.type!=null&&c.type!=null&&h.type!=c.type||h.apply!=c.apply||h.boost!=c.boost?l.push(a):No(a.completion)>No(h)&&(l[l.length-1]=a),h=a.completion}return l}class Be{constructor(t,e,i,n,r,o){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=n,this.selected=r,this.disabled=o}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Be(this.options,Fo(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,n,r,o){if(n&&!o&&t.some(f=>f.isPending))return n.setDisabled();let l=_u(t,e);if(!l.length)return n&&t.some(f=>f.isPending)?n.setDisabled():null;let h=e.facet(Z).selectOnOpen?0:-1;if(n&&n.selected!=h&&n.selected!=-1){let f=n.options[n.selected].completion;for(let a=0;a<l.length;a++)if(l[a].completion==f){h=a;break}}return new Be(l,Fo(i,h),{pos:t.reduce((f,a)=>a.hasResult()?Math.min(f,a.from):f,1e8),create:nd,above:r.aboveCursor},n?n.timestamp:Date.now(),h,!1)}map(t){return new Be(this.options,this.attrs,{...this.tooltip,pos:t.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Be(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class kn{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new kn(ed,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(t){let{state:e}=t,i=e.facet(Z),r=(i.override||e.languageDataAt("autocomplete",Se(e)).map(qu)).map(h=>(this.active.find(a=>a.source==h)||new vt(h,this.active.some(a=>a.state!=0)?1:0)).update(t,i));r.length==this.active.length&&r.every((h,f)=>h==this.active[f])&&(r=this.active);let o=this.open,l=t.effects.some(h=>h.is(pr));o&&t.docChanged&&(o=o.map(t.changes)),t.selection||r.some(h=>h.hasResult()&&t.changes.touchesRange(h.from,h.to))||!Ju(r,this.active)||l?o=Be.build(r,e,this.id,o,i,l):o&&o.disabled&&!r.some(h=>h.isPending)&&(o=null),!o&&r.every(h=>!h.isPending)&&r.some(h=>h.hasResult())&&(r=r.map(h=>h.hasResult()?new vt(h.source,0):h));for(let h of t.effects)h.is(Wh)&&(o=o&&o.setSelected(h.value,this.id));return r==this.active&&o==this.open?this:new kn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Zu:td}}function Ju(s,t){if(s==t)return!0;for(let e=0,i=0;;){for(;e<s.length&&!s[e].hasResult();)e++;for(;i<t.length&&!t[i].hasResult();)i++;let n=e==s.length,r=i==t.length;if(n||r)return n==r;if(s[e++].result!=t[i++].result)return!1}}const Zu={"aria-autocomplete":"list"},td={};function Fo(s,t){let e={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":s};return t>-1&&(e["aria-activedescendant"]=s+"-"+t),e}const ed=[];function zh(s,t){if(s.isUserEvent("input.complete")){let i=s.annotation(dr);if(i&&t.activateOnCompletion(i))return 12}let e=s.isUserEvent("input.type");return e&&t.activateOnTyping?5:e?1:s.isUserEvent("delete.backward")?2:s.selection?8:s.docChanged?16:0}class vt{constructor(t,e,i=!1){this.source=t,this.state=e,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(t,e){let i=zh(t,e),n=this;(i&8||i&16&&this.touches(t))&&(n=new vt(n.source,0)),i&4&&n.state==0&&(n=new vt(this.source,1)),n=n.updateFor(t,i);for(let r of t.effects)if(r.is(wn))n=new vt(n.source,1,r.value);else if(r.is(wi))n=new vt(n.source,0);else if(r.is(pr))for(let o of r.value)o.source==n.source&&(n=o);return n}updateFor(t,e){return this.map(t.changes)}map(t){return this}touches(t){return t.changes.touchesRange(Se(t.state))}}class Ie extends vt{constructor(t,e,i,n,r,o){super(t,3,e),this.limit=i,this.result=n,this.from=r,this.to=o}hasResult(){return!0}updateFor(t,e){var i;if(!(e&3))return this.map(t.changes);let n=this.result;n.map&&!t.changes.empty&&(n=n.map(n,t.changes));let r=t.changes.mapPos(this.from),o=t.changes.mapPos(this.to,1),l=Se(t.state);if(l>o||!n||e&2&&(Se(t.startState)==this.from||l<this.limit))return new vt(this.source,e&4?1:0);let h=t.changes.mapPos(this.limit);return id(n.validFor,t.state,r,o)?new Ie(this.source,this.explicit,h,n,r,o):n.update&&(n=n.update(n,r,o,new Vh(t.state,l,!1)))?new Ie(this.source,this.explicit,h,n,n.from,(i=n.to)!==null&&i!==void 0?i:Se(t.state)):new vt(this.source,1,this.explicit)}map(t){return t.empty?this:(this.result.map?this.result.map(this.result,t):this.result)?new Ie(this.source,this.explicit,t.mapPos(this.limit),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new vt(this.source,0)}touches(t){return t.changes.touchesRange(this.from,this.to)}}function id(s,t,e,i){if(!s)return!1;let n=t.sliceDoc(e,i);return typeof s=="function"?s(n,e,i,t):Hh(s,!0).test(n)}const pr=R.define({map(s,t){return s.map(e=>e.map(t))}}),Wh=R.define(),rt=ct.define({create(){return kn.start()},update(s,t){return s.update(t)},provide:s=>[qe.from(s,t=>t.tooltip),T.contentAttributes.from(s,t=>t.attrs)]});function gr(s,t){const e=t.completion.apply||t.completion.label;let i=s.state.field(rt).active.find(n=>n.source==t.source);return i instanceof Ie?(typeof e=="string"?s.dispatch({...$u(s.state,e,i.from,i.to),annotations:dr.of(t.completion)}):e(s,t.completion,i.from,i.to),!0):!1}const nd=Gu(rt,gr);function ji(s,t="option"){return e=>{let i=e.state.field(rt,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<e.state.facet(Z).interactionDelay)return!1;let n=1,r;t=="page"&&(r=Sh(e,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=t=="page"?0:o-1:l>=o&&(l=t=="page"?o-1:0),e.dispatch({effects:Wh.of(l)}),!0}}const sd=s=>{let t=s.state.field(rt,!1);return s.state.readOnly||!t||!t.open||t.open.selected<0||t.open.disabled||Date.now()-t.open.timestamp<s.state.facet(Z).interactionDelay?!1:gr(s,t.open.options[t.open.selected])},Ne=s=>s.state.field(rt,!1)?(s.dispatch({effects:wn.of(!0)}),!0):!1,rd=s=>{let t=s.state.field(rt,!1);return!t||!t.active.some(e=>e.state!=0)?!1:(s.dispatch({effects:wi.of(null)}),!0)};class od{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const ld=50,hd=1e3,ad=At.fromClass(class{constructor(s){this.view=s,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let t of s.state.field(rt).active)t.isPending&&this.startQuery(t)}update(s){let t=s.state.field(rt),e=s.state.facet(Z);if(!s.selectionSet&&!s.docChanged&&s.startState.field(rt)==t)return;let i=s.transactions.some(r=>{let o=zh(r,e);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&s.docChanged||o.updates.length+s.transactions.length>ld&&Date.now()-o.time>hd){for(let l of o.context.abortListeners)try{l()}catch(h){at(this.view.state,h)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...s.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),s.transactions.some(r=>r.effects.some(o=>o.is(wn)))&&(this.pendingStart=!0);let n=this.pendingStart?50:e.activateOnTypingDelay;if(this.debounceUpdate=t.active.some(r=>r.isPending&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),n):-1,this.composing!=0)for(let r of s.transactions)r.isUserEvent("input.type")?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:s}=this.view,t=s.field(rt);for(let e of t.active)e.isPending&&!this.running.some(i=>i.active.source==e.source)&&this.startQuery(e);this.running.length&&t.open&&t.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Z).updateSyncTime))}startQuery(s){let{state:t}=this.view,e=Se(t),i=new Vh(t,e,s.explicit,this.view),n=new od(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:wi.of(null)}),at(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(Z).updateSyncTime))}accept(){var s;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let t=[],e=this.view.state.facet(Z),i=this.view.state.field(rt);for(let n=0;n<this.running.length;n++){let r=this.running[n];if(r.done===void 0)continue;if(this.running.splice(n--,1),r.done){let l=Se(r.updates.length?r.updates[0].startState:this.view.state),h=Math.min(l,r.done.from+(r.active.explicit?0:1)),f=new Ie(r.active.source,r.active.explicit,h,r.done,r.done.from,(s=r.done.to)!==null&&s!==void 0?s:l);for(let a of r.updates)f=f.update(a,e);if(f.hasResult()){t.push(f);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new vt(r.active.source,0);for(let h of r.updates)l=l.update(h,e);l.isPending||t.push(l)}else this.startQuery(o)}(t.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:pr.of(t)})}},{eventHandlers:{blur(s){let t=this.view.state.field(rt,!1);if(t&&t.tooltip&&this.view.state.facet(Z).closeOnBlur){let e=t.open&&Sh(this.view,t.open.tooltip);(!e||!e.dom.contains(s.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:wi.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:wn.of(!1)}),20),this.composing=0}}}),fd=typeof navigator=="object"&&/Win/.test(navigator.platform),cd=Ye.highest(T.domEventHandlers({keydown(s,t){let e=t.state.field(rt,!1);if(!e||!e.open||e.open.disabled||e.open.selected<0||s.key.length>1||s.ctrlKey&&!(fd&&s.altKey)||s.metaKey)return!1;let i=e.open.options[e.open.selected],n=e.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||n.result.commitCharacters;return r&&r.indexOf(s.key)>-1&&gr(t,i),!1}})),$h=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",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class ud{constructor(t,e,i,n){this.field=t,this.line=e,this.from=i,this.to=n}}class mr{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,nt.TrackDel),i=t.mapPos(this.to,1,nt.TrackDel);return e==null||i==null?null:new mr(this.field,e,i)}}class yr{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],n=[e],r=t.doc.lineAt(e),o=/^\s*/.exec(r.text)[0];for(let h of this.lines){if(i.length){let f=o,a=/^\t*/.exec(h)[0].length;for(let c=0;c<a;c++)f+=t.facet(Nn);n.push(e+f.length-a),h=f+h.slice(a)}i.push(h),e+=h.length+1}let l=this.fieldPositions.map(h=>new mr(h.field,n[h.line]+h.from,n[h.line]+h.to));return{text:i,ranges:l}}static parse(t){let e=[],i=[],n=[],r;for(let o of t.split(/\r\n?|\n/)){for(;r=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(o);){let l=r[1]?+r[1]:null,h=r[2]||r[3]||"",f=-1,a=h.replace(/\\[{}]/g,c=>c[1]);for(let c=0;c<e.length;c++)(l!=null?e[c].seq==l:a&&e[c].name==a)&&(f=c);if(f<0){let c=0;for(;c<e.length&&(l==null||e[c].seq!=null&&e[c].seq<l);)c++;e.splice(c,0,{seq:l,name:a}),f=c;for(let u of n)u.field>=f&&u.field++}for(let c of n)if(c.line==i.length&&c.from>r.index){let u=r[2]?3+(r[1]||"").length:2;c.from-=u,c.to-=u}n.push(new ud(f,i.length,r.index,r.index+a.length)),o=o.slice(0,r.index)+h+o.slice(r.index+r[0].length)}o=o.replace(/\\([{}])/g,(l,h,f)=>{for(let a of n)a.line==i.length&&a.from>f&&(a.from--,a.to--);return h}),i.push(o)}return new yr(i,n)}}let dd=N.widget({widget:new class extends vi{toDOM(){let s=document.createElement("span");return s.className="cm-snippetFieldPosition",s}ignoreEvent(){return!1}}}),pd=N.mark({class:"cm-snippetField"});class Ge{constructor(t,e){this.ranges=t,this.active=e,this.deco=N.set(t.map(i=>(i.from==i.to?dd:pd).range(i.from,i.to)),!0)}map(t){let e=[];for(let i of this.ranges){let n=i.map(t);if(!n)return null;e.push(n)}return new Ge(e,this.active)}selectionInsideField(t){return t.ranges.every(e=>this.ranges.some(i=>i.field==this.active&&i.from<=e.from&&i.to>=e.to))}}const Oi=R.define({map(s,t){return s&&s.map(t)}}),gd=R.define(),ki=ct.define({create(){return null},update(s,t){for(let e of t.effects){if(e.is(Oi))return e.value;if(e.is(gd)&&s)return new Ge(s.ranges,e.value)}return s&&t.docChanged&&(s=s.map(t.changes)),s&&t.selection&&!s.selectionInsideField(t.selection)&&(s=null),s},provide:s=>T.decorations.from(s,t=>t?t.deco:N.none)});function br(s,t){return w.create(s.filter(e=>e.field==t).map(e=>w.range(e.from,e.to)))}function md(s){let t=yr.parse(s);return(e,i,n,r)=>{let{text:o,ranges:l}=t.instantiate(e.state,n),{main:h}=e.state.selection,f={changes:{from:n,to:r==h.from?h.to:r,insert:L.of(o)},scrollIntoView:!0,annotations:i?[dr.of(i),G.userEvent.of("input.complete")]:void 0};if(l.length&&(f.selection=br(l,0)),l.some(a=>a.field>0)){let a=new Ge(l,0),c=f.effects=[Oi.of(a)];e.state.field(ki,!1)===void 0&&c.push(R.appendConfig.of([ki,kd,vd,$h]))}e.dispatch(e.state.update(f))}}function qh(s){return({state:t,dispatch:e})=>{let i=t.field(ki,!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 e(t.update({selection:br(i.ranges,n),effects:Oi.of(r?null:new Ge(i.ranges,n)),scrollIntoView:!0})),!0}}const yd=({state:s,dispatch:t})=>s.field(ki,!1)?(t(s.update({effects:Oi.of(null)})),!0):!1,bd=qh(1),xd=qh(-1),wd=[{key:"Tab",run:bd,shift:xd},{key:"Escape",run:yd}],Vo=P.define({combine(s){return s.length?s[0]:wd}}),kd=Ye.highest(Ln.compute([Vo],s=>s.facet(Vo))),vd=T.domEventHandlers({mousedown(s,t){let e=t.state.field(ki,!1),i;if(!e||(i=t.posAtCoords({x:s.clientX,y:s.clientY}))==null)return!1;let n=e.ranges.find(r=>r.from<=i&&r.to>=i);return!n||n.field==e.active?!1:(t.dispatch({selection:br(e.ranges,n.field),effects:Oi.of(e.ranges.some(r=>r.field>n.field)?new Ge(e.ranges,n.field):null),scrollIntoView:!0}),!0)}}),vn={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},ke=R.define({map(s,t){let e=t.mapPos(s,-1,nt.TrackAfter);return e??void 0}}),xr=new class extends Ce{};xr.startSide=1;xr.endSide=-1;const Uh=ct.define({create(){return H.empty},update(s,t){if(s=s.map(t.changes),t.selection){let e=t.state.doc.lineAt(t.selection.main.head);s=s.update({filter:i=>i>=e.from&&i<=e.to})}for(let e of t.effects)e.is(ke)&&(s=s.update({add:[xr.range(e.value,e.value+1)]}));return s}});function Sd(){return[Md,Uh]}const ss="()[]{}<>«»»«[]{}";function Cd(s){for(let t=0;t<ss.length;t+=2)if(ss.charCodeAt(t)==s)return ss.charAt(t+1);return dl(s<128?s:s+1)}function Od(s,t){return s.languageDataAt("closeBrackets",t)[0]||vn}const Ad=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),Md=T.inputHandler.of((s,t,e,i)=>{if((Ad?s.composing:s.compositionStarted)||s.state.readOnly)return!1;let n=s.state.selection.main;if(i.length>2||i.length==2&&ne(Ht(i,0))==1||t!=n.from||e!=n.to)return!1;let r=Td(s.state,i);return r?(s.dispatch(r),!0):!1});function Td(s,t){let e=Od(s,s.selection.main.head),i=e.brackets||vn.brackets;for(let n of i){let r=Cd(Ht(n,0));if(t==n)return r==n?Bd(s,n,i.indexOf(n+n+n)>-1,e):Pd(s,n,r,e.before||vn.before);if(t==r&&Kh(s,s.selection.main.from))return Dd(s,n,r)}return null}function Kh(s,t){let e=!1;return s.field(Uh).between(0,s.doc.length,i=>{i==t&&(e=!0)}),e}function wr(s,t){let e=s.sliceString(t,t+2);return e.slice(0,ne(Ht(e,0)))}function Pd(s,t,e,i){let n=null,r=s.changeByRange(o=>{if(!o.empty)return{changes:[{insert:t,from:o.from},{insert:e,from:o.to}],effects:ke.of(o.to+t.length),range:w.range(o.anchor+t.length,o.head+t.length)};let l=wr(s.doc,o.head);return!l||/\s/.test(l)||i.indexOf(l)>-1?{changes:{insert:t+e,from:o.head},effects:ke.of(o.head+t.length),range:w.cursor(o.head+t.length)}:{range:n=o}});return n?null:s.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Dd(s,t,e){let i=null,n=s.changeByRange(r=>r.empty&&wr(s.doc,r.head)==e?{changes:{from:r.head,to:r.head+e.length,insert:e},range:w.cursor(r.head+e.length)}:i={range:r});return i?null:s.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function Bd(s,t,e,i){let n=i.stringPrefixes||vn.stringPrefixes,r=null,o=s.changeByRange(l=>{if(!l.empty)return{changes:[{insert:t,from:l.from},{insert:t,from:l.to}],effects:ke.of(l.to+t.length),range:w.range(l.anchor+t.length,l.head+t.length)};let h=l.head,f=wr(s.doc,h),a;if(f==t){if(Ho(s,h))return{changes:{insert:t+t,from:h},effects:ke.of(h+t.length),range:w.cursor(h+t.length)};if(Kh(s,h)){let u=e&&s.sliceDoc(h,h+t.length*3)==t+t+t?t+t+t:t;return{changes:{from:h,to:h+u.length,insert:u},range:w.cursor(h+u.length)}}}else{if(e&&s.sliceDoc(h-2*t.length,h)==t+t&&(a=zo(s,h-2*t.length,n))>-1&&Ho(s,a))return{changes:{insert:t+t+t+t,from:h},effects:ke.of(h+t.length),range:w.cursor(h+t.length)};if(s.charCategorizer(h)(f)!=kt.Word&&zo(s,h,n)>-1&&!Rd(s,h,t,n))return{changes:{insert:t+t,from:h},effects:ke.of(h+t.length),range:w.cursor(h+t.length)}}return{range:r=l}});return r?null:s.update(o,{scrollIntoView:!0,userEvent:"input.type"})}function Ho(s,t){let e=gt(s).resolveInner(t+1);return e.parent&&e.from==t}function Rd(s,t,e,i){let n=gt(s).resolveInner(t,-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+e.length+r)),h=l.indexOf(e);if(!h||h>-1&&i.indexOf(l.slice(0,h))>-1){let a=n.firstChild;for(;a&&a.from==n.from&&a.to-a.from>e.length+h;){if(s.sliceDoc(a.to-e.length,a.to)==e)return!1;a=a.firstChild}return!0}let f=n.to==t&&n.parent;if(!f)break;n=f}return!1}function zo(s,t,e){let i=s.charCategorizer(t);if(i(s.sliceDoc(t-1,t))!=kt.Word)return t;for(let n of e){let r=t-n.length;if(s.sliceDoc(r,t)==n&&i(s.sliceDoc(r-1,r))!=kt.Word)return r}return-1}function Ed(s={}){return[cd,rt,Z.of(s),ad,Id,$h]}const Ld=[{key:"Ctrl-Space",run:Ne},{mac:"Alt-`",run:Ne},{mac:"Alt-i",run:Ne},{key:"Escape",run:rd},{key:"ArrowDown",run:ji(!0)},{key:"ArrowUp",run:ji(!1)},{key:"PageDown",run:ji(!0,"page")},{key:"PageUp",run:ji(!1,"page")},{key:"Enter",run:sd}],Id=Ye.highest(Ln.computeN([Z],s=>s.facet(Z).defaultKeymap?[Ld]:[]));function Eg(s){let t=s.field(rt,!1);return t&&t.active.some(e=>e.isPending)?"pending":t&&t.active.some(e=>e.state!=0)?"active":null}const Wo=new WeakMap;function Lg(s){var t;let e=(t=s.field(rt,!1))===null||t===void 0?void 0:t.open;if(!e||e.disabled)return[];let i=Wo.get(e.options);return i||Wo.set(e.options,i=e.options.map(n=>n.completion)),i}const Nd=s=>{let{state:t}=s,e=t.doc.lineAt(t.selection.main.from),i=vr(s.state,e.from);return i.line?Fd(s):i.block?Hd(s):!1};function kr(s,t){return({state:e,dispatch:i})=>{if(e.readOnly)return!1;let n=s(t,e);return n?(i(e.update(n)),!0):!1}}const Fd=kr($d,0),Vd=kr(Qh,0),Hd=kr((s,t)=>Qh(s,t,Wd(t)),0);function vr(s,t){let e=s.languageDataAt("commentTokens",t,1);return e.length?e[0]:{}}const ni=50;function zd(s,{open:t,close:e},i,n){let r=s.sliceDoc(i-ni,i),o=s.sliceDoc(n,n+ni),l=/\s*$/.exec(r)[0].length,h=/^\s*/.exec(o)[0].length,f=r.length-l;if(r.slice(f-t.length,f)==t&&o.slice(h,h+e.length)==e)return{open:{pos:i-l,margin:l&&1},close:{pos:n+h,margin:h&&1}};let a,c;n-i<=2*ni?a=c=s.sliceDoc(i,n):(a=s.sliceDoc(i,i+ni),c=s.sliceDoc(n-ni,n));let u=/^\s*/.exec(a)[0].length,d=/\s*$/.exec(c)[0].length,p=c.length-d-e.length;return a.slice(u,u+t.length)==t&&c.slice(p,p+e.length)==e?{open:{pos:i+u+t.length,margin:/\s/.test(a.charAt(u+t.length))?1:0},close:{pos:n-d-e.length,margin:/\s/.test(c.charAt(p-1))?1:0}}:null}function Wd(s){let t=[];for(let e of s.selection.ranges){let i=s.doc.lineAt(e.from),n=e.to<=i.to?i:s.doc.lineAt(e.to);n.from>i.from&&n.from==e.to&&(n=e.to==i.to+1?i:s.doc.lineAt(e.to-1));let r=t.length-1;r>=0&&t[r].to>i.from?t[r].to=n.to:t.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:n.to})}return t}function Qh(s,t,e=t.selection.ranges){let i=e.map(r=>vr(t,r.from).block);if(!i.every(r=>r))return null;let n=e.map((r,o)=>zd(t,i[o],r.from,r.to));if(s!=2&&!n.every(r=>r))return{changes:t.changes(e.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 h=i[o],{open:f,close:a}=l;r.push({from:f.pos-h.open.length,to:f.pos+f.margin},{from:a.pos-a.margin,to:a.pos+h.close.length})}return{changes:r}}return null}function $d(s,t,e=t.selection.ranges){let i=[],n=-1;for(let{from:r,to:o}of e){let l=i.length,h=1e9,f=vr(t,r).line;if(f){for(let a=r;a<=o;){let c=t.doc.lineAt(a);if(c.from>n&&(r==o||o>c.from)){n=c.from;let u=/^\s*/.exec(c.text)[0].length,d=u==c.length,p=c.text.slice(u,u+f.length)==f?u:-1;u<c.text.length&&u<h&&(h=u),i.push({line:c,comment:p,token:f,indent:u,empty:d,single:!1})}a=c.to+1}if(h<1e9)for(let a=l;a<i.length;a++)i[a].indent<i[a].line.text.length&&(i[a].indent=h);i.length==l+1&&(i[l].single=!0)}}if(s!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:h,indent:f,empty:a,single:c}of i)(c||!a)&&r.push({from:l.from+f,insert:h+" "});let o=t.changes(r);return{changes:o,selection:t.selection.map(o,1)}}else if(s!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:h}of i)if(l>=0){let f=o.from+l,a=f+h.length;o.text[a-o.from]==" "&&a++,r.push({from:f,to:a})}return{changes:r}}return null}const Qs=Zt.define(),qd=Zt.define(),Ud=P.define(),jh=P.define({combine(s){return Pn(s,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,n)=>t(i,n)||e(i,n)})}}),Yh=ct.define({create(){return Ut.empty},update(s,t){let e=t.state.facet(jh),i=t.annotation(Qs);if(i){let h=dt.fromTransaction(t,i.selection),f=i.side,a=f==0?s.undone:s.done;return h?a=Sn(a,a.length,e.minDepth,h):a=_h(a,t.startState.selection),new Ut(f==0?i.rest:a,f==0?a:i.rest)}let n=t.annotation(qd);if((n=="full"||n=="before")&&(s=s.isolate()),t.annotation(G.addToHistory)===!1)return t.changes.empty?s:s.addMapping(t.changes.desc);let r=dt.fromTransaction(t),o=t.annotation(G.time),l=t.annotation(G.userEvent);return r?s=s.addChanges(r,o,l,e,t):t.selection&&(s=s.addSelection(t.startState.selection,o,l,e.newGroupDelay)),(n=="full"||n=="after")&&(s=s.isolate()),s},toJSON(s){return{done:s.done.map(t=>t.toJSON()),undone:s.undone.map(t=>t.toJSON())}},fromJSON(s){return new Ut(s.done.map(dt.fromJSON),s.undone.map(dt.fromJSON))}});function Kd(s={}){return[Yh,jh.of(s),T.domEventHandlers({beforeinput(t,e){let i=t.inputType=="historyUndo"?Qd:t.inputType=="historyRedo"?jd:null;return i?(t.preventDefault(),i(e)):!1}})]}function Gh(s,t){return function({state:e,dispatch:i}){if(!t&&e.readOnly)return!1;let n=e.field(Yh,!1);if(!n)return!1;let r=n.pop(s,e,t);return r?(i(r),!0):!1}}const Qd=Gh(0,!1),jd=Gh(1,!1);class dt{constructor(t,e,i,n,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=n,this.selectionsAfter=r}setSelAfter(t){return new dt(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(e=this.mapped)===null||e===void 0?void 0:e.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(n=>n.toJSON())}}static fromJSON(t){return new dt(t.changes&&_.fromJSON(t.changes),[],t.mapped&&Qt.fromJSON(t.mapped),t.startSelection&&w.fromJSON(t.startSelection),t.selectionsAfter.map(w.fromJSON))}static fromTransaction(t,e){let i=St;for(let n of t.startState.facet(Ud)){let r=n(t);r.length&&(i=i.concat(r))}return!i.length&&t.changes.empty?null:new dt(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,St)}static selection(t){return new dt(void 0,St,void 0,void 0,t)}}function Sn(s,t,e,i){let n=t+1>e+20?t-e-1:0,r=s.slice(n,t);return r.push(i),r}function Yd(s,t){let e=[],i=!1;return s.iterChangedRanges((n,r)=>e.push(n,r)),t.iterChangedRanges((n,r,o,l)=>{for(let h=0;h<e.length;){let f=e[h++],a=e[h++];l>=f&&o<=a&&(i=!0)}}),i}function Gd(s,t){return s.ranges.length==t.ranges.length&&s.ranges.filter((e,i)=>e.empty!=t.ranges[i].empty).length===0}function Xh(s,t){return s.length?t.length?s.concat(t):s:t}const St=[],Xd=200;function _h(s,t){if(s.length){let e=s[s.length-1],i=e.selectionsAfter.slice(Math.max(0,e.selectionsAfter.length-Xd));return i.length&&i[i.length-1].eq(t)?s:(i.push(t),Sn(s,s.length-1,1e9,e.setSelAfter(i)))}else return[dt.selection([t])]}function _d(s){let t=s[s.length-1],e=s.slice();return e[s.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),e}function rs(s,t){if(!s.length)return s;let e=s.length,i=St;for(;e;){let n=Jd(s[e-1],t,i);if(n.changes&&!n.changes.empty||n.effects.length){let r=s.slice(0,e);return r[e-1]=n,r}else t=n.mapped,e--,i=n.selectionsAfter}return i.length?[dt.selection(i)]:St}function Jd(s,t,e){let i=Xh(s.selectionsAfter.length?s.selectionsAfter.map(l=>l.map(t)):St,e);if(!s.changes)return dt.selection(i);let n=s.changes.map(t),r=t.mapDesc(s.changes,!0),o=s.mapped?s.mapped.composeDesc(r):r;return new dt(n,R.mapEffects(s.effects,t),o,s.startSelection.map(r),i)}const Zd=/^(input\.type|delete)($|\.)/;class Ut{constructor(t,e,i=0,n=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=n}isolate(){return this.prevTime?new Ut(this.done,this.undone):this}addChanges(t,e,i,n,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&t.changes&&(!i||Zd.test(i))&&(!l.selectionsAfter.length&&e-this.prevTime<n.newGroupDelay&&n.joinToEvent(r,Yd(l.changes,t.changes))||i=="input.type.compose")?o=Sn(o,o.length-1,n.minDepth,new dt(t.changes.compose(l.changes),Xh(R.mapEffects(t.effects,l.changes),l.effects),l.mapped,l.startSelection,St)):o=Sn(o,o.length,n.minDepth,t),new Ut(o,St,e,i)}addSelection(t,e,i,n){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:St;return r.length>0&&e-this.prevTime<n&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&Gd(r[r.length-1],t)?this:new Ut(_h(this.done,t),this.undone,e,i)}addMapping(t){return new Ut(rs(this.done,t),rs(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let n=t==0?this.done:this.undone;if(n.length==0)return null;let r=n[n.length-1],o=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Qs.of({side:t,rest:_d(n),selection:o}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=n.length==1?St:n.slice(0,n.length-1);return r.mapped&&(l=rs(l,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Qs.of({side:t,rest:l,selection:o}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}}Ut.empty=new Ut(St,St);function Xe(s,t){return w.create(s.ranges.map(t),s.mainIndex)}function Rt(s,t){return s.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function Et({state:s,dispatch:t},e){let i=Xe(s.selection,e);return i.eq(s.selection,!0)?!1:(t(Rt(s,i)),!0)}function Hn(s,t){return w.cursor(t?s.to:s.from)}function Jh(s,t){return Et(s,e=>e.empty?s.moveByChar(e,t):Hn(e,t))}function lt(s){return s.textDirectionAt(s.state.selection.main.head)==j.LTR}const Zh=s=>Jh(s,!lt(s)),ta=s=>Jh(s,lt(s));function ea(s,t){return Et(s,e=>e.empty?s.moveByGroup(e,t):Hn(e,t))}const tp=s=>ea(s,!lt(s)),ep=s=>ea(s,lt(s));function ip(s,t,e){if(t.type.prop(e))return!0;let i=t.to-t.from;return i&&(i>2||/[^\s,.;:]/.test(s.sliceDoc(t.from,t.to)))||t.firstChild}function zn(s,t,e){let i=gt(s).resolveInner(t.head),n=e?B.closedBy:B.openedBy;for(let h=t.head;;){let f=e?i.childAfter(h):i.childBefore(h);if(!f)break;ip(s,f,n)?i=f:h=e?f.to:f.from}let r=i.type.prop(n),o,l;return r&&(o=e?qt(s,i.from,1):qt(s,i.to,-1))&&o.matched?l=e?o.end.to:o.end.from:l=e?i.to:i.from,w.cursor(l,e?-1:1)}const np=s=>Et(s,t=>zn(s.state,t,!lt(s))),sp=s=>Et(s,t=>zn(s.state,t,lt(s)));function ia(s,t){return Et(s,e=>{if(!e.empty)return Hn(e,t);let i=s.moveVertically(e,t);return i.head!=e.head?i:s.moveToLineBoundary(e,t)})}const na=s=>ia(s,!1),sa=s=>ia(s,!0);function ra(s){let t=s.scrollDOM.clientHeight<s.scrollDOM.scrollHeight-2,e=0,i=0,n;if(t){for(let r of s.state.facet(T.scrollMargins)){let o=r(s);o!=null&&o.top&&(e=Math.max(o==null?void 0:o.top,e)),o!=null&&o.bottom&&(i=Math.max(o==null?void 0:o.bottom,i))}n=s.scrollDOM.clientHeight-e-i}else n=(s.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:e,marginBottom:i,selfScroll:t,height:Math.max(s.defaultLineHeight,n-5)}}function oa(s,t){let e=ra(s),{state:i}=s,n=Xe(i.selection,o=>o.empty?s.moveVertically(o,t,e.height):Hn(o,t));if(n.eq(i.selection))return!1;let r;if(e.selfScroll){let o=s.coordsAtPos(i.selection.main.head),l=s.scrollDOM.getBoundingClientRect(),h=l.top+e.marginTop,f=l.bottom-e.marginBottom;o&&o.top>h&&o.bottom<f&&(r=T.scrollIntoView(n.main.head,{y:"start",yMargin:o.top-h}))}return s.dispatch(Rt(i,n),{effects:r}),!0}const $o=s=>oa(s,!1),js=s=>oa(s,!0);function pe(s,t,e){let i=s.lineBlockAt(t.head),n=s.moveToLineBoundary(t,e);if(n.head==t.head&&n.head!=(e?i.to:i.from)&&(n=s.moveToLineBoundary(t,e,!1)),!e&&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&&t.head!=i.from+r&&(n=w.cursor(i.from+r))}return n}const rp=s=>Et(s,t=>pe(s,t,!0)),op=s=>Et(s,t=>pe(s,t,!1)),lp=s=>Et(s,t=>pe(s,t,!lt(s))),hp=s=>Et(s,t=>pe(s,t,lt(s))),ap=s=>Et(s,t=>w.cursor(s.lineBlockAt(t.head).from,1)),fp=s=>Et(s,t=>w.cursor(s.lineBlockAt(t.head).to,-1));function cp(s,t,e){let i=!1,n=Xe(s.selection,r=>{let o=qt(s,r.head,-1)||qt(s,r.head,1)||r.head>0&&qt(s,r.head-1,1)||r.head<s.doc.length&&qt(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 w.cursor(l)});return i?(t(Rt(s,n)),!0):!1}const up=({state:s,dispatch:t})=>cp(s,t);function Tt(s,t){let e=Xe(s.state.selection,i=>{let n=t(i);return w.range(i.anchor,n.head,n.goalColumn,n.bidiLevel||void 0)});return e.eq(s.state.selection)?!1:(s.dispatch(Rt(s.state,e)),!0)}function la(s,t){return Tt(s,e=>s.moveByChar(e,t))}const ha=s=>la(s,!lt(s)),aa=s=>la(s,lt(s));function fa(s,t){return Tt(s,e=>s.moveByGroup(e,t))}const dp=s=>fa(s,!lt(s)),pp=s=>fa(s,lt(s)),gp=s=>Tt(s,t=>zn(s.state,t,!lt(s))),mp=s=>Tt(s,t=>zn(s.state,t,lt(s)));function ca(s,t){return Tt(s,e=>s.moveVertically(e,t))}const ua=s=>ca(s,!1),da=s=>ca(s,!0);function pa(s,t){return Tt(s,e=>s.moveVertically(e,t,ra(s).height))}const qo=s=>pa(s,!1),Uo=s=>pa(s,!0),yp=s=>Tt(s,t=>pe(s,t,!0)),bp=s=>Tt(s,t=>pe(s,t,!1)),xp=s=>Tt(s,t=>pe(s,t,!lt(s))),wp=s=>Tt(s,t=>pe(s,t,lt(s))),kp=s=>Tt(s,t=>w.cursor(s.lineBlockAt(t.head).from)),vp=s=>Tt(s,t=>w.cursor(s.lineBlockAt(t.head).to)),Ko=({state:s,dispatch:t})=>(t(Rt(s,{anchor:0})),!0),Qo=({state:s,dispatch:t})=>(t(Rt(s,{anchor:s.doc.length})),!0),jo=({state:s,dispatch:t})=>(t(Rt(s,{anchor:s.selection.main.anchor,head:0})),!0),Yo=({state:s,dispatch:t})=>(t(Rt(s,{anchor:s.selection.main.anchor,head:s.doc.length})),!0),Sp=({state:s,dispatch:t})=>(t(s.update({selection:{anchor:0,head:s.doc.length},userEvent:"select"})),!0),Cp=({state:s,dispatch:t})=>{let e=Wn(s).map(({from:i,to:n})=>w.range(i,Math.min(n+1,s.doc.length)));return t(s.update({selection:w.create(e),userEvent:"select"})),!0},Op=({state:s,dispatch:t})=>{let e=Xe(s.selection,i=>{let n=gt(s),r=n.resolveStack(i.from,1);if(i.empty){let o=n.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return w.range(l.to,l.from)}return i});return e.eq(s.selection)?!1:(t(Rt(s,e)),!0)};function ga(s,t){let{state:e}=s,i=e.selection,n=e.selection.ranges.slice();for(let r of e.selection.ranges){let o=e.doc.lineAt(r.head);if(t?o.to<s.state.doc.length:o.from>0)for(let l=r;;){let h=s.moveVertically(l,t);if(h.head<o.from||h.head>o.to){n.some(f=>f.head==h.head)||n.push(h);break}else{if(h.head==l.head)break;l=h}}}return n.length==i.ranges.length?!1:(s.dispatch(Rt(e,w.create(n,n.length-1))),!0)}const Ap=s=>ga(s,!1),Mp=s=>ga(s,!0),Tp=({state:s,dispatch:t})=>{let e=s.selection,i=null;return e.ranges.length>1?i=w.create([e.main]):e.main.empty||(i=w.create([w.cursor(e.main.head)])),i?(t(Rt(s,i)),!0):!1};function Ai(s,t){if(s.state.readOnly)return!1;let e="delete.selection",{state:i}=s,n=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let h=t(r);h<o?(e="delete.backward",h=Yi(s,h,!1)):h>o&&(e="delete.forward",h=Yi(s,h,!0)),o=Math.min(o,h),l=Math.max(l,h)}else o=Yi(s,o,!1),l=Yi(s,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:w.cursor(o,o<r.head?-1:1)}});return n.changes.empty?!1:(s.dispatch(i.update(n,{scrollIntoView:!0,userEvent:e,effects:e=="delete.selection"?T.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Yi(s,t,e){if(s instanceof T)for(let i of s.state.facet(T.atomicRanges).map(n=>n(s)))i.between(t,t,(n,r)=>{n<t&&r>t&&(t=e?r:n)});return t}const ma=(s,t,e)=>Ai(s,i=>{let n=i.from,{state:r}=s,o=r.doc.lineAt(n),l,h;if(e&&!t&&n>o.from&&n<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,n-o.from))){if(l[l.length-1]==" ")return n-1;let f=Dn(l,r.tabSize),a=f%bn(r)||bn(r);for(let c=0;c<a&&l[l.length-1-c]==" ";c++)n--;h=n}else h=ht(o.text,n-o.from,t,t)+o.from,h==n&&o.number!=(t?r.doc.lines:1)?h+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(h-o.from,n-o.from))&&(h=ht(o.text,h-o.from,!1,!1)+o.from);return h}),Ys=s=>ma(s,!1,!0),ya=s=>ma(s,!0,!1),ba=(s,t)=>Ai(s,e=>{let i=e.head,{state:n}=s,r=n.doc.lineAt(i),o=n.charCategorizer(i);for(let l=null;;){if(i==(t?r.to:r.from)){i==e.head&&r.number!=(t?n.doc.lines:1)&&(i+=t?1:-1);break}let h=ht(r.text,i-r.from,t)+r.from,f=r.text.slice(Math.min(i,h)-r.from,Math.max(i,h)-r.from),a=o(f);if(l!=null&&a!=l)break;(f!=" "||i!=e.head)&&(l=a),i=h}return i}),xa=s=>ba(s,!1),Pp=s=>ba(s,!0),Dp=s=>Ai(s,t=>{let e=s.lineBlockAt(t.head).to;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),Bp=s=>Ai(s,t=>{let e=s.moveToLineBoundary(t,!1).head;return t.head>e?e:Math.max(0,t.head-1)}),Rp=s=>Ai(s,t=>{let e=s.moveToLineBoundary(t,!0).head;return t.head<e?e:Math.min(s.state.doc.length,t.head+1)}),Ep=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=s.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:L.of(["",""])},range:w.cursor(i.from)}));return t(s.update(e,{scrollIntoView:!0,userEvent:"input"})),!0},Lp=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=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:ht(r.text,n-r.from,!1)+r.from,l=n==r.to?n+1:ht(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:w.cursor(l)}});return e.changes.empty?!1:(t(s.update(e,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Wn(s){let t=[],e=-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)),e>=n.number){let o=t[t.length-1];o.to=r.to,o.ranges.push(i)}else t.push({from:n.from,to:r.to,ranges:[i]});e=r.number+1}return t}function wa(s,t,e){if(s.readOnly)return!1;let i=[],n=[];for(let r of Wn(s)){if(e?r.to==s.doc.length:r.from==0)continue;let o=s.doc.lineAt(e?r.to+1:r.from-1),l=o.length+1;if(e){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+s.lineBreak});for(let h of r.ranges)n.push(w.range(Math.min(s.doc.length,h.anchor+l),Math.min(s.doc.length,h.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:s.lineBreak+o.text});for(let h of r.ranges)n.push(w.range(h.anchor-l,h.head-l))}}return i.length?(t(s.update({changes:i,scrollIntoView:!0,selection:w.create(n,s.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Ip=({state:s,dispatch:t})=>wa(s,t,!1),Np=({state:s,dispatch:t})=>wa(s,t,!0);function ka(s,t,e){if(s.readOnly)return!1;let i=[];for(let n of Wn(s))e?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 t(s.update({changes:i,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Fp=({state:s,dispatch:t})=>ka(s,t,!1),Vp=({state:s,dispatch:t})=>ka(s,t,!0),Hp=s=>{if(s.state.readOnly)return!1;let{state:t}=s,e=t.changes(Wn(t).map(({from:n,to:r})=>(n>0?n--:r<t.doc.length&&r++,{from:n,to:r}))),i=Xe(t.selection,n=>{let r;if(s.lineWrapping){let o=s.lineBlockAt(n.head),l=s.coordsAtPos(n.head,n.assoc||1);l&&(r=o.bottom+s.documentTop-l.bottom+s.defaultLineHeight/2)}return s.moveVertically(n,!0,r)}).map(e);return s.dispatch({changes:e,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function zp(s,t){if(/\(\)|\[\]|\{\}/.test(s.sliceDoc(t-1,t+1)))return{from:t,to:t};let e=gt(s).resolveInner(t),i=e.childBefore(t),n=e.childAfter(t),r;return i&&n&&i.to<=t&&n.from>=t&&(r=i.type.prop(B.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 Go=va(!1),Wp=va(!0);function va(s){return({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange(n=>{let{from:r,to:o}=n,l=t.doc.lineAt(r),h=!s&&r==o&&zp(t,r);s&&(r=o=(o<=l.to?l:t.doc.lineAt(o)).to);let f=new Fn(t,{simulateBreak:r,simulateDoubleBreak:!!h}),a=Eh(f,r);for(a==null&&(a=Dn(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;h?{from:r,to:o}=h:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let c=["",xn(t,a)];return h&&c.push(xn(t,f.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:L.of(c)},range:w.cursor(r+1+c[1].length)}});return e(t.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function Sr(s,t){let e=-1;return s.changeByRange(i=>{let n=[];for(let o=i.from;o<=i.to;){let l=s.doc.lineAt(o);l.number>e&&(i.empty||i.to>l.from)&&(t(l,n,i),e=l.number),o=l.to+1}let r=s.changes(n);return{changes:n,range:w.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const $p=({state:s,dispatch:t})=>{if(s.readOnly)return!1;let e=Object.create(null),i=new Fn(s,{overrideIndentation:r=>{let o=e[r];return o??-1}}),n=Sr(s,(r,o,l)=>{let h=Eh(i,r.from);if(h==null)return;/\S/.test(r.text)||(h=0);let f=/^\s*/.exec(r.text)[0],a=xn(s,h);(f!=a||l.from<r.from+f.length)&&(e[r.from]=h,o.push({from:r.from,to:r.from+f.length,insert:a}))});return n.changes.empty||t(s.update(n,{userEvent:"indent"})),!0},Sa=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Sr(s,(e,i)=>{i.push({from:e.from,insert:s.facet(Nn)})}),{userEvent:"input.indent"})),!0),Ca=({state:s,dispatch:t})=>s.readOnly?!1:(t(s.update(Sr(s,(e,i)=>{let n=/^\s*/.exec(e.text)[0];if(!n)return;let r=Dn(n,s.tabSize),o=0,l=xn(s,Math.max(0,r-bn(s)));for(;o<n.length&&o<l.length&&n.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:e.from+o,to:e.from+n.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),qp=s=>(s.setTabFocusMode(),!0),Up=[{key:"Ctrl-b",run:Zh,shift:ha,preventDefault:!0},{key:"Ctrl-f",run:ta,shift:aa},{key:"Ctrl-p",run:na,shift:ua},{key:"Ctrl-n",run:sa,shift:da},{key:"Ctrl-a",run:ap,shift:kp},{key:"Ctrl-e",run:fp,shift:vp},{key:"Ctrl-d",run:ya},{key:"Ctrl-h",run:Ys},{key:"Ctrl-k",run:Dp},{key:"Ctrl-Alt-h",run:xa},{key:"Ctrl-o",run:Ep},{key:"Ctrl-t",run:Lp},{key:"Ctrl-v",run:js}],Kp=[{key:"ArrowLeft",run:Zh,shift:ha,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:tp,shift:dp,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:lp,shift:xp,preventDefault:!0},{key:"ArrowRight",run:ta,shift:aa,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:ep,shift:pp,preventDefault:!0},{mac:"Cmd-ArrowRight",run:hp,shift:wp,preventDefault:!0},{key:"ArrowUp",run:na,shift:ua,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Ko,shift:jo},{mac:"Ctrl-ArrowUp",run:$o,shift:qo},{key:"ArrowDown",run:sa,shift:da,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Qo,shift:Yo},{mac:"Ctrl-ArrowDown",run:js,shift:Uo},{key:"PageUp",run:$o,shift:qo},{key:"PageDown",run:js,shift:Uo},{key:"Home",run:op,shift:bp,preventDefault:!0},{key:"Mod-Home",run:Ko,shift:jo},{key:"End",run:rp,shift:yp,preventDefault:!0},{key:"Mod-End",run:Qo,shift:Yo},{key:"Enter",run:Go,shift:Go},{key:"Mod-a",run:Sp},{key:"Backspace",run:Ys,shift:Ys,preventDefault:!0},{key:"Delete",run:ya,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:xa,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:Pp,preventDefault:!0},{mac:"Mod-Backspace",run:Bp,preventDefault:!0},{mac:"Mod-Delete",run:Rp,preventDefault:!0}].concat(Up.map(s=>({mac:s.key,run:s.run,shift:s.shift}))),Qp=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:np,shift:gp},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:sp,shift:mp},{key:"Alt-ArrowUp",run:Ip},{key:"Shift-Alt-ArrowUp",run:Fp},{key:"Alt-ArrowDown",run:Np},{key:"Shift-Alt-ArrowDown",run:Vp},{key:"Mod-Alt-ArrowUp",run:Ap},{key:"Mod-Alt-ArrowDown",run:Mp},{key:"Escape",run:Tp},{key:"Mod-Enter",run:Wp},{key:"Alt-l",mac:"Ctrl-l",run:Cp},{key:"Mod-i",run:Op,preventDefault:!0},{key:"Mod-[",run:Ca},{key:"Mod-]",run:Sa},{key:"Mod-Alt-\\",run:$p},{key:"Shift-Mod-k",run:Hp},{key:"Shift-Mod-\\",run:up},{key:"Mod-/",run:Nd},{key:"Alt-A",run:Vd},{key:"Ctrl-m",mac:"Shift-Alt-m",run:qp}].concat(Kp),jp={key:"Tab",run:Sa,shift:Ca};function Yp({util:s,dataSource:t,getDataSourceCallback:e}){const i=n=>{const r=s.unNormalizePropertyNamesExpression(n.doc.toString());return typeof e!="function"?[]:n.selection.ranges.map(o=>({...s.getAutocompleteData(r,o.to),range:o})).filter(({dataSourceKey:o,itemsType:l})=>l==="datasource"&&o&&o in t).map(({range:o,dataSourceKey:l,dataSourceValue:h})=>({pos:o.head,above:!0,arrow:!1,create:()=>{const f=e(l,h),a=document.createElement("div");return f&&(f.$widget.appendTo(a),setTimeout(()=>{f.$widget.trigger("content:changed")})),a.className="cm-tooltip-control",{dom:a}}}))};return[ct.define({create:i,update(n,r){return!r.docChanged&&!r.selection?n:i(r.state)},provide:n=>qe.computeN([n],r=>r.field(n))})]}const Gp=Ph({Operator:C.operator,LiteralOperator:C.operator,GroupOperator:C.operator,Dot:C.punctuation,BracketOpen:C.bracket,BracketClose:C.bracket,"()":C.bracket,EntityName:C.variableName,PropertyName:C.propertyName,String:C.string,Number:C.integer,FunctionName:C.literal,Boolean:C.bool}),Xp=Vn.define([{tag:C.name,class:"cm-tag-name"},{tag:C.variableName,class:"cm-tag-name"},{tag:C.propertyName,class:"cm-tag-property-name"},{tag:C.literal,class:"cm-tag-literal"},{tag:C.string,class:"cm-tag-string"},{tag:C.integer,class:"cm-tag-number"},{tag:C.unit,class:"cm-tag-literal"},{tag:C.null,class:"cm-tag-literal"},{tag:C.keyword,class:"cm-tag-punctuation"},{tag:C.punctuation,class:"cm-tag-punctuation"},{tag:C.derefOperator,class:"cm-tag-punctuation"},{tag:C.bracket,class:"cm-tag-punctuation"},{tag:C.operator,class:"cm-tag-operator"},{tag:C.bool,class:"cm-tag-boolean"}],{all:{class:"cm-tag-common"}});var Xo={};class Cn{constructor(t,e,i,n,r,o,l,h,f,a=0,c){this.p=t,this.stack=e,this.state=i,this.reducePos=n,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=h,this.curContext=f,this.lookAhead=a,this.parent=c}toString(){return`[${this.stack.filter((t,e)=>e%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(t,e,i=0){let n=t.parser.context;return new Cn(t,[],e,i,i,0,[],0,n?new _o(n,n.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(t,e){this.stack.push(this.state,e,this.bufferBase+this.buffer.length),this.state=t}reduce(t){var e;let i=t>>19,n=t&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(n);if(l&&(this.score+=l),i==0){this.pushState(r.getGoto(this.state,n,!0),this.reducePos),n<r.minRepeatTerm&&this.storeNode(n,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(n,this.reducePos);return}let h=this.stack.length-(i-1)*3-(t&262144?6:0),f=h?this.stack[h-2]:this.p.ranges[0].from,a=this.reducePos-f;a>=2e3&&!(!((e=this.p.parser.nodeSet.types[n])===null||e===void 0)&&e.isAnonymous)&&(f==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=a):this.p.lastBigReductionSize<a&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=f,this.p.lastBigReductionSize=a));let c=h?this.stack[h-1]:0,u=this.bufferBase+this.buffer.length-c;if(n<r.minRepeatTerm||t&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(n,f,d,u+4,!0)}if(t&262144)this.state=this.stack[h];else{let d=this.stack[h-3];this.state=r.getGoto(d,n,!0)}for(;this.stack.length>h;)this.stack.pop();this.reduceContext(n,f)}storeNode(t,e,i,n=4,r=!1){if(t==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(e==i)return;if(o.buffer[l-2]>=e){o.buffer[l-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(t,e,i,n);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let h=o;h>0&&this.buffer[h-2]>i;h-=4)if(this.buffer[h-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,n>4&&(n-=4)}this.buffer[o]=t,this.buffer[o+1]=e,this.buffer[o+2]=i,this.buffer[o+3]=n}}shift(t,e,i,n){if(t&131072)this.pushState(t&65535,this.pos);else if((t&262144)==0){let r=t,{parser:o}=this.p;(n>this.pos||e<=o.maxNode)&&(this.pos=n,o.stateFlag(r,1)||(this.reducePos=n)),this.pushState(r,i),this.shiftContext(e,i),e<=o.maxNode&&this.buffer.push(e,i,n,4)}else this.pos=n,this.shiftContext(e,i),e<=this.p.parser.maxNode&&this.buffer.push(e,i,n,4)}apply(t,e,i,n){t&65536?this.reduce(t):this.shift(t,e,i,n)}useNode(t,e){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=t)&&(this.p.reused.push(t),i++);let n=this.pos;this.reducePos=this.pos=n+t.length,this.pushState(e,n),this.buffer.push(i,n,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,t,this,this.p.stream.reset(this.pos-t.length)))}split(){let t=this,e=t.buffer.length;for(;e>0&&t.buffer[e-2]>t.reducePos;)e-=4;let i=t.buffer.slice(e),n=t.bufferBase+e;for(;t&&n==t.bufferBase;)t=t.parent;return new Cn(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,n,this.curContext,this.lookAhead,t)}recoverByDelete(t,e){let i=t<=this.p.parser.maxNode;i&&this.storeNode(t,this.pos,e,4),this.storeNode(0,this.pos,e,i?8:4),this.pos=this.reducePos=e,this.score-=190}canShift(t){for(let e=new _p(this);;){let i=this.p.parser.stateSlot(e.state,4)||this.p.parser.hasAction(e.state,t);if(i==0)return!1;if((i&65536)==0)return!0;e.reduce(i)}}recoverByInsert(t){if(this.stack.length>=300)return[];let e=this.p.parser.nextStates(this.state);if(e.length>8||this.stack.length>=120){let n=[];for(let r=0,o;r<e.length;r+=2)(o=e[r+1])!=this.state&&this.p.parser.hasAction(o,t)&&n.push(e[r],o);if(this.stack.length<120)for(let r=0;n.length<8&&r<e.length;r+=2){let o=e[r+1];n.some((l,h)=>h&1&&l==o)||n.push(e[r],o)}e=n}let i=[];for(let n=0;n<e.length&&i.length<4;n+=2){let r=e[n+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(e[n],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:t}=this.p,e=t.stateSlot(this.state,5);if((e&65536)==0)return!1;if(!t.validAction(this.state,e)){let i=e>>19,n=e&65535,r=this.stack.length-i*3;if(r<0||t.getGoto(this.stack[r],n,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;e=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(e),!0}findForcedReduction(){let{parser:t}=this.p,e=[],i=(n,r)=>{if(!e.includes(n))return e.push(n),t.allActions(n,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let h=o&65535,f=this.stack.length-l*3;if(f>=0&&t.getGoto(this.stack[f],h,!1)>=0)return l<<19|65536|h}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:t}=this.p;return t.data[t.stateSlot(this.state,1)]==65535&&!t.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(t){if(this.state!=t.state||this.stack.length!=t.stack.length)return!1;for(let e=0;e<this.stack.length;e+=3)if(this.stack[e]!=t.stack[e])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(t){return this.p.parser.dialect.flags[t]}shiftContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,t,this,this.p.stream.reset(e)))}reduceContext(t,e){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,t,this,this.p.stream.reset(e)))}emitContext(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let t=this.buffer.length-1;(t<0||this.buffer[t]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(t){if(t!=this.curContext.context){let e=new _o(this.curContext.tracker,t);e.hash!=this.curContext.hash&&this.emitContext(),this.curContext=e}}setLookAhead(t){return t<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=t,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class _o{constructor(t,e){this.tracker=t,this.context=e,this.hash=t.strict?t.hash(e):0}}class _p{constructor(t){this.start=t,this.state=t.state,this.stack=t.stack,this.base=this.stack.length}reduce(t){let e=t&65535,i=t>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let n=this.start.p.parser.getGoto(this.stack[this.base-3],e,!0);this.state=n}}class On{constructor(t,e,i){this.stack=t,this.pos=e,this.index=i,this.buffer=t.buffer,this.index==0&&this.maybeNext()}static create(t,e=t.bufferBase+t.buffer.length){return new On(t,e,e-t.bufferBase)}maybeNext(){let t=this.stack.parent;t!=null&&(this.index=this.stack.bufferBase-t.bufferBase,this.stack=t,this.buffer=t.buffer)}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]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new On(this.stack,this.pos,this.index)}}function Gi(s,t=Uint16Array){if(typeof s!="string")return s;let e=null;for(let i=0,n=0;i<s.length;){let r=0;for(;;){let o=s.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let h=o-32;if(h>=46&&(h-=46,l=!0),r+=h,l)break;r*=46}e?e[n++]=r:e=new t(r)}return e}class rn{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const Jo=new rn;class Jp{constructor(t,e){this.input=t,this.ranges=e,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=Jo,this.rangeIndex=0,this.pos=this.chunkPos=e[0].from,this.range=e[0],this.end=e[e.length-1].to,this.readNext()}resolveOffset(t,e){let i=this.range,n=this.rangeIndex,r=this.pos+t;for(;r<i.from;){if(!n)return null;let o=this.ranges[--n];r-=i.from-o.to,i=o}for(;e<0?r>i.to:r>=i.to;){if(n==this.ranges.length-1)return null;let o=this.ranges[++n];r+=o.from-i.to,i=o}return r}clipPos(t){if(t>=this.range.from&&t<this.range.to)return t;for(let e of this.ranges)if(e.to>t)return Math.max(t,e.from);return this.end}peek(t){let e=this.chunkOff+t,i,n;if(e>=0&&e<this.chunk.length)i=this.pos+t,n=this.chunk.charCodeAt(e);else{let r=this.resolveOffset(t,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)n=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),n=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),n}acceptToken(t,e=0){let i=e?this.resolveOffset(e,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=t,this.token.end=i}acceptTokenTo(t,e){this.token.value=t,this.token.end=e}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:t,chunkPos:e}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=t,this.chunk2Pos=e,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let t=this.input.chunk(this.pos),e=this.pos+t.length;this.chunk=e>this.range.to?t.slice(0,this.range.to-this.pos):t,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(t=1){for(this.chunkOff+=t;this.pos+t>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();t-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=t,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(t,e){if(e?(this.token=e,e.start=t,e.lookAhead=t+1,e.value=e.extended=-1):this.token=Jo,this.pos!=t){if(this.pos=t,t==this.end)return this.setDone(),this;for(;t<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;t>=this.range.to;)this.range=this.ranges[++this.rangeIndex];t>=this.chunkPos&&t<this.chunkPos+this.chunk.length?this.chunkOff=t-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(t,e){if(t>=this.chunkPos&&e<=this.chunkPos+this.chunk.length)return this.chunk.slice(t-this.chunkPos,e-this.chunkPos);if(t>=this.chunk2Pos&&e<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(t-this.chunk2Pos,e-this.chunk2Pos);if(t>=this.range.from&&e<=this.range.to)return this.input.read(t,e);let i="";for(let n of this.ranges){if(n.from>=e)break;n.to>t&&(i+=this.input.read(Math.max(n.from,t),Math.min(n.to,e)))}return i}}class Fe{constructor(t,e){this.data=t,this.id=e}token(t,e){let{parser:i}=e.p;Zp(this.data,t,e,this.id,i.data,i.tokenPrecTable)}}Fe.prototype.contextual=Fe.prototype.fallback=Fe.prototype.extend=!1;Fe.prototype.fallback=Fe.prototype.extend=!1;function Zp(s,t,e,i,n,r){let o=0,l=1<<i,{dialect:h}=e.p.parser;t:for(;(l&s[o])!=0;){let f=s[o+1];for(let d=o+3;d<f;d+=2)if((s[d+1]&l)>0){let p=s[d];if(h.allows(p)&&(t.token.value==-1||t.token.value==p||tg(p,t.token.value,n,r))){t.acceptToken(p);break}}let a=t.next,c=0,u=s[o+2];if(t.next<0&&u>c&&s[f+u*3-3]==65535){o=s[f+u*3-1];continue t}for(;c<u;){let d=c+u>>1,p=f+d+(d<<1),g=s[p],m=s[p+1]||65536;if(a<g)u=d;else if(a>=m)c=d+1;else{o=s[p+2],t.advance();continue t}}break}}function Zo(s,t,e){for(let i=t,n;(n=s[i])!=65535;i++)if(n==e)return i-t;return-1}function tg(s,t,e,i){let n=Zo(e,i,t);return n<0||Zo(e,i,s)<n}const mt=typeof process<"u"&&Xo&&/\bparse\b/.test(Xo.LOG);let os=null;function tl(s,t,e){let i=s.cursor(J.IncludeAnonymous);for(i.moveTo(t);;)if(!(e<0?i.childBefore(t):i.childAfter(t)))for(;;){if((e<0?i.to<t:i.from>t)&&!i.type.isError)return e<0?Math.max(0,Math.min(i.to-1,t-25)):Math.min(s.length,Math.max(i.from+1,t+25));if(e<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return e<0?0:s.length}}class eg{constructor(t,e){this.fragments=t,this.nodeSet=e,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let t=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(t){for(this.safeFrom=t.openStart?tl(t.tree,t.from+t.offset,1)-t.offset:t.from,this.safeTo=t.openEnd?tl(t.tree,t.to+t.offset,-1)-t.offset:t.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(t.tree),this.start.push(-t.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(t){if(t<this.nextStart)return null;for(;this.fragment&&this.safeTo<=t;)this.nextFragment();if(!this.fragment)return null;for(;;){let e=this.trees.length-1;if(e<0)return this.nextFragment(),null;let i=this.trees[e],n=this.index[e];if(n==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[n],o=this.start[e]+i.positions[n];if(o>t)return this.nextStart=o,null;if(r instanceof X){if(o==t){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let h=r.prop(B.lookAhead);if(!h||l+h<this.fragment.to)return r}}this.index[e]++,o+r.length>=Math.max(this.safeFrom,t)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[e]++,this.nextStart=o+r.length}}}class ig{constructor(t,e){this.stream=e,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=t.tokenizers.map(i=>new rn)}getActions(t){let e=0,i=null,{parser:n}=t.p,{tokenizers:r}=n,o=n.stateSlot(t.state,3),l=t.curContext?t.curContext.hash:0,h=0;for(let f=0;f<r.length;f++){if((1<<f&o)==0)continue;let a=r[f],c=this.tokens[f];if(!(i&&!a.fallback)&&((a.contextual||c.start!=t.pos||c.mask!=o||c.context!=l)&&(this.updateCachedToken(c,a,t),c.mask=o,c.context=l),c.lookAhead>c.end+25&&(h=Math.max(c.lookAhead,h)),c.value!=0)){let u=e;if(c.extended>-1&&(e=this.addActions(t,c.extended,c.end,e)),e=this.addActions(t,c.value,c.end,e),!a.extend&&(i=c,e>u))break}}for(;this.actions.length>e;)this.actions.pop();return h&&t.setLookAhead(h),!i&&t.pos==this.stream.end&&(i=new rn,i.value=t.p.parser.eofTerm,i.start=i.end=t.pos,e=this.addActions(t,i.value,i.end,e)),this.mainToken=i,this.actions}getMainToken(t){if(this.mainToken)return this.mainToken;let e=new rn,{pos:i,p:n}=t;return e.start=i,e.end=Math.min(i+1,n.stream.end),e.value=i==n.stream.end?n.parser.eofTerm:0,e}updateCachedToken(t,e,i){let n=this.stream.clipPos(i.pos);if(e.token(this.stream.reset(n,t),i),t.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==t.value){let l=r.specializers[o](this.stream.read(t.start,t.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?t.value=l>>1:t.extended=l>>1;break}}}else t.value=0,t.end=this.stream.clipPos(n+1)}putAction(t,e,i,n){for(let r=0;r<n;r+=3)if(this.actions[r]==t)return n;return this.actions[n++]=t,this.actions[n++]=e,this.actions[n++]=i,n}addActions(t,e,i,n){let{state:r}=t,{parser:o}=t.p,{data:l}=o;for(let h=0;h<2;h++)for(let f=o.stateSlot(r,h?2:1);;f+=3){if(l[f]==65535)if(l[f+1]==1)f=Xt(l,f+2);else{n==0&&l[f+1]==2&&(n=this.putAction(Xt(l,f+2),e,i,n));break}l[f]==e&&(n=this.putAction(Xt(l,f+1),e,i,n))}return n}}class ng{constructor(t,e,i,n){this.parser=t,this.input=e,this.ranges=n,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new Jp(e,n),this.tokens=new ig(t,this.stream),this.topTerm=t.top[1];let{from:r}=n[0];this.stacks=[Cn.start(this,t.top[0],r)],this.fragments=i.length&&this.stream.end-r>t.bufferLength*4?new eg(i,t.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let t=this.stacks,e=this.minStackPos,i=this.stacks=[],n,r;if(this.bigReductionCount>300&&t.length==1){let[o]=t;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<t.length;o++){let l=t[o];for(;;){if(this.tokens.mainToken=null,l.pos>e)i.push(l);else{if(this.advanceStack(l,i,t))continue;{n||(n=[],r=[]),n.push(l);let h=this.tokens.getMainToken(l);r.push(h.value,h.end)}}break}}if(!i.length){let o=n&&rg(n);if(o)return mt&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw mt&&n&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+e);this.recovering||(this.recovering=5)}if(this.recovering&&n){let o=this.stoppedAt!=null&&n[0].pos>this.stoppedAt?n[0]:this.runRecovery(n,r,i);if(o)return mt&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,h)=>h.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>e)&&this.recovering--}else if(i.length>1){t:for(let o=0;o<i.length-1;o++){let l=i[o];for(let h=o+1;h<i.length;h++){let f=i[h];if(l.sameState(f)||l.buffer.length>500&&f.buffer.length>500)if((l.score-f.score||l.buffer.length-f.buffer.length)>0)i.splice(h--,1);else{i.splice(o--,1);continue t}}}i.length>12&&i.splice(12,i.length-12)}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(t){if(this.stoppedAt!=null&&this.stoppedAt<t)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=t}advanceStack(t,e,i){let n=t.pos,{parser:r}=this,o=mt?this.stackID(t)+" -> ":"";if(this.stoppedAt!=null&&n>this.stoppedAt)return t.forceReduce()?t:null;if(this.fragments){let f=t.curContext&&t.curContext.tracker.strict,a=f?t.curContext.hash:0;for(let c=this.fragments.nodeAt(n);c;){let u=this.parser.nodeSet.types[c.type.id]==c.type?r.getGoto(t.state,c.type.id):-1;if(u>-1&&c.length&&(!f||(c.prop(B.contextHash)||0)==a))return t.useNode(c,u),mt&&console.log(o+this.stackID(t)+` (via reuse of ${r.getName(c.type.id)})`),!0;if(!(c instanceof X)||c.children.length==0||c.positions[0]>0)break;let d=c.children[0];if(d instanceof X&&c.positions[0]==0)c=d;else break}}let l=r.stateSlot(t.state,4);if(l>0)return t.reduce(l),mt&&console.log(o+this.stackID(t)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(t.stack.length>=8400)for(;t.stack.length>6e3&&t.forceReduce(););let h=this.tokens.getActions(t);for(let f=0;f<h.length;){let a=h[f++],c=h[f++],u=h[f++],d=f==h.length||!i,p=d?t:t.split(),g=this.tokens.mainToken;if(p.apply(a,c,g?g.start:p.pos,u),mt&&console.log(o+this.stackID(p)+` (via ${(a&65536)==0?"shift":`reduce of ${r.getName(a&65535)}`} for ${r.getName(c)} @ ${n}${p==t?"":", split"})`),d)return!0;p.pos>n?e.push(p):i.push(p)}return!1}advanceFully(t,e){let i=t.pos;for(;;){if(!this.advanceStack(t,null,null))return!1;if(t.pos>i)return el(t,e),!0}}runRecovery(t,e,i){let n=null,r=!1;for(let o=0;o<t.length;o++){let l=t[o],h=e[o<<1],f=e[(o<<1)+1],a=mt?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),mt&&console.log(a+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let c=l.split(),u=a;for(let d=0;d<10&&c.forceReduce()&&(mt&&console.log(u+this.stackID(c)+" (via force-reduce)"),!this.advanceFully(c,i));d++)mt&&(u=this.stackID(c)+" -> ");for(let d of l.recoverByInsert(h))mt&&console.log(a+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(f==l.pos&&(f++,h=0),l.recoverByDelete(h,f),mt&&console.log(a+this.stackID(l)+` (via recover-delete ${this.parser.getName(h)})`),el(l,i)):(!n||n.score<l.score)&&(n=l)}return n}stackToTree(t){return t.close(),X.build({buffer:On.create(t),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:t.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(t){let e=(os||(os=new WeakMap)).get(t);return e||os.set(t,e=String.fromCodePoint(this.nextStackID++)),e+t}}function el(s,t){for(let e=0;e<t.length;e++){let i=t[e];if(i.pos==s.pos&&i.sameState(s)){t[e].score<s.score&&(t[e]=s);return}}t.push(s)}class sg{constructor(t,e,i){this.source=t,this.flags=e,this.disabled=i}allows(t){return!this.disabled||this.disabled[t]==0}}class An extends Th{constructor(t){if(super(),this.wrappers=[],t.version!=14)throw new RangeError(`Parser version (${t.version}) doesn't match runtime version (14)`);let e=t.nodeNames.split(" ");this.minRepeatTerm=e.length;for(let l=0;l<t.repeatNodeCount;l++)e.push("");let i=Object.keys(t.topRules).map(l=>t.topRules[l][1]),n=[];for(let l=0;l<e.length;l++)n.push([]);function r(l,h,f){n[l].push([h,h.deserialize(String(f))])}if(t.nodeProps)for(let l of t.nodeProps){let h=l[0];typeof h=="string"&&(h=B[h]);for(let f=1;f<l.length;){let a=l[f++];if(a>=0)r(a,h,l[f++]);else{let c=l[f+-a];for(let u=-a;u>0;u--)r(l[f++],h,c);f++}}}this.nodeSet=new hr(e.map((l,h)=>pt.define({name:h>=this.minRepeatTerm?void 0:l,id:h,props:n[h],top:i.indexOf(h)>-1,error:h==0,skipped:t.skippedNodes&&t.skippedNodes.indexOf(h)>-1}))),t.propSources&&(this.nodeSet=this.nodeSet.extend(...t.propSources)),this.strict=!1,this.bufferLength=Ch;let o=Gi(t.tokenData);this.context=t.context,this.specializerSpecs=t.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(il),this.states=Gi(t.states,Uint32Array),this.data=Gi(t.stateData),this.goto=Gi(t.goto),this.maxTerm=t.maxTerm,this.tokenizers=t.tokenizers.map(l=>typeof l=="number"?new Fe(o,l):l),this.topRules=t.topRules,this.dialects=t.dialects||{},this.dynamicPrecedences=t.dynamicPrecedences||null,this.tokenPrecTable=t.tokenPrec,this.termNames=t.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(t,e,i){let n=new ng(this,t,e,i);for(let r of this.wrappers)n=r(n,t,e,i);return n}getGoto(t,e,i=!1){let n=this.goto;if(e>=n[0])return-1;for(let r=n[e+1];;){let o=n[r++],l=o&1,h=n[r++];if(l&&i)return h;for(let f=r+(o>>1);r<f;r++)if(n[r]==t)return h;if(l)return-1}}hasAction(t,e){let i=this.data;for(let n=0;n<2;n++)for(let r=this.stateSlot(t,n?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=Xt(i,r+2)];else{if(i[r+1]==2)return Xt(i,r+2);break}if(o==e||o==0)return Xt(i,r+1)}return 0}stateSlot(t,e){return this.states[t*6+e]}stateFlag(t,e){return(this.stateSlot(t,0)&e)>0}validAction(t,e){return!!this.allActions(t,i=>i==e?!0:null)}allActions(t,e){let i=this.stateSlot(t,4),n=i?e(i):void 0;for(let r=this.stateSlot(t,1);n==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=Xt(this.data,r+2);else break;n=e(Xt(this.data,r+1))}return n}nextStates(t){let e=[];for(let i=this.stateSlot(t,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=Xt(this.data,i+2);else break;if((this.data[i+2]&1)==0){let n=this.data[i+1];e.some((r,o)=>o&1&&r==n)||e.push(this.data[i],n)}}return e}configure(t){let e=Object.assign(Object.create(An.prototype),this);if(t.props&&(e.nodeSet=this.nodeSet.extend(...t.props)),t.top){let i=this.topRules[t.top];if(!i)throw new RangeError(`Invalid top rule name ${t.top}`);e.top=i}return t.tokenizers&&(e.tokenizers=this.tokenizers.map(i=>{let n=t.tokenizers.find(r=>r.from==i);return n?n.to:i})),t.specializers&&(e.specializers=this.specializers.slice(),e.specializerSpecs=this.specializerSpecs.map((i,n)=>{let r=t.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return e.specializers[n]=il(o),o})),t.contextTracker&&(e.context=t.contextTracker),t.dialect&&(e.dialect=this.parseDialect(t.dialect)),t.strict!=null&&(e.strict=t.strict),t.wrap&&(e.wrappers=e.wrappers.concat(t.wrap)),t.bufferLength!=null&&(e.bufferLength=t.bufferLength),e}hasWrappers(){return this.wrappers.length>0}getName(t){return this.termNames?this.termNames[t]:String(t<=this.maxNode&&this.nodeSet.types[t].name||t)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(t){let e=this.dynamicPrecedences;return e==null?0:e[t]||0}parseDialect(t){let e=Object.keys(this.dialects),i=e.map(()=>!1);if(t)for(let r of t.split(" ")){let o=e.indexOf(r);o>=0&&(i[o]=!0)}let n=null;for(let r=0;r<e.length;r++)if(!i[r])for(let o=this.dialects[e[r]],l;(l=this.data[o++])!=65535;)(n||(n=new Uint8Array(this.maxTerm+1)))[l]=1;return new sg(t,i,n)}static deserialize(t){return new An(t)}}function Xt(s,t){return s[t]|s[t+1]<<16}function rg(s){let t=null;for(let e of s){let i=e.p.stoppedAt;(e.pos==e.p.stream.end||i!=null&&e.pos>i)&&e.p.parser.stateFlag(e.state,2)&&(!t||t.score<e.score)&&(t=e)}return t}function il(s){if(s.external){let t=s.extend?1:0;return(e,i)=>s.external(e,i)<<1|t}return s.get}const og={__proto__:null,true:40,false:42,in:48,not:50,matches:52,or:56,and:58},lg=An.deserialize({version:14,states:"(WQYQPOOOOQO'#C_'#C_O!uQPO'#CdO!|QPO'#CaO#[QPO'#C`O#aQPO'#CiOOQO'#DY'#DYOOQO'#Da'#DaOOQO'#C^'#C^O#iQPO'#CzO#pQPO'#C}OOQO'#DX'#DXOOQO'#DO'#DOQYQPOOOOQO'#Cs'#CsOOQO'#Cw'#CwOOQO'#Ce'#CeOOQO'#DP'#DPO#wQPO'#D]O$gQPO'#DQO$qQPO'#D]O$yQPO,59OOOQO,58{,58{O%OQQO'#DRO%TQPO,58zO&hQSO,59TOOQO,59T,59TOOQO,59f,59fO&rQPO,59fOOQO,59i,59iO&yQPO,59iOOQO-E6|-E6|OOQO-E6}-E6}O'QQPO,59wO'YQPO,59lOOQO-E7O-E7OOOQO1G.j1G.jOOQO'#Ch'#ChOOQO,59m,59mOOQO-E7P-E7PO'dQPO'#D_O$OQPO'#D_OOQO'#Cl'#ClO'lQPO1G.oOOQO1G/Q1G/QOOQO1G/T1G/TO'qQSO'#DSO(OQPO,59yO(OQPO,59yOOQO7+$Z7+$ZOOQO,59n,59nO$OQPO,59nOOQO-E7Q-E7QO(WQPO1G/eOOQO1G/Y1G/Y",stateData:"(`~OyOSzOS~OVQO_XObUOcUOdUOeUOfVOh^Oi^Oj^Ol_Om_OpYO}PO!ORO~OVQOYcObUOcUOdUOeUO}PO!ORO~OU!PP~P!ZOVQOZTX_^X}^X~OZgO~O_iO}PO~OakO~PYOomO~PYOU!PX~P!ZOVQObUOcUOdUOeUO}PO!ORO~OUtXYtX~P$OOYcOU!PX~OUtO~O!QuO~OZgOVSa_SabSacSadSaeSafSahSaiSajSalSamSapSawSa}Sa!OSaUSaYSaaSaoSa~O!SyOa!RP~P$OOa|O~PYOo}O~PYOYcOU!Pa~OUtaYta~P$OOY!OOa!RX~Oa!RO~O!S!TOYvXavX~P$OOY!OOa!Ra~OY!OOa!Ri~O",goto:"&s!UPP!V!_!r#SPP#d#wPP#}!r$QP$bPPPPPP$ePPP!VPP!VPP!V$m${%V%a%gPPPP%q%yPP&eP&hP&k]ZOXY]lnlUOQXY]bcilnry!O!TRjTmUOQXY]bcilnry!O!TmSOQXY]bcilnry!O!TlUOQXY]bcilnry!O!TRfRXaQbcrRvgmTOQXY]bcilnry!O!TR{i]VOXY]lnQ]OQlXQnYVo]lnQbQSpbrRrcQdQQqbTsdqQhSRwhQ!PxS!U!P!VR!V!Q][OXY]ln[WOXY]lnW`QbcrQxiQ!QyQ!S!OR!W!TReQRzi]WOXY]ln",nodeNames:"⚠ SymfonyExpression GroupNode EmptyBrackets Entity EntityName SquareBracketClose SquareBracketOpen Array ArrayItem Comma Dot PropertyName Function FunctionName BracketOpen ArgList BracketClose String Number Boolean Boolean Operator LiteralOperator LiteralOperator LiteralOperator LiteralOperator GroupNode GroupOperator GroupOperator BracketGroup BraceClose BraceOpen BracesGroup",maxTerm:51,nodeProps:[["openedBy",6,"SquareBracketOpen",17,"BracketOpen",31,"BraceOpen"],["closedBy",7,"SquareBracketClose",15,"BracketClose",32,"BraceClose"]],skippedNodes:[0],repeatNodeCount:5,tokenData:"*o~RwXY#lYZ$aZ[#l]^$apq#lqr$frs$quv$lwx&ixy([yz(iz{$l{|$l|}(n}!O$l!O!P(s!P!Q$l!Q![)W![!])`!^!_)y!_!`*R!`!a)y!c!})`!}#O*Z#O#P)`#P#Q*`#R#S)`#T#o)`#o#p*e#q#r*j$f$g#l#BY#BZ#l$IS$I_#l$I|$I}$a$I}$JO$a$JT$JU#l$KV$KW#l&FU&FV#l?HT?HU#l~#qYy~XY#lZ[#lpq#l$f$g#l#BY#BZ#l$IS$I_#l$JT$JU#l$KV$KW#l&FU&FV#l?HT?HU#l~$fOz~~$iP!_!`$l~$qOf~~$vWb~OY$qZr$qrs%`s#O$q#O#P%e#P;'S$q;'S;=`&c<%lO$q~%eOb~~%hRO;'S$q;'S;=`%q;=`O$q~%vXb~OY$qZr$qrs%`s#O$q#O#P%e#P;'S$q;'S;=`&c;=`<%l$q<%lO$q~&fP;=`<%l$q~&nWb~OY&iZw&iwx%`x#O&i#O#P'W#P;'S&i;'S;=`(U<%lO&i~'ZRO;'S&i;'S;=`'d;=`O&i~'iXb~OY&iZw&iwx%`x#O&i#O#P'W#P;'S&i;'S;=`(U;=`<%l&i<%lO&i~(XP;=`<%l&i~(aP_~yz(d~(iO}~~(nOa~~(sOY~T(xPZP!O!P({S)OP!O!P)RS)WO!SS~)]Pc~!Q![)WV)gU!OT!QQ!Q![)`![!])`!c!})`#O#P)`#R#S)`#T#o)`~*OPf~!_!`$l~*WPf~!_!`)y~*`OV~~*eOU~~*jOp~~*oOo~",tokenizers:[0,1,2],topRules:{SymfonyExpression:[0,1]},specialized:[{term:46,get:s=>og[s]||-1}],tokenPrec:0}),hg={"=":"= #{1}","==":"== #{1}","!=":"!= #{1}",">=":">= #{1}",">":"> #{1}","<=":"<= #{1}","<":"< #{1}","*":"* #{1}","/":"/ #{1}","%":"% #{1}","+":"+ #{1}","-":"- #{1}",and:"and #{1}",or:"or #{1}",in:"in [#{1}]","not in":"not in [#{1}]",matches:"matches containsRegExp(#{1})","does not match":"not matches containsRegExp(#{1})","()":"(#{1})","is empty":"#{1} == 0","is not empty":"#{1} != 0",between:"#{1} >= #{2} and #{3} <= #{4}","not between":"#{1} < #{2} and #{3} > #{4}",yes:"#{1} == true",no:"#{1} == false"},ag=(s,t=!1,e={})=>{let i=hg[s.trim()];return i||(i=s,e.isCollection&&(i+="[#{1}]"),e.hasChildren!==void 0&&(i+=e.hasChildren?".":" "),i+=i.includes("#{1}")?"#{2}":"#{1}"),t&&(i=` ${i}`),md(i)},fg=({items:s},t={})=>Object.entries(s).sort().map(([e,{hasChildren:i,normalizedName:n,isCollection:r}])=>{const o=n||e;return{label:o+(i?"…":""),apply:ag(o,!1,{hasChildren:i,isCollection:r}),detail:t.operatorsDetailMap[e]}}),cg=(s,t={},e)=>{const i=gt(e.state).resolveInner(e.pos,-1),n=fg(s.getAutocompleteData(e.state.doc.lineAt(e.pos).text,e.pos),t),{text:r}=e.matchBefore(/\s*/),o=i.from<e.pos&&i.to>e.pos,l=i.name==="Dot"||r===" "?e.pos:i.from;if(n.length)return{from:l,to:o?i.to:null,options:n}},ug=lg.configure({props:[Gp]}),Oa=mn.define({name:"symfony-expression-lang",parser:ug}),dg=(s,t={})=>Oa.data.of({autocomplete:cg.bind(null,s,t)});function pg(s,t={operatorsDetailMap:[]}){return new du(Oa,[dg(s,t)])}const gg=P.define(),mg=gg.compute([qe],s=>{const t=s.facet(qe).filter(e=>e)||[];return t.forEach(e=>e.arrow=!1),t}),yg=({util:s,interactionDelay:t=75,maxRenderedOptions:e=20,dataSource:i={},getDataSourceCallback:n,operatorsDetailMap:r={}})=>[pg(s,{operatorsDetailMap:r}),Ln.of([jp,Qp,{key:"Alt-ArrowDown",run:Ne}]),Ed({icons:!1,interactionDelay:t,maxRenderedOptions:e,compareCompletions(o,l){return o-l}}),T.lineWrapping,T.editorAttributes.of({class:"expression-editor"}),Cu(Xp),T.updateListener.of(o=>{[2,4,6].includes(o.flags)&&setTimeout(()=>Ne(o.view))}),T.domEventHandlers({focusin(o,l){setTimeout(()=>Ne(l))}}),Fc({position:"fixed",parent:document.body}),Sd(),Eu(),Kd(),mg,Yp({util:s,dataSource:i,getDataSourceCallback:n})];function $t(){var s=arguments[0];typeof s=="string"&&(s=document.createElement(s));var t=1,e=arguments[1];if(e&&typeof e=="object"&&e.nodeType==null&&!Array.isArray(e)){for(var i in e)if(Object.prototype.hasOwnProperty.call(e,i)){var n=e[i];typeof n=="string"?s.setAttribute(i,n):n!=null&&(s[i]=n)}t++}for(;t<arguments.length;t++)Aa(s,arguments[t]);return s}function Aa(s,t){if(typeof t=="string")s.appendChild(document.createTextNode(t));else if(t!=null)if(t.nodeType!=null)s.appendChild(t);else if(Array.isArray(t))for(var e=0;e<t.length;e++)Aa(s,t[e]);else throw new RangeError("Unsupported child node: "+t)}class nl{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class xe{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let n=i.facet(Kt).markerFilter;n&&(t=n(t,i));let r=t.slice().sort((d,p)=>d.from-p.from||d.to-p.to),o=new He,l=[],h=0,f=i.doc.iter(),a=0,c=i.doc.length;for(let d=0;;){let p=d==r.length?null:r[d];if(!p&&!l.length)break;let g,m;if(l.length)g=h,m=l.reduce((b,k)=>Math.min(b,k.to),p&&p.from>g?p.from:1e8);else{if(g=p.from,g>c)break;m=p.to,l.push(p),d++}for(;d<r.length;){let b=r[d];if(b.from==g&&(b.to>b.from||b.to==g))l.push(b),d++,m=Math.min(b.to,m);else{m=Math.min(b.from,m);break}}m=Math.min(m,c);let y=!1;if(l.some(b=>b.from==g&&(b.to==m||m==c))&&(y=g==m,!y&&m-g<10)){let b=g-(a+f.value.length);b>0&&(f.next(b),a=g);for(let k=g;;){if(k>=m){y=!0;break}if(!f.lineBreak&&a+f.value.length>k)break;k=a+f.value.length,a+=f.value.length,f.next()}}let x=Dg(l);if(y)o.add(g,g,N.widget({widget:new Ag(x),diagnostics:l.slice()}));else{let b=l.reduce((k,v)=>v.markClass?k+" "+v.markClass:k,"");o.add(g,m,N.mark({class:"cm-lintRange cm-lintRange-"+x+b,diagnostics:l.slice(),inclusiveEnd:l.some(k=>k.to>m)}))}if(h=m,h==c)break;for(let b=0;b<l.length;b++)l[b].to<=h&&l.splice(b--,1)}let u=o.finish();return new xe(u,e,je(u))}}function je(s,t=null,e=0){let i=null;return s.between(e,1e9,(n,r,{spec:o})=>{if(!(t&&o.diagnostics.indexOf(t)<0))if(!i)i=new nl(n,r,t||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new nl(i.from,r,i.diagnostic)}}),i}function bg(s,t){let e=t.pos,i=t.end||e,n=s.state.facet(Kt).hideOn(s,e,i);if(n!=null)return n;let r=s.startState.doc.lineAt(t.pos);return!!(s.effects.some(o=>o.is(Cr))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function xg(s,t){return s.field(bt,!1)?t:t.concat(R.appendConfig.of(Ba))}function wg(s,t){return{effects:xg(s,[Cr.of(t)])}}const Cr=R.define(),Ma=R.define(),Ta=R.define(),bt=ct.define({create(){return new xe(N.none,null,null)},update(s,t){if(t.docChanged&&s.diagnostics.size){let e=s.diagnostics.map(t.changes),i=null,n=s.panel;if(s.selected){let r=t.changes.mapPos(s.selected.from,1);i=je(e,s.selected.diagnostic,r)||je(e,null,r)}!e.size&&n&&t.state.facet(Kt).autoPanel&&(n=null),s=new xe(e,n,i)}for(let e of t.effects)if(e.is(Cr)){let i=t.state.facet(Kt).autoPanel?e.value.length?Mn.open:null:s.panel;s=xe.init(e.value,i,t.state)}else e.is(Ma)?s=new xe(s.diagnostics,e.value?Mn.open:null,s.selected):e.is(Ta)&&(s=new xe(s.diagnostics,s.panel,e.value));return s},provide:s=>[Hs.from(s,t=>t.panel),T.decorations.from(s,t=>t.diagnostics)]});function Ig(s){let t=s.field(bt,!1);return t?t.diagnostics.size:0}const kg=N.mark({class:"cm-lintRange cm-lintRange-active"});function vg(s,t,e){let{diagnostics:i}=s.state.field(bt),n,r=-1,o=-1;i.between(t-(e<0?1:0),t+(e>0?1:0),(h,f,{spec:a})=>{if(t>=h&&t<=f&&(h==f||(t>h||e>0)&&(t<f||e<0)))return n=a.diagnostics,r=h,o=f,!1});let l=s.state.facet(Kt).tooltipFilter;return n&&l&&(n=l(n,s.state)),n?{pos:r,end:o,above:s.state.doc.lineAt(r).to<o,create(){return{dom:Sg(s,n)}}}:null}function Sg(s,t){return $t("ul",{class:"cm-tooltip-lint"},t.map(e=>Da(s,e,!1)))}const sl=s=>{let t=s.state.field(bt,!1);return!t||!t.panel?!1:(s.dispatch({effects:Ma.of(!1)}),!0)},Cg=At.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:t}=s.state.facet(Kt);this.lintTime=Date.now()+t,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:t}=this.view,{sources:e}=t.facet(Kt);e.length&&Og(e.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==t.doc&&this.view.dispatch(wg(this.view.state,i.reduce((n,r)=>n.concat(r))))},i=>{at(this.view.state,i)})}}update(s){let t=s.state.facet(Kt);(s.docChanged||t!=s.startState.facet(Kt)||t.needsRefresh&&t.needsRefresh(s))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function Og(s,t,e){let i=[],n=-1;for(let r of s)r.then(o=>{i.push(o),clearTimeout(n),i.length==s.length?t(i):n=setTimeout(()=>t(i),200)},e)}const Kt=P.define({combine(s){return{sources:s.map(t=>t.source).filter(t=>t!=null),...Pn(s.map(t=>t.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:rl,tooltipFilter:rl,needsRefresh:(t,e)=>t?e?i=>t(i)||e(i):t:e,hideOn:(t,e)=>t?e?(i,n,r)=>t(i,n,r)||e(i,n,r):t:e,autoPanel:(t,e)=>t||e})}}});function rl(s,t){return s?t?(e,i)=>t(s(e,i),i):s:t}function Ng(s,t={}){return[Kt.of({source:s,config:t}),Cg,Ba]}function Pa(s){let t=[];if(s)t:for(let{name:e}of s){for(let i=0;i<e.length;i++){let n=e[i];if(/[a-zA-Z]/.test(n)&&!t.some(r=>r.toLowerCase()==n.toLowerCase())){t.push(n);continue t}}t.push("")}return t}function Da(s,t,e){var i;let n=e?Pa(t.actions):[];return $t("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},$t("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(s):t.message),(i=t.actions)===null||i===void 0?void 0:i.map((r,o)=>{let l=!1,h=d=>{if(d.preventDefault(),l)return;l=!0;let p=je(s.state.field(bt).diagnostics,t);p&&r.apply(s,p.from,p.to)},{name:f}=r,a=n[o]?f.indexOf(n[o]):-1,c=a<0?f:[f.slice(0,a),$t("u",f.slice(a,a+1)),f.slice(a+1)],u=r.markClass?" "+r.markClass:"";return $t("button",{type:"button",class:"cm-diagnosticAction"+u,onclick:h,onmousedown:h,"aria-label":` Action: ${f}${a<0?"":` (access key "${n[o]})"`}.`},c)}),t.source&&$t("div",{class:"cm-diagnosticSource"},t.source))}class Ag extends vi{constructor(t){super(),this.sev=t}eq(t){return t.sev==this.sev}toDOM(){return $t("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ol{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=Da(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Mn{constructor(t){this.view=t,this.items=[];let e=n=>{if(n.keyCode==27)sl(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=Pa(r.actions);for(let l=0;l<o.length;l++)if(o[l].toUpperCase().charCodeAt(0)==n.keyCode){let h=je(this.view.state.field(bt).diagnostics,r);h&&r.actions[l].apply(t,h.from,h.to)}}else return;n.preventDefault()},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=$t("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e,onclick:i}),this.dom=$t("div",{class:"cm-panel-lint"},this.list,$t("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>sl(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(bt).selected;if(!t)return-1;for(let e=0;e<this.items.length;e++)if(this.items[e].diagnostic==t.diagnostic)return e;return-1}update(){let{diagnostics:t,selected:e}=this.view.state.field(bt),i=0,n=!1,r=null,o=new Set;for(t.between(0,this.view.state.doc.length,(l,h,{spec:f})=>{for(let a of f.diagnostics){if(o.has(a))continue;o.add(a);let c=-1,u;for(let d=i;d<this.items.length;d++)if(this.items[d].diagnostic==a){c=d;break}c<0?(u=new ol(this.view,a),this.items.splice(i,0,u),n=!0):(u=this.items[c],c>i&&(this.items.splice(i,c-i),n=!0)),e&&u.diagnostic==e.diagnostic?u.dom.hasAttribute("aria-selected")||(u.dom.setAttribute("aria-selected","true"),r=u):u.dom.hasAttribute("aria-selected")&&u.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new ol(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:h})=>{let f=h.height/this.list.offsetHeight;l.top<h.top?this.list.scrollTop-=(h.top-l.top)/f:l.bottom>h.bottom&&(this.list.scrollTop+=(l.bottom-h.bottom)/f)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let t=this.list.firstChild;function e(){let i=t;t=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;t!=i.dom;)e();t=i.dom.nextSibling}else this.list.insertBefore(i.dom,t);for(;t;)e()}moveSelection(t){if(this.selectedIndex<0)return;let e=this.view.state.field(bt),i=je(e.diagnostics,this.items[t].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:Ta.of(i)})}static open(t){return new Mn(t)}}function Mg(s,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(s)}</svg>')`}function Xi(s){return Mg(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Tg=T.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:Xi("#d11")},".cm-lintRange-warning":{backgroundImage:Xi("orange")},".cm-lintRange-info":{backgroundImage:Xi("#999")},".cm-lintRange-hint":{backgroundImage:Xi("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function Pg(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function Dg(s){let t="hint",e=1;for(let i of s){let n=Pg(i.severity);n>e&&(e=n,t=i.severity)}return t}const Ba=[bt,T.decorations.compute([bt],s=>{let{selected:t,panel:e}=s.field(bt);return!t||!e||t.from==t.to?N.none:N.set([kg.range(t.from,t.to)])}),Kc(vg,{hideOn:bg}),Tg];function Fg(s,t){let e=s.field(bt,!1);if(e&&e.diagnostics.size){let i=[],n=[],r=-1;for(let o=H.iter([e.diagnostics]);;o.next()){for(let l=0;l<i.length;l++)(!o.value||o.value.spec.diagnostics.indexOf(i[l])<0)&&(t(i[l],n[l],r),i.splice(l,1),n.splice(l--,1));if(!o.value)break;for(let l of o.value.spec.diagnostics)i.indexOf(l)<0&&(i.push(l),n.push(o.from));r=o.to}}}const Vg=(s,t={doc:null,extensions:[],extensionsOptions:{}})=>{if(!s)throw new Error("Element is required to create editor");if(t.doc===void 0)throw new Error("Document content is required to create editor");const e=F.create({doc:t.doc,extensions:[...yg(t.extensionsOptions),...t.extensions]}),i=new T({state:e,parent:s});return{editorState:e,editorView:i}};export{F as EditorState,T as EditorView,hg as OPERATORS_SNIPPET_TEMPLATES,ct as StateField,sd as acceptCompletion,Eg as completionStatus,Vg as createEditor,Lg as currentCompletions,Ig as diagnosticCount,Fg as forEachDiagnostic,ag as getResolvedSnippetByName,Ng as linter,ji as moveCompletionSelection,Hs as showPanel,md as snippet,Ne as startCompletion,gt as syntaxTree};