@aquera/nile-elements 0.1.12 → 0.1.14
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.
- package/README.md +7 -0
- package/dist/nile-code-editor/extensionSetup.cjs.js +5 -5
- package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
- package/dist/nile-code-editor/extensionSetup.esm.js +1 -1
- package/dist/nile-code-editor/nile-code-editor.cjs.js +2 -2
- package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
- package/dist/nile-code-editor/nile-code-editor.esm.js +3 -3
- package/dist/nile-code-editor/theme.cjs.js +1 -1
- package/dist/nile-code-editor/theme.cjs.js.map +1 -1
- package/dist/nile-code-editor/theme.esm.js +1 -1
- package/dist/nile-form-help-text/index.cjs.js +1 -1
- package/dist/nile-form-help-text/index.esm.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.cjs.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.cjs.js.map +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.css.cjs.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.css.cjs.js.map +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.css.esm.js +22 -6
- package/dist/nile-form-help-text/nile-form-help-text.esm.js +20 -16
- package/dist/nile-form-help-text/nile-form-help-text.test.cjs.js +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.test.cjs.js.map +1 -1
- package/dist/nile-form-help-text/nile-form-help-text.test.esm.js +1 -1
- package/dist/src/nile-code-editor/extensionSetup.js +1 -3
- package/dist/src/nile-code-editor/extensionSetup.js.map +1 -1
- package/dist/src/nile-code-editor/nile-code-editor.d.ts +5 -0
- package/dist/src/nile-code-editor/nile-code-editor.js +32 -2
- package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
- package/dist/src/nile-code-editor/theme.d.ts +24 -0
- package/dist/src/nile-code-editor/theme.js +24 -0
- package/dist/src/nile-code-editor/theme.js.map +1 -1
- package/dist/src/nile-form-help-text/nile-form-help-text.css.js +22 -6
- package/dist/src/nile-form-help-text/nile-form-help-text.css.js.map +1 -1
- package/dist/src/nile-form-help-text/nile-form-help-text.d.ts +13 -10
- package/dist/src/nile-form-help-text/nile-form-help-text.js +61 -82
- package/dist/src/nile-form-help-text/nile-form-help-text.js.map +1 -1
- package/dist/src/nile-form-help-text/nile-form-help-text.test.js +73 -52
- package/dist/src/nile-form-help-text/nile-form-help-text.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-code-editor/extensionSetup.ts +0 -6
- package/src/nile-code-editor/nile-code-editor.ts +34 -2
- package/src/nile-code-editor/theme.ts +28 -0
- package/src/nile-form-help-text/nile-form-help-text.css.ts +22 -6
- package/src/nile-form-help-text/nile-form-help-text.test.ts +83 -59
- package/src/nile-form-help-text/nile-form-help-text.ts +64 -82
- package/vscode-html-custom-data.json +2 -14
@@ -1 +1 @@
|
|
1
|
-
class t{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,s){[t,e]=u(this,t,e);let r=[];return this.decompose(0,t,r,2),s.length&&s.decompose(0,s.length,r,3),this.decompose(e,this.length,r,1),i.from(r,this.length-(e-t)+s.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=u(this,t,e);let s=[];return this.decompose(t,e,s,0),i.from(s,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new n(this),r=new n(t);for(let t=e,n=e;;){if(s.next(t),r.next(t),t=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(n+=s.value.length,s.done||n>=i)return!0}}iter(t=1){return new n(this,t)}iterRange(t,e=this.length){return new h(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new l(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(s){if(0==s.length)throw new RangeError("A document must have at least one line");return 1!=s.length||s[0]?s.length<=32?new e(s):i.from(e.split(s,[])):t.empty}}class e extends t{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.text[r],h=s+n.length;if((e?i:h)>=t)return new o(s,h,i,n);s=h+1,i++}}decompose(t,i,n,h){let l=t<=0&&i>=this.length?this:new e(r(this.text,t,i),Math.min(i,this.length)-Math.max(0,t));if(1&h){let t=n.pop(),i=s(l.text,t.text.slice(),0,l.length);if(i.length<=32)n.push(new e(i,t.length+l.length));else{let t=i.length>>1;n.push(new e(i.slice(0,t)),new e(i.slice(t)))}}else n.push(l)}replace(t,n,h){if(!(h instanceof e))return super.replace(t,n,h);[t,n]=u(this,t,n);let l=s(this.text,s(h.text,r(this.text,0,t)),n),o=this.length+h.length-(n-t);return l.length<=32?new e(l,o):i.from(e.split(l,[]),o)}sliceString(t,e=this.length,i="\n"){[t,e]=u(this,t,e);let s="";for(let r=0,n=0;r<=e&&n<this.text.length;n++){let h=this.text[n],l=r+h.length;r>t&&n&&(s+=i),t<l&&e>r&&(s+=h.slice(Math.max(0,t-r),e-r)),r=l+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,i){let s=[],r=-1;for(let n of t)s.push(n),r+=n.length+1,32==s.length&&(i.push(new e(s,r)),s=[],r=-1);return r>-1&&i.push(new e(s,r)),i}}class i extends t{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.children[r],h=s+n.length,l=i+n.lines-1;if((e?l:h)>=t)return n.lineInner(t,e,i,s);s=h+1,i=l+1}}decompose(t,e,i,s){for(let r=0,n=0;n<=e&&r<this.children.length;r++){let h=this.children[r],l=n+h.length;if(t<=l&&e>=n){let r=s&((n<=t?1:0)|(l>=e?2:0));n>=t&&l<=e&&!r?i.push(h):h.decompose(t-n,e-n,i,r)}n=l+1}}replace(t,e,s){if([t,e]=u(this,t,e),s.lines<this.lines)for(let r=0,n=0;r<this.children.length;r++){let h=this.children[r],l=n+h.length;if(t>=n&&e<=l){let o=h.replace(t-n,e-n,s),u=this.lines-h.lines+o.lines;if(o.lines<u>>4&&o.lines>u>>6){let n=this.children.slice();return n[r]=o,new i(n,this.length-(e-t)+s.length)}return super.replace(n,l,o)}n=l+1}return super.replace(t,e,s)}sliceString(t,e=this.length,i="\n"){[t,e]=u(this,t,e);let s="";for(let r=0,n=0;r<this.children.length&&n<=e;r++){let h=this.children[r],l=n+h.length;n>t&&r&&(s+=i),t<l&&e>n&&(s+=h.sliceString(t-n,e-n,i)),n=l+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof i))return 0;let s=0,[r,n,h,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;r+=e,n+=e){if(r==h||n==l)return s;let i=this.children[r],o=t.children[n];if(i!=o)return s+i.scanIdentical(o,e);s+=i.length+1}}static from(t,s=t.reduce(((t,e)=>t+e.length+1),-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let i=[];for(let e of t)e.flatten(i);return new e(i,s)}let n=Math.max(32,r>>5),h=n<<1,l=n>>1,o=[],u=0,f=-1,a=[];function c(t){let s;if(t.lines>h&&t instanceof i)for(let e of t.children)c(e);else t.lines>l&&(u>l||!u)?(d(),o.push(t)):t instanceof e&&u&&(s=a[a.length-1])instanceof e&&t.lines+s.lines<=32?(u+=t.lines,f+=t.length+1,a[a.length-1]=new e(s.text.concat(t.text),s.length+1+t.length)):(u+t.lines>n&&d(),u+=t.lines,f+=t.length+1,a.push(t))}function d(){0!=u&&(o.push(1==a.length?a[0]:i.from(a,f)),f=-1,u=a.length=0)}for(let e of t)c(e);return d(),1==o.length?o[0]:new i(o,s)}}function s(t,e,i=0,s=1e9){for(let r=0,n=0,h=!0;n<t.length&&r<=s;n++){let l=t[n],o=r+l.length;o>=i&&(o>s&&(l=l.slice(0,s-r)),r<i&&(l=l.slice(i-r)),h?(e[e.length-1]+=l,h=!1):e.push(l)),r=o+1}return e}function r(t,e,i){return s(t,[""],e,i)}t.empty=new e([""],0);class n{constructor(t,i=1){this.dir=i,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[i>0?1:(t instanceof e?t.text.length:t.children.length)<<1]}nextInner(t,i){for(this.done=this.lineBreak=!1;;){let s=this.nodes.length-1,r=this.nodes[s],n=this.offsets[s],h=n>>1,l=r instanceof e?r.text.length:r.children.length;if(h==(i>0?l:0)){if(0==s)return this.done=!0,this.value="",this;i>0&&this.offsets[s-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&n)==(i>0?0:1)){if(this.offsets[s]+=i,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(r instanceof e){let e=r.text[h+(i<0?-1:0)];if(this.offsets[s]+=i,e.length>Math.max(0,t))return this.value=0==t?e:i>0?e.slice(t):e.slice(0,e.length-t),this;t-=e.length}else{let n=r.children[h+(i<0?-1:0)];t>n.length?(t-=n.length,this.offsets[s]+=i):(i<0&&this.offsets[s]--,this.nodes.push(n),this.offsets.push(i>0?1:(n instanceof e?n.text.length:n.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class h{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new n(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class l{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(t.prototype[Symbol.iterator]=function(){return this.iter()},n.prototype[Symbol.iterator]=h.prototype[Symbol.iterator]=l.prototype[Symbol.iterator]=function(){return this});class o{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}function u(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}let f="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=1;t<f.length;t++)f[t]+=f[t-1];function a(t){for(let e=1;e<f.length;e+=2)if(f[e]>t)return f[e-1]<=t;return!1}function c(t){return t>=127462&&t<=127487}const d=8205;function p(t,e,i=!0,s=!0){return(i?m:g)(t,e,s)}function m(t,e,i){if(e==t.length)return e;e&&w(t.charCodeAt(e))&&b(t.charCodeAt(e-1))&&e--;let s=v(t,e);for(e+=y(s);e<t.length;){let r=v(t,e);if(s==d||r==d||i&&a(r))e+=y(r),s=r;else{if(!c(r))break;{let i=0,s=e-2;for(;s>=0&&c(v(t,s));)i++,s-=2;if(i%2==0)break;e+=2}}}return e}function g(t,e,i){for(;e>0;){let s=m(t,e-2,i);if(s<e)return s;e--}return 0}function w(t){return t>=56320&&t<57344}function b(t){return t>=55296&&t<56320}function v(t,e){let i=t.charCodeAt(e);if(!b(i)||e+1==t.length)return i;let s=t.charCodeAt(e+1);return w(s)?s-56320+(i-55296<<10)+65536:i}function k(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function y(t){return t<65536?1:2}const M=/\r\n?|\n/;var x=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(x||(x={}));class S{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 0==this.sections.length||2==this.sections.length&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,s=0;e<this.sections.length;){let r=this.sections[e++],n=this.sections[e++];n<0?(t(i,s,r),s+=r):s+=n,i+=r}}iterChangedRanges(t,e=!1){D(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];s<0?t.push(i,s):t.push(s,i)}return new S(t)}composeDesc(t){return this.empty?t:t.empty?this:I(this,t)}mapDesc(t,e=!1){return t.empty?this:E(this,t,e)}mapPos(t,e=-1,i=x.Simple){let s=0,r=0;for(let n=0;n<this.sections.length;){let h=this.sections[n++],l=this.sections[n++],o=s+h;if(l<0){if(o>t)return r+(t-s);r+=h}else{if(i!=x.Simple&&o>=t&&(i==x.TrackDel&&s<t&&o>t||i==x.TrackBefore&&s<t||i==x.TrackAfter&&o>t))return null;if(o>t||o==t&&e<0&&!h)return t==s||e<0?r:r+l;r+=l}s=o}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return r}touchesRange(t,e=t){for(let i=0,s=0;i<this.sections.length&&s<=e;){let r=s+this.sections[i++];if(this.sections[i++]>=0&&s<=e&&r>=t)return!(s<t&&r>e)||"cover";s=r}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];t+=(t?" ":"")+i+(s>=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some((t=>"number"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeDesc");return new S(t)}static create(t){return new S(t)}}class A extends S{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 D(this,((e,i,s,r,n)=>t=t.replace(s,s+(i-e),n)),!1),t}mapDesc(t,e=!1){return E(this,t,e,!0)}invert(e){let i=this.sections.slice(),s=[];for(let r=0,n=0;r<i.length;r+=2){let h=i[r],l=i[r+1];if(l>=0){i[r]=l,i[r+1]=h;let o=r>>1;for(;s.length<o;)s.push(t.empty);s.push(h?e.slice(n,n+h):t.empty)}n+=h}return new A(i,s)}compose(t){return this.empty?t:t.empty?this:I(this,t,!0)}map(t,e=!1){return t.empty?this:E(this,t,e,!0)}iterChanges(t,e=!1){D(this,t,e)}get desc(){return S.create(this.sections)}filter(t){let e=[],i=[],s=[],r=new R(this);t:for(let n=0,h=0;;){let l=n==t.length?1e9:t[n++];for(;h<l||h==l&&0==r.len;){if(r.done)break t;let t=Math.min(r.len,l-h);C(s,t,-1);let n=-1==r.ins?-1:0==r.off?r.ins:0;C(e,t,n),n>0&&O(i,e,r.text),r.forward(t),h+=t}let o=t[n++];for(;h<o;){if(r.done)break t;let t=Math.min(r.len,o-h);C(e,t,-1),C(s,t,-1==r.ins?-1:0==r.off?r.ins:0),r.forward(t),h+=t}}return{changes:new A(e,i),filtered:S.create(s)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],s=this.sections[e+1];s<0?t.push(i):0==s?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(e,i,s){let r=[],n=[],h=0,l=null;function o(t=!1){if(!t&&!r.length)return;h<i&&C(r,i-h,-1);let e=new A(r,n);l=l?l.compose(e.map(l)):e,r=[],n=[],h=0}return function e(u){if(Array.isArray(u))for(let t of u)e(t);else if(u instanceof A){if(u.length!=i)throw new RangeError(`Mismatched change set length (got ${u.length}, expected ${i})`);o(),l=l?l.compose(u.map(l)):u}else{let{from:e,to:l=e,insert:f}=u;if(e>l||e<0||l>i)throw new RangeError(`Invalid change range ${e} to ${l} (in doc of length ${i})`);let a=f?"string"==typeof f?t.of(f.split(s||M)):f:t.empty,c=a.length;if(e==l&&0==c)return;e<h&&o(),e>h&&C(r,e-h,-1),C(r,l-e,c),O(n,r,a),h=l}}(e),o(!l),l}static empty(t){return new A(t?[t,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let i=[],s=[];for(let r=0;r<e.length;r++){let n=e[r];if("number"==typeof n)i.push(n,-1);else{if(!Array.isArray(n)||"number"!=typeof n[0]||n.some(((t,e)=>e&&"string"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==n.length)i.push(n[0],0);else{for(;s.length<r;)s.push(t.empty);s[r]=t.of(n.slice(1)),i.push(n[0],s[r].length)}}}return new A(i,s)}static createSet(t,e){return new A(t,e)}}function C(t,e,i,s=!1){if(0==e&&i<=0)return;let r=t.length-2;r>=0&&i<=0&&i==t[r+1]?t[r]+=e:0==e&&0==t[r]?t[r+1]+=i:s?(t[r]+=e,t[r+1]+=i):t.push(e,i)}function O(e,i,s){if(0==s.length)return;let r=i.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(s);else{for(;e.length<r;)e.push(t.empty);e.push(s)}}function D(e,i,s){let r=e.inserted;for(let n=0,h=0,l=0;l<e.sections.length;){let o=e.sections[l++],u=e.sections[l++];if(u<0)n+=o,h+=o;else{let f=n,a=h,c=t.empty;for(;f+=o,a+=u,u&&r&&(c=c.append(r[l-2>>1])),!(s||l==e.sections.length||e.sections[l+1]<0);)o=e.sections[l++],u=e.sections[l++];i(n,f,h,a,c),n=f,h=a}}}function E(t,e,i,s=!1){let r=[],n=s?[]:null,h=new R(t),l=new R(e);for(let t=-1;;)if(-1==h.ins&&-1==l.ins){let t=Math.min(h.len,l.len);C(r,t,-1),h.forward(t),l.forward(t)}else if(l.ins>=0&&(h.ins<0||t==h.i||0==h.off&&(l.len<h.len||l.len==h.len&&!i))){let e=l.len;for(C(r,l.ins,-1);e;){let i=Math.min(h.len,e);h.ins>=0&&t<h.i&&h.len<=i&&(C(r,0,h.ins),n&&O(n,r,h.text),t=h.i),h.forward(i),e-=i}l.next()}else{if(!(h.ins>=0)){if(h.done&&l.done)return n?A.createSet(r,n):S.create(r);throw new Error("Mismatched change set lengths")}{let e=0,i=h.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.len<i))break;i-=l.len,l.next()}C(r,e,t<h.i?h.ins:0),n&&t<h.i&&O(n,r,h.text),t=h.i,h.forward(h.len-i)}}}function I(t,e,i=!1){let s=[],r=i?[]:null,n=new R(t),h=new R(e);for(let t=!1;;){if(n.done&&h.done)return r?A.createSet(s,r):S.create(s);if(0==n.ins)C(s,n.len,0,t),n.next();else if(0!=h.len||h.done){if(n.done||h.done)throw new Error("Mismatched change set lengths");{let e=Math.min(n.len2,h.len),i=s.length;if(-1==n.ins){let i=-1==h.ins?-1:h.off?0:h.ins;C(s,e,i,t),r&&i&&O(r,s,h.text)}else-1==h.ins?(C(s,n.off?0:n.len,e,t),r&&O(r,s,n.textBit(e))):(C(s,n.off?0:n.len,h.off?0:h.ins,t),r&&!h.off&&O(r,s,h.text));t=(n.ins>e||h.ins>=0&&h.len>e)&&(t||s.length>i),n.forward2(e),h.forward(e)}}else C(s,0,h.ins,t),r&&O(r,s,h.text),h.next()}}class R{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-2==this.ins}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length?t.empty:e[i]}textBit(e){let{inserted:i}=this.set,s=this.i-2>>1;return s>=i.length&&!e?t.empty:i[s].slice(this.off,null==e?void 0:this.off+e)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class T{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}get goalColumn(){let t=this.flags>>6;return 16777215==t?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new T(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return B.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return B.range(this.anchor,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return B.range(t.anchor,t.head)}static create(t,e,i){return new T(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 1==this.ranges.length?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)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new B(t.ranges.map((t=>T.fromJSON(t))),t.main)}static single(t,e=t){return new B([B.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<t.length;s++){let r=t[s];if(r.empty?r.from<=i:r.from<i)return B.normalized(t.slice(),e);i=r.to}return new B(t,e)}static cursor(t,e=0,i,s){return T.create(t,t,(0==e?0:e<0?8:16)|(null==i?7:Math.min(6,i))|(null!=s?s:16777215)<<6)}static range(t,e,i,s){let r=(null!=i?i:16777215)<<6|(null==s?7:Math.min(6,s));return e<t?T.create(e,t,48|r):T.create(t,e,(e>t?8:0)|r)}static normalized(t,e=0){let i=t[e];t.sort(((t,e)=>t.from-e.from)),e=t.indexOf(i);for(let i=1;i<t.length;i++){let s=t[i],r=t[i-1];if(s.empty?s.from<=r.to:s.from<r.to){let n=r.from,h=Math.max(s.to,r.to);i<=e&&e--,t.splice(--i,2,s.anchor>s.head?B.range(h,n):B.range(n,h))}}return new B(t,e)}}function L(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let N=0;class j{constructor(t,e,i,s,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.id=N++,this.default=t([]),this.extensions="function"==typeof r?r(this):r}get reader(){return this}static define(t={}){return new j(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:$),!!t.static,t.enables)}of(t){return new z([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new z(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new z(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],(i=>e(i.field(t))))}}function $(t,e){return t==e||t.length==e.length&&t.every(((t,i)=>t===e[i]))}class z{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=N++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,r=this.id,n=t[r]>>1,h=2==this.type,l=!1,o=!1,u=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?o=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||u.push(t[i.id]);return{create:t=>(t.values[n]=i(t),1),update(t,e){if(l&&e.docChanged||o&&(e.docChanged||e.selection)||H(t,u)){let e=i(t);if(h?!P(e,t.values[n],s):!s(e,t.values[n]))return t.values[n]=e,1}return 0},reconfigure:(t,e)=>{let l,o=e.config.address[r];if(null!=o){let r=et(e,o);if(this.dependencies.every((i=>i instanceof j?e.facet(i)===t.facet(i):!(i instanceof F)||e.field(i,!1)==t.field(i,!1)))||(h?P(l=i(t),r,s):s(l=i(t),r)))return t.values[n]=r,0}else l=i(t);return t.values[n]=l,1}}}}function P(t,e,i){if(t.length!=e.length)return!1;for(let s=0;s<t.length;s++)if(!i(t[s],e[s]))return!1;return!0}function H(t,e){let i=!1;for(let s of e)1&tt(t,s)&&(i=!0);return i}function W(t,e,i){let s=i.map((e=>t[e.id])),r=i.map((t=>t.type)),n=s.filter((t=>!(1&t))),h=t[e.id]>>1;function l(t){let i=[];for(let e=0;e<s.length;e++){let n=et(t,s[e]);if(2==r[e])for(let t of n)i.push(t);else i.push(n)}return e.combine(i)}return{create(t){for(let e of s)tt(t,e);return t.values[h]=l(t),1},update(t,i){if(!H(t,n))return 0;let s=l(t);return e.compare(s,t.values[h])?0:(t.values[h]=s,1)},reconfigure(t,r){let n=H(t,s),o=r.config.facets[e.id],u=r.facet(e);if(o&&!n&&$(i,o))return t.values[h]=u,0;let f=l(t);return e.compare(f,u)?(t.values[h]=u,0):(t.values[h]=f,1)}}}const V=j.define({static:!0});class F{constructor(t,e,i,s,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(t){let e=new F(N++,t.create,t.update,t.compare||((t,e)=>t===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(V).find((t=>t.field==this));return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let s=t.values[e],r=this.updateF(s,i);return this.compareF(s,r)?0:(t.values[e]=r,1)},reconfigure:(t,i)=>null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}init(t){return[this,V.of({field:this,create:t})]}get extension(){return this}}const q=4,U=3,J=2,G=1;function K(t){return e=>new X(e,t)}const _={highest:K(0),high:K(G),default:K(J),low:K(U),lowest:K(q)};class X{constructor(t,e){this.inner=t,this.prec=e}}class Y{of(t){return new Q(this,t)}reconfigure(t){return Y.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class Q{constructor(t,e){this.compartment=t,this.inner=e}}class Z{constructor(t,e,i,s,r,n){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=n,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return null==e?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let s=[],r=Object.create(null),n=new Map;for(let i of function(t,e,i){let s=[[],[],[],[],[]],r=new Map;function n(t,h){let l=r.get(t);if(null!=l){if(l<=h)return;let e=s[l].indexOf(t);e>-1&&s[l].splice(e,1),t instanceof Q&&i.delete(t.compartment)}if(r.set(t,h),Array.isArray(t))for(let e of t)n(e,h);else if(t instanceof Q){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let s=e.get(t.compartment)||t.inner;i.set(t.compartment,s),n(s,h)}else if(t instanceof X)n(t.inner,t.prec);else if(t instanceof F)s[h].push(t),t.provides&&n(t.provides,h);else if(t instanceof z)s[h].push(t),t.facet.extensions&&n(t.facet.extensions,J);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(e,h)}}return n(t,J),s.reduce(((t,e)=>t.concat(e)))}(t,e,n))i instanceof F?s.push(i):(r[i.facet.id]||(r[i.facet.id]=[])).push(i);let h=Object.create(null),l=[],o=[];for(let t of s)h[t.id]=o.length<<1,o.push((e=>t.slot(e)));let u=null==i?void 0:i.config.facets;for(let t in r){let e=r[t],s=e[0].facet,n=u&&u[t]||[];if(e.every((t=>0==t.type)))if(h[s.id]=l.length<<1|1,$(n,e))l.push(i.facet(s));else{let t=s.combine(e.map((t=>t.value)));l.push(i&&s.compare(t,i.facet(s))?i.facet(s):t)}else{for(let t of e)0==t.type?(h[t.id]=l.length<<1|1,l.push(t.value)):(h[t.id]=o.length<<1,o.push((e=>t.dynamicSlot(e))));h[s.id]=o.length<<1,o.push((t=>W(t,s,e)))}}let f=o.map((t=>t(h)));return new Z(t,n,f,h,l,r)}}function tt(t,e){if(1&e)return 2;let i=e>>1,s=t.status[i];if(4==s)throw new Error("Cyclic dependency between fields and/or facets");if(2&s)return s;t.status[i]=4;let r=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|r}function et(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const it=j.define(),st=j.define({combine:t=>t.some((t=>t)),static:!0}),rt=j.define({combine:t=>t.length?t[0]:void 0,static:!0}),nt=j.define(),ht=j.define(),lt=j.define(),ot=j.define({combine:t=>!!t.length&&t[0]});class ut{constructor(t,e){this.type=t,this.value=e}static define(){return new ft}}class ft{of(t){return new ut(this,t)}}class at{constructor(t){this.map=t}of(t){return new ct(this,t)}}class ct{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new ct(this.type,e)}is(t){return this.type==t}static define(t={}){return new at(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let t=s.map(e);t&&i.push(t)}return i}}ct.reconfigure=ct.define(),ct.appendConfig=ct.define();class dt{constructor(t,e,i,s,r,n){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=n,this._doc=null,this._state=null,i&&L(i,e.newLength),r.some((t=>t.type==dt.time))||(this.annotations=r.concat(dt.time.of(Date.now())))}static create(t,e,i,s,r,n){return new dt(t,e,i,s,r,n)}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(dt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function pt(t,e){let i=[];for(let s=0,r=0;;){let n,h;if(s<t.length&&(r==e.length||e[r]>=t[s]))n=t[s++],h=t[s++];else{if(!(r<e.length))return i;n=e[r++],h=e[r++]}!i.length||i[i.length-1]<n?i.push(n,h):i[i.length-1]<h&&(i[i.length-1]=h)}}function mt(t,e,i){var s;let r,n,h;return i?(r=e.changes,n=A.empty(e.changes.length),h=t.changes.compose(e.changes)):(r=e.changes.map(t.changes),n=t.changes.mapDesc(e.changes,!0),h=t.changes.compose(r)),{changes:h,selection:e.selection?e.selection.map(n):null===(s=t.selection)||void 0===s?void 0:s.map(r),effects:ct.mapEffects(t.effects,r).concat(ct.mapEffects(e.effects,n)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function gt(t,e,i){let s=e.selection,r=vt(e.annotations);return e.userEvent&&(r=r.concat(dt.userEvent.of(e.userEvent))),{changes:e.changes instanceof A?e.changes:A.of(e.changes||[],i,t.facet(rt)),selection:s&&(s instanceof B?s:B.single(s.anchor,s.head)),effects:vt(e.effects),annotations:r,scrollIntoView:!!e.scrollIntoView}}function wt(t,e,i){let s=gt(t,e.length?e[0]:{},t.doc.length);e.length&&!1===e[0].filter&&(i=!1);for(let r=1;r<e.length;r++){!1===e[r].filter&&(i=!1);let n=!!e[r].sequential;s=mt(s,gt(t,e[r],n?s.changes.newLength:t.doc.length),n)}let r=dt.create(t,s.changes,s.selection,s.effects,s.annotations,s.scrollIntoView);return function(t){let e=t.startState,i=e.facet(lt),s=t;for(let r=i.length-1;r>=0;r--){let n=i[r](t);n&&Object.keys(n).length&&(s=mt(s,gt(e,n,t.changes.newLength),!0))}return s==t?t:dt.create(e,t.changes,t.selection,s.effects,s.annotations,s.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let s of e.facet(nt)){let e=s(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:pt(i,e))}if(!0!==i){let s,r;if(!1===i)r=t.changes.invertedDesc,s=A.empty(e.doc.length);else{let e=t.changes.filter(i);s=e.changes,r=e.filtered.mapDesc(e.changes).invertedDesc}t=dt.create(e,s,t.selection&&t.selection.map(r),ct.mapEffects(t.effects,r),t.annotations,t.scrollIntoView)}let s=e.facet(ht);for(let i=s.length-1;i>=0;i--){let r=s[i](t);t=r instanceof dt?r:Array.isArray(r)&&1==r.length&&r[0]instanceof dt?r[0]:wt(e,vt(r),!1)}return t}(r):r)}dt.time=ut.define(),dt.userEvent=ut.define(),dt.addToHistory=ut.define(),dt.remote=ut.define();const bt=[];function vt(t){return null==t?bt:Array.isArray(t)?t:[t]}var kt=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(kt||(kt={}));const yt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Mt;try{Mt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function xt(t){return e=>{if(!/\S/.test(e))return kt.Space;if(function(t){if(Mt)return Mt.test(t);for(let e=0;e<t.length;e++){let i=t[e];if(/\w/.test(i)||i>""&&(i.toUpperCase()!=i.toLowerCase()||yt.test(i)))return!0}return!1}(e))return kt.Word;for(let i=0;i<t.length;i++)if(e.indexOf(t[i])>-1)return kt.Word;return kt.Other}}class St{constructor(t,e,i,s,r,n){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=r,n&&(n._state=this);for(let t=0;t<this.config.dynamicSlots.length;t++)tt(this,t<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(null!=i)return tt(this,i),et(this,i);if(e)throw new RangeError("Field is not present in this state")}update(...t){return wt(this,t,!0)}applyTransaction(t){let e,i=this.config,{base:s,compartments:r}=i;for(let e of t.effects)e.is(Y.reconfigure)?(i&&(r=new Map,i.compartments.forEach(((t,e)=>r.set(e,t))),i=null),r.set(e.value.compartment,e.value.extension)):e.is(ct.reconfigure)?(i=null,s=e.value):e.is(ct.appendConfig)&&(i=null,s=vt(s).concat(e.value));if(i)e=t.startState.values.slice();else{i=Z.resolve(s,r,this),e=new St(i,this.doc,this.selection,i.dynamicSlots.map((()=>null)),((t,e)=>e.reconfigure(t,this)),null).values}let n=t.startState.facet(st)?t.newSelection:t.newSelection.asSingle();new St(i,t.newDoc,n,e,((e,i)=>i.update(e,t)),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t},range:B.cursor(e.from+t.length)})))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),r=[i.range],n=vt(i.effects);for(let i=1;i<e.ranges.length;i++){let h=t(e.ranges[i]),l=this.changes(h.changes),o=l.map(s);for(let t=0;t<i;t++)r[t]=r[t].map(o);let u=s.mapDesc(l,!0);r.push(h.range.map(u)),s=s.compose(o),n=ct.mapEffects(n,o).concat(ct.mapEffects(vt(h.effects),u))}return{changes:s,selection:B.create(r,e.mainIndex),effects:n}}changes(t=[]){return t instanceof A?t:A.of(t,this.doc.length,this.facet(St.lineSeparator))}toText(e){return t.of(e.split(this.facet(St.lineSeparator)||M))}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 null==e?t.default:(tt(this,e),et(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let s=t[i];s instanceof F&&null!=this.config.address[s.id]&&(e[i]=s.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||"string"!=typeof t.doc)throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i)for(let e in i)if(Object.prototype.hasOwnProperty.call(t,e)){let r=i[e],n=t[e];s.push(r.init((t=>r.spec.fromJSON(n,t))))}return St.create({doc:t.doc,selection:B.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(e={}){let i=Z.resolve(e.extensions||[],new Map),s=e.doc instanceof t?e.doc:t.of((e.doc||"").split(i.staticFacet(St.lineSeparator)||M)),r=e.selection?e.selection instanceof B?e.selection:B.single(e.selection.anchor,e.selection.head):B.single(0);return L(r,s.length),i.staticFacet(st)||(r=r.asSingle()),new St(i,s,r,i.dynamicSlots.map((()=>null)),((t,e)=>e.create(t)),null)}get tabSize(){return this.facet(St.tabSize)}get lineBreak(){return this.facet(St.lineSeparator)||"\n"}get readOnly(){return this.facet(ot)}phrase(t,...e){for(let e of this.facet(St.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,((t,i)=>{if("$"==i)return"$";let s=+(i||1);return!s||s>e.length?t:e[s-1]}))),t}languageDataAt(t,e,i=-1){let s=[];for(let r of this.facet(it))for(let n of r(this,e,i))Object.prototype.hasOwnProperty.call(n,t)&&s.push(n[t]);return s}charCategorizer(t){return xt(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),r=this.charCategorizer(t),n=t-i,h=t-i;for(;n>0;){let t=p(e,n,!1);if(r(e.slice(t,n))!=kt.Word)break;n=t}for(;h<s;){let t=p(e,h);if(r(e.slice(h,t))!=kt.Word)break;h=t}return n==h?null:B.range(n+i,h+i)}}function At(t,e,i={}){let s={};for(let e of t)for(let t of Object.keys(e)){let r=e[t],n=s[t];if(void 0===n)s[t]=r;else if(n===r||void 0===r);else{if(!Object.hasOwnProperty.call(i,t))throw new Error("Config merge conflict for field "+t);s[t]=i[t](n,r)}}for(let t in e)void 0===s[t]&&(s[t]=e[t]);return s}St.allowMultipleSelections=st,St.tabSize=j.define({combine:t=>t.length?t[0]:4}),St.lineSeparator=rt,St.readOnly=ot,St.phrases=j.define({compare(t,e){let i=Object.keys(t),s=Object.keys(e);return i.length==s.length&&i.every((i=>t[i]==e[i]))}}),St.languageData=it,St.changeFilter=nt,St.transactionFilter=ht,St.transactionExtender=lt,Y.reconfigure=ct.define();class Ct{eq(t){return this==t}range(t,e=t){return Ot.create(t,e,this)}}Ct.prototype.startSide=Ct.prototype.endSide=0,Ct.prototype.point=!1,Ct.prototype.mapMode=x.TrackDel;let Ot=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,s){return new t(e,i,s)}};function Dt(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Et{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let r=i?this.to:this.from;for(let n=s,h=r.length;;){if(n==h)return n;let s=n+h>>1,l=r[s]-t||(i?this.value[s].endSide:this.value[s].startSide)-e;if(s==n)return l>=0?n:h;l>=0?h=s:n=s+1}}between(t,e,i,s){for(let r=this.findIndex(e,-1e9,!0),n=this.findIndex(i,1e9,!1,r);r<n;r++)if(!1===s(this.from[r]+t,this.to[r]+t,this.value[r]))return!1}map(t,e){let i=[],s=[],r=[],n=-1,h=-1;for(let l=0;l<this.value.length;l++){let o,u,f=this.value[l],a=this.from[l]+t,c=this.to[l]+t;if(a==c){let t=e.mapPos(a,f.startSide,f.mapMode);if(null==t)continue;if(o=u=t,f.startSide!=f.endSide&&(u=e.mapPos(a,f.endSide),u<o))continue}else if(o=e.mapPos(a,f.startSide),u=e.mapPos(c,f.endSide),o>u||o==u&&f.startSide>0&&f.endSide<=0)continue;(u-o||f.endSide-f.startSide)<0||(n<0&&(n=o),f.point&&(h=Math.max(h,u-o)),i.push(f),s.push(o-n),r.push(u-n))}return{mapped:i.length?new Et(s,r,i,h):null,pos:n}}}class It{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new It(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=t,n=t.filter;if(0==e.length&&!n)return this;if(i&&(e=e.slice().sort(Dt)),this.isEmpty)return e.length?It.of(e):this;let h=new Bt(this,null,-1).goto(0),l=0,o=[],u=new Rt;for(;h.value||l<e.length;)if(l<e.length&&(h.from-e[l].from||h.startSide-e[l].value.startSide)>=0){let t=e[l++];u.addInner(t.from,t.to,t.value)||o.push(t)}else 1==h.rangeIndex&&h.chunkIndex<this.chunk.length&&(l==e.length||this.chunkEnd(h.chunkIndex)<e[l].from)&&(!n||s>this.chunkEnd(h.chunkIndex)||r<this.chunkPos[h.chunkIndex])&&u.addChunk(this.chunkPos[h.chunkIndex],this.chunk[h.chunkIndex])?h.nextChunk():((!n||s>h.to||r<h.from||n(h.from,h.to,h.value))&&(u.addInner(h.from,h.to,h.value)||o.push(Ot.create(h.from,h.to,h.value))),h.next());return u.finishInner(this.nextLayer.isEmpty&&!o.length?It.empty:this.nextLayer.update({add:o,filter:n,filterFrom:s,filterTo:r}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],s=-1;for(let r=0;r<this.chunk.length;r++){let n=this.chunkPos[r],h=this.chunk[r],l=t.touchesRange(n,n+h.length);if(!1===l)s=Math.max(s,h.maxPoint),e.push(h),i.push(t.mapPos(n));else if(!0===l){let{mapped:r,pos:l}=h.map(n,t);r&&(s=Math.max(s,r.maxPoint),e.push(r),i.push(l))}}let r=this.nextLayer.map(t);return 0==e.length?r:new It(i,e,r||It.empty,s)}between(t,e,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],n=this.chunk[s];if(e>=r&&t<=r+n.length&&!1===n.between(r,t-r,e-r,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Lt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Lt.from(t).goto(e)}static compare(t,e,i,s,r=-1){let n=t.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),h=e.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),l=Tt(n,h,i),o=new jt(n,l,r),u=new jt(h,l,r);i.iterGaps(((t,e,i)=>$t(o,t,u,e,i,s))),i.empty&&0==i.length&&$t(o,0,u,0,0,s)}static eq(t,e,i=0,s){null==s&&(s=999999999);let r=t.filter((t=>!t.isEmpty&&e.indexOf(t)<0)),n=e.filter((e=>!e.isEmpty&&t.indexOf(e)<0));if(r.length!=n.length)return!1;if(!r.length)return!0;let h=Tt(r,n),l=new jt(r,h,0).goto(i),o=new jt(n,h,0).goto(i);for(;;){if(l.to!=o.to||!zt(l.active,o.active)||l.point&&(!o.point||!l.point.eq(o.point)))return!1;if(l.to>s)return!0;l.next(),o.next()}}static spans(t,e,i,s,r=-1){let n=new jt(t,null,r).goto(e),h=e,l=n.openStart;for(;;){let t=Math.min(n.to,i);if(n.point){let i=n.activeForPoint(n.to),r=n.pointFrom<e?i.length+1:n.point.startSide<0?i.length:Math.min(i.length,l);s.point(h,t,n.point,i,r,n.pointRank),l=Math.min(n.openEnd(t),i.length)}else t>h&&(s.span(h,t,n.active,l),l=n.openEnd(t));if(n.to>i)return l+(n.point&&n.to>i?1:0);h=n.to,n.next()}}static of(t,e=!1){let i=new Rt;for(let s of t instanceof Ot?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i<t.length;i++){let s=t[i];if(Dt(e,s)>0)return t.slice().sort(Dt);e=s}return t}(t):t)i.add(s.from,s.to,s.value);return i.finish()}static join(t){if(!t.length)return It.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let s=t[i];s!=It.empty;s=s.nextLayer)e=new It(s.chunkPos,s.chunk,e,Math.max(s.maxPoint,e.maxPoint));return e}}It.empty=new It([],[],null,-1),It.empty.nextLayer=It.empty;class Rt{finishChunk(t){this.chunks.push(new Et(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 Rt)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(s<0)&&(250==this.from.length&&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(It.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=It.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Tt(t,e,i){let s=new Map;for(let e of t)for(let t=0;t<e.chunk.length;t++)e.chunk[t].maxPoint<=0&&s.set(e.chunk[t],e.chunkPos[t]);let r=new Set;for(let t of e)for(let e=0;e<t.chunk.length;e++){let n=s.get(t.chunk[e]);null==n||(i?i.mapPos(n):n)!=t.chunkPos[e]||(null==i?void 0:i.touchesRange(n,n+t.chunk[e].length))||r.add(t.chunk[e])}return r}class Bt{constructor(t,e,i,s=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let e=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(e)||this.layer.chunkEnd(this.chunkIndex)<t||e.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}{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 Lt{constructor(t){this.heap=t}static from(t,e=null,i=-1){let s=[];for(let r=0;r<t.length;r++)for(let n=t[r];!n.isEmpty;n=n.nextLayer)n.maxPoint>=i&&s.push(new Bt(n,e,i,r));return 1==s.length?s[0]:new Lt(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)Nt(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)Nt(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)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(),Nt(this.heap,0)}}}function Nt(t,e){for(let i=t[e];;){let s=1+(e<<1);if(s>=t.length)break;let r=t[s];if(s+1<t.length&&r.compare(t[s+1])>=0&&(r=t[s+1],s++),i.compare(r)<0)break;t[s]=i,t[e]=r,e=s}}class jt{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=Lt.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){Pt(this.active,t),Pt(this.activeTo,t),Pt(this.activeRank,t),this.minActive=Wt(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:r}=this.cursor;for(;e<this.activeRank.length&&(r-this.activeRank[e]||s-this.activeTo[e])>0;)e++;Ht(this.active,e,i),Ht(this.activeTo,e,s),Ht(this.activeRank,e,r),t&&Ht(t,e,this.cursor.from),this.minActive=Wt(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>t){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&Pt(i,s)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){this.point=t,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=t.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}this.cursor.next()}else this.addActive(i),this.cursor.next()}}}if(i){this.openStart=0;for(let e=i.length-1;e>=0&&i[e]<t;e--)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 $t(t,e,i,s,r,n){t.goto(e),i.goto(s);let h=s+r,l=s,o=s-e;for(;;){let e=t.to+o-i.to||t.endSide-i.endSide,s=e<0?t.to+o:i.to,r=Math.min(s,h);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&zt(t.activeForPoint(t.to),i.activeForPoint(i.to))||n.comparePoint(l,r,t.point,i.point):r>l&&!zt(t.active,i.active)&&n.compareRange(l,r,t.active,i.active),s>h)break;l=s,e<=0&&t.next(),e>=0&&i.next()}}function zt(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!=e[i]&&!t[i].eq(e[i]))return!1;return!0}function Pt(t,e){for(let i=e,s=t.length-1;i<s;i++)t[i]=t[i+1];t.pop()}function Ht(t,e,i){for(let i=t.length-1;i>=e;i--)t[i+1]=t[i];t[e]=i}function Wt(t,e){let i=-1,s=1e9;for(let r=0;r<e.length;r++)(e[r]-s||t[r].endSide-t[i].endSide)<0&&(i=r,s=e[r]);return i}function Vt(t,e,i=t.length){let s=0;for(let r=0;r<i;)9==t.charCodeAt(r)?(s+=e-s%e,r++):(s++,r=p(t,r));return s}function Ft(t,e,i,s){for(let s=0,r=0;;){if(r>=e)return s;if(s==t.length)break;r+=9==t.charCodeAt(s)?i-r%i:1,s=p(t,s)}return!0===s?-1:t.length}const qt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Ut="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Jt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Gt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function r(t,e,n,h){let l=[],o=/^@(\w+)\b/.exec(t[0]),u=o&&"keyframes"==o[1];if(o&&null==e)return n.push(t[0]+";");for(let i in e){let h=e[i];if(/&/.test(i))r(i.split(/,\s*/).map((e=>t.map((t=>e.replace(/&/,t))))).reduce(((t,e)=>t.concat(e))),h,n);else if(h&&"object"==typeof h){if(!o)throw new RangeError("The value of a property ("+i+") should be a primitive value.");r(s(i),h,l,u)}else null!=h&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,(t=>"-"+t.toLowerCase()))+": "+h+";")}(l.length||u)&&n.push((!i||o||h?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)r(s(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Jt[qt]||1;return Jt[qt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let s=t[Ut],r=i&&i.nonce;s?r&&s.setNonce(r):s=new _t(t,r),s.mount(Array.isArray(e)?e:[e],t)}}let Kt=new Map;class _t{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let e=Kt.get(i);if(e)return t[Ut]=e;this.sheet=new s.CSSStyleSheet,Kt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Ut]=this}mount(t,e){let i=this.sheet,s=0,r=0;for(let e=0;e<t.length;e++){let n=t[e],h=this.modules.indexOf(n);if(h<r&&h>-1&&(this.modules.splice(h,1),r--,h=-1),-1==h){if(this.modules.splice(r++,0,n),i)for(let t=0;t<n.rules.length;t++)i.insertRule(n.rules[t],s++)}else{for(;r<h;)s+=this.modules[r++].rules.length;s+=n.rules.length,r++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let t="";for(let e=0;e<this.modules.length;e++)t+=this.modules[e].getRules()+"\n";this.styleTag.textContent=t;let i=e.head||e;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}for(var Xt={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:"'"},Yt={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Qt="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),Zt="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),te=0;te<10;te++)Xt[48+te]=Xt[96+te]=String(te);for(te=1;te<=24;te++)Xt[te+111]="F"+te;for(te=65;te<=90;te++)Xt[te]=String.fromCharCode(te+32),Yt[te]=String.fromCharCode(te);for(var ee in Xt)Yt.hasOwnProperty(ee)||(Yt[ee]=Xt[ee]);function ie(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function se(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function re(t,e){if(!e.anchorNode)return!1;try{return se(t,e.anchorNode)}catch(t){return!1}}function ne(t){return 3==t.nodeType?be(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function he(t,e,i,s){return!!i&&(ue(t,e,i,s,-1)||ue(t,e,i,s,1))}function le(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function oe(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function ue(t,e,i,s,r){for(;;){if(t==i&&e==s)return!0;if(e==(r<0?0:fe(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=le(t)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(r<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=r<0?fe(t):0}}}function fe(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ae(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function ce(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function de(t,e){let i=e.width/t.offsetWidth,s=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(s>.995&&s<1.005||!isFinite(s)||Math.abs(e.height-t.offsetHeight)<1)&&(s=1),{scaleX:i,scaleY:s}}class pe{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?fe(e):0),i,Math.min(t.focusOffset,i?fe(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let me,ge=null;function we(t){if(t.setActive)return t.setActive();if(ge)return t.focus(ge);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ge?{get preventScroll(){return ge={preventScroll:!0},!0}}:void 0),!ge){ge=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}function be(t,e,i=e){let s=me||(me=document.createRange());return s.setEnd(t,i),s.setStart(t,e),s}function ve(t,e,i,s){let r={key:e,code:e,keyCode:i,which:i,cancelable:!0};s&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=s);let n=new KeyboardEvent("keydown",r);n.synthetic=!0,t.dispatchEvent(n);let h=new KeyboardEvent("keyup",r);return h.synthetic=!0,t.dispatchEvent(h),n.defaultPrevented||h.defaultPrevented}function ke(t){for(;t.attributes.length;)t.removeAttributeNode(t.attributes[0])}function ye(t){return t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function Me(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s>0)return{node:i,offset:s};if(1==i.nodeType&&s>0){if("false"==i.contentEditable)return null;i=i.childNodes[s-1],s=fe(i)}else{if(!i.parentNode||oe(i))return null;s=le(i),i=i.parentNode}}}function xe(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s<i.nodeValue.length)return{node:i,offset:s};if(1==i.nodeType&&s<i.childNodes.length){if("false"==i.contentEditable)return null;i=i.childNodes[s],s=0}else{if(!i.parentNode||oe(i))return null;s=le(i)+1,i=i.parentNode}}}class Se{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new Se(t.parentNode,le(t),e)}static after(t,e){return new Se(t.parentNode,le(t)+1,e)}}const Ae=[];class Ce{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(2&this.flags){let i,s=this.dom,r=null;for(let n of this.children){if(7&n.flags){if(!n.dom&&(i=r?r.nextSibling:s.firstChild)){let t=Ce.get(i);(!t||!t.parent&&t.canReuseDOM(n))&&n.reuseDOM(i)}n.sync(t,e),n.flags&=-8}if(i=r?r.nextSibling:s.firstChild,e&&!e.written&&e.node==s&&i!=n.dom&&(e.written=!0),n.dom.parentNode==s)for(;i&&i!=n.dom;)i=Oe(i);else s.insertBefore(n.dom,i);r=n.dom}for(i=r?r.nextSibling:s.firstChild,i&&e&&e.node==s&&(e.written=!0);i;)i=Oe(i)}else if(1&this.flags)for(let i of this.children)7&i.flags&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=0==fe(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==this.dom)break;0==s&&e.firstChild!=e.lastChild&&(s=t==e.firstChild?-1:1),t=e}i=s<0?t:t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!Ce.get(i);)i=i.nextSibling;if(!i)return this.length;for(let t=0,e=0;;t++){let s=this.children[t];if(s.dom==i)return e;e+=s.length+s.breakAfter}}domBoundsAround(t,e,i=0){let s=-1,r=-1,n=-1,h=-1;for(let l=0,o=i,u=i;l<this.children.length;l++){let i=this.children[l],f=o+i.length;if(o<t&&f>e)return i.domBoundsAround(t,e,o);if(f>=t&&-1==s&&(s=l,r=o),o>e&&i.dom.parentNode==this.dom){n=l,h=u;break}u=f,o=f+i.breakAfter}return{from:r,to:h<0?i+this.length:h,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:n<this.children.length&&n>=0?this.children[n].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),1&e.flags)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,7&this.flags&&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=Ae){this.markDirty();for(let s=t;s<e;s++){let t=this.children[s];t.parent==this&&i.indexOf(t)<0&&t.destroy()}this.children.splice(t,e-t,...i);for(let t=0;t<i.length;t++)i[t].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new De(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?"["+("Text"==t?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,s,r,n){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!(8&(this.flags|t.flags))}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}function Oe(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}Ce.prototype.breakAfter=0;class De{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||0==this.i||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 Ee(t,e,i,s,r,n,h,l,o){let{children:u}=t,f=u.length?u[e]:null,a=n.length?n[n.length-1]:null,c=a?a.breakAfter:h;if(!(e==s&&f&&!h&&!c&&n.length<2&&f.merge(i,r,n.length?a:null,0==i,l,o))){if(s<u.length){let t=u[s];t&&(r<t.length||t.breakAfter&&(null==a?void 0:a.breakAfter))?(e==s&&(t=t.split(r),r=0),!c&&a&&t.merge(0,r,a,!0,0,o)?n[n.length-1]=t:((r||t.children.length&&!t.children[0].length)&&t.merge(0,r,null,!1,0,o),n.push(t))):(null==t?void 0:t.breakAfter)&&(a?a.breakAfter=1:h=1),s++}for(f&&(f.breakAfter=h,i>0&&(!h&&n.length&&f.merge(i,f.length,n[0],!1,l,0)?f.breakAfter=n.shift().breakAfter:(i<f.length||f.children.length&&0==f.children[f.children.length-1].length)&&f.merge(i,f.length,null,!1,l,0),e++));e<s&&n.length;)if(u[s-1].become(n[n.length-1]))s--,n.pop(),o=n.length?0:l;else{if(!u[e].become(n[0]))break;e++,n.shift(),l=n.length?0:o}!n.length&&e&&s<u.length&&!u[e-1].breakAfter&&u[s].merge(0,0,u[e-1],!1,l,o)&&e--,(e<s||n.length)&&t.replaceChildren(e,s,n)}}function Ie(t,e,i,s,r,n){let h=t.childCursor(),{i:l,off:o}=h.findPos(i,1),{i:u,off:f}=h.findPos(e,-1),a=e-i;for(let t of s)a+=t.length;t.length+=a,Ee(t,u,f,l,o,s,0,r,n)}let Re="undefined"!=typeof navigator?navigator:{userAgent:"",vendor:"",platform:""},Te="undefined"!=typeof document?document:{documentElement:{style:{}}};const Be=/Edge\/(\d+)/.exec(Re.userAgent),Le=/MSIE \d/.test(Re.userAgent),Ne=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Re.userAgent),je=!!(Le||Ne||Be),$e=!je&&/gecko\/(\d+)/i.test(Re.userAgent),ze=!je&&/Chrome\/(\d+)/.exec(Re.userAgent),Pe="webkitFontSmoothing"in Te.documentElement.style,He=!je&&/Apple Computer/.test(Re.vendor),We=He&&(/Mobile\/\w+/.test(Re.userAgent)||Re.maxTouchPoints>2);var Ve={mac:We||/Mac/.test(Re.platform),windows:/Win/.test(Re.platform),linux:/Linux|X11/.test(Re.platform),ie:je,ie_version:Le?Te.documentMode||6:Ne?+Ne[1]:Be?+Be[1]:0,gecko:$e,gecko_version:$e?+(/Firefox\/(\d+)/.exec(Re.userAgent)||[0,0])[1]:0,chrome:!!ze,chrome_version:ze?+ze[1]:0,ios:We,android:/Android\b/.test(Re.userAgent),webkit:Pe,safari:He,webkit_version:Pe?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:null!=Te.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Fe extends Ce{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){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return!(8&this.flags||i&&(!(i instanceof Fe)||this.length-(e-t)+i.length>256||8&i.flags))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Fe(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=8&this.flags,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Se(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 function(t,e,i){let s=t.nodeValue.length;e>s&&(e=s);let r=e,n=e,h=0;0==e&&i<0||e==s&&i>=0?Ve.chrome||Ve.gecko||(e?(r--,h=1):n<s&&(n++,h=-1)):i<0?r--:n<s&&n++;let l=be(t,r,n).getClientRects();if(!l.length)return null;let o=l[(h?h<0:i>=0)?0:l.length-1];Ve.safari&&!h&&0==o.width&&(o=Array.prototype.find.call(l,(t=>t.width))||o);return h?ae(o,h<0):o||null}(this.dom,t,e)}}class qe extends Ce{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let t of e)t.setParent(this)}setAttrs(t){if(ke(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)&&!(8&(this.flags|t.flags))}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?4&this.flags&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,s,r,n){return(!i||!(!(i instanceof qe&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&n<=0))&&(Ie(this,t,e,i?i.children.slice():[],r-1,n-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let n of this.children){let h=i+n.length;h>t&&e.push(i<t?n.split(t-i):n),s<0&&i>=t&&(s=r),i=h,r++}let n=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new qe(this.mark,e,n)}domAtPos(t){return Ge(this,t)}coordsAt(t,e){return _e(this,t,e)}}class Ue extends Ce{static create(t,e,i){return new Ue(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Ue.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){this.dom&&this.widget.updateDOM(this.dom,t)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof Ue&&this.widget.compare(i.widget))||t>0&&r<=0||e<this.length&&n<=0))&&(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof Ue&&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)}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(0==this.length)return t.empty;let e=this;for(;e.parent;)e=e.parent;let{view:i}=e,s=i&&i.state.doc,r=this.posAtStart;return s?s.slice(r,r+this.length):t.empty}domAtPos(t){return(this.length?0==t:this.side>0)?Se.before(this.dom):Se.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let n=this.side?this.side<0:t>0;for(let e=n?s.length-1:0;r=s[e],!(t>0?0==e:e==s.length-1||r.top<r.bottom);e+=n?-1:1);return ae(r,!n)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Je extends Ce{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof Je&&t.side==this.side}split(){return new Je(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?Se.before(this.dom):Se.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return t.empty}get isHidden(){return!0}}function Ge(t,e){let i=t.dom,{children:s}=t,r=0;for(let t=0;r<s.length;r++){let n=s[r],h=t+n.length;if(!(h==t&&n.getSide()<=0)){if(e>t&&e<h&&n.dom.parentNode==i)return n.domAtPos(e-t);if(e<=t)break;t=h}}for(let t=r;t>0;t--){let e=s[t-1];if(e.dom.parentNode==i)return e.domAtPos(e.length)}for(let t=r;t<s.length;t++){let e=s[t];if(e.dom.parentNode==i)return e.domAtPos(0)}return new Se(i,0)}function Ke(t,e,i){let s,{children:r}=t;i>0&&e instanceof qe&&r.length&&(s=r[r.length-1])instanceof qe&&s.mark.eq(e.mark)?Ke(s,e.children[0],i-1):(r.push(e),e.setParent(t)),t.length+=e.length}function _e(t,e,i){let s=null,r=-1,n=null,h=-1;!function t(e,l){for(let o=0,u=0;o<e.children.length&&u<=l;o++){let f=e.children[o],a=u+f.length;a>=l&&(f.children.length?t(f,l-u):(!n||n.isHidden&&i>0)&&(a>l||u==a&&f.getSide()>0)?(n=f,h=l-u):(u<l||u==a&&f.getSide()<0&&!f.isHidden)&&(s=f,r=l-u)),u=a}}(t,e);let l=(i<0?s:n)||s||n;return l?l.coordsAt(Math.max(0,l==s?r:h),i):function(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let i=ne(e);return i[i.length-1]||null}(t)}function Xe(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}Fe.prototype.children=Ue.prototype.children=Je.prototype.children=Ae;const Ye=Object.create(null);function Qe(t,e,i){if(t==e)return!0;t||(t=Ye),e||(e=Ye);let s=Object.keys(t),r=Object.keys(e);if(s.length-(i&&s.indexOf(i)>-1?1:0)!=r.length-(i&&r.indexOf(i)>-1?1:0))return!1;for(let n of s)if(n!=i&&(-1==r.indexOf(n)||t[n]!==e[n]))return!1;return!0}function Ze(t,e,i){let s=!1;if(e)for(let r in e)i&&r in i||(s=!0,"style"==r?t.style.cssText="":t.removeAttribute(r));if(i)for(let r in i)e&&e[r]==i[r]||(s=!0,"style"==r?t.style.cssText=i[r]:t.setAttribute(r,i[r]));return s}function ti(t){let e=Object.create(null);for(let i=0;i<t.attributes.length;i++){let s=t.attributes[i];e[s.name]=s.value}return e}class ei extends Ce{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,n){if(i){if(!(i instanceof ei))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ie(this,t,e,i?i.children.slice():[],r,n),!0}split(t){let e=new ei;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let t=i;t<this.children.length;t++)e.append(this.children[t],0);for(;i>0&&0==this.children[i-1].length;)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=void 0===this.prevAttrs?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Qe(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Ke(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Xe(e,this.attrs||{})),i&&(this.attrs=Xe({class:i},this.attrs||{}))}domAtPos(t){return Ge(this,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?4&this.flags&&(ke(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),void 0!==this.prevAttrs&&(Ze(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let s=this.dom.lastChild;for(;s&&Ce.get(s)instanceof qe;)s=s.lastChild;if(!(s&&this.length&&("BR"==s.nodeName||0!=(null===(i=Ce.get(s))||void 0===i?void 0:i.isEditable)||Ve.ios&&this.children.some((t=>t instanceof Fe))))){let t=document.createElement("BR");t.cmIgnore=!0,this.dom.appendChild(t)}}measureTextSize(){if(0==this.children.length||this.length>20)return null;let t,e=0;for(let i of this.children){if(!(i instanceof Fe)||/[^ -~]/.test(i.text))return null;let s=ne(i.dom);if(1!=s.length)return null;e+=s[0].width,t=s[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(t,e){let i=_e(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:t}=this.parent.view.viewState,e=i.bottom-i.top;if(Math.abs(e-t.lineHeight)<2&&t.textHeight<e){let s=(e-t.textHeight)/2;return{top:i.top+s,bottom:i.bottom-s,left:i.left,right:i.left}}}return i}become(t){return!1}covers(){return!0}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],n=s+r.length;if(n>=e){if(r instanceof ei)return r;if(n>e)break}s=n+r.breakAfter}return null}}class ii extends Ce{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof ii&&this.widget.compare(i.widget))||t>0&&r<=0||e<this.length&&n<=0))&&(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return 0==t?Se.before(this.dom):Se.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new ii(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Ae}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):t.empty}domBoundsAround(){return null}become(t){return t instanceof ii&&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)}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e!=i&&(t<0?e<0:i>0)}}class si{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 ri=function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t}(ri||(ri={}));class ni extends Ct{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new hi(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 oi(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,s=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:r,end:n}=ui(t,s);e=(r?s?-3e8:-1:5e8)-1,i=1+(n?s?2e8:1:-6e8)}return new oi(t,e,i,s,t.widget||null,!0)}static line(t){return new li(t)}static set(t,e=!1){return It.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ni.none=It.empty;class hi extends ni{constructor(t){let{start:e,end:i}=ui(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 hi&&this.tagName==t.tagName&&(this.class||(null===(e=this.attrs)||void 0===e?void 0:e.class))==(t.class||(null===(i=t.attrs)||void 0===i?void 0:i.class))&&Qe(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)}}hi.prototype.point=!1;class li extends ni{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof li&&this.spec.class==t.spec.class&&Qe(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}li.prototype.mapMode=x.TrackBefore,li.prototype.point=!0;class oi extends ni{constructor(t,e,i,s,r,n){super(e,i,r,t),this.block=s,this.isReplace=n,this.mapMode=s?e<=0?x.TrackBefore:x.TrackAfter:x.TrackDel}get type(){return this.startSide!=this.endSide?ri.WidgetRange:this.startSide<=0?ri.WidgetBefore:ri.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof oi&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}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)}}function ui(t,e=!1){let{inclusiveStart:i,inclusiveEnd:s}=t;return null==i&&(i=t.inclusive),null==s&&(s=t.inclusive),{start:null!=i?i:e,end:null!=s?s:e}}function fi(t,e,i,s=0){let r=i.length-1;r>=0&&i[r]+s>=t?i[r]=Math.max(i[r],e):i.push(t,e)}oi.prototype.point=!0;class ai{constructor(t,e,i,s){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(0==this.content.length)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof ii&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new ei),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(ci(new Je(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||t&&this.content.length&&this.content[this.content.length-1]instanceof ii||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skip);if(this.skip=0,s)throw new Error("Ran out of text content when drawing inline views");if(i){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}this.text=e,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(ci(new Fe(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,n){if(this.disallowBlockEffectsFor[n]&&i instanceof oi){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 h=e-t;if(i instanceof oi)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new ii(i.widget||di.block,h,i));else{let n=Ue.create(i.widget||di.inline,h,h?0:i.startSide),l=this.atCursorPos&&!n.isEditable&&r<=s.length&&(t<e||i.startSide>0),o=!n.isEditable&&(t<e||r>s.length||i.startSide<=0),u=this.getLine();2!=this.pendingBuffer||l||n.isEditable||(this.pendingBuffer=0),this.flushBuffer(s),l&&(u.append(ci(new Je(1),s),r),r=s.length+Math.max(0,r-s.length)),u.append(ci(n,s),r),this.atCursorPos=o,this.pendingBuffer=o?t<e||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);h&&(this.textOff+h<=this.text.length?this.textOff+=h:(this.skip+=h-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let n=new ai(t,e,i,r);return n.openEnd=It.spans(s,e,i,n),n.openStart<0&&(n.openStart=n.openEnd),n.finish(n.openEnd),n}}function ci(t,e){for(let i of e)t=new qe(i,[t],t.length);return t}class di extends si{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}}di.inline=new di("span"),di.block=new di("div");var pi=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(pi||(pi={}));const mi=pi.LTR,gi=pi.RTL;function wi(t){let e=[];for(let i=0;i<t.length;i++)e.push(1<<+t[i]);return e}const bi=wi("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),vi=wi("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),ki=Object.create(null),yi=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),i=t.charCodeAt(1);ki[e]=i,ki[i]=-e}function Mi(t){return t<=247?bi[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?vi[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}const xi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Si{get dir(){return this.level%2?gi:mi}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let r=-1;for(let n=0;n<t.length;n++){let h=t[n];if(h.from<=e&&h.to>=e){if(h.level==i)return n;(r<0||(0!=s?s<0?h.from<e:h.to>e:t[r].level>h.level))&&(r=n)}}if(r<0)throw new RangeError("Index out of range");return r}}function Ai(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.direction!=r.direction||!Ai(s.inner,r.inner))return!1}return!0}const Ci=[];function Oi(t,e,i,s,r,n,h){let l=s%2?2:1;if(s%2==r%2)for(let o=e,u=0;o<i;){let e=!0,f=!1;if(u==n.length||o<n[u].from){let t=Ci[o];t!=l&&(e=!1,f=16==t)}let a=e||1!=l?null:[],c=e?s:s+1,d=o;t:for(;;)if(u<n.length&&d==n[u].from){if(f)break t;let p=n[u];if(!e)for(let t=p.to,e=u+1;;){if(t==i)break t;if(!(e<n.length&&n[e].from==t)){if(Ci[t]==l)break t;break}t=n[e++].to}if(u++,a)a.push(p);else{p.from>o&&h.push(new Si(o,p.from,c)),Di(t,p.direction==mi!=!(c%2)?s+1:s,r,p.inner,p.from,p.to,h),o=p.to}d=p.to}else{if(d==i||(e?Ci[d]!=l:Ci[d]==l))break;d++}a?Oi(t,o,d,s+1,r,a,h):o<d&&h.push(new Si(o,d,c)),o=d}else for(let o=i,u=n.length;o>e;){let i=!0,f=!1;if(!u||o>n[u-1].to){let t=Ci[o-1];t!=l&&(i=!1,f=16==t)}let a=i||1!=l?null:[],c=i?s:s+1,d=o;t:for(;;)if(u&&d==n[u-1].to){if(f)break t;let p=n[--u];if(!i)for(let t=p.from,i=u;;){if(t==e)break t;if(!i||n[i-1].to!=t){if(Ci[t-1]==l)break t;break}t=n[--i].from}if(a)a.push(p);else{p.to<o&&h.push(new Si(p.to,o,c)),Di(t,p.direction==mi!=!(c%2)?s+1:s,r,p.inner,p.from,p.to,h),o=p.from}d=p.from}else{if(d==e||(i?Ci[d-1]!=l:Ci[d-1]==l))break;d--}a?Oi(t,d,o,s+1,r,a,h):d<o&&h.push(new Si(d,o,c)),o=d}}function Di(t,e,i,s,r,n,h){let l=e%2?2:1;!function(t,e,i,s,r){for(let n=0;n<=s.length;n++){let h=n?s[n-1].to:e,l=n<s.length?s[n].from:i,o=n?256:r;for(let e=h,i=o,s=o;e<l;e++){let r=Mi(t.charCodeAt(e));512==r?r=i:8==r&&4==s&&(r=16),Ci[e]=4==r?2:r,7&r&&(s=r),i=r}for(let t=h,e=o,s=o;t<l;t++){let r=Ci[t];if(128==r)t<l-1&&e==Ci[t+1]&&24&e?r=Ci[t]=e:Ci[t]=256;else if(64==r){let r=t+1;for(;r<l&&64==Ci[r];)r++;let n=t&&8==e||r<i&&8==Ci[r]?1==s?1:8:256;for(let e=t;e<r;e++)Ci[e]=n;t=r-1}else 8==r&&1==s&&(Ci[t]=1);e=r,7&r&&(s=r)}}}(t,r,n,s,l),function(t,e,i,s,r){let n=1==r?2:1;for(let h=0,l=0,o=0;h<=s.length;h++){let u=h?s[h-1].to:e,f=h<s.length?s[h].from:i;for(let e,i,s,h=u;h<f;h++)if(i=ki[e=t.charCodeAt(h)])if(i<0){for(let t=l-3;t>=0;t-=3)if(yi[t+1]==-i){let e=yi[t+2],i=2&e?r:4&e?1&e?n:r:0;i&&(Ci[h]=Ci[yi[t]]=i),l=t;break}}else{if(189==yi.length)break;yi[l++]=h,yi[l++]=e,yi[l++]=o}else if(2==(s=Ci[h])||1==s){let t=s==r;o=t?0:1;for(let e=l-3;e>=0;e-=3){let i=yi[e+2];if(2&i)break;if(t)yi[e+2]|=2;else{if(4&i)break;yi[e+2]|=4}}}}}(t,r,n,s,l),function(t,e,i,s){for(let r=0,n=s;r<=i.length;r++){let h=r?i[r-1].to:t,l=r<i.length?i[r].from:e;for(let o=h;o<l;){let h=Ci[o];if(256==h){let h=o+1;for(;;)if(h==l){if(r==i.length)break;h=i[r++].to,l=r<i.length?i[r].from:e}else{if(256!=Ci[h])break;h++}let u=1==n,f=u==(1==(h<e?Ci[h]:s))?u?1:2:s;for(let e=h,s=r,n=s?i[s-1].to:t;e>o;)e==n&&(e=i[--s].from,n=s?i[s-1].to:t),Ci[--e]=f;o=h}else n=h,o++}}}(r,n,s,l),Oi(t,r,n,e,i,s,h)}function Ei(t){return[new Si(0,t,0)]}let Ii="";function Ri(t,e,i,s,r){var n;let h=s.head-t.from,l=Si.find(e,h,null!==(n=s.bidiLevel)&&void 0!==n?n:-1,s.assoc),o=e[l],u=o.side(r,i);if(h==u){let t=l+=r?1:-1;if(t<0||t>=e.length)return null;o=e[l=t],h=o.side(!r,i),u=o.side(r,i)}let f=p(t.text,h,o.forward(r,i));(f<o.from||f>o.to)&&(f=u),Ii=t.text.slice(Math.min(h,f),Math.max(h,f));let a=l==(r?e.length-1:0)?null:e[l+(r?1:-1)];return a&&f==u&&a.level+(r?0:1)<o.level?B.cursor(a.side(!r,i)+t.from,a.forward(r,i)?1:-1,a.level):B.cursor(f+t.from,o.forward(r,i)?-1:1,o.level)}function Ti(t,e,i){for(let s=e;s<i;s++){let e=Mi(t.charCodeAt(s));if(1==e)return mi;if(2==e||4==e)return gi}return mi}const Bi=j.define(),Li=j.define(),Ni=j.define(),ji=j.define(),$i=j.define(),zi=j.define(),Pi=j.define(),Hi=j.define({combine:t=>t.some((t=>t))}),Wi=j.define({combine:t=>t.some((t=>t))}),Vi=j.define();class Fi{constructor(t,e="nearest",i="nearest",s=5,r=5,n=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=n}map(t){return t.empty?this:new Fi(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 Fi(B.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const qi=ct.define({map:(t,e)=>t.map(e)});function Ui(t,e,i){let s=t.facet(ji);s.length?s[0](e):window.onerror?window.onerror(String(e),i,void 0,void 0,e):i?console.error(i+":",e):console.error(e)}const Ji=j.define({combine:t=>!t.length||t[0]});let Gi=0;const Ki=j.define();class _i{constructor(t,e,i,s,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:r,decorations:n}=e||{};return new _i(Gi++,t,i,s,(t=>{let e=[Ki.of(t)];return n&&e.push(Zi.of((e=>{let i=e.plugin(t);return i?n(i):ni.none}))),r&&e.push(r(t)),e}))}static fromClass(t,e){return _i.define((e=>new t(e)),e)}}class Xi{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(Ui(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Ui(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){Ui(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Yi=j.define(),Qi=j.define(),Zi=j.define(),ts=j.define(),es=j.define(),is=j.define();function ss(t,e){let i=t.state.facet(is);if(!i.length)return i;let s=i.map((e=>e instanceof Function?e(t):e)),r=[];return It.spans(s,e.from,e.to,{point(){},span(t,i,s,n){let h=t-e.from,l=i-e.from,o=r;for(let t=s.length-1;t>=0;t--,n--){let i,r=s[t].spec.bidiIsolate;if(null==r&&(r=Ti(e.text,h,l)),n>0&&o.length&&(i=o[o.length-1]).to==h&&i.direction==r)i.to=l,o=i.inner;else{let t={from:h,to:l,direction:r,inner:[]};o.push(t),o=t.inner}}}}),r}const rs=j.define();function ns(t){let e=0,i=0,s=0,r=0;for(let n of t.state.facet(rs)){let h=n(t);h&&(null!=h.left&&(e=Math.max(e,h.left)),null!=h.right&&(i=Math.max(i,h.right)),null!=h.top&&(s=Math.max(s,h.top)),null!=h.bottom&&(r=Math.max(r,h.bottom)))}return{left:e,right:i,top:s,bottom:r}}const hs=j.define();class ls{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new ls(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(0==e.length)return t;let i=[];for(let s=0,r=0,n=0,h=0;;s++){let l=s==t.length?null:t[s],o=n-h,u=l?l.fromB:1e9;for(;r<e.length&&e[r]<u;){let t=e[r],s=e[r+1],n=Math.max(h,t),l=Math.min(u,s);if(n<=l&&new ls(n+o,l+o,n,l).addToSet(i),s>u)break;r+=2}if(!l)return i;new ls(l.fromA,l.toA,l.fromB,l.toB).addToSet(i),n=l.toA,h=l.toB}}}class os{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=A.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let s=[];this.changes.iterChangedRanges(((t,e,i,r)=>s.push(new ls(t,e,i,r)))),this.changedRanges=s}static create(t,e,i){return new os(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(10&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((t=>t.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}class us extends Ce{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,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 ei],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new ls(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:t,toA:e})=>e<this.minWidthFrom||t>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);let s=-1;this.view.inputState.composing>=0&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?s=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges(((t,s)=>{t<e.to&&s>e.from&&(i=!0)}));return i}(t.changes,this.hasComposition)||t.selectionSet||(s=t.state.selection.main.head));let r=s>-1?function(t,e,i){let s=as(t,i);if(!s)return null;let{node:r,from:n,to:h}=s,l=r.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(s.from,s.to)!=l)return null;let o=e.invertedDesc,u=new ls(o.mapPos(n),o.mapPos(h),n,h),f=[];for(let e=r.parentNode;;e=e.parentNode){let i=Ce.get(e);if(i instanceof qe)f.push({node:e,deco:i.mark});else{if(i instanceof ei||"DIV"==e.nodeName&&e.parentNode==t.contentDOM)return{range:u,text:r,marks:f,line:e};if(e==t.contentDOM)return null;f.push({node:e,deco:new hi({inclusive:!0,attributes:ti(e),tagName:e.tagName.toLowerCase()})})}}}(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:e,to:s}=this.hasComposition;i=new ls(e,s,t.changes.mapPos(e,-1),t.changes.mapPos(s,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(Ve.ie||Ve.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let n=function(t,e,i){let s=new cs;return It.compare(t,e,i,s),s.changes}(this.decorations,this.updateDeco(),t.changes);return i=ls.extendWithRanges(i,n),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:s}=this.view;s.ignore((()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=Ve.chrome||Ve.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,t),this.flags&=-8,t&&(t.written||s.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""})),this.markedForComposition.forEach((t=>t.flags&=-9));let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let t of this.children)t instanceof ii&&t.widget instanceof fs&&r.push(t.dom);s.updateGaps(r)}updateChildren(t,e,i){let s=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let t=s.length-1;;t--){let e=t>=0?s[t]:null;if(!e)break;let n,h,l,o,{fromA:u,toA:f,fromB:a,toB:c}=e;if(i&&i.range.fromB<c&&i.range.toB>a){let t=ai.build(this.view.state.doc,a,i.range.fromB,this.decorations,this.dynamicDecorationMap),e=ai.build(this.view.state.doc,i.range.toB,c,this.decorations,this.dynamicDecorationMap);h=t.breakAtStart,l=t.openStart,o=e.openEnd;let s=this.compositionView(i);e.breakAtStart?s.breakAfter=1:e.content.length&&s.merge(s.length,s.length,e.content[0],!1,e.openStart,0)&&(s.breakAfter=e.content[0].breakAfter,e.content.shift()),t.content.length&&s.merge(0,0,t.content[t.content.length-1],!0,0,t.openEnd)&&t.content.pop(),n=t.content.concat(s).concat(e.content)}else({content:n,breakAtStart:h,openStart:l,openEnd:o}=ai.build(this.view.state.doc,a,c,this.decorations,this.dynamicDecorationMap));let{i:d,off:p}=r.findPos(f,1),{i:m,off:g}=r.findPos(u,-1);Ee(this,m,g,d,p,n,h,l,o)}i&&this.fixCompositionDOM(i)}compositionView(t){let e=new Fe(t.text.nodeValue);e.flags|=8;for(let{deco:i}of t.marks)e=new qe(i,[e],e.length);let i=new ei;return i.append(e,0),i}fixCompositionDOM(t){let e=(t,e)=>{e.flags|=8|(e.children.some((t=>7&t.flags))?1:0),this.markedForComposition.add(e);let i=Ce.get(t);i&&i!=e&&(i.dom=null),e.setDOM(t)},i=this.childPos(t.range.fromB,1),s=this.children[i.i];e(t.line,s);for(let r=t.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],e(r>=0?t.marks[r].node:t.text,s)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&re(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||e||r))return;let n=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,l=this.moveToLine(this.domAtPos(h.anchor)),o=h.empty?l:this.moveToLine(this.domAtPos(h.head));if(Ve.gecko&&h.empty&&!this.hasComposition&&(1==(u=l).node.nodeType&&u.node.firstChild&&(0==u.offset||"false"==u.node.childNodes[u.offset-1].contentEditable)&&(u.offset==u.node.childNodes.length||"false"==u.node.childNodes[u.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore((()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null))),l=o=new Se(t,0),n=!0}var u;let f=this.view.observer.selectionRange;!n&&f.focusNode&&(he(l.node,l.offset,f.anchorNode,f.anchorOffset)&&he(o.node,o.offset,f.focusNode,f.focusOffset)||this.suppressWidgetCursorChange(f,h))||(this.view.observer.ignore((()=>{Ve.android&&Ve.chrome&&this.dom.contains(f.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(f.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=ie(this.view.root);if(t)if(h.empty){if(Ve.gecko){let t=(e=l.node,s=l.offset,1!=e.nodeType?0:(s&&"false"==e.childNodes[s-1].contentEditable?1:0)|(s<e.childNodes.length&&"false"==e.childNodes[s].contentEditable?2:0));if(t&&3!=t){let e=(1==t?Me:xe)(l.node,l.offset);e&&(l=new Se(e.node,e.offset))}}t.collapse(l.node,l.offset),null!=h.bidiLevel&&void 0!==t.caretBidiLevel&&(t.caretBidiLevel=h.bidiLevel)}else if(t.extend){t.collapse(l.node,l.offset);try{t.extend(o.node,o.offset)}catch(t){}}else{let e=document.createRange();h.anchor>h.head&&([l,o]=[o,l]),e.setEnd(o.node,o.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,s;r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())})),this.view.observer.setSelectionRange(l,o)),this.impreciseAnchor=l.precise?null:new Se(f.anchorNode,f.anchorOffset),this.impreciseHead=o.precise?null:new Se(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&he(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=ie(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let n=ei.find(this,e.head);if(!n)return;let h=n.posAtStart;if(e.head==h||e.head==h+n.length)return;let l=this.coordsAt(e.head,-1),o=this.coordsAt(e.head,1);if(!l||!o||l.bottom>o.top)return;let u=this.domAtPos(e.head+e.assoc);i.collapse(u.node,u.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(s,r)}moveToLine(t){let e,i=this.dom;if(t.node!=i)return t;for(let s=t.offset;!e&&s<i.childNodes.length;s++){let t=Ce.get(i.childNodes[s]);t instanceof ei&&(e=t.domAtPos(0))}for(let s=t.offset-1;!e&&s>=0;s--){let t=Ce.get(i.childNodes[s]);t instanceof ei&&(e=t.domAtPos(t.length))}return e?new Se(e.node,e.offset,!0):t}nearest(t){for(let e=t;e;){let t=Ce.get(e);if(t&&t.rootView==this)return t;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 t=this.children[e];if(i<t.length||t instanceof ei)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,s=0;for(let r=this.length,n=this.children.length-1;n>=0;n--){let h=this.children[n],l=r-h.breakAfter,o=l-h.length;if(l<t)break;o<=t&&(o<t||h.covers(-1))&&(l>t||h.covers(1))&&(!i||h instanceof ei&&!(i instanceof ei&&e>=0))&&(i=h,s=o),r=o}return i?i.coordsAt(t-s,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),s=this.children[e];if(!(s instanceof ei))return null;for(;s.children.length;){let{i:t,off:e}=s.childPos(i,1);for(;;t++){if(t==s.children.length)return null;if((s=s.children[t]).length)break}i=e}if(!(s instanceof Fe))return null;let r=p(s.text,i);if(r==i)return null;let n=be(s.dom,i,r).getClientRects();for(let t=0;t<n.length;t++){let e=n[t];if(t==n.length-1||e.top<e.bottom&&e.left<e.right)return e}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,n=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,h=-1,l=this.view.textDirection==pi.LTR;for(let t=0,o=0;o<this.children.length;o++){let u=this.children[o],f=t+u.length;if(f>s)break;if(t>=i){let i=u.dom.getBoundingClientRect();if(e.push(i.height),n){let e=u.dom.lastChild,s=e?ne(e):[];if(s.length){let e=s[s.length-1],n=l?e.right-i.left:i.right-e.left;n>h&&(h=n,this.minWidth=r,this.minWidthFrom=t,this.minWidthTo=f)}}}t=f+u.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?pi.RTL:pi.LTR}measureTextSize(){for(let t of this.children)if(t instanceof ei){let e=t.measureTextSize();if(e)return e}let t,e,i,s=document.createElement("div");return s.className="cm-line",s.style.width="99999px",s.style.position="absolute",s.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(s);let r=ne(s.firstChild)[0];t=s.getBoundingClientRect().height,e=r?r.width/27:7,i=r?r.height:t,s.remove()})),{lineHeight:t,charWidth:e,textHeight:i}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new De(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],n=r?r.from-1:this.length;if(n>i){let s=(e.lineBlockAt(n).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(ni.replace({widget:new fs(s),block:!0,inclusive:!0,isBlockGap:!0}).range(i,n))}if(!r)break;i=r.to+1}return ni.set(t)}updateDeco(){let t=0,e=this.view.state.facet(Zi).map((e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e)),i=!1,s=this.view.state.facet(ts).map(((t,e)=>{let s="function"==typeof t;return s&&(i=!0),s?t(this.view):t}));for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(It.join(s))),this.decorations=[...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);return this.view.scrollDOM.scrollTop=e.top-t.yMargin,void(this.view.scrollDOM.scrollLeft=t.xMargin)}for(let e of this.view.state.facet(Vi))try{if(e(this.view,t.range,t))return!0}catch(t){Ui(this.view.state,t,"scroll handler")}let e,{range:i}=t,s=this.coordsAt(i.head,i.empty?i.assoc:i.head>i.anchor?-1:1);if(!s)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,e.left),top:Math.min(s.top,e.top),right:Math.max(s.right,e.right),bottom:Math.max(s.bottom,e.bottom)});let r=ns(this.view),n={left:s.left-r.left,top:s.top-r.top,right:s.right+r.right,bottom:s.bottom+r.bottom},{offsetWidth:h,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,s,r,n,h,l){let o=t.ownerDocument,u=o.defaultView||window;for(let f=t,a=!1;f&&!a;)if(1==f.nodeType){let t,c=f==o.body,d=1,p=1;if(c)t=ce(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(a=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let e=f.getBoundingClientRect();({scaleX:d,scaleY:p}=de(f,e)),t={left:e.left,right:e.left+f.clientWidth*d,top:e.top,bottom:e.top+f.clientHeight*p}}let m=0,g=0;if("nearest"==r)e.top<t.top?(g=-(t.top-e.top+h),i>0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+g+h)):e.bottom>t.bottom&&(g=e.bottom-t.bottom+h,i<0&&e.top-g<t.top&&(g=-(t.top+g-e.top+h)));else{let s=e.bottom-e.top,n=t.bottom-t.top;g=("center"==r&&s<=n?e.top+s/2-n/2:"start"==r||"center"==r&&i<0?e.top-h:e.bottom-n+h)-t.top}if("nearest"==s?e.left<t.left?(m=-(t.left-e.left+n),i>0&&e.right>t.right+m&&(m=e.right-t.right+m+n)):e.right>t.right&&(m=e.right-t.right+n,i<0&&e.left<t.left+m&&(m=-(t.left+m-e.left+n))):m=("center"==s?e.left+(e.right-e.left)/2-(t.right-t.left)/2:"start"==s==l?e.left-n:e.right-(t.right-t.left)+n)-t.left,m||g)if(c)u.scrollBy(m,g);else{let t=0,i=0;if(g){let t=f.scrollTop;f.scrollTop+=g/p,i=(f.scrollTop-t)*p}if(m){let e=f.scrollLeft;f.scrollLeft+=m/d,t=(f.scrollLeft-e)*d}e={left:e.left-t,top:e.top-i,right:e.right-t,bottom:e.bottom-i},t&&Math.abs(t-m)<1&&(s="nearest"),i&&Math.abs(i-g)<1&&(r="nearest")}if(c)break;f=f.assignedSlot||f.parentNode}else{if(11!=f.nodeType)break;f=f.host}}(this.view.scrollDOM,n,i.head<i.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,h),-h),Math.max(Math.min(t.yMargin,l),-l),this.view.textDirection==pi.LTR)}}class fs extends si{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function as(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let s=Me(i.focusNode,i.focusOffset),r=xe(i.focusNode,i.focusOffset),n=s||r;if(r&&s&&r.node!=s.node){let e=Ce.get(r.node);if(!e||e instanceof Fe&&e.text!=r.node.nodeValue)n=r;else if(t.docView.lastCompositionAfterCursor){let t=Ce.get(s.node);!t||t instanceof Fe&&t.text!=s.node.nodeValue||(n=r)}}if(t.docView.lastCompositionAfterCursor=n!=s,!n)return null;let h=e-n.offset;return{from:h,to:h+n.node.nodeValue.length,node:n.node}}let cs=class{constructor(){this.changes=[]}compareRange(t,e){fi(t,e,this.changes)}comparePoint(t,e){fi(t,e,this.changes)}};function ds(t,e){return e.left>t?e.left-t:Math.max(0,t-e.right)}function ps(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function ms(t,e){return t.top<e.bottom-1&&t.bottom>e.top+1}function gs(t,e){return e<t.top?{top:e,left:t.left,right:t.right,bottom:t.bottom}:t}function ws(t,e){return e>t.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function bs(t,e,i){let s,r,n,h,l,o,u,f,a=!1;for(let c=t.firstChild;c;c=c.nextSibling){let t=ne(c);for(let d=0;d<t.length;d++){let p=t[d];r&&ms(r,p)&&(p=gs(ws(p,r.bottom),r.top));let m=ds(e,p),g=ps(i,p);if(0==m&&0==g)return 3==c.nodeType?vs(c,e,i):bs(c,e,i);if(!s||h>g||h==g&&n>m){s=c,r=p,n=m,h=g;let l=g?i<p.top?-1:1:m?e<p.left?-1:1:0;a=!l||(l>0?d<t.length-1:d>0)}0==m?i>p.bottom&&(!u||u.bottom<p.bottom)?(l=c,u=p):i<p.top&&(!f||f.top>p.top)&&(o=c,f=p):u&&ms(u,p)?u=ws(u,p.bottom):f&&ms(f,p)&&(f=gs(f,p.top))}}if(u&&u.bottom>=i?(s=l,r=u):f&&f.top<=i&&(s=o,r=f),!s)return{node:t,offset:0};let c=Math.max(r.left,Math.min(r.right,e));return 3==s.nodeType?vs(s,c,i):a&&"false"!=s.contentEditable?bs(s,c,i):{node:t,offset:Array.prototype.indexOf.call(t.childNodes,s)+(e>=(r.left+r.right)/2?1:0)}}function vs(t,e,i){let s=t.nodeValue.length,r=-1,n=1e9,h=0;for(let l=0;l<s;l++){let s=be(t,l,l+1).getClientRects();for(let o=0;o<s.length;o++){let u=s[o];if(u.top==u.bottom)continue;h||(h=e-u.left);let f=(u.top>i?u.top-i:i-u.bottom)-1;if(u.left-1<=e&&u.right+1>=e&&f<n){let i=e>=(u.left+u.right)/2,s=i;if(Ve.chrome||Ve.gecko){be(t,l).getBoundingClientRect().left==u.right&&(s=!i)}if(f<=0)return{node:t,offset:l+(s?1:0)};r=l+(s?1:0),n=f}}}return{node:t,offset:r>-1?r:h>0?t.nodeValue.length:0}}function ks(t,e,i,s=-1){var r,n;let h,l=t.contentDOM.getBoundingClientRect(),o=l.top+t.viewState.paddingTop,{docHeight:u}=t.viewState,{x:f,y:a}=e,c=a-o;if(c<0)return 0;if(c>u)return t.state.doc.length;for(let e=t.viewState.heightOracle.textHeight/2,r=!1;h=t.elementAtHeight(c),h.type!=ri.Text;)for(;c=s>0?h.bottom+e:h.top-e,!(c>=0&&c<=u);){if(r)return i?null:0;r=!0,s=-s}a=o+c;let d=h.from;if(d<t.viewport.from)return 0==t.viewport.from?0:i?null:ys(t,l,h,f,a);if(d>t.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:i?null:ys(t,l,h,f,a);let p=t.dom.ownerDocument,m=t.root.elementFromPoint?t.root:p,g=m.elementFromPoint(f,a);g&&!t.contentDOM.contains(g)&&(g=null),g||(f=Math.max(l.left+1,Math.min(l.right-1,f)),g=m.elementFromPoint(f,a),g&&!t.contentDOM.contains(g)&&(g=null));let w,b=-1;if(g&&0!=(null===(r=t.docView.nearest(g))||void 0===r?void 0:r.isEditable))if(p.caretPositionFromPoint){let t=p.caretPositionFromPoint(f,a);t&&({offsetNode:w,offset:b}=t)}else if(p.caretRangeFromPoint){let e=p.caretRangeFromPoint(f,a);e&&(({startContainer:w,startOffset:b}=e),(!t.contentDOM.contains(w)||Ve.safari&&function(t,e,i){let s;if(3!=t.nodeType||e!=(s=t.nodeValue.length))return!1;for(let e=t.nextSibling;e;e=e.nextSibling)if(1!=e.nodeType||"BR"!=e.nodeName)return!1;return be(t,s-1,s).getBoundingClientRect().left>i}(w,b,f)||Ve.chrome&&function(t,e,i){if(0!=e)return!1;for(let e=t;;){let t=e.parentNode;if(!t||1!=t.nodeType||t.firstChild!=e)return!1;if(t.classList.contains("cm-line"))break;e=t}let s=1==t.nodeType?t.getBoundingClientRect():be(t,0,Math.max(t.nodeValue.length,1)).getBoundingClientRect();return i-s.left>5}(w,b,f))&&(w=void 0))}if(!w||!t.docView.dom.contains(w)){let e=ei.find(t.docView,d);if(!e)return c>h.top+h.height/2?h.to:h.from;({node:w,offset:b}=bs(e.dom,f,a))}let v=t.docView.nearest(w);if(!v)return null;if(v.isWidget&&1==(null===(n=v.dom)||void 0===n?void 0:n.nodeType)){let t=v.dom.getBoundingClientRect();return e.y<t.top||e.y<=t.bottom&&e.x<=(t.left+t.right)/2?v.posAtStart:v.posAtEnd}return v.localPosFromDOM(w,b)+v.posAtStart}function ys(t,e,i,s,r){let n=Math.round((s-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;n+=Math.floor((r-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let h=t.state.sliceDoc(i.from,i.to);return i.from+Ft(h,n,t.state.tabSize)}function Ms(t,e){let i=t.lineBlockAt(e);if(Array.isArray(i.type))for(let t of i.type)if(t.to>e||t.to==e&&(t.to==i.to||t.type==ri.Text))return t;return i}function xs(t,e,i,s){let r=t.state.doc.lineAt(e.head),n=t.bidiSpans(r),h=t.textDirectionAt(r.from);for(let l=e,o=null;;){let e=Ri(r,n,h,l,i),u=Ii;if(!e){if(r.number==(i?t.state.doc.lines:1))return l;u="\n",r=t.state.doc.line(r.number+(i?1:-1)),n=t.bidiSpans(r),e=t.visualLineSide(r,!i)}if(o){if(!o(u))return l}else{if(!s)return e;o=s(u)}l=e}}function Ss(t,e,i){for(;;){let s=0;for(let r of t)r.between(e-1,e+1,((t,r,n)=>{if(e>t&&e<r){let n=s||i||(e-t<r-e?-1:1);e=n<0?t:r,s=n}}));if(!s)return e}}function As(t,e,i){let s=Ss(t.state.facet(es).map((e=>e(t))),i.from,e.head>i.from?-1:1);return s==i.from?i:B.cursor(s,s<i.from?1:-1)}class Cs{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.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,Ve.safari&&t.contentDOM.addEventListener("input",(()=>null)),Ve.gecko&&function(t){Zs.has(t)||(Zs.add(t),t.addEventListener("copy",(()=>{})),t.addEventListener("cut",(()=>{})))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,s=e.target;s!=t.contentDOM;s=s.parentNode)if(!s||11==s.nodeType||(i=Ce.get(s))&&i.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Ds(t),i=this.handlers,s=this.view.contentDOM;for(let t in e)if("scroll"!=t){let r=!e[t].handlers.length,n=i[t];n&&r!=!n.handlers.length&&(s.removeEventListener(t,this.handleEvent),n=null),n||s.addEventListener(t,this.handleEvent,{passive:r})}for(let t in i)"scroll"==t||e[t]||s.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&Date.now()<this.lastEscPress+2e3)return!0;if(27!=t.keyCode&&Rs.indexOf(t.keyCode)<0&&(this.view.inputState.lastEscPress=0),Ve.android&&Ve.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!Ve.ios||t.synthetic||t.altKey||t.metaKey||!((e=Es.find((e=>e.keyCode==t.keyCode)))&&!t.ctrlKey||Is.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout((()=>this.flushIOSKey()),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString()))&&(this.pendingIOSKey=void 0,ve(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0)))}ignoreDuringComposition(t){return!!/^key/.test(t.type)&&(this.composing>0||!!(Ve.safari&&!Ve.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}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 Os(t,e){return(i,s)=>{try{return e.call(t,s,i)}catch(t){Ui(i.state,t)}}}function Ds(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec;if(t&&t.domEventHandlers)for(let s in t.domEventHandlers){let r=t.domEventHandlers[s];r&&i(s).handlers.push(Os(e.value,r))}if(t&&t.domEventObservers)for(let s in t.domEventObservers){let r=t.domEventObservers[s];r&&i(s).observers.push(Os(e.value,r))}}for(let t in Ls)i(t).handlers.push(Ls[t]);for(let t in Ns)i(t).observers.push(Ns[t]);return e}const Es=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Is="dthko",Rs=[16,17,18,20,91,92,224,225];function Ts(t){return.7*Math.max(0,t)+8}class Bs{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParent=function(t){let e=t.ownerDocument;for(let i=t.parentNode;i&&i!=e.body;)if(1==i.nodeType){if(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)return i;i=i.assignedSlot||i.parentNode}else{if(11!=i.nodeType)break;i=i.host}return null}(t.contentDOM),this.atoms=t.state.facet(es).map((e=>e(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(St.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Bi);return i.length?i[0](e):Ve.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let s=ie(t.root);if(!s||0==s.rangeCount)return!0;let r=s.getRangeAt(0).getClientRects();for(let t=0;t<r.length;t++){let i=r[t];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=Gs(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){var e,i,s;if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(i=this.startEvent,s=t,Math.max(Math.abs(i.clientX-s.clientX),Math.abs(i.clientY-s.clientY))<10))return;this.select(this.lastEvent=t);let r=0,n=0,h=(null===(e=this.scrollParent)||void 0===e?void 0:e.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},l=ns(this.view);t.clientX-l.left<=h.left+6?r=-Ts(h.left-t.clientX):t.clientX+l.right>=h.right-6&&(r=Ts(t.clientX-h.right)),t.clientY-l.top<=h.top+6?n=-Ts(h.top-t.clientY):t.clientY+l.bottom>=h.bottom-6&&(n=Ts(t.clientY-h.bottom)),this.setScrollSpeed(r,n)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval((()=>this.scroll()),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let t=Ss(this.atoms,s.from,0);t!=s.from&&(r=B.cursor(t,-1))}else{let t=Ss(this.atoms,s.from,-1),e=Ss(this.atoms,s.to,1);t==s.from&&e==s.to||(r=B.range(s.from==s.anchor?t:e,s.from==s.head?t:e))}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,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){this.style.update(t)&&setTimeout((()=>this.select(this.lastEvent)),20)}}const Ls=Object.create(null),Ns=Object.create(null),js=Ve.ie&&Ve.ie_version<15||Ve.ios&&Ve.webkit_version<604;function $s(t,e){let i,{state:s}=t,r=1,n=s.toText(e),h=n.lines==s.selection.ranges.length;if(null!=_s&&s.selection.ranges.every((t=>t.empty))&&_s==n.toString()){let t=-1;i=s.changeByRange((i=>{let l=s.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let o=s.toText((h?n.line(r++).text:e)+s.lineBreak);return{changes:{from:l.from,insert:o},range:B.cursor(i.from+o.length)}}))}else i=h?s.changeByRange((t=>{let e=n.line(r++);return{changes:{from:t.from,to:t.to,insert:e.text},range:B.cursor(t.from+e.length)}})):s.replaceSelection(n);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function zs(t,e,i,s){if(1==s)return B.cursor(e,i);if(2==s)return function(t,e,i=1){let s=t.charCategorizer(e),r=t.doc.lineAt(e),n=e-r.from;if(0==r.length)return B.cursor(e);0==n?i=1:n==r.length&&(i=-1);let h=n,l=n;i<0?h=p(r.text,n,!1):l=p(r.text,n);let o=s(r.text.slice(h,l));for(;h>0;){let t=p(r.text,h,!1);if(s(r.text.slice(t,h))!=o)break;h=t}for(;l<r.length;){let t=p(r.text,l);if(s(r.text.slice(l,t))!=o)break;l=t}return B.range(h+r.from,l+r.from)}(t.state,e,i);{let i=ei.find(t.docView,e),s=t.state.doc.lineAt(i?i.posAtEnd:e),r=i?i.posAtStart:s.from,n=i?i.posAtEnd:s.to;return n<t.state.doc.length&&n==s.to&&n++,B.range(r,n)}}Ns.scroll=t=>{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},Ls.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&(t.inputState.lastEscPress=Date.now()),!1),Ns.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Ns.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Ls.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let s of t.state.facet(Ni))if(i=s(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=Vs(t,e),s=Gs(e),r=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),r=r.map(t.changes))},get(e,n,h){let l,o=Vs(t,e),u=zs(t,o.pos,o.bias,s);if(i.pos!=o.pos&&!n){let e=zs(t,i.pos,i.bias,s),r=Math.min(e.from,u.from),n=Math.max(e.to,u.to);u=r<u.from?B.range(r,n):B.range(n,r)}return n?r.replaceRange(r.main.extend(u.from,u.to)):h&&1==s&&r.ranges.length>1&&(l=function(t,e){for(let i=0;i<t.ranges.length;i++){let{from:s,to:r}=t.ranges[i];if(s<=e&&r>=e)return B.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(r,o.pos))?l:h?r.addRange(u):B.create([u])}}}(t,e)),i){let s=!t.hasFocus;t.inputState.startMouseSelection(new Bs(t,e,i,s)),s&&t.observer.ignore((()=>we(t.contentDOM)));let r=t.inputState.mouseSelection;if(r)return r.start(e),!1===r.dragging}return!1};let Ps=(t,e)=>t>=e.top&&t<=e.bottom,Hs=(t,e,i)=>Ps(e,i)&&t>=i.left&&t<=i.right;function Ws(t,e,i,s){let r=ei.find(t.docView,e);if(!r)return 1;let n=e-r.posAtStart;if(0==n)return 1;if(n==r.length)return-1;let h=r.coordsAt(n,-1);if(h&&Hs(i,s,h))return-1;let l=r.coordsAt(n,1);return l&&Hs(i,s,l)?1:h&&Ps(s,h)?-1:1}function Vs(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:Ws(t,i,e.clientX,e.clientY)}}const Fs=Ve.ie&&Ve.ie_version<=11;let qs=null,Us=0,Js=0;function Gs(t){if(!Fs)return t.detail;let e=qs,i=Js;return qs=t,Js=Date.now(),Us=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Us+1)%3:1}function Ks(t,e,i,s){if(!i)return;let r=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:n}=t.inputState,h=s&&n&&function(t,e){let i=t.state.facet(Li);return i.length?i[0](e):Ve.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:n.from,to:n.to}:null,l={from:r,insert:i},o=t.state.changes(h?[h,l]:l);t.focus(),t.dispatch({changes:o,selection:{anchor:o.mapPos(r,-1),head:o.mapPos(r,1)},userEvent:h?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Ls.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let s=t.docView.nearest(e.target);if(s&&s.isWidget){let t=s.posAtStart,e=t+s.length;(t>=i.to||e<=i.from)&&(i=B.range(t,e))}}let{inputState:s}=t;return s.mouseSelection&&(s.mouseSelection.dragging=!0),s.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",t.state.sliceDoc(i.from,i.to)),e.dataTransfer.effectAllowed="copyMove"),!1},Ls.dragend=t=>(t.inputState.draggedContent=null,!1),Ls.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let s=Array(i.length),r=0,n=()=>{++r==i.length&&Ks(t,e,s.filter((t=>null!=t)).join(t.state.lineBreak),!1)};for(let t=0;t<i.length;t++){let e=new FileReader;e.onerror=n,e.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(s[t]=e.result),n()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return Ks(t,e,i,!0),!0}return!1},Ls.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=js?null:e.clipboardData;return i?($s(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{t.focus(),i.remove(),$s(t,i.value)}),50)}(t),!1)};let _s=null;Ls.copy=Ls.cut=(t,e)=>{let{text:i,ranges:s,linewise:r}=function(t){let e=[],i=[],s=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let r=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);n.number>r&&(e.push(n.text),i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})),r=n.number}s=!0}return{text:e.join(t.lineBreak),ranges:i,linewise:s}}(t.state);if(!i&&!r)return!1;_s=r?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"});let n=js?null:e.clipboardData;return n?(n.clearData(),n.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px",s.value=e,s.focus(),s.selectionEnd=e.length,s.selectionStart=0,setTimeout((()=>{s.remove(),t.focus()}),50)}(t,i),!1)};const Xs=ut.define();function Ys(t,e){let i=[];for(let s of t.facet(Pi)){let r=s(t,e);r&&i.push(r)}return i?t.update({effects:i,annotations:Xs.of(!0)}):null}function Qs(t){setTimeout((()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=Ys(t.state,e);i?t.dispatch(i):t.update([])}}),10)}Ns.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),Qs(t)},Ns.blur=t=>{t.observer.clearSelectionRange(),Qs(t)},Ns.compositionstart=Ns.compositionupdate=t=>{null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0)},Ns.compositionend=t=>{t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,Ve.chrome&&Ve.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then((()=>t.observer.flush())):setTimeout((()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])}),50)},Ns.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Ls.beforeinput=(t,e)=>{var i;let s;if(Ve.chrome&&Ve.android&&(s=Es.find((t=>t.inputType==e.inputType)))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())}),100)}return Ve.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),Ve.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout((()=>Ns.compositionend(t,e)),20),!1};const Zs=new Set;const tr=["pre-wrap","normal","pre-line","break-spaces"];class er{constructor(e){this.lineWrapping=e,this.doc=t.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return tr.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(10*s)]||(e=!0,this.heightSamples[Math.floor(10*s)]=!0)}return e}refresh(t,e,i,s,r,n){let h=tr.indexOf(t)>-1,l=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=h;if(this.lineWrapping=h,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=r,l){this.heightSamples={};for(let t=0;t<n.length;t++){let e=n[t];e<0?t++:this.heightSamples[Math.floor(10*e)]=!0}}return l}}class ir{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class sr{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return"number"==typeof this._content?ri.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 oi?this._content.widget:null}get widgetLineBreaks(){return"number"==typeof this._content?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new sr(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var rr=function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t}(rr||(rr={}));const nr=.001;class hr{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(2&this.flags)>0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>nr&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return hr.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this,n=i.doc;for(let h=s.length-1;h>=0;h--){let{fromA:l,toA:o,fromB:u,toB:f}=s[h],a=r.lineAt(l,rr.ByPosNoHeight,i.setDoc(e),0,0),c=a.to>=o?a:r.lineAt(o,rr.ByPosNoHeight,i,0,0);for(f+=c.to-o,o=c.to;h>0&&a.from<=s[h-1].toA;)l=s[h-1].fromA,u=s[h-1].fromB,h--,l<a.from&&(a=r.lineAt(l,rr.ByPosNoHeight,i,0,0));u+=a.from-l,l=a.from;let d=cr.build(i.setDoc(n),t,u,f);r=r.replace(l,o,d)}return r.updateHeight(i,0)}static empty(){return new or(0,0)}static of(t){if(1==t.length)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>2*r){let r=t[e-1];r.break?t.splice(--e,1,r.left,null,r.right):t.splice(--e,1,r.left,r.right),i+=1+r.break,s-=r.size}else{if(!(r>2*s))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,r-=e.size}}else if(s<r){let i=t[e++];i&&(s+=i.size)}else{let e=t[--i];e&&(r+=e.size)}let n=0;return null==t[e-1]?(n=1,e--):null==t[e]&&(n=1,i++),new fr(hr.of(t.slice(0,e)),n,hr.of(t.slice(i)))}}hr.prototype.size=1;class lr extends hr{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,s){return new sr(s,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,n){t<=r+this.length&&e>=r&&n(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class or extends lr{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,s){return new sr(s,this.length,i,this.height,this.breaks)}replace(t,e,i){let s=i[0];return 1==i.length&&(s instanceof or||s instanceof ur&&4&s.flags)&&Math.abs(this.length-s.length)<10?(s instanceof ur?s=new or(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):hr.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ur extends hr{constructor(t){super(t,0)}heightMetrics(t,e){let i,s=t.doc.lineAt(e).number,r=t.doc.lineAt(e+this.length).number,n=r-s+1,h=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*n);i=e/n,this.length>n+1&&(h=(this.height-e)/(this.length-n-1))}else i=this.height/n;return{firstLine:s,lastLine:r,perLine:i,perChar:h}}blockAt(t,e,i,s){let{firstLine:r,lastLine:n,perLine:h,perChar:l}=this.heightMetrics(e,s);if(e.lineWrapping){let r=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),n=e.doc.lineAt(r),o=h+n.length*l,u=Math.max(i,t-o/2);return new sr(n.from,n.length,u,o,0)}{let s=Math.max(0,Math.min(n-r,Math.floor((t-i)/h))),{from:l,length:o}=e.doc.line(r+s);return new sr(l,o,i+h*s,h,0)}}lineAt(t,e,i,s,r){if(e==rr.ByHeight)return this.blockAt(t,i,s,r);if(e==rr.ByPosNoHeight){let{from:e,to:s}=i.doc.lineAt(t);return new sr(e,s-e,0,0,0)}let{firstLine:n,perLine:h,perChar:l}=this.heightMetrics(i,r),o=i.doc.lineAt(t),u=h+o.length*l,f=o.number-n,a=s+h*f+l*(o.from-r-f);return new sr(o.from,o.length,Math.max(s,Math.min(a,s+this.height-u)),u,0)}forEachLine(t,e,i,s,r,n){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:h,perLine:l,perChar:o}=this.heightMetrics(i,r);for(let u=t,f=s;u<=e;){let e=i.doc.lineAt(u);if(u==t){let i=e.number-h;f+=l*i+o*(t-r-i)}let s=l+o*e.length;n(new sr(e.from,e.length,f,s,0)),f+=s,u=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];t instanceof ur?i[i.length-1]=new ur(t.length+s):i.push(null,new ur(s-1))}if(t>0){let e=i[0];e instanceof ur?i[0]=new ur(t+e.length):i.unshift(new ur(t-1),null)}return hr.of(i)}decomposeLeft(t,e){e.push(new ur(t-1),null)}decomposeRight(t,e){e.push(null,new ur(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),h=-1;for(s.from>e&&i.push(new ur(s.from-e-1).updateHeight(t,e));n<=r&&s.more;){let e=t.doc.lineAt(n).length;i.length&&i.push(null);let r=s.heights[s.index++];-1==h?h=r:Math.abs(r-h)>=nr&&(h=-2);let l=new or(e,r);l.outdated=!1,i.push(l),n+=e+1}n<=r&&i.push(null,new ur(r-n).updateHeight(t,n));let l=hr.of(i);return(h<0||Math.abs(l.height-this.height)>=nr||Math.abs(h-this.heightMetrics(t,e).perLine)>=nr)&&(t.heightChanged=!0),l}return(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class fr extends hr{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 1&this.flags}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let n=s+this.left.height,h=r+this.left.length+this.break,l=e==rr.ByHeight?t<n:t<h,o=l?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,n,h);if(this.break||(l?o.to<h:o.from>h))return o;let u=e==rr.ByPosNoHeight?rr.ByPosNoHeight:rr.ByPos;return l?o.join(this.right.lineAt(h,u,i,n,h)):this.left.lineAt(h,u,i,s,r).join(o)}forEachLine(t,e,i,s,r,n){let h=s+this.left.height,l=r+this.left.length+this.break;if(this.break)t<l&&this.left.forEachLine(t,e,i,s,r,n),e>=l&&this.right.forEachLine(t,e,i,h,l,n);else{let o=this.lineAt(l,rr.ByPos,i,s,r);t<o.from&&this.left.forEachLine(t,o.from-1,i,s,r,n),o.to>=t&&o.from<=e&&n(o),e>o.to&&this.right.forEachLine(o.to+1,e,i,h,l,n)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let n=r.length;for(let t of i)r.push(t);if(t>0&&ar(r,n-1),e<this.length){let t=r.length;this.decomposeRight(e,r),ar(r,t)}return hr.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?hr.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:n}=this,h=e+r.length+this.break,l=null;return s&&s.from<=e+r.length&&s.more?l=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=h+n.length&&s.more?l=n=n.updateHeight(t,h,i,s):n.updateHeight(t,h,i),l?this.balanced(r,n):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function ar(t,e){let i,s;null==t[e]&&(i=t[e-1])instanceof ur&&(s=t[e+1])instanceof ur&&t.splice(e-1,3,new ur(i.length+1+s.length))}class cr{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 t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof or?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new or(t-this.pos,-1)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let n=e-t;i.block?this.addBlock(new lr(n,s,i)):(n||r||s>=5)&&this.addLineDeco(s,r,n)}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||null==this.nodes[this.nodes.length-1])&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new or(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new ur(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 or)return t;let e=new or(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof or||this.isCovered?(this.writtenTo<this.pos||null==e)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos)):this.nodes.push(new or(0,-1));let i=t;for(let t of this.nodes)t instanceof or&&t.updateHeight(this.oracle,i),i+=t?t.length:1;return this.nodes}static build(t,e,i,s){let r=new cr(i,t);return It.spans(e,i,s,r,0),r.finish(i)}}class dr{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&fi(t,e,this.changes,5)}}function pr(t,e){let i=t.getBoundingClientRect(),s=t.ownerDocument,r=s.defaultView||window,n=Math.max(0,i.left),h=Math.min(r.innerWidth,i.right),l=Math.max(0,i.top),o=Math.min(r.innerHeight,i.bottom);for(let e=t.parentNode;e&&e!=s.body;)if(1==e.nodeType){let i=e,s=window.getComputedStyle(i);if((i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=s.overflow){let s=i.getBoundingClientRect();n=Math.max(n,s.left),h=Math.min(h,s.right),l=Math.max(l,s.top),o=e==t.parentNode?s.bottom:Math.min(o,s.bottom)}e="absolute"==s.position||"fixed"==s.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:n-i.left,right:Math.max(n,h)-i.left,top:l-(i.top+e),bottom:Math.max(l,o)-(i.top+e)}}function mr(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class gr{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t,e){return ni.replace({widget:new wr(this.size*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class wr extends si{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 br{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=xr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=pi.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=e.facet(Qi).some((t=>"function"!=typeof t&&"cm-lineWrapping"==t.class));this.heightOracle=new er(i),this.stateDeco=e.facet(Zi).filter((t=>"function"!=typeof t)),this.heightMap=hr.empty().applyChanges(this.stateDeco,t.empty,this.heightOracle.setDoc(e.doc),[new ls(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ni.set(this.lineGaps.map((t=>t.draw(this,!1)))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some((({from:t,to:e})=>s>=t&&s<=e))){let{from:e,to:i}=this.lineBlockAt(s);t.push(new vr(e,i))}}this.viewports=t.sort(((t,e)=>t.from-e.from)),this.scaler=this.heightMap.height<=7e6?xr:new Sr(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,(t=>{this.viewportLines.push(1==this.scaler.scale?t:Ar(t,this.scaler))}))}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Zi).filter((t=>"function"!=typeof t));let s=t.changedRanges,r=ls.extendWithRanges(s,function(t,e,i){let s=new dr;return It.compare(t,e,i,s,0),s.changes}(i,this.stateDeco,t?t.changes:A.empty(this.state.doc.length))),n=this.heightMap.height,h=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=n&&(t.flags|=2),h?(this.scrollAnchorPos=t.changes.mapPos(h.from,-1),this.scrollAnchorHeight=h.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let l=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<l.from||e.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let o=!t.changes.empty||2&t.flags||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),o&&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(Wi)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let i=e.contentDOM,s=window.getComputedStyle(i),r=this.heightOracle,n=s.whiteSpace;this.defaultTextDirection="rtl"==s.direction?pi.RTL:pi.LTR;let h=this.heightOracle.mustRefreshForWrapping(n),l=i.getBoundingClientRect(),o=h||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let u=0,f=0;if(l.width&&l.height){let{scaleX:t,scaleY:e}=de(i,l);(t>.005&&Math.abs(this.scaleX-t)>.005||e>.005&&Math.abs(this.scaleY-e)>.005)&&(this.scaleX=t,this.scaleY=e,u|=8,h=o=!0)}let a=(parseInt(s.paddingTop)||0)*this.scaleY,c=(parseInt(s.paddingBottom)||0)*this.scaleY;this.paddingTop==a&&this.paddingBottom==c||(this.paddingTop=a,this.paddingBottom=c,u|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(o=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=ye(e.scrollDOM);let p=(this.printing?mr:pr)(i,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(o=!0)),!this.inView&&!this.scrollTarget)return 0;let b=l.width;if(this.contentDOMWidth==b&&this.editorHeight==e.scrollDOM.clientHeight||(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,u|=8),o){let i=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(i)&&(h=!0),h||r.lineWrapping&&Math.abs(b-this.contentDOMWidth)>r.charWidth){let{lineHeight:t,charWidth:s,textHeight:l}=e.docView.measureTextSize();h=t>0&&r.refresh(n,t,s,l,b/s,i),h&&(e.docView.minWidth=0,u|=8)}m>0&&g>0?f=Math.max(m,g):m<0&&g<0&&(f=Math.min(m,g)),r.heightChanged=!1;for(let s of this.viewports){let n=s.from==this.viewport.from?i:e.docView.measureVisibleLineHeights(s);this.heightMap=(h?hr.empty().applyChanges(this.stateDeco,t.empty,this.heightOracle,[new ls(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,h,new ir(s.from,n))}r.heightChanged&&(u|=2)}let v=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return v&&(this.viewport=this.getViewport(f,this.scrollTarget)),this.updateForViewport(),(2&u||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(h?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:n,visibleBottom:h}=this,l=new vr(s.lineAt(n-1e3*i,rr.ByHeight,r,0,0).from,s.lineAt(h+1e3*(1-i),rr.ByHeight,r,0,0).to);if(e){let{head:t}=e.range;if(t<l.from||t>l.to){let i,n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),h=s.lineAt(t,rr.ByPos,r,0,0);i="center"==e.y?(h.top+h.bottom)/2-n/2:"start"==e.y||"nearest"==e.y&&t<l.from?h.top:h.bottom-n,l=new vr(s.lineAt(i-500,rr.ByHeight,r,0,0).from,s.lineAt(i+n+500,rr.ByHeight,r,0,0).to)}}return l}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new vr(this.heightMap.lineAt(i,rr.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,rr.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,rr.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,rr.ByPos,this.heightOracle,0,0),{visibleTop:n,visibleBottom:h}=this;return(0==t||s<=n-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=h+Math.max(10,Math.min(i,250)))&&s>n-2e3&&r<h+2e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new gr(e.mapPos(s.from),e.mapPos(s.to),s.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,n=s<<1;if(this.defaultTextDirection!=pi.LTR&&!i)return[];let h=[],l=(s,n,o,u)=>{if(n-s<r)return;let f=this.state.selection.main,a=[f.from];f.empty||a.push(f.to);for(let t of a)if(t>s&&t<n)return l(s,t-10,o,u),void l(t+10,n,o,u);let c=function(t,e){for(let i of t)if(e(i))return i;return}(t,(t=>t.from>=o.from&&t.to<=o.to&&Math.abs(t.from-s)<r&&Math.abs(t.to-n)<r&&!a.some((e=>t.from<e&&t.to>e))));if(!c){if(n<o.to&&e&&i&&e.visibleRanges.some((t=>t.from<=n&&t.to>=n))){let t=e.moveToLineBoundary(B.cursor(n),!1,!0).head;t>s&&(n=t)}c=new gr(s,n,this.gapSize(o,s,n,u))}h.push(c)};for(let t of this.viewportLines){if(t.length<n)continue;let e=kr(t.from,t.to,this.stateDeco);if(e.total<n)continue;let r,h,o=this.scrollTarget?this.scrollTarget.range.head:null;if(i){let i,n,l=s/this.heightOracle.lineLength*this.heightOracle.lineHeight;if(null!=o){let s=Mr(e,o),r=((this.visibleBottom-this.visibleTop)/2+l)/t.height;i=s-r,n=s+r}else i=(this.visibleTop-t.top-l)/t.height,n=(this.visibleBottom-t.top+l)/t.height;r=yr(e,i),h=yr(e,n)}else{let t,i,n=e.total*this.heightOracle.charWidth,l=s*this.heightOracle.charWidth;if(null!=o){let s=Mr(e,o),r=((this.pixelViewport.right-this.pixelViewport.left)/2+l)/n;t=s-r,i=s+r}else t=(this.pixelViewport.left-l)/n,i=(this.pixelViewport.right+l)/n;r=yr(e,t),h=yr(e,i)}r>t.from&&l(t.from,r,t,e),h<t.to&&l(h,t.to,t,e)}return h}gapSize(t,e,i,s){let r=Mr(s,i)-Mr(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){gr.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=ni.set(t.map((t=>t.draw(this,this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];It.spans(t,this.viewport.from,this.viewport.to,{span(t,i){e.push({from:t,to:i})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some(((t,i)=>t.from!=e[i].from||t.to!=e[i].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))||Ar(this.heightMap.lineAt(t,rr.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return Ar(this.heightMap.lineAt(this.scaler.fromDOM(t),rr.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 Ar(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 vr{constructor(t,e){this.from=t,this.to=e}}function kr(t,e,i){let s=[],r=t,n=0;return It.spans(i,t,e,{span(){},point(t,e){t>r&&(s.push({from:r,to:t}),n+=t-r),r=e}},20),r<e&&(s.push({from:r,to:e}),n+=e-r),{total:n,ranges:s}}function yr({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:r}=e[t],n=r-i;if(s<=n)return i+s;s-=n}}function Mr(t,e){let i=0;for(let{from:s,to:r}of t.ranges){if(e<=r){i+=e-s;break}i+=r-s}return i/t.total}const xr={toDOM:t=>t,fromDOM:t=>t,scale:1};class Sr{constructor(t,e,i){let s=0,r=0,n=0;this.viewports=i.map((({from:i,to:r})=>{let n=e.lineAt(i,rr.ByPos,t,0,0).top,h=e.lineAt(r,rr.ByPos,t,0,0).bottom;return s+=h-n,{from:i,to:r,top:n,bottom:h,domTop:0,domBottom:0}})),this.scale=(7e6-s)/(e.height-s);for(let t of this.viewports)t.domTop=n+(t.top-r)*this.scale,n=t.domBottom=t.domTop+(t.bottom-t.top),r=t.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}}function Ar(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),s=e.toDOM(t.bottom);return new sr(t.from,t.length,i,s-i,Array.isArray(t._content)?t._content.map((t=>Ar(t,e))):t._content)}const Cr=j.define({combine:t=>t.join(" ")}),Or=j.define({combine:t=>t.indexOf(!0)>-1}),Dr=Gt.newName(),Er=Gt.newName(),Ir=Gt.newName(),Rr={"&light":"."+Er,"&dark":"."+Ir};function Tr(t,e,i){return new Gt(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,(e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]})):t+" "+e})}const Br=Tr("."+Dr,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Rr),Lr="";class Nr{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(St.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Lr}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let t=this.text.length;this.readNode(s);let r=s.nextSibling;if(r==e)break;let n=Ce.get(s),h=Ce.get(r);(n&&h?n.breakAfter:(n?n.breakAfter:oe(s))||oe(r)&&("BR"!=s.nodeName||s.cmIgnore)&&this.text.length>t)&&this.lineBreak(),s=r}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r,n=-1,h=1;if(this.lineSeparator?(n=e.indexOf(this.lineSeparator,i),h=this.lineSeparator.length):(r=s.exec(e))&&(n=r.index,h=r[0].length),this.append(e.slice(i,n<0?e.length:n)),n<0)break;if(this.lineBreak(),h>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=h-1);i=n+h}}readNode(t){if(t.cmIgnore)return;let e=Ce.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&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)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(jr(t,i.node,i.offset)?e:0))}}function jr(t,e,i){for(;;){if(!e||i<fe(e))return!1;if(e==t)return!0;i=le(e)+1,e=e.parentNode}}class $r{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class zr{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:n}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let e=r||n?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}=t.observer.selectionRange;i&&(e.push(new $r(i,s)),r==i&&n==s||e.push(new $r(r,n)));return e}(t),i=new Nr(e,t.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,s=2==t.length?t[1].pos:i;return i>-1&&s>-1?B.single(i+e,s+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=r&&r.node==e.focusNode&&r.offset==e.focusOffset||!se(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),s=n&&n.node==e.anchorNode&&n.offset==e.anchorOffset||!se(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),h=t.viewport;if((Ve.ios||Ve.chrome)&&t.state.selection.main.empty&&i!=s&&(h.from>0||h.to<t.state.doc.length)){let e=Math.min(i,s),r=Math.max(i,s),n=h.from-e,l=h.to-r;0!=n&&1!=n&&0!=e||0!=l&&-1!=l&&r!=t.state.doc.length||(i=0,s=t.state.doc.length)}this.newSel=B.single(s,i)}}}function Pr(e,i){let s,{newSel:r}=i,n=e.state.selection.main,h=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(i.bounds){let{from:r,to:l}=i.bounds,o=n.from,u=null;(8===h||Ve.android&&i.text.length<l-r)&&(o=n.to,u="end");let f=function(t,e,i,s){let r=Math.min(t.length,e.length),n=0;for(;n<r&&t.charCodeAt(n)==e.charCodeAt(n);)n++;if(n==r&&t.length==e.length)return null;let h=t.length,l=e.length;for(;h>0&&l>0&&t.charCodeAt(h-1)==e.charCodeAt(l-1);)h--,l--;if("end"==s){i-=h+Math.max(0,n-Math.min(h,l))-n}if(h<n&&t.length<e.length){n-=i<=n&&i>=h?n-i:0,l=n+(l-h),h=n}else if(l<n){n-=i<=n&&i>=l?n-i:0,h=n+(h-l),l=n}return{from:n,toA:h,toB:l}}(e.state.doc.sliceString(r,l,Lr),i.text,o-r,u);f&&(Ve.chrome&&13==h&&f.toB==f.from+2&&i.text.slice(f.from,f.toB)==Lr+Lr&&f.toB--,s={from:r+f.from,to:r+f.toA,insert:t.of(i.text.slice(f.from,f.toB).split(Lr))})}else r&&(!e.hasFocus&&e.state.facet(Ji)||r.main.eq(n))&&(r=null);if(!s&&!r)return!1;if(!s&&i.typeOver&&!n.empty&&r&&r.main.empty?s={from:n.from,to:n.to,insert:e.state.doc.slice(n.from,n.to)}:s&&s.from>=n.from&&s.to<=n.to&&(s.from!=n.from||s.to!=n.to)&&n.to-n.from-(s.to-s.from)<=4?s={from:n.from,to:n.to,insert:e.state.doc.slice(n.from,s.from).append(s.insert).append(e.state.doc.slice(s.to,n.to))}:(Ve.mac||Ve.android)&&s&&s.from==s.to&&s.from==n.head-1&&/^\. ?$/.test(s.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(r&&2==s.insert.length&&(r=B.single(r.main.anchor-1,r.main.head-1)),s={from:n.from,to:n.to,insert:t.of([" "])}):Ve.chrome&&s&&s.from==s.to&&s.from==n.head&&"\n "==s.insert.toString()&&e.lineWrapping&&(r&&(r=B.single(r.main.anchor-1,r.main.head-1)),s={from:n.from,to:n.to,insert:t.of([" "])}),s){if(Ve.ios&&e.inputState.flushIOSKey(s))return!0;if(Ve.android&&(s.to==n.to&&(s.from==n.from||s.from==n.from-1&&" "==e.state.sliceDoc(s.from,n.from))&&1==s.insert.length&&2==s.insert.lines&&ve(e.contentDOM,"Enter",13)||(s.from==n.from-1&&s.to==n.to&&0==s.insert.length||8==h&&s.insert.length<s.to-s.from&&s.to>n.head)&&ve(e.contentDOM,"Backspace",8)||s.from==n.from&&s.to==n.to+1&&0==s.insert.length&&ve(e.contentDOM,"Delete",46)))return!0;let t,i=s.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let l=()=>t||(t=function(t,e,i){let s,r=t.state,n=r.selection.main;if(e.from>=n.from&&e.to<=n.to&&e.to-e.from>=(n.to-n.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=n.from<e.from?r.sliceDoc(n.from,e.from):"",h=n.to>e.to?r.sliceDoc(e.to,n.to):"";s=r.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+h))}else{let h=r.changes(e),l=i&&i.main.to<=h.newLength?i.main:void 0;if(r.selection.ranges.length>1&&t.inputState.composing>=0&&e.to<=n.to&&e.to>=n.to-10){let o,u=t.state.sliceDoc(e.from,e.to),f=i&&as(t,i.main.head);if(f){let t=e.insert.length-(e.to-e.from);o={from:f.from,to:f.to-t}}else o=t.state.doc.lineAt(n.head);let a=n.to-e.to,c=n.to-n.from;s=r.changeByRange((i=>{if(i.from==n.from&&i.to==n.to)return{changes:h,range:l||i.map(h)};let s=i.to-a,f=s-u.length;if(i.to-i.from!=c||t.state.sliceDoc(f,s)!=u||i.to>=o.from&&i.from<=o.to)return{range:i};let d=r.changes({from:f,to:s,insert:e.insert}),p=i.to-n.to;return{changes:d,range:l?B.range(Math.max(0,l.anchor+p),Math.max(0,l.head+p)):i.map(d)}}))}else s={changes:h,selection:l&&r.selection.replaceRange(l)}}let h="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,h+=".compose",t.inputState.compositionFirstChange&&(h+=".start",t.inputState.compositionFirstChange=!1));return r.update(s,{userEvent:h,scrollIntoView:!0})}(e,s,r));return e.state.facet(zi).some((t=>t(e,s.from,s.to,i,l)))||e.dispatch(l()),!0}if(r&&!r.main.eq(n)){let t=!1,i="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),i=e.inputState.lastSelectionOrigin),e.dispatch({selection:r,scrollIntoView:t,userEvent:i}),!0}return!1}const Hr={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Wr=Ve.ie&&Ve.ie_version<=11;class Vr{constructor(t){this.view=t,this.active=!1,this.selectionRange=new pe,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 t of e)this.queue.push(t);(Ve.ie&&Ve.ie_version<=11||Ve.ios&&t.composing)&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():this.flush()})),Wr&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver((()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()})),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver((t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))}),{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1,this.view.requestMeasure()}),50))}onPrint(t){("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,s=this.selectionRange;if(i.state.facet(Ji)?i.root.activeElement!=this.dom:!re(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);r&&r.ignoreEvent(t)?e||(this.selectionChanged=!1):(Ve.ie&&Ve.ie_version<=11||Ve.android&&Ve.chrome)&&!i.state.selection.main.empty&&s.focusNode&&he(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ie(t.root);if(!e)return!1;let i=Ve.safari&&11==t.root.nodeType&&function(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}(this.dom.ownerDocument)==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return qr(t,i)}let i=null;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",s,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",s,!0),i?qr(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=re(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&function(t,e){let i=e.focusNode,s=e.focusOffset;if(!i||e.anchorNode!=i||e.anchorOffset!=s)return!1;for(s=Math.min(s,fe(i));;)if(s){if(1!=i.nodeType)return!1;let t=i.childNodes[s-1];"false"==t.contentEditable?s--:(i=t,s=fe(i))}else{if(i==t)return!0;s=le(i),i=i.parentNode}}(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(1==i.nodeType)!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(11!=i.nodeType)break;i=i.host}if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);for(let t of this.scrollTargets=e)t.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,Hr),Wr&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Wr&&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 t=()=>{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&ve(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(null===(i=this.delayedAndroidKey)||void 0===i?void 0:i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame((()=>{this.delayedFlush=-1,this.flush()})))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let t=this.readMutation(r);t&&(t.typeOver&&(s=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&re(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new zr(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Pr(this.view,e);return this.view.state==i&&this.view.update([]),s}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty("attributes"==t.type),"attributes"==t.type&&(e.flags|=4),"childList"==t.type){let i=Fr(e,t.previousSibling||t.target.previousSibling,-1),s=Fr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Fr(t,e,i){for(;e;){let s=Ce.get(e);if(s&&s.parent==t)return s;let r=e.parentNode;e=r!=t.dom?r:i>0?e.nextSibling:e.previousSibling}return null}function qr(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,h=t.docView.domAtPos(t.state.selection.main.anchor);return he(h.node,h.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}class Ur{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(t=>t.forEach((t=>e(t,this))))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new br(t.state||St.create(t)),t.scrollTo&&t.scrollTo.is(qi)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ki).map((t=>new Xi(t)));for(let t of this.plugins)t.update(this);this.observer=new Vr(this),this.inputState=new Cs(this),this.inputState.ensureHandlers(this.plugins),this.docView=new us(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=1==t.length&&t[0]instanceof dt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,s=!1,r=this.state;for(let e of t){if(e.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=e.state}if(this.destroyed)return void(this.viewState.state=r);let n=this.hasFocus,h=0,l=null;t.some((t=>t.annotation(Xs)))?(this.inputState.notifiedFocused=n,h=1):n!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=n,l=Ys(r,n),l||(h=1));let o=this.observer.delayedAndroidKey,u=null;if(o?(this.observer.clearDelayedAndroidKey(),u=this.observer.readChange(),(u&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(u=null)):this.observer.clear(),r.facet(St.phrases)!=this.state.facet(St.phrases))return this.setState(r);e=os.create(this,r,t),e.flags|=h;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(f&&(f=f.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;f=new Fi(t.empty?t:B.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(qi)&&(f=t.value.clip(this.state))}this.viewState.update(e,f),this.bidiCache=Kr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(hs)!=this.styleModules&&this.mountStyles(),s=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some((t=>t.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(e.startState.facet(Cr)!=e.state.facet(Cr)&&(this.viewState.mustMeasureContent=!0),(i||s||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet($i))try{t(e)}catch(t){Ui(this.state,t,"update listener")}(l||u)&&Promise.resolve().then((()=>{l&&this.state==l.startState&&this.dispatch(l),u&&!Pr(this,u)&&o.force&&ve(this.contentDOM,o.key,o.keyCode)}))}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new br(t),this.plugins=t.facet(Ki).map((t=>new Xi(t))),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new us(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(Ki),i=t.state.facet(Ki);if(e!=i){let s=[];for(let r of i){let i=e.indexOf(r);if(i<0)s.push(new Xi(r));else{let e=this.plugins[i];e.mustUpdate=t,s.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t<this.plugins.length;t++)this.plugins[t].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(t){Ui(this.state,t,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:n}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(n=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(n<0)if(ye(i))r=-1,n=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(s);r=t.from,n=t.top}this.updateState=1;let h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&h||([this.measureRequests,l]=[l,this.measureRequests]);let o=l.map((t=>{try{return t.read(this)}catch(t){return Ui(this.state,t),Gr}})),u=os.create(this,this.state,[]),f=!1;u.flags|=h,e?e.flags|=h:e=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),f=this.docView.update(u),f&&this.docViewUpdate());for(let t=0;t<l.length;t++)if(o[t]!=Gr)try{let e=l[t];e.write&&e.write(o[t],this)}catch(t){Ui(this.state,t)}if(f&&this.docView.updateSelection(!0),!u.viewportChanged&&0==this.measureRequests.length){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,n=-1;continue}{let t=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-n;if(t>1||t<-1){s+=t,i.scrollTop=s/this.scaleY,n=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet($i))t(e)}get themeClasses(){return Dr+" "+(this.state.facet(Or)?Ir:Er)+" "+this.state.facet(Cr)}updateAttrs(){let t=_r(this,Yi,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Ji)?"true":"false",class:"cm-content",style:`${Ve.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),_r(this,Qi,e);let i=this.observer.ignore((()=>{let i=Ze(this.contentDOM,this.contentAttrs,e),s=Ze(this.dom,this.editorAttrs,t);return i||s}));return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(Ur.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(hs);let t=this.state.facet(Ur.cspNonce);Gt.mount(this.root,this.styleModules.concat(Br).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&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(null!=t.key)for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key)return void(this.measureRequests[e]=t);this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(void 0===e||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find((e=>e.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 As(this,t,xs(this,t,e,i))}moveByGroup(t,e){return As(this,t,xs(this,t,e,(e=>function(t,e,i){let s=t.state.charCategorizer(e),r=s(i);return t=>{let e=s(t);return r==kt.Space&&(r=e),r==e}}(this,t.head,e))))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return B.cursor(r.side(e,s)+t.from,r.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,s){let r=Ms(t,e.head),n=s&&r.type==ri.Text&&(t.lineWrapping||r.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head):null;if(n){let e=t.dom.getBoundingClientRect(),s=t.textDirectionAt(r.from),h=t.posAtCoords({x:i==(s==pi.LTR)?e.right-1:e.left+1,y:(n.top+n.bottom)/2});if(null!=h)return B.cursor(h,i?-1:1)}return B.cursor(i?r.to:r.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return As(this,t,function(t,e,i,s){let r=e.head,n=i?1:-1;if(r==(i?t.state.doc.length:0))return B.cursor(r,e.assoc);let h,l=e.goalColumn,o=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(r,e.assoc||-1),f=t.documentTop;if(u)null==l&&(l=u.left-o.left),h=n<0?u.top:u.bottom;else{let e=t.viewState.lineBlockAt(r);null==l&&(l=Math.min(o.right-o.left,t.defaultCharacterWidth*(r-e.from))),h=(n<0?e.top:e.bottom)+f}let a=o.left+l,c=null!=s?s:t.viewState.heightOracle.textHeight>>1;for(let e=0;;e+=10){let i=h+(c+e)*n,s=ks(t,{x:a,y:i},!1,n);if(i<o.top||i>o.bottom||(n<0?s<r:s>r)){let e=t.docView.coordsForChar(s),r=!e||i<e.top?-1:1;return B.cursor(s,r,void 0,l)}}}(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(),ks(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s);return ae(i,r[Si.find(r,t-s.from,-1,e)].dir==pi.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(Hi)||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>Jr)return Ei(t.length);let e,i=this.textDirectionAt(t.from);for(let s of this.bidiCache)if(s.from==t.from&&s.dir==i&&(s.fresh||Ai(s.isolates,e=ss(this,t))))return s.order;e||(e=ss(this,t));let s=function(t,e,i){if(!t)return[new Si(0,0,e==gi?1:0)];if(e==mi&&!i.length&&!xi.test(t))return Ei(t.length);if(i.length)for(;t.length>Ci.length;)Ci[Ci.length]=256;let s=[],r=e==mi?0:1;return Di(t,r,r,i,0,t.length,s),s}(t.text,i,e);return this.bidiCache.push(new Kr(t.from,t.to,i,e,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Ve.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{we(this.contentDOM),this.docView.updateSelection()}))}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return qi.of(new Fi("number"==typeof t?B.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return qi.of(new Fi(B.cursor(i.from),"start","start",i.top-t,e,!0))}static domEventHandlers(t){return _i.define((()=>({})),{eventHandlers:t})}static domEventObservers(t){return _i.define((()=>({})),{eventObservers:t})}static theme(t,e){let i=Gt.newName(),s=[Cr.of(i),hs.of(Tr(`.${i}`,t))];return e&&e.dark&&s.push(Or.of(!0)),s}static baseTheme(t){return _.lowest(hs.of(Tr("."+Dr,t,Rr)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Ce.get(i)||Ce.get(t);return(null===(e=null==s?void 0:s.rootView)||void 0===e?void 0:e.view)||null}}Ur.styleModule=hs,Ur.inputHandler=zi,Ur.scrollHandler=Vi,Ur.focusChangeEffect=Pi,Ur.perLineTextDirection=Hi,Ur.exceptionSink=ji,Ur.updateListener=$i,Ur.editable=Ji,Ur.mouseSelectionStyle=Ni,Ur.dragMovesSelection=Li,Ur.clickAddsSelectionRange=Bi,Ur.decorations=Zi,Ur.outerDecorations=ts,Ur.atomicRanges=es,Ur.bidiIsolatedRanges=is,Ur.scrollMargins=rs,Ur.darkTheme=Or,Ur.cspNonce=j.define({combine:t=>t.length?t[0]:""}),Ur.contentAttributes=Qi,Ur.editorAttributes=Yi,Ur.lineWrapping=Ur.contentAttributes.of({class:"cm-lineWrapping"}),Ur.announce=ct.define();const Jr=4096,Gr={};class Kr{constructor(t,e,i,s,r,n){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=n}static update(t,e){if(e.empty&&!t.some((t=>t.fresh)))return t;let i=[],s=t.length?t[t.length-1].dir:pi.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let n=t[r];n.dir!=s||e.touchesRange(n.from,n.to)||i.push(new Kr(e.mapPos(n.from,1),e.mapPos(n.to,-1),n.dir,n.isolates,!1,n.order))}return i}}function _r(t,e,i){for(let s=t.state.facet(e),r=s.length-1;r>=0;r--){let e=s[r],n="function"==typeof e?e(t):e;n&&Xe(n,i)}return i}const Xr=Ve.mac?"mac":Ve.windows?"win":Ve.linux?"linux":"key";function Yr(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const Qr=_.default(Ur.domEventHandlers({keydown:(t,e)=>nn(en(e.state),t,e,"editor")})),Zr=j.define({enables:Qr}),tn=new WeakMap;function en(t){let e=t.facet(Zr),i=tn.get(e);return i||tn.set(e,i=function(t,e=Xr){let i=Object.create(null),s=Object.create(null),r=(t,e)=>{let i=s[t];if(null==i)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},n=(t,s,n,h,l)=>{var o,u;let f=i[t]||(i[t]=Object.create(null)),a=s.split(/ (?!$)/).map((t=>function(t,e){const i=t.split(/-(?!$)/);let s,r,n,h,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t<i.length-1;++t){const l=i[t];if(/^(cmd|meta|m)$/i.test(l))h=!0;else if(/^a(lt)?$/i.test(l))s=!0;else if(/^(c|ctrl|control)$/i.test(l))r=!0;else if(/^s(hift)?$/i.test(l))n=!0;else{if(!/^mod$/i.test(l))throw new Error("Unrecognized modifier name: "+l);"mac"==e?h=!0:r=!0}}return s&&(l="Alt-"+l),r&&(l="Ctrl-"+l),h&&(l="Meta-"+l),n&&(l="Shift-"+l),l}(t,e)));for(let e=1;e<a.length;e++){let i=a.slice(0,e).join(" ");r(i,!0),f[i]||(f[i]={preventDefault:!0,stopPropagation:!1,run:[e=>{let s=sn={view:e,prefix:i,scope:t};return setTimeout((()=>{sn==s&&(sn=null)}),rn),!0}]})}let c=a.join(" ");r(c,!1);let d=f[c]||(f[c]={preventDefault:!1,stopPropagation:!1,run:(null===(u=null===(o=f._any)||void 0===o?void 0:o.run)||void 0===u?void 0:u.slice())||[]});n&&d.run.push(n),h&&(d.preventDefault=!0),l&&(d.stopPropagation=!0)};for(let s of t){let t=s.scope?s.scope.split(" "):["editor"];if(s.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let e in t)t[e].run.push(s.any)}let r=s[e]||s.key;if(r)for(let e of t)n(e,r,s.run,s.preventDefault,s.stopPropagation),s.shift&&n(e,"Shift-"+r,s.shift,s.preventDefault,s.stopPropagation)}return i}(e.reduce(((t,e)=>t.concat(e)),[]))),i}let sn=null;const rn=4e3;function nn(t,e,i,s){let r=function(t){var e=!(Qt&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||Zt&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?Yt:Xt)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),n=y(v(r,0))==r.length&&" "!=r,h="",l=!1,o=!1,u=!1;sn&&sn.view==i&&sn.scope==s&&(h=sn.prefix+" ",Rs.indexOf(e.keyCode)<0&&(o=!0,sn=null));let f,a,c=new Set,d=t=>{if(t){for(let s of t.run)if(!c.has(s)&&(c.add(s),s(i,e)))return t.stopPropagation&&(u=!0),!0;t.preventDefault&&(t.stopPropagation&&(u=!0),o=!0)}return!1},p=t[s];return p&&(d(p[h+Yr(r,e,!n)])?l=!0:n&&(e.altKey||e.metaKey||e.ctrlKey)&&!(Ve.windows&&e.ctrlKey&&e.altKey)&&(f=Xt[e.keyCode])&&f!=r?(d(p[h+Yr(f,e,!0)])||e.shiftKey&&(a=Yt[e.keyCode])!=r&&a!=f&&d(p[h+Yr(a,e,!1)]))&&(l=!0):n&&e.shiftKey&&d(p[h+Yr(r,e,!0)])&&(l=!0),!l&&d(p._any)&&(l=!0)),o&&(l=!0),l&&u&&e.stopPropagation(),l}class hn{constructor(t,e,i,s,r){this.className=t,this.left=e,this.top=i,this.width=s,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=ln(t);return[new hn(e,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let s=Math.max(i.from,t.viewport.from),r=Math.min(i.to,t.viewport.to),n=t.textDirection==pi.LTR,h=t.contentDOM,l=h.getBoundingClientRect(),o=ln(t),u=h.querySelector(".cm-line"),f=u&&window.getComputedStyle(u),a=l.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),c=l.right-(f?parseInt(f.paddingRight):0),d=Ms(t,s),p=Ms(t,r),m=d.type==ri.Text?d:null,g=p.type==ri.Text?p:null;m&&(t.lineWrapping||d.widgetLineBreaks)&&(m=on(t,s,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=on(t,r,g));if(m&&g&&m.from==g.from)return b(v(i.from,i.to,m));{let e=m?v(i.from,null,m):k(d,!1),s=g?v(null,i.to,g):k(p,!0),r=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2<s.top?r.push(w(a,e.bottom,c,s.top)):e.bottom<s.top&&t.elementAtHeight((e.bottom+s.top)/2).type==ri.Text&&(e.bottom=s.top=(e.bottom+s.top)/2),b(e).concat(r).concat(b(s))}function w(t,i,s,r){return new hn(e,t-o.left,i-o.top-.01,s-t,r-i+.01)}function b({top:t,bottom:e,horizontal:i}){let s=[];for(let r=0;r<i.length;r+=2)s.push(w(i[r],t,i[r+1],e));return s}function v(e,i,s){let r=1e9,h=-1e9,l=[];function o(e,i,o,u,f){let d=t.coordsAtPos(e,e==s.to?-2:2),p=t.coordsAtPos(o,o==s.from?2:-2);d&&p&&(r=Math.min(d.top,p.top,r),h=Math.max(d.bottom,p.bottom,h),f==pi.LTR?l.push(n&&i?a:d.left,n&&u?c:p.right):l.push(!n&&u?a:p.left,!n&&i?c:d.right))}let u=null!=e?e:s.from,f=null!=i?i:s.to;for(let s of t.visibleRanges)if(s.to>u&&s.from<f)for(let r=Math.max(s.from,u),n=Math.min(s.to,f);;){let s=t.state.doc.lineAt(r);for(let h of t.bidiSpans(s)){let t=h.from+s.from,l=h.to+s.from;if(t>=n)break;l>r&&o(Math.max(t,r),null==e&&t<=u,Math.min(l,n),null==i&&l>=f,h.dir)}if(r=s.to+1,r>=n)break}return 0==l.length&&o(u,null==e,f,null==i,t.textDirection),{top:r,bottom:h,horizontal:l}}function k(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function ln(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==pi.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function on(t,e,i){let s=B.cursor(e);return{from:Math.max(i.from,t.moveToLineBoundary(s,!1,!0).from),to:Math.min(i.to,t.moveToLineBoundary(s,!0,!0).from),type:ri.Text}}class un{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(fn)!=t.state.facet(fn)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(fn);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;t==this.scaleX&&e==this.scaleY||(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some(((t,e)=>{return i=t,s=this.drawn[e],!(i.constructor==s.constructor&&i.eq(s));var i,s}))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const fn=j.define();function an(t){return[_i.define((e=>new un(e,t))),fn.of(t)]}const cn=!Ve.ios,dn=j.define({combine:t=>At(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function pn(t){return t.startState.facet(dn)!=t.state.facet(dn)}const mn=an({above:!0,markers(t){let{state:e}=t,i=e.facet(dn),s=[];for(let r of e.selection.ranges){let n=r==e.selection.main;if(r.empty?!n||cn:i.drawRangeCursor){let e=n?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=r.empty?r:B.cursor(r.head,r.head>r.anchor?-1:1);for(let r of hn.forRange(t,e,i))s.push(r)}}return s},update(t,e){t.transactions.some((t=>t.selection))&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=pn(t);return i&&gn(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){gn(e.state,t)},class:"cm-cursorLayer"});function gn(t,e){e.style.animationDuration=t.facet(dn).cursorBlinkRate+"ms"}const wn=an({above:!1,markers:t=>t.state.selection.ranges.map((e=>e.empty?[]:hn.forRange(t,"cm-selectionBackground",e))).reduce(((t,e)=>t.concat(e))),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||pn(t),class:"cm-selectionLayer"}),bn={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};cn&&(bn[".cm-line"].caretColor="transparent !important",bn[".cm-content"]={caretColor:"transparent !important"});const vn=_.highest(Ur.theme(bn)),kn=ct.define({map:(t,e)=>null==t?null:e.mapPos(t)}),yn=F.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce(((t,e)=>e.is(kn)?e.value:t),t))}),Mn=_i.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(yn);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(yn)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(yn),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let s=t.scrollDOM.getBoundingClientRect();return{left:i.left-s.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-s.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(yn)!=t&&this.view.dispatch({effects:kn.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function xn(t,e,i,s,r){e.lastIndex=0;for(let n,h=t.iterRange(i,s),l=i;!h.next().done;l+=h.value.length)if(!h.lineBreak)for(;n=e.exec(h.value);)r(l+n.index,n)}class Sn{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:r,maxLength:n=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(t,e,i,r)=>s(r,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,s,r)=>{let n=i(t,e,s);n&&r(s,s+t[0].length,n)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,s,r)=>r(s,s+t[0].length,i)}this.boundary=r,this.maxLength=n}createDeco(t){let e=new Rt,i=e.add.bind(e);for(let{from:e,to:s}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:r,to:n}of i)r=Math.max(t.state.doc.lineAt(r).from,r-e),n=Math.min(t.state.doc.lineAt(n).to,n+e),s.length&&s[s.length-1].to>=r?s[s.length-1].to=n:s.push({from:r,to:n});return s}(t,this.maxLength))xn(t.state.doc,this.regexp,e,s,((e,s)=>this.addMatch(s,t,e,i)));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges(((e,r,n,h)=>{h>t.view.viewport.from&&n<t.view.viewport.to&&(i=Math.min(n,i),s=Math.max(h,s))})),t.viewportChanged||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let r of t.visibleRanges){let n=Math.max(r.from,i),h=Math.min(r.to,s);if(h>n){let i=t.state.doc.lineAt(n),s=i.to<h?t.state.doc.lineAt(h):i,l=Math.max(r.from,i.from),o=Math.min(r.to,s.to);if(this.boundary){for(;n>i.from;n--)if(this.boundary.test(i.text[n-1-i.from])){l=n;break}for(;h<s.to;h++)if(this.boundary.test(s.text[h-s.from])){o=h;break}}let u,f=[],a=(t,e,i)=>f.push(i.range(t,e));if(i==s)for(this.regexp.lastIndex=l-i.from;(u=this.regexp.exec(i.text))&&u.index<o-i.from;)this.addMatch(u,t,u.index+i.from,a);else xn(t.state.doc,this.regexp,l,o,((e,i)=>this.addMatch(i,t,e,a)));e=e.update({filterFrom:l,filterTo:o,filter:(t,e)=>t<l||e>o,add:f})}}return e}}const An=null!=/x/.unicode?"gu":"g",Cn=new RegExp("[\0-\b\n--\u2028\u2029\ufeff-]",An),On={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Dn=null;const En=j.define({combine(t){let e=At(t,{render:null,specialChars:Cn,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==Dn&&"undefined"!=typeof document&&document.body){let e=document.body.style;Dn=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return Dn||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,An)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,An)),e}});let In=null;class Rn extends si{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"":String.fromCharCode(9216+t)}(this.code),i=t.state.phrase("Control character")+" "+(On[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Tn extends si{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const Bn=ni.line({class:"cm-activeLine"}),Ln=_i.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){let r=t.lineBlockAt(s.head);r.from>e&&(i.push(Bn.range(r.from)),e=r.from)}return ni.set(i)}},{decorations:t=>t.decorations});class Nn extends si{constructor(t){super(),this.content=t}toDOM(){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild("string"==typeof this.content?document.createTextNode(this.content):this.content),"string"==typeof this.content?t.setAttribute("aria-label","placeholder "+this.content):t.setAttribute("aria-hidden","true"),t}coordsAt(t){let e=t.firstChild?ne(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=ae(e[0],"rtl"!=i.direction),r=parseInt(i.lineHeight);return s.bottom-s.top>1.5*r?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function jn(t){return _i.fromClass(class{constructor(e){this.view=e,this.placeholder=t?ni.set([ni.widget({widget:new Nn(t),side:1}).range(0)]):ni.none}get decorations(){return this.view.state.doc.length?ni.none:this.placeholder}},{decorations:t=>t.decorations})}const $n=2e3;function zn(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(i),r=i-s.from,n=r>$n?-1:r==s.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Vt(s.text,t.state.tabSize,i-s.from);return{line:s.number,col:n,off:r}}function Pn(t,e){let i=zn(t,e),s=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),r=t.state.doc.lineAt(e);i={line:r.number,col:i.col,off:Math.min(i.off,r.length)},s=s.map(t.changes)}},get(e,r,n){let h=zn(t,e);if(!h)return s;let l=function(t,e,i){let s=Math.min(e.line,i.line),r=Math.max(e.line,i.line),n=[];if(e.off>$n||i.off>$n||e.col<0||i.col<0){let h=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=s;e<=r;e++){let i=t.doc.line(e);i.length<=l&&n.push(B.range(i.from+h,i.to+l))}}else{let h=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=s;e<=r;e++){let i=t.doc.line(e),s=Ft(i.text,h,t.tabSize,!0);if(s<0)n.push(B.cursor(i.to));else{let e=Ft(i.text,l,t.tabSize);n.push(B.range(i.from+s,i.from+e))}}}return n}(t.state,i,h);return l.length?n?B.create(l.concat(s.ranges)):B.create(l):s}}:null}const Hn={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Wn={style:"cursor: crosshair"};const Vn="-10000px";class Fn{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter((t=>t));let r=null;this.tooltipViews=this.tooltips.map((t=>r=i(t,r)))}update(t,e){var i;let s=t.state.facet(this.facet),r=s.filter((t=>t));if(s===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let n=[],h=e?[]:null;for(let i=0;i<r.length;i++){let s=r[i],l=-1;if(s){for(let t=0;t<this.tooltips.length;t++){let e=this.tooltips[t];e&&e.create==s.create&&(l=t)}if(l<0)n[i]=this.createTooltipView(s,i?n[i-1]:null),h&&(h[i]=!!s.above);else{let s=n[i]=this.tooltipViews[l];h&&(h[i]=e[l]),s.update&&s.update(t)}}}for(let t of this.tooltipViews)n.indexOf(t)<0&&(this.removeTooltipView(t),null===(i=t.destroy)||void 0===i||i.call(t));return e&&(h.forEach(((t,i)=>e[i]=t)),e.length=h.length),this.input=s,this.tooltips=r,this.tooltipViews=n,!0}}function qn(t){let{win:e}=t;return{top:0,left:0,bottom:e.innerHeight,right:e.innerWidth}}const Un=j.define({combine:t=>{var e,i,s;return{position:Ve.ios?"absolute":(null===(e=t.find((t=>t.position)))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find((t=>t.parent)))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(s=t.find((t=>t.tooltipSpace)))||void 0===s?void 0:s.tooltipSpace)||qn}}}),Jn=new WeakMap,Gn=_i.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(Un);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver((()=>this.measureSoon())):null,this.manager=new Fn(t,Xn,((t,e)=>this.createTooltip(t,e)),(t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()})),this.above=this.manager.tooltips.map((t=>!!t.above)),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver((t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()}),{threshold:[1]}):null,this.observeIntersection(),t.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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1,this.maybeMeasure()}),50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,s=t.state.facet(Un);if(s.position!=this.position&&!this.madeAbsolute){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(s.parent!=this.parent){this.parent&&this.container.remove(),this.parent=s.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),s=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=Vn,i.dom.style.left="0px",this.container.insertBefore(i.dom,s),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=this.view.dom.getBoundingClientRect(),e=1,i=1,s=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(Ve.gecko)s=t.offsetParent!=this.container.ownerDocument.body;else if(t.style.top==Vn&&"0px"==t.style.left){let e=t.getBoundingClientRect();s=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}}if(s||"absolute"==this.position)if(this.parent){let t=this.parent.getBoundingClientRect();t.width&&t.height&&(e=t.width/this.parent.offsetWidth,i=t.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:i}=this.view.viewState);return{editor:t,parent:this.parent?this.container.getBoundingClientRect():t,pos:this.manager.tooltips.map(((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)})),size:this.manager.tooltipViews.map((({dom:t})=>t.getBoundingClientRect())),space:this.view.state.facet(Un).tooltipSpace(this.view),scaleX:e,scaleY:i,makeAbsolute:s}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{editor:i,space:s,scaleX:r,scaleY:n}=t,h=[];for(let l=0;l<this.manager.tooltips.length;l++){let o=this.manager.tooltips[l],u=this.manager.tooltipViews[l],{dom:f}=u,a=t.pos[l],c=t.size[l];if(!a||a.bottom<=Math.max(i.top,s.top)||a.top>=Math.min(i.bottom,s.bottom)||a.right<Math.max(i.left,s.left)-.1||a.left>Math.min(i.right,s.right)+.1){f.style.top=Vn;continue}let d=o.arrow?u.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=c.right-c.left,g=null!==(e=Jn.get(u))&&void 0!==e?e:c.bottom-c.top,w=u.offset||_n,b=this.view.textDirection==pi.LTR,v=c.width>s.right-s.left?b?s.left:s.right-c.width:b?Math.min(a.left-(d?14:0)+w.x,s.right-m):Math.max(s.left,a.left-m+(d?14:0)-w.x),k=this.above[l];!o.strictSide&&(k?a.top-(c.bottom-c.top)-w.y<s.top:a.bottom+(c.bottom-c.top)+w.y>s.bottom)&&k==s.bottom-a.bottom>a.top-s.top&&(k=this.above[l]=!k);let y=(k?a.top-s.top:s.bottom-a.bottom)-p;if(y<g&&!1!==u.resize){if(y<this.view.defaultLineHeight){f.style.top=Vn;continue}Jn.set(u,g),f.style.height=(g=y)/n+"px"}else f.style.height&&(f.style.height="");let M=k?a.top-g-p-w.y:a.bottom+p+w.y,x=v+m;if(!0!==u.overlap)for(let t of h)t.left<x&&t.right>v&&t.top<M+g&&t.bottom>M&&(M=k?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(f.style.top=(M-t.parent.top)/n+"px",f.style.left=(v-t.parent.left)/r+"px"):(f.style.top=M/n+"px",f.style.left=v/r+"px"),d){let t=a.left+(b?w.x:-w.x)-(v+14-7);d.style.left=t/r+"px"}!0!==u.overlap&&h.push({left:v,top:M,right:x,bottom:M+g}),f.classList.toggle("cm-tooltip-above",k),f.classList.toggle("cm-tooltip-below",!k),u.positioned&&u.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=Vn}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Kn=Ur.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"}}}),_n={x:0,y:0},Xn=j.define({enables:[Gn,Kn]}),Yn=j.define({combine:t=>t.reduce(((t,e)=>t.concat(e)),[])});class Qn{static create(t){return new Qn(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Fn(t,Yn,((t,e)=>this.createHostedView(t,e)),(t=>t.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)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(void 0!==s)if(void 0===e)e=s;else if(e!==s)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 Zn=Xn.compute([Yn],(t=>{let e=t.facet(Yn);return 0===e.length?null:{pos:Math.min(...e.map((t=>t.pos))),end:Math.max(...e.map((t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos}))),create:Qn.create,above:e[0].above,arrow:e.some((t=>t.arrow))}}));class th{constructor(t,e,i,s,r){this.view=t,this.source=e,this.field=i,this.setHover=s,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 s,r=1;if(i instanceof Ue)s=i.posAtStart;else{if(s=t.posAtCoords(e),null==s)return;let i=t.coordsAtPos(s);if(!i||e.y<i.top||e.y>i.bottom||e.x<i.left-t.defaultCharacterWidth||e.x>i.right+t.defaultCharacterWidth)return;let n=t.bidiSpans(t.state.doc.lineAt(s)).find((t=>t.from<=s&&t.to>=s)),h=n&&n.dir==pi.RTL?-1:1;r=e.x<i.left?-h:h}let n=this.source(t,s,r);if(null==n?void 0:n.then){let e=this.pending={pos:s};n.then((i=>{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))}),(e=>Ui(t.state,e,"hover tooltip")))}else!n||Array.isArray(n)&&!n.length||t.dispatch({effects:this.setHover.of(Array.isArray(n)?n:[n])})}get tooltip(){let t=this.view.plugin(Gn),e=t?t.manager.tooltips.findIndex((t=>t.create==Qn.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:s,tooltip:r}=this;if(s.length&&r&&!function(t,e){let i=t.getBoundingClientRect();return e.clientX>=i.left-eh&&e.clientX<=i.right+eh&&e.clientY>=i.top-eh&&e.clientY<=i.bottom+eh}(r.dom,t)||this.pending){let{pos:r}=s[0]||this.pending,n=null!==(i=null===(e=s[0])||void 0===e?void 0:e.end)&&void 0!==i?i:r;(r==n?this.view.posAtCoords(this.lastMove)==r:function(t,e,i,s,r,n){let h=t.scrollDOM.getBoundingClientRect(),l=t.documentTop+t.documentPadding.top+t.contentHeight;if(h.left>s||h.right<s||h.top>r||Math.min(h.bottom,l)<r)return!1;let o=t.posAtCoords({x:s,y:r},!1);return o>=e&&o<=i}(this.view,r,n,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:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.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 eh=4;function ih(t,e={}){let i=ct.define(),s=F.define({create:()=>[],update(t,s){if(t.length&&(e.hideOnChange&&(s.docChanged||s.selection)?t=[]:e.hideOn&&(t=t.filter((t=>!e.hideOn(s,t)))),s.docChanged)){let e=[];for(let i of t){let t=s.changes.mapPos(i.pos,-1,x.TrackDel);if(null!=t){let r=Object.assign(Object.create(null),i);r.pos=t,null!=r.end&&(r.end=s.changes.mapPos(r.end)),e.push(r)}}t=e}for(let e of s.effects)e.is(i)&&(t=e.value),e.is(rh)&&(t=[]);return t},provide:t=>Yn.from(t)});return[s,_i.define((r=>new th(r,t,s,i,e.hoverTime||300))),Zn]}function sh(t,e){let i=t.plugin(Gn);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}const rh=ct.define(),nh=j.define({combine(t){let e,i;for(let s of t)e=e||s.topContainer,i=i||s.bottomContainer;return{topContainer:e,bottomContainer:i}}});function hh(t,e){let i=t.plugin(lh),s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const lh=_i.fromClass(class{constructor(t){this.input=t.state.facet(fh),this.specs=this.input.filter((t=>t)),this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(nh);this.top=new oh(t,!0,e.topContainer),this.bottom=new oh(t,!1,e.bottomContainer),this.top.sync(this.panels.filter((t=>t.top))),this.bottom.sync(this.panels.filter((t=>!t.top)));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(nh);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new oh(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new oh(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(fh);if(i!=this.input){let e=i.filter((t=>t)),s=[],r=[],n=[],h=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),h.push(e)):(e=this.panels[l],e.update&&e.update(t)),s.push(e),(e.top?r:n).push(e)}this.specs=e,this.panels=s,this.top.sync(r),this.bottom.sync(n);for(let t of h)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>Ur.scrollMargins.of((e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class oh{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(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=uh(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=uh(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 uh(t){let e=t.nextSibling;return t.remove(),e}const fh=j.define({enables:lh});class ah extends Ct{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}ah.prototype.elementClass="",ah.prototype.toDOM=void 0,ah.prototype.mapMode=x.TrackBefore,ah.prototype.startSide=ah.prototype.endSide=-1,ah.prototype.point=!0;const ch=j.define(),dh={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>It.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},ph=j.define();function mh(t){return[wh(),ph.of(Object.assign(Object.assign({},dh),t))]}const gh=j.define({combine:t=>t.some((t=>t))});function wh(t){let e=[bh];return t&&!1===t.fixed&&e.push(gh.of(!0)),e}const bh=_i.fromClass(class{constructor(t){this.view=t,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(ph).map((e=>new Mh(t,e)));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!t.state.facet(gh),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<.8*(i.to-i.from))}t.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(gh)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&this.dom.remove();let i=It.iter(this.view.state.facet(ch),this.view.viewport.from),s=[],r=this.gutters.map((t=>new yh(t,this.view.viewport,-this.view.documentPadding.top)));for(let t of this.view.viewportLineBlocks)if(s.length&&(s=[]),Array.isArray(t.type)){let e=!0;for(let n of t.type)if(n.type==ri.Text&&e){kh(i,s,n.from);for(let t of r)t.line(this.view,n,s);e=!1}else if(n.widget)for(let t of r)t.widget(this.view,n)}else if(t.type==ri.Text){kh(i,s,t.from);for(let e of r)e.line(this.view,t,s)}else if(t.widget)for(let e of r)e.widget(this.view,t);for(let t of r)t.finish();t&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(t){let e=t.startState.facet(ph),i=t.state.facet(ph),s=t.docChanged||t.heightChanged||t.viewportChanged||!It.eq(t.startState.facet(ch),t.state.facet(ch),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(s=!0);else{s=!0;let r=[];for(let s of i){let i=e.indexOf(s);i<0?r.push(new Mh(this.view,s)):(this.gutters[i].update(t),r.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),r.indexOf(t)<0&&t.destroy();for(let t of r)this.dom.appendChild(t.dom);this.gutters=r}return s}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove()}},{provide:t=>Ur.scrollMargins.of((e=>{let i=e.plugin(t);return i&&0!=i.gutters.length&&i.fixed?e.textDirection==pi.LTR?{left:i.dom.offsetWidth*e.scaleX}:{right:i.dom.offsetWidth*e.scaleX}:null}))});function vh(t){return Array.isArray(t)?t:[t]}function kh(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class yh{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=It.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,r=(e.top-this.height)/t.scaleY,n=e.height/t.scaleY;if(this.i==s.elements.length){let e=new xh(t,n,r,i);s.elements.push(e),s.dom.appendChild(e.dom)}else s.elements[this.i].update(t,n,r,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];kh(this.cursor,s,e.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let n=this.gutter;(0!=s.length||n.config.renderEmptyElements)&&this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e);i&&this.addElement(t,e,[i])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Mh{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,(s=>{let r,n=s.target;if(n!=this.dom&&this.dom.contains(n)){for(;n.parentNode!=this.dom;)n=n.parentNode;let t=n.getBoundingClientRect();r=(t.top+t.bottom)/2}else r=s.clientY;let h=t.lineBlockAtHeight(r-t.documentTop);e.domEventHandlers[i](t,h,s)&&s.preventDefault()}));this.markers=vh(e.markers(t)),e.initialSpacer&&(this.spacer=new xh(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=vh(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!It.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class xh{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].compare(e[i]))return!1;return!0}(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,n=0;;){let h=n,l=r<e.length?e[r++]:null,o=!1;if(l){let t=l.elementClass;t&&(i+=" "+t);for(let t=n;t<this.markers.length;t++)if(this.markers[t].compare(l)){h=t,o=!0;break}}else h=this.markers.length;for(;n<h;){let t=this.markers[n++];if(t.toDOM){t.destroy(s);let e=s.nextSibling;s.remove(),s=e}}if(!l)break;l.toDOM&&(o?s=s.nextSibling:this.dom.insertBefore(l.toDOM(t),s)),o&&n++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}const Sh=j.define(),Ah=j.define({combine:t=>At(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let s=i[t],r=e[t];i[t]=s?(t,e,i)=>s(t,e,i)||r(t,e,i):r}return i}})});class Ch extends ah{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Oh(t,e){return t.state.facet(Ah).formatNumber(e,t.state)}const Dh=ph.compute([Ah],(t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(Sh),lineMarker:(t,e,i)=>i.some((t=>t.toDOM))?null:new Ch(Oh(t,t.state.doc.lineAt(e.from).number)),widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(Ah)!=t.state.facet(Ah),initialSpacer:t=>new Ch(Oh(t,Ih(t.state.doc.lines))),updateSpacer(t,e){let i=Oh(e.view,Ih(e.view.state.doc.lines));return i==t.number?t:new Ch(i)},domEventHandlers:t.facet(Ah).domEventHandlers})));function Eh(t={}){return[Ah.of(t),wh(),Dh]}function Ih(t){let e=9;for(;e<t;)e=10*e+9;return e}const Rh=new class extends ah{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Th=ch.compute(["selection"],(t=>{let e=[],i=-1;for(let s of t.selection.ranges){let r=t.doc.lineAt(s.head).from;r>i&&(i=r,e.push(Rh.range(r)))}return It.of(e)}));const Bh=1024;let Lh=0;class Nh{constructor(t,e){this.from=t,this.to=e}}class jh{constructor(t={}){this.id=Lh++,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"function"!=typeof t&&(t=Ph.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}jh.closedBy=new jh({deserialize:t=>t.split(" ")}),jh.openedBy=new jh({deserialize:t=>t.split(" ")}),jh.group=new jh({deserialize:t=>t.split(" ")}),jh.isolate=new jh({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),jh.contextHash=new jh({perNode:!0}),jh.lookAhead=new jh({perNode:!0}),jh.mounted=new jh({perNode:!0});class $h{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[jh.mounted.id]}}const zh=Object.create(null);class Ph{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):zh,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),s=new Ph(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(s)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return s}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(jh.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return t=>{for(let i=t.prop(jh.group),s=-1;s<(i?i.length:0);s++){let r=e[s<0?t.name:i[s]];if(r)return r}}}}Ph.none=new Ph("",Object.create(null),0,8);class Hh{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let s=null;for(let e of t){let t=e(i);t&&(s||(s=Object.assign({},i.props)),s[t[0].id]=t[1])}e.push(s?new Ph(i.name,s,i.id,i.flags):i)}return new Hh(e)}}const Wh=new WeakMap,Vh=new WeakMap;var Fh;!function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays"}(Fh||(Fh={}));class qh{constructor(t,e,i,s,r){if(this.type=t,this.children=e,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[t,e]of r)this.props["number"==typeof t?t:t.id]=e}}toString(){let t=$h.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let t of this.children){let i=t.toString();i&&(e&&(e+=","),e+=i)}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 sl(this.topNode,t)}cursorAt(t,e=0,i=0){let s=Wh.get(this)||this.topNode,r=new sl(s);return r.moveTo(t,e),Wh.set(this,r._tree),r}get topNode(){return new Xh(this,0,0,null)}resolve(t,e=0){let i=Kh(Wh.get(this)||this.topNode,t,e,!1);return Wh.set(this,i),i}resolveInner(t,e=0){let i=Kh(Vh.get(this)||this.topNode,t,e,!0);return Vh.set(this,i),i}resolveStack(t,e=0){return function(t,e,i){let s=t.resolveInner(e,i),r=null;for(let t=s instanceof Xh?s:s.context.parent;t;t=t.parent)if(t.index<0){let n=t.parent;(r||(r=[s])).push(n.resolve(e,i)),t=n}else{let n=$h.get(t.tree);if(n&&n.overlay&&n.overlay[0].from<=e&&n.overlay[n.overlay.length-1].to>=e){let h=new Xh(n.tree,n.overlay[0].from+t.from,-1,t);(r||(r=[s])).push(Kh(h,e,i,!1))}}return r?el(r):s}(this,t,e)}iterate(t){let{enter:e,leave:i,from:s=0,to:r=this.length}=t,n=t.mode||0,h=(n&Fh.IncludeAnonymous)>0;for(let t=this.cursor(n|Fh.IncludeAnonymous);;){let n=!1;if(t.from<=r&&t.to>=s&&(!h&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;n=!0}for(;n&&i&&(h||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;n=!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:ll(Ph.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,i)=>new qh(this.type,t,e,i,this.propValues)),t.makeTree||((t,e,i)=>new qh(Ph.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:s,maxBufferLength:r=Bh,reused:n=[],minRepeatType:h=s.types.length}=t,l=Array.isArray(i)?new Uh(i,i.length):i,o=s.types,u=0,f=0;function a(t,e,i,b,v,k){let{id:y,start:M,end:x,size:S}=l,A=f;for(;S<0;){if(l.next(),-1==S){let e=n[y];return i.push(e),void b.push(M-t)}if(-3==S)return void(u=y);if(-4==S)return void(f=y);throw new RangeError(`Unrecognized record size: ${S}`)}let C,O,D=o[y],E=M-t;if(x-M<=r&&(O=g(l.pos-e,v))){let e=new Uint16Array(O.size-O.skip),i=l.pos-O.size,r=e.length;for(;l.pos>i;)r=w(O.start,e,r);C=new Jh(e,x-O.start,s),E=O.start-t}else{let t=l.pos-S;l.next();let e=[],i=[],s=y>=h?y:-1,n=0,o=x;for(;l.pos>t;)s>=0&&l.id==s&&l.size>=0?(l.end<=o-r&&(p(e,i,M,n,l.end,o,s,A),n=e.length,o=l.end),l.next()):k>2500?c(M,t,e,i):a(M,t,e,i,s,k+1);if(s>=0&&n>0&&n<e.length&&p(e,i,M,n,M,o,s,A),e.reverse(),i.reverse(),s>-1&&n>0){let t=d(D);C=ll(D,e,i,0,e.length,0,x-M,t,t)}else C=m(D,e,i,x-M,A-x)}i.push(C),b.push(E)}function c(t,e,i,n){let h=[],o=0,u=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:s}=l;if(s>4)l.next();else{if(u>-1&&e<u)break;u<0&&(u=i-r),h.push(t,e,i),o++,l.next()}}if(o){let e=new Uint16Array(4*o),r=h[h.length-2];for(let t=h.length-3,i=0;t>=0;t-=3)e[i++]=h[t],e[i++]=h[t+1]-r,e[i++]=h[t+2]-r,e[i++]=i;i.push(new Jh(e,h[2]-r,s)),n.push(r-t)}}function d(t){return(e,i,s)=>{let r,n,h=0,l=e.length-1;if(l>=0&&(r=e[l])instanceof qh){if(!l&&r.type==t&&r.length==s)return r;(n=r.prop(jh.lookAhead))&&(h=i[l]+r.length+n)}return m(t,e,i,s,h)}}function p(t,e,i,r,n,h,l,o){let u=[],f=[];for(;t.length>r;)u.push(t.pop()),f.push(e.pop()+i-n);t.push(m(s.types[l],u,f,h-n,o-h)),e.push(n-i)}function m(t,e,i,s,r=0,n){if(u){let t=[jh.contextHash,u];n=n?[t].concat(n):[t]}if(r>25){let t=[jh.lookAhead,r];n=n?[t].concat(n):[t]}return new qh(t,e,i,s,n)}function g(t,e){let i=l.fork(),s=0,n=0,o=0,u=i.end-r,f={size:0,start:0,skip:0};t:for(let r=i.pos-t;i.pos>r;){let t=i.size;if(i.id==e&&t>=0){f.size=s,f.start=n,f.skip=o,o+=4,s+=4,i.next();continue}let l=i.pos-t;if(t<0||l<r||i.start<u)break;let a=i.id>=h?4:0,c=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size)break t;a+=4}else i.id>=h&&(a+=4);i.next()}n=c,s+=t,o+=a}return(e<0||s==t)&&(f.size=s,f.start=n,f.skip=o),f.size>4?f:void 0}function w(t,e,i){let{id:s,start:r,end:n,size:o}=l;if(l.next(),o>=0&&s<h){let h=i;if(o>4){let s=l.pos-(o-4);for(;l.pos>s;)i=w(t,e,i)}e[--i]=h,e[--i]=n-t,e[--i]=r-t,e[--i]=s}else-3==o?u=s:-4==o&&(f=s);return i}let b=[],v=[];for(;l.pos>0;)a(t.start||0,t.bufferStart||0,b,v,-1,0);let k=null!==(e=t.length)&&void 0!==e?e:b.length?v[0]+b[0].length:0;return new qh(o[t.topID],b.reverse(),v.reverse(),k)}(t)}}qh.empty=new qh(Ph.none,[],[],0);class Uh{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 Uh(this.buffer,this.index)}}class Jh{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return Ph.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],s=this.set.types[e],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),i==(t+=4))return r;let n=[];for(;t<i;)n.push(this.childString(t)),t=this.buffer[t+3];return r+"("+n.join(",")+")"}findChild(t,e,i,s,r){let{buffer:n}=this,h=-1;for(let l=t;l!=e&&!(Gh(r,s,n[l+1],n[l+2])&&(h=l,i>0));l=n[l+3]);return h}slice(t,e,i){let s=this.buffer,r=new Uint16Array(e-t),n=0;for(let h=t,l=0;h<e;){r[l++]=s[h++],r[l++]=s[h++]-i;let e=r[l++]=s[h++]-i;r[l++]=s[h++]-t,n=Math.max(n,e)}return new Jh(r,n,this.set)}}function Gh(t,e,i,s){switch(t){case-2:return i<e;case-1:return s>=e&&i<e;case 0:return i<e&&s>e;case 1:return i<=e&&s>e;case 2:return s>e;case 4:return!0}}function Kh(t,e,i,s){for(var r;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to<e);){let e=!s&&t instanceof Xh&&t.index<0?null:t.parent;if(!e)return t;t=e}let n=s?0:Fh.IgnoreOverlays;if(s)for(let s=t,h=s.parent;h;s=h,h=s.parent)s instanceof Xh&&s.index<0&&(null===(r=h.enter(e,i,n))||void 0===r?void 0:r.from)!=s.from&&(t=h);for(;;){let s=t.enter(e,i,n);if(!s)return t;t=s}}class _h{cursor(t=0){return new sl(this,t)}getChild(t,e=null,i=null){let s=Yh(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Yh(this,t,e,i)}resolve(t,e=0){return Kh(this,t,e,!1)}resolveInner(t,e=0){return Kh(this,t,e,!0)}matchContext(t){return Qh(this,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let t=e.lastChild;if(!t||t.to!=e.to)break;t.type.isError&&t.from==t.to?(i=e,e=t.prevSibling):e=t}return i}get node(){return this}get next(){return this.parent}}class Xh extends _h{constructor(t,e,i,s){super(),this._tree=t,this.from=e,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,i,s,r=0){for(let n=this;;){for(let{children:h,positions:l}=n._tree,o=e>0?h.length:-1;t!=o;t+=e){let o=h[t],u=l[t]+n.from;if(Gh(s,i,u,u+o.length))if(o instanceof Jh){if(r&Fh.ExcludeBuffers)continue;let h=o.findChild(0,o.buffer.length,e,i-u,s);if(h>-1)return new tl(new Zh(n,o,t,u),null,h)}else if(r&Fh.IncludeAnonymous||!o.type.isAnonymous||rl(o)){let h;if(!(r&Fh.IgnoreMounts)&&(h=$h.get(o))&&!h.overlay)return new Xh(h.tree,u,t,n);let l=new Xh(o,u,t,n);return r&Fh.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?o.children.length-1:0,e,i,s)}}if(r&Fh.IncludeAnonymous||!n.type.isAnonymous)return null;if(t=n.index>=0?n.index+e:e<0?-1:n._parent._tree.children.length,n=n._parent,!n)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let s;if(!(i&Fh.IgnoreOverlays)&&(s=$h.get(this._tree))&&s.overlay){let i=t-this.from;for(let{from:t,to:r}of s.overlay)if((e>0?t<=i:t<i)&&(e<0?r>=i:r>i))return new Xh(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Yh(t,e,i,s){let r=t.cursor(),n=[];if(!r.firstChild())return n;if(null!=i)for(let t=!1;!t;)if(t=r.type.is(i),!r.nextSibling())return n;for(;;){if(null!=s&&r.type.is(s))return n;if(r.type.is(e)&&n.push(r.node),!r.nextSibling())return null==s?n:[]}}function Qh(t,e,i=e.length-1){for(let s=t.parent;i>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(e[i]&&e[i]!=s.name)return!1;i--}}return!0}class Zh{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class tl extends _h{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new tl(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&Fh.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new tl(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 tl(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 tl(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let n=i.buffer[this.index+1];t.push(i.slice(s,r,n)),e.push(0)}return new qh(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function el(t){if(!t.length)return null;let e=0,i=t[0];for(let s=1;s<t.length;s++){let r=t[s];(r.from>i.from||r.to<i.to)&&(i=r,e=s)}let s=i instanceof Xh&&i.index<0?null:i.parent,r=t.slice();return s?r[e]=s:r.splice(e,1),new il(r,i)}class il{constructor(t,e){this.heads=t,this.node=e}get next(){return el(this.heads)}}class sl{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 Xh)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.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)}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return!!t&&(t instanceof Xh?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.buffer.start,i);return!(r<0)&&(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&Fh.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Fh.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Fh.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));let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let t=i<0?0:this.stack[i]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(t)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>0){if(this.index<s.buffer.buffer.length)return!1}else for(let t=0;t<this.index;t++)if(s.buffer.buffer[t+3]<this.index)return!1;({index:e,parent:i}=s)}else({index:e,_parent:i}=this._tree);for(;i;({index:e,_parent:i}=i))if(e>-1)for(let s=e+t,r=t<0?-1:i._tree.children.length;s!=r;s+=t){let t=i._tree.children[s];if(this.mode&Fh.IncludeAnonymous||t instanceof Jh||!t.type.isAnonymous||rl(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let s=this.index,r=this.stack.length;r>=0;){for(let n=t;n;n=n._parent)if(n.index==s){if(s==this.index)return n;e=n,i=r+1;break t}s=this.stack[--r]}for(let t=i;t<this.stack.length;t++)e=new tl(this.buffer,e,this.stack[t]);return this.bufferNode=new tl(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let s=!1;if(this.type.isAnonymous||!1!==t(this)){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;s&&e&&e(this),s=this.type.isAnonymous,!this.nextSibling();){if(!i)return;this.parent(),i--,s=!0}}}matchContext(t){if(!this.buffer)return Qh(this.node,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let s=t.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Qh(this.node,t,s);let n=i[e.buffer[this.stack[r]]];if(!n.isAnonymous){if(t[s]&&t[s]!=n.name)return!1;s--}}return!0}}function rl(t){return t.children.some((t=>t instanceof Jh||!t.type.isAnonymous||rl(t)))}const nl=new WeakMap;function hl(t,e){if(!t.isAnonymous||e instanceof Jh||e.type!=t)return 1;let i=nl.get(e);if(null==i){i=1;for(let s of e.children){if(s.type!=t||!(s instanceof qh)){i=1;break}i+=hl(t,s)}nl.set(e,i)}return i}function ll(t,e,i,s,r,n,h,l,o){let u=0;for(let i=s;i<r;i++)u+=hl(t,e[i]);let f=Math.ceil(1.5*u/8),a=[],c=[];return function e(i,s,r,h,l){for(let u=r;u<h;){let r=u,d=s[u],p=hl(t,i[u]);for(u++;u<h;u++){let e=hl(t,i[u]);if(p+e>=f)break;p+=e}if(u==r+1){if(p>f){let t=i[r];e(t.children,t.positions,0,t.children.length,s[r]+l);continue}a.push(i[r])}else{let e=s[u-1]+i[u-1].length-d;a.push(ll(t,i,s,r,u,d,e,null,o))}c.push(d+l-n)}}(e,i,s,r,0),(l||o)(a,c,h)}class ol{constructor(){this.map=new WeakMap}setBuffer(t,e,i){let s=this.map.get(t);s||this.map.set(t,s=new Map),s.set(e,i)}getBuffer(t,e){let i=this.map.get(t);return i&&i.get(e)}set(t,e){t instanceof tl?this.setBuffer(t.context.buffer,t.index,e):t instanceof Xh&&this.map.set(t.tree,e)}get(t){return t instanceof tl?this.getBuffer(t.context.buffer,t.index):t instanceof Xh?this.map.get(t.tree):void 0}cursorSet(t,e){t.buffer?this.setBuffer(t.buffer.buffer,t.index,e):this.map.set(t.tree,e)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}}class ul{constructor(t,e,i,s,r=!1,n=!1){this.from=t,this.to=e,this.tree=i,this.offset=s,this.open=(r?1:0)|(n?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let s=[new ul(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&s.push(i);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],r=1,n=t.length?t[0]:null;for(let h=0,l=0,o=0;;h++){let u=h<e.length?e[h]:null,f=u?u.fromA:1e9;if(f-l>=i)for(;n&&n.from<f;){let e=n;if(l>=e.from||f<=e.to||o){let t=Math.max(e.from,l)-o,i=Math.min(e.to,f)-o;e=t>=i?null:new ul(t,i,e.tree,e.offset+o,h>0,!!u)}if(e&&s.push(e),n.to>f)break;n=r<t.length?t[r++]:null}if(!u)break;l=u.toA,o=u.toA-u.toB}return s}}class fl{startParse(t,e,i){return"string"==typeof t&&(t=new al(t)),i=i?i.length?i.map((t=>new Nh(t.from,t.to))):[new Nh(0,0)]:[new Nh(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let t=s.advance();if(t)return t}}}class al{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}function cl(t){return(e,i,s,r)=>new wl(e,t,i,s,r)}class dl{constructor(t,e,i,s,r){this.parser=t,this.parse=e,this.overlay=i,this.target=s,this.from=r}}function pl(t){if(!t.length||t.some((t=>t.from>=t.to)))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(t))}class ml{constructor(t,e,i,s,r,n,h){this.parser=t,this.predicate=e,this.mounts=i,this.index=s,this.start=r,this.target=n,this.prev=h,this.depth=0,this.ranges=[]}}const gl=new jh({perNode:!0});class wl{constructor(t,e,i,s,r){this.nest=e,this.input=i,this.fragments=s,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let t=this.baseParse.advance();if(!t)return null;if(this.baseParse=null,this.baseTree=t,this.startInner(),null!=this.stoppedAt)for(let t of this.inner)t.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let t=this.baseTree;return null!=this.stoppedAt&&(t=new qh(t.type,t.children,t.positions,t.length,t.propValues.concat([[gl,this.stoppedAt]]))),t}let t=this.inner[this.innerDone],e=t.parse.advance();if(e){this.innerDone++;let i=Object.assign(Object.create(null),t.target.props);i[jh.mounted.id]=new $h(e,t.overlay,t.parser),t.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].from<t&&(t=Math.min(t,this.inner[e].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].parse.stopAt(t)}startInner(){let t=new Ml(this.fragments),e=null,i=null,s=new sl(new Xh(this.baseTree,this.ranges[0].from,0,null),Fh.IncludeAnonymous|Fh.IgnoreMounts);t:for(let r,n;;){let h,l=!0;if(null!=this.stoppedAt&&s.from>=this.stoppedAt)l=!1;else if(t.hasNode(s)){if(e){let t=e.mounts.find((t=>t.frag.from<=s.from&&t.frag.to>=s.to&&t.mount.overlay));if(t)for(let i of t.mount.overlay){let r=i.from+t.pos,n=i.to+t.pos;r>=s.from&&n<=s.to&&!e.ranges.some((t=>t.from<n&&t.to>r))&&e.ranges.push({from:r,to:n})}}l=!1}else if(i&&(n=bl(i.ranges,s.from,s.to)))l=2!=n;else if(!s.type.isAnonymous&&(r=this.nest(s,this.input))&&(s.from<s.to||!r.overlay)){s.tree||kl(s);let n=t.findMounts(s.from,r.parser);if("function"==typeof r.overlay)e=new ml(r.parser,r.overlay,n,this.inner.length,s.from,s.tree,e);else{let t=xl(this.ranges,r.overlay||(s.from<s.to?[new Nh(s.from,s.to)]:[]));t.length&&pl(t),!t.length&&r.overlay||this.inner.push(new dl(r.parser,t.length?r.parser.startParse(this.input,Al(n,t),t):r.parser.startParse(""),r.overlay?r.overlay.map((t=>new Nh(t.from-s.from,t.to-s.from))):null,s.tree,t.length?t[0].from:s.from)),r.overlay?t.length&&(i={ranges:t,depth:0,prev:i}):l=!1}}else e&&(h=e.predicate(s))&&(!0===h&&(h=new Nh(s.from,s.to)),h.from<h.to&&e.ranges.push(h));if(l&&s.firstChild())e&&e.depth++,i&&i.depth++;else for(;!s.nextSibling();){if(!s.parent())break t;if(e&&! --e.depth){let t=xl(this.ranges,e.ranges);t.length&&(pl(t),this.inner.splice(e.index,0,new dl(e.parser,e.parser.startParse(this.input,Al(e.mounts,t),t),e.ranges.map((t=>new Nh(t.from-e.start,t.to-e.start))),e.target,t[0].from))),e=e.prev}i&&! --i.depth&&(i=i.prev)}}}}function bl(t,e,i){for(let s of t){if(s.from>=i)break;if(s.to>e)return s.from<=e&&s.to>=i?2:1}return 0}function vl(t,e,i,s,r,n){if(e<i){let h=t.buffer[e+1];s.push(t.slice(e,i,h)),r.push(h-n)}}function kl(t){let{node:e}=t,i=[],s=e.context.buffer;do{i.push(t.index),t.parent()}while(!t.tree);let r=t.tree,n=r.children.indexOf(s),h=r.children[n],l=h.buffer,o=[n];r.children[n]=function t(s,r,n,u,f,a){let c=i[a],d=[],p=[];vl(h,s,c,d,p,u);let m=l[c+1],g=l[c+2];o.push(d.length);let w=a?t(c+4,l[c+3],h.set.types[l[c]],m,g-m,a-1):e.toTree();return d.push(w),p.push(m-u),vl(h,l[c+3],r,d,p,u),new qh(n,d,p,f)}(0,l.length,Ph.none,0,h.length,i.length-1);for(let e of o){let i=t.tree.children[e],s=t.tree.positions[e];t.yield(new Xh(i,s+t.from,e,t._tree))}}class yl{constructor(t,e){this.offset=e,this.done=!1,this.cursor=t.cursor(Fh.IncludeAnonymous|Fh.IgnoreMounts)}moveTo(t){let{cursor:e}=this,i=t-this.offset;for(;!this.done&&e.from<i;)e.to>=t&&e.enter(i,1,Fh.IgnoreOverlays|Fh.ExcludeBuffers)||e.next(!1)||(this.done=!0)}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let e=this.cursor.tree;;){if(e==t.tree)return!0;if(!(e.children.length&&0==e.positions[0]&&e.children[0]instanceof qh))break;e=e.children[0]}return!1}}class Ml{constructor(t){var e;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let i=this.curFrag=t[0];this.curTo=null!==(e=i.tree.prop(gl))&&void 0!==e?e:i.to,this.inner=new yl(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=null!==(t=e.tree.prop(gl))&&void 0!==t?t:e.to,this.inner=new yl(e.tree,-e.offset)}}findMounts(t,e){var i;let s=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let t=this.inner.cursor.node;t;t=t.parent){let r=null===(i=t.tree)||void 0===i?void 0:i.prop(jh.mounted);if(r&&r.parser==e)for(let e=this.fragI;e<this.fragments.length;e++){let i=this.fragments[e];if(i.from>=t.to)break;i.tree==this.curFrag.tree&&s.push({frag:i,pos:t.from-i.offset,mount:r})}}}return s}}function xl(t,e){let i=null,s=e;for(let r=1,n=0;r<t.length;r++){let h=t[r-1].to,l=t[r].from;for(;n<s.length;n++){let t=s[n];if(t.from>=l)break;t.to<=h||(i||(s=i=e.slice()),t.from<h?(i[n]=new Nh(t.from,h),t.to>l&&i.splice(n+1,0,new Nh(l,t.to))):t.to>l?i[n--]=new Nh(l,t.to):i.splice(n--,1))}}return s}function Sl(t,e,i,s){let r=0,n=0,h=!1,l=!1,o=-1e9,u=[];for(;;){let f=r==t.length?1e9:h?t[r].to:t[r].from,a=n==e.length?1e9:l?e[n].to:e[n].from;if(h!=l){let t=Math.max(o,i),e=Math.min(f,a,s);t<e&&u.push(new Nh(t,e))}if(o=Math.min(f,a),1e9==o)break;f==o&&(h?(h=!1,r++):h=!0),a==o&&(l?(l=!1,n++):l=!0)}return u}function Al(t,e){let i=[];for(let{pos:s,mount:r,frag:n}of t){let t=s+(r.overlay?r.overlay[0].from:0),h=t+r.tree.length,l=Math.max(n.from,t),o=Math.min(n.to,h);if(r.overlay){let h=Sl(e,r.overlay.map((t=>new Nh(t.from+s,t.to+s))),l,o);for(let e=0,s=l;;e++){let l=e==h.length,u=l?o:h[e].from;if(u>s&&i.push(new ul(s,u,r.tree,-t,n.from>=s||n.openStart,n.to<=u||n.openEnd)),l)break;s=h[e].to}}else i.push(new ul(l,o,r.tree,-t,n.from>=t||n.openStart,n.to<=h||n.openEnd))}return i}let Cl=0;class Ol{constructor(t,e,i){this.set=t,this.base=e,this.modified=i,this.id=Cl++}static define(t){if(null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let e=new Ol([],null,[]);if(e.set.push(e),t)for(let i of t.set)e.set.push(i);return e}static defineModifier(){let t=new El;return e=>e.modified.indexOf(t)>-1?e:El.get(e.base||e,e.modified.concat(t).sort(((t,e)=>t.id-e.id)))}}let Dl=0;class El{constructor(){this.instances=[],this.id=Dl++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find((i=>{return i.base==t&&(s=e,r=i.modified,s.length==r.length&&s.every(((t,e)=>t==r[e])));var s,r}));if(i)return i;let s=[],r=new Ol(s,t,e);for(let t of e)t.instances.push(r);let n=function(t){let e=[[]];for(let i=0;i<t.length;i++)for(let s=0,r=e.length;s<r;s++)e.push(e[s].concat(t[i]));return e.sort(((t,e)=>e.length-t.length))}(e);for(let e of t.set)if(!e.modified.length)for(let t of n)s.push(El.get(e,t));return r}}function Il(t){let e=Object.create(null);for(let i in t){let s=t[i];Array.isArray(s)||(s=[s]);for(let t of i.split(" "))if(t){let i=[],r=2,n=t;for(let e=0;;){if("..."==n&&e>0&&e+3==t.length){r=1;break}let s=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(n);if(!s)throw new RangeError("Invalid path: "+t);if(i.push("*"==s[0]?"":'"'==s[0][0]?JSON.parse(s[0]):s[0]),e+=s[0].length,e==t.length)break;let h=t[e++];if(e==t.length&&"!"==h){r=0;break}if("/"!=h)throw new RangeError("Invalid path: "+t);n=t.slice(e)}let h=i.length-1,l=i[h];if(!l)throw new RangeError("Invalid path: "+t);let o=new Tl(s,r,h>0?i.slice(0,h):null);e[l]=o.sort(e[l])}}return Rl.add(e)}const Rl=new jh;class Tl{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}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}}function Bl(t,e){let i=Object.create(null);for(let e of t)if(Array.isArray(e.tag))for(let t of e.tag)i[t.id]=e.class;else i[e.tag.id]=e.class;let{scope:s,all:r=null}=e||{};return{style:t=>{let e=r;for(let s of t)for(let t of s.set){let s=i[t.id];if(s){e=e?e+" "+s:s;break}}return e},scope:s}}function Ll(t,e,i,s=0,r=t.length){let n=new Nl(s,Array.isArray(e)?e:[e],i);n.highlightRange(t.cursor(),s,r,"",n.highlighters),n.flush(r)}Tl.empty=new Tl([],2,null);class Nl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,r){let{type:n,from:h,to:l}=t;if(h>=i||l<=e)return;n.isTop&&(r=this.highlighters.filter((t=>!t.scope||t.scope(n))));let o=s,u=function(t){let e=t.type.prop(Rl);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||Tl.empty,f=function(t,e){let i=null;for(let s of t){let t=s.style(e);t&&(i=i?i+" "+t:t)}return i}(r,u.tags);if(f&&(o&&(o+=" "),o+=f,1==u.mode&&(s+=(s?" ":"")+f)),this.startSpan(Math.max(e,h),o),u.opaque)return;let a=t.tree&&t.tree.prop(jh.mounted);if(a&&a.overlay){let n=t.node.enter(a.overlay[0].from+h,1),u=this.highlighters.filter((t=>!t.scope||t.scope(a.tree.type))),f=t.firstChild();for(let c=0,d=h;;c++){let p=c<a.overlay.length?a.overlay[c]:null,m=p?p.from+h:l,g=Math.max(e,d),w=Math.min(i,m);if(g<w&&f)for(;t.from<w&&(this.highlightRange(t,g,w,s,r),this.startSpan(Math.min(w,t.to),o),!(t.to>=m)&&t.nextSibling()););if(!p||m>i)break;d=p.to+h,d>e&&(this.highlightRange(n.cursor(),Math.max(e,p.from+h),Math.min(i,d),"",u),this.startSpan(Math.min(i,d),o))}f&&t.parent()}else if(t.firstChild()){a&&(s="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,r),this.startSpan(Math.min(i,t.to),o)}}while(t.nextSibling());t.parent()}}}const jl=Ol.define,$l=jl(),zl=jl(),Pl=jl(zl),Hl=jl(zl),Wl=jl(),Vl=jl(Wl),Fl=jl(Wl),ql=jl(),Ul=jl(ql),Jl=jl(),Gl=jl(),Kl=jl(),_l=jl(Kl),Xl=jl(),Yl={comment:$l,lineComment:jl($l),blockComment:jl($l),docComment:jl($l),name:zl,variableName:jl(zl),typeName:Pl,tagName:jl(Pl),propertyName:Hl,attributeName:jl(Hl),className:jl(zl),labelName:jl(zl),namespace:jl(zl),macroName:jl(zl),literal:Wl,string:Vl,docString:jl(Vl),character:jl(Vl),attributeValue:jl(Vl),number:Fl,integer:jl(Fl),float:jl(Fl),bool:jl(Wl),regexp:jl(Wl),escape:jl(Wl),color:jl(Wl),url:jl(Wl),keyword:Jl,self:jl(Jl),null:jl(Jl),atom:jl(Jl),unit:jl(Jl),modifier:jl(Jl),operatorKeyword:jl(Jl),controlKeyword:jl(Jl),definitionKeyword:jl(Jl),moduleKeyword:jl(Jl),operator:Gl,derefOperator:jl(Gl),arithmeticOperator:jl(Gl),logicOperator:jl(Gl),bitwiseOperator:jl(Gl),compareOperator:jl(Gl),updateOperator:jl(Gl),definitionOperator:jl(Gl),typeOperator:jl(Gl),controlOperator:jl(Gl),punctuation:Kl,separator:jl(Kl),bracket:_l,angleBracket:jl(_l),squareBracket:jl(_l),paren:jl(_l),brace:jl(_l),content:ql,heading:Ul,heading1:jl(Ul),heading2:jl(Ul),heading3:jl(Ul),heading4:jl(Ul),heading5:jl(Ul),heading6:jl(Ul),contentSeparator:jl(ql),list:jl(ql),quote:jl(ql),emphasis:jl(ql),strong:jl(ql),link:jl(ql),monospace:jl(ql),strikethrough:jl(ql),inserted:jl(),deleted:jl(),changed:jl(),invalid:jl(),meta:Xl,documentMeta:jl(Xl),annotation:jl(Xl),processingInstruction:jl(Xl),definition:Ol.defineModifier(),constant:Ol.defineModifier(),function:Ol.defineModifier(),standard:Ol.defineModifier(),local:Ol.defineModifier(),special:Ol.defineModifier()};var Ql;Bl([{tag:Yl.link,class:"tok-link"},{tag:Yl.heading,class:"tok-heading"},{tag:Yl.emphasis,class:"tok-emphasis"},{tag:Yl.strong,class:"tok-strong"},{tag:Yl.keyword,class:"tok-keyword"},{tag:Yl.atom,class:"tok-atom"},{tag:Yl.bool,class:"tok-bool"},{tag:Yl.url,class:"tok-url"},{tag:Yl.labelName,class:"tok-labelName"},{tag:Yl.inserted,class:"tok-inserted"},{tag:Yl.deleted,class:"tok-deleted"},{tag:Yl.literal,class:"tok-literal"},{tag:Yl.string,class:"tok-string"},{tag:Yl.number,class:"tok-number"},{tag:[Yl.regexp,Yl.escape,Yl.special(Yl.string)],class:"tok-string2"},{tag:Yl.variableName,class:"tok-variableName"},{tag:Yl.local(Yl.variableName),class:"tok-variableName tok-local"},{tag:Yl.definition(Yl.variableName),class:"tok-variableName tok-definition"},{tag:Yl.special(Yl.variableName),class:"tok-variableName2"},{tag:Yl.definition(Yl.propertyName),class:"tok-propertyName tok-definition"},{tag:Yl.typeName,class:"tok-typeName"},{tag:Yl.namespace,class:"tok-namespace"},{tag:Yl.className,class:"tok-className"},{tag:Yl.macroName,class:"tok-macroName"},{tag:Yl.propertyName,class:"tok-propertyName"},{tag:Yl.operator,class:"tok-operator"},{tag:Yl.comment,class:"tok-comment"},{tag:Yl.meta,class:"tok-meta"},{tag:Yl.invalid,class:"tok-invalid"},{tag:Yl.punctuation,class:"tok-punctuation"}]);const Zl=new jh;function to(t){return j.define({combine:t?e=>e.concat(t):void 0})}const eo=new jh;class io{constructor(t,e,i=[],s=""){this.data=t,this.name=s,St.prototype.hasOwnProperty("tree")||Object.defineProperty(St.prototype,"tree",{get(){return no(this)}}),this.parser=e,this.extension=[mo.of(this),St.languageData.of(((t,e,i)=>{let s=so(t,e,i),r=s.type.prop(Zl);if(!r)return[];let n=t.facet(r),h=s.type.prop(eo);if(h){let r=s.resolve(e-s.from,i);for(let e of h)if(e.test(r,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(n)}}return n}))].concat(i)}isActiveAt(t,e,i=-1){return so(t,e,i).type.prop(Zl)==this.data}findRegions(t){let e=t.facet(mo);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(t,e)=>{if(t.prop(Zl)==this.data)return void i.push({from:e,to:e+t.length});let r=t.prop(jh.mounted);if(r){if(r.tree.prop(Zl)==this.data){if(r.overlay)for(let t of r.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(r.overlay){let t=i.length;if(s(r.tree,r.overlay[0].from+e),i.length>t)return}}for(let i=0;i<t.children.length;i++){let r=t.children[i];r instanceof qh&&s(r,t.positions[i]+e)}};return s(no(t),0),i}get allowsNesting(){return!0}}function so(t,e,i){let s=t.facet(mo),r=no(t).topNode;if(!s||s.allowsNesting)for(let t=r;t;t=t.enter(e,i,Fh.ExcludeBuffers))t.type.isTop&&(r=t);return r}io.setState=ct.define();class ro extends io{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=to(t.languageData);return new ro(e,t.parser.configure({props:[Zl.add((t=>t.isTop?e:void 0))]}),t.name)}configure(t,e){return new ro(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function no(t){let e=t.field(io.state,!1);return e?e.tree:qh.empty}class ho{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 lo=null;class oo{constructor(t,e,i=[],s,r,n,h,l){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=n,this.skipped=h,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new oo(t,e,[],qh.empty,0,i,[],null)}startParse(){return this.parser.startParse(new ho(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=qh.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s){if(this.fragments=this.withoutTempSkipped(ul.addTree(s,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(i=this.parse.stoppedAt)&&void 0!==i?i:this.state.doc.length,this.tree=s,this.parse=null,!(this.treeLen<(null!=e?e:this.state.doc.length)))return!0;this.parse=this.startParse()}if(t())return!1}}))}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((null==this.parse.stoppedAt||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(ul.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=lo;lo=this;try{return t()}finally{lo=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=uo(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:n,skipped:h}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges(((t,i,s,r)=>e.push({fromA:t,toA:i,fromB:s,toB:r}))),i=ul.applyChanges(i,e),s=qh.empty,r=0,n={from:t.mapPos(n.from,-1),to:t.mapPos(n.to,1)},this.skipped.length){h=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),s=t.mapPos(e.to,-1);i<s&&h.push({from:i,to:s})}}}return new oo(this.parser,e,i,s,r,n,h,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 e=0;e<this.skipped.length;e++){let{from:i,to:s}=this.skipped[e];i<t.to&&s>t.from&&(this.fragments=uo(this.fragments,i,s),this.skipped.splice(e--,1))}return!(this.skipped.length>=e)&&(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 fl{createParse(e,i,s){let r=s[0].from,n=s[s.length-1].to;return{parsedPos:r,advance(){let e=lo;if(e){for(let t of s)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=n,new qh(Ph.none,[],[],n-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return lo}}function uo(t,e,i){return ul.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class fo{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 fo(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=oo.create(t.facet(mo).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new fo(i)}}io.state=F.define({create:fo.init,update(t,e){for(let t of e.effects)if(t.is(io.setState))return t.value;return e.startState.facet(mo)!=e.state.facet(mo)?fo.init(e.state):t.apply(e)}});let ao=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(ao=t=>{let e=-1,i=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const co="undefined"!=typeof navigator&&(null===(Ql=navigator.scheduling)||void 0===Ql?void 0:Ql.isInputPending)?()=>navigator.scheduling.isInputPending():null,po=_i.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(io.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(io.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=ao(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(io.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let n=Date.now()+Math.min(this.chunkBudget,100,t&&!co?Math.max(25,t.timeRemaining()-5):1e9),h=r.context.treeLen<s&&i.doc.length>s+1e3,l=r.context.work((()=>co&&co()||Date.now()>n),s+(h?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:io.setState.of(new fo(r.context))})),this.chunkBudget>0&&(!l||h)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then((()=>this.scheduleWork())).catch((t=>Ui(this.view.state,t))).then((()=>this.workScheduled--)),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),mo=j.define({combine:t=>t.length?t[0]:null,enables:t=>[io.state,po,Ur.contentAttributes.compute([t],(e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}}))]});class go{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const wo=j.define(),bo=j.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some((t=>t!=e[0])))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function vo(t){let e=t.facet(bo);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function ko(t,e){let i="",s=t.tabSize,r=t.facet(bo)[0];if("\t"==r){for(;e>=s;)i+="\t",e-=s;r=" "}for(let t=0;t<e;t++)i+=r;return i}function yo(t,e){t instanceof St&&(t=new Mo(t));for(let i of t.state.facet(wo)){let s=i(t,e);if(void 0!==s)return s}let i=no(t.state);return i.length>=e?function(t,e,i){let s=e.resolveStack(i),r=s.node.enterUnfinishedNodesBefore(i);if(r!=s.node){let t=[];for(let e=r;e!=s.node;e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)s={node:t[e],next:s}}return So(s,t,i)}(t,i,e):null}class Mo{constructor(t,e={}){this.state=t,this.options=e,this.unit=vo(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return null!=s&&s>=i.from&&s<=i.to?r&&s==t?{text:"",from:t}:(e<0?s<t:s<=t)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(t,e);return i.slice(t-s,Math.min(i.length,t+100-s))}column(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.countColumn(i,t-s),n=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return n>-1&&(r+=n-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return Vt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.options.overrideIndentation;if(r){let t=r(s);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const xo=new jh;function So(t,e,i){for(let s=t;s;s=s.next){let t=Ao(s.node);if(t)return t(Oo.create(e,i,s))}return 0}function Ao(t){let e=t.type.prop(xo);if(e)return e;let i,s=t.firstChild;if(s&&(i=s.type.prop(jh.closedBy))){let e=t.lastChild,s=e&&i.indexOf(e.name)>-1;return t=>Io(t,!0,1,void 0,s&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?Co:null}function Co(){return 0}class Oo extends Mo{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 Oo(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(Do(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return So(this.context.next,this.base,this.pos)}}function Do(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}function Eo({closing:t,align:e=!0,units:i=1}){return s=>Io(s,e,i,t)}function Io(t,e,i,s,r){let n=t.textAfter,h=n.match(/^\s*/)[0].length,l=s&&n.slice(h,h+s.length)==s||r==t.pos+h,o=e?function(t){let e=t.node,i=e.childAfter(e.from),s=e.lastChild;if(!i)return null;let r=t.options.simulateBreak,n=t.state.doc.lineAt(i.from),h=null==r||r<=n.from?n.to:Math.min(n.to,r);for(let t=i.to;;){let r=e.childAfter(t);if(!r||r==s)return null;if(!r.type.isSkipped)return r.from<h?i:null;t=r.to}}(t):null;return o?l?t.column(o.from):t.column(o.to):t.baseIndent+(l?0:t.unit*i)}const Ro=t=>t.baseIndent;function To({except:t,units:e=1}={}){return i=>{let s=t&&t.test(i.textAfter);return i.baseIndent+(s?0:e*i.unit)}}const Bo=j.define(),Lo=new jh;function No(t){let e=t.firstChild,i=t.lastChild;return e&&e.to<i.from?{from:e.to,to:i.type.isError?t.to:i.from}:null}function jo(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function $o(t,e,i){for(let s of t.facet(Bo)){let r=s(t,e,i);if(r)return r}return function(t,e,i){let s=no(t);if(s.length<i)return null;let r=null;for(let n=s.resolveStack(i,1);n;n=n.next){let h=n.node;if(h.to<=i||h.from>i)continue;if(r&&h.from<e)break;let l=h.type.prop(Lo);if(l&&(h.to<s.length-50||s.length==t.doc.length||!jo(h))){let s=l(h,t);s&&s.from<=i&&s.from>=e&&s.to>i&&(r=s)}}return r}(t,e,i)}function zo(t,e){let i=e.mapPos(t.from,1),s=e.mapPos(t.to,-1);return i>=s?void 0:{from:i,to:s}}const Po=ct.define({map:zo}),Ho=ct.define({map:zo});function Wo(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some((t=>t.from<=i&&t.to>=i))||e.push(t.lineBlockAt(i));return e}const Vo=F.define({create:()=>ni.none,update(t,e){t=t.map(e.changes);for(let i of e.effects)if(i.is(Po)&&!qo(t,i.value.from,i.value.to)){let{preparePlaceholder:s}=e.state.facet(_o),r=s?ni.replace({widget:new Zo(s(e.state,i.value))}):Qo;t=t.update({add:[r.range(i.value.from,i.value.to)]})}else i.is(Ho)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));if(e.selection){let i=!1,{head:s}=e.selection.main;t.between(s,s,((t,e)=>{t<s&&e>s&&(i=!0)})),i&&(t=t.update({filterFrom:s,filterTo:s,filter:(t,e)=>e<=s||t>=s}))}return t},provide:t=>Ur.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,((t,e)=>{i.push(t,e)})),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i<t.length;){let s=t[i++],r=t[i++];if("number"!=typeof s||"number"!=typeof r)throw new RangeError("Invalid JSON for fold state");e.push(Qo.range(s,r))}return ni.set(e,!0)}});function Fo(t,e,i){var s;let r=null;return null===(s=t.field(Vo,!1))||void 0===s||s.between(e,i,((t,e)=>{(!r||r.from>t)&&(r={from:t,to:e})})),r}function qo(t,e,i){let s=!1;return t.between(e,e,((t,r)=>{t==e&&r==i&&(s=!0)})),s}function Uo(t,e){return t.field(Vo,!1)?e:e.concat(ct.appendConfig.of(Xo()))}function Jo(t,e,i=!0){let s=t.state.doc.lineAt(e.from).number,r=t.state.doc.lineAt(e.to).number;return Ur.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${s} ${t.state.phrase("to")} ${r}.`)}const Go=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of Wo(t)){let i=$o(t.state,e.from,e.to);if(i)return t.dispatch({effects:Uo(t.state,[Po.of(i),Jo(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(Vo,!1))return!1;let e=[];for(let i of Wo(t)){let s=Fo(t.state,i.from,i.to);s&&e.push(Ho.of(s),Jo(t,s,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let s=0;s<e.doc.length;){let r=t.lineBlockAt(s),n=$o(e,r.from,r.to);n&&i.push(Po.of(n)),s=(n?t.lineBlockAt(n.to):r).to+1}return i.length&&t.dispatch({effects:Uo(t.state,i)}),!!i.length}},{key:"Ctrl-Alt-]",run:t=>{let e=t.state.field(Vo,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,((t,e)=>{i.push(Ho.of({from:t,to:e}))})),t.dispatch({effects:i}),!0}}],Ko={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},_o=j.define({combine:t=>At(t,Ko)});function Xo(t){let e=[Vo,iu];return t&&e.push(_o.of(t)),e}function Yo(t,e){let{state:i}=t,s=i.facet(_o),r=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),s=Fo(t.state,i.from,i.to);s&&t.dispatch({effects:Ho.of(s)}),e.preventDefault()};if(s.placeholderDOM)return s.placeholderDOM(t,r,e);let n=document.createElement("span");return n.textContent=s.placeholderText,n.setAttribute("aria-label",i.phrase("folded code")),n.title=i.phrase("unfold"),n.className="cm-foldPlaceholder",n.onclick=r,n}const Qo=ni.replace({widget:new class extends si{toDOM(t){return Yo(t,null)}}});class Zo extends si{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return Yo(t,this.value)}}const tu={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class eu extends ah{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}const iu=Ur.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class su{constructor(t,e){let i;function s(t){let e=Gt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const r="string"==typeof e.all?e.all:e.all?s(e.all):void 0,n=e.scope;this.scope=n instanceof io?t=>t.prop(Zl)==n.data:n?t=>t==n:void 0,this.style=Bl(t.map((t=>({tag:t.tag,class:t.class||s(Object.assign({},t,{tag:null}))}))),{all:r}).style,this.module=i?new Gt(i):null,this.themeType=e.themeType}static define(t,e){return new su(t,e||{})}}const ru=j.define(),nu=j.define({combine:t=>t.length?[t[0]]:null});function hu(t){let e=t.facet(ru);return e.length?e:t.facet(nu)}class lu{constructor(t){this.markCache=Object.create(null),this.tree=no(t.state),this.decorations=this.buildDeco(t,hu(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=no(t.state),i=hu(t.state),s=i!=hu(t.startState),{viewport:r}=t.view,n=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!s&&e.type==this.tree.type&&n>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=n):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return ni.none;let i=new Rt;for(let{from:s,to:r}of t.visibleRanges)Ll(this.tree,e,((t,e,s)=>{i.add(t,e,this.markCache[s]||(this.markCache[s]=ni.mark({class:s})))}),s,r);return i.finish()}}const ou=_.high(_i.fromClass(lu,{decorations:t=>t.decorations})),uu=su.define([{tag:Yl.meta,color:"#404740"},{tag:Yl.link,textDecoration:"underline"},{tag:Yl.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Yl.emphasis,fontStyle:"italic"},{tag:Yl.strong,fontWeight:"bold"},{tag:Yl.strikethrough,textDecoration:"line-through"},{tag:Yl.keyword,color:"#708"},{tag:[Yl.atom,Yl.bool,Yl.url,Yl.contentSeparator,Yl.labelName],color:"#219"},{tag:[Yl.literal,Yl.inserted],color:"#164"},{tag:[Yl.string,Yl.deleted],color:"#a11"},{tag:[Yl.regexp,Yl.escape,Yl.special(Yl.string)],color:"#e40"},{tag:Yl.definition(Yl.variableName),color:"#00f"},{tag:Yl.local(Yl.variableName),color:"#30a"},{tag:[Yl.typeName,Yl.namespace],color:"#085"},{tag:Yl.className,color:"#167"},{tag:[Yl.special(Yl.variableName),Yl.macroName],color:"#256"},{tag:Yl.definition(Yl.propertyName),color:"#00c"},{tag:Yl.comment,color:"#940"},{tag:Yl.invalid,color:"#f00"}]),fu=Ur.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),au=1e4,cu="()[]{}",du=j.define({combine:t=>At(t,{afterCursor:!0,brackets:cu,maxScanDistance:au,renderMatch:gu})}),pu=ni.mark({class:"cm-matchingBracket"}),mu=ni.mark({class:"cm-nonmatchingBracket"});function gu(t){let e=[],i=t.matched?pu:mu;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}const wu=F.define({create:()=>ni.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],s=e.state.facet(du);for(let t of e.state.selection.ranges){if(!t.empty)continue;let r=Mu(e.state,t.head,-1,s)||t.head>0&&Mu(e.state,t.head-1,1,s)||s.afterCursor&&(Mu(e.state,t.head,1,s)||t.head<e.state.doc.length&&Mu(e.state,t.head+1,-1,s));r&&(i=i.concat(s.renderMatch(r,e.state)))}return ni.set(i,!0)},provide:t=>Ur.decorations.from(t)}),bu=[wu,fu];const vu=new jh;function ku(t,e,i){let s=t.prop(e<0?jh.openedBy:jh.closedBy);if(s)return s;if(1==t.name.length){let s=i.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[i[s+e]]}return null}function yu(t){let e=t.type.prop(vu);return e?e(t.node):t}function Mu(t,e,i,s={}){let r=s.maxScanDistance||au,n=s.brackets||cu,h=no(t),l=h.resolveInner(e,i);for(let s=l;s;s=s.parent){let r=ku(s.type,i,n);if(r&&s.from<s.to){let h=yu(s);if(h&&(i>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return xu(t,e,i,s,h,r,n)}}return function(t,e,i,s,r,n,h){let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),o=h.indexOf(l);if(o<0||o%2==0!=i>0)return null;let u={from:i<0?e-1:e,to:i>0?e+1:e},f=t.doc.iterRange(e,i>0?t.doc.length:0),a=0;for(let t=0;!f.next().done&&t<=n;){let n=f.value;i<0&&(t+=n.length);let l=e+t*i;for(let t=i>0?0:n.length-1,e=i>0?n.length:-1;t!=e;t+=i){let e=h.indexOf(n[t]);if(!(e<0||s.resolveInner(l+t,1).type!=r))if(e%2==0==i>0)a++;else{if(1==a)return{start:u,end:{from:l+t,to:l+t+1},matched:e>>1==o>>1};a--}}i>0&&(t+=n.length)}return f.done?{start:u,matched:!1}:null}(t,e,i,h,l.type,r,n)}function xu(t,e,i,s,r,n,h){let l=s.parent,o={from:r.from,to:r.to},u=0,f=null==l?void 0:l.cursor();if(f&&(i<0?f.childBefore(s.from):f.childAfter(s.to)))do{if(i<0?f.to<=s.from:f.from>=s.to){if(0==u&&n.indexOf(f.type.name)>-1&&f.from<f.to){let t=yu(f);return{start:o,end:t?{from:t.from,to:t.to}:void 0,matched:!0}}if(ku(f.type,i,h))u++;else if(ku(f.type,-i,h)){if(0==u){let t=yu(f);return{start:o,end:t&&t.from<t.to?{from:t.from,to:t.to}:void 0,matched:!1}}u--}}}while(i<0?f.prevSibling():f.nextSibling());return{start:o,matched:!1}}const Su=Object.create(null),Au=[Ph.none],Cu=[],Ou=Object.create(null),Du=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Du[t]=Iu(Su,e);function Eu(t,e){Cu.indexOf(t)>-1||(Cu.push(t),console.warn(e))}function Iu(t,e){let i=[];for(let s of e.split(" ")){let e=[];for(let i of s.split(".")){let s=t[i]||Yl[i];s?"function"==typeof s?e.length?e=e.map(s):Eu(i,`Modifier ${i} used at start of tag`):e.length?Eu(i,`Tag ${i} used as modifier`):e=Array.isArray(s)?s:[s]:Eu(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let s=e.replace(/ /g,"_"),r=s+" "+i.map((t=>t.id)),n=Ou[r];if(n)return n.id;let h=Ou[r]=Ph.define({id:Au.length,name:s,props:[Il({[s]:i})]});return Au.push(h),h.id}pi.RTL,pi.LTR;function Ru(t,e){return({state:i,dispatch:s})=>{if(i.readOnly)return!1;let r=t(e,i);return!!r&&(s(i.update(r)),!0)}}const Tu=Ru(zu,0),Bu=Ru($u,0),Lu=Ru(((t,e)=>$u(t,e,function(t){let e=[];for(let i of t.selection.ranges){let s=t.doc.lineAt(i.from),r=i.to<=s.to?s:t.doc.lineAt(i.to),n=e.length-1;n>=0&&e[n].to>s.from?e[n].to=r.to:e.push({from:s.from+/^\s*/.exec(s.text)[0].length,to:r.to})}return e}(e))),0);function Nu(t,e){let i=t.languageDataAt("commentTokens",e);return i.length?i[0]:{}}const ju=50;function $u(t,e,i=e.selection.ranges){let s=i.map((t=>Nu(e,t.from).block));if(!s.every((t=>t)))return null;let r=i.map(((t,i)=>function(t,{open:e,close:i},s,r){let n,h,l=t.sliceDoc(s-ju,s),o=t.sliceDoc(r,r+ju),u=/\s*$/.exec(l)[0].length,f=/^\s*/.exec(o)[0].length,a=l.length-u;if(l.slice(a-e.length,a)==e&&o.slice(f,f+i.length)==i)return{open:{pos:s-u,margin:u&&1},close:{pos:r+f,margin:f&&1}};r-s<=2*ju?n=h=t.sliceDoc(s,r):(n=t.sliceDoc(s,s+ju),h=t.sliceDoc(r-ju,r));let c=/^\s*/.exec(n)[0].length,d=/\s*$/.exec(h)[0].length,p=h.length-d-i.length;return n.slice(c,c+e.length)==e&&h.slice(p,p+i.length)==i?{open:{pos:s+c+e.length,margin:/\s/.test(n.charAt(c+e.length))?1:0},close:{pos:r-d-i.length,margin:/\s/.test(h.charAt(p-1))?1:0}}:null}(e,s[i],t.from,t.to)));if(2!=t&&!r.every((t=>t)))return{changes:e.changes(i.map(((t,e)=>r[e]?[]:[{from:t.from,insert:s[e].open+" "},{from:t.to,insert:" "+s[e].close}])))};if(1!=t&&r.some((t=>t))){let t=[];for(let e,i=0;i<r.length;i++)if(e=r[i]){let r=s[i],{open:n,close:h}=e;t.push({from:n.pos-r.open.length,to:n.pos+n.margin},{from:h.pos-h.margin,to:h.pos+r.close.length})}return{changes:t}}return null}function zu(t,e,i=e.selection.ranges){let s=[],r=-1;for(let{from:t,to:n}of i){let i=s.length,h=1e9,l=Nu(e,t).line;if(l){for(let i=t;i<=n;){let o=e.doc.lineAt(i);if(o.from>r&&(t==n||n>o.from)){r=o.from;let t=/^\s*/.exec(o.text)[0].length,e=t==o.length,i=o.text.slice(t,t+l.length)==l?t:-1;t<o.text.length&&t<h&&(h=t),s.push({line:o,comment:i,token:l,indent:t,empty:e,single:!1})}i=o.to+1}if(h<1e9)for(let t=i;t<s.length;t++)s[t].indent<s[t].line.text.length&&(s[t].indent=h);s.length==i+1&&(s[i].single=!0)}}if(2!=t&&s.some((t=>t.comment<0&&(!t.empty||t.single)))){let t=[];for(let{line:e,token:i,indent:r,empty:n,single:h}of s)!h&&n||t.push({from:e.from+r,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&s.some((t=>t.comment>=0))){let t=[];for(let{line:e,comment:i,token:r}of s)if(i>=0){let s=e.from+i,n=s+r.length;" "==e.text[n-e.from]&&n++,t.push({from:s,to:n})}return{changes:t}}return null}const Pu=ut.define(),Hu=ut.define(),Wu=j.define(),Vu=j.define({combine:t=>At(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,s)=>t(i,s)||e(i,s)})}),Fu=F.define({create:()=>hf.empty,update(t,e){let i=e.state.facet(Vu),s=e.annotation(Pu);if(s){let r=_u.fromTransaction(e,s.selection),n=s.side,h=0==n?t.undone:t.done;return h=r?Xu(h,h.length,i.minDepth,r):tf(h,e.startState.selection),new hf(0==n?s.rest:h,0==n?h:s.rest)}let r=e.annotation(Hu);if("full"!=r&&"before"!=r||(t=t.isolate()),!1===e.annotation(dt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let n=_u.fromTransaction(e),h=e.annotation(dt.time),l=e.annotation(dt.userEvent);return n?t=t.addChanges(n,h,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,h,l,i.newGroupDelay)),"full"!=r&&"after"!=r||(t=t.isolate()),t},toJSON:t=>({done:t.done.map((t=>t.toJSON())),undone:t.undone.map((t=>t.toJSON()))}),fromJSON:t=>new hf(t.done.map(_u.fromJSON),t.undone.map(_u.fromJSON))});function qu(t,e){return function({state:i,dispatch:s}){if(!e&&i.readOnly)return!1;let r=i.field(Fu,!1);if(!r)return!1;let n=r.pop(t,i,e);return!!n&&(s(n),!0)}}const Uu=qu(0,!1),Ju=qu(1,!1),Gu=qu(0,!0),Ku=qu(1,!0);class _u{constructor(t,e,i,s,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(t){return new _u(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map((t=>t.toJSON()))}}static fromJSON(t){return new _u(t.changes&&A.fromJSON(t.changes),[],t.mapped&&S.fromJSON(t.mapped),t.startSelection&&B.fromJSON(t.startSelection),t.selectionsAfter.map(B.fromJSON))}static fromTransaction(t,e){let i=Qu;for(let e of t.startState.facet(Wu)){let s=e(t);s.length&&(i=i.concat(s))}return!i.length&&t.changes.empty?null:new _u(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Qu)}static selection(t){return new _u(void 0,Qu,void 0,void 0,t)}}function Xu(t,e,i,s){let r=e+1>i+20?e-i-1:0,n=t.slice(r,e);return n.push(s),n}function Yu(t,e){return t.length?e.length?t.concat(e):t:e}const Qu=[],Zu=200;function tf(t,e){if(t.length){let i=t[t.length-1],s=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-Zu));return s.length&&s[s.length-1].eq(e)?t:(s.push(e),Xu(t,t.length-1,1e9,i.setSelAfter(s)))}return[_u.selection([e])]}function ef(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function sf(t,e){if(!t.length)return t;let i=t.length,s=Qu;for(;i;){let r=rf(t[i-1],e,s);if(r.changes&&!r.changes.empty||r.effects.length){let e=t.slice(0,i);return e[i-1]=r,e}e=r.mapped,i--,s=r.selectionsAfter}return s.length?[_u.selection(s)]:Qu}function rf(t,e,i){let s=Yu(t.selectionsAfter.length?t.selectionsAfter.map((t=>t.map(e))):Qu,i);if(!t.changes)return _u.selection(s);let r=t.changes.map(e),n=e.mapDesc(t.changes,!0),h=t.mapped?t.mapped.composeDesc(n):n;return new _u(r,ct.mapEffects(t.effects,e),h,t.startSelection.map(n),s)}const nf=/^(input\.type|delete)($|\.)/;class hf{constructor(t,e,i=0,s=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new hf(this.done,this.undone):this}addChanges(t,e,i,s,r){let n=this.done,h=n[n.length-1];return n=h&&h.changes&&!h.changes.empty&&t.changes&&(!i||nf.test(i))&&(!h.selectionsAfter.length&&e-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,function(t,e){let i=[],s=!1;return t.iterChangedRanges(((t,e)=>i.push(t,e))),e.iterChangedRanges(((t,e,r,n)=>{for(let t=0;t<i.length;){let e=i[t++],h=i[t++];n>=e&&r<=h&&(s=!0)}})),s}(h.changes,t.changes))||"input.type.compose"==i)?Xu(n,n.length-1,s.minDepth,new _u(t.changes.compose(h.changes),Yu(t.effects,h.effects),h.mapped,h.startSelection,Qu)):Xu(n,n.length,s.minDepth,t),new hf(n,Qu,e,i)}addSelection(t,e,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Qu;return r.length>0&&e-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&(n=r[r.length-1],h=t,n.ranges.length==h.ranges.length&&0===n.ranges.filter(((t,e)=>t.empty!=h.ranges[e].empty)).length)?this:new hf(tf(this.done,t),this.undone,e,i);var n,h}addMapping(t){return new hf(sf(this.done,t),sf(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let s=0==t?this.done:this.undone;if(0==s.length)return null;let r=s[s.length-1],n=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Pu.of({side:t,rest:ef(s),selection:n}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let i=1==s.length?Qu:s.slice(0,s.length-1);return r.mapped&&(i=sf(i,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Pu.of({side:t,rest:i,selection:n}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}hf.empty=new hf(Qu,Qu);const lf=[{key:"Mod-z",run:Uu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Ju,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Ju,preventDefault:!0},{key:"Mod-u",run:Gu,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Ku,preventDefault:!0}];function of(t,e){return B.create(t.ranges.map(e),t.mainIndex)}function uf(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function ff({state:t,dispatch:e},i){let s=of(t.selection,i);return!s.eq(t.selection,!0)&&(e(uf(t,s)),!0)}function af(t,e){return B.cursor(e?t.to:t.from)}function cf(t,e){return ff(t,(i=>i.empty?t.moveByChar(i,e):af(i,e)))}function df(t){return t.textDirectionAt(t.state.selection.main.head)==pi.LTR}const pf=t=>cf(t,!df(t)),mf=t=>cf(t,df(t));function gf(t,e){return ff(t,(i=>i.empty?t.moveByGroup(i,e):af(i,e)))}function wf(t,e,i){if(e.type.prop(i))return!0;let s=e.to-e.from;return s&&(s>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function bf(t,e,i){let s,r,n=no(t).resolveInner(e.head),h=i?jh.closedBy:jh.openedBy;for(let s=e.head;;){let e=i?n.childAfter(s):n.childBefore(s);if(!e)break;wf(t,e,h)?n=e:s=i?e.to:e.from}return r=n.type.prop(h)&&(s=i?Mu(t,n.from,1):Mu(t,n.to,-1))&&s.matched?i?s.end.to:s.end.from:i?n.to:n.from,B.cursor(r,i?-1:1)}function vf(t,e){return ff(t,(i=>{if(!i.empty)return af(i,e);let s=t.moveVertically(i,e);return s.head!=i.head?s:t.moveToLineBoundary(i,e)}))}const kf=t=>vf(t,!1),yf=t=>vf(t,!0);function Mf(t){let e,i=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,s=0,r=0;if(i){for(let e of t.state.facet(Ur.scrollMargins)){let i=e(t);(null==i?void 0:i.top)&&(s=Math.max(null==i?void 0:i.top,s)),(null==i?void 0:i.bottom)&&(r=Math.max(null==i?void 0:i.bottom,r))}e=t.scrollDOM.clientHeight-s-r}else e=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:s,marginBottom:r,selfScroll:i,height:Math.max(t.defaultLineHeight,e-5)}}function xf(t,e){let i,s=Mf(t),{state:r}=t,n=of(r.selection,(i=>i.empty?t.moveVertically(i,e,s.height):af(i,e)));if(n.eq(r.selection))return!1;if(s.selfScroll){let e=t.coordsAtPos(r.selection.main.head),h=t.scrollDOM.getBoundingClientRect(),l=h.top+s.marginTop,o=h.bottom-s.marginBottom;e&&e.top>l&&e.bottom<o&&(i=Ur.scrollIntoView(n.main.head,{y:"start",yMargin:e.top-l}))}return t.dispatch(uf(r,n),{effects:i}),!0}const Sf=t=>xf(t,!1),Af=t=>xf(t,!0);function Cf(t,e,i){let s=t.lineBlockAt(e.head),r=t.moveToLineBoundary(e,i);if(r.head==e.head&&r.head!=(i?s.to:s.from)&&(r=t.moveToLineBoundary(e,i,!1)),!i&&r.head==s.from&&s.length){let i=/^\s*/.exec(t.state.sliceDoc(s.from,Math.min(s.from+100,s.to)))[0].length;i&&e.head!=s.from+i&&(r=B.cursor(s.from+i))}return r}function Of(t,e){let i=of(t.state.selection,(t=>{let i=e(t);return B.range(t.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)}));return!i.eq(t.state.selection)&&(t.dispatch(uf(t.state,i)),!0)}function Df(t,e){return Of(t,(i=>t.moveByChar(i,e)))}const Ef=t=>Df(t,!df(t)),If=t=>Df(t,df(t));function Rf(t,e){return Of(t,(i=>t.moveByGroup(i,e)))}function Tf(t,e){return Of(t,(i=>t.moveVertically(i,e)))}const Bf=t=>Tf(t,!1),Lf=t=>Tf(t,!0);function Nf(t,e){return Of(t,(i=>t.moveVertically(i,e,Mf(t).height)))}const jf=t=>Nf(t,!1),$f=t=>Nf(t,!0),zf=({state:t,dispatch:e})=>(e(uf(t,{anchor:0})),!0),Pf=({state:t,dispatch:e})=>(e(uf(t,{anchor:t.doc.length})),!0),Hf=({state:t,dispatch:e})=>(e(uf(t,{anchor:t.selection.main.anchor,head:0})),!0),Wf=({state:t,dispatch:e})=>(e(uf(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function Vf(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:s}=t,r=s.changeByRange((s=>{let{from:r,to:n}=s;if(r==n){let h=e(s);h<r?(i="delete.backward",h=Ff(t,h,!1)):h>r&&(i="delete.forward",h=Ff(t,h,!0)),r=Math.min(r,h),n=Math.max(n,h)}else r=Ff(t,r,!1),n=Ff(t,n,!0);return r==n?{range:s}:{changes:{from:r,to:n},range:B.cursor(r,r<s.head?-1:1)}}));return!r.changes.empty&&(t.dispatch(s.update(r,{scrollIntoView:!0,userEvent:i,effects:"delete.selection"==i?Ur.announce.of(s.phrase("Selection deleted")):void 0})),!0)}function Ff(t,e,i){if(t instanceof Ur)for(let s of t.state.facet(Ur.atomicRanges).map((e=>e(t))))s.between(e,e,((t,s)=>{t<e&&s>e&&(e=i?s:t)}));return e}const qf=(t,e,i)=>Vf(t,(s=>{let r,n,h=s.from,{state:l}=t,o=l.doc.lineAt(h);if(i&&!e&&h>o.from&&h<o.from+200&&!/[^ \t]/.test(r=o.text.slice(0,h-o.from))){if("\t"==r[r.length-1])return h-1;let t=Vt(r,l.tabSize)%vo(l)||vo(l);for(let e=0;e<t&&" "==r[r.length-1-e];e++)h--;n=h}else n=p(o.text,h-o.from,e,e)+o.from,n==h&&o.number!=(e?l.doc.lines:1)?n+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(n-o.from,h-o.from))&&(n=p(o.text,n-o.from,!1,!1)+o.from);return n})),Uf=t=>qf(t,!1,!0),Jf=t=>qf(t,!0,!1),Gf=(t,e)=>Vf(t,(i=>{let s=i.head,{state:r}=t,n=r.doc.lineAt(s),h=r.charCategorizer(s);for(let t=null;;){if(s==(e?n.to:n.from)){s==i.head&&n.number!=(e?r.doc.lines:1)&&(s+=e?1:-1);break}let l=p(n.text,s-n.from,e)+n.from,o=n.text.slice(Math.min(s,l)-n.from,Math.max(s,l)-n.from),u=h(o);if(null!=t&&u!=t)break;" "==o&&s==i.head||(t=u),s=l}return s})),Kf=t=>Gf(t,!1);function _f(t){let e=[],i=-1;for(let s of t.selection.ranges){let r=t.doc.lineAt(s.from),n=t.doc.lineAt(s.to);if(s.empty||s.to!=n.from||(n=t.doc.lineAt(s.to-1)),i>=r.number){let t=e[e.length-1];t.to=n.to,t.ranges.push(s)}else e.push({from:r.from,to:n.to,ranges:[s]});i=n.number+1}return e}function Xf(t,e,i){if(t.readOnly)return!1;let s=[],r=[];for(let e of _f(t)){if(i?e.to==t.doc.length:0==e.from)continue;let n=t.doc.lineAt(i?e.to+1:e.from-1),h=n.length+1;if(i){s.push({from:e.to,to:n.to},{from:e.from,insert:n.text+t.lineBreak});for(let i of e.ranges)r.push(B.range(Math.min(t.doc.length,i.anchor+h),Math.min(t.doc.length,i.head+h)))}else{s.push({from:n.from,to:e.from},{from:e.to,insert:t.lineBreak+n.text});for(let t of e.ranges)r.push(B.range(t.anchor-h,t.head-h))}}return!!s.length&&(e(t.update({changes:s,scrollIntoView:!0,selection:B.create(r,t.selection.mainIndex),userEvent:"move.line"})),!0)}function Yf(t,e,i){if(t.readOnly)return!1;let s=[];for(let e of _f(t))i?s.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):s.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:s,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Qf=Zf(!1);function Zf(e){return({state:i,dispatch:s})=>{if(i.readOnly)return!1;let r=i.changeByRange((s=>{let{from:r,to:n}=s,h=i.doc.lineAt(r),l=!e&&r==n&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,s=no(t).resolveInner(e),r=s.childBefore(e),n=s.childAfter(e);return r&&n&&r.to<=e&&n.from>=e&&(i=r.type.prop(jh.closedBy))&&i.indexOf(n.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(n.from).from&&!/\S/.test(t.sliceDoc(r.to,n.from))?{from:r.to,to:n.from}:null}(i,r);e&&(r=n=(n<=h.to?h:i.doc.lineAt(n)).to);let o=new Mo(i,{simulateBreak:r,simulateDoubleBreak:!!l}),u=yo(o,r);for(null==u&&(u=Vt(/^\s*/.exec(i.doc.lineAt(r).text)[0],i.tabSize));n<h.to&&/\s/.test(h.text[n-h.from]);)n++;l?({from:r,to:n}=l):r>h.from&&r<h.from+100&&!/\S/.test(h.text.slice(0,r))&&(r=h.from);let f=["",ko(i,u)];return l&&f.push(ko(i,o.lineIndent(h.from,-1))),{changes:{from:r,to:n,insert:t.of(f)},range:B.cursor(r+1+f[1].length)}}));return s(i.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function ta(t,e){let i=-1;return t.changeByRange((s=>{let r=[];for(let n=s.from;n<=s.to;){let h=t.doc.lineAt(n);h.number>i&&(s.empty||s.to>h.from)&&(e(h,r,s),i=h.number),n=h.to+1}let n=t.changes(r);return{changes:r,range:B.range(n.mapPos(s.anchor,1),n.mapPos(s.head,1))}}))}const ea=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>ff(t,(e=>bf(t.state,e,!df(t)))),shift:t=>Of(t,(e=>bf(t.state,e,!df(t))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>ff(t,(e=>bf(t.state,e,df(t)))),shift:t=>Of(t,(e=>bf(t.state,e,df(t))))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>Xf(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>Yf(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>Xf(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>Yf(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,s=null;return i.ranges.length>1?s=B.create([i.main]):i.main.empty||(s=B.create([B.cursor(i.main.head)])),!!s&&(e(uf(t,s)),!0)}},{key:"Mod-Enter",run:Zf(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=_f(t).map((({from:e,to:i})=>B.range(e,Math.min(i+1,t.doc.length))));return e(t.update({selection:B.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=of(t.selection,(e=>{var i;for(let s=no(t).resolveStack(e.from,1);s;s=s.next){let{node:t}=s;if((t.from<e.from&&t.to>=e.to||t.to>e.to&&t.from<=e.from)&&(null===(i=t.parent)||void 0===i?void 0:i.parent))return B.range(t.to,t.from)}return e}));return e(uf(t,i)),!0},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(ta(t,((e,i)=>{let s=/^\s*/.exec(e.text)[0];if(!s)return;let r=Vt(s,t.tabSize),n=0,h=ko(t,Math.max(0,r-vo(t)));for(;n<s.length&&n<h.length&&s.charCodeAt(n)==h.charCodeAt(n);)n++;i.push({from:e.from+n,to:e.from+s.length,insert:h.slice(n)})})),{userEvent:"delete.dedent"})),!0)},{key:"Mod-]",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(ta(t,((e,i)=>{i.push({from:e.from,insert:t.facet(bo)})})),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),s=new Mo(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),r=ta(t,((e,r,n)=>{let h=yo(s,e.from);if(null==h)return;/\S/.test(e.text)||(h=0);let l=/^\s*/.exec(e.text)[0],o=ko(t,h);(l!=o||n.from<e.from+l.length)&&(i[e.from]=h,r.push({from:e.from,to:e.from+l.length,insert:o}))}));return r.changes.empty||e(t.update(r,{userEvent:"indent"})),!0}},{key:"Shift-Mod-k",run:t=>{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(_f(e).map((({from:t,to:i})=>(t>0?t--:i<e.doc.length&&i++,{from:t,to:i})))),s=of(e.selection,(e=>{let i;if(t.lineWrapping){let s=t.lineBlockAt(e.head),r=t.coordsAtPos(e.head,e.assoc||1);r&&(i=s.bottom+t.documentTop-r.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)})).map(i);return t.dispatch({changes:i,selection:s,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e,i){let s=!1,r=of(t.selection,(e=>{let r=Mu(t,e.head,-1)||Mu(t,e.head,1)||e.head>0&&Mu(t,e.head-1,1)||e.head<t.doc.length&&Mu(t,e.head+1,-1);if(!r||!r.end)return e;s=!0;let n=r.start.from==e.head?r.end.to:r.end.from;return i?B.range(e.anchor,n):B.cursor(n)}));return!!s&&(e(uf(t,r)),!0)}(t,e,!1)},{key:"Mod-/",run:t=>{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),s=Nu(t.state,i.from);return s.line?Tu(t):!!s.block&&Lu(t)}},{key:"Alt-A",run:Bu}].concat([{key:"ArrowLeft",run:pf,shift:Ef,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>gf(t,!df(t)),shift:t=>Rf(t,!df(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>ff(t,(e=>Cf(t,e,!df(t)))),shift:t=>Of(t,(e=>Cf(t,e,!df(t)))),preventDefault:!0},{key:"ArrowRight",run:mf,shift:If,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>gf(t,df(t)),shift:t=>Rf(t,df(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>ff(t,(e=>Cf(t,e,df(t)))),shift:t=>Of(t,(e=>Cf(t,e,df(t)))),preventDefault:!0},{key:"ArrowUp",run:kf,shift:Bf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:zf,shift:Hf},{mac:"Ctrl-ArrowUp",run:Sf,shift:jf},{key:"ArrowDown",run:yf,shift:Lf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Pf,shift:Wf},{mac:"Ctrl-ArrowDown",run:Af,shift:$f},{key:"PageUp",run:Sf,shift:jf},{key:"PageDown",run:Af,shift:$f},{key:"Home",run:t=>ff(t,(e=>Cf(t,e,!1))),shift:t=>Of(t,(e=>Cf(t,e,!1))),preventDefault:!0},{key:"Mod-Home",run:zf,shift:Hf},{key:"End",run:t=>ff(t,(e=>Cf(t,e,!0))),shift:t=>Of(t,(e=>Cf(t,e,!0))),preventDefault:!0},{key:"Mod-End",run:Pf,shift:Wf},{key:"Enter",run:Qf},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Uf,shift:Uf},{key:"Delete",run:Jf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Kf},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Gf(t,!0)},{mac:"Mod-Backspace",run:t=>Vf(t,(e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)}))},{mac:"Mod-Delete",run:t=>Vf(t,(e=>{let i=t.moveToLineBoundary(e,!0).head;return e.head<i?i:Math.min(t.state.doc.length,e.head+1)}))}].concat([{key:"Ctrl-b",run:pf,shift:Ef,preventDefault:!0},{key:"Ctrl-f",run:mf,shift:If},{key:"Ctrl-p",run:kf,shift:Bf},{key:"Ctrl-n",run:yf,shift:Lf},{key:"Ctrl-a",run:t=>ff(t,(e=>B.cursor(t.lineBlockAt(e.head).from,1))),shift:t=>Of(t,(e=>B.cursor(t.lineBlockAt(e.head).from)))},{key:"Ctrl-e",run:t=>ff(t,(e=>B.cursor(t.lineBlockAt(e.head).to,-1))),shift:t=>Of(t,(e=>B.cursor(t.lineBlockAt(e.head).to)))},{key:"Ctrl-d",run:Jf},{key:"Ctrl-h",run:Uf},{key:"Ctrl-k",run:t=>Vf(t,(e=>{let i=t.lineBlockAt(e.head).to;return e.head<i?i:Math.min(t.state.doc.length,e.head+1)}))},{key:"Ctrl-Alt-h",run:Kf},{key:"Ctrl-o",run:({state:e,dispatch:i})=>{if(e.readOnly)return!1;let s=e.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t.of(["",""])},range:B.cursor(e.from)})));return i(e.update(s,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange((e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,s=t.doc.lineAt(i),r=i==s.from?i-1:p(s.text,i-s.from,!1)+s.from,n=i==s.to?i+1:p(s.text,i-s.from,!0)+s.from;return{changes:{from:r,to:n,insert:t.doc.slice(i,n).append(t.doc.slice(r,i))},range:B.cursor(n)}}));return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Af}].map((t=>({mac:t.key,run:t.run,shift:t.shift})))));function ia(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var r=i[s];"string"==typeof r?t.setAttribute(s,r):null!=r&&(t[s]=r)}e++}for(;e<arguments.length;e++)sa(t,arguments[e]);return t}function sa(t,e){if("string"==typeof e)t.appendChild(document.createTextNode(e));else if(null==e);else if(null!=e.nodeType)t.appendChild(e);else{if(!Array.isArray(e))throw new RangeError("Unsupported child node: "+e);for(var i=0;i<e.length;i++)sa(t,e[i])}}const ra="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class na{constructor(t,e,i=0,s=t.length,r,n){this.test=n,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,s),this.bufferStart=i,this.normalize=r?t=>r(ra(t)):ra,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return v(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=k(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=y(t);let s=this.normalize(e);for(let t=0,r=i;;t++){let n=s.charCodeAt(t),h=this.match(n,r,this.bufferPos+this.bufferStart);if(t==s.length-1){if(h)return this.value=h,this;break}r==i&&t<e.length&&e.charCodeAt(t)==n&&r++}}}match(t,e,i){let s=null;for(let e=0;e<this.matches.length;e+=2){let r=this.matches[e],n=!1;this.query.charCodeAt(r)==t&&(r==this.query.length-1?s={from:this.matches[e+1],to:i}:(this.matches[e]++,n=!0)),n||(this.matches.splice(e,2),e-=2)}return this.query.charCodeAt(0)==t&&(1==this.query.length?s={from:e,to:i}:this.matches.push(1,e)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}"undefined"!=typeof Symbol&&(na.prototype[Symbol.iterator]=function(){return this});const ha={from:-1,to:-1,match:/.*/.exec("")},la="gm"+(null==/x/.unicode?"":"u");class oa{constructor(t,e,i,s=0,r=t.length){if(this.text=t,this.to=r,this.curLine="",this.done=!1,this.value=ha,/\\[sWDnr]|\n|\r|\[\^/.test(e))return new aa(t,e,i,s,r);this.re=new RegExp(e,la+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.iter=t.iter();let n=t.lineAt(s);this.curLineStart=n.from,this.matchPos=ca(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,s=i+e[0].length;if(this.matchPos=ca(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,e)))return this.value={from:i,to:s,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),t=0}}}}const ua=new WeakMap;class fa{constructor(t,e){this.from=t,this.text=e}get to(){return this.from+this.text.length}static get(t,e,i){let s=ua.get(t);if(!s||s.from>=i||s.to<=e){let s=new fa(e,t.sliceString(e,i));return ua.set(t,s),s}if(s.from==e&&s.to==i)return s;let{text:r,from:n}=s;return n>e&&(r=t.sliceString(e,n)+r,n=e),s.to<i&&(r+=t.sliceString(s.to,i)),ua.set(t,new fa(n,r)),new fa(e,r.slice(e-n,i-n))}}class aa{constructor(t,e,i,s,r){this.text=t,this.to=r,this.done=!1,this.value=ha,this.matchPos=ca(t,s),this.re=new RegExp(e,la+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.flat=fa.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,match:e},this.matchPos=ca(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=fa.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function ca(t,e){if(e>=t.length)return e;let i,s=t.lineAt(e);for(;e<s.to&&(i=s.text.charCodeAt(e-s.from))>=56320&&i<57344;)e++;return e}function da(t){let e=ia("input",{class:"cm-textfield",name:"line",value:String(t.state.doc.lineAt(t.state.selection.main.head).number)});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:s}=t,r=s.doc.lineAt(s.selection.main.head),[,n,h,l,o]=i,u=l?+l.slice(1):0,f=h?+h:r.number;if(h&&o){let t=f/100;n&&(t=t*("-"==n?-1:1)+r.number/s.doc.lines),f=Math.round(s.doc.lines*t)}else h&&n&&(f=f*("-"==n?-1:1)+r.number);let a=s.doc.line(Math.max(1,Math.min(s.doc.lines,f))),c=B.cursor(a.from+Math.max(0,Math.min(u,a.length)));t.dispatch({effects:[pa.of(!1),Ur.scrollIntoView(c.from,{y:"center"})],selection:c}),t.focus()}return{dom:ia("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:pa.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},ia("label",t.state.phrase("Go to line"),": ",e)," ",ia("button",{class:"cm-button",type:"submit"},t.state.phrase("go")))}}"undefined"!=typeof Symbol&&(oa.prototype[Symbol.iterator]=aa.prototype[Symbol.iterator]=function(){return this});const pa=ct.define(),ma=F.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(pa)&&(t=i.value);return t},provide:t=>fh.from(t,(t=>t?da:null))}),ga=Ur.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),wa={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ba=j.define({combine:t=>At(t,wa,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});const va=ni.mark({class:"cm-selectionMatch"}),ka=ni.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ya(t,e,i,s){return!(0!=i&&t(e.sliceDoc(i-1,i))==kt.Word||s!=e.doc.length&&t(e.sliceDoc(s,s+1))==kt.Word)}const Ma=_i.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(ba),{state:i}=t,s=i.selection;if(s.ranges.length>1)return ni.none;let r,n=s.main,h=null;if(n.empty){if(!e.highlightWordAroundCursor)return ni.none;let t=i.wordAt(n.head);if(!t)return ni.none;h=i.charCategorizer(n.head),r=i.sliceDoc(t.from,t.to)}else{let t=n.to-n.from;if(t<e.minSelectionLength||t>200)return ni.none;if(e.wholeWords){if(r=i.sliceDoc(n.from,n.to),h=i.charCategorizer(n.head),!ya(h,i,n.from,n.to)||!function(t,e,i,s){return t(e.sliceDoc(i,i+1))==kt.Word&&t(e.sliceDoc(s-1,s))==kt.Word}(h,i,n.from,n.to))return ni.none}else if(r=i.sliceDoc(n.from,n.to),!r)return ni.none}let l=[];for(let s of t.visibleRanges){let t=new na(i.doc,r,s.from,s.to);for(;!t.next().done;){let{from:s,to:r}=t.value;if((!h||ya(h,i,s,r))&&(n.empty&&s<=n.from&&r>=n.to?l.push(ka.range(s,r)):(s>=n.to||r<=n.from)&&l.push(va.range(s,r)),l.length>e.maxMatches))return ni.none}}return ni.set(l)}},{decorations:t=>t.decorations}),xa=Ur.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const Sa=j.define({combine:t=>At(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Za(t),scrollToMatch:t=>Ur.scrollIntoView(t)})});class Aa{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,la),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,((t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\"))}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new Ta(this):new Da(this)}getCursor(t,e=0,i){let s=t.doc?t:St.create({doc:t});return null==i&&(i=s.doc.length),this.regexp?Ea(this,s,e,i):Oa(this,s,e,i)}}class Ca{constructor(t){this.spec=t}}function Oa(t,e,i,s){return new na(e.doc,t.unquoted,i,s,t.caseSensitive?void 0:t=>t.toLowerCase(),t.wholeWord?function(t,e){return(i,s,r,n)=>((n>i||n+r.length<s)&&(n=Math.max(0,i-2),r=t.sliceString(n,Math.min(t.length,s+2))),!(e(Ia(r,i-n))==kt.Word&&e(Ra(r,i-n))==kt.Word||e(Ra(r,s-n))==kt.Word&&e(Ia(r,s-n))==kt.Word))}(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}class Da extends Ca{constructor(t){super(t)}nextMatch(t,e,i){let s=Oa(this.spec,t,i,t.doc.length).nextOverlapping();return s.done&&(s=Oa(this.spec,t,0,e).nextOverlapping()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=i;;){let i=Math.max(e,s-1e4-this.spec.unquoted.length),r=Oa(this.spec,t,i,s),n=null;for(;!r.nextOverlapping().done;)n=r.value;if(n)return n;if(i==e)return null;s-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Oa(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Oa(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ea(t,e,i,s){return new oa(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(r=e.charCategorizer(e.selection.main.head),(t,e,i)=>!i[0].length||(r(Ia(i.input,i.index))!=kt.Word||r(Ra(i.input,i.index))!=kt.Word)&&(r(Ra(i.input,i.index+i[0].length))!=kt.Word||r(Ia(i.input,i.index+i[0].length))!=kt.Word)):void 0},i,s);var r}function Ia(t,e){return t.slice(p(t,e,!1),e)}function Ra(t,e){return t.slice(e,p(t,e))}class Ta extends Ca{nextMatch(t,e,i){let s=Ea(this.spec,t,i,t.doc.length).next();return s.done&&(s=Ea(this.spec,t,0,e).next()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=1;;s++){let r=Math.max(e,i-1e4*s),n=Ea(this.spec,t,r,i),h=null;for(;!n.next().done;)h=n.value;if(h&&(r==e||h.from>r+10))return h;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,((e,i)=>"$"==i?"$":"&"==i?t.match[0]:"0"!=i&&+i<t.match.length?t.match[i]:e))}matchAll(t,e){let i=Ea(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Ea(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const Ba=ct.define(),La=ct.define(),Na=F.define({create:t=>new ja(Ga(t).create(),null),update(t,e){for(let i of e.effects)i.is(Ba)?t=new ja(i.value.create(),t.panel):i.is(La)&&(t=new ja(t.query,i.value?Ja:null));return t},provide:t=>fh.from(t,(t=>t.panel))});class ja{constructor(t,e){this.query=t,this.panel=e}}const $a=ni.mark({class:"cm-searchMatch"}),za=ni.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Pa=_i.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(Na))}update(t){let e=t.state.field(Na);(e!=t.startState.field(Na)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ni.none;let{view:i}=this,s=new Rt;for(let e=0,r=i.visibleRanges,n=r.length;e<n;e++){let{from:h,to:l}=r[e];for(;e<n-1&&l>r[e+1].from-500;)l=r[++e].to;t.highlight(i.state,h,l,((t,e)=>{let r=i.state.selection.ranges.some((i=>i.from==t&&i.to==e));s.add(t,e,r?za:$a)}))}return s.finish()}},{decorations:t=>t.decorations});function Ha(t){return e=>{let i=e.state.field(Na,!1);return i&&i.query.spec.valid?t(e,i):Xa(e)}}const Wa=Ha(((t,{query:e})=>{let{to:i}=t.state.selection.main,s=e.nextMatch(t.state,i,i);if(!s)return!1;let r=B.single(s.from,s.to),n=t.state.facet(Sa);return t.dispatch({selection:r,effects:[sc(t,s),n.scrollToMatch(r.main,t)],userEvent:"select.search"}),_a(t),!0})),Va=Ha(((t,{query:e})=>{let{state:i}=t,{from:s}=i.selection.main,r=e.prevMatch(i,s,s);if(!r)return!1;let n=B.single(r.from,r.to),h=t.state.facet(Sa);return t.dispatch({selection:n,effects:[sc(t,r),h.scrollToMatch(n.main,t)],userEvent:"select.search"}),_a(t),!0})),Fa=Ha(((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:B.create(i.map((t=>B.range(t.from,t.to)))),userEvent:"select.search.matches"}),!0)})),qa=Ha(((t,{query:e})=>{let{state:i}=t,{from:s,to:r}=i.selection.main;if(i.readOnly)return!1;let n=e.nextMatch(i,s,s);if(!n)return!1;let h,l,o=[],u=[];if(n.from==s&&n.to==r&&(l=i.toText(e.getReplacement(n)),o.push({from:n.from,to:n.to,insert:l}),n=e.nextMatch(i,n.from,n.to),u.push(Ur.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(s).number)+"."))),n){let e=0==o.length||o[0].from>=n.to?0:n.to-n.from-l.length;h=B.single(n.from-e,n.to-e),u.push(sc(t,n)),u.push(i.facet(Sa).scrollToMatch(h.main,t))}return t.dispatch({changes:o,selection:h,effects:u,userEvent:"input.replace"}),!0})),Ua=Ha(((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state,1e9).map((t=>{let{from:i,to:s}=t;return{from:i,to:s,insert:e.getReplacement(t)}}));if(!i.length)return!1;let s=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:Ur.announce.of(s),userEvent:"input.replace.all"}),!0}));function Ja(t){return t.state.facet(Sa).createPanel(t)}function Ga(t,e){var i,s,r,n,h;let l=t.selection.main,o=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!o)return e;let u=t.facet(Sa);return new Aa({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:u.literal)?o:o.replace(/\n/g,"\\n"),caseSensitive:null!==(s=null==e?void 0:e.caseSensitive)&&void 0!==s?s:u.caseSensitive,literal:null!==(r=null==e?void 0:e.literal)&&void 0!==r?r:u.literal,regexp:null!==(n=null==e?void 0:e.regexp)&&void 0!==n?n:u.regexp,wholeWord:null!==(h=null==e?void 0:e.wholeWord)&&void 0!==h?h:u.wholeWord})}function Ka(t){let e=hh(t,Ja);return e&&e.dom.querySelector("[main-field]")}function _a(t){let e=Ka(t);e&&e==t.root.activeElement&&e.select()}const Xa=t=>{let e=t.state.field(Na,!1);if(e&&e.panel){let i=Ka(t);if(i&&i!=t.root.activeElement){let s=Ga(t.state,e.query.spec);s.valid&&t.dispatch({effects:Ba.of(s)}),i.focus(),i.select()}}else t.dispatch({effects:[La.of(!0),e?Ba.of(Ga(t.state,e.query.spec)):ct.appendConfig.of(nc)]});return!0},Ya=t=>{let e=t.state.field(Na,!1);if(!e||!e.panel)return!1;let i=hh(t,Ja);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:La.of(!1)}),!0},Qa=[{key:"Mod-f",run:Xa,scope:"editor search-panel"},{key:"F3",run:Wa,shift:Va,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Wa,shift:Va,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Ya,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:s,to:r}=i.main,n=[],h=0;for(let e=new na(t.doc,t.sliceDoc(s,r));!e.next().done;){if(n.length>1e3)return!1;e.value.from==s&&(h=n.length),n.push(B.range(e.value.from,e.value.to))}return e(t.update({selection:B.create(n,h),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let e=hh(t,da);if(!e){let i=[pa.of(!0)];null==t.state.field(ma,!1)&&i.push(ct.appendConfig.of([ma,ga])),t.dispatch({effects:i}),e=hh(t,da)}return e&&e.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some((t=>t.from===t.to)))return(({state:t,dispatch:e})=>{let{selection:i}=t,s=B.create(i.ranges.map((e=>t.wordAt(e.head)||B.cursor(e.head))),i.mainIndex);return!s.eq(i)&&(e(t.update({selection:s})),!0)})({state:t,dispatch:e});let s=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=s)))return!1;let r=function(t,e){let{main:i,ranges:s}=t.selection,r=t.wordAt(i.head),n=r&&r.from==i.from&&r.to==i.to;for(let i=!1,r=new na(t.doc,e,s[s.length-1].to);;){if(r.next(),!r.done){if(i&&s.some((t=>t.from==r.value.from)))continue;if(n){let e=t.wordAt(r.value.from);if(!e||e.from!=r.value.from||e.to!=r.value.to)continue}return r.value}if(i)return null;r=new na(t.doc,e,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(t,s);return!!r&&(e(t.update({selection:t.selection.addRange(B.range(r.from,r.to),!1),effects:Ur.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class Za{constructor(t){this.view=t;let e=this.query=t.state.field(Na).query.spec;function i(t,e,i){return ia("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=ia("input",{value:e.search,placeholder:tc(t,"Find"),"aria-label":tc(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=ia("input",{value:e.replace,placeholder:tc(t,"Replace"),"aria-label":tc(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=ia("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=ia("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=ia("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=ia("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",(()=>Wa(t)),[tc(t,"next")]),i("prev",(()=>Va(t)),[tc(t,"previous")]),i("select",(()=>Fa(t)),[tc(t,"all")]),ia("label",null,[this.caseField,tc(t,"match case")]),ia("label",null,[this.reField,tc(t,"regexp")]),ia("label",null,[this.wordField,tc(t,"by word")]),...t.state.readOnly?[]:[ia("br"),this.replaceField,i("replace",(()=>qa(t)),[tc(t,"replace")]),i("replaceAll",(()=>Ua(t)),[tc(t,"replace all")])],ia("button",{name:"close",onclick:()=>Ya(t),"aria-label":tc(t,"close"),type:"button"},["×"])])}commit(){let t=new Aa({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:Ba.of(t)}))}keydown(t){var e,i,s;e=this.view,i=t,s="search-panel",nn(en(e.state),i,e,s)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Va:Wa)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),qa(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(Ba)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Sa).top}}function tc(t,e){return t.state.phrase(e)}const ec=30,ic=/[\s\.,:;?!]/;function sc(t,{from:e,to:i}){let s=t.state.doc.lineAt(e),r=t.state.doc.lineAt(i).to,n=Math.max(s.from,e-ec),h=Math.min(r,i+ec),l=t.state.sliceDoc(n,h);if(n!=s.from)for(let t=0;t<ec;t++)if(!ic.test(l[t+1])&&ic.test(l[t])){l=l.slice(t);break}if(h!=r)for(let t=l.length-1;t>l.length-ec;t--)if(!ic.test(l[t-1])&&ic.test(l[t])){l=l.slice(0,t);break}return Ur.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${s.number}.`)}const rc=Ur.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),nc=[Na,_.low(Pa),rc];class hc{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=no(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),s=e.text.slice(i-e.from,this.pos-e.from),r=s.search(cc(t,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return null==this.abortListeners}addEventListener(t,e){"abort"==t&&this.abortListeners&&this.abortListeners.push(e)}}function lc(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function oc(t){let e=t.map((t=>"string"==typeof t?{label:t}:t)),[i,s]=e.every((t=>/^\w+$/.test(t.label)))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let t=1;t<s.length;t++)i[s[t]]=!0}let s=lc(e)+lc(i)+"*$";return[new RegExp("^"+s),new RegExp(s)]}(e);return t=>{let r=t.matchBefore(s);return r||t.explicit?{from:r?r.from:t.pos,options:e,validFor:i}:null}}function uc(t,e){return i=>{for(let e=no(i.state).resolveInner(i.pos,-1);e;e=e.parent){if(t.indexOf(e.name)>-1)return null;if(e.type.isTop)break}return e(i)}}class fc{constructor(t,e,i,s){this.completion=t,this.source=e,this.match=i,this.score=s}}function ac(t){return t.selection.main.from}function cc(t,e){var i;let{source:s}=t,r=e&&"^"!=s[0],n="$"!=s[s.length-1];return r||n?new RegExp(`${r?"^":""}(?:${s})${n?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const dc=ut.define();const pc=new WeakMap;function mc(t){if(!Array.isArray(t))return t;let e=pc.get(t);return e||pc.set(t,e=oc(t)),e}const gc=ct.define(),wc=ct.define();class bc{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=v(t,e),s=y(i);this.chars.push(i);let r=t.slice(e,e+s),n=r.toUpperCase();this.folded.push(v(n==r?r.toLowerCase():n,0)),e+=s}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(t){if(0==this.pattern.length)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:e,folded:i,any:s,precise:r,byWord:n}=this;if(1==e.length){let s=v(t,0),r=y(s),n=r==t.length?0:-100;if(s==e[0]);else{if(s!=i[0])return null;n+=-200}return this.ret(n,[0,r])}let h=t.indexOf(this.pattern);if(0==h)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let l=e.length,o=0;if(h<0){for(let r=0,n=Math.min(t.length,200);r<n&&o<l;){let n=v(t,r);n!=e[o]&&n!=i[o]||(s[o++]=r),r+=y(n)}if(o<l)return null}let u=0,f=0,a=!1,c=0,d=-1,p=-1,m=/[a-z]/.test(t),g=!0;for(let s=0,o=Math.min(t.length,200),w=0;s<o&&f<l;){let o=v(t,s);h<0&&(u<l&&o==e[u]&&(r[u++]=s),c<l&&(o==e[c]||o==i[c]?(0==c&&(d=s),p=s+1,c++):c=0));let b,M=o<255?o>=48&&o<=57||o>=97&&o<=122?2:o>=65&&o<=90?1:0:(b=k(o))!=b.toLowerCase()?1:b!=b.toUpperCase()?2:0;(!s||1==M&&m||0==w&&0!=M)&&(e[f]==o||i[f]==o&&(a=!0)?n[f++]=s:n.length&&(g=!1)),w=M,s+=y(o)}return f==l&&0==n[0]&&g?this.result((a?-200:0)-100,n,t):c==l&&0==d?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):h>-1?this.ret(-700-t.length,[h,h+this.pattern.length]):c==l?this.ret(-900-t.length,[d,p]):f==l?this.result((a?-200:0)-100-700+(g?0:-1100),n,t):2==e.length?null:this.result((s[0]?-700:0)-200-1100,s,t)}result(t,e,i){let s=[],r=0;for(let t of e){let e=t+(this.astral?y(v(i,t)):1);r&&s[r-1]==t?s[r-1]=e:(s[r++]=t,s[r++]=e)}return this.ret(t-i.length,s)}}class vc{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 null==i?null:(this.matched=[0,e.length],this.score=i+(t.length==this.pattern.length?0:-100),this)}}const kc=j.define({combine:t=>At(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Mc,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=>yc(t(i),e(i)),optionClass:(t,e)=>i=>yc(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function yc(t,e){return t?e?t+" "+e:t:e}function Mc(t,e,i,s,r,n){let h,l,o=t.textDirection==pi.RTL,u=o,f=!1,a="top",c=e.left-r.left,d=r.right-e.right,p=s.right-s.left,m=s.bottom-s.top;if(u&&c<Math.min(p,d)?u=!1:!u&&d<Math.min(p,c)&&(u=!0),p<=(u?c:d))h=Math.max(r.top,Math.min(i.top,r.bottom-m))-e.top,l=Math.min(400,u?c:d);else{f=!0,l=Math.min(400,(o?e.right:r.right-e.left)-30);let t=r.bottom-e.bottom;t>=m||t>e.top?h=i.bottom-e.top:(a="bottom",h=e.bottom-i.top)}return{style:`${a}: ${h/((e.bottom-e.top)/n.offsetHeight)}px; max-width: ${l/((e.right-e.left)/n.offsetWidth)}px`,class:"cm-completionInfo-"+(f?o?"left-narrow":"right-narrow":u?"left":"right")}}function xc(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let s=Math.floor((t-e)/i);return{from:t-(s+1)*i,to:t-s*i}}class Sc{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:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let s=t.state.field(e),{options:r,selected:n}=s.open,h=t.state.facet(kc);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map((t=>"cm-completionIcon-"+t))),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i,s){let r=document.createElement("span");r.className="cm-completionLabel";let n=t.displayLabel||t.label,h=0;for(let t=0;t<s.length;){let e=s[t++],i=s[t++];e>h&&r.appendChild(document.createTextNode(n.slice(h,e)));let l=r.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(n.slice(e,i))),l.className="cm-completionMatchedText",h=i}return h<n.length&&r.appendChild(document.createTextNode(n.slice(h))),r},position:50},{render(t){if(!t.detail)return null;let e=document.createElement("span");return e.className="cm-completionDetail",e.textContent=t.detail,e},position:80}),e.sort(((t,e)=>t.position-e.position)).map((t=>t.render))}(h),this.optionClass=h.optionClass,this.tooltipClass=h.tooltipClass,this.range=xc(r.length,n,h.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",(i=>{let{options:s}=t.state.field(e).open;for(let e,r=i.target;r&&r!=this.dom;r=r.parentNode)if("LI"==r.nodeName&&(e=/-(\d+)$/.exec(r.id))&&+e[1]<s.length)return this.applyCompletion(t,s[+e[1]]),void i.preventDefault()})),this.dom.addEventListener("focusout",(e=>{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(kc).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:wc.of(null)})})),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",(()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)}))}update(t){var e;let i=t.state.field(this.stateField),s=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=s){let{options:r,selected:n,disabled:h}=i.open;s.open&&s.open.options==r||(this.range=xc(r.length,n,t.state.facet(kc).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),h!=(null===(e=s.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!h)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);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=xc(e.options.length,e.selected,this.view.state.facet(kc).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:s}=i;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then((e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,i)})).catch((t=>Ui(this.view.state,t,"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",null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:s}=t;i.appendChild(e),this.infoDestroy=s||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)"LI"==i.nodeName&&i.id?s==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected"):s--;return e&&function(t,e){let i=t.getBoundingClientRect(),s=e.getBoundingClientRect(),r=i.height/t.offsetHeight;s.top<i.top?t.scrollTop-=(i.top-s.top)/r:s.bottom>i.bottom&&(t.scrollTop+=(s.bottom-i.bottom)/r)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=t.getBoundingClientRect(),r=this.space;if(!r){let t=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:t.innerWidth,bottom:t.innerHeight}}return s.top>Math.min(r.bottom,e.bottom)-10||s.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(kc).positionInfo(this.view,e,s,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const s=document.createElement("ul");s.id=e,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let n=i.from;n<i.to;n++){let{completion:h,match:l}=t[n],{section:o}=h;if(o){let t="string"==typeof o?o:o.name;if(t!=r&&(n>i.from||0==i.from))if(r=t,"string"!=typeof o&&o.header)s.appendChild(o.header(o));else{s.appendChild(document.createElement("completion-section")).textContent=t}}const u=s.appendChild(document.createElement("li"));u.id=e+"-"+n,u.setAttribute("role","option");let f=this.optionClass(h);f&&(u.className=f);for(let t of this.optionContent){let e=t(h,this.view.state,this.view,l);e&&u.appendChild(e)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Ac(t,e){return i=>new Sc(i,t,e)}function Cc(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class Oc{constructor(t,e,i,s,r,n){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=n}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Oc(this.options,Ic(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,s,r){let n=function(t,e){let i=[],s=null,r=t=>{i.push(t);let{section:e}=t.completion;if(e){s||(s=[]);let t="string"==typeof e?e:e.name;s.some((e=>e.name==t))||s.push("string"==typeof e?{name:t}:e)}},n=e.facet(kc);for(let s of t)if(s.hasResult()){let t=s.result.getMatch;if(!1===s.result.filter)for(let e of s.result.options)r(new fc(e,s.source,t?t(e):[],1e9-i.length));else{let i,h=e.sliceDoc(s.from,s.to),l=n.filterStrict?new vc(h):new bc(h);for(let e of s.result.options)if(i=l.match(e.label)){let n=e.displayLabel?t?t(e,i.matched):[]:i.matched;r(new fc(e,s.source,n,i.score+(e.boost||0)))}}}if(s){let t=Object.create(null),e=0,r=(t,e)=>{var i,s;return(null!==(i=t.rank)&&void 0!==i?i:1e9)-(null!==(s=e.rank)&&void 0!==s?s:1e9)||(t.name<e.name?-1:1)};for(let i of s.sort(r))e-=1e5,t[i.name]=e;for(let e of i){let{section:i}=e.completion;i&&(e.score+=t["string"==typeof i?i:i.name])}}let h=[],l=null,o=n.compareCompletions;for(let t of i.sort(((t,e)=>e.score-t.score||o(t.completion,e.completion)))){let e=t.completion;!l||l.label!=e.label||l.detail!=e.detail||null!=l.type&&null!=e.type&&l.type!=e.type||l.apply!=e.apply||l.boost!=e.boost?h.push(t):Cc(t.completion)>Cc(l)&&(h[h.length-1]=t),l=t.completion}return h}(t,e);if(!n.length)return s&&t.some((t=>1==t.state))?new Oc(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let h=e.facet(kc).selectOnOpen?0:-1;if(s&&s.selected!=h&&-1!=s.selected){let t=s.options[s.selected].completion;for(let e=0;e<n.length;e++)if(n[e].completion==t){h=e;break}}return new Oc(n,Ic(i,h),{pos:t.reduce(((t,e)=>e.hasResult()?Math.min(t,e.from):t),1e8),create:Pc,above:r.aboveCursor},s?s.timestamp:Date.now(),h,!1)}map(t){return new Oc(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Dc{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Dc(Rc,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(kc),s=(i.override||e.languageDataAt("autocomplete",ac(e)).map(mc)).map((e=>(this.active.find((t=>t.source==e))||new Bc(e,this.active.some((t=>0!=t.state))?1:0)).update(t,i)));s.length==this.active.length&&s.every(((t,e)=>t==this.active[e]))&&(s=this.active);let r=this.open;r&&t.docChanged&&(r=r.map(t.changes)),t.selection||s.some((e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to)))||!function(t,e){if(t==e)return!0;for(let i=0,s=0;;){for(;i<t.length&&!t[i].hasResult;)i++;for(;s<e.length&&!e[s].hasResult;)s++;let r=i==t.length,n=s==e.length;if(r||n)return r==n;if(t[i++].result!=e[s++].result)return!1}}(s,this.active)?r=Oc.build(s,e,this.id,r,i):r&&r.disabled&&!s.some((t=>1==t.state))&&(r=null),!r&&s.every((t=>1!=t.state))&&s.some((t=>t.hasResult()))&&(s=s.map((t=>t.hasResult()?new Bc(t.source,0):t)));for(let e of t.effects)e.is(jc)&&(r=r&&r.setSelected(e.value,this.id));return s==this.active&&r==this.open?this:new Dc(s,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Ec}}const Ec={"aria-autocomplete":"list"};function Ic(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const Rc=[];function Tc(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(dc);if(i&&e.activateOnCompletion(i))return"input"}return t.isUserEvent("input.type")?"input":t.isUserEvent("delete.backward")?"delete":null}class Bc{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=Tc(t,e),s=this;i?s=s.handleUserEvent(t,i,e):t.docChanged?s=s.handleChange(t):t.selection&&0!=s.state&&(s=new Bc(s.source,0));for(let e of t.effects)if(e.is(gc))s=new Bc(s.source,1,e.value?ac(t.state):-1);else if(e.is(wc))s=new Bc(s.source,0);else if(e.is(Nc))for(let t of e.value)t.source==s.source&&(s=t);return s}handleUserEvent(t,e,i){return"delete"!=e&&i.activateOnTyping?new Bc(this.source,1):this.map(t.changes)}handleChange(t){return t.changes.touchesRange(ac(t.startState))?new Bc(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new Bc(this.source,this.state,t.mapPos(this.explicitPos))}}class Lc extends Bc{constructor(t,e,i,s,r){super(t,2,e),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var s;let r=this.result;r.map&&!t.changes.empty&&(r=r.map(r,t.changes));let n=t.changes.mapPos(this.from),h=t.changes.mapPos(this.to,1),l=ac(t.state);if((this.explicitPos<0?l<=n:l<this.from)||l>h||!r||"delete"==e&&ac(t.startState)==this.from)return new Bc(this.source,"input"==e&&i.activateOnTyping?1:0);let o=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos);return function(t,e,i,s){if(!t)return!1;let r=e.sliceDoc(i,s);return"function"==typeof t?t(r,i,s,e):cc(t,!0).test(r)}(r.validFor,t.state,n,h)?new Lc(this.source,o,r,n,h):r.update&&(r=r.update(r,n,h,new hc(t.state,l,o>=0)))?new Lc(this.source,o,r,r.from,null!==(s=r.to)&&void 0!==s?s:ac(t.state)):new Bc(this.source,1,o)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new Bc(this.source,0):this.map(t.changes)}map(t){if(t.empty)return this;return(this.result.map?this.result.map(this.result,t):this.result)?new Lc(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new Bc(this.source,0)}}const Nc=ct.define({map:(t,e)=>t.map((t=>t.map(e)))}),jc=ct.define(),$c=F.define({create:()=>Dc.start(),update:(t,e)=>t.update(e),provide:t=>[Xn.from(t,(t=>t.tooltip)),Ur.contentAttributes.from(t,(t=>t.attrs))]});function zc(t,e){const i=e.completion.apply||e.completion.label;let s=t.state.field($c).active.find((t=>t.source==e.source));return s instanceof Lc&&("string"==typeof i?t.dispatch(Object.assign(Object.assign({},function(t,e,i,s){let{main:r}=t.selection,n=i-r.from,h=s-r.from;return Object.assign(Object.assign({},t.changeByRange((l=>l!=r&&i!=s&&t.sliceDoc(l.from+n,l.from+h)!=t.sliceDoc(i,s)?{range:l}:{changes:{from:l.from+n,to:s==r.from?l.to:l.from+h,insert:e},range:B.cursor(l.from+n+e.length)}))),{scrollIntoView:!0,userEvent:"input.complete"})}(t.state,i,s.from,s.to)),{annotations:dc.of(e.completion)})):i(t,e.completion,s.from,s.to),!0)}const Pc=Ac($c,zc);function Hc(t,e="option"){return i=>{let s=i.state.field($c,!1);if(!s||!s.open||s.open.disabled||Date.now()-s.open.timestamp<i.state.facet(kc).interactionDelay)return!1;let r,n=1;"page"==e&&(r=sh(i,s.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:h}=s.open.options,l=s.open.selected>-1?s.open.selected+n*(t?1:-1):t?0:h-1;return l<0?l="page"==e?0:h-1:l>=h&&(l="page"==e?h-1:0),i.dispatch({effects:jc.of(l)}),!0}}class Wc{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Vc=_i.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field($c).active)1==e.state&&this.startQuery(e)}update(t){let e=t.state.field($c),i=t.state.facet(kc);if(!t.selectionSet&&!t.docChanged&&t.startState.field($c)==e)return;let s=t.transactions.some((t=>(t.selection||t.docChanged)&&!Tc(t,i)));for(let e=0;e<this.running.length;e++){let i=this.running[e];if(s||i.updates.length+t.transactions.length>50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){Ui(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some((t=>t.effects.some((t=>t.is(gc)))))&&(this.pendingStart=!0);let r=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some((t=>1==t.state&&!this.running.some((e=>e.active.source==t.source))))?setTimeout((()=>this.startUpdate()),r):-1,0!=this.composing)for(let e of t.transactions)"input"==Tc(e,i)?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field($c);for(let t of e.active)1!=t.state||this.running.some((e=>e.active.source==t.source))||this.startQuery(t)}startQuery(t){let{state:e}=this.view,i=ac(e),s=new hc(e,i,t.explicitPos==i),r=new Wc(t,s);this.running.push(r),Promise.resolve(t.source(s)).then((t=>{r.context.aborted||(r.done=t||null,this.scheduleAccept())}),(t=>{this.view.dispatch({effects:wc.of(null)}),Ui(this.view.state,t)}))}scheduleAccept(){this.running.every((t=>void 0!==t.done))?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout((()=>this.accept()),this.view.state.facet(kc).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(kc);for(let s=0;s<this.running.length;s++){let r=this.running[s];if(void 0===r.done)continue;if(this.running.splice(s--,1),r.done){let s=new Lc(r.active.source,r.active.explicitPos,r.done,r.done.from,null!==(t=r.done.to)&&void 0!==t?t:ac(r.updates.length?r.updates[0].startState:this.view.state));for(let t of r.updates)s=s.update(t,i);if(s.hasResult()){e.push(s);continue}}let n=this.view.state.field($c).active.find((t=>t.source==r.active.source));if(n&&1==n.state)if(null==r.done){let t=new Bc(r.active.source,0);for(let e of r.updates)t=t.update(e,i);1!=t.state&&e.push(t)}else this.startQuery(n)}e.length&&this.view.dispatch({effects:Nc.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field($c,!1);if(e&&e.tooltip&&this.view.state.facet(kc).closeOnBlur){let i=e.open&&sh(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout((()=>this.view.dispatch({effects:wc.of(null)})),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout((()=>this.view.dispatch({effects:gc.of(!1)})),20),this.composing=0}}}),Fc="object"==typeof navigator&&/Win/.test(navigator.platform),qc=_.highest(Ur.domEventHandlers({keydown(t,e){let i=e.state.field($c,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!Fc||!t.altKey)||t.metaKey)return!1;let s=i.open.options[i.open.selected],r=i.active.find((t=>t.source==s.source)),n=s.completion.commitCharacters||r.result.commitCharacters;return n&&n.indexOf(t.key)>-1&&zc(e,s),!1}})),Uc=Ur.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Jc{constructor(t,e,i,s){this.field=t,this.line=e,this.from=i,this.to=s}}class Gc{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,x.TrackDel),i=t.mapPos(this.to,1,x.TrackDel);return null==e||null==i?null:new Gc(this.field,e,i)}}class Kc{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],s=[e],r=t.doc.lineAt(e),n=/^\s*/.exec(r.text)[0];for(let r of this.lines){if(i.length){let i=n,h=/^\t*/.exec(r)[0].length;for(let e=0;e<h;e++)i+=t.facet(bo);s.push(e+i.length-h),r=i+r.slice(h)}i.push(r),e+=r.length+1}let h=this.fieldPositions.map((t=>new Gc(t.field,s[t.line]+t.from,s[t.line]+t.to)));return{text:i,ranges:h}}static parse(t){let e,i=[],s=[],r=[];for(let n of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(n);){let t=e[1]?+e[1]:null,h=e[2]||e[3]||"",l=-1;for(let e=0;e<i.length;e++)(null!=t?i[e].seq==t:h&&i[e].name==h)&&(l=e);if(l<0){let e=0;for(;e<i.length&&(null==t||null!=i[e].seq&&i[e].seq<t);)e++;i.splice(e,0,{seq:t,name:h}),l=e;for(let t of r)t.field>=l&&t.field++}r.push(new Jc(l,s.length,e.index,e.index+h.length)),n=n.slice(0,e.index)+h+n.slice(e.index+e[0].length)}for(let t;t=/\\([{}])/.exec(n);){n=n.slice(0,t.index)+t[1]+n.slice(t.index+t[0].length);for(let e of r)e.line==s.length&&e.from>t.index&&(e.from--,e.to--)}s.push(n)}return new Kc(s,r)}}let _c=ni.widget({widget:new class extends si{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),Xc=ni.mark({class:"cm-snippetField"});class Yc{constructor(t,e){this.ranges=t,this.active=e,this.deco=ni.set(t.map((t=>(t.from==t.to?_c:Xc).range(t.from,t.to))))}map(t){let e=[];for(let i of this.ranges){let s=i.map(t);if(!s)return null;e.push(s)}return new Yc(e,this.active)}selectionInsideField(t){return t.ranges.every((t=>this.ranges.some((e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))))}}const Qc=ct.define({map:(t,e)=>t&&t.map(e)}),Zc=ct.define(),td=F.define({create:()=>null,update(t,e){for(let i of e.effects){if(i.is(Qc))return i.value;if(i.is(Zc)&&t)return new Yc(t.ranges,i.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>Ur.decorations.from(t,(t=>t?t.deco:ni.none))});function ed(t,e){return B.create(t.filter((t=>t.field==e)).map((t=>B.range(t.from,t.to))))}function id(e){let i=Kc.parse(e);return(e,s,r,n)=>{let{text:h,ranges:l}=i.instantiate(e.state,r),o={changes:{from:r,to:n,insert:t.of(h)},scrollIntoView:!0,annotations:s?[dc.of(s),dt.userEvent.of("input.complete")]:void 0};if(l.length&&(o.selection=ed(l,0)),l.some((t=>t.field>0))){let t=new Yc(l,0),i=o.effects=[Qc.of(t)];void 0===e.state.field(td,!1)&&i.push(ct.appendConfig.of([td,hd,od,Uc]))}e.dispatch(e.state.update(o))}}function sd(t){return({state:e,dispatch:i})=>{let s=e.field(td,!1);if(!s||t<0&&0==s.active)return!1;let r=s.active+t,n=t>0&&!s.ranges.some((e=>e.field==r+t));return i(e.update({selection:ed(s.ranges,r),effects:Qc.of(n?null:new Yc(s.ranges,r)),scrollIntoView:!0})),!0}}const rd=[{key:"Tab",run:sd(1),shift:sd(-1)},{key:"Escape",run:({state:t,dispatch:e})=>!!t.field(td,!1)&&(e(t.update({effects:Qc.of(null)})),!0)}],nd=j.define({combine:t=>t.length?t[0]:rd}),hd=_.highest(Zr.compute([nd],(t=>t.facet(nd))));function ld(t,e){return Object.assign(Object.assign({},e),{apply:id(t)})}const od=Ur.domEventHandlers({mousedown(t,e){let i,s=e.state.field(td,!1);if(!s||null==(i=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let r=s.ranges.find((t=>t.from<=i&&t.to>=i));return!(!r||r.field==s.active)&&(e.dispatch({selection:ed(s.ranges,r.field),effects:Qc.of(s.ranges.some((t=>t.field>r.field))?new Yc(s.ranges,r.field):null),scrollIntoView:!0}),!0)}}),ud={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},fd=ct.define({map(t,e){let i=e.mapPos(t,-1,x.TrackAfter);return null==i?void 0:i}}),ad=new class extends Ct{};ad.startSide=1,ad.endSide=-1;const cd=F.define({create:()=>It.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(fd)&&(t=t.update({add:[ad.range(i.value,i.value+1)]}));return t}});const dd="()[]{}<>";function pd(t){for(let e=0;e<dd.length;e+=2)if(dd.charCodeAt(e)==t)return dd.charAt(e+1);return k(t<128?t:t+1)}function md(t,e){return t.languageDataAt("closeBrackets",e)[0]||ud}const gd="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),wd=Ur.inputHandler.of(((t,e,i,s)=>{if((gd?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let r=t.state.selection.main;if(s.length>2||2==s.length&&1==y(v(s,0))||e!=r.from||i!=r.to)return!1;let n=function(t,e){let i=md(t,t.selection.main.head),s=i.brackets||ud.brackets;for(let r of s){let n=pd(v(r,0));if(e==r)return n==r?xd(t,r,s.indexOf(r+r+r)>-1,i):yd(t,r,n,i.before||ud.before);if(e==n&&vd(t,t.selection.main.from))return Md(t,r,n)}return null}(t.state,s);return!!n&&(t.dispatch(n),!0)})),bd=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=md(t,t.selection.main.head).brackets||ud.brackets,s=null,r=t.changeByRange((e=>{if(e.empty){let s=function(t,e){let i=t.sliceString(e-2,e);return y(v(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let r of i)if(r==s&&kd(t.doc,e.head)==pd(v(r,0)))return{changes:{from:e.head-r.length,to:e.head+r.length},range:B.cursor(e.head-r.length)}}return{range:s=e}}));return s||e(t.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s}}];function vd(t,e){let i=!1;return t.field(cd).between(0,t.doc.length,(t=>{t==e&&(i=!0)})),i}function kd(t,e){let i=t.sliceString(e,e+2);return i.slice(0,y(v(i,0)))}function yd(t,e,i,s){let r=null,n=t.changeByRange((n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:i,from:n.to}],effects:fd.of(n.to+e.length),range:B.range(n.anchor+e.length,n.head+e.length)};let h=kd(t.doc,n.head);return!h||/\s/.test(h)||s.indexOf(h)>-1?{changes:{insert:e+i,from:n.head},effects:fd.of(n.head+e.length),range:B.cursor(n.head+e.length)}:{range:r=n}}));return r?null:t.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function Md(t,e,i){let s=null,r=t.changeByRange((e=>e.empty&&kd(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:B.cursor(e.head+i.length)}:s={range:e}));return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function xd(t,e,i,s){let r=s.stringPrefixes||ud.stringPrefixes,n=null,h=t.changeByRange((s=>{if(!s.empty)return{changes:[{insert:e,from:s.from},{insert:e,from:s.to}],effects:fd.of(s.to+e.length),range:B.range(s.anchor+e.length,s.head+e.length)};let h,l=s.head,o=kd(t.doc,l);if(o==e){if(Sd(t,l))return{changes:{insert:e+e,from:l},effects:fd.of(l+e.length),range:B.cursor(l+e.length)};if(vd(t,l)){let s=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+s.length,insert:s},range:B.cursor(l+s.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(h=Ad(t,l-2*e.length,r))>-1&&Sd(t,h))return{changes:{insert:e+e+e+e,from:l},effects:fd.of(l+e.length),range:B.cursor(l+e.length)};if(t.charCategorizer(l)(o)!=kt.Word&&Ad(t,l,r)>-1&&!function(t,e,i,s){let r=no(t).resolveInner(e,-1),n=s.reduce(((t,e)=>Math.max(t,e.length)),0);for(let h=0;h<5;h++){let h=t.sliceDoc(r.from,Math.min(r.to,r.from+i.length+n)),l=h.indexOf(i);if(!l||l>-1&&s.indexOf(h.slice(0,l))>-1){let e=r.firstChild;for(;e&&e.from==r.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let o=r.to==e&&r.parent;if(!o)break;r=o}return!1}(t,l,e,r))return{changes:{insert:e+e,from:l},effects:fd.of(l+e.length),range:B.cursor(l+e.length)}}return{range:n=s}}));return n?null:t.update(h,{scrollIntoView:!0,userEvent:"input.type"})}function Sd(t,e){let i=no(t).resolveInner(e+1);return i.parent&&i.from==e}function Ad(t,e,i){let s=t.charCategorizer(e);if(s(t.sliceDoc(e-1,e))!=kt.Word)return e;for(let r of i){let i=e-r.length;if(t.sliceDoc(i,e)==r&&s(t.sliceDoc(i-1,i))!=kt.Word)return i}return-1}function Cd(t={}){return[qc,$c,kc.of(t),Vc,Dd,Uc]}const Od=[{key:"Ctrl-Space",run:t=>!!t.state.field($c,!1)&&(t.dispatch({effects:gc.of(!0)}),!0)},{key:"Escape",run:t=>{let e=t.state.field($c,!1);return!(!e||!e.active.some((t=>0!=t.state)))&&(t.dispatch({effects:wc.of(null)}),!0)}},{key:"ArrowDown",run:Hc(!0)},{key:"ArrowUp",run:Hc(!1)},{key:"PageDown",run:Hc(!0,"page")},{key:"PageUp",run:Hc(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field($c,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(kc).interactionDelay)&&zc(t,e.open.options[e.open.selected])}}],Dd=_.highest(Zr.computeN([kc],(t=>t.facet(kc).defaultKeymap?[Od]:[])));class Ed{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class Id{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let s=t,r=i.facet(Wd).markerFilter;r&&(s=r(s,i));let n=ni.set(s.map((t=>t.from==t.to||t.from==t.to-1&&i.doc.lineAt(t.from).to==t.from?ni.widget({widget:new qd(t),diagnostic:t}).range(t.from):ni.mark({attributes:{class:"cm-lintRange cm-lintRange-"+t.severity+(t.markClass?" "+t.markClass:"")},diagnostic:t,inclusive:!0}).range(t.from,t.to))),!0);return new Id(n,e,Rd(n))}}function Rd(t,e=null,i=0){let s=null;return t.between(i,1e9,((t,i,{spec:r})=>{if(!e||r.diagnostic==e)return s=new Ed(t,i,r.diagnostic),!1})),s}const Td=ct.define(),Bd=ct.define(),Ld=ct.define(),Nd=F.define({create:()=>new Id(ni.none,null,null),update(t,e){if(e.docChanged){let i=t.diagnostics.map(e.changes),s=null;if(t.selected){let r=e.changes.mapPos(t.selected.from,1);s=Rd(i,t.selected.diagnostic,r)||Rd(i,null,r)}t=new Id(i,t.panel,s)}for(let i of e.effects)i.is(Td)?t=Id.init(i.value,t.panel,e.state):i.is(Bd)?t=new Id(t.diagnostics,i.value?Jd.open:null,t.selected):i.is(Ld)&&(t=new Id(t.diagnostics,t.panel,i.value));return t},provide:t=>[fh.from(t,(t=>t.panel)),Ur.decorations.from(t,(t=>t.diagnostics))]}),jd=ni.mark({class:"cm-lintRange cm-lintRange-active",inclusive:!0});function $d(t,e,i){let{diagnostics:s}=t.state.field(Nd),r=[],n=2e8,h=0;s.between(e-(i<0?1:0),e+(i>0?1:0),((t,s,{spec:l})=>{e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e<s||i<0))&&(r.push(l.diagnostic),n=Math.min(t,n),h=Math.max(s,h))}));let l=t.state.facet(Wd).tooltipFilter;return l&&(r=l(r,t.state)),r.length?{pos:n,end:h,above:t.state.doc.lineAt(n).to<h,create:()=>({dom:zd(t,r)})}:null}function zd(t,e){return ia("ul",{class:"cm-tooltip-lint"},e.map((e=>Fd(t,e,!1))))}const Pd=t=>{let e=t.state.field(Nd,!1);return!(!e||!e.panel)&&(t.dispatch({effects:Bd.of(!1)}),!0)},Hd=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(Nd,!1);var i,s;e&&e.panel||t.dispatch({effects:(i=t.state,s=[Bd.of(!0)],i.field(Nd,!1)?s:s.concat(ct.appendConfig.of(_d)))});let r=hh(t,Jd.open);return r&&r.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(Nd,!1);if(!e)return!1;let i=t.state.selection.main,s=e.diagnostics.iter(i.to+1);return!(!s.value&&(s=e.diagnostics.iter(0),!s.value||s.from==i.from&&s.to==i.to))&&(t.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0}),!0)}}],Wd=j.define({combine:t=>Object.assign({sources:t.map((t=>t.source)).filter((t=>null!=t))},At(t.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 Vd(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;t<i.length;t++){let s=i[t];if(/[a-zA-Z]/.test(s)&&!e.some((t=>t.toLowerCase()==s.toLowerCase()))){e.push(s);continue t}}e.push("")}return e}function Fd(t,e,i){var s;let r=i?Vd(e.actions):[];return ia("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},ia("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(s=e.actions)||void 0===s?void 0:s.map(((i,s)=>{let n=!1,h=s=>{if(s.preventDefault(),n)return;n=!0;let r=Rd(t.state.field(Nd).diagnostics,e);r&&i.apply(t,r.from,r.to)},{name:l}=i,o=r[s]?l.indexOf(r[s]):-1,u=o<0?l:[l.slice(0,o),ia("u",l.slice(o,o+1)),l.slice(o+1)];return ia("button",{type:"button",class:"cm-diagnosticAction",onclick:h,onmousedown:h,"aria-label":` Action: ${l}${o<0?"":` (access key "${r[s]})"`}.`},u)})),e.source&&ia("div",{class:"cm-diagnosticSource"},e.source))}class qd extends si{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return ia("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class Ud{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=Fd(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Jd{constructor(t){this.view=t,this.items=[];this.list=ia("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)Pd(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],s=Vd(i.actions);for(let r=0;r<s.length;r++)if(s[r].toUpperCase().charCodeAt(0)==e.keyCode){let e=Rd(this.view.state.field(Nd).diagnostics,i);e&&i.actions[r].apply(t,e.from,e.to)}}}e.preventDefault()},onclick:t=>{for(let e=0;e<this.items.length;e++)this.items[e].dom.contains(t.target)&&this.moveSelection(e)}}),this.dom=ia("div",{class:"cm-panel-lint"},this.list,ia("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Pd(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(Nd).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(Nd),i=0,s=!1,r=null;for(t.between(0,this.view.state.doc.length,((t,n,{spec:h})=>{let l,o=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==h.diagnostic){o=t;break}o<0?(l=new Ud(this.view,h.diagnostic),this.items.splice(i,0,l),s=!0):(l=this.items[o],o>i&&(this.items.splice(i,o-i),s=!0)),e&&l.diagnostic==e.diagnostic?l.dom.hasAttribute("aria-selected")||(l.dom.setAttribute("aria-selected","true"),r=l):l.dom.hasAttribute("aria-selected")&&l.dom.removeAttribute("aria-selected"),i++}));i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();0==this.items.length&&(this.items.push(new Ud(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!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:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.top<e.top?this.list.scrollTop-=(e.top-t.top)/i:t.bottom>e.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.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=Rd(this.view.state.field(Nd).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:Ld.of(e)})}static open(t){return new Jd(t)}}function Gd(t){return function(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Kd=Ur.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:Gd("#d11")},".cm-lintRange-warning":{backgroundImage:Gd("orange")},".cm-lintRange-info":{backgroundImage:Gd("#999")},".cm-lintRange-hint":{backgroundImage:Gd("#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}}}),_d=[Nd,Ur.decorations.compute([Nd],(t=>{let{selected:e,panel:i}=t.field(Nd);return e&&i&&e.from!=e.to?ni.set([jd.range(e.from,e.to)]):ni.none})),ih($d,{hideOn:function(t,e){let i=e.pos,s=e.end||i,r=t.state.facet(Wd).hideOn(t,i,s);if(null!=r)return r;let n=t.startState.doc.lineAt(e.pos);return!(!t.effects.some((t=>t.is(Td)))&&!t.changes.touchesRange(n.from,Math.max(n.to,s)))}}),Kd],Xd=t=>void 0===t||t,Yd=(t={})=>{let e=[];Xd(t.defaultKeymap)&&e.push(...ea),Xd(t.closeBracketsKeymap)&&e.push(...bd),Xd(t.searchKeymap)&&e.push(...Qa),Xd(t.historyKeymap)&&e.push(...lf),Xd(t.foldKeymap)&&e.push(...Go),Xd(t.lintKeymap)&&e.push(...Hd);const i=[];return Xd(t.highlightActiveLineGutter)&&i.push(Th),Xd(t.highlightSpecialChars)&&i.push(function(t={}){return[En.of(t),In||(In=_i.fromClass(class{constructor(t){this.view=t,this.decorations=ni.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(En)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new Sn({regexp:t.specialChars,decoration:(e,i,s)=>{let{doc:r}=i.state,n=v(e[0],0);if(9==n){let t=r.lineAt(s),e=i.state.tabSize,n=Vt(t.text,e,s-t.from);return ni.replace({widget:new Tn((e-n%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[n]||(this.decorationCache[n]=ni.replace({widget:new Rn(t,n)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(En);t.startState.facet(En)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}()),Xd(t.history)&&i.push(function(t={}){return[Fu,Vu.of(t),Ur.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?Uu:"historyRedo"==t.inputType?Ju:null;return!!i&&(t.preventDefault(),i(e))}})]}()),Xd(t.foldGutter)&&i.push(function(t={}){let e=Object.assign(Object.assign({},tu),t),i=new eu(e,!0),s=new eu(e,!1),r=_i.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(mo)!=t.state.facet(mo)||t.startState.field(Vo,!1)!=t.state.field(Vo,!1)||no(t.startState)!=no(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new Rt;for(let r of t.viewportLineBlocks){let n=Fo(t.state,r.from,r.to)?s:$o(t.state,r.from,r.to)?i:null;n&&e.add(r.from,r.from,n)}return e.finish()}}),{domEventHandlers:n}=e;return[r,mh({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(r))||void 0===e?void 0:e.markers)||It.empty},initialSpacer:()=>new eu(e,!1),domEventHandlers:Object.assign(Object.assign({},n),{click:(t,e,i)=>{if(n.click&&n.click(t,e,i))return!0;let s=Fo(t.state,e.from,e.to);if(s)return t.dispatch({effects:Ho.of(s)}),!0;let r=$o(t.state,e.from,e.to);return!!r&&(t.dispatch({effects:Po.of(r)}),!0)}})}),Xo()]}()),Xd(t.drawSelection)&&i.push(function(t={}){return[dn.of(t),mn,wn,vn,Wi.of(!0)]}()),Xd(t.dropCursor)&&i.push([yn,Mn]),Xd(t.allowMultipleSelections)&&i.push(St.allowMultipleSelections.of(!0)),Xd(t.indentOnInput)&&i.push(St.transactionFilter.of((t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:s}=t.newSelection.main,r=i.lineAt(s);if(s>r.from+200)return t;let n=i.sliceString(r.from,s);if(!e.some((t=>t.test(n))))return t;let{state:h}=t,l=-1,o=[];for(let{head:t}of h.selection.ranges){let e=h.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=yo(h,e.from);if(null==i)continue;let s=/^\s*/.exec(e.text)[0],r=ko(h,i);s!=r&&o.push({from:e.from,to:e.from+s.length,insert:r})}return o.length?[t,{changes:o,sequential:!0}]:t}))),Xd(t.syntaxHighlighting)&&i.push(function(t,e){let i,s=[ou];return t instanceof su&&(t.module&&s.push(Ur.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?s.push(nu.of(t)):i?s.push(ru.computeN([Ur.darkTheme],(e=>e.facet(Ur.darkTheme)==("dark"==i)?[t]:[]))):s.push(ru.of(t)),s}(uu,{fallback:!0})),Xd(t.bracketMatching)&&i.push(function(t={}){return[du.of(t),bu]}()),Xd(t.closeBrackets)&&i.push([wd,cd]),Xd(t.autocompletion)&&i.push(Cd()),Xd(t.rectangularSelection)&&i.push(function(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return Ur.mouseSelectionStyle.of(((t,i)=>e(i)?Pn(t,i):null))}()),Xd(t.crosshairCursor)&&i.push(function(t={}){let[e,i]=Hn[t.key||"Alt"],s=_i.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[s,Ur.contentAttributes.of((t=>{var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.isDown)?Wn:null}))]}()),Xd(t.highlightActiveLine)&&i.push(Ln),Xd(t.highlightSelectionMatches)&&i.push(function(t){let e=[xa,Ma];return t&&e.push(ba.of(t)),e}()),t.tabSize&&"number"==typeof t.tabSize&&i.push(bo.of(" ".repeat(t.tabSize))),i.concat([Zr.of(e.flat())]).filter(Boolean)};export{t as A,dt as B,_ as C,Bh as D,Ur as E,j as F,Zr as G,ut as H,Fh as I,Y as J,Yd as K,ro as L,x as M,Hh as N,Cd as O,fl as P,Eh as Q,Ct as R,F as S,qh as T,jn as U,_i as V,si as W,Ph as a,jh as b,To as c,Eo as d,Lo as e,Ro as f,No as g,go as h,xo as i,uc as j,oc as k,no as l,B as m,ld as n,eo as o,to as p,ol as q,cl as r,Il as s,Yl as t,ni as u,pi as v,St as w,ct as x,Ui as y,ul as z};
|
1
|
+
class t{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,s){[t,e]=u(this,t,e);let r=[];return this.decompose(0,t,r,2),s.length&&s.decompose(0,s.length,r,3),this.decompose(e,this.length,r,1),i.from(r,this.length-(e-t)+s.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=u(this,t,e);let s=[];return this.decompose(t,e,s,0),i.from(s,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),i=this.length-this.scanIdentical(t,-1),s=new n(this),r=new n(t);for(let t=e,n=e;;){if(s.next(t),r.next(t),t=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(n+=s.value.length,s.done||n>=i)return!0}}iter(t=1){return new n(this,t)}iterRange(t,e=this.length){return new h(this,t,e)}iterLines(t,e){let i;if(null==t)i=this.iter();else{null==e&&(e=this.lines+1);let s=this.line(t).from;i=this.iterRange(s,Math.max(s,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new l(i)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(s){if(0==s.length)throw new RangeError("A document must have at least one line");return 1!=s.length||s[0]?s.length<=32?new e(s):i.from(e.split(s,[])):t.empty}}class e extends t{constructor(t,e=function(t){let e=-1;for(let i of t)e+=i.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.text[r],h=s+n.length;if((e?i:h)>=t)return new o(s,h,i,n);s=h+1,i++}}decompose(t,i,n,h){let l=t<=0&&i>=this.length?this:new e(r(this.text,t,i),Math.min(i,this.length)-Math.max(0,t));if(1&h){let t=n.pop(),i=s(l.text,t.text.slice(),0,l.length);if(i.length<=32)n.push(new e(i,t.length+l.length));else{let t=i.length>>1;n.push(new e(i.slice(0,t)),new e(i.slice(t)))}}else n.push(l)}replace(t,n,h){if(!(h instanceof e))return super.replace(t,n,h);[t,n]=u(this,t,n);let l=s(this.text,s(h.text,r(this.text,0,t)),n),o=this.length+h.length-(n-t);return l.length<=32?new e(l,o):i.from(e.split(l,[]),o)}sliceString(t,e=this.length,i="\n"){[t,e]=u(this,t,e);let s="";for(let r=0,n=0;r<=e&&n<this.text.length;n++){let h=this.text[n],l=r+h.length;r>t&&n&&(s+=i),t<l&&e>r&&(s+=h.slice(Math.max(0,t-r),e-r)),r=l+1}return s}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,i){let s=[],r=-1;for(let n of t)s.push(n),r+=n.length+1,32==s.length&&(i.push(new e(s,r)),s=[],r=-1);return r>-1&&i.push(new e(s,r)),i}}class i extends t{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,i,s){for(let r=0;;r++){let n=this.children[r],h=s+n.length,l=i+n.lines-1;if((e?l:h)>=t)return n.lineInner(t,e,i,s);s=h+1,i=l+1}}decompose(t,e,i,s){for(let r=0,n=0;n<=e&&r<this.children.length;r++){let h=this.children[r],l=n+h.length;if(t<=l&&e>=n){let r=s&((n<=t?1:0)|(l>=e?2:0));n>=t&&l<=e&&!r?i.push(h):h.decompose(t-n,e-n,i,r)}n=l+1}}replace(t,e,s){if([t,e]=u(this,t,e),s.lines<this.lines)for(let r=0,n=0;r<this.children.length;r++){let h=this.children[r],l=n+h.length;if(t>=n&&e<=l){let o=h.replace(t-n,e-n,s),u=this.lines-h.lines+o.lines;if(o.lines<u>>4&&o.lines>u>>6){let n=this.children.slice();return n[r]=o,new i(n,this.length-(e-t)+s.length)}return super.replace(n,l,o)}n=l+1}return super.replace(t,e,s)}sliceString(t,e=this.length,i="\n"){[t,e]=u(this,t,e);let s="";for(let r=0,n=0;r<this.children.length&&n<=e;r++){let h=this.children[r],l=n+h.length;n>t&&r&&(s+=i),t<l&&e>n&&(s+=h.sliceString(t-n,e-n,i)),n=l+1}return s}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof i))return 0;let s=0,[r,n,h,l]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;r+=e,n+=e){if(r==h||n==l)return s;let i=this.children[r],o=t.children[n];if(i!=o)return s+i.scanIdentical(o,e);s+=i.length+1}}static from(t,s=t.reduce(((t,e)=>t+e.length+1),-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let i=[];for(let e of t)e.flatten(i);return new e(i,s)}let n=Math.max(32,r>>5),h=n<<1,l=n>>1,o=[],u=0,f=-1,a=[];function c(t){let s;if(t.lines>h&&t instanceof i)for(let e of t.children)c(e);else t.lines>l&&(u>l||!u)?(d(),o.push(t)):t instanceof e&&u&&(s=a[a.length-1])instanceof e&&t.lines+s.lines<=32?(u+=t.lines,f+=t.length+1,a[a.length-1]=new e(s.text.concat(t.text),s.length+1+t.length)):(u+t.lines>n&&d(),u+=t.lines,f+=t.length+1,a.push(t))}function d(){0!=u&&(o.push(1==a.length?a[0]:i.from(a,f)),f=-1,u=a.length=0)}for(let e of t)c(e);return d(),1==o.length?o[0]:new i(o,s)}}function s(t,e,i=0,s=1e9){for(let r=0,n=0,h=!0;n<t.length&&r<=s;n++){let l=t[n],o=r+l.length;o>=i&&(o>s&&(l=l.slice(0,s-r)),r<i&&(l=l.slice(i-r)),h?(e[e.length-1]+=l,h=!1):e.push(l)),r=o+1}return e}function r(t,e,i){return s(t,[""],e,i)}t.empty=new e([""],0);class n{constructor(t,i=1){this.dir=i,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[t],this.offsets=[i>0?1:(t instanceof e?t.text.length:t.children.length)<<1]}nextInner(t,i){for(this.done=this.lineBreak=!1;;){let s=this.nodes.length-1,r=this.nodes[s],n=this.offsets[s],h=n>>1,l=r instanceof e?r.text.length:r.children.length;if(h==(i>0?l:0)){if(0==s)return this.done=!0,this.value="",this;i>0&&this.offsets[s-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&n)==(i>0?0:1)){if(this.offsets[s]+=i,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(r instanceof e){let e=r.text[h+(i<0?-1:0)];if(this.offsets[s]+=i,e.length>Math.max(0,t))return this.value=0==t?e:i>0?e.slice(t):e.slice(0,e.length-t),this;t-=e.length}else{let n=r.children[h+(i<0?-1:0)];t>n.length?(t-=n.length,this.offsets[s]+=i):(i<0&&this.offsets[s]--,this.nodes.push(n),this.offsets.push(i>0?1:(n instanceof e?n.text.length:n.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class h{constructor(t,e,i){this.value="",this.done=!1,this.cursor=new n(t,e>i?-1:1),this.pos=e>i?t.length:0,this.from=Math.min(e,i),this.to=Math.max(e,i)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let i=e<0?this.pos-this.from:this.to-this.pos;t>i&&(t=i),i-=t;let{value:s}=this.cursor.next(t);return this.pos+=(s.length+t)*e,this.value=s.length<=i?s:e<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class l{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:i,value:s}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(t.prototype[Symbol.iterator]=function(){return this.iter()},n.prototype[Symbol.iterator]=h.prototype[Symbol.iterator]=l.prototype[Symbol.iterator]=function(){return this});class o{constructor(t,e,i,s){this.from=t,this.to=e,this.number=i,this.text=s}get length(){return this.to-this.from}}function u(t,e,i){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,i))]}let f="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=1;t<f.length;t++)f[t]+=f[t-1];function a(t){for(let e=1;e<f.length;e+=2)if(f[e]>t)return f[e-1]<=t;return!1}function c(t){return t>=127462&&t<=127487}const d=8205;function p(t,e,i=!0,s=!0){return(i?m:g)(t,e,s)}function m(t,e,i){if(e==t.length)return e;e&&w(t.charCodeAt(e))&&b(t.charCodeAt(e-1))&&e--;let s=v(t,e);for(e+=y(s);e<t.length;){let r=v(t,e);if(s==d||r==d||i&&a(r))e+=y(r),s=r;else{if(!c(r))break;{let i=0,s=e-2;for(;s>=0&&c(v(t,s));)i++,s-=2;if(i%2==0)break;e+=2}}}return e}function g(t,e,i){for(;e>0;){let s=m(t,e-2,i);if(s<e)return s;e--}return 0}function w(t){return t>=56320&&t<57344}function b(t){return t>=55296&&t<56320}function v(t,e){let i=t.charCodeAt(e);if(!b(i)||e+1==t.length)return i;let s=t.charCodeAt(e+1);return w(s)?s-56320+(i-55296<<10)+65536:i}function k(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function y(t){return t<65536?1:2}const M=/\r\n?|\n/;var x=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(x||(x={}));class S{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 0==this.sections.length||2==this.sections.length&&this.sections[1]<0}iterGaps(t){for(let e=0,i=0,s=0;e<this.sections.length;){let r=this.sections[e++],n=this.sections[e++];n<0?(t(i,s,r),s+=r):s+=n,i+=r}}iterChangedRanges(t,e=!1){D(this,t,e)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];s<0?t.push(i,s):t.push(s,i)}return new S(t)}composeDesc(t){return this.empty?t:t.empty?this:I(this,t)}mapDesc(t,e=!1){return t.empty?this:E(this,t,e)}mapPos(t,e=-1,i=x.Simple){let s=0,r=0;for(let n=0;n<this.sections.length;){let h=this.sections[n++],l=this.sections[n++],o=s+h;if(l<0){if(o>t)return r+(t-s);r+=h}else{if(i!=x.Simple&&o>=t&&(i==x.TrackDel&&s<t&&o>t||i==x.TrackBefore&&s<t||i==x.TrackAfter&&o>t))return null;if(o>t||o==t&&e<0&&!h)return t==s||e<0?r:r+l;r+=l}s=o}if(t>s)throw new RangeError(`Position ${t} is out of range for changeset of length ${s}`);return r}touchesRange(t,e=t){for(let i=0,s=0;i<this.sections.length&&s<=e;){let r=s+this.sections[i++];if(this.sections[i++]>=0&&s<=e&&r>=t)return!(s<t&&r>e)||"cover";s=r}return!1}toString(){let t="";for(let e=0;e<this.sections.length;){let i=this.sections[e++],s=this.sections[e++];t+=(t?" ":"")+i+(s>=0?":"+s:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some((t=>"number"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeDesc");return new S(t)}static create(t){return new S(t)}}class A extends S{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 D(this,((e,i,s,r,n)=>t=t.replace(s,s+(i-e),n)),!1),t}mapDesc(t,e=!1){return E(this,t,e,!0)}invert(e){let i=this.sections.slice(),s=[];for(let r=0,n=0;r<i.length;r+=2){let h=i[r],l=i[r+1];if(l>=0){i[r]=l,i[r+1]=h;let o=r>>1;for(;s.length<o;)s.push(t.empty);s.push(h?e.slice(n,n+h):t.empty)}n+=h}return new A(i,s)}compose(t){return this.empty?t:t.empty?this:I(this,t,!0)}map(t,e=!1){return t.empty?this:E(this,t,e,!0)}iterChanges(t,e=!1){D(this,t,e)}get desc(){return S.create(this.sections)}filter(t){let e=[],i=[],s=[],r=new R(this);t:for(let n=0,h=0;;){let l=n==t.length?1e9:t[n++];for(;h<l||h==l&&0==r.len;){if(r.done)break t;let t=Math.min(r.len,l-h);C(s,t,-1);let n=-1==r.ins?-1:0==r.off?r.ins:0;C(e,t,n),n>0&&O(i,e,r.text),r.forward(t),h+=t}let o=t[n++];for(;h<o;){if(r.done)break t;let t=Math.min(r.len,o-h);C(e,t,-1),C(s,t,-1==r.ins?-1:0==r.off?r.ins:0),r.forward(t),h+=t}}return{changes:new A(e,i),filtered:S.create(s)}}toJSON(){let t=[];for(let e=0;e<this.sections.length;e+=2){let i=this.sections[e],s=this.sections[e+1];s<0?t.push(i):0==s?t.push([i]):t.push([i].concat(this.inserted[e>>1].toJSON()))}return t}static of(e,i,s){let r=[],n=[],h=0,l=null;function o(t=!1){if(!t&&!r.length)return;h<i&&C(r,i-h,-1);let e=new A(r,n);l=l?l.compose(e.map(l)):e,r=[],n=[],h=0}return function e(u){if(Array.isArray(u))for(let t of u)e(t);else if(u instanceof A){if(u.length!=i)throw new RangeError(`Mismatched change set length (got ${u.length}, expected ${i})`);o(),l=l?l.compose(u.map(l)):u}else{let{from:e,to:l=e,insert:f}=u;if(e>l||e<0||l>i)throw new RangeError(`Invalid change range ${e} to ${l} (in doc of length ${i})`);let a=f?"string"==typeof f?t.of(f.split(s||M)):f:t.empty,c=a.length;if(e==l&&0==c)return;e<h&&o(),e>h&&C(r,e-h,-1),C(r,l-e,c),O(n,r,a),h=l}}(e),o(!l),l}static empty(t){return new A(t?[t,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let i=[],s=[];for(let r=0;r<e.length;r++){let n=e[r];if("number"==typeof n)i.push(n,-1);else{if(!Array.isArray(n)||"number"!=typeof n[0]||n.some(((t,e)=>e&&"string"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==n.length)i.push(n[0],0);else{for(;s.length<r;)s.push(t.empty);s[r]=t.of(n.slice(1)),i.push(n[0],s[r].length)}}}return new A(i,s)}static createSet(t,e){return new A(t,e)}}function C(t,e,i,s=!1){if(0==e&&i<=0)return;let r=t.length-2;r>=0&&i<=0&&i==t[r+1]?t[r]+=e:0==e&&0==t[r]?t[r+1]+=i:s?(t[r]+=e,t[r+1]+=i):t.push(e,i)}function O(e,i,s){if(0==s.length)return;let r=i.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(s);else{for(;e.length<r;)e.push(t.empty);e.push(s)}}function D(e,i,s){let r=e.inserted;for(let n=0,h=0,l=0;l<e.sections.length;){let o=e.sections[l++],u=e.sections[l++];if(u<0)n+=o,h+=o;else{let f=n,a=h,c=t.empty;for(;f+=o,a+=u,u&&r&&(c=c.append(r[l-2>>1])),!(s||l==e.sections.length||e.sections[l+1]<0);)o=e.sections[l++],u=e.sections[l++];i(n,f,h,a,c),n=f,h=a}}}function E(t,e,i,s=!1){let r=[],n=s?[]:null,h=new R(t),l=new R(e);for(let t=-1;;)if(-1==h.ins&&-1==l.ins){let t=Math.min(h.len,l.len);C(r,t,-1),h.forward(t),l.forward(t)}else if(l.ins>=0&&(h.ins<0||t==h.i||0==h.off&&(l.len<h.len||l.len==h.len&&!i))){let e=l.len;for(C(r,l.ins,-1);e;){let i=Math.min(h.len,e);h.ins>=0&&t<h.i&&h.len<=i&&(C(r,0,h.ins),n&&O(n,r,h.text),t=h.i),h.forward(i),e-=i}l.next()}else{if(!(h.ins>=0)){if(h.done&&l.done)return n?A.createSet(r,n):S.create(r);throw new Error("Mismatched change set lengths")}{let e=0,i=h.len;for(;i;)if(-1==l.ins){let t=Math.min(i,l.len);e+=t,i-=t,l.forward(t)}else{if(!(0==l.ins&&l.len<i))break;i-=l.len,l.next()}C(r,e,t<h.i?h.ins:0),n&&t<h.i&&O(n,r,h.text),t=h.i,h.forward(h.len-i)}}}function I(t,e,i=!1){let s=[],r=i?[]:null,n=new R(t),h=new R(e);for(let t=!1;;){if(n.done&&h.done)return r?A.createSet(s,r):S.create(s);if(0==n.ins)C(s,n.len,0,t),n.next();else if(0!=h.len||h.done){if(n.done||h.done)throw new Error("Mismatched change set lengths");{let e=Math.min(n.len2,h.len),i=s.length;if(-1==n.ins){let i=-1==h.ins?-1:h.off?0:h.ins;C(s,e,i,t),r&&i&&O(r,s,h.text)}else-1==h.ins?(C(s,n.off?0:n.len,e,t),r&&O(r,s,n.textBit(e))):(C(s,n.off?0:n.len,h.off?0:h.ins,t),r&&!h.off&&O(r,s,h.text));t=(n.ins>e||h.ins>=0&&h.len>e)&&(t||s.length>i),n.forward2(e),h.forward(e)}}else C(s,0,h.ins,t),r&&O(r,s,h.text),h.next()}}class R{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-2==this.ins}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,i=this.i-2>>1;return i>=e.length?t.empty:e[i]}textBit(e){let{inserted:i}=this.set,s=this.i-2>>1;return s>=i.length&&!e?t.empty:i[s].slice(this.off,null==e?void 0:this.off+e)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class T{constructor(t,e,i){this.from=t,this.to=e,this.flags=i}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}get goalColumn(){let t=this.flags>>6;return 16777215==t?void 0:t}map(t,e=-1){let i,s;return this.empty?i=s=t.mapPos(this.from,e):(i=t.mapPos(this.from,1),s=t.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new T(i,s,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return B.range(t,e);let i=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return B.range(this.anchor,i)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return B.range(t.anchor,t.head)}static create(t,e,i){return new T(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 1==this.ranges.length?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)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new B(t.ranges.map((t=>T.fromJSON(t))),t.main)}static single(t,e=t){return new B([B.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<t.length;s++){let r=t[s];if(r.empty?r.from<=i:r.from<i)return B.normalized(t.slice(),e);i=r.to}return new B(t,e)}static cursor(t,e=0,i,s){return T.create(t,t,(0==e?0:e<0?8:16)|(null==i?7:Math.min(6,i))|(null!=s?s:16777215)<<6)}static range(t,e,i,s){let r=(null!=i?i:16777215)<<6|(null==s?7:Math.min(6,s));return e<t?T.create(e,t,48|r):T.create(t,e,(e>t?8:0)|r)}static normalized(t,e=0){let i=t[e];t.sort(((t,e)=>t.from-e.from)),e=t.indexOf(i);for(let i=1;i<t.length;i++){let s=t[i],r=t[i-1];if(s.empty?s.from<=r.to:s.from<r.to){let n=r.from,h=Math.max(s.to,r.to);i<=e&&e--,t.splice(--i,2,s.anchor>s.head?B.range(h,n):B.range(n,h))}}return new B(t,e)}}function L(t,e){for(let i of t.ranges)if(i.to>e)throw new RangeError("Selection points outside of document")}let N=0;class j{constructor(t,e,i,s,r){this.combine=t,this.compareInput=e,this.compare=i,this.isStatic=s,this.id=N++,this.default=t([]),this.extensions="function"==typeof r?r(this):r}get reader(){return this}static define(t={}){return new j(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:$),!!t.static,t.enables)}of(t){return new z([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new z(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new z(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],(i=>e(i.field(t))))}}function $(t,e){return t==e||t.length==e.length&&t.every(((t,i)=>t===e[i]))}class z{constructor(t,e,i,s){this.dependencies=t,this.facet=e,this.type=i,this.value=s,this.id=N++}dynamicSlot(t){var e;let i=this.value,s=this.facet.compareInput,r=this.id,n=t[r]>>1,h=2==this.type,l=!1,o=!1,u=[];for(let i of this.dependencies)"doc"==i?l=!0:"selection"==i?o=!0:1&(null!==(e=t[i.id])&&void 0!==e?e:1)||u.push(t[i.id]);return{create:t=>(t.values[n]=i(t),1),update(t,e){if(l&&e.docChanged||o&&(e.docChanged||e.selection)||H(t,u)){let e=i(t);if(h?!P(e,t.values[n],s):!s(e,t.values[n]))return t.values[n]=e,1}return 0},reconfigure:(t,e)=>{let l,o=e.config.address[r];if(null!=o){let r=et(e,o);if(this.dependencies.every((i=>i instanceof j?e.facet(i)===t.facet(i):!(i instanceof F)||e.field(i,!1)==t.field(i,!1)))||(h?P(l=i(t),r,s):s(l=i(t),r)))return t.values[n]=r,0}else l=i(t);return t.values[n]=l,1}}}}function P(t,e,i){if(t.length!=e.length)return!1;for(let s=0;s<t.length;s++)if(!i(t[s],e[s]))return!1;return!0}function H(t,e){let i=!1;for(let s of e)1&tt(t,s)&&(i=!0);return i}function W(t,e,i){let s=i.map((e=>t[e.id])),r=i.map((t=>t.type)),n=s.filter((t=>!(1&t))),h=t[e.id]>>1;function l(t){let i=[];for(let e=0;e<s.length;e++){let n=et(t,s[e]);if(2==r[e])for(let t of n)i.push(t);else i.push(n)}return e.combine(i)}return{create(t){for(let e of s)tt(t,e);return t.values[h]=l(t),1},update(t,i){if(!H(t,n))return 0;let s=l(t);return e.compare(s,t.values[h])?0:(t.values[h]=s,1)},reconfigure(t,r){let n=H(t,s),o=r.config.facets[e.id],u=r.facet(e);if(o&&!n&&$(i,o))return t.values[h]=u,0;let f=l(t);return e.compare(f,u)?(t.values[h]=u,0):(t.values[h]=f,1)}}}const V=j.define({static:!0});class F{constructor(t,e,i,s,r){this.id=t,this.createF=e,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(t){let e=new F(N++,t.create,t.update,t.compare||((t,e)=>t===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(V).find((t=>t.field==this));return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,i)=>{let s=t.values[e],r=this.updateF(s,i);return this.compareF(s,r)?0:(t.values[e]=r,1)},reconfigure:(t,i)=>null!=i.config.address[this.id]?(t.values[e]=i.field(this),0):(t.values[e]=this.create(t),1)}}init(t){return[this,V.of({field:this,create:t})]}get extension(){return this}}const q=4,U=3,J=2,G=1;function K(t){return e=>new X(e,t)}const _={highest:K(0),high:K(G),default:K(J),low:K(U),lowest:K(q)};class X{constructor(t,e){this.inner=t,this.prec=e}}class Y{of(t){return new Q(this,t)}reconfigure(t){return Y.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class Q{constructor(t,e){this.compartment=t,this.inner=e}}class Z{constructor(t,e,i,s,r,n){for(this.base=t,this.compartments=e,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=n,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(t){let e=this.address[t.id];return null==e?t.default:this.staticValues[e>>1]}static resolve(t,e,i){let s=[],r=Object.create(null),n=new Map;for(let i of function(t,e,i){let s=[[],[],[],[],[]],r=new Map;function n(t,h){let l=r.get(t);if(null!=l){if(l<=h)return;let e=s[l].indexOf(t);e>-1&&s[l].splice(e,1),t instanceof Q&&i.delete(t.compartment)}if(r.set(t,h),Array.isArray(t))for(let e of t)n(e,h);else if(t instanceof Q){if(i.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let s=e.get(t.compartment)||t.inner;i.set(t.compartment,s),n(s,h)}else if(t instanceof X)n(t.inner,t.prec);else if(t instanceof F)s[h].push(t),t.provides&&n(t.provides,h);else if(t instanceof z)s[h].push(t),t.facet.extensions&&n(t.facet.extensions,J);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);n(e,h)}}return n(t,J),s.reduce(((t,e)=>t.concat(e)))}(t,e,n))i instanceof F?s.push(i):(r[i.facet.id]||(r[i.facet.id]=[])).push(i);let h=Object.create(null),l=[],o=[];for(let t of s)h[t.id]=o.length<<1,o.push((e=>t.slot(e)));let u=null==i?void 0:i.config.facets;for(let t in r){let e=r[t],s=e[0].facet,n=u&&u[t]||[];if(e.every((t=>0==t.type)))if(h[s.id]=l.length<<1|1,$(n,e))l.push(i.facet(s));else{let t=s.combine(e.map((t=>t.value)));l.push(i&&s.compare(t,i.facet(s))?i.facet(s):t)}else{for(let t of e)0==t.type?(h[t.id]=l.length<<1|1,l.push(t.value)):(h[t.id]=o.length<<1,o.push((e=>t.dynamicSlot(e))));h[s.id]=o.length<<1,o.push((t=>W(t,s,e)))}}let f=o.map((t=>t(h)));return new Z(t,n,f,h,l,r)}}function tt(t,e){if(1&e)return 2;let i=e>>1,s=t.status[i];if(4==s)throw new Error("Cyclic dependency between fields and/or facets");if(2&s)return s;t.status[i]=4;let r=t.computeSlot(t,t.config.dynamicSlots[i]);return t.status[i]=2|r}function et(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const it=j.define(),st=j.define({combine:t=>t.some((t=>t)),static:!0}),rt=j.define({combine:t=>t.length?t[0]:void 0,static:!0}),nt=j.define(),ht=j.define(),lt=j.define(),ot=j.define({combine:t=>!!t.length&&t[0]});class ut{constructor(t,e){this.type=t,this.value=e}static define(){return new ft}}class ft{of(t){return new ut(this,t)}}class at{constructor(t){this.map=t}of(t){return new ct(this,t)}}class ct{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new ct(this.type,e)}is(t){return this.type==t}static define(t={}){return new at(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let i=[];for(let s of t){let t=s.map(e);t&&i.push(t)}return i}}ct.reconfigure=ct.define(),ct.appendConfig=ct.define();class dt{constructor(t,e,i,s,r,n){this.startState=t,this.changes=e,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=n,this._doc=null,this._state=null,i&&L(i,e.newLength),r.some((t=>t.type==dt.time))||(this.annotations=r.concat(dt.time.of(Date.now())))}static create(t,e,i,s,r,n){return new dt(t,e,i,s,r,n)}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(dt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function pt(t,e){let i=[];for(let s=0,r=0;;){let n,h;if(s<t.length&&(r==e.length||e[r]>=t[s]))n=t[s++],h=t[s++];else{if(!(r<e.length))return i;n=e[r++],h=e[r++]}!i.length||i[i.length-1]<n?i.push(n,h):i[i.length-1]<h&&(i[i.length-1]=h)}}function mt(t,e,i){var s;let r,n,h;return i?(r=e.changes,n=A.empty(e.changes.length),h=t.changes.compose(e.changes)):(r=e.changes.map(t.changes),n=t.changes.mapDesc(e.changes,!0),h=t.changes.compose(r)),{changes:h,selection:e.selection?e.selection.map(n):null===(s=t.selection)||void 0===s?void 0:s.map(r),effects:ct.mapEffects(t.effects,r).concat(ct.mapEffects(e.effects,n)),annotations:t.annotations.length?t.annotations.concat(e.annotations):e.annotations,scrollIntoView:t.scrollIntoView||e.scrollIntoView}}function gt(t,e,i){let s=e.selection,r=vt(e.annotations);return e.userEvent&&(r=r.concat(dt.userEvent.of(e.userEvent))),{changes:e.changes instanceof A?e.changes:A.of(e.changes||[],i,t.facet(rt)),selection:s&&(s instanceof B?s:B.single(s.anchor,s.head)),effects:vt(e.effects),annotations:r,scrollIntoView:!!e.scrollIntoView}}function wt(t,e,i){let s=gt(t,e.length?e[0]:{},t.doc.length);e.length&&!1===e[0].filter&&(i=!1);for(let r=1;r<e.length;r++){!1===e[r].filter&&(i=!1);let n=!!e[r].sequential;s=mt(s,gt(t,e[r],n?s.changes.newLength:t.doc.length),n)}let r=dt.create(t,s.changes,s.selection,s.effects,s.annotations,s.scrollIntoView);return function(t){let e=t.startState,i=e.facet(lt),s=t;for(let r=i.length-1;r>=0;r--){let n=i[r](t);n&&Object.keys(n).length&&(s=mt(s,gt(e,n,t.changes.newLength),!0))}return s==t?t:dt.create(e,t.changes,t.selection,s.effects,s.annotations,s.scrollIntoView)}(i?function(t){let e=t.startState,i=!0;for(let s of e.facet(nt)){let e=s(t);if(!1===e){i=!1;break}Array.isArray(e)&&(i=!0===i?e:pt(i,e))}if(!0!==i){let s,r;if(!1===i)r=t.changes.invertedDesc,s=A.empty(e.doc.length);else{let e=t.changes.filter(i);s=e.changes,r=e.filtered.mapDesc(e.changes).invertedDesc}t=dt.create(e,s,t.selection&&t.selection.map(r),ct.mapEffects(t.effects,r),t.annotations,t.scrollIntoView)}let s=e.facet(ht);for(let i=s.length-1;i>=0;i--){let r=s[i](t);t=r instanceof dt?r:Array.isArray(r)&&1==r.length&&r[0]instanceof dt?r[0]:wt(e,vt(r),!1)}return t}(r):r)}dt.time=ut.define(),dt.userEvent=ut.define(),dt.addToHistory=ut.define(),dt.remote=ut.define();const bt=[];function vt(t){return null==t?bt:Array.isArray(t)?t:[t]}var kt=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(kt||(kt={}));const yt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Mt;try{Mt=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function xt(t){return e=>{if(!/\S/.test(e))return kt.Space;if(function(t){if(Mt)return Mt.test(t);for(let e=0;e<t.length;e++){let i=t[e];if(/\w/.test(i)||i>""&&(i.toUpperCase()!=i.toLowerCase()||yt.test(i)))return!0}return!1}(e))return kt.Word;for(let i=0;i<t.length;i++)if(e.indexOf(t[i])>-1)return kt.Word;return kt.Other}}class St{constructor(t,e,i,s,r,n){this.config=t,this.doc=e,this.selection=i,this.values=s,this.status=t.statusTemplate.slice(),this.computeSlot=r,n&&(n._state=this);for(let t=0;t<this.config.dynamicSlots.length;t++)tt(this,t<<1);this.computeSlot=null}field(t,e=!0){let i=this.config.address[t.id];if(null!=i)return tt(this,i),et(this,i);if(e)throw new RangeError("Field is not present in this state")}update(...t){return wt(this,t,!0)}applyTransaction(t){let e,i=this.config,{base:s,compartments:r}=i;for(let e of t.effects)e.is(Y.reconfigure)?(i&&(r=new Map,i.compartments.forEach(((t,e)=>r.set(e,t))),i=null),r.set(e.value.compartment,e.value.extension)):e.is(ct.reconfigure)?(i=null,s=e.value):e.is(ct.appendConfig)&&(i=null,s=vt(s).concat(e.value));if(i)e=t.startState.values.slice();else{i=Z.resolve(s,r,this),e=new St(i,this.doc,this.selection,i.dynamicSlots.map((()=>null)),((t,e)=>e.reconfigure(t,this)),null).values}let n=t.startState.facet(st)?t.newSelection:t.newSelection.asSingle();new St(i,t.newDoc,n,e,((e,i)=>i.update(e,t)),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t},range:B.cursor(e.from+t.length)})))}changeByRange(t){let e=this.selection,i=t(e.ranges[0]),s=this.changes(i.changes),r=[i.range],n=vt(i.effects);for(let i=1;i<e.ranges.length;i++){let h=t(e.ranges[i]),l=this.changes(h.changes),o=l.map(s);for(let t=0;t<i;t++)r[t]=r[t].map(o);let u=s.mapDesc(l,!0);r.push(h.range.map(u)),s=s.compose(o),n=ct.mapEffects(n,o).concat(ct.mapEffects(vt(h.effects),u))}return{changes:s,selection:B.create(r,e.mainIndex),effects:n}}changes(t=[]){return t instanceof A?t:A.of(t,this.doc.length,this.facet(St.lineSeparator))}toText(e){return t.of(e.split(this.facet(St.lineSeparator)||M))}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 null==e?t.default:(tt(this,e),et(this,e))}toJSON(t){let e={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(t)for(let i in t){let s=t[i];s instanceof F&&null!=this.config.address[s.id]&&(e[i]=s.spec.toJSON(this.field(t[i]),this))}return e}static fromJSON(t,e={},i){if(!t||"string"!=typeof t.doc)throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i)for(let e in i)if(Object.prototype.hasOwnProperty.call(t,e)){let r=i[e],n=t[e];s.push(r.init((t=>r.spec.fromJSON(n,t))))}return St.create({doc:t.doc,selection:B.fromJSON(t.selection),extensions:e.extensions?s.concat([e.extensions]):s})}static create(e={}){let i=Z.resolve(e.extensions||[],new Map),s=e.doc instanceof t?e.doc:t.of((e.doc||"").split(i.staticFacet(St.lineSeparator)||M)),r=e.selection?e.selection instanceof B?e.selection:B.single(e.selection.anchor,e.selection.head):B.single(0);return L(r,s.length),i.staticFacet(st)||(r=r.asSingle()),new St(i,s,r,i.dynamicSlots.map((()=>null)),((t,e)=>e.create(t)),null)}get tabSize(){return this.facet(St.tabSize)}get lineBreak(){return this.facet(St.lineSeparator)||"\n"}get readOnly(){return this.facet(ot)}phrase(t,...e){for(let e of this.facet(St.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,((t,i)=>{if("$"==i)return"$";let s=+(i||1);return!s||s>e.length?t:e[s-1]}))),t}languageDataAt(t,e,i=-1){let s=[];for(let r of this.facet(it))for(let n of r(this,e,i))Object.prototype.hasOwnProperty.call(n,t)&&s.push(n[t]);return s}charCategorizer(t){return xt(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:i,length:s}=this.doc.lineAt(t),r=this.charCategorizer(t),n=t-i,h=t-i;for(;n>0;){let t=p(e,n,!1);if(r(e.slice(t,n))!=kt.Word)break;n=t}for(;h<s;){let t=p(e,h);if(r(e.slice(h,t))!=kt.Word)break;h=t}return n==h?null:B.range(n+i,h+i)}}function At(t,e,i={}){let s={};for(let e of t)for(let t of Object.keys(e)){let r=e[t],n=s[t];if(void 0===n)s[t]=r;else if(n===r||void 0===r);else{if(!Object.hasOwnProperty.call(i,t))throw new Error("Config merge conflict for field "+t);s[t]=i[t](n,r)}}for(let t in e)void 0===s[t]&&(s[t]=e[t]);return s}St.allowMultipleSelections=st,St.tabSize=j.define({combine:t=>t.length?t[0]:4}),St.lineSeparator=rt,St.readOnly=ot,St.phrases=j.define({compare(t,e){let i=Object.keys(t),s=Object.keys(e);return i.length==s.length&&i.every((i=>t[i]==e[i]))}}),St.languageData=it,St.changeFilter=nt,St.transactionFilter=ht,St.transactionExtender=lt,Y.reconfigure=ct.define();class Ct{eq(t){return this==t}range(t,e=t){return Ot.create(t,e,this)}}Ct.prototype.startSide=Ct.prototype.endSide=0,Ct.prototype.point=!1,Ct.prototype.mapMode=x.TrackDel;let Ot=class t{constructor(t,e,i){this.from=t,this.to=e,this.value=i}static create(e,i,s){return new t(e,i,s)}};function Dt(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Et{constructor(t,e,i,s){this.from=t,this.to=e,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(t,e,i,s=0){let r=i?this.to:this.from;for(let n=s,h=r.length;;){if(n==h)return n;let s=n+h>>1,l=r[s]-t||(i?this.value[s].endSide:this.value[s].startSide)-e;if(s==n)return l>=0?n:h;l>=0?h=s:n=s+1}}between(t,e,i,s){for(let r=this.findIndex(e,-1e9,!0),n=this.findIndex(i,1e9,!1,r);r<n;r++)if(!1===s(this.from[r]+t,this.to[r]+t,this.value[r]))return!1}map(t,e){let i=[],s=[],r=[],n=-1,h=-1;for(let l=0;l<this.value.length;l++){let o,u,f=this.value[l],a=this.from[l]+t,c=this.to[l]+t;if(a==c){let t=e.mapPos(a,f.startSide,f.mapMode);if(null==t)continue;if(o=u=t,f.startSide!=f.endSide&&(u=e.mapPos(a,f.endSide),u<o))continue}else if(o=e.mapPos(a,f.startSide),u=e.mapPos(c,f.endSide),o>u||o==u&&f.startSide>0&&f.endSide<=0)continue;(u-o||f.endSide-f.startSide)<0||(n<0&&(n=o),f.point&&(h=Math.max(h,u-o)),i.push(f),s.push(o-n),r.push(u-n))}return{mapped:i.length?new Et(s,r,i,h):null,pos:n}}}class It{constructor(t,e,i,s){this.chunkPos=t,this.chunk=e,this.nextLayer=i,this.maxPoint=s}static create(t,e,i,s){return new It(t,e,i,s)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=t,n=t.filter;if(0==e.length&&!n)return this;if(i&&(e=e.slice().sort(Dt)),this.isEmpty)return e.length?It.of(e):this;let h=new Bt(this,null,-1).goto(0),l=0,o=[],u=new Rt;for(;h.value||l<e.length;)if(l<e.length&&(h.from-e[l].from||h.startSide-e[l].value.startSide)>=0){let t=e[l++];u.addInner(t.from,t.to,t.value)||o.push(t)}else 1==h.rangeIndex&&h.chunkIndex<this.chunk.length&&(l==e.length||this.chunkEnd(h.chunkIndex)<e[l].from)&&(!n||s>this.chunkEnd(h.chunkIndex)||r<this.chunkPos[h.chunkIndex])&&u.addChunk(this.chunkPos[h.chunkIndex],this.chunk[h.chunkIndex])?h.nextChunk():((!n||s>h.to||r<h.from||n(h.from,h.to,h.value))&&(u.addInner(h.from,h.to,h.value)||o.push(Ot.create(h.from,h.to,h.value))),h.next());return u.finishInner(this.nextLayer.isEmpty&&!o.length?It.empty:this.nextLayer.update({add:o,filter:n,filterFrom:s,filterTo:r}))}map(t){if(t.empty||this.isEmpty)return this;let e=[],i=[],s=-1;for(let r=0;r<this.chunk.length;r++){let n=this.chunkPos[r],h=this.chunk[r],l=t.touchesRange(n,n+h.length);if(!1===l)s=Math.max(s,h.maxPoint),e.push(h),i.push(t.mapPos(n));else if(!0===l){let{mapped:r,pos:l}=h.map(n,t);r&&(s=Math.max(s,r.maxPoint),e.push(r),i.push(l))}}let r=this.nextLayer.map(t);return 0==e.length?r:new It(i,e,r||It.empty,s)}between(t,e,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],n=this.chunk[s];if(e>=r&&t<=r+n.length&&!1===n.between(r,t-r,e-r,i))return}this.nextLayer.between(t,e,i)}}iter(t=0){return Lt.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Lt.from(t).goto(e)}static compare(t,e,i,s,r=-1){let n=t.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),h=e.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=r)),l=Tt(n,h,i),o=new jt(n,l,r),u=new jt(h,l,r);i.iterGaps(((t,e,i)=>$t(o,t,u,e,i,s))),i.empty&&0==i.length&&$t(o,0,u,0,0,s)}static eq(t,e,i=0,s){null==s&&(s=999999999);let r=t.filter((t=>!t.isEmpty&&e.indexOf(t)<0)),n=e.filter((e=>!e.isEmpty&&t.indexOf(e)<0));if(r.length!=n.length)return!1;if(!r.length)return!0;let h=Tt(r,n),l=new jt(r,h,0).goto(i),o=new jt(n,h,0).goto(i);for(;;){if(l.to!=o.to||!zt(l.active,o.active)||l.point&&(!o.point||!l.point.eq(o.point)))return!1;if(l.to>s)return!0;l.next(),o.next()}}static spans(t,e,i,s,r=-1){let n=new jt(t,null,r).goto(e),h=e,l=n.openStart;for(;;){let t=Math.min(n.to,i);if(n.point){let i=n.activeForPoint(n.to),r=n.pointFrom<e?i.length+1:n.point.startSide<0?i.length:Math.min(i.length,l);s.point(h,t,n.point,i,r,n.pointRank),l=Math.min(n.openEnd(t),i.length)}else t>h&&(s.span(h,t,n.active,l),l=n.openEnd(t));if(n.to>i)return l+(n.point&&n.to>i?1:0);h=n.to,n.next()}}static of(t,e=!1){let i=new Rt;for(let s of t instanceof Ot?[t]:e?function(t){if(t.length>1)for(let e=t[0],i=1;i<t.length;i++){let s=t[i];if(Dt(e,s)>0)return t.slice().sort(Dt);e=s}return t}(t):t)i.add(s.from,s.to,s.value);return i.finish()}static join(t){if(!t.length)return It.empty;let e=t[t.length-1];for(let i=t.length-2;i>=0;i--)for(let s=t[i];s!=It.empty;s=s.nextLayer)e=new It(s.chunkPos,s.chunk,e,Math.max(s.maxPoint,e.maxPoint));return e}}It.empty=new It([],[],null,-1),It.empty.nextLayer=It.empty;class Rt{finishChunk(t){this.chunks.push(new Et(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 Rt)).add(t,e,i)}addInner(t,e,i){let s=t-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(t-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(s<0)&&(250==this.from.length&&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(It.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=It.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Tt(t,e,i){let s=new Map;for(let e of t)for(let t=0;t<e.chunk.length;t++)e.chunk[t].maxPoint<=0&&s.set(e.chunk[t],e.chunkPos[t]);let r=new Set;for(let t of e)for(let e=0;e<t.chunk.length;e++){let n=s.get(t.chunk[e]);null==n||(i?i.mapPos(n):n)!=t.chunkPos[e]||(null==i?void 0:i.touchesRange(n,n+t.chunk[e].length))||r.add(t.chunk[e])}return r}class Bt{constructor(t,e,i,s=0){this.layer=t,this.skip=e,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(t,e=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(t,e,!1),this}gotoInner(t,e,i){for(;this.chunkIndex<this.layer.chunk.length;){let e=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(e)||this.layer.chunkEnd(this.chunkIndex)<t||e.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(t-this.layer.chunkPos[this.chunkIndex],e,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(t,e){(this.to-t||this.endSide-e)<0&&this.gotoInner(t,e,!0)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}{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 Lt{constructor(t){this.heap=t}static from(t,e=null,i=-1){let s=[];for(let r=0;r<t.length;r++)for(let n=t[r];!n.isEmpty;n=n.nextLayer)n.maxPoint>=i&&s.push(new Bt(n,e,i,r));return 1==s.length?s[0]:new Lt(s)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let i of this.heap)i.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)Nt(this.heap,t);return this.next(),this}forward(t,e){for(let i of this.heap)i.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)Nt(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)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(),Nt(this.heap,0)}}}function Nt(t,e){for(let i=t[e];;){let s=1+(e<<1);if(s>=t.length)break;let r=t[s];if(s+1<t.length&&r.compare(t[s+1])>=0&&(r=t[s+1],s++),i.compare(r)<0)break;t[s]=i,t[e]=r,e=s}}class jt{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=Lt.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){Pt(this.active,t),Pt(this.activeTo,t),Pt(this.activeRank,t),this.minActive=Wt(this.active,this.activeTo)}addActive(t){let e=0,{value:i,to:s,rank:r}=this.cursor;for(;e<this.activeRank.length&&(r-this.activeRank[e]||s-this.activeTo[e])>0;)e++;Ht(this.active,e,i),Ht(this.activeTo,e,s),Ht(this.activeRank,e,r),t&&Ht(t,e,this.cursor.from),this.minActive=Wt(this.active,this.activeTo)}next(){let t=this.to,e=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>t){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&Pt(i,s)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){this.point=t,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=t.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}this.cursor.next()}else this.addActive(i),this.cursor.next()}}}if(i){this.openStart=0;for(let e=i.length-1;e>=0&&i[e]<t;e--)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 $t(t,e,i,s,r,n){t.goto(e),i.goto(s);let h=s+r,l=s,o=s-e;for(;;){let e=t.to+o-i.to||t.endSide-i.endSide,s=e<0?t.to+o:i.to,r=Math.min(s,h);if(t.point||i.point?t.point&&i.point&&(t.point==i.point||t.point.eq(i.point))&&zt(t.activeForPoint(t.to),i.activeForPoint(i.to))||n.comparePoint(l,r,t.point,i.point):r>l&&!zt(t.active,i.active)&&n.compareRange(l,r,t.active,i.active),s>h)break;l=s,e<=0&&t.next(),e>=0&&i.next()}}function zt(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!=e[i]&&!t[i].eq(e[i]))return!1;return!0}function Pt(t,e){for(let i=e,s=t.length-1;i<s;i++)t[i]=t[i+1];t.pop()}function Ht(t,e,i){for(let i=t.length-1;i>=e;i--)t[i+1]=t[i];t[e]=i}function Wt(t,e){let i=-1,s=1e9;for(let r=0;r<e.length;r++)(e[r]-s||t[r].endSide-t[i].endSide)<0&&(i=r,s=e[r]);return i}function Vt(t,e,i=t.length){let s=0;for(let r=0;r<i;)9==t.charCodeAt(r)?(s+=e-s%e,r++):(s++,r=p(t,r));return s}function Ft(t,e,i,s){for(let s=0,r=0;;){if(r>=e)return s;if(s==t.length)break;r+=9==t.charCodeAt(s)?i-r%i:1,s=p(t,s)}return!0===s?-1:t.length}const qt="undefined"==typeof Symbol?"__ͼ":Symbol.for("ͼ"),Ut="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Jt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Gt{constructor(t,e){this.rules=[];let{finish:i}=e||{};function s(t){return/^@/.test(t)?[t]:t.split(/,\s*/)}function r(t,e,n,h){let l=[],o=/^@(\w+)\b/.exec(t[0]),u=o&&"keyframes"==o[1];if(o&&null==e)return n.push(t[0]+";");for(let i in e){let h=e[i];if(/&/.test(i))r(i.split(/,\s*/).map((e=>t.map((t=>e.replace(/&/,t))))).reduce(((t,e)=>t.concat(e))),h,n);else if(h&&"object"==typeof h){if(!o)throw new RangeError("The value of a property ("+i+") should be a primitive value.");r(s(i),h,l,u)}else null!=h&&l.push(i.replace(/_.*/,"").replace(/[A-Z]/g,(t=>"-"+t.toLowerCase()))+": "+h+";")}(l.length||u)&&n.push((!i||o||h?t:t.map(i)).join(", ")+" {"+l.join(" ")+"}")}for(let e in t)r(s(e),t[e],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let t=Jt[qt]||1;return Jt[qt]=t+1,"ͼ"+t.toString(36)}static mount(t,e,i){let s=t[Ut],r=i&&i.nonce;s?r&&s.setNonce(r):s=new _t(t,r),s.mount(Array.isArray(e)?e:[e],t)}}let Kt=new Map;class _t{constructor(t,e){let i=t.ownerDocument||t,s=i.defaultView;if(!t.head&&t.adoptedStyleSheets&&s.CSSStyleSheet){let e=Kt.get(i);if(e)return t[Ut]=e;this.sheet=new s.CSSStyleSheet,Kt.set(i,this)}else this.styleTag=i.createElement("style"),e&&this.styleTag.setAttribute("nonce",e);this.modules=[],t[Ut]=this}mount(t,e){let i=this.sheet,s=0,r=0;for(let e=0;e<t.length;e++){let n=t[e],h=this.modules.indexOf(n);if(h<r&&h>-1&&(this.modules.splice(h,1),r--,h=-1),-1==h){if(this.modules.splice(r++,0,n),i)for(let t=0;t<n.rules.length;t++)i.insertRule(n.rules[t],s++)}else{for(;r<h;)s+=this.modules[r++].rules.length;s+=n.rules.length,r++}}if(i)e.adoptedStyleSheets.indexOf(this.sheet)<0&&(e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets]);else{let t="";for(let e=0;e<this.modules.length;e++)t+=this.modules[e].getRules()+"\n";this.styleTag.textContent=t;let i=e.head||e;this.styleTag.parentNode!=i&&i.insertBefore(this.styleTag,i.firstChild)}}setNonce(t){this.styleTag&&this.styleTag.getAttribute("nonce")!=t&&this.styleTag.setAttribute("nonce",t)}}for(var Xt={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:"'"},Yt={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Qt="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),Zt="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),te=0;te<10;te++)Xt[48+te]=Xt[96+te]=String(te);for(te=1;te<=24;te++)Xt[te+111]="F"+te;for(te=65;te<=90;te++)Xt[te]=String.fromCharCode(te+32),Yt[te]=String.fromCharCode(te);for(var ee in Xt)Yt.hasOwnProperty(ee)||(Yt[ee]=Xt[ee]);function ie(t){let e;return e=11==t.nodeType?t.getSelection?t:t.ownerDocument:t,e.getSelection()}function se(t,e){return!!e&&(t==e||t.contains(1!=e.nodeType?e.parentNode:e))}function re(t,e){if(!e.anchorNode)return!1;try{return se(t,e.anchorNode)}catch(t){return!1}}function ne(t){return 3==t.nodeType?be(t,0,t.nodeValue.length).getClientRects():1==t.nodeType?t.getClientRects():[]}function he(t,e,i,s){return!!i&&(ue(t,e,i,s,-1)||ue(t,e,i,s,1))}function le(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e}function oe(t){return 1==t.nodeType&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(t.nodeName)}function ue(t,e,i,s,r){for(;;){if(t==i&&e==s)return!0;if(e==(r<0?0:fe(t))){if("DIV"==t.nodeName)return!1;let i=t.parentNode;if(!i||1!=i.nodeType)return!1;e=le(t)+(r<0?0:1),t=i}else{if(1!=t.nodeType)return!1;if(1==(t=t.childNodes[e+(r<0?-1:0)]).nodeType&&"false"==t.contentEditable)return!1;e=r<0?fe(t):0}}}function fe(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function ae(t,e){let i=e?t.left:t.right;return{left:i,right:i,top:t.top,bottom:t.bottom}}function ce(t){let e=t.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:t.innerWidth,top:0,bottom:t.innerHeight}}function de(t,e){let i=e.width/t.offsetWidth,s=e.height/t.offsetHeight;return(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.width-t.offsetWidth)<1)&&(i=1),(s>.995&&s<1.005||!isFinite(s)||Math.abs(e.height-t.offsetHeight)<1)&&(s=1),{scaleX:i,scaleY:s}}class pe{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?fe(e):0),i,Math.min(t.focusOffset,i?fe(i):0))}set(t,e,i,s){this.anchorNode=t,this.anchorOffset=e,this.focusNode=i,this.focusOffset=s}}let me,ge=null;function we(t){if(t.setActive)return t.setActive();if(ge)return t.focus(ge);let e=[];for(let i=t;i&&(e.push(i,i.scrollTop,i.scrollLeft),i!=i.ownerDocument);i=i.parentNode);if(t.focus(null==ge?{get preventScroll(){return ge={preventScroll:!0},!0}}:void 0),!ge){ge=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}function be(t,e,i=e){let s=me||(me=document.createRange());return s.setEnd(t,i),s.setStart(t,e),s}function ve(t,e,i,s){let r={key:e,code:e,keyCode:i,which:i,cancelable:!0};s&&({altKey:r.altKey,ctrlKey:r.ctrlKey,shiftKey:r.shiftKey,metaKey:r.metaKey}=s);let n=new KeyboardEvent("keydown",r);n.synthetic=!0,t.dispatchEvent(n);let h=new KeyboardEvent("keyup",r);return h.synthetic=!0,t.dispatchEvent(h),n.defaultPrevented||h.defaultPrevented}function ke(t){for(;t.attributes.length;)t.removeAttributeNode(t.attributes[0])}function ye(t){return t.scrollTop>Math.max(1,t.scrollHeight-t.clientHeight-4)}function Me(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s>0)return{node:i,offset:s};if(1==i.nodeType&&s>0){if("false"==i.contentEditable)return null;i=i.childNodes[s-1],s=fe(i)}else{if(!i.parentNode||oe(i))return null;s=le(i),i=i.parentNode}}}function xe(t,e){for(let i=t,s=e;;){if(3==i.nodeType&&s<i.nodeValue.length)return{node:i,offset:s};if(1==i.nodeType&&s<i.childNodes.length){if("false"==i.contentEditable)return null;i=i.childNodes[s],s=0}else{if(!i.parentNode||oe(i))return null;s=le(i)+1,i=i.parentNode}}}class Se{constructor(t,e,i=!0){this.node=t,this.offset=e,this.precise=i}static before(t,e){return new Se(t.parentNode,le(t),e)}static after(t,e){return new Se(t.parentNode,le(t)+1,e)}}const Ae=[];class Ce{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(2&this.flags){let i,s=this.dom,r=null;for(let n of this.children){if(7&n.flags){if(!n.dom&&(i=r?r.nextSibling:s.firstChild)){let t=Ce.get(i);(!t||!t.parent&&t.canReuseDOM(n))&&n.reuseDOM(i)}n.sync(t,e),n.flags&=-8}if(i=r?r.nextSibling:s.firstChild,e&&!e.written&&e.node==s&&i!=n.dom&&(e.written=!0),n.dom.parentNode==s)for(;i&&i!=n.dom;)i=Oe(i);else s.insertBefore(n.dom,i);r=n.dom}for(i=r?r.nextSibling:s.firstChild,i&&e&&e.node==s&&(e.written=!0);i;)i=Oe(i)}else if(1&this.flags)for(let i of this.children)7&i.flags&&(i.sync(t,e),i.flags&=-8)}reuseDOM(t){}localPosFromDOM(t,e){let i;if(t==this.dom)i=this.dom.childNodes[e];else{let s=0==fe(t)?0:0==e?-1:1;for(;;){let e=t.parentNode;if(e==this.dom)break;0==s&&e.firstChild!=e.lastChild&&(s=t==e.firstChild?-1:1),t=e}i=s<0?t:t.nextSibling}if(i==this.dom.firstChild)return 0;for(;i&&!Ce.get(i);)i=i.nextSibling;if(!i)return this.length;for(let t=0,e=0;;t++){let s=this.children[t];if(s.dom==i)return e;e+=s.length+s.breakAfter}}domBoundsAround(t,e,i=0){let s=-1,r=-1,n=-1,h=-1;for(let l=0,o=i,u=i;l<this.children.length;l++){let i=this.children[l],f=o+i.length;if(o<t&&f>e)return i.domBoundsAround(t,e,o);if(f>=t&&-1==s&&(s=l,r=o),o>e&&i.dom.parentNode==this.dom){n=l,h=u;break}u=f,o=f+i.breakAfter}return{from:r,to:h<0?i+this.length:h,startDOM:(s?this.children[s-1].dom.nextSibling:null)||this.dom.firstChild,endDOM:n<this.children.length&&n>=0?this.children[n].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),1&e.flags)return;e.flags|=1,t=!1}}setParent(t){this.parent!=t&&(this.parent=t,7&this.flags&&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=Ae){this.markDirty();for(let s=t;s<e;s++){let t=this.children[s];t.parent==this&&i.indexOf(t)<0&&t.destroy()}this.children.splice(t,e-t,...i);for(let t=0;t<i.length;t++)i[t].setParent(this)}ignoreMutation(t){return!1}ignoreEvent(t){return!1}childCursor(t=this.length){return new De(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?"["+("Text"==t?this.text:this.length)+"]":"")+(this.breakAfter?"#":"")}static get(t){return t.cmView}get isEditable(){return!0}get isWidget(){return!1}get isHidden(){return!1}merge(t,e,i,s,r,n){return!1}become(t){return!1}canReuseDOM(t){return t.constructor==this.constructor&&!(8&(this.flags|t.flags))}getSide(){return 0}destroy(){for(let t of this.children)t.parent==this&&t.destroy();this.parent=null}}function Oe(t){let e=t.nextSibling;return t.parentNode.removeChild(t),e}Ce.prototype.breakAfter=0;class De{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||0==this.i||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 Ee(t,e,i,s,r,n,h,l,o){let{children:u}=t,f=u.length?u[e]:null,a=n.length?n[n.length-1]:null,c=a?a.breakAfter:h;if(!(e==s&&f&&!h&&!c&&n.length<2&&f.merge(i,r,n.length?a:null,0==i,l,o))){if(s<u.length){let t=u[s];t&&(r<t.length||t.breakAfter&&(null==a?void 0:a.breakAfter))?(e==s&&(t=t.split(r),r=0),!c&&a&&t.merge(0,r,a,!0,0,o)?n[n.length-1]=t:((r||t.children.length&&!t.children[0].length)&&t.merge(0,r,null,!1,0,o),n.push(t))):(null==t?void 0:t.breakAfter)&&(a?a.breakAfter=1:h=1),s++}for(f&&(f.breakAfter=h,i>0&&(!h&&n.length&&f.merge(i,f.length,n[0],!1,l,0)?f.breakAfter=n.shift().breakAfter:(i<f.length||f.children.length&&0==f.children[f.children.length-1].length)&&f.merge(i,f.length,null,!1,l,0),e++));e<s&&n.length;)if(u[s-1].become(n[n.length-1]))s--,n.pop(),o=n.length?0:l;else{if(!u[e].become(n[0]))break;e++,n.shift(),l=n.length?0:o}!n.length&&e&&s<u.length&&!u[e-1].breakAfter&&u[s].merge(0,0,u[e-1],!1,l,o)&&e--,(e<s||n.length)&&t.replaceChildren(e,s,n)}}function Ie(t,e,i,s,r,n){let h=t.childCursor(),{i:l,off:o}=h.findPos(i,1),{i:u,off:f}=h.findPos(e,-1),a=e-i;for(let t of s)a+=t.length;t.length+=a,Ee(t,u,f,l,o,s,0,r,n)}let Re="undefined"!=typeof navigator?navigator:{userAgent:"",vendor:"",platform:""},Te="undefined"!=typeof document?document:{documentElement:{style:{}}};const Be=/Edge\/(\d+)/.exec(Re.userAgent),Le=/MSIE \d/.test(Re.userAgent),Ne=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Re.userAgent),je=!!(Le||Ne||Be),$e=!je&&/gecko\/(\d+)/i.test(Re.userAgent),ze=!je&&/Chrome\/(\d+)/.exec(Re.userAgent),Pe="webkitFontSmoothing"in Te.documentElement.style,He=!je&&/Apple Computer/.test(Re.vendor),We=He&&(/Mobile\/\w+/.test(Re.userAgent)||Re.maxTouchPoints>2);var Ve={mac:We||/Mac/.test(Re.platform),windows:/Win/.test(Re.platform),linux:/Linux|X11/.test(Re.platform),ie:je,ie_version:Le?Te.documentMode||6:Ne?+Ne[1]:Be?+Be[1]:0,gecko:$e,gecko_version:$e?+(/Firefox\/(\d+)/.exec(Re.userAgent)||[0,0])[1]:0,chrome:!!ze,chrome_version:ze?+ze[1]:0,ios:We,android:/Android\b/.test(Re.userAgent),webkit:Pe,safari:He,webkit_version:Pe?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0,tabSize:null!=Te.documentElement.style.tabSize?"tab-size":"-moz-tab-size"};class Fe extends Ce{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){3==t.nodeType&&this.createDOM(t)}merge(t,e,i){return!(8&this.flags||i&&(!(i instanceof Fe)||this.length-(e-t)+i.length>256||8&i.flags))&&(this.text=this.text.slice(0,t)+(i?i.text:"")+this.text.slice(e),this.markDirty(),!0)}split(t){let e=new Fe(this.text.slice(t));return this.text=this.text.slice(0,t),this.markDirty(),e.flags|=8&this.flags,e}localPosFromDOM(t,e){return t==this.dom?e:e?this.text.length:0}domAtPos(t){return new Se(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 function(t,e,i){let s=t.nodeValue.length;e>s&&(e=s);let r=e,n=e,h=0;0==e&&i<0||e==s&&i>=0?Ve.chrome||Ve.gecko||(e?(r--,h=1):n<s&&(n++,h=-1)):i<0?r--:n<s&&n++;let l=be(t,r,n).getClientRects();if(!l.length)return null;let o=l[(h?h<0:i>=0)?0:l.length-1];Ve.safari&&!h&&0==o.width&&(o=Array.prototype.find.call(l,(t=>t.width))||o);return h?ae(o,h<0):o||null}(this.dom,t,e)}}class qe extends Ce{constructor(t,e=[],i=0){super(),this.mark=t,this.children=e,this.length=i;for(let t of e)t.setParent(this)}setAttrs(t){if(ke(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)&&!(8&(this.flags|t.flags))}reuseDOM(t){t.nodeName==this.mark.tagName.toUpperCase()&&(this.setDOM(t),this.flags|=6)}sync(t,e){this.dom?4&this.flags&&this.setAttrs(this.dom):this.setDOM(this.setAttrs(document.createElement(this.mark.tagName))),super.sync(t,e)}merge(t,e,i,s,r,n){return(!i||!(!(i instanceof qe&&i.mark.eq(this.mark))||t&&r<=0||e<this.length&&n<=0))&&(Ie(this,t,e,i?i.children.slice():[],r-1,n-1),this.markDirty(),!0)}split(t){let e=[],i=0,s=-1,r=0;for(let n of this.children){let h=i+n.length;h>t&&e.push(i<t?n.split(t-i):n),s<0&&i>=t&&(s=r),i=h,r++}let n=this.length-t;return this.length=t,s>-1&&(this.children.length=s,this.markDirty()),new qe(this.mark,e,n)}domAtPos(t){return Ge(this,t)}coordsAt(t,e){return _e(this,t,e)}}class Ue extends Ce{static create(t,e,i){return new Ue(t,e,i)}constructor(t,e,i){super(),this.widget=t,this.length=e,this.side=i,this.prevWidget=null}split(t){let e=Ue.create(this.widget,this.length-t,this.side);return this.length-=t,e}sync(t){this.dom&&this.widget.updateDOM(this.dom,t)||(this.dom&&this.prevWidget&&this.prevWidget.destroy(this.dom),this.prevWidget=null,this.setDOM(this.widget.toDOM(t)),this.widget.editable||(this.dom.contentEditable="false"))}getSide(){return this.side}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof Ue&&this.widget.compare(i.widget))||t>0&&r<=0||e<this.length&&n<=0))&&(this.length=t+(i?i.length:0)+(this.length-e),!0)}become(t){return t instanceof Ue&&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)}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get overrideDOMText(){if(0==this.length)return t.empty;let e=this;for(;e.parent;)e=e.parent;let{view:i}=e,s=i&&i.state.doc,r=this.posAtStart;return s?s.slice(r,r+this.length):t.empty}domAtPos(t){return(this.length?0==t:this.side>0)?Se.before(this.dom):Se.after(this.dom,t==this.length)}domBoundsAround(){return null}coordsAt(t,e){let i=this.widget.coordsAt(this.dom,t,e);if(i)return i;let s=this.dom.getClientRects(),r=null;if(!s.length)return null;let n=this.side?this.side<0:t>0;for(let e=n?s.length-1:0;r=s[e],!(t>0?0==e:e==s.length-1||r.top<r.bottom);e+=n?-1:1);return ae(r,!n)}get isEditable(){return!1}get isWidget(){return!0}get isHidden(){return this.widget.isHidden}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}}class Je extends Ce{constructor(t){super(),this.side=t}get length(){return 0}merge(){return!1}become(t){return t instanceof Je&&t.side==this.side}split(){return new Je(this.side)}sync(){if(!this.dom){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),this.setDOM(t)}}getSide(){return this.side}domAtPos(t){return this.side>0?Se.before(this.dom):Se.after(this.dom)}localPosFromDOM(){return 0}domBoundsAround(){return null}coordsAt(t){return this.dom.getBoundingClientRect()}get overrideDOMText(){return t.empty}get isHidden(){return!0}}function Ge(t,e){let i=t.dom,{children:s}=t,r=0;for(let t=0;r<s.length;r++){let n=s[r],h=t+n.length;if(!(h==t&&n.getSide()<=0)){if(e>t&&e<h&&n.dom.parentNode==i)return n.domAtPos(e-t);if(e<=t)break;t=h}}for(let t=r;t>0;t--){let e=s[t-1];if(e.dom.parentNode==i)return e.domAtPos(e.length)}for(let t=r;t<s.length;t++){let e=s[t];if(e.dom.parentNode==i)return e.domAtPos(0)}return new Se(i,0)}function Ke(t,e,i){let s,{children:r}=t;i>0&&e instanceof qe&&r.length&&(s=r[r.length-1])instanceof qe&&s.mark.eq(e.mark)?Ke(s,e.children[0],i-1):(r.push(e),e.setParent(t)),t.length+=e.length}function _e(t,e,i){let s=null,r=-1,n=null,h=-1;!function t(e,l){for(let o=0,u=0;o<e.children.length&&u<=l;o++){let f=e.children[o],a=u+f.length;a>=l&&(f.children.length?t(f,l-u):(!n||n.isHidden&&i>0)&&(a>l||u==a&&f.getSide()>0)?(n=f,h=l-u):(u<l||u==a&&f.getSide()<0&&!f.isHidden)&&(s=f,r=l-u)),u=a}}(t,e);let l=(i<0?s:n)||s||n;return l?l.coordsAt(Math.max(0,l==s?r:h),i):function(t){let e=t.dom.lastChild;if(!e)return t.dom.getBoundingClientRect();let i=ne(e);return i[i.length-1]||null}(t)}function Xe(t,e){for(let i in t)"class"==i&&e.class?e.class+=" "+t.class:"style"==i&&e.style?e.style+=";"+t.style:e[i]=t[i];return e}Fe.prototype.children=Ue.prototype.children=Je.prototype.children=Ae;const Ye=Object.create(null);function Qe(t,e,i){if(t==e)return!0;t||(t=Ye),e||(e=Ye);let s=Object.keys(t),r=Object.keys(e);if(s.length-(i&&s.indexOf(i)>-1?1:0)!=r.length-(i&&r.indexOf(i)>-1?1:0))return!1;for(let n of s)if(n!=i&&(-1==r.indexOf(n)||t[n]!==e[n]))return!1;return!0}function Ze(t,e,i){let s=!1;if(e)for(let r in e)i&&r in i||(s=!0,"style"==r?t.style.cssText="":t.removeAttribute(r));if(i)for(let r in i)e&&e[r]==i[r]||(s=!0,"style"==r?t.style.cssText=i[r]:t.setAttribute(r,i[r]));return s}function ti(t){let e=Object.create(null);for(let i=0;i<t.attributes.length;i++){let s=t.attributes[i];e[s.name]=s.value}return e}class ei extends Ce{constructor(){super(...arguments),this.children=[],this.length=0,this.prevAttrs=void 0,this.attrs=null,this.breakAfter=0}merge(t,e,i,s,r,n){if(i){if(!(i instanceof ei))return!1;this.dom||i.transferDOM(this)}return s&&this.setDeco(i?i.attrs:null),Ie(this,t,e,i?i.children.slice():[],r,n),!0}split(t){let e=new ei;if(e.breakAfter=this.breakAfter,0==this.length)return e;let{i,off:s}=this.childPos(t);s&&(e.append(this.children[i].split(s),0),this.children[i].merge(s,this.children[i].length,null,!1,0,0),i++);for(let t=i;t<this.children.length;t++)e.append(this.children[t],0);for(;i>0&&0==this.children[i-1].length;)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=void 0===this.prevAttrs?this.attrs:this.prevAttrs,this.prevAttrs=void 0,this.dom=null)}setDeco(t){Qe(this.attrs,t)||(this.dom&&(this.prevAttrs=this.attrs,this.markDirty()),this.attrs=t)}append(t,e){Ke(this,t,e)}addLineDeco(t){let e=t.spec.attributes,i=t.spec.class;e&&(this.attrs=Xe(e,this.attrs||{})),i&&(this.attrs=Xe({class:i},this.attrs||{}))}domAtPos(t){return Ge(this,t)}reuseDOM(t){"DIV"==t.nodeName&&(this.setDOM(t),this.flags|=6)}sync(t,e){var i;this.dom?4&this.flags&&(ke(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),void 0!==this.prevAttrs&&(Ze(this.dom,this.prevAttrs,this.attrs),this.dom.classList.add("cm-line"),this.prevAttrs=void 0),super.sync(t,e);let s=this.dom.lastChild;for(;s&&Ce.get(s)instanceof qe;)s=s.lastChild;if(!(s&&this.length&&("BR"==s.nodeName||0!=(null===(i=Ce.get(s))||void 0===i?void 0:i.isEditable)||Ve.ios&&this.children.some((t=>t instanceof Fe))))){let t=document.createElement("BR");t.cmIgnore=!0,this.dom.appendChild(t)}}measureTextSize(){if(0==this.children.length||this.length>20)return null;let t,e=0;for(let i of this.children){if(!(i instanceof Fe)||/[^ -~]/.test(i.text))return null;let s=ne(i.dom);if(1!=s.length)return null;e+=s[0].width,t=s[0].height}return e?{lineHeight:this.dom.getBoundingClientRect().height,charWidth:e/this.length,textHeight:t}:null}coordsAt(t,e){let i=_e(this,t,e);if(!this.children.length&&i&&this.parent){let{heightOracle:t}=this.parent.view.viewState,e=i.bottom-i.top;if(Math.abs(e-t.lineHeight)<2&&t.textHeight<e){let s=(e-t.textHeight)/2;return{top:i.top+s,bottom:i.bottom-s,left:i.left,right:i.left}}}return i}become(t){return!1}covers(){return!0}static find(t,e){for(let i=0,s=0;i<t.children.length;i++){let r=t.children[i],n=s+r.length;if(n>=e){if(r instanceof ei)return r;if(n>e)break}s=n+r.breakAfter}return null}}class ii extends Ce{constructor(t,e,i){super(),this.widget=t,this.length=e,this.deco=i,this.breakAfter=0,this.prevWidget=null}merge(t,e,i,s,r,n){return!(i&&(!(i instanceof ii&&this.widget.compare(i.widget))||t>0&&r<=0||e<this.length&&n<=0))&&(this.length=t+(i?i.length:0)+(this.length-e),!0)}domAtPos(t){return 0==t?Se.before(this.dom):Se.after(this.dom,t==this.length)}split(t){let e=this.length-t;this.length=t;let i=new ii(this.widget,e,this.deco);return i.breakAfter=this.breakAfter,i}get children(){return Ae}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):t.empty}domBoundsAround(){return null}become(t){return t instanceof ii&&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)}ignoreMutation(){return!0}ignoreEvent(t){return this.widget.ignoreEvent(t)}get isEditable(){return!1}get isWidget(){return!0}coordsAt(t,e){return this.widget.coordsAt(this.dom,t,e)}destroy(){super.destroy(),this.dom&&this.widget.destroy(this.dom)}covers(t){let{startSide:e,endSide:i}=this.deco;return e!=i&&(t<0?e<0:i>0)}}class si{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 ri=function(t){return t[t.Text=0]="Text",t[t.WidgetBefore=1]="WidgetBefore",t[t.WidgetAfter=2]="WidgetAfter",t[t.WidgetRange=3]="WidgetRange",t}(ri||(ri={}));class ni extends Ct{constructor(t,e,i,s){super(),this.startSide=t,this.endSide=e,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(t){return new hi(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 oi(t,e,e,i,t.widget||null,!1)}static replace(t){let e,i,s=!!t.block;if(t.isBlockGap)e=-5e8,i=4e8;else{let{start:r,end:n}=ui(t,s);e=(r?s?-3e8:-1:5e8)-1,i=1+(n?s?2e8:1:-6e8)}return new oi(t,e,i,s,t.widget||null,!0)}static line(t){return new li(t)}static set(t,e=!1){return It.of(t,e)}hasHeight(){return!!this.widget&&this.widget.estimatedHeight>-1}}ni.none=It.empty;class hi extends ni{constructor(t){let{start:e,end:i}=ui(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 hi&&this.tagName==t.tagName&&(this.class||(null===(e=this.attrs)||void 0===e?void 0:e.class))==(t.class||(null===(i=t.attrs)||void 0===i?void 0:i.class))&&Qe(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)}}hi.prototype.point=!1;class li extends ni{constructor(t){super(-2e8,-2e8,null,t)}eq(t){return t instanceof li&&this.spec.class==t.spec.class&&Qe(this.spec.attributes,t.spec.attributes)}range(t,e=t){if(e!=t)throw new RangeError("Line decoration ranges must be zero-length");return super.range(t,e)}}li.prototype.mapMode=x.TrackBefore,li.prototype.point=!0;class oi extends ni{constructor(t,e,i,s,r,n){super(e,i,r,t),this.block=s,this.isReplace=n,this.mapMode=s?e<=0?x.TrackBefore:x.TrackAfter:x.TrackDel}get type(){return this.startSide!=this.endSide?ri.WidgetRange:this.startSide<=0?ri.WidgetBefore:ri.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof oi&&(e=this.widget,i=t.widget,e==i||!!(e&&i&&e.compare(i)))&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide;var e,i}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)}}function ui(t,e=!1){let{inclusiveStart:i,inclusiveEnd:s}=t;return null==i&&(i=t.inclusive),null==s&&(s=t.inclusive),{start:null!=i?i:e,end:null!=s?s:e}}function fi(t,e,i,s=0){let r=i.length-1;r>=0&&i[r]+s>=t?i[r]=Math.max(i[r],e):i.push(t,e)}oi.prototype.point=!0;class ai{constructor(t,e,i,s){this.doc=t,this.pos=e,this.end=i,this.disallowBlockEffectsFor=s,this.content=[],this.curLine=null,this.breakAtStart=0,this.pendingBuffer=0,this.bufferMarks=[],this.atCursorPos=!0,this.openStart=-1,this.openEnd=-1,this.text="",this.textOff=0,this.cursor=t.iter(),this.skip=e}posCovered(){if(0==this.content.length)return!this.breakAtStart&&this.doc.lineAt(this.pos).from!=this.pos;let t=this.content[this.content.length-1];return!(t.breakAfter||t instanceof ii&&t.deco.endSide<0)}getLine(){return this.curLine||(this.content.push(this.curLine=new ei),this.atCursorPos=!0),this.curLine}flushBuffer(t=this.bufferMarks){this.pendingBuffer&&(this.curLine.append(ci(new Je(-1),t),t.length),this.pendingBuffer=0)}addBlockWidget(t){this.flushBuffer(),this.curLine=null,this.content.push(t)}finish(t){this.pendingBuffer&&t<=this.bufferMarks.length?this.flushBuffer():this.pendingBuffer=0,this.posCovered()||t&&this.content.length&&this.content[this.content.length-1]instanceof ii||this.getLine()}buildText(t,e,i){for(;t>0;){if(this.textOff==this.text.length){let{value:e,lineBreak:i,done:s}=this.cursor.next(this.skip);if(this.skip=0,s)throw new Error("Ran out of text content when drawing inline views");if(i){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}this.text=e,this.textOff=0}let s=Math.min(this.text.length-this.textOff,t,512);this.flushBuffer(e.slice(e.length-i)),this.getLine().append(ci(new Fe(this.text.slice(this.textOff,this.textOff+s)),e),i),this.atCursorPos=!0,this.textOff+=s,t-=s,i=0}}span(t,e,i,s){this.buildText(e-t,i,s),this.pos=e,this.openStart<0&&(this.openStart=s)}point(t,e,i,s,r,n){if(this.disallowBlockEffectsFor[n]&&i instanceof oi){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 h=e-t;if(i instanceof oi)if(i.block)i.startSide>0&&!this.posCovered()&&this.getLine(),this.addBlockWidget(new ii(i.widget||di.block,h,i));else{let n=Ue.create(i.widget||di.inline,h,h?0:i.startSide),l=this.atCursorPos&&!n.isEditable&&r<=s.length&&(t<e||i.startSide>0),o=!n.isEditable&&(t<e||r>s.length||i.startSide<=0),u=this.getLine();2!=this.pendingBuffer||l||n.isEditable||(this.pendingBuffer=0),this.flushBuffer(s),l&&(u.append(ci(new Je(1),s),r),r=s.length+Math.max(0,r-s.length)),u.append(ci(n,s),r),this.atCursorPos=o,this.pendingBuffer=o?t<e||r>s.length?1:2:0,this.pendingBuffer&&(this.bufferMarks=s.slice())}else this.doc.lineAt(this.pos).from==this.pos&&this.getLine().addLineDeco(i);h&&(this.textOff+h<=this.text.length?this.textOff+=h:(this.skip+=h-(this.text.length-this.textOff),this.text="",this.textOff=0),this.pos=e),this.openStart<0&&(this.openStart=r)}static build(t,e,i,s,r){let n=new ai(t,e,i,r);return n.openEnd=It.spans(s,e,i,n),n.openStart<0&&(n.openStart=n.openEnd),n.finish(n.openEnd),n}}function ci(t,e){for(let i of e)t=new qe(i,[t],t.length);return t}class di extends si{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}}di.inline=new di("span"),di.block=new di("div");var pi=function(t){return t[t.LTR=0]="LTR",t[t.RTL=1]="RTL",t}(pi||(pi={}));const mi=pi.LTR,gi=pi.RTL;function wi(t){let e=[];for(let i=0;i<t.length;i++)e.push(1<<+t[i]);return e}const bi=wi("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),vi=wi("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),ki=Object.create(null),yi=[];for(let t of["()","[]","{}"]){let e=t.charCodeAt(0),i=t.charCodeAt(1);ki[e]=i,ki[i]=-e}function Mi(t){return t<=247?bi[t]:1424<=t&&t<=1524?2:1536<=t&&t<=1785?vi[t-1536]:1774<=t&&t<=2220?4:8192<=t&&t<=8204?256:64336<=t&&t<=65023?4:1}const xi=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class Si{get dir(){return this.level%2?gi:mi}constructor(t,e,i){this.from=t,this.to=e,this.level=i}side(t,e){return this.dir==e==t?this.to:this.from}forward(t,e){return t==(this.dir==e)}static find(t,e,i,s){let r=-1;for(let n=0;n<t.length;n++){let h=t[n];if(h.from<=e&&h.to>=e){if(h.level==i)return n;(r<0||(0!=s?s<0?h.from<e:h.to>e:t[r].level>h.level))&&(r=n)}}if(r<0)throw new RangeError("Index out of range");return r}}function Ai(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.direction!=r.direction||!Ai(s.inner,r.inner))return!1}return!0}const Ci=[];function Oi(t,e,i,s,r,n,h){let l=s%2?2:1;if(s%2==r%2)for(let o=e,u=0;o<i;){let e=!0,f=!1;if(u==n.length||o<n[u].from){let t=Ci[o];t!=l&&(e=!1,f=16==t)}let a=e||1!=l?null:[],c=e?s:s+1,d=o;t:for(;;)if(u<n.length&&d==n[u].from){if(f)break t;let p=n[u];if(!e)for(let t=p.to,e=u+1;;){if(t==i)break t;if(!(e<n.length&&n[e].from==t)){if(Ci[t]==l)break t;break}t=n[e++].to}if(u++,a)a.push(p);else{p.from>o&&h.push(new Si(o,p.from,c)),Di(t,p.direction==mi!=!(c%2)?s+1:s,r,p.inner,p.from,p.to,h),o=p.to}d=p.to}else{if(d==i||(e?Ci[d]!=l:Ci[d]==l))break;d++}a?Oi(t,o,d,s+1,r,a,h):o<d&&h.push(new Si(o,d,c)),o=d}else for(let o=i,u=n.length;o>e;){let i=!0,f=!1;if(!u||o>n[u-1].to){let t=Ci[o-1];t!=l&&(i=!1,f=16==t)}let a=i||1!=l?null:[],c=i?s:s+1,d=o;t:for(;;)if(u&&d==n[u-1].to){if(f)break t;let p=n[--u];if(!i)for(let t=p.from,i=u;;){if(t==e)break t;if(!i||n[i-1].to!=t){if(Ci[t-1]==l)break t;break}t=n[--i].from}if(a)a.push(p);else{p.to<o&&h.push(new Si(p.to,o,c)),Di(t,p.direction==mi!=!(c%2)?s+1:s,r,p.inner,p.from,p.to,h),o=p.from}d=p.from}else{if(d==e||(i?Ci[d-1]!=l:Ci[d-1]==l))break;d--}a?Oi(t,d,o,s+1,r,a,h):d<o&&h.push(new Si(d,o,c)),o=d}}function Di(t,e,i,s,r,n,h){let l=e%2?2:1;!function(t,e,i,s,r){for(let n=0;n<=s.length;n++){let h=n?s[n-1].to:e,l=n<s.length?s[n].from:i,o=n?256:r;for(let e=h,i=o,s=o;e<l;e++){let r=Mi(t.charCodeAt(e));512==r?r=i:8==r&&4==s&&(r=16),Ci[e]=4==r?2:r,7&r&&(s=r),i=r}for(let t=h,e=o,s=o;t<l;t++){let r=Ci[t];if(128==r)t<l-1&&e==Ci[t+1]&&24&e?r=Ci[t]=e:Ci[t]=256;else if(64==r){let r=t+1;for(;r<l&&64==Ci[r];)r++;let n=t&&8==e||r<i&&8==Ci[r]?1==s?1:8:256;for(let e=t;e<r;e++)Ci[e]=n;t=r-1}else 8==r&&1==s&&(Ci[t]=1);e=r,7&r&&(s=r)}}}(t,r,n,s,l),function(t,e,i,s,r){let n=1==r?2:1;for(let h=0,l=0,o=0;h<=s.length;h++){let u=h?s[h-1].to:e,f=h<s.length?s[h].from:i;for(let e,i,s,h=u;h<f;h++)if(i=ki[e=t.charCodeAt(h)])if(i<0){for(let t=l-3;t>=0;t-=3)if(yi[t+1]==-i){let e=yi[t+2],i=2&e?r:4&e?1&e?n:r:0;i&&(Ci[h]=Ci[yi[t]]=i),l=t;break}}else{if(189==yi.length)break;yi[l++]=h,yi[l++]=e,yi[l++]=o}else if(2==(s=Ci[h])||1==s){let t=s==r;o=t?0:1;for(let e=l-3;e>=0;e-=3){let i=yi[e+2];if(2&i)break;if(t)yi[e+2]|=2;else{if(4&i)break;yi[e+2]|=4}}}}}(t,r,n,s,l),function(t,e,i,s){for(let r=0,n=s;r<=i.length;r++){let h=r?i[r-1].to:t,l=r<i.length?i[r].from:e;for(let o=h;o<l;){let h=Ci[o];if(256==h){let h=o+1;for(;;)if(h==l){if(r==i.length)break;h=i[r++].to,l=r<i.length?i[r].from:e}else{if(256!=Ci[h])break;h++}let u=1==n,f=u==(1==(h<e?Ci[h]:s))?u?1:2:s;for(let e=h,s=r,n=s?i[s-1].to:t;e>o;)e==n&&(e=i[--s].from,n=s?i[s-1].to:t),Ci[--e]=f;o=h}else n=h,o++}}}(r,n,s,l),Oi(t,r,n,e,i,s,h)}function Ei(t){return[new Si(0,t,0)]}let Ii="";function Ri(t,e,i,s,r){var n;let h=s.head-t.from,l=Si.find(e,h,null!==(n=s.bidiLevel)&&void 0!==n?n:-1,s.assoc),o=e[l],u=o.side(r,i);if(h==u){let t=l+=r?1:-1;if(t<0||t>=e.length)return null;o=e[l=t],h=o.side(!r,i),u=o.side(r,i)}let f=p(t.text,h,o.forward(r,i));(f<o.from||f>o.to)&&(f=u),Ii=t.text.slice(Math.min(h,f),Math.max(h,f));let a=l==(r?e.length-1:0)?null:e[l+(r?1:-1)];return a&&f==u&&a.level+(r?0:1)<o.level?B.cursor(a.side(!r,i)+t.from,a.forward(r,i)?1:-1,a.level):B.cursor(f+t.from,o.forward(r,i)?-1:1,o.level)}function Ti(t,e,i){for(let s=e;s<i;s++){let e=Mi(t.charCodeAt(s));if(1==e)return mi;if(2==e||4==e)return gi}return mi}const Bi=j.define(),Li=j.define(),Ni=j.define(),ji=j.define(),$i=j.define(),zi=j.define(),Pi=j.define(),Hi=j.define({combine:t=>t.some((t=>t))}),Wi=j.define({combine:t=>t.some((t=>t))}),Vi=j.define();class Fi{constructor(t,e="nearest",i="nearest",s=5,r=5,n=!1){this.range=t,this.y=e,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=n}map(t){return t.empty?this:new Fi(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 Fi(B.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const qi=ct.define({map:(t,e)=>t.map(e)});function Ui(t,e,i){let s=t.facet(ji);s.length?s[0](e):window.onerror?window.onerror(String(e),i,void 0,void 0,e):i?console.error(i+":",e):console.error(e)}const Ji=j.define({combine:t=>!t.length||t[0]});let Gi=0;const Ki=j.define();class _i{constructor(t,e,i,s,r){this.id=t,this.create=e,this.domEventHandlers=i,this.domEventObservers=s,this.extension=r(this)}static define(t,e){const{eventHandlers:i,eventObservers:s,provide:r,decorations:n}=e||{};return new _i(Gi++,t,i,s,(t=>{let e=[Ki.of(t)];return n&&e.push(Zi.of((e=>{let i=e.plugin(t);return i?n(i):ni.none}))),r&&e.push(r(t)),e}))}static fromClass(t,e){return _i.define((e=>new t(e)),e)}}class Xi{constructor(t){this.spec=t,this.mustUpdate=null,this.value=null}update(t){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(e){if(Ui(t.state,e,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch(t){}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.create(t)}catch(e){Ui(t.state,e,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(t){var e;if(null===(e=this.value)||void 0===e?void 0:e.destroy)try{this.value.destroy()}catch(e){Ui(t.state,e,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Yi=j.define(),Qi=j.define(),Zi=j.define(),ts=j.define(),es=j.define(),is=j.define();function ss(t,e){let i=t.state.facet(is);if(!i.length)return i;let s=i.map((e=>e instanceof Function?e(t):e)),r=[];return It.spans(s,e.from,e.to,{point(){},span(t,i,s,n){let h=t-e.from,l=i-e.from,o=r;for(let t=s.length-1;t>=0;t--,n--){let i,r=s[t].spec.bidiIsolate;if(null==r&&(r=Ti(e.text,h,l)),n>0&&o.length&&(i=o[o.length-1]).to==h&&i.direction==r)i.to=l,o=i.inner;else{let t={from:h,to:l,direction:r,inner:[]};o.push(t),o=t.inner}}}}),r}const rs=j.define();function ns(t){let e=0,i=0,s=0,r=0;for(let n of t.state.facet(rs)){let h=n(t);h&&(null!=h.left&&(e=Math.max(e,h.left)),null!=h.right&&(i=Math.max(i,h.right)),null!=h.top&&(s=Math.max(s,h.top)),null!=h.bottom&&(r=Math.max(r,h.bottom)))}return{left:e,right:i,top:s,bottom:r}}const hs=j.define();class ls{constructor(t,e,i,s){this.fromA=t,this.toA=e,this.fromB=i,this.toB=s}join(t){return new ls(Math.min(this.fromA,t.fromA),Math.max(this.toA,t.toA),Math.min(this.fromB,t.fromB),Math.max(this.toB,t.toB))}addToSet(t){let e=t.length,i=this;for(;e>0;e--){let s=t[e-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),t.splice(e-1,1)}}return t.splice(e,0,i),t}static extendWithRanges(t,e){if(0==e.length)return t;let i=[];for(let s=0,r=0,n=0,h=0;;s++){let l=s==t.length?null:t[s],o=n-h,u=l?l.fromB:1e9;for(;r<e.length&&e[r]<u;){let t=e[r],s=e[r+1],n=Math.max(h,t),l=Math.min(u,s);if(n<=l&&new ls(n+o,l+o,n,l).addToSet(i),s>u)break;r+=2}if(!l)return i;new ls(l.fromA,l.toA,l.fromB,l.toB).addToSet(i),n=l.toA,h=l.toB}}}class os{constructor(t,e,i){this.view=t,this.state=e,this.transactions=i,this.flags=0,this.startState=t.state,this.changes=A.empty(this.startState.doc.length);for(let t of i)this.changes=this.changes.compose(t.changes);let s=[];this.changes.iterChangedRanges(((t,e,i,r)=>s.push(new ls(t,e,i,r)))),this.changedRanges=s}static create(t,e,i){return new os(t,e,i)}get viewportChanged(){return(4&this.flags)>0}get heightChanged(){return(2&this.flags)>0}get geometryChanged(){return this.docChanged||(10&this.flags)>0}get focusChanged(){return(1&this.flags)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some((t=>t.selection))}get empty(){return 0==this.flags&&0==this.transactions.length}}class us extends Ce{get length(){return this.view.state.doc.length}constructor(t){super(),this.view=t,this.decorations=[],this.dynamicDecorationMap=[],this.domChanged=null,this.hasComposition=null,this.markedForComposition=new Set,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 ei],this.children[0].setParent(this),this.updateDeco(),this.updateInner([new ls(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:t,toA:e})=>e<this.minWidthFrom||t>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);let s=-1;this.view.inputState.composing>=0&&((null===(e=this.domChanged)||void 0===e?void 0:e.newSel)?s=this.domChanged.newSel.head:function(t,e){let i=!1;e&&t.iterChangedRanges(((t,s)=>{t<e.to&&s>e.from&&(i=!0)}));return i}(t.changes,this.hasComposition)||t.selectionSet||(s=t.state.selection.main.head));let r=s>-1?function(t,e,i){let s=as(t,i);if(!s)return null;let{node:r,from:n,to:h}=s,l=r.nodeValue;if(/[\n\r]/.test(l))return null;if(t.state.doc.sliceString(s.from,s.to)!=l)return null;let o=e.invertedDesc,u=new ls(o.mapPos(n),o.mapPos(h),n,h),f=[];for(let e=r.parentNode;;e=e.parentNode){let i=Ce.get(e);if(i instanceof qe)f.push({node:e,deco:i.mark});else{if(i instanceof ei||"DIV"==e.nodeName&&e.parentNode==t.contentDOM)return{range:u,text:r,marks:f,line:e};if(e==t.contentDOM)return null;f.push({node:e,deco:new hi({inclusive:!0,attributes:ti(e),tagName:e.tagName.toLowerCase()})})}}}(this.view,t.changes,s):null;if(this.domChanged=null,this.hasComposition){this.markedForComposition.clear();let{from:e,to:s}=this.hasComposition;i=new ls(e,s,t.changes.mapPos(e,-1),t.changes.mapPos(s,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(Ve.ie||Ve.chrome)&&!r&&t&&t.state.doc.lines!=t.startState.doc.lines&&(this.forceSelection=!0);let n=function(t,e,i){let s=new cs;return It.compare(t,e,i,s),s.changes}(this.decorations,this.updateDeco(),t.changes);return i=ls.extendWithRanges(i,n),!!(7&this.flags||0!=i.length)&&(this.updateInner(i,t.startState.doc.length,r),t.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(t,e,i){this.view.viewState.mustMeasureContent=!0,this.updateChildren(t,e,i);let{observer:s}=this.view;s.ignore((()=>{this.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let t=Ve.chrome||Ve.ios?{node:s.selectionRange.focusNode,written:!1}:void 0;this.sync(this.view,t),this.flags&=-8,t&&(t.written||s.selectionRange.focusNode!=t.node)&&(this.forceSelection=!0),this.dom.style.height=""})),this.markedForComposition.forEach((t=>t.flags&=-9));let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let t of this.children)t instanceof ii&&t.widget instanceof fs&&r.push(t.dom);s.updateGaps(r)}updateChildren(t,e,i){let s=i?i.range.addToSet(t.slice()):t,r=this.childCursor(e);for(let t=s.length-1;;t--){let e=t>=0?s[t]:null;if(!e)break;let n,h,l,o,{fromA:u,toA:f,fromB:a,toB:c}=e;if(i&&i.range.fromB<c&&i.range.toB>a){let t=ai.build(this.view.state.doc,a,i.range.fromB,this.decorations,this.dynamicDecorationMap),e=ai.build(this.view.state.doc,i.range.toB,c,this.decorations,this.dynamicDecorationMap);h=t.breakAtStart,l=t.openStart,o=e.openEnd;let s=this.compositionView(i);e.breakAtStart?s.breakAfter=1:e.content.length&&s.merge(s.length,s.length,e.content[0],!1,e.openStart,0)&&(s.breakAfter=e.content[0].breakAfter,e.content.shift()),t.content.length&&s.merge(0,0,t.content[t.content.length-1],!0,0,t.openEnd)&&t.content.pop(),n=t.content.concat(s).concat(e.content)}else({content:n,breakAtStart:h,openStart:l,openEnd:o}=ai.build(this.view.state.doc,a,c,this.decorations,this.dynamicDecorationMap));let{i:d,off:p}=r.findPos(f,1),{i:m,off:g}=r.findPos(u,-1);Ee(this,m,g,d,p,n,h,l,o)}i&&this.fixCompositionDOM(i)}compositionView(t){let e=new Fe(t.text.nodeValue);e.flags|=8;for(let{deco:i}of t.marks)e=new qe(i,[e],e.length);let i=new ei;return i.append(e,0),i}fixCompositionDOM(t){let e=(t,e)=>{e.flags|=8|(e.children.some((t=>7&t.flags))?1:0),this.markedForComposition.add(e);let i=Ce.get(t);i&&i!=e&&(i.dom=null),e.setDOM(t)},i=this.childPos(t.range.fromB,1),s=this.children[i.i];e(t.line,s);for(let r=t.marks.length-1;r>=-1;r--)i=s.childPos(i.off,1),s=s.children[i.i],e(r>=0?t.marks[r].node:t.text,s)}updateSelection(t=!1,e=!1){!t&&this.view.observer.selectionRange.focusNode||this.view.observer.readSelectionRange();let i=this.view.root.activeElement,s=i==this.dom,r=!s&&re(this.dom,this.view.observer.selectionRange)&&!(i&&this.dom.contains(i));if(!(s||e||r))return;let n=this.forceSelection;this.forceSelection=!1;let h=this.view.state.selection.main,l=this.moveToLine(this.domAtPos(h.anchor)),o=h.empty?l:this.moveToLine(this.domAtPos(h.head));if(Ve.gecko&&h.empty&&!this.hasComposition&&(1==(u=l).node.nodeType&&u.node.firstChild&&(0==u.offset||"false"==u.node.childNodes[u.offset-1].contentEditable)&&(u.offset==u.node.childNodes.length||"false"==u.node.childNodes[u.offset].contentEditable))){let t=document.createTextNode("");this.view.observer.ignore((()=>l.node.insertBefore(t,l.node.childNodes[l.offset]||null))),l=o=new Se(t,0),n=!0}var u;let f=this.view.observer.selectionRange;!n&&f.focusNode&&(he(l.node,l.offset,f.anchorNode,f.anchorOffset)&&he(o.node,o.offset,f.focusNode,f.focusOffset)||this.suppressWidgetCursorChange(f,h))||(this.view.observer.ignore((()=>{Ve.android&&Ve.chrome&&this.dom.contains(f.focusNode)&&function(t,e){for(let i=t;i&&i!=e;i=i.assignedSlot||i.parentNode)if(1==i.nodeType&&"false"==i.contentEditable)return!0;return!1}(f.focusNode,this.dom)&&(this.dom.blur(),this.dom.focus({preventScroll:!0}));let t=ie(this.view.root);if(t)if(h.empty){if(Ve.gecko){let t=(e=l.node,s=l.offset,1!=e.nodeType?0:(s&&"false"==e.childNodes[s-1].contentEditable?1:0)|(s<e.childNodes.length&&"false"==e.childNodes[s].contentEditable?2:0));if(t&&3!=t){let e=(1==t?Me:xe)(l.node,l.offset);e&&(l=new Se(e.node,e.offset))}}t.collapse(l.node,l.offset),null!=h.bidiLevel&&void 0!==t.caretBidiLevel&&(t.caretBidiLevel=h.bidiLevel)}else if(t.extend){t.collapse(l.node,l.offset);try{t.extend(o.node,o.offset)}catch(t){}}else{let e=document.createRange();h.anchor>h.head&&([l,o]=[o,l]),e.setEnd(o.node,o.offset),e.setStart(l.node,l.offset),t.removeAllRanges(),t.addRange(e)}else;var e,s;r&&this.view.root.activeElement==this.dom&&(this.dom.blur(),i&&i.focus())})),this.view.observer.setSelectionRange(l,o)),this.impreciseAnchor=l.precise?null:new Se(f.anchorNode,f.anchorOffset),this.impreciseHead=o.precise?null:new Se(f.focusNode,f.focusOffset)}suppressWidgetCursorChange(t,e){return this.hasComposition&&e.empty&&he(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=ie(t.root),{anchorNode:s,anchorOffset:r}=t.observer.selectionRange;if(!(i&&e.empty&&e.assoc&&i.modify))return;let n=ei.find(this,e.head);if(!n)return;let h=n.posAtStart;if(e.head==h||e.head==h+n.length)return;let l=this.coordsAt(e.head,-1),o=this.coordsAt(e.head,1);if(!l||!o||l.bottom>o.top)return;let u=this.domAtPos(e.head+e.assoc);i.collapse(u.node,u.offset),i.modify("move",e.assoc<0?"forward":"backward","lineboundary"),t.observer.readSelectionRange();let f=t.observer.selectionRange;t.docView.posFromDOM(f.anchorNode,f.anchorOffset)!=e.from&&i.collapse(s,r)}moveToLine(t){let e,i=this.dom;if(t.node!=i)return t;for(let s=t.offset;!e&&s<i.childNodes.length;s++){let t=Ce.get(i.childNodes[s]);t instanceof ei&&(e=t.domAtPos(0))}for(let s=t.offset-1;!e&&s>=0;s--){let t=Ce.get(i.childNodes[s]);t instanceof ei&&(e=t.domAtPos(t.length))}return e?new Se(e.node,e.offset,!0):t}nearest(t){for(let e=t;e;){let t=Ce.get(e);if(t&&t.rootView==this)return t;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 t=this.children[e];if(i<t.length||t instanceof ei)break;e++,i=0}return this.children[e].domAtPos(i)}coordsAt(t,e){let i=null,s=0;for(let r=this.length,n=this.children.length-1;n>=0;n--){let h=this.children[n],l=r-h.breakAfter,o=l-h.length;if(l<t)break;o<=t&&(o<t||h.covers(-1))&&(l>t||h.covers(1))&&(!i||h instanceof ei&&!(i instanceof ei&&e>=0))&&(i=h,s=o),r=o}return i?i.coordsAt(t-s,e):null}coordsForChar(t){let{i:e,off:i}=this.childPos(t,1),s=this.children[e];if(!(s instanceof ei))return null;for(;s.children.length;){let{i:t,off:e}=s.childPos(i,1);for(;;t++){if(t==s.children.length)return null;if((s=s.children[t]).length)break}i=e}if(!(s instanceof Fe))return null;let r=p(s.text,i);if(r==i)return null;let n=be(s.dom,i,r).getClientRects();for(let t=0;t<n.length;t++){let e=n[t];if(t==n.length-1||e.top<e.bottom&&e.left<e.right)return e}return null}measureVisibleLineHeights(t){let e=[],{from:i,to:s}=t,r=this.view.contentDOM.clientWidth,n=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,h=-1,l=this.view.textDirection==pi.LTR;for(let t=0,o=0;o<this.children.length;o++){let u=this.children[o],f=t+u.length;if(f>s)break;if(t>=i){let i=u.dom.getBoundingClientRect();if(e.push(i.height),n){let e=u.dom.lastChild,s=e?ne(e):[];if(s.length){let e=s[s.length-1],n=l?e.right-i.left:i.right-e.left;n>h&&(h=n,this.minWidth=r,this.minWidthFrom=t,this.minWidthTo=f)}}}t=f+u.breakAfter}return e}textDirectionAt(t){let{i:e}=this.childPos(t,1);return"rtl"==getComputedStyle(this.children[e].dom).direction?pi.RTL:pi.LTR}measureTextSize(){for(let t of this.children)if(t instanceof ei){let e=t.measureTextSize();if(e)return e}let t,e,i,s=document.createElement("div");return s.className="cm-line",s.style.width="99999px",s.style.position="absolute",s.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore((()=>{this.dom.appendChild(s);let r=ne(s.firstChild)[0];t=s.getBoundingClientRect().height,e=r?r.width/27:7,i=r?r.height:t,s.remove()})),{lineHeight:t,charWidth:e,textHeight:i}}childCursor(t=this.length){let e=this.children.length;return e&&(t-=this.children[--e].length),new De(this.children,t,e)}computeBlockGapDeco(){let t=[],e=this.view.viewState;for(let i=0,s=0;;s++){let r=s==e.viewports.length?null:e.viewports[s],n=r?r.from-1:this.length;if(n>i){let s=(e.lineBlockAt(n).bottom-e.lineBlockAt(i).top)/this.view.scaleY;t.push(ni.replace({widget:new fs(s),block:!0,inclusive:!0,isBlockGap:!0}).range(i,n))}if(!r)break;i=r.to+1}return ni.set(t)}updateDeco(){let t=0,e=this.view.state.facet(Zi).map((e=>(this.dynamicDecorationMap[t++]="function"==typeof e)?e(this.view):e)),i=!1,s=this.view.state.facet(ts).map(((t,e)=>{let s="function"==typeof t;return s&&(i=!0),s?t(this.view):t}));for(s.length&&(this.dynamicDecorationMap[t++]=i,e.push(It.join(s))),this.decorations=[...e,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];t<this.decorations.length;)this.dynamicDecorationMap[t++]=!1;return this.decorations}scrollIntoView(t){if(t.isSnapshot){let e=this.view.viewState.lineBlockAt(t.range.head);return this.view.scrollDOM.scrollTop=e.top-t.yMargin,void(this.view.scrollDOM.scrollLeft=t.xMargin)}for(let e of this.view.state.facet(Vi))try{if(e(this.view,t.range,t))return!0}catch(t){Ui(this.view.state,t,"scroll handler")}let e,{range:i}=t,s=this.coordsAt(i.head,i.empty?i.assoc:i.head>i.anchor?-1:1);if(!s)return;!i.empty&&(e=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,e.left),top:Math.min(s.top,e.top),right:Math.max(s.right,e.right),bottom:Math.max(s.bottom,e.bottom)});let r=ns(this.view),n={left:s.left-r.left,top:s.top-r.top,right:s.right+r.right,bottom:s.bottom+r.bottom},{offsetWidth:h,offsetHeight:l}=this.view.scrollDOM;!function(t,e,i,s,r,n,h,l){let o=t.ownerDocument,u=o.defaultView||window;for(let f=t,a=!1;f&&!a;)if(1==f.nodeType){let t,c=f==o.body,d=1,p=1;if(c)t=ce(u);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(a=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let e=f.getBoundingClientRect();({scaleX:d,scaleY:p}=de(f,e)),t={left:e.left,right:e.left+f.clientWidth*d,top:e.top,bottom:e.top+f.clientHeight*p}}let m=0,g=0;if("nearest"==r)e.top<t.top?(g=-(t.top-e.top+h),i>0&&e.bottom>t.bottom+g&&(g=e.bottom-t.bottom+g+h)):e.bottom>t.bottom&&(g=e.bottom-t.bottom+h,i<0&&e.top-g<t.top&&(g=-(t.top+g-e.top+h)));else{let s=e.bottom-e.top,n=t.bottom-t.top;g=("center"==r&&s<=n?e.top+s/2-n/2:"start"==r||"center"==r&&i<0?e.top-h:e.bottom-n+h)-t.top}if("nearest"==s?e.left<t.left?(m=-(t.left-e.left+n),i>0&&e.right>t.right+m&&(m=e.right-t.right+m+n)):e.right>t.right&&(m=e.right-t.right+n,i<0&&e.left<t.left+m&&(m=-(t.left+m-e.left+n))):m=("center"==s?e.left+(e.right-e.left)/2-(t.right-t.left)/2:"start"==s==l?e.left-n:e.right-(t.right-t.left)+n)-t.left,m||g)if(c)u.scrollBy(m,g);else{let t=0,i=0;if(g){let t=f.scrollTop;f.scrollTop+=g/p,i=(f.scrollTop-t)*p}if(m){let e=f.scrollLeft;f.scrollLeft+=m/d,t=(f.scrollLeft-e)*d}e={left:e.left-t,top:e.top-i,right:e.right-t,bottom:e.bottom-i},t&&Math.abs(t-m)<1&&(s="nearest"),i&&Math.abs(i-g)<1&&(r="nearest")}if(c)break;f=f.assignedSlot||f.parentNode}else{if(11!=f.nodeType)break;f=f.host}}(this.view.scrollDOM,n,i.head<i.anchor?-1:1,t.x,t.y,Math.max(Math.min(t.xMargin,h),-h),Math.max(Math.min(t.yMargin,l),-l),this.view.textDirection==pi.LTR)}}class fs extends si{constructor(t){super(),this.height=t}toDOM(){let t=document.createElement("div");return t.className="cm-gap",this.updateDOM(t),t}eq(t){return t.height==this.height}updateDOM(t){return t.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function as(t,e){let i=t.observer.selectionRange;if(!i.focusNode)return null;let s=Me(i.focusNode,i.focusOffset),r=xe(i.focusNode,i.focusOffset),n=s||r;if(r&&s&&r.node!=s.node){let e=Ce.get(r.node);if(!e||e instanceof Fe&&e.text!=r.node.nodeValue)n=r;else if(t.docView.lastCompositionAfterCursor){let t=Ce.get(s.node);!t||t instanceof Fe&&t.text!=s.node.nodeValue||(n=r)}}if(t.docView.lastCompositionAfterCursor=n!=s,!n)return null;let h=e-n.offset;return{from:h,to:h+n.node.nodeValue.length,node:n.node}}let cs=class{constructor(){this.changes=[]}compareRange(t,e){fi(t,e,this.changes)}comparePoint(t,e){fi(t,e,this.changes)}};function ds(t,e){return e.left>t?e.left-t:Math.max(0,t-e.right)}function ps(t,e){return e.top>t?e.top-t:Math.max(0,t-e.bottom)}function ms(t,e){return t.top<e.bottom-1&&t.bottom>e.top+1}function gs(t,e){return e<t.top?{top:e,left:t.left,right:t.right,bottom:t.bottom}:t}function ws(t,e){return e>t.bottom?{top:t.top,left:t.left,right:t.right,bottom:e}:t}function bs(t,e,i){let s,r,n,h,l,o,u,f,a=!1;for(let c=t.firstChild;c;c=c.nextSibling){let t=ne(c);for(let d=0;d<t.length;d++){let p=t[d];r&&ms(r,p)&&(p=gs(ws(p,r.bottom),r.top));let m=ds(e,p),g=ps(i,p);if(0==m&&0==g)return 3==c.nodeType?vs(c,e,i):bs(c,e,i);if(!s||h>g||h==g&&n>m){s=c,r=p,n=m,h=g;let l=g?i<p.top?-1:1:m?e<p.left?-1:1:0;a=!l||(l>0?d<t.length-1:d>0)}0==m?i>p.bottom&&(!u||u.bottom<p.bottom)?(l=c,u=p):i<p.top&&(!f||f.top>p.top)&&(o=c,f=p):u&&ms(u,p)?u=ws(u,p.bottom):f&&ms(f,p)&&(f=gs(f,p.top))}}if(u&&u.bottom>=i?(s=l,r=u):f&&f.top<=i&&(s=o,r=f),!s)return{node:t,offset:0};let c=Math.max(r.left,Math.min(r.right,e));return 3==s.nodeType?vs(s,c,i):a&&"false"!=s.contentEditable?bs(s,c,i):{node:t,offset:Array.prototype.indexOf.call(t.childNodes,s)+(e>=(r.left+r.right)/2?1:0)}}function vs(t,e,i){let s=t.nodeValue.length,r=-1,n=1e9,h=0;for(let l=0;l<s;l++){let s=be(t,l,l+1).getClientRects();for(let o=0;o<s.length;o++){let u=s[o];if(u.top==u.bottom)continue;h||(h=e-u.left);let f=(u.top>i?u.top-i:i-u.bottom)-1;if(u.left-1<=e&&u.right+1>=e&&f<n){let i=e>=(u.left+u.right)/2,s=i;if(Ve.chrome||Ve.gecko){be(t,l).getBoundingClientRect().left==u.right&&(s=!i)}if(f<=0)return{node:t,offset:l+(s?1:0)};r=l+(s?1:0),n=f}}}return{node:t,offset:r>-1?r:h>0?t.nodeValue.length:0}}function ks(t,e,i,s=-1){var r,n;let h,l=t.contentDOM.getBoundingClientRect(),o=l.top+t.viewState.paddingTop,{docHeight:u}=t.viewState,{x:f,y:a}=e,c=a-o;if(c<0)return 0;if(c>u)return t.state.doc.length;for(let e=t.viewState.heightOracle.textHeight/2,r=!1;h=t.elementAtHeight(c),h.type!=ri.Text;)for(;c=s>0?h.bottom+e:h.top-e,!(c>=0&&c<=u);){if(r)return i?null:0;r=!0,s=-s}a=o+c;let d=h.from;if(d<t.viewport.from)return 0==t.viewport.from?0:i?null:ys(t,l,h,f,a);if(d>t.viewport.to)return t.viewport.to==t.state.doc.length?t.state.doc.length:i?null:ys(t,l,h,f,a);let p=t.dom.ownerDocument,m=t.root.elementFromPoint?t.root:p,g=m.elementFromPoint(f,a);g&&!t.contentDOM.contains(g)&&(g=null),g||(f=Math.max(l.left+1,Math.min(l.right-1,f)),g=m.elementFromPoint(f,a),g&&!t.contentDOM.contains(g)&&(g=null));let w,b=-1;if(g&&0!=(null===(r=t.docView.nearest(g))||void 0===r?void 0:r.isEditable))if(p.caretPositionFromPoint){let t=p.caretPositionFromPoint(f,a);t&&({offsetNode:w,offset:b}=t)}else if(p.caretRangeFromPoint){let e=p.caretRangeFromPoint(f,a);e&&(({startContainer:w,startOffset:b}=e),(!t.contentDOM.contains(w)||Ve.safari&&function(t,e,i){let s;if(3!=t.nodeType||e!=(s=t.nodeValue.length))return!1;for(let e=t.nextSibling;e;e=e.nextSibling)if(1!=e.nodeType||"BR"!=e.nodeName)return!1;return be(t,s-1,s).getBoundingClientRect().left>i}(w,b,f)||Ve.chrome&&function(t,e,i){if(0!=e)return!1;for(let e=t;;){let t=e.parentNode;if(!t||1!=t.nodeType||t.firstChild!=e)return!1;if(t.classList.contains("cm-line"))break;e=t}let s=1==t.nodeType?t.getBoundingClientRect():be(t,0,Math.max(t.nodeValue.length,1)).getBoundingClientRect();return i-s.left>5}(w,b,f))&&(w=void 0))}if(!w||!t.docView.dom.contains(w)){let e=ei.find(t.docView,d);if(!e)return c>h.top+h.height/2?h.to:h.from;({node:w,offset:b}=bs(e.dom,f,a))}let v=t.docView.nearest(w);if(!v)return null;if(v.isWidget&&1==(null===(n=v.dom)||void 0===n?void 0:n.nodeType)){let t=v.dom.getBoundingClientRect();return e.y<t.top||e.y<=t.bottom&&e.x<=(t.left+t.right)/2?v.posAtStart:v.posAtEnd}return v.localPosFromDOM(w,b)+v.posAtStart}function ys(t,e,i,s,r){let n=Math.round((s-e.left)*t.defaultCharacterWidth);if(t.lineWrapping&&i.height>1.5*t.defaultLineHeight){let e=t.viewState.heightOracle.textHeight;n+=Math.floor((r-i.top-.5*(t.defaultLineHeight-e))/e)*t.viewState.heightOracle.lineLength}let h=t.state.sliceDoc(i.from,i.to);return i.from+Ft(h,n,t.state.tabSize)}function Ms(t,e){let i=t.lineBlockAt(e);if(Array.isArray(i.type))for(let t of i.type)if(t.to>e||t.to==e&&(t.to==i.to||t.type==ri.Text))return t;return i}function xs(t,e,i,s){let r=t.state.doc.lineAt(e.head),n=t.bidiSpans(r),h=t.textDirectionAt(r.from);for(let l=e,o=null;;){let e=Ri(r,n,h,l,i),u=Ii;if(!e){if(r.number==(i?t.state.doc.lines:1))return l;u="\n",r=t.state.doc.line(r.number+(i?1:-1)),n=t.bidiSpans(r),e=t.visualLineSide(r,!i)}if(o){if(!o(u))return l}else{if(!s)return e;o=s(u)}l=e}}function Ss(t,e,i){for(;;){let s=0;for(let r of t)r.between(e-1,e+1,((t,r,n)=>{if(e>t&&e<r){let n=s||i||(e-t<r-e?-1:1);e=n<0?t:r,s=n}}));if(!s)return e}}function As(t,e,i){let s=Ss(t.state.facet(es).map((e=>e(t))),i.from,e.head>i.from?-1:1);return s==i.from?i:B.cursor(s,s<i.from?1:-1)}class Cs{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.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastEscPress=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=t.hasFocus,Ve.safari&&t.contentDOM.addEventListener("input",(()=>null)),Ve.gecko&&function(t){Zs.has(t)||(Zs.add(t),t.addEventListener("copy",(()=>{})),t.addEventListener("cut",(()=>{})))}(t.contentDOM.ownerDocument)}handleEvent(t){(function(t,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let i,s=e.target;s!=t.contentDOM;s=s.parentNode)if(!s||11==s.nodeType||(i=Ce.get(s))&&i.ignoreEvent(e))return!1;return!0})(this.view,t)&&!this.ignoreDuringComposition(t)&&("keydown"==t.type&&this.keydown(t)||this.runHandlers(t.type,t))}runHandlers(t,e){let i=this.handlers[t];if(i){for(let t of i.observers)t(this.view,e);for(let t of i.handlers){if(e.defaultPrevented)break;if(t(this.view,e)){e.preventDefault();break}}}}ensureHandlers(t){let e=Ds(t),i=this.handlers,s=this.view.contentDOM;for(let t in e)if("scroll"!=t){let r=!e[t].handlers.length,n=i[t];n&&r!=!n.handlers.length&&(s.removeEventListener(t,this.handleEvent),n=null),n||s.addEventListener(t,this.handleEvent,{passive:r})}for(let t in i)"scroll"==t||e[t]||s.removeEventListener(t,this.handleEvent);this.handlers=e}keydown(t){if(this.lastKeyCode=t.keyCode,this.lastKeyTime=Date.now(),9==t.keyCode&&Date.now()<this.lastEscPress+2e3)return!0;if(27!=t.keyCode&&Rs.indexOf(t.keyCode)<0&&(this.view.inputState.lastEscPress=0),Ve.android&&Ve.chrome&&!t.synthetic&&(13==t.keyCode||8==t.keyCode))return this.view.observer.delayAndroidKey(t.key,t.keyCode),!0;let e;return!Ve.ios||t.synthetic||t.altKey||t.metaKey||!((e=Es.find((e=>e.keyCode==t.keyCode)))&&!t.ctrlKey||Is.indexOf(t.key)>-1&&t.ctrlKey&&!t.shiftKey)?(229!=t.keyCode&&this.view.observer.forceFlush(),!1):(this.pendingIOSKey=e||t,setTimeout((()=>this.flushIOSKey()),250),!0)}flushIOSKey(t){let e=this.pendingIOSKey;return!!e&&(!("Enter"==e.key&&t&&t.from<t.to&&/^\S+$/.test(t.insert.toString()))&&(this.pendingIOSKey=void 0,ve(this.view.contentDOM,e.key,e.keyCode,e instanceof KeyboardEvent?e:void 0)))}ignoreDuringComposition(t){return!!/^key/.test(t.type)&&(this.composing>0||!!(Ve.safari&&!Ve.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100)&&(this.compositionPendingKey=!1,!0))}startMouseSelection(t){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=t}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 Os(t,e){return(i,s)=>{try{return e.call(t,s,i)}catch(t){Ui(i.state,t)}}}function Ds(t){let e=Object.create(null);function i(t){return e[t]||(e[t]={observers:[],handlers:[]})}for(let e of t){let t=e.spec;if(t&&t.domEventHandlers)for(let s in t.domEventHandlers){let r=t.domEventHandlers[s];r&&i(s).handlers.push(Os(e.value,r))}if(t&&t.domEventObservers)for(let s in t.domEventObservers){let r=t.domEventObservers[s];r&&i(s).observers.push(Os(e.value,r))}}for(let t in Ls)i(t).handlers.push(Ls[t]);for(let t in Ns)i(t).observers.push(Ns[t]);return e}const Es=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],Is="dthko",Rs=[16,17,18,20,91,92,224,225];function Ts(t){return.7*Math.max(0,t)+8}class Bs{constructor(t,e,i,s){this.view=t,this.startEvent=e,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=e,this.scrollParent=function(t){let e=t.ownerDocument;for(let i=t.parentNode;i&&i!=e.body;)if(1==i.nodeType){if(i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)return i;i=i.assignedSlot||i.parentNode}else{if(11!=i.nodeType)break;i=i.host}return null}(t.contentDOM),this.atoms=t.state.facet(es).map((e=>e(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(St.allowMultipleSelections)&&function(t,e){let i=t.state.facet(Bi);return i.length?i[0](e):Ve.mac?e.metaKey:e.ctrlKey}(t,e),this.dragging=!(!function(t,e){let{main:i}=t.state.selection;if(i.empty)return!1;let s=ie(t.root);if(!s||0==s.rangeCount)return!0;let r=s.getRangeAt(0).getClientRects();for(let t=0;t<r.length;t++){let i=r[t];if(i.left<=e.clientX&&i.right>=e.clientX&&i.top<=e.clientY&&i.bottom>=e.clientY)return!0}return!1}(t,e)||1!=Gs(e))&&null}start(t){!1===this.dragging&&this.select(t)}move(t){var e,i,s;if(0==t.buttons)return this.destroy();if(this.dragging||null==this.dragging&&(i=this.startEvent,s=t,Math.max(Math.abs(i.clientX-s.clientX),Math.abs(i.clientY-s.clientY))<10))return;this.select(this.lastEvent=t);let r=0,n=0,h=(null===(e=this.scrollParent)||void 0===e?void 0:e.getBoundingClientRect())||{left:0,top:0,right:this.view.win.innerWidth,bottom:this.view.win.innerHeight},l=ns(this.view);t.clientX-l.left<=h.left+6?r=-Ts(h.left-t.clientX):t.clientX+l.right>=h.right-6&&(r=Ts(t.clientX-h.right)),t.clientY-l.top<=h.top+6?n=-Ts(h.top-t.clientY):t.clientY+l.bottom>=h.bottom-6&&(n=Ts(t.clientY-h.bottom)),this.setScrollSpeed(r,n)}up(t){null==this.dragging&&this.select(this.lastEvent),this.dragging||t.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let t=this.view.contentDOM.ownerDocument;t.removeEventListener("mousemove",this.move),t.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(t,e){this.scrollSpeed={x:t,y:e},t||e?this.scrolling<0&&(this.scrolling=setInterval((()=>this.scroll()),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){this.scrollParent?(this.scrollParent.scrollLeft+=this.scrollSpeed.x,this.scrollParent.scrollTop+=this.scrollSpeed.y):this.view.win.scrollBy(this.scrollSpeed.x,this.scrollSpeed.y),!1===this.dragging&&this.select(this.lastEvent)}skipAtoms(t){let e=null;for(let i=0;i<t.ranges.length;i++){let s=t.ranges[i],r=null;if(s.empty){let t=Ss(this.atoms,s.from,0);t!=s.from&&(r=B.cursor(t,-1))}else{let t=Ss(this.atoms,s.from,-1),e=Ss(this.atoms,s.to,1);t==s.from&&e==s.to||(r=B.range(s.from==s.anchor?t:e,s.from==s.head?t:e))}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,!1===this.dragging)||this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(t){this.style.update(t)&&setTimeout((()=>this.select(this.lastEvent)),20)}}const Ls=Object.create(null),Ns=Object.create(null),js=Ve.ie&&Ve.ie_version<15||Ve.ios&&Ve.webkit_version<604;function $s(t,e){let i,{state:s}=t,r=1,n=s.toText(e),h=n.lines==s.selection.ranges.length;if(null!=_s&&s.selection.ranges.every((t=>t.empty))&&_s==n.toString()){let t=-1;i=s.changeByRange((i=>{let l=s.doc.lineAt(i.from);if(l.from==t)return{range:i};t=l.from;let o=s.toText((h?n.line(r++).text:e)+s.lineBreak);return{changes:{from:l.from,insert:o},range:B.cursor(i.from+o.length)}}))}else i=h?s.changeByRange((t=>{let e=n.line(r++);return{changes:{from:t.from,to:t.to,insert:e.text},range:B.cursor(t.from+e.length)}})):s.replaceSelection(n);t.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}function zs(t,e,i,s){if(1==s)return B.cursor(e,i);if(2==s)return function(t,e,i=1){let s=t.charCategorizer(e),r=t.doc.lineAt(e),n=e-r.from;if(0==r.length)return B.cursor(e);0==n?i=1:n==r.length&&(i=-1);let h=n,l=n;i<0?h=p(r.text,n,!1):l=p(r.text,n);let o=s(r.text.slice(h,l));for(;h>0;){let t=p(r.text,h,!1);if(s(r.text.slice(t,h))!=o)break;h=t}for(;l<r.length;){let t=p(r.text,l);if(s(r.text.slice(l,t))!=o)break;l=t}return B.range(h+r.from,l+r.from)}(t.state,e,i);{let i=ei.find(t.docView,e),s=t.state.doc.lineAt(i?i.posAtEnd:e),r=i?i.posAtStart:s.from,n=i?i.posAtEnd:s.to;return n<t.state.doc.length&&n==s.to&&n++,B.range(r,n)}}Ns.scroll=t=>{t.inputState.lastScrollTop=t.scrollDOM.scrollTop,t.inputState.lastScrollLeft=t.scrollDOM.scrollLeft},Ls.keydown=(t,e)=>(t.inputState.setSelectionOrigin("select"),27==e.keyCode&&(t.inputState.lastEscPress=Date.now()),!1),Ns.touchstart=(t,e)=>{t.inputState.lastTouchTime=Date.now(),t.inputState.setSelectionOrigin("select.pointer")},Ns.touchmove=t=>{t.inputState.setSelectionOrigin("select.pointer")},Ls.mousedown=(t,e)=>{if(t.observer.flush(),t.inputState.lastTouchTime>Date.now()-2e3)return!1;let i=null;for(let s of t.state.facet(Ni))if(i=s(t,e),i)break;if(i||0!=e.button||(i=function(t,e){let i=Vs(t,e),s=Gs(e),r=t.state.selection;return{update(t){t.docChanged&&(i.pos=t.changes.mapPos(i.pos),r=r.map(t.changes))},get(e,n,h){let l,o=Vs(t,e),u=zs(t,o.pos,o.bias,s);if(i.pos!=o.pos&&!n){let e=zs(t,i.pos,i.bias,s),r=Math.min(e.from,u.from),n=Math.max(e.to,u.to);u=r<u.from?B.range(r,n):B.range(n,r)}return n?r.replaceRange(r.main.extend(u.from,u.to)):h&&1==s&&r.ranges.length>1&&(l=function(t,e){for(let i=0;i<t.ranges.length;i++){let{from:s,to:r}=t.ranges[i];if(s<=e&&r>=e)return B.create(t.ranges.slice(0,i).concat(t.ranges.slice(i+1)),t.mainIndex==i?0:t.mainIndex-(t.mainIndex>i?1:0))}return null}(r,o.pos))?l:h?r.addRange(u):B.create([u])}}}(t,e)),i){let s=!t.hasFocus;t.inputState.startMouseSelection(new Bs(t,e,i,s)),s&&t.observer.ignore((()=>we(t.contentDOM)));let r=t.inputState.mouseSelection;if(r)return r.start(e),!1===r.dragging}return!1};let Ps=(t,e)=>t>=e.top&&t<=e.bottom,Hs=(t,e,i)=>Ps(e,i)&&t>=i.left&&t<=i.right;function Ws(t,e,i,s){let r=ei.find(t.docView,e);if(!r)return 1;let n=e-r.posAtStart;if(0==n)return 1;if(n==r.length)return-1;let h=r.coordsAt(n,-1);if(h&&Hs(i,s,h))return-1;let l=r.coordsAt(n,1);return l&&Hs(i,s,l)?1:h&&Ps(s,h)?-1:1}function Vs(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1);return{pos:i,bias:Ws(t,i,e.clientX,e.clientY)}}const Fs=Ve.ie&&Ve.ie_version<=11;let qs=null,Us=0,Js=0;function Gs(t){if(!Fs)return t.detail;let e=qs,i=Js;return qs=t,Js=Date.now(),Us=!e||i>Date.now()-400&&Math.abs(e.clientX-t.clientX)<2&&Math.abs(e.clientY-t.clientY)<2?(Us+1)%3:1}function Ks(t,e,i,s){if(!i)return;let r=t.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:n}=t.inputState,h=s&&n&&function(t,e){let i=t.state.facet(Li);return i.length?i[0](e):Ve.mac?!e.altKey:!e.ctrlKey}(t,e)?{from:n.from,to:n.to}:null,l={from:r,insert:i},o=t.state.changes(h?[h,l]:l);t.focus(),t.dispatch({changes:o,selection:{anchor:o.mapPos(r,-1),head:o.mapPos(r,1)},userEvent:h?"move.drop":"input.drop"}),t.inputState.draggedContent=null}Ls.dragstart=(t,e)=>{let{selection:{main:i}}=t.state;if(e.target.draggable){let s=t.docView.nearest(e.target);if(s&&s.isWidget){let t=s.posAtStart,e=t+s.length;(t>=i.to||e<=i.from)&&(i=B.range(t,e))}}let{inputState:s}=t;return s.mouseSelection&&(s.mouseSelection.dragging=!0),s.draggedContent=i,e.dataTransfer&&(e.dataTransfer.setData("Text",t.state.sliceDoc(i.from,i.to)),e.dataTransfer.effectAllowed="copyMove"),!1},Ls.dragend=t=>(t.inputState.draggedContent=null,!1),Ls.drop=(t,e)=>{if(!e.dataTransfer)return!1;if(t.state.readOnly)return!0;let i=e.dataTransfer.files;if(i&&i.length){let s=Array(i.length),r=0,n=()=>{++r==i.length&&Ks(t,e,s.filter((t=>null!=t)).join(t.state.lineBreak),!1)};for(let t=0;t<i.length;t++){let e=new FileReader;e.onerror=n,e.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(e.result)||(s[t]=e.result),n()},e.readAsText(i[t])}return!0}{let i=e.dataTransfer.getData("Text");if(i)return Ks(t,e,i,!0),!0}return!1},Ls.paste=(t,e)=>{if(t.state.readOnly)return!0;t.observer.flush();let i=js?null:e.clipboardData;return i?($s(t,i.getData("text/plain")||i.getData("text/uri-list")),!0):(function(t){let e=t.dom.parentNode;if(!e)return;let i=e.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.focus(),setTimeout((()=>{t.focus(),i.remove(),$s(t,i.value)}),50)}(t),!1)};let _s=null;Ls.copy=Ls.cut=(t,e)=>{let{text:i,ranges:s,linewise:r}=function(t){let e=[],i=[],s=!1;for(let s of t.selection.ranges)s.empty||(e.push(t.sliceDoc(s.from,s.to)),i.push(s));if(!e.length){let r=-1;for(let{from:s}of t.selection.ranges){let n=t.doc.lineAt(s);n.number>r&&(e.push(n.text),i.push({from:n.from,to:Math.min(t.doc.length,n.to+1)})),r=n.number}s=!0}return{text:e.join(t.lineBreak),ranges:i,linewise:s}}(t.state);if(!i&&!r)return!1;_s=r?i:null,"cut"!=e.type||t.state.readOnly||t.dispatch({changes:s,scrollIntoView:!0,userEvent:"delete.cut"});let n=js?null:e.clipboardData;return n?(n.clearData(),n.setData("text/plain",i),!0):(function(t,e){let i=t.dom.parentNode;if(!i)return;let s=i.appendChild(document.createElement("textarea"));s.style.cssText="position: fixed; left: -10000px; top: 10px",s.value=e,s.focus(),s.selectionEnd=e.length,s.selectionStart=0,setTimeout((()=>{s.remove(),t.focus()}),50)}(t,i),!1)};const Xs=ut.define();function Ys(t,e){let i=[];for(let s of t.facet(Pi)){let r=s(t,e);r&&i.push(r)}return i?t.update({effects:i,annotations:Xs.of(!0)}):null}function Qs(t){setTimeout((()=>{let e=t.hasFocus;if(e!=t.inputState.notifiedFocused){let i=Ys(t.state,e);i?t.dispatch(i):t.update([])}}),10)}Ns.focus=t=>{t.inputState.lastFocusTime=Date.now(),t.scrollDOM.scrollTop||!t.inputState.lastScrollTop&&!t.inputState.lastScrollLeft||(t.scrollDOM.scrollTop=t.inputState.lastScrollTop,t.scrollDOM.scrollLeft=t.inputState.lastScrollLeft),Qs(t)},Ns.blur=t=>{t.observer.clearSelectionRange(),Qs(t)},Ns.compositionstart=Ns.compositionupdate=t=>{null==t.inputState.compositionFirstChange&&(t.inputState.compositionFirstChange=!0),t.inputState.composing<0&&(t.inputState.composing=0)},Ns.compositionend=t=>{t.inputState.composing=-1,t.inputState.compositionEndedAt=Date.now(),t.inputState.compositionPendingKey=!0,t.inputState.compositionPendingChange=t.observer.pendingRecords().length>0,t.inputState.compositionFirstChange=null,Ve.chrome&&Ve.android?t.observer.flushSoon():t.inputState.compositionPendingChange?Promise.resolve().then((()=>t.observer.flush())):setTimeout((()=>{t.inputState.composing<0&&t.docView.hasComposition&&t.update([])}),50)},Ns.contextmenu=t=>{t.inputState.lastContextMenu=Date.now()},Ls.beforeinput=(t,e)=>{var i;let s;if(Ve.chrome&&Ve.android&&(s=Es.find((t=>t.inputType==e.inputType)))&&(t.observer.delayAndroidKey(s.key,s.keyCode),"Backspace"==s.key||"Delete"==s.key)){let e=(null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0;setTimeout((()=>{var i;((null===(i=window.visualViewport)||void 0===i?void 0:i.height)||0)>e+10&&t.hasFocus&&(t.contentDOM.blur(),t.focus())}),100)}return Ve.ios&&"deleteContentForward"==e.inputType&&t.observer.flushSoon(),Ve.safari&&"insertText"==e.inputType&&t.inputState.composing>=0&&setTimeout((()=>Ns.compositionend(t,e)),20),!1};const Zs=new Set;const tr=["pre-wrap","normal","pre-line","break-spaces"];class er{constructor(e){this.lineWrapping=e,this.doc=t.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30,this.heightChanged=!1}heightForGap(t,e){let i=this.doc.lineAt(e).number-this.doc.lineAt(t).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((e-t-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(t){if(!this.lineWrapping)return this.lineHeight;return(1+Math.max(0,Math.ceil((t-this.lineLength)/(this.lineLength-5))))*this.lineHeight}setDoc(t){return this.doc=t,this}mustRefreshForWrapping(t){return tr.indexOf(t)>-1!=this.lineWrapping}mustRefreshForHeights(t){let e=!1;for(let i=0;i<t.length;i++){let s=t[i];s<0?i++:this.heightSamples[Math.floor(10*s)]||(e=!0,this.heightSamples[Math.floor(10*s)]=!0)}return e}refresh(t,e,i,s,r,n){let h=tr.indexOf(t)>-1,l=Math.round(e)!=Math.round(this.lineHeight)||this.lineWrapping!=h;if(this.lineWrapping=h,this.lineHeight=e,this.charWidth=i,this.textHeight=s,this.lineLength=r,l){this.heightSamples={};for(let t=0;t<n.length;t++){let e=n[t];e<0?t++:this.heightSamples[Math.floor(10*e)]=!0}}return l}}class ir{constructor(t,e){this.from=t,this.heights=e,this.index=0}get more(){return this.index<this.heights.length}}class sr{constructor(t,e,i,s,r){this.from=t,this.length=e,this.top=i,this.height=s,this._content=r}get type(){return"number"==typeof this._content?ri.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 oi?this._content.widget:null}get widgetLineBreaks(){return"number"==typeof this._content?this._content:0}join(t){let e=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new sr(this.from,this.length+t.length,this.top,this.height+t.height,e)}}var rr=function(t){return t[t.ByPos=0]="ByPos",t[t.ByHeight=1]="ByHeight",t[t.ByPosNoHeight=2]="ByPosNoHeight",t}(rr||(rr={}));const nr=.001;class hr{constructor(t,e,i=2){this.length=t,this.height=e,this.flags=i}get outdated(){return(2&this.flags)>0}set outdated(t){this.flags=(t?2:0)|-3&this.flags}setHeight(t,e){this.height!=e&&(Math.abs(this.height-e)>nr&&(t.heightChanged=!0),this.height=e)}replace(t,e,i){return hr.of(i)}decomposeLeft(t,e){e.push(this)}decomposeRight(t,e){e.push(this)}applyChanges(t,e,i,s){let r=this,n=i.doc;for(let h=s.length-1;h>=0;h--){let{fromA:l,toA:o,fromB:u,toB:f}=s[h],a=r.lineAt(l,rr.ByPosNoHeight,i.setDoc(e),0,0),c=a.to>=o?a:r.lineAt(o,rr.ByPosNoHeight,i,0,0);for(f+=c.to-o,o=c.to;h>0&&a.from<=s[h-1].toA;)l=s[h-1].fromA,u=s[h-1].fromB,h--,l<a.from&&(a=r.lineAt(l,rr.ByPosNoHeight,i,0,0));u+=a.from-l,l=a.from;let d=cr.build(i.setDoc(n),t,u,f);r=r.replace(l,o,d)}return r.updateHeight(i,0)}static empty(){return new or(0,0)}static of(t){if(1==t.length)return t[0];let e=0,i=t.length,s=0,r=0;for(;;)if(e==i)if(s>2*r){let r=t[e-1];r.break?t.splice(--e,1,r.left,null,r.right):t.splice(--e,1,r.left,r.right),i+=1+r.break,s-=r.size}else{if(!(r>2*s))break;{let e=t[i];e.break?t.splice(i,1,e.left,null,e.right):t.splice(i,1,e.left,e.right),i+=2+e.break,r-=e.size}}else if(s<r){let i=t[e++];i&&(s+=i.size)}else{let e=t[--i];e&&(r+=e.size)}let n=0;return null==t[e-1]?(n=1,e--):null==t[e]&&(n=1,i++),new fr(hr.of(t.slice(0,e)),n,hr.of(t.slice(i)))}}hr.prototype.size=1;class lr extends hr{constructor(t,e,i){super(t,e),this.deco=i}blockAt(t,e,i,s){return new sr(s,this.length,i,this.height,this.deco||0)}lineAt(t,e,i,s,r){return this.blockAt(0,i,s,r)}forEachLine(t,e,i,s,r,n){t<=r+this.length&&e>=r&&n(this.blockAt(0,i,s,r))}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more&&this.setHeight(t,s.heights[s.index++]),this.outdated=!1,this}toString(){return`block(${this.length})`}}class or extends lr{constructor(t,e){super(t,e,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0}blockAt(t,e,i,s){return new sr(s,this.length,i,this.height,this.breaks)}replace(t,e,i){let s=i[0];return 1==i.length&&(s instanceof or||s instanceof ur&&4&s.flags)&&Math.abs(this.length-s.length)<10?(s instanceof ur?s=new or(s.length,this.height):s.height=this.height,this.outdated||(s.outdated=!1),s):hr.of(i)}updateHeight(t,e=0,i=!1,s){return s&&s.from<=e&&s.more?this.setHeight(t,s.heights[s.index++]):(i||this.outdated)&&this.setHeight(t,Math.max(this.widgetHeight,t.heightForLine(this.length-this.collapsed))+this.breaks*t.lineHeight),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ur extends hr{constructor(t){super(t,0)}heightMetrics(t,e){let i,s=t.doc.lineAt(e).number,r=t.doc.lineAt(e+this.length).number,n=r-s+1,h=0;if(t.lineWrapping){let e=Math.min(this.height,t.lineHeight*n);i=e/n,this.length>n+1&&(h=(this.height-e)/(this.length-n-1))}else i=this.height/n;return{firstLine:s,lastLine:r,perLine:i,perChar:h}}blockAt(t,e,i,s){let{firstLine:r,lastLine:n,perLine:h,perChar:l}=this.heightMetrics(e,s);if(e.lineWrapping){let r=s+(t<e.lineHeight?0:Math.round(Math.max(0,Math.min(1,(t-i)/this.height))*this.length)),n=e.doc.lineAt(r),o=h+n.length*l,u=Math.max(i,t-o/2);return new sr(n.from,n.length,u,o,0)}{let s=Math.max(0,Math.min(n-r,Math.floor((t-i)/h))),{from:l,length:o}=e.doc.line(r+s);return new sr(l,o,i+h*s,h,0)}}lineAt(t,e,i,s,r){if(e==rr.ByHeight)return this.blockAt(t,i,s,r);if(e==rr.ByPosNoHeight){let{from:e,to:s}=i.doc.lineAt(t);return new sr(e,s-e,0,0,0)}let{firstLine:n,perLine:h,perChar:l}=this.heightMetrics(i,r),o=i.doc.lineAt(t),u=h+o.length*l,f=o.number-n,a=s+h*f+l*(o.from-r-f);return new sr(o.from,o.length,Math.max(s,Math.min(a,s+this.height-u)),u,0)}forEachLine(t,e,i,s,r,n){t=Math.max(t,r),e=Math.min(e,r+this.length);let{firstLine:h,perLine:l,perChar:o}=this.heightMetrics(i,r);for(let u=t,f=s;u<=e;){let e=i.doc.lineAt(u);if(u==t){let i=e.number-h;f+=l*i+o*(t-r-i)}let s=l+o*e.length;n(new sr(e.from,e.length,f,s,0)),f+=s,u=e.to+1}}replace(t,e,i){let s=this.length-e;if(s>0){let t=i[i.length-1];t instanceof ur?i[i.length-1]=new ur(t.length+s):i.push(null,new ur(s-1))}if(t>0){let e=i[0];e instanceof ur?i[0]=new ur(t+e.length):i.unshift(new ur(t-1),null)}return hr.of(i)}decomposeLeft(t,e){e.push(new ur(t-1),null)}decomposeRight(t,e){e.push(null,new ur(this.length-t-1))}updateHeight(t,e=0,i=!1,s){let r=e+this.length;if(s&&s.from<=e+this.length&&s.more){let i=[],n=Math.max(e,s.from),h=-1;for(s.from>e&&i.push(new ur(s.from-e-1).updateHeight(t,e));n<=r&&s.more;){let e=t.doc.lineAt(n).length;i.length&&i.push(null);let r=s.heights[s.index++];-1==h?h=r:Math.abs(r-h)>=nr&&(h=-2);let l=new or(e,r);l.outdated=!1,i.push(l),n+=e+1}n<=r&&i.push(null,new ur(r-n).updateHeight(t,n));let l=hr.of(i);return(h<0||Math.abs(l.height-this.height)>=nr||Math.abs(h-this.heightMetrics(t,e).perLine)>=nr)&&(t.heightChanged=!0),l}return(i||this.outdated)&&(this.setHeight(t,t.heightForGap(e,e+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}}class fr extends hr{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 1&this.flags}blockAt(t,e,i,s){let r=i+this.left.height;return t<r?this.left.blockAt(t,e,i,s):this.right.blockAt(t,e,r,s+this.left.length+this.break)}lineAt(t,e,i,s,r){let n=s+this.left.height,h=r+this.left.length+this.break,l=e==rr.ByHeight?t<n:t<h,o=l?this.left.lineAt(t,e,i,s,r):this.right.lineAt(t,e,i,n,h);if(this.break||(l?o.to<h:o.from>h))return o;let u=e==rr.ByPosNoHeight?rr.ByPosNoHeight:rr.ByPos;return l?o.join(this.right.lineAt(h,u,i,n,h)):this.left.lineAt(h,u,i,s,r).join(o)}forEachLine(t,e,i,s,r,n){let h=s+this.left.height,l=r+this.left.length+this.break;if(this.break)t<l&&this.left.forEachLine(t,e,i,s,r,n),e>=l&&this.right.forEachLine(t,e,i,h,l,n);else{let o=this.lineAt(l,rr.ByPos,i,s,r);t<o.from&&this.left.forEachLine(t,o.from-1,i,s,r,n),o.to>=t&&o.from<=e&&n(o),e>o.to&&this.right.forEachLine(o.to+1,e,i,h,l,n)}}replace(t,e,i){let s=this.left.length+this.break;if(e<s)return this.balanced(this.left.replace(t,e,i),this.right);if(t>this.left.length)return this.balanced(this.left,this.right.replace(t-s,e-s,i));let r=[];t>0&&this.decomposeLeft(t,r);let n=r.length;for(let t of i)r.push(t);if(t>0&&ar(r,n-1),e<this.length){let t=r.length;this.decomposeRight(e,r),ar(r,t)}return hr.of(r)}decomposeLeft(t,e){let i=this.left.length;if(t<=i)return this.left.decomposeLeft(t,e);e.push(this.left),this.break&&(i++,t>=i&&e.push(null)),t>i&&this.right.decomposeLeft(t-i,e)}decomposeRight(t,e){let i=this.left.length,s=i+this.break;if(t>=s)return this.right.decomposeRight(t-s,e);t<i&&this.left.decomposeRight(t,e),this.break&&t<s&&e.push(null),e.push(this.right)}balanced(t,e){return t.size>2*e.size||e.size>2*t.size?hr.of(this.break?[t,null,e]:[t,e]):(this.left=t,this.right=e,this.height=t.height+e.height,this.outdated=t.outdated||e.outdated,this.size=t.size+e.size,this.length=t.length+this.break+e.length,this)}updateHeight(t,e=0,i=!1,s){let{left:r,right:n}=this,h=e+r.length+this.break,l=null;return s&&s.from<=e+r.length&&s.more?l=r=r.updateHeight(t,e,i,s):r.updateHeight(t,e,i),s&&s.from<=h+n.length&&s.more?l=n=n.updateHeight(t,h,i,s):n.updateHeight(t,h,i),l?this.balanced(r,n):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function ar(t,e){let i,s;null==t[e]&&(i=t[e-1])instanceof ur&&(s=t[e+1])instanceof ur&&t.splice(e-1,3,new ur(i.length+1+s.length))}class cr{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 t=Math.min(e,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof or?i.length+=t-this.pos:(t>this.pos||!this.isCovered)&&this.nodes.push(new or(t-this.pos,-1)),this.writtenTo=t,e>t&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=e}point(t,e,i){if(t<e||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let n=e-t;i.block?this.addBlock(new lr(n,s,i)):(n||r||s>=5)&&this.addLineDeco(s,r,n)}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||null==this.nodes[this.nodes.length-1])&&this.nodes.push(this.blankContent(this.writtenTo,t-1)),this.nodes.push(null)),this.pos>t&&this.nodes.push(new or(this.pos-t,-1)),this.writtenTo=this.pos}blankContent(t,e){let i=new ur(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 or)return t;let e=new or(0,-1);return this.nodes.push(e),e}addBlock(t){this.enterLine();let e=t.deco;e&&e.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(t),this.writtenTo=this.pos=this.pos+t.length,e&&e.endSide>0&&(this.covering=t)}addLineDeco(t,e,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,t),s.breaks+=e,this.writtenTo=this.pos=this.pos+i}finish(t){let e=0==this.nodes.length?null:this.nodes[this.nodes.length-1];!(this.lineStart>-1)||e instanceof or||this.isCovered?(this.writtenTo<this.pos||null==e)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos)):this.nodes.push(new or(0,-1));let i=t;for(let t of this.nodes)t instanceof or&&t.updateHeight(this.oracle,i),i+=t?t.length:1;return this.nodes}static build(t,e,i,s){let r=new cr(i,t);return It.spans(e,i,s,r,0),r.finish(i)}}class dr{constructor(){this.changes=[]}compareRange(){}comparePoint(t,e,i,s){(t<e||i&&i.heightRelevant||s&&s.heightRelevant)&&fi(t,e,this.changes,5)}}function pr(t,e){let i=t.getBoundingClientRect(),s=t.ownerDocument,r=s.defaultView||window,n=Math.max(0,i.left),h=Math.min(r.innerWidth,i.right),l=Math.max(0,i.top),o=Math.min(r.innerHeight,i.bottom);for(let e=t.parentNode;e&&e!=s.body;)if(1==e.nodeType){let i=e,s=window.getComputedStyle(i);if((i.scrollHeight>i.clientHeight||i.scrollWidth>i.clientWidth)&&"visible"!=s.overflow){let s=i.getBoundingClientRect();n=Math.max(n,s.left),h=Math.min(h,s.right),l=Math.max(l,s.top),o=e==t.parentNode?s.bottom:Math.min(o,s.bottom)}e="absolute"==s.position||"fixed"==s.position?i.offsetParent:i.parentNode}else{if(11!=e.nodeType)break;e=e.host}return{left:n-i.left,right:Math.max(n,h)-i.left,top:l-(i.top+e),bottom:Math.max(l,o)-(i.top+e)}}function mr(t,e){let i=t.getBoundingClientRect();return{left:0,right:i.right-i.left,top:e,bottom:i.bottom-(i.top+e)}}class gr{constructor(t,e,i){this.from=t,this.to=e,this.size=i}static same(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++){let s=t[i],r=e[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(t,e){return ni.replace({widget:new wr(this.size*(e?t.scaleY:t.scaleX),e)}).range(this.from,this.to)}}class wr extends si{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 br{constructor(e){this.state=e,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scrollTop=0,this.scrolledToBottom=!1,this.scaleX=1,this.scaleY=1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=xr,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=pi.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=e.facet(Qi).some((t=>"function"!=typeof t&&"cm-lineWrapping"==t.class));this.heightOracle=new er(i),this.stateDeco=e.facet(Zi).filter((t=>"function"!=typeof t)),this.heightMap=hr.empty().applyChanges(this.stateDeco,t.empty,this.heightOracle.setDoc(e.doc),[new ls(0,0,0,e.doc.length)]),this.viewport=this.getViewport(0,null),this.updateViewportLines(),this.updateForViewport(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=ni.set(this.lineGaps.map((t=>t.draw(this,!1)))),this.computeVisibleRanges()}updateForViewport(){let t=[this.viewport],{main:e}=this.state.selection;for(let i=0;i<=1;i++){let s=i?e.head:e.anchor;if(!t.some((({from:t,to:e})=>s>=t&&s<=e))){let{from:e,to:i}=this.lineBlockAt(s);t.push(new vr(e,i))}}this.viewports=t.sort(((t,e)=>t.from-e.from)),this.scaler=this.heightMap.height<=7e6?xr:new Sr(this.heightOracle,this.heightMap,this.viewports)}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,(t=>{this.viewportLines.push(1==this.scaler.scale?t:Ar(t,this.scaler))}))}update(t,e=null){this.state=t.state;let i=this.stateDeco;this.stateDeco=this.state.facet(Zi).filter((t=>"function"!=typeof t));let s=t.changedRanges,r=ls.extendWithRanges(s,function(t,e,i){let s=new dr;return It.compare(t,e,i,s,0),s.changes}(i,this.stateDeco,t?t.changes:A.empty(this.state.doc.length))),n=this.heightMap.height,h=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollTop);this.heightMap=this.heightMap.applyChanges(this.stateDeco,t.startState.doc,this.heightOracle.setDoc(this.state.doc),r),this.heightMap.height!=n&&(t.flags|=2),h?(this.scrollAnchorPos=t.changes.mapPos(h.from,-1),this.scrollAnchorHeight=h.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=this.heightMap.height);let l=r.length?this.mapViewport(this.viewport,t.changes):this.viewport;(e&&(e.range.head<l.from||e.range.head>l.to)||!this.viewportIsAppropriate(l))&&(l=this.getViewport(0,e));let o=!t.changes.empty||2&t.flags||l.from!=this.viewport.from||l.to!=this.viewport.to;this.viewport=l,this.updateForViewport(),o&&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(Wi)&&(this.mustEnforceCursorAssoc=!0)}measure(e){let i=e.contentDOM,s=window.getComputedStyle(i),r=this.heightOracle,n=s.whiteSpace;this.defaultTextDirection="rtl"==s.direction?pi.RTL:pi.LTR;let h=this.heightOracle.mustRefreshForWrapping(n),l=i.getBoundingClientRect(),o=h||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let u=0,f=0;if(l.width&&l.height){let{scaleX:t,scaleY:e}=de(i,l);(t>.005&&Math.abs(this.scaleX-t)>.005||e>.005&&Math.abs(this.scaleY-e)>.005)&&(this.scaleX=t,this.scaleY=e,u|=8,h=o=!0)}let a=(parseInt(s.paddingTop)||0)*this.scaleY,c=(parseInt(s.paddingBottom)||0)*this.scaleY;this.paddingTop==a&&this.paddingBottom==c||(this.paddingTop=a,this.paddingBottom=c,u|=10),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(o=!0),this.editorWidth=e.scrollDOM.clientWidth,u|=8);let d=e.scrollDOM.scrollTop*this.scaleY;this.scrollTop!=d&&(this.scrollAnchorHeight=-1,this.scrollTop=d),this.scrolledToBottom=ye(e.scrollDOM);let p=(this.printing?mr:pr)(i,this.paddingTop),m=p.top-this.pixelViewport.top,g=p.bottom-this.pixelViewport.bottom;this.pixelViewport=p;let w=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(w!=this.inView&&(this.inView=w,w&&(o=!0)),!this.inView&&!this.scrollTarget)return 0;let b=l.width;if(this.contentDOMWidth==b&&this.editorHeight==e.scrollDOM.clientHeight||(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,u|=8),o){let i=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(i)&&(h=!0),h||r.lineWrapping&&Math.abs(b-this.contentDOMWidth)>r.charWidth){let{lineHeight:t,charWidth:s,textHeight:l}=e.docView.measureTextSize();h=t>0&&r.refresh(n,t,s,l,b/s,i),h&&(e.docView.minWidth=0,u|=8)}m>0&&g>0?f=Math.max(m,g):m<0&&g<0&&(f=Math.min(m,g)),r.heightChanged=!1;for(let s of this.viewports){let n=s.from==this.viewport.from?i:e.docView.measureVisibleLineHeights(s);this.heightMap=(h?hr.empty().applyChanges(this.stateDeco,t.empty,this.heightOracle,[new ls(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,h,new ir(s.from,n))}r.heightChanged&&(u|=2)}let v=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return v&&(this.viewport=this.getViewport(f,this.scrollTarget)),this.updateForViewport(),(2&u||v)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(h?[]:this.lineGaps,e)),u|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),u}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(t,e){let i=.5-Math.max(-.5,Math.min(.5,t/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:n,visibleBottom:h}=this,l=new vr(s.lineAt(n-1e3*i,rr.ByHeight,r,0,0).from,s.lineAt(h+1e3*(1-i),rr.ByHeight,r,0,0).to);if(e){let{head:t}=e.range;if(t<l.from||t>l.to){let i,n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),h=s.lineAt(t,rr.ByPos,r,0,0);i="center"==e.y?(h.top+h.bottom)/2-n/2:"start"==e.y||"nearest"==e.y&&t<l.from?h.top:h.bottom-n,l=new vr(s.lineAt(i-500,rr.ByHeight,r,0,0).from,s.lineAt(i+n+500,rr.ByHeight,r,0,0).to)}}return l}mapViewport(t,e){let i=e.mapPos(t.from,-1),s=e.mapPos(t.to,1);return new vr(this.heightMap.lineAt(i,rr.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,rr.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:t,to:e},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(t,rr.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(e,rr.ByPos,this.heightOracle,0,0),{visibleTop:n,visibleBottom:h}=this;return(0==t||s<=n-Math.max(10,Math.min(-i,250)))&&(e==this.state.doc.length||r>=h+Math.max(10,Math.min(i,250)))&&s>n-2e3&&r<h+2e3}mapLineGaps(t,e){if(!t.length||e.empty)return t;let i=[];for(let s of t)e.touchesRange(s.from,s.to)||i.push(new gr(e.mapPos(s.from),e.mapPos(s.to),s.size));return i}ensureLineGaps(t,e){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,n=s<<1;if(this.defaultTextDirection!=pi.LTR&&!i)return[];let h=[],l=(s,n,o,u)=>{if(n-s<r)return;let f=this.state.selection.main,a=[f.from];f.empty||a.push(f.to);for(let t of a)if(t>s&&t<n)return l(s,t-10,o,u),void l(t+10,n,o,u);let c=function(t,e){for(let i of t)if(e(i))return i;return}(t,(t=>t.from>=o.from&&t.to<=o.to&&Math.abs(t.from-s)<r&&Math.abs(t.to-n)<r&&!a.some((e=>t.from<e&&t.to>e))));if(!c){if(n<o.to&&e&&i&&e.visibleRanges.some((t=>t.from<=n&&t.to>=n))){let t=e.moveToLineBoundary(B.cursor(n),!1,!0).head;t>s&&(n=t)}c=new gr(s,n,this.gapSize(o,s,n,u))}h.push(c)};for(let t of this.viewportLines){if(t.length<n)continue;let e=kr(t.from,t.to,this.stateDeco);if(e.total<n)continue;let r,h,o=this.scrollTarget?this.scrollTarget.range.head:null;if(i){let i,n,l=s/this.heightOracle.lineLength*this.heightOracle.lineHeight;if(null!=o){let s=Mr(e,o),r=((this.visibleBottom-this.visibleTop)/2+l)/t.height;i=s-r,n=s+r}else i=(this.visibleTop-t.top-l)/t.height,n=(this.visibleBottom-t.top+l)/t.height;r=yr(e,i),h=yr(e,n)}else{let t,i,n=e.total*this.heightOracle.charWidth,l=s*this.heightOracle.charWidth;if(null!=o){let s=Mr(e,o),r=((this.pixelViewport.right-this.pixelViewport.left)/2+l)/n;t=s-r,i=s+r}else t=(this.pixelViewport.left-l)/n,i=(this.pixelViewport.right+l)/n;r=yr(e,t),h=yr(e,i)}r>t.from&&l(t.from,r,t,e),h<t.to&&l(h,t.to,t,e)}return h}gapSize(t,e,i,s){let r=Mr(s,i)-Mr(s,e);return this.heightOracle.lineWrapping?t.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(t){gr.same(t,this.lineGaps)||(this.lineGaps=t,this.lineGapDeco=ni.set(t.map((t=>t.draw(this,this.heightOracle.lineWrapping)))))}computeVisibleRanges(){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let e=[];It.spans(t,this.viewport.from,this.viewport.to,{span(t,i){e.push({from:t,to:i})},point(){}},20);let i=e.length!=this.visibleRanges.length||this.visibleRanges.some(((t,i)=>t.from!=e[i].from||t.to!=e[i].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))||Ar(this.heightMap.lineAt(t,rr.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(t){return Ar(this.heightMap.lineAt(this.scaler.fromDOM(t),rr.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 Ar(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 vr{constructor(t,e){this.from=t,this.to=e}}function kr(t,e,i){let s=[],r=t,n=0;return It.spans(i,t,e,{span(){},point(t,e){t>r&&(s.push({from:r,to:t}),n+=t-r),r=e}},20),r<e&&(s.push({from:r,to:e}),n+=e-r),{total:n,ranges:s}}function yr({total:t,ranges:e},i){if(i<=0)return e[0].from;if(i>=1)return e[e.length-1].to;let s=Math.floor(t*i);for(let t=0;;t++){let{from:i,to:r}=e[t],n=r-i;if(s<=n)return i+s;s-=n}}function Mr(t,e){let i=0;for(let{from:s,to:r}of t.ranges){if(e<=r){i+=e-s;break}i+=r-s}return i/t.total}const xr={toDOM:t=>t,fromDOM:t=>t,scale:1};class Sr{constructor(t,e,i){let s=0,r=0,n=0;this.viewports=i.map((({from:i,to:r})=>{let n=e.lineAt(i,rr.ByPos,t,0,0).top,h=e.lineAt(r,rr.ByPos,t,0,0).bottom;return s+=h-n,{from:i,to:r,top:n,bottom:h,domTop:0,domBottom:0}})),this.scale=(7e6-s)/(e.height-s);for(let t of this.viewports)t.domTop=n+(t.top-r)*this.scale,n=t.domBottom=t.domTop+(t.bottom-t.top),r=t.bottom}toDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.top)return s+(t-i)*this.scale;if(t<=r.bottom)return r.domTop+(t-r.top);i=r.bottom,s=r.domBottom}}fromDOM(t){for(let e=0,i=0,s=0;;e++){let r=e<this.viewports.length?this.viewports[e]:null;if(!r||t<r.domTop)return i+(t-s)/this.scale;if(t<=r.domBottom)return r.top+(t-r.domTop);i=r.bottom,s=r.domBottom}}}function Ar(t,e){if(1==e.scale)return t;let i=e.toDOM(t.top),s=e.toDOM(t.bottom);return new sr(t.from,t.length,i,s-i,Array.isArray(t._content)?t._content.map((t=>Ar(t,e))):t._content)}const Cr=j.define({combine:t=>t.join(" ")}),Or=j.define({combine:t=>t.indexOf(!0)>-1}),Dr=Gt.newName(),Er=Gt.newName(),Ir=Gt.newName(),Rr={"&light":"."+Er,"&dark":"."+Ir};function Tr(t,e,i){return new Gt(e,{finish:e=>/&/.test(e)?e.replace(/&\w*/,(e=>{if("&"==e)return t;if(!i||!i[e])throw new RangeError(`Unsupported selector: ${e}`);return i[e]})):t+" "+e})}const Br=Tr("."+Dr,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#444"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",insetInlineStart:0,zIndex:200},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",borderRight:"1px solid #ddd"},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top"},".cm-highlightSpace:before":{content:"attr(data-display)",position:"absolute",pointerEvents:"none",color:"#888"},".cm-highlightTab":{backgroundImage:'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>\')',backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Rr),Lr="";class Nr{constructor(t,e){this.points=t,this.text="",this.lineSeparator=e.facet(St.lineSeparator)}append(t){this.text+=t}lineBreak(){this.text+=Lr}readRange(t,e){if(!t)return this;let i=t.parentNode;for(let s=t;;){this.findPointBefore(i,s);let t=this.text.length;this.readNode(s);let r=s.nextSibling;if(r==e)break;let n=Ce.get(s),h=Ce.get(r);(n&&h?n.breakAfter:(n?n.breakAfter:oe(s))||oe(r)&&("BR"!=s.nodeName||s.cmIgnore)&&this.text.length>t)&&this.lineBreak(),s=r}return this.findPointBefore(i,e),this}readTextNode(t){let e=t.nodeValue;for(let i of this.points)i.node==t&&(i.pos=this.text.length+Math.min(i.offset,e.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r,n=-1,h=1;if(this.lineSeparator?(n=e.indexOf(this.lineSeparator,i),h=this.lineSeparator.length):(r=s.exec(e))&&(n=r.index,h=r[0].length),this.append(e.slice(i,n<0?e.length:n)),n<0)break;if(this.lineBreak(),h>1)for(let e of this.points)e.node==t&&e.pos>this.text.length&&(e.pos-=h-1);i=n+h}}readNode(t){if(t.cmIgnore)return;let e=Ce.get(t),i=e&&e.overrideDOMText;if(null!=i){this.findPointInside(t,i.length);for(let t=i.iter();!t.next().done;)t.lineBreak?this.lineBreak():this.append(t.value)}else 3==t.nodeType?this.readTextNode(t):"BR"==t.nodeName?t.nextSibling&&this.lineBreak():1==t.nodeType&&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)(3==t.nodeType?i.node==t:t.contains(i.node))&&(i.pos=this.text.length+(jr(t,i.node,i.offset)?e:0))}}function jr(t,e,i){for(;;){if(!e||i<fe(e))return!1;if(e==t)return!0;i=le(e)+1,e=e.parentNode}}class $r{constructor(t,e){this.node=t,this.offset=e,this.pos=-1}}class zr{constructor(t,e,i,s){this.typeOver=s,this.bounds=null,this.text="";let{impreciseHead:r,impreciseAnchor:n}=t.docView;if(t.state.readOnly&&e>-1)this.newSel=null;else if(e>-1&&(this.bounds=t.docView.domBoundsAround(e,i,0))){let e=r||n?[]:function(t){let e=[];if(t.root.activeElement!=t.contentDOM)return e;let{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}=t.observer.selectionRange;i&&(e.push(new $r(i,s)),r==i&&n==s||e.push(new $r(r,n)));return e}(t),i=new Nr(e,t.state);i.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=i.text,this.newSel=function(t,e){if(0==t.length)return null;let i=t[0].pos,s=2==t.length?t[1].pos:i;return i>-1&&s>-1?B.single(i+e,s+e):null}(e,this.bounds.from)}else{let e=t.observer.selectionRange,i=r&&r.node==e.focusNode&&r.offset==e.focusOffset||!se(t.contentDOM,e.focusNode)?t.state.selection.main.head:t.docView.posFromDOM(e.focusNode,e.focusOffset),s=n&&n.node==e.anchorNode&&n.offset==e.anchorOffset||!se(t.contentDOM,e.anchorNode)?t.state.selection.main.anchor:t.docView.posFromDOM(e.anchorNode,e.anchorOffset),h=t.viewport;if((Ve.ios||Ve.chrome)&&t.state.selection.main.empty&&i!=s&&(h.from>0||h.to<t.state.doc.length)){let e=Math.min(i,s),r=Math.max(i,s),n=h.from-e,l=h.to-r;0!=n&&1!=n&&0!=e||0!=l&&-1!=l&&r!=t.state.doc.length||(i=0,s=t.state.doc.length)}this.newSel=B.single(s,i)}}}function Pr(e,i){let s,{newSel:r}=i,n=e.state.selection.main,h=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(i.bounds){let{from:r,to:l}=i.bounds,o=n.from,u=null;(8===h||Ve.android&&i.text.length<l-r)&&(o=n.to,u="end");let f=function(t,e,i,s){let r=Math.min(t.length,e.length),n=0;for(;n<r&&t.charCodeAt(n)==e.charCodeAt(n);)n++;if(n==r&&t.length==e.length)return null;let h=t.length,l=e.length;for(;h>0&&l>0&&t.charCodeAt(h-1)==e.charCodeAt(l-1);)h--,l--;if("end"==s){i-=h+Math.max(0,n-Math.min(h,l))-n}if(h<n&&t.length<e.length){n-=i<=n&&i>=h?n-i:0,l=n+(l-h),h=n}else if(l<n){n-=i<=n&&i>=l?n-i:0,h=n+(h-l),l=n}return{from:n,toA:h,toB:l}}(e.state.doc.sliceString(r,l,Lr),i.text,o-r,u);f&&(Ve.chrome&&13==h&&f.toB==f.from+2&&i.text.slice(f.from,f.toB)==Lr+Lr&&f.toB--,s={from:r+f.from,to:r+f.toA,insert:t.of(i.text.slice(f.from,f.toB).split(Lr))})}else r&&(!e.hasFocus&&e.state.facet(Ji)||r.main.eq(n))&&(r=null);if(!s&&!r)return!1;if(!s&&i.typeOver&&!n.empty&&r&&r.main.empty?s={from:n.from,to:n.to,insert:e.state.doc.slice(n.from,n.to)}:s&&s.from>=n.from&&s.to<=n.to&&(s.from!=n.from||s.to!=n.to)&&n.to-n.from-(s.to-s.from)<=4?s={from:n.from,to:n.to,insert:e.state.doc.slice(n.from,s.from).append(s.insert).append(e.state.doc.slice(s.to,n.to))}:(Ve.mac||Ve.android)&&s&&s.from==s.to&&s.from==n.head-1&&/^\. ?$/.test(s.insert.toString())&&"off"==e.contentDOM.getAttribute("autocorrect")?(r&&2==s.insert.length&&(r=B.single(r.main.anchor-1,r.main.head-1)),s={from:n.from,to:n.to,insert:t.of([" "])}):Ve.chrome&&s&&s.from==s.to&&s.from==n.head&&"\n "==s.insert.toString()&&e.lineWrapping&&(r&&(r=B.single(r.main.anchor-1,r.main.head-1)),s={from:n.from,to:n.to,insert:t.of([" "])}),s){if(Ve.ios&&e.inputState.flushIOSKey(s))return!0;if(Ve.android&&(s.to==n.to&&(s.from==n.from||s.from==n.from-1&&" "==e.state.sliceDoc(s.from,n.from))&&1==s.insert.length&&2==s.insert.lines&&ve(e.contentDOM,"Enter",13)||(s.from==n.from-1&&s.to==n.to&&0==s.insert.length||8==h&&s.insert.length<s.to-s.from&&s.to>n.head)&&ve(e.contentDOM,"Backspace",8)||s.from==n.from&&s.to==n.to+1&&0==s.insert.length&&ve(e.contentDOM,"Delete",46)))return!0;let t,i=s.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let l=()=>t||(t=function(t,e,i){let s,r=t.state,n=r.selection.main;if(e.from>=n.from&&e.to<=n.to&&e.to-e.from>=(n.to-n.from)/3&&(!i||i.main.empty&&i.main.from==e.from+e.insert.length)&&t.inputState.composing<0){let i=n.from<e.from?r.sliceDoc(n.from,e.from):"",h=n.to>e.to?r.sliceDoc(e.to,n.to):"";s=r.replaceSelection(t.state.toText(i+e.insert.sliceString(0,void 0,t.state.lineBreak)+h))}else{let h=r.changes(e),l=i&&i.main.to<=h.newLength?i.main:void 0;if(r.selection.ranges.length>1&&t.inputState.composing>=0&&e.to<=n.to&&e.to>=n.to-10){let o,u=t.state.sliceDoc(e.from,e.to),f=i&&as(t,i.main.head);if(f){let t=e.insert.length-(e.to-e.from);o={from:f.from,to:f.to-t}}else o=t.state.doc.lineAt(n.head);let a=n.to-e.to,c=n.to-n.from;s=r.changeByRange((i=>{if(i.from==n.from&&i.to==n.to)return{changes:h,range:l||i.map(h)};let s=i.to-a,f=s-u.length;if(i.to-i.from!=c||t.state.sliceDoc(f,s)!=u||i.to>=o.from&&i.from<=o.to)return{range:i};let d=r.changes({from:f,to:s,insert:e.insert}),p=i.to-n.to;return{changes:d,range:l?B.range(Math.max(0,l.anchor+p),Math.max(0,l.head+p)):i.map(d)}}))}else s={changes:h,selection:l&&r.selection.replaceRange(l)}}let h="input.type";(t.composing||t.inputState.compositionPendingChange&&t.inputState.compositionEndedAt>Date.now()-50)&&(t.inputState.compositionPendingChange=!1,h+=".compose",t.inputState.compositionFirstChange&&(h+=".start",t.inputState.compositionFirstChange=!1));return r.update(s,{userEvent:h,scrollIntoView:!0})}(e,s,r));return e.state.facet(zi).some((t=>t(e,s.from,s.to,i,l)))||e.dispatch(l()),!0}if(r&&!r.main.eq(n)){let t=!1,i="select";return e.inputState.lastSelectionTime>Date.now()-50&&("select"==e.inputState.lastSelectionOrigin&&(t=!0),i=e.inputState.lastSelectionOrigin),e.dispatch({selection:r,scrollIntoView:t,userEvent:i}),!0}return!1}const Hr={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Wr=Ve.ie&&Ve.ie_version<=11;class Vr{constructor(t){this.view=t,this.active=!1,this.selectionRange=new pe,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 t of e)this.queue.push(t);(Ve.ie&&Ve.ie_version<=11||Ve.ios&&t.composing)&&e.some((t=>"childList"==t.type&&t.removedNodes.length||"characterData"==t.type&&t.oldValue.length>t.target.nodeValue.length))?this.flushSoon():this.flush()})),Wr&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),"function"==typeof ResizeObserver&&(this.resizeScroll=new ResizeObserver((()=>{var t;(null===(t=this.view.docView)||void 0===t?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()})),this.resizeScroll.observe(t.scrollDOM)),this.addWindowListeners(this.win=t.win),this.start(),"function"==typeof IntersectionObserver&&(this.intersection=new IntersectionObserver((t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))}),{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver((t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))}),{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(t){this.view.inputState.runHandlers("scroll",t),this.intersecting&&this.view.measure()}onScroll(t){this.intersecting&&this.flush(!1),this.onScrollChanged(t)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout((()=>{this.resizeTimeout=-1,this.view.requestMeasure()}),50))}onPrint(t){("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,s=this.selectionRange;if(i.state.facet(Ji)?i.root.activeElement!=this.dom:!re(i.dom,s))return;let r=s.anchorNode&&i.docView.nearest(s.anchorNode);r&&r.ignoreEvent(t)?e||(this.selectionChanged=!1):(Ve.ie&&Ve.ie_version<=11||Ve.android&&Ve.chrome)&&!i.state.selection.main.empty&&s.focusNode&&he(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:t}=this,e=ie(t.root);if(!e)return!1;let i=Ve.safari&&11==t.root.nodeType&&function(t){let e=t.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}(this.dom.ownerDocument)==this.dom&&function(t,e){if(e.getComposedRanges){let i=e.getComposedRanges(t.root)[0];if(i)return qr(t,i)}let i=null;function s(t){t.preventDefault(),t.stopImmediatePropagation(),i=t.getTargetRanges()[0]}return t.contentDOM.addEventListener("beforeinput",s,!0),t.dom.ownerDocument.execCommand("indent"),t.contentDOM.removeEventListener("beforeinput",s,!0),i?qr(t,i):null}(this.view,e)||e;if(!i||this.selectionRange.eq(i))return!1;let s=re(this.dom,i);return s&&!this.selectionChanged&&t.inputState.lastFocusTime>Date.now()-200&&t.inputState.lastTouchTime<Date.now()-300&&function(t,e){let i=e.focusNode,s=e.focusOffset;if(!i||e.anchorNode!=i||e.anchorOffset!=s)return!1;for(s=Math.min(s,fe(i));;)if(s){if(1!=i.nodeType)return!1;let t=i.childNodes[s-1];"false"==t.contentEditable?s--:(i=t,s=fe(i))}else{if(i==t)return!0;s=le(i),i=i.parentNode}}(this.dom,i)?(this.view.inputState.lastFocusTime=0,t.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(t,e){this.selectionRange.set(t.node,t.offset,e.node,e.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let t=0,e=null;for(let i=this.dom;i;)if(1==i.nodeType)!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(11!=i.nodeType)break;i=i.host}if(t<this.scrollTargets.length&&!e&&(e=this.scrollTargets.slice(0,t)),e){for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);for(let t of this.scrollTargets=e)t.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,Hr),Wr&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Wr&&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 t=()=>{let t=this.delayedAndroidKey;if(t){this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=t.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&t.force&&ve(this.dom,t.key,t.keyCode)}};this.flushingAndroidKey=this.view.win.requestAnimationFrame(t)}this.delayedAndroidKey&&"Enter"!=t||(this.delayedAndroidKey={key:t,keyCode:e,force:this.lastChange<Date.now()-50||!!(null===(i=this.delayedAndroidKey)||void 0===i?void 0:i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame((()=>{this.delayedFlush=-1,this.flush()})))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let t of this.observer.takeRecords())this.queue.push(t);return this.queue}processRecords(){let t=this.pendingRecords();t.length&&(this.queue=[]);let e=-1,i=-1,s=!1;for(let r of t){let t=this.readMutation(r);t&&(t.typeOver&&(s=!0),-1==e?({from:e,to:i}=t):(e=Math.min(t.from,e),i=Math.max(t.to,i)))}return{from:e,to:i,typeOver:s}}readChange(){let{from:t,to:e,typeOver:i}=this.processRecords(),s=this.selectionChanged&&re(this.dom,this.selectionRange);if(t<0&&!s)return null;t>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new zr(this.view,t,e,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(t=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;t&&this.readSelectionRange();let e=this.readChange();if(!e)return this.view.requestMeasure(),!1;let i=this.view.state,s=Pr(this.view,e);return this.view.state==i&&this.view.update([]),s}readMutation(t){let e=this.view.docView.nearest(t.target);if(!e||e.ignoreMutation(t))return null;if(e.markDirty("attributes"==t.type),"attributes"==t.type&&(e.flags|=4),"childList"==t.type){let i=Fr(e,t.previousSibling||t.target.previousSibling,-1),s=Fr(e,t.nextSibling||t.target.nextSibling,1);return{from:i?e.posAfter(i):e.posAtStart,to:s?e.posBefore(s):e.posAtEnd,typeOver:!1}}return"characterData"==t.type?{from:e.posAtStart,to:e.posAtEnd,typeOver:t.target.nodeValue==t.oldValue}:null}setWindow(t){t!=this.win&&(this.removeWindowListeners(this.win),this.win=t,this.addWindowListeners(this.win))}addWindowListeners(t){t.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener("change",this.onPrint):t.addEventListener("beforeprint",this.onPrint),t.addEventListener("scroll",this.onScroll),t.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(t){t.removeEventListener("scroll",this.onScroll),t.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener("change",this.onPrint):t.removeEventListener("beforeprint",this.onPrint),t.document.removeEventListener("selectionchange",this.onSelectionChange)}destroy(){var t,e,i;this.stop(),null===(t=this.intersection)||void 0===t||t.disconnect(),null===(e=this.gapIntersection)||void 0===e||e.disconnect(),null===(i=this.resizeScroll)||void 0===i||i.disconnect();for(let t of this.scrollTargets)t.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey)}}function Fr(t,e,i){for(;e;){let s=Ce.get(e);if(s&&s.parent==t)return s;let r=e.parentNode;e=r!=t.dom?r:i>0?e.nextSibling:e.previousSibling}return null}function qr(t,e){let i=e.startContainer,s=e.startOffset,r=e.endContainer,n=e.endOffset,h=t.docView.domAtPos(t.state.selection.main.anchor);return he(h.node,h.offset,r,n)&&([i,s,r,n]=[r,n,i,s]),{anchorNode:i,anchorOffset:s,focusNode:r,focusOffset:n}}class Ur{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return this.inputState.composing>0}get compositionStarted(){return this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(t={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),t.parent&&t.parent.appendChild(this.dom);let{dispatch:e}=t;this.dispatchTransactions=t.dispatchTransactions||e&&(t=>t.forEach((t=>e(t,this))))||(t=>this.update(t)),this.dispatch=this.dispatch.bind(this),this._root=t.root||function(t){for(;t;){if(t&&(9==t.nodeType||11==t.nodeType&&t.host))return t;t=t.assignedSlot||t.parentNode}return null}(t.parent)||document,this.viewState=new br(t.state||St.create(t)),t.scrollTo&&t.scrollTo.is(qi)&&(this.viewState.scrollTarget=t.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ki).map((t=>new Xi(t)));for(let t of this.plugins)t.update(this);this.observer=new Vr(this),this.inputState=new Cs(this),this.inputState.ensureHandlers(this.plugins),this.docView=new us(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure()}dispatch(...t){let e=1==t.length&&t[0]instanceof dt?t:1==t.length&&Array.isArray(t[0])?t[0]:[this.state.update(...t)];this.dispatchTransactions(e,this)}update(t){if(0!=this.updateState)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let e,i=!1,s=!1,r=this.state;for(let e of t){if(e.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");r=e.state}if(this.destroyed)return void(this.viewState.state=r);let n=this.hasFocus,h=0,l=null;t.some((t=>t.annotation(Xs)))?(this.inputState.notifiedFocused=n,h=1):n!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=n,l=Ys(r,n),l||(h=1));let o=this.observer.delayedAndroidKey,u=null;if(o?(this.observer.clearDelayedAndroidKey(),u=this.observer.readChange(),(u&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(u=null)):this.observer.clear(),r.facet(St.phrases)!=this.state.facet(St.phrases))return this.setState(r);e=os.create(this,r,t),e.flags|=h;let f=this.viewState.scrollTarget;try{this.updateState=2;for(let e of t){if(f&&(f=f.map(e.changes)),e.scrollIntoView){let{main:t}=e.state.selection;f=new Fi(t.empty?t:B.cursor(t.head,t.head>t.anchor?-1:1))}for(let t of e.effects)t.is(qi)&&(f=t.value.clip(this.state))}this.viewState.update(e,f),this.bidiCache=Kr.update(this.bidiCache,e.changes),e.empty||(this.updatePlugins(e),this.inputState.update(e)),i=this.docView.update(e),this.state.facet(hs)!=this.styleModules&&this.mountStyles(),s=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(i,t.some((t=>t.isUserEvent("select.pointer"))))}finally{this.updateState=0}if(e.startState.facet(Cr)!=e.state.facet(Cr)&&(this.viewState.mustMeasureContent=!0),(i||s||f||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),i&&this.docViewUpdate(),!e.empty)for(let t of this.state.facet($i))try{t(e)}catch(t){Ui(this.state,t,"update listener")}(l||u)&&Promise.resolve().then((()=>{l&&this.state==l.startState&&this.dispatch(l),u&&!Pr(this,u)&&o.force&&ve(this.contentDOM,o.key,o.keyCode)}))}setState(t){if(0!=this.updateState)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed)return void(this.viewState.state=t);this.updateState=2;let e=this.hasFocus;try{for(let t of this.plugins)t.destroy(this);this.viewState=new br(t),this.plugins=t.facet(Ki).map((t=>new Xi(t))),this.pluginMap.clear();for(let t of this.plugins)t.update(this);this.docView.destroy(),this.docView=new us(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(Ki),i=t.state.facet(Ki);if(e!=i){let s=[];for(let r of i){let i=e.indexOf(r);if(i<0)s.push(new Xi(r));else{let e=this.plugins[i];e.mustUpdate=t,s.push(e)}}for(let e of this.plugins)e.mustUpdate!=t&&e.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let e of this.plugins)e.mustUpdate=t;for(let t=0;t<this.plugins.length;t++)this.plugins[t].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(t){Ui(this.state,t,"doc view update listener")}}}measure(t=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey)return this.measureScheduled=-1,void this.requestMeasure();this.measureScheduled=0,t&&this.observer.forceFlush();let e=null,i=this.scrollDOM,s=i.scrollTop*this.scaleY,{scrollAnchorPos:r,scrollAnchorHeight:n}=this.viewState;Math.abs(s-this.viewState.scrollTop)>1&&(n=-1),this.viewState.scrollAnchorHeight=-1;try{for(let t=0;;t++){if(n<0)if(ye(i))r=-1,n=this.viewState.heightMap.height;else{let t=this.viewState.scrollAnchorAt(s);r=t.from,n=t.top}this.updateState=1;let h=this.viewState.measure(this);if(!h&&!this.measureRequests.length&&null==this.viewState.scrollTarget)break;if(t>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let l=[];4&h||([this.measureRequests,l]=[l,this.measureRequests]);let o=l.map((t=>{try{return t.read(this)}catch(t){return Ui(this.state,t),Gr}})),u=os.create(this,this.state,[]),f=!1;u.flags|=h,e?e.flags|=h:e=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),f=this.docView.update(u),f&&this.docViewUpdate());for(let t=0;t<l.length;t++)if(o[t]!=Gr)try{let e=l[t];e.write&&e.write(o[t],this)}catch(t){Ui(this.state,t)}if(f&&this.docView.updateSelection(!0),!u.viewportChanged&&0==this.measureRequests.length){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,n=-1;continue}{let t=(r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-n;if(t>1||t<-1){s+=t,i.scrollTop=s/this.scaleY,n=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(e&&!e.empty)for(let t of this.state.facet($i))t(e)}get themeClasses(){return Dr+" "+(this.state.facet(Or)?Ir:Er)+" "+this.state.facet(Cr)}updateAttrs(){let t=_r(this,Yi,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),e={spellcheck:"false",autocorrect:"off",autocapitalize:"off",translate:"no",contenteditable:this.state.facet(Ji)?"true":"false",class:"cm-content",style:`${Ve.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(e["aria-readonly"]="true"),_r(this,Qi,e);let i=this.observer.ignore((()=>{let i=Ze(this.contentDOM,this.contentAttrs,e),s=Ze(this.dom,this.editorAttrs,t);return i||s}));return this.editorAttrs=t,this.contentAttrs=e,i}showAnnouncements(t){let e=!0;for(let i of t)for(let t of i.effects)if(t.is(Ur.announce)){e&&(this.announceDOM.textContent=""),e=!1,this.announceDOM.appendChild(document.createElement("div")).textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(hs);let t=this.state.facet(Ur.cspNonce);Gt.mount(this.root,this.styleModules.concat(Br).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(2==this.updateState)throw new Error("Reading the editor layout isn't allowed during an update");0==this.updateState&&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(null!=t.key)for(let e=0;e<this.measureRequests.length;e++)if(this.measureRequests[e].key===t.key)return void(this.measureRequests[e]=t);this.measureRequests.push(t)}}plugin(t){let e=this.pluginMap.get(t);return(void 0===e||e&&e.spec!=t)&&this.pluginMap.set(t,e=this.plugins.find((e=>e.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 As(this,t,xs(this,t,e,i))}moveByGroup(t,e){return As(this,t,xs(this,t,e,(e=>function(t,e,i){let s=t.state.charCategorizer(e),r=s(i);return t=>{let e=s(t);return r==kt.Space&&(r=e),r==e}}(this,t.head,e))))}visualLineSide(t,e){let i=this.bidiSpans(t),s=this.textDirectionAt(t.from),r=i[e?i.length-1:0];return B.cursor(r.side(e,s)+t.from,r.forward(!e,s)?1:-1)}moveToLineBoundary(t,e,i=!0){return function(t,e,i,s){let r=Ms(t,e.head),n=s&&r.type==ri.Text&&(t.lineWrapping||r.widgetLineBreaks)?t.coordsAtPos(e.assoc<0&&e.head>r.from?e.head-1:e.head):null;if(n){let e=t.dom.getBoundingClientRect(),s=t.textDirectionAt(r.from),h=t.posAtCoords({x:i==(s==pi.LTR)?e.right-1:e.left+1,y:(n.top+n.bottom)/2});if(null!=h)return B.cursor(h,i?-1:1)}return B.cursor(i?r.to:r.from,i?-1:1)}(this,t,e,i)}moveVertically(t,e,i){return As(this,t,function(t,e,i,s){let r=e.head,n=i?1:-1;if(r==(i?t.state.doc.length:0))return B.cursor(r,e.assoc);let h,l=e.goalColumn,o=t.contentDOM.getBoundingClientRect(),u=t.coordsAtPos(r,e.assoc||-1),f=t.documentTop;if(u)null==l&&(l=u.left-o.left),h=n<0?u.top:u.bottom;else{let e=t.viewState.lineBlockAt(r);null==l&&(l=Math.min(o.right-o.left,t.defaultCharacterWidth*(r-e.from))),h=(n<0?e.top:e.bottom)+f}let a=o.left+l,c=null!=s?s:t.viewState.heightOracle.textHeight>>1;for(let e=0;;e+=10){let i=h+(c+e)*n,s=ks(t,{x:a,y:i},!1,n);if(i<o.top||i>o.bottom||(n<0?s<r:s>r)){let e=t.docView.coordsForChar(s),r=!e||i<e.top?-1:1;return B.cursor(s,r,void 0,l)}}}(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(),ks(this,t,e)}coordsAtPos(t,e=1){this.readMeasured();let i=this.docView.coordsAt(t,e);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(t),r=this.bidiSpans(s);return ae(i,r[Si.find(r,t-s.from,-1,e)].dir==pi.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(Hi)||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>Jr)return Ei(t.length);let e,i=this.textDirectionAt(t.from);for(let s of this.bidiCache)if(s.from==t.from&&s.dir==i&&(s.fresh||Ai(s.isolates,e=ss(this,t))))return s.order;e||(e=ss(this,t));let s=function(t,e,i){if(!t)return[new Si(0,0,e==gi?1:0)];if(e==mi&&!i.length&&!xi.test(t))return Ei(t.length);if(i.length)for(;t.length>Ci.length;)Ci[Ci.length]=256;let s=[],r=e==mi?0:1;return Di(t,r,r,i,0,t.length,s),s}(t.text,i,e);return this.bidiCache.push(new Kr(t.from,t.to,i,e,!0,s)),s}get hasFocus(){var t;return(this.dom.ownerDocument.hasFocus()||Ve.safari&&(null===(t=this.inputState)||void 0===t?void 0:t.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore((()=>{we(this.contentDOM),this.docView.updateSelection()}))}setRoot(t){this._root!=t&&(this._root=t,this.observer.setWindow((9==t.nodeType?t:t.ownerDocument).defaultView||window),this.mountStyles())}destroy(){for(let t of this.plugins)t.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(t,e={}){return qi.of(new Fi("number"==typeof t?B.cursor(t):t,e.y,e.x,e.yMargin,e.xMargin))}scrollSnapshot(){let{scrollTop:t,scrollLeft:e}=this.scrollDOM,i=this.viewState.scrollAnchorAt(t);return qi.of(new Fi(B.cursor(i.from),"start","start",i.top-t,e,!0))}static domEventHandlers(t){return _i.define((()=>({})),{eventHandlers:t})}static domEventObservers(t){return _i.define((()=>({})),{eventObservers:t})}static theme(t,e){let i=Gt.newName(),s=[Cr.of(i),hs.of(Tr(`.${i}`,t))];return e&&e.dark&&s.push(Or.of(!0)),s}static baseTheme(t){return _.lowest(hs.of(Tr("."+Dr,t,Rr)))}static findFromDOM(t){var e;let i=t.querySelector(".cm-content"),s=i&&Ce.get(i)||Ce.get(t);return(null===(e=null==s?void 0:s.rootView)||void 0===e?void 0:e.view)||null}}Ur.styleModule=hs,Ur.inputHandler=zi,Ur.scrollHandler=Vi,Ur.focusChangeEffect=Pi,Ur.perLineTextDirection=Hi,Ur.exceptionSink=ji,Ur.updateListener=$i,Ur.editable=Ji,Ur.mouseSelectionStyle=Ni,Ur.dragMovesSelection=Li,Ur.clickAddsSelectionRange=Bi,Ur.decorations=Zi,Ur.outerDecorations=ts,Ur.atomicRanges=es,Ur.bidiIsolatedRanges=is,Ur.scrollMargins=rs,Ur.darkTheme=Or,Ur.cspNonce=j.define({combine:t=>t.length?t[0]:""}),Ur.contentAttributes=Qi,Ur.editorAttributes=Yi,Ur.lineWrapping=Ur.contentAttributes.of({class:"cm-lineWrapping"}),Ur.announce=ct.define();const Jr=4096,Gr={};class Kr{constructor(t,e,i,s,r,n){this.from=t,this.to=e,this.dir=i,this.isolates=s,this.fresh=r,this.order=n}static update(t,e){if(e.empty&&!t.some((t=>t.fresh)))return t;let i=[],s=t.length?t[t.length-1].dir:pi.LTR;for(let r=Math.max(0,t.length-10);r<t.length;r++){let n=t[r];n.dir!=s||e.touchesRange(n.from,n.to)||i.push(new Kr(e.mapPos(n.from,1),e.mapPos(n.to,-1),n.dir,n.isolates,!1,n.order))}return i}}function _r(t,e,i){for(let s=t.state.facet(e),r=s.length-1;r>=0;r--){let e=s[r],n="function"==typeof e?e(t):e;n&&Xe(n,i)}return i}const Xr=Ve.mac?"mac":Ve.windows?"win":Ve.linux?"linux":"key";function Yr(t,e,i){return e.altKey&&(t="Alt-"+t),e.ctrlKey&&(t="Ctrl-"+t),e.metaKey&&(t="Meta-"+t),!1!==i&&e.shiftKey&&(t="Shift-"+t),t}const Qr=_.default(Ur.domEventHandlers({keydown:(t,e)=>nn(en(e.state),t,e,"editor")})),Zr=j.define({enables:Qr}),tn=new WeakMap;function en(t){let e=t.facet(Zr),i=tn.get(e);return i||tn.set(e,i=function(t,e=Xr){let i=Object.create(null),s=Object.create(null),r=(t,e)=>{let i=s[t];if(null==i)s[t]=e;else if(i!=e)throw new Error("Key binding "+t+" is used both as a regular binding and as a multi-stroke prefix")},n=(t,s,n,h,l)=>{var o,u;let f=i[t]||(i[t]=Object.create(null)),a=s.split(/ (?!$)/).map((t=>function(t,e){const i=t.split(/-(?!$)/);let s,r,n,h,l=i[i.length-1];"Space"==l&&(l=" ");for(let t=0;t<i.length-1;++t){const l=i[t];if(/^(cmd|meta|m)$/i.test(l))h=!0;else if(/^a(lt)?$/i.test(l))s=!0;else if(/^(c|ctrl|control)$/i.test(l))r=!0;else if(/^s(hift)?$/i.test(l))n=!0;else{if(!/^mod$/i.test(l))throw new Error("Unrecognized modifier name: "+l);"mac"==e?h=!0:r=!0}}return s&&(l="Alt-"+l),r&&(l="Ctrl-"+l),h&&(l="Meta-"+l),n&&(l="Shift-"+l),l}(t,e)));for(let e=1;e<a.length;e++){let i=a.slice(0,e).join(" ");r(i,!0),f[i]||(f[i]={preventDefault:!0,stopPropagation:!1,run:[e=>{let s=sn={view:e,prefix:i,scope:t};return setTimeout((()=>{sn==s&&(sn=null)}),rn),!0}]})}let c=a.join(" ");r(c,!1);let d=f[c]||(f[c]={preventDefault:!1,stopPropagation:!1,run:(null===(u=null===(o=f._any)||void 0===o?void 0:o.run)||void 0===u?void 0:u.slice())||[]});n&&d.run.push(n),h&&(d.preventDefault=!0),l&&(d.stopPropagation=!0)};for(let s of t){let t=s.scope?s.scope.split(" "):["editor"];if(s.any)for(let e of t){let t=i[e]||(i[e]=Object.create(null));t._any||(t._any={preventDefault:!1,stopPropagation:!1,run:[]});for(let e in t)t[e].run.push(s.any)}let r=s[e]||s.key;if(r)for(let e of t)n(e,r,s.run,s.preventDefault,s.stopPropagation),s.shift&&n(e,"Shift-"+r,s.shift,s.preventDefault,s.stopPropagation)}return i}(e.reduce(((t,e)=>t.concat(e)),[]))),i}let sn=null;const rn=4e3;function nn(t,e,i,s){let r=function(t){var e=!(Qt&&t.metaKey&&t.shiftKey&&!t.ctrlKey&&!t.altKey||Zt&&t.shiftKey&&t.key&&1==t.key.length||"Unidentified"==t.key)&&t.key||(t.shiftKey?Yt:Xt)[t.keyCode]||t.key||"Unidentified";return"Esc"==e&&(e="Escape"),"Del"==e&&(e="Delete"),"Left"==e&&(e="ArrowLeft"),"Up"==e&&(e="ArrowUp"),"Right"==e&&(e="ArrowRight"),"Down"==e&&(e="ArrowDown"),e}(e),n=y(v(r,0))==r.length&&" "!=r,h="",l=!1,o=!1,u=!1;sn&&sn.view==i&&sn.scope==s&&(h=sn.prefix+" ",Rs.indexOf(e.keyCode)<0&&(o=!0,sn=null));let f,a,c=new Set,d=t=>{if(t){for(let s of t.run)if(!c.has(s)&&(c.add(s),s(i,e)))return t.stopPropagation&&(u=!0),!0;t.preventDefault&&(t.stopPropagation&&(u=!0),o=!0)}return!1},p=t[s];return p&&(d(p[h+Yr(r,e,!n)])?l=!0:n&&(e.altKey||e.metaKey||e.ctrlKey)&&!(Ve.windows&&e.ctrlKey&&e.altKey)&&(f=Xt[e.keyCode])&&f!=r?(d(p[h+Yr(f,e,!0)])||e.shiftKey&&(a=Yt[e.keyCode])!=r&&a!=f&&d(p[h+Yr(a,e,!1)]))&&(l=!0):n&&e.shiftKey&&d(p[h+Yr(r,e,!0)])&&(l=!0),!l&&d(p._any)&&(l=!0)),o&&(l=!0),l&&u&&e.stopPropagation(),l}class hn{constructor(t,e,i,s,r){this.className=t,this.left=e,this.top=i,this.width=s,this.height=r}draw(){let t=document.createElement("div");return t.className=this.className,this.adjust(t),t}update(t,e){return e.className==this.className&&(this.adjust(t),!0)}adjust(t){t.style.left=this.left+"px",t.style.top=this.top+"px",null!=this.width&&(t.style.width=this.width+"px"),t.style.height=this.height+"px"}eq(t){return this.left==t.left&&this.top==t.top&&this.width==t.width&&this.height==t.height&&this.className==t.className}static forRange(t,e,i){if(i.empty){let s=t.coordsAtPos(i.head,i.assoc||1);if(!s)return[];let r=ln(t);return[new hn(e,s.left-r.left,s.top-r.top,null,s.bottom-s.top)]}return function(t,e,i){if(i.to<=t.viewport.from||i.from>=t.viewport.to)return[];let s=Math.max(i.from,t.viewport.from),r=Math.min(i.to,t.viewport.to),n=t.textDirection==pi.LTR,h=t.contentDOM,l=h.getBoundingClientRect(),o=ln(t),u=h.querySelector(".cm-line"),f=u&&window.getComputedStyle(u),a=l.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),c=l.right-(f?parseInt(f.paddingRight):0),d=Ms(t,s),p=Ms(t,r),m=d.type==ri.Text?d:null,g=p.type==ri.Text?p:null;m&&(t.lineWrapping||d.widgetLineBreaks)&&(m=on(t,s,m));g&&(t.lineWrapping||p.widgetLineBreaks)&&(g=on(t,r,g));if(m&&g&&m.from==g.from)return b(v(i.from,i.to,m));{let e=m?v(i.from,null,m):k(d,!1),s=g?v(null,i.to,g):k(p,!0),r=[];return(m||d).to<(g||p).from-(m&&g?1:0)||d.widgetLineBreaks>1&&e.bottom+t.defaultLineHeight/2<s.top?r.push(w(a,e.bottom,c,s.top)):e.bottom<s.top&&t.elementAtHeight((e.bottom+s.top)/2).type==ri.Text&&(e.bottom=s.top=(e.bottom+s.top)/2),b(e).concat(r).concat(b(s))}function w(t,i,s,r){return new hn(e,t-o.left,i-o.top-.01,s-t,r-i+.01)}function b({top:t,bottom:e,horizontal:i}){let s=[];for(let r=0;r<i.length;r+=2)s.push(w(i[r],t,i[r+1],e));return s}function v(e,i,s){let r=1e9,h=-1e9,l=[];function o(e,i,o,u,f){let d=t.coordsAtPos(e,e==s.to?-2:2),p=t.coordsAtPos(o,o==s.from?2:-2);d&&p&&(r=Math.min(d.top,p.top,r),h=Math.max(d.bottom,p.bottom,h),f==pi.LTR?l.push(n&&i?a:d.left,n&&u?c:p.right):l.push(!n&&u?a:p.left,!n&&i?c:d.right))}let u=null!=e?e:s.from,f=null!=i?i:s.to;for(let s of t.visibleRanges)if(s.to>u&&s.from<f)for(let r=Math.max(s.from,u),n=Math.min(s.to,f);;){let s=t.state.doc.lineAt(r);for(let h of t.bidiSpans(s)){let t=h.from+s.from,l=h.to+s.from;if(t>=n)break;l>r&&o(Math.max(t,r),null==e&&t<=u,Math.min(l,n),null==i&&l>=f,h.dir)}if(r=s.to+1,r>=n)break}return 0==l.length&&o(u,null==e,f,null==i,t.textDirection),{top:r,bottom:h,horizontal:l}}function k(t,e){let i=l.top+(e?t.top:t.bottom);return{top:i,bottom:i,horizontal:[]}}}(t,e,i)}}function ln(t){let e=t.scrollDOM.getBoundingClientRect();return{left:(t.textDirection==pi.LTR?e.left:e.right-t.scrollDOM.clientWidth*t.scaleX)-t.scrollDOM.scrollLeft*t.scaleX,top:e.top-t.scrollDOM.scrollTop*t.scaleY}}function on(t,e,i){let s=B.cursor(e);return{from:Math.max(i.from,t.moveToLineBoundary(s,!1,!0).from),to:Math.min(i.to,t.moveToLineBoundary(s,!0,!0).from),type:ri.Text}}class un{constructor(t,e){this.view=t,this.layer=e,this.drawn=[],this.scaleX=1,this.scaleY=1,this.measureReq={read:this.measure.bind(this),write:this.draw.bind(this)},this.dom=t.scrollDOM.appendChild(document.createElement("div")),this.dom.classList.add("cm-layer"),e.above&&this.dom.classList.add("cm-layer-above"),e.class&&this.dom.classList.add(e.class),this.scale(),this.dom.setAttribute("aria-hidden","true"),this.setOrder(t.state),t.requestMeasure(this.measureReq),e.mount&&e.mount(this.dom,t)}update(t){t.startState.facet(fn)!=t.state.facet(fn)&&this.setOrder(t.state),(this.layer.update(t,this.dom)||t.geometryChanged)&&(this.scale(),t.view.requestMeasure(this.measureReq))}docViewUpdate(t){!1!==this.layer.updateOnDocViewUpdate&&t.requestMeasure(this.measureReq)}setOrder(t){let e=0,i=t.facet(fn);for(;e<i.length&&i[e]!=this.layer;)e++;this.dom.style.zIndex=String((this.layer.above?150:-1)-e)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:t,scaleY:e}=this.view;t==this.scaleX&&e==this.scaleY||(this.scaleX=t,this.scaleY=e,this.dom.style.transform=`scale(${1/t}, ${1/e})`)}draw(t){if(t.length!=this.drawn.length||t.some(((t,e)=>{return i=t,s=this.drawn[e],!(i.constructor==s.constructor&&i.eq(s));var i,s}))){let e=this.dom.firstChild,i=0;for(let s of t)s.update&&e&&s.constructor&&this.drawn[i].constructor&&s.update(e,this.drawn[i])?(e=e.nextSibling,i++):this.dom.insertBefore(s.draw(),e);for(;e;){let t=e.nextSibling;e.remove(),e=t}this.drawn=t}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const fn=j.define();function an(t){return[_i.define((e=>new un(e,t))),fn.of(t)]}const cn=!Ve.ios,dn=j.define({combine:t=>At(t,{cursorBlinkRate:1200,drawRangeCursor:!0},{cursorBlinkRate:(t,e)=>Math.min(t,e),drawRangeCursor:(t,e)=>t||e})});function pn(t){return t.startState.facet(dn)!=t.state.facet(dn)}const mn=an({above:!0,markers(t){let{state:e}=t,i=e.facet(dn),s=[];for(let r of e.selection.ranges){let n=r==e.selection.main;if(r.empty?!n||cn:i.drawRangeCursor){let e=n?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",i=r.empty?r:B.cursor(r.head,r.head>r.anchor?-1:1);for(let r of hn.forRange(t,e,i))s.push(r)}}return s},update(t,e){t.transactions.some((t=>t.selection))&&(e.style.animationName="cm-blink"==e.style.animationName?"cm-blink2":"cm-blink");let i=pn(t);return i&&gn(t.state,e),t.docChanged||t.selectionSet||i},mount(t,e){gn(e.state,t)},class:"cm-cursorLayer"});function gn(t,e){e.style.animationDuration=t.facet(dn).cursorBlinkRate+"ms"}const wn=an({above:!1,markers:t=>t.state.selection.ranges.map((e=>e.empty?[]:hn.forRange(t,"cm-selectionBackground",e))).reduce(((t,e)=>t.concat(e))),update:(t,e)=>t.docChanged||t.selectionSet||t.viewportChanged||pn(t),class:"cm-selectionLayer"}),bn={".cm-line":{"& ::selection":{backgroundColor:"transparent !important"},"&::selection":{backgroundColor:"transparent !important"}}};cn&&(bn[".cm-line"].caretColor="transparent !important",bn[".cm-content"]={caretColor:"transparent !important"});const vn=_.highest(Ur.theme(bn)),kn=ct.define({map:(t,e)=>null==t?null:e.mapPos(t)}),yn=F.define({create:()=>null,update:(t,e)=>(null!=t&&(t=e.changes.mapPos(t)),e.effects.reduce(((t,e)=>e.is(kn)?e.value:t),t))}),Mn=_i.fromClass(class{constructor(t){this.view=t,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(t){var e;let i=t.state.field(yn);null==i?null!=this.cursor&&(null===(e=this.cursor)||void 0===e||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(t.startState.field(yn)!=i||t.docChanged||t.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:t}=this,e=t.state.field(yn),i=null!=e&&t.coordsAtPos(e);if(!i)return null;let s=t.scrollDOM.getBoundingClientRect();return{left:i.left-s.left+t.scrollDOM.scrollLeft*t.scaleX,top:i.top-s.top+t.scrollDOM.scrollTop*t.scaleY,height:i.bottom-i.top}}drawCursor(t){if(this.cursor){let{scaleX:e,scaleY:i}=this.view;t?(this.cursor.style.left=t.left/e+"px",this.cursor.style.top=t.top/i+"px",this.cursor.style.height=t.height/i+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(t){this.view.state.field(yn)!=t&&this.view.dispatch({effects:kn.of(t)})}},{eventObservers:{dragover(t){this.setDropPos(this.view.posAtCoords({x:t.clientX,y:t.clientY}))},dragleave(t){t.target!=this.view.contentDOM&&this.view.contentDOM.contains(t.relatedTarget)||this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function xn(t,e,i,s,r){e.lastIndex=0;for(let n,h=t.iterRange(i,s),l=i;!h.next().done;l+=h.value.length)if(!h.lineBreak)for(;n=e.exec(h.value);)r(l+n.index,n)}class Sn{constructor(t){const{regexp:e,decoration:i,decorate:s,boundary:r,maxLength:n=1e3}=t;if(!e.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=e,s)this.addMatch=(t,e,i,r)=>s(r,i,i+t[0].length,t,e);else if("function"==typeof i)this.addMatch=(t,e,s,r)=>{let n=i(t,e,s);n&&r(s,s+t[0].length,n)};else{if(!i)throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.addMatch=(t,e,s,r)=>r(s,s+t[0].length,i)}this.boundary=r,this.maxLength=n}createDeco(t){let e=new Rt,i=e.add.bind(e);for(let{from:e,to:s}of function(t,e){let i=t.visibleRanges;if(1==i.length&&i[0].from==t.viewport.from&&i[0].to==t.viewport.to)return i;let s=[];for(let{from:r,to:n}of i)r=Math.max(t.state.doc.lineAt(r).from,r-e),n=Math.min(t.state.doc.lineAt(n).to,n+e),s.length&&s[s.length-1].to>=r?s[s.length-1].to=n:s.push({from:r,to:n});return s}(t,this.maxLength))xn(t.state.doc,this.regexp,e,s,((e,s)=>this.addMatch(s,t,e,i)));return e.finish()}updateDeco(t,e){let i=1e9,s=-1;return t.docChanged&&t.changes.iterChanges(((e,r,n,h)=>{h>t.view.viewport.from&&n<t.view.viewport.to&&(i=Math.min(n,i),s=Math.max(h,s))})),t.viewportChanged||s-i>1e3?this.createDeco(t.view):s>-1?this.updateRange(t.view,e.map(t.changes),i,s):e}updateRange(t,e,i,s){for(let r of t.visibleRanges){let n=Math.max(r.from,i),h=Math.min(r.to,s);if(h>n){let i=t.state.doc.lineAt(n),s=i.to<h?t.state.doc.lineAt(h):i,l=Math.max(r.from,i.from),o=Math.min(r.to,s.to);if(this.boundary){for(;n>i.from;n--)if(this.boundary.test(i.text[n-1-i.from])){l=n;break}for(;h<s.to;h++)if(this.boundary.test(s.text[h-s.from])){o=h;break}}let u,f=[],a=(t,e,i)=>f.push(i.range(t,e));if(i==s)for(this.regexp.lastIndex=l-i.from;(u=this.regexp.exec(i.text))&&u.index<o-i.from;)this.addMatch(u,t,u.index+i.from,a);else xn(t.state.doc,this.regexp,l,o,((e,i)=>this.addMatch(i,t,e,a)));e=e.update({filterFrom:l,filterTo:o,filter:(t,e)=>t<l||e>o,add:f})}}return e}}const An=null!=/x/.unicode?"gu":"g",Cn=new RegExp("[\0-\b\n--\u2028\u2029\ufeff-]",An),On={0:"null",7:"bell",8:"backspace",10:"newline",11:"vertical tab",13:"carriage return",27:"escape",8203:"zero width space",8204:"zero width non-joiner",8205:"zero width joiner",8206:"left-to-right mark",8207:"right-to-left mark",8232:"line separator",8237:"left-to-right override",8238:"right-to-left override",8294:"left-to-right isolate",8295:"right-to-left isolate",8297:"pop directional isolate",8233:"paragraph separator",65279:"zero width no-break space",65532:"object replacement"};let Dn=null;const En=j.define({combine(t){let e=At(t,{render:null,specialChars:Cn,addSpecialChars:null});return(e.replaceTabs=!function(){var t;if(null==Dn&&"undefined"!=typeof document&&document.body){let e=document.body.style;Dn=null!=(null!==(t=e.tabSize)&&void 0!==t?t:e.MozTabSize)}return Dn||!1}())&&(e.specialChars=new RegExp("\t|"+e.specialChars.source,An)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,An)),e}});let In=null;class Rn extends si{constructor(t,e){super(),this.options=t,this.code=e}eq(t){return t.code==this.code}toDOM(t){let e=function(t){return t>=32?"•":10==t?"":String.fromCharCode(9216+t)}(this.code),i=t.state.phrase("Control character")+" "+(On[this.code]||"0x"+this.code.toString(16)),s=this.options.render&&this.options.render(this.code,i,e);if(s)return s;let r=document.createElement("span");return r.textContent=e,r.title=i,r.setAttribute("aria-label",i),r.className="cm-specialChar",r}ignoreEvent(){return!1}}class Tn extends si{constructor(t){super(),this.width=t}eq(t){return t.width==this.width}toDOM(){let t=document.createElement("span");return t.textContent="\t",t.className="cm-tab",t.style.width=this.width+"px",t}ignoreEvent(){return!1}}const Bn=ni.line({class:"cm-activeLine"}),Ln=_i.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.docChanged||t.selectionSet)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=-1,i=[];for(let s of t.state.selection.ranges){let r=t.lineBlockAt(s.head);r.from>e&&(i.push(Bn.range(r.from)),e=r.from)}return ni.set(i)}},{decorations:t=>t.decorations});class Nn extends si{constructor(t){super(),this.content=t}toDOM(){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild("string"==typeof this.content?document.createTextNode(this.content):this.content),"string"==typeof this.content?t.setAttribute("aria-label","placeholder "+this.content):t.setAttribute("aria-hidden","true"),t}coordsAt(t){let e=t.firstChild?ne(t.firstChild):[];if(!e.length)return null;let i=window.getComputedStyle(t.parentNode),s=ae(e[0],"rtl"!=i.direction),r=parseInt(i.lineHeight);return s.bottom-s.top>1.5*r?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function jn(t){return _i.fromClass(class{constructor(e){this.view=e,this.placeholder=t?ni.set([ni.widget({widget:new Nn(t),side:1}).range(0)]):ni.none}get decorations(){return this.view.state.doc.length?ni.none:this.placeholder}},{decorations:t=>t.decorations})}const $n=2e3;function zn(t,e){let i=t.posAtCoords({x:e.clientX,y:e.clientY},!1),s=t.state.doc.lineAt(i),r=i-s.from,n=r>$n?-1:r==s.length?function(t,e){let i=t.coordsAtPos(t.viewport.from);return i?Math.round(Math.abs((i.left-e)/t.defaultCharacterWidth)):-1}(t,e.clientX):Vt(s.text,t.state.tabSize,i-s.from);return{line:s.number,col:n,off:r}}function Pn(t,e){let i=zn(t,e),s=t.state.selection;return i?{update(t){if(t.docChanged){let e=t.changes.mapPos(t.startState.doc.line(i.line).from),r=t.state.doc.lineAt(e);i={line:r.number,col:i.col,off:Math.min(i.off,r.length)},s=s.map(t.changes)}},get(e,r,n){let h=zn(t,e);if(!h)return s;let l=function(t,e,i){let s=Math.min(e.line,i.line),r=Math.max(e.line,i.line),n=[];if(e.off>$n||i.off>$n||e.col<0||i.col<0){let h=Math.min(e.off,i.off),l=Math.max(e.off,i.off);for(let e=s;e<=r;e++){let i=t.doc.line(e);i.length<=l&&n.push(B.range(i.from+h,i.to+l))}}else{let h=Math.min(e.col,i.col),l=Math.max(e.col,i.col);for(let e=s;e<=r;e++){let i=t.doc.line(e),s=Ft(i.text,h,t.tabSize,!0);if(s<0)n.push(B.cursor(i.to));else{let e=Ft(i.text,l,t.tabSize);n.push(B.range(i.from+s,i.from+e))}}}return n}(t.state,i,h);return l.length?n?B.create(l.concat(s.ranges)):B.create(l):s}}:null}const Hn={Alt:[18,t=>!!t.altKey],Control:[17,t=>!!t.ctrlKey],Shift:[16,t=>!!t.shiftKey],Meta:[91,t=>!!t.metaKey]},Wn={style:"cursor: crosshair"};const Vn="-10000px";class Fn{constructor(t,e,i,s){this.facet=e,this.createTooltipView=i,this.removeTooltipView=s,this.input=t.state.facet(e),this.tooltips=this.input.filter((t=>t));let r=null;this.tooltipViews=this.tooltips.map((t=>r=i(t,r)))}update(t,e){var i;let s=t.state.facet(this.facet),r=s.filter((t=>t));if(s===this.input){for(let e of this.tooltipViews)e.update&&e.update(t);return!1}let n=[],h=e?[]:null;for(let i=0;i<r.length;i++){let s=r[i],l=-1;if(s){for(let t=0;t<this.tooltips.length;t++){let e=this.tooltips[t];e&&e.create==s.create&&(l=t)}if(l<0)n[i]=this.createTooltipView(s,i?n[i-1]:null),h&&(h[i]=!!s.above);else{let s=n[i]=this.tooltipViews[l];h&&(h[i]=e[l]),s.update&&s.update(t)}}}for(let t of this.tooltipViews)n.indexOf(t)<0&&(this.removeTooltipView(t),null===(i=t.destroy)||void 0===i||i.call(t));return e&&(h.forEach(((t,i)=>e[i]=t)),e.length=h.length),this.input=s,this.tooltips=r,this.tooltipViews=n,!0}}function qn(t){let{win:e}=t;return{top:0,left:0,bottom:e.innerHeight,right:e.innerWidth}}const Un=j.define({combine:t=>{var e,i,s;return{position:Ve.ios?"absolute":(null===(e=t.find((t=>t.position)))||void 0===e?void 0:e.position)||"fixed",parent:(null===(i=t.find((t=>t.parent)))||void 0===i?void 0:i.parent)||null,tooltipSpace:(null===(s=t.find((t=>t.tooltipSpace)))||void 0===s?void 0:s.tooltipSpace)||qn}}}),Jn=new WeakMap,Gn=_i.fromClass(class{constructor(t){this.view=t,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=t.state.facet(Un);this.position=e.position,this.parent=e.parent,this.classes=t.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver="function"==typeof ResizeObserver?new ResizeObserver((()=>this.measureSoon())):null,this.manager=new Fn(t,Xn,((t,e)=>this.createTooltip(t,e)),(t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()})),this.above=this.manager.tooltips.map((t=>!!t.above)),this.intersectionObserver="function"==typeof IntersectionObserver?new IntersectionObserver((t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()}),{threshold:[1]}):null,this.observeIntersection(),t.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 t of this.manager.tooltipViews)this.intersectionObserver.observe(t.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout((()=>{this.measureTimeout=-1,this.maybeMeasure()}),50))}update(t){t.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(t,this.above);e&&this.observeIntersection();let i=e||t.geometryChanged,s=t.state.facet(Un);if(s.position!=this.position&&!this.madeAbsolute){this.position=s.position;for(let t of this.manager.tooltipViews)t.dom.style.position=this.position;i=!0}if(s.parent!=this.parent){this.parent&&this.container.remove(),this.parent=s.parent,this.createContainer();for(let t of this.manager.tooltipViews)this.container.appendChild(t.dom);i=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);i&&this.maybeMeasure()}createTooltip(t,e){let i=t.create(this.view),s=e?e.dom:null;if(i.dom.classList.add("cm-tooltip"),t.arrow&&!i.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let t=document.createElement("div");t.className="cm-tooltip-arrow",i.dom.appendChild(t)}return i.dom.style.position=this.position,i.dom.style.top=Vn,i.dom.style.left="0px",this.container.insertBefore(i.dom,s),i.mount&&i.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(i.dom),i}destroy(){var t,e,i;this.view.win.removeEventListener("resize",this.measureSoon);for(let e of this.manager.tooltipViews)e.dom.remove(),null===(t=e.destroy)||void 0===t||t.call(e);this.parent&&this.container.remove(),null===(e=this.resizeObserver)||void 0===e||e.disconnect(),null===(i=this.intersectionObserver)||void 0===i||i.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let t=this.view.dom.getBoundingClientRect(),e=1,i=1,s=!1;if("fixed"==this.position&&this.manager.tooltipViews.length){let{dom:t}=this.manager.tooltipViews[0];if(Ve.gecko)s=t.offsetParent!=this.container.ownerDocument.body;else if(t.style.top==Vn&&"0px"==t.style.left){let e=t.getBoundingClientRect();s=Math.abs(e.top+1e4)>1||Math.abs(e.left)>1}}if(s||"absolute"==this.position)if(this.parent){let t=this.parent.getBoundingClientRect();t.width&&t.height&&(e=t.width/this.parent.offsetWidth,i=t.height/this.parent.offsetHeight)}else({scaleX:e,scaleY:i}=this.view.viewState);return{editor:t,parent:this.parent?this.container.getBoundingClientRect():t,pos:this.manager.tooltips.map(((t,e)=>{let i=this.manager.tooltipViews[e];return i.getCoords?i.getCoords(t.pos):this.view.coordsAtPos(t.pos)})),size:this.manager.tooltipViews.map((({dom:t})=>t.getBoundingClientRect())),space:this.view.state.facet(Un).tooltipSpace(this.view),scaleX:e,scaleY:i,makeAbsolute:s}}writeMeasure(t){var e;if(t.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let t of this.manager.tooltipViews)t.dom.style.position="absolute"}let{editor:i,space:s,scaleX:r,scaleY:n}=t,h=[];for(let l=0;l<this.manager.tooltips.length;l++){let o=this.manager.tooltips[l],u=this.manager.tooltipViews[l],{dom:f}=u,a=t.pos[l],c=t.size[l];if(!a||a.bottom<=Math.max(i.top,s.top)||a.top>=Math.min(i.bottom,s.bottom)||a.right<Math.max(i.left,s.left)-.1||a.left>Math.min(i.right,s.right)+.1){f.style.top=Vn;continue}let d=o.arrow?u.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=c.right-c.left,g=null!==(e=Jn.get(u))&&void 0!==e?e:c.bottom-c.top,w=u.offset||_n,b=this.view.textDirection==pi.LTR,v=c.width>s.right-s.left?b?s.left:s.right-c.width:b?Math.min(a.left-(d?14:0)+w.x,s.right-m):Math.max(s.left,a.left-m+(d?14:0)-w.x),k=this.above[l];!o.strictSide&&(k?a.top-(c.bottom-c.top)-w.y<s.top:a.bottom+(c.bottom-c.top)+w.y>s.bottom)&&k==s.bottom-a.bottom>a.top-s.top&&(k=this.above[l]=!k);let y=(k?a.top-s.top:s.bottom-a.bottom)-p;if(y<g&&!1!==u.resize){if(y<this.view.defaultLineHeight){f.style.top=Vn;continue}Jn.set(u,g),f.style.height=(g=y)/n+"px"}else f.style.height&&(f.style.height="");let M=k?a.top-g-p-w.y:a.bottom+p+w.y,x=v+m;if(!0!==u.overlap)for(let t of h)t.left<x&&t.right>v&&t.top<M+g&&t.bottom>M&&(M=k?t.top-g-2-p:t.bottom+p+2);if("absolute"==this.position?(f.style.top=(M-t.parent.top)/n+"px",f.style.left=(v-t.parent.left)/r+"px"):(f.style.top=M/n+"px",f.style.left=v/r+"px"),d){let t=a.left+(b?w.x:-w.x)-(v+14-7);d.style.left=t/r+"px"}!0!==u.overlap&&h.push({left:v,top:M,right:x,bottom:M+g}),f.classList.toggle("cm-tooltip-above",k),f.classList.toggle("cm-tooltip-below",!k),u.positioned&&u.positioned(t.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 t of this.manager.tooltipViews)t.dom.style.top=Vn}},{eventObservers:{scroll(){this.maybeMeasure()}}}),Kn=Ur.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"}}}),_n={x:0,y:0},Xn=j.define({enables:[Gn,Kn]}),Yn=j.define({combine:t=>t.reduce(((t,e)=>t.concat(e)),[])});class Qn{static create(t){return new Qn(t)}constructor(t){this.view=t,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new Fn(t,Yn,((t,e)=>this.createHostedView(t,e)),(t=>t.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)null===(t=e.destroy)||void 0===t||t.call(e)}passProp(t){let e;for(let i of this.manager.tooltipViews){let s=i[t];if(void 0!==s)if(void 0===e)e=s;else if(e!==s)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 Zn=Xn.compute([Yn],(t=>{let e=t.facet(Yn);return 0===e.length?null:{pos:Math.min(...e.map((t=>t.pos))),end:Math.max(...e.map((t=>{var e;return null!==(e=t.end)&&void 0!==e?e:t.pos}))),create:Qn.create,above:e[0].above,arrow:e.some((t=>t.arrow))}}));class th{constructor(t,e,i,s,r){this.view=t,this.source=e,this.field=i,this.setHover=s,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 s,r=1;if(i instanceof Ue)s=i.posAtStart;else{if(s=t.posAtCoords(e),null==s)return;let i=t.coordsAtPos(s);if(!i||e.y<i.top||e.y>i.bottom||e.x<i.left-t.defaultCharacterWidth||e.x>i.right+t.defaultCharacterWidth)return;let n=t.bidiSpans(t.state.doc.lineAt(s)).find((t=>t.from<=s&&t.to>=s)),h=n&&n.dir==pi.RTL?-1:1;r=e.x<i.left?-h:h}let n=this.source(t,s,r);if(null==n?void 0:n.then){let e=this.pending={pos:s};n.then((i=>{this.pending==e&&(this.pending=null,!i||Array.isArray(i)&&!i.length||t.dispatch({effects:this.setHover.of(Array.isArray(i)?i:[i])}))}),(e=>Ui(t.state,e,"hover tooltip")))}else!n||Array.isArray(n)&&!n.length||t.dispatch({effects:this.setHover.of(Array.isArray(n)?n:[n])})}get tooltip(){let t=this.view.plugin(Gn),e=t?t.manager.tooltips.findIndex((t=>t.create==Qn.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:s,tooltip:r}=this;if(s.length&&r&&!function(t,e){let i=t.getBoundingClientRect();return e.clientX>=i.left-eh&&e.clientX<=i.right+eh&&e.clientY>=i.top-eh&&e.clientY<=i.bottom+eh}(r.dom,t)||this.pending){let{pos:r}=s[0]||this.pending,n=null!==(i=null===(e=s[0])||void 0===e?void 0:e.end)&&void 0!==i?i:r;(r==n?this.view.posAtCoords(this.lastMove)==r:function(t,e,i,s,r,n){let h=t.scrollDOM.getBoundingClientRect(),l=t.documentTop+t.documentPadding.top+t.contentHeight;if(h.left>s||h.right<s||h.top>r||Math.min(h.bottom,l)<r)return!1;let o=t.posAtCoords({x:s,y:r},!1);return o>=e&&o<=i}(this.view,r,n,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:e}=this;e&&e.dom.contains(t.relatedTarget)?this.watchTooltipLeave(e.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 eh=4;function ih(t,e={}){let i=ct.define(),s=F.define({create:()=>[],update(t,s){if(t.length&&(e.hideOnChange&&(s.docChanged||s.selection)?t=[]:e.hideOn&&(t=t.filter((t=>!e.hideOn(s,t)))),s.docChanged)){let e=[];for(let i of t){let t=s.changes.mapPos(i.pos,-1,x.TrackDel);if(null!=t){let r=Object.assign(Object.create(null),i);r.pos=t,null!=r.end&&(r.end=s.changes.mapPos(r.end)),e.push(r)}}t=e}for(let e of s.effects)e.is(i)&&(t=e.value),e.is(rh)&&(t=[]);return t},provide:t=>Yn.from(t)});return[s,_i.define((r=>new th(r,t,s,i,e.hoverTime||300))),Zn]}function sh(t,e){let i=t.plugin(Gn);if(!i)return null;let s=i.manager.tooltips.indexOf(e);return s<0?null:i.manager.tooltipViews[s]}const rh=ct.define(),nh=j.define({combine(t){let e,i;for(let s of t)e=e||s.topContainer,i=i||s.bottomContainer;return{topContainer:e,bottomContainer:i}}});function hh(t,e){let i=t.plugin(lh),s=i?i.specs.indexOf(e):-1;return s>-1?i.panels[s]:null}const lh=_i.fromClass(class{constructor(t){this.input=t.state.facet(fh),this.specs=this.input.filter((t=>t)),this.panels=this.specs.map((e=>e(t)));let e=t.state.facet(nh);this.top=new oh(t,!0,e.topContainer),this.bottom=new oh(t,!1,e.bottomContainer),this.top.sync(this.panels.filter((t=>t.top))),this.bottom.sync(this.panels.filter((t=>!t.top)));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(t){let e=t.state.facet(nh);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new oh(t.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new oh(t.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let i=t.state.facet(fh);if(i!=this.input){let e=i.filter((t=>t)),s=[],r=[],n=[],h=[];for(let i of e){let e,l=this.specs.indexOf(i);l<0?(e=i(t.view),h.push(e)):(e=this.panels[l],e.update&&e.update(t)),s.push(e),(e.top?r:n).push(e)}this.specs=e,this.panels=s,this.top.sync(r),this.bottom.sync(n);for(let t of h)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}else for(let e of this.panels)e.update&&e.update(t)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:t=>Ur.scrollMargins.of((e=>{let i=e.plugin(t);return i&&{top:i.top.scrollMargin(),bottom:i.bottom.scrollMargin()}}))});class oh{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(0==this.panels.length)return void(this.dom&&(this.dom.remove(),this.dom=void 0));if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let t=this.dom.firstChild;for(let e of this.panels)if(e.dom.parentNode==this.dom){for(;t!=e.dom;)t=uh(t);t=t.nextSibling}else this.dom.insertBefore(e.dom,t);for(;t;)t=uh(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 uh(t){let e=t.nextSibling;return t.remove(),e}const fh=j.define({enables:lh});class ah extends Ct{compare(t){return this==t||this.constructor==t.constructor&&this.eq(t)}eq(t){return!1}destroy(t){}}ah.prototype.elementClass="",ah.prototype.toDOM=void 0,ah.prototype.mapMode=x.TrackBefore,ah.prototype.startSide=ah.prototype.endSide=-1,ah.prototype.point=!0;const ch=j.define(),dh={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>It.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{}},ph=j.define();function mh(t){return[wh(),ph.of(Object.assign(Object.assign({},dh),t))]}const gh=j.define({combine:t=>t.some((t=>t))});function wh(t){let e=[bh];return t&&!1===t.fixed&&e.push(gh.of(!0)),e}const bh=_i.fromClass(class{constructor(t){this.view=t,this.prevViewport=t.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=t.state.facet(ph).map((e=>new Mh(t,e)));for(let t of this.gutters)this.dom.appendChild(t.dom);this.fixed=!t.state.facet(gh),this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),t.scrollDOM.insertBefore(this.dom,t.contentDOM)}update(t){if(this.updateGutters(t)){let e=this.prevViewport,i=t.view.viewport,s=Math.min(e.to,i.to)-Math.max(e.from,i.from);this.syncGutters(s<.8*(i.to-i.from))}t.geometryChanged&&(this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px"),this.view.state.facet(gh)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":""),this.prevViewport=t.view.viewport}syncGutters(t){let e=this.dom.nextSibling;t&&this.dom.remove();let i=It.iter(this.view.state.facet(ch),this.view.viewport.from),s=[],r=this.gutters.map((t=>new yh(t,this.view.viewport,-this.view.documentPadding.top)));for(let t of this.view.viewportLineBlocks)if(s.length&&(s=[]),Array.isArray(t.type)){let e=!0;for(let n of t.type)if(n.type==ri.Text&&e){kh(i,s,n.from);for(let t of r)t.line(this.view,n,s);e=!1}else if(n.widget)for(let t of r)t.widget(this.view,n)}else if(t.type==ri.Text){kh(i,s,t.from);for(let e of r)e.line(this.view,t,s)}else if(t.widget)for(let e of r)e.widget(this.view,t);for(let t of r)t.finish();t&&this.view.scrollDOM.insertBefore(this.dom,e)}updateGutters(t){let e=t.startState.facet(ph),i=t.state.facet(ph),s=t.docChanged||t.heightChanged||t.viewportChanged||!It.eq(t.startState.facet(ch),t.state.facet(ch),t.view.viewport.from,t.view.viewport.to);if(e==i)for(let e of this.gutters)e.update(t)&&(s=!0);else{s=!0;let r=[];for(let s of i){let i=e.indexOf(s);i<0?r.push(new Mh(this.view,s)):(this.gutters[i].update(t),r.push(this.gutters[i]))}for(let t of this.gutters)t.dom.remove(),r.indexOf(t)<0&&t.destroy();for(let t of r)this.dom.appendChild(t.dom);this.gutters=r}return s}destroy(){for(let t of this.gutters)t.destroy();this.dom.remove()}},{provide:t=>Ur.scrollMargins.of((e=>{let i=e.plugin(t);return i&&0!=i.gutters.length&&i.fixed?e.textDirection==pi.LTR?{left:i.dom.offsetWidth*e.scaleX}:{right:i.dom.offsetWidth*e.scaleX}:null}))});function vh(t){return Array.isArray(t)?t:[t]}function kh(t,e,i){for(;t.value&&t.from<=i;)t.from==i&&e.push(t.value),t.next()}class yh{constructor(t,e,i){this.gutter=t,this.height=i,this.i=0,this.cursor=It.iter(t.markers,e.from)}addElement(t,e,i){let{gutter:s}=this,r=(e.top-this.height)/t.scaleY,n=e.height/t.scaleY;if(this.i==s.elements.length){let e=new xh(t,n,r,i);s.elements.push(e),s.dom.appendChild(e.dom)}else s.elements[this.i].update(t,n,r,i);this.height=e.bottom,this.i++}line(t,e,i){let s=[];kh(this.cursor,s,e.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(t,e,s);r&&s.unshift(r);let n=this.gutter;(0!=s.length||n.config.renderEmptyElements)&&this.addElement(t,e,s)}widget(t,e){let i=this.gutter.config.widgetMarker(t,e.widget,e);i&&this.addElement(t,e,[i])}finish(){let t=this.gutter;for(;t.elements.length>this.i;){let e=t.elements.pop();t.dom.removeChild(e.dom),e.destroy()}}}class Mh{constructor(t,e){this.view=t,this.config=e,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in e.domEventHandlers)this.dom.addEventListener(i,(s=>{let r,n=s.target;if(n!=this.dom&&this.dom.contains(n)){for(;n.parentNode!=this.dom;)n=n.parentNode;let t=n.getBoundingClientRect();r=(t.top+t.bottom)/2}else r=s.clientY;let h=t.lineBlockAtHeight(r-t.documentTop);e.domEventHandlers[i](t,h,s)&&s.preventDefault()}));this.markers=vh(e.markers(t)),e.initialSpacer&&(this.spacer=new xh(t,0,0,[e.initialSpacer(t)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(t){let e=this.markers;if(this.markers=vh(this.config.markers(t.view)),this.spacer&&this.config.updateSpacer){let e=this.config.updateSpacer(this.spacer.markers[0],t);e!=this.spacer.markers[0]&&this.spacer.update(t.view,0,0,[e])}let i=t.view.viewport;return!It.eq(this.markers,e,i.from,i.to)||!!this.config.lineMarkerChange&&this.config.lineMarkerChange(t)}destroy(){for(let t of this.elements)t.destroy()}}class xh{constructor(t,e,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(t,e,i,s)}update(t,e,i,s){this.height!=e&&(this.height=e,this.dom.style.height=e+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),function(t,e){if(t.length!=e.length)return!1;for(let i=0;i<t.length;i++)if(!t[i].compare(e[i]))return!1;return!0}(this.markers,s)||this.setMarkers(t,s)}setMarkers(t,e){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,n=0;;){let h=n,l=r<e.length?e[r++]:null,o=!1;if(l){let t=l.elementClass;t&&(i+=" "+t);for(let t=n;t<this.markers.length;t++)if(this.markers[t].compare(l)){h=t,o=!0;break}}else h=this.markers.length;for(;n<h;){let t=this.markers[n++];if(t.toDOM){t.destroy(s);let e=s.nextSibling;s.remove(),s=e}}if(!l)break;l.toDOM&&(o?s=s.nextSibling:this.dom.insertBefore(l.toDOM(t),s)),o&&n++}this.dom.className=i,this.markers=e}destroy(){this.setMarkers(null,[])}}const Sh=j.define(),Ah=j.define({combine:t=>At(t,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(t,e){let i=Object.assign({},t);for(let t in e){let s=i[t],r=e[t];i[t]=s?(t,e,i)=>s(t,e,i)||r(t,e,i):r}return i}})});class Ch extends ah{constructor(t){super(),this.number=t}eq(t){return this.number==t.number}toDOM(){return document.createTextNode(this.number)}}function Oh(t,e){return t.state.facet(Ah).formatNumber(e,t.state)}const Dh=ph.compute([Ah],(t=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers:t=>t.state.facet(Sh),lineMarker:(t,e,i)=>i.some((t=>t.toDOM))?null:new Ch(Oh(t,t.state.doc.lineAt(e.from).number)),widgetMarker:()=>null,lineMarkerChange:t=>t.startState.facet(Ah)!=t.state.facet(Ah),initialSpacer:t=>new Ch(Oh(t,Ih(t.state.doc.lines))),updateSpacer(t,e){let i=Oh(e.view,Ih(e.view.state.doc.lines));return i==t.number?t:new Ch(i)},domEventHandlers:t.facet(Ah).domEventHandlers})));function Eh(t={}){return[Ah.of(t),wh(),Dh]}function Ih(t){let e=9;for(;e<t;)e=10*e+9;return e}const Rh=new class extends ah{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},Th=ch.compute(["selection"],(t=>{let e=[],i=-1;for(let s of t.selection.ranges){let r=t.doc.lineAt(s.head).from;r>i&&(i=r,e.push(Rh.range(r)))}return It.of(e)}));const Bh=1024;let Lh=0;class Nh{constructor(t,e){this.from=t,this.to=e}}class jh{constructor(t={}){this.id=Lh++,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"function"!=typeof t&&(t=Ph.match(t)),e=>{let i=t(e);return void 0===i?null:[this,i]}}}jh.closedBy=new jh({deserialize:t=>t.split(" ")}),jh.openedBy=new jh({deserialize:t=>t.split(" ")}),jh.group=new jh({deserialize:t=>t.split(" ")}),jh.isolate=new jh({deserialize:t=>{if(t&&"rtl"!=t&&"ltr"!=t&&"auto"!=t)throw new RangeError("Invalid value for isolate: "+t);return t||"auto"}}),jh.contextHash=new jh({perNode:!0}),jh.lookAhead=new jh({perNode:!0}),jh.mounted=new jh({perNode:!0});class $h{constructor(t,e,i){this.tree=t,this.overlay=e,this.parser=i}static get(t){return t&&t.props&&t.props[jh.mounted.id]}}const zh=Object.create(null);class Ph{constructor(t,e,i,s=0){this.name=t,this.props=e,this.id=i,this.flags=s}static define(t){let e=t.props&&t.props.length?Object.create(null):zh,i=(t.top?1:0)|(t.skipped?2:0)|(t.error?4:0)|(null==t.name?8:0),s=new Ph(t.name||"",e,t.id,i);if(t.props)for(let i of t.props)if(Array.isArray(i)||(i=i(s)),i){if(i[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");e[i[0].id]=i[1]}return s}prop(t){return this.props[t.id]}get isTop(){return(1&this.flags)>0}get isSkipped(){return(2&this.flags)>0}get isError(){return(4&this.flags)>0}get isAnonymous(){return(8&this.flags)>0}is(t){if("string"==typeof t){if(this.name==t)return!0;let e=this.prop(jh.group);return!!e&&e.indexOf(t)>-1}return this.id==t}static match(t){let e=Object.create(null);for(let i in t)for(let s of i.split(" "))e[s]=t[i];return t=>{for(let i=t.prop(jh.group),s=-1;s<(i?i.length:0);s++){let r=e[s<0?t.name:i[s]];if(r)return r}}}}Ph.none=new Ph("",Object.create(null),0,8);class Hh{constructor(t){this.types=t;for(let e=0;e<t.length;e++)if(t[e].id!=e)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...t){let e=[];for(let i of this.types){let s=null;for(let e of t){let t=e(i);t&&(s||(s=Object.assign({},i.props)),s[t[0].id]=t[1])}e.push(s?new Ph(i.name,s,i.id,i.flags):i)}return new Hh(e)}}const Wh=new WeakMap,Vh=new WeakMap;var Fh;!function(t){t[t.ExcludeBuffers=1]="ExcludeBuffers",t[t.IncludeAnonymous=2]="IncludeAnonymous",t[t.IgnoreMounts=4]="IgnoreMounts",t[t.IgnoreOverlays=8]="IgnoreOverlays"}(Fh||(Fh={}));class qh{constructor(t,e,i,s,r){if(this.type=t,this.children=e,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[t,e]of r)this.props["number"==typeof t?t:t.id]=e}}toString(){let t=$h.get(this);if(t&&!t.overlay)return t.tree.toString();let e="";for(let t of this.children){let i=t.toString();i&&(e&&(e+=","),e+=i)}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 sl(this.topNode,t)}cursorAt(t,e=0,i=0){let s=Wh.get(this)||this.topNode,r=new sl(s);return r.moveTo(t,e),Wh.set(this,r._tree),r}get topNode(){return new Xh(this,0,0,null)}resolve(t,e=0){let i=Kh(Wh.get(this)||this.topNode,t,e,!1);return Wh.set(this,i),i}resolveInner(t,e=0){let i=Kh(Vh.get(this)||this.topNode,t,e,!0);return Vh.set(this,i),i}resolveStack(t,e=0){return function(t,e,i){let s=t.resolveInner(e,i),r=null;for(let t=s instanceof Xh?s:s.context.parent;t;t=t.parent)if(t.index<0){let n=t.parent;(r||(r=[s])).push(n.resolve(e,i)),t=n}else{let n=$h.get(t.tree);if(n&&n.overlay&&n.overlay[0].from<=e&&n.overlay[n.overlay.length-1].to>=e){let h=new Xh(n.tree,n.overlay[0].from+t.from,-1,t);(r||(r=[s])).push(Kh(h,e,i,!1))}}return r?el(r):s}(this,t,e)}iterate(t){let{enter:e,leave:i,from:s=0,to:r=this.length}=t,n=t.mode||0,h=(n&Fh.IncludeAnonymous)>0;for(let t=this.cursor(n|Fh.IncludeAnonymous);;){let n=!1;if(t.from<=r&&t.to>=s&&(!h&&t.type.isAnonymous||!1!==e(t))){if(t.firstChild())continue;n=!0}for(;n&&i&&(h||!t.type.isAnonymous)&&i(t),!t.nextSibling();){if(!t.parent())return;n=!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:ll(Ph.none,this.children,this.positions,0,this.children.length,0,this.length,((t,e,i)=>new qh(this.type,t,e,i,this.propValues)),t.makeTree||((t,e,i)=>new qh(Ph.none,t,e,i)))}static build(t){return function(t){var e;let{buffer:i,nodeSet:s,maxBufferLength:r=Bh,reused:n=[],minRepeatType:h=s.types.length}=t,l=Array.isArray(i)?new Uh(i,i.length):i,o=s.types,u=0,f=0;function a(t,e,i,b,v,k){let{id:y,start:M,end:x,size:S}=l,A=f;for(;S<0;){if(l.next(),-1==S){let e=n[y];return i.push(e),void b.push(M-t)}if(-3==S)return void(u=y);if(-4==S)return void(f=y);throw new RangeError(`Unrecognized record size: ${S}`)}let C,O,D=o[y],E=M-t;if(x-M<=r&&(O=g(l.pos-e,v))){let e=new Uint16Array(O.size-O.skip),i=l.pos-O.size,r=e.length;for(;l.pos>i;)r=w(O.start,e,r);C=new Jh(e,x-O.start,s),E=O.start-t}else{let t=l.pos-S;l.next();let e=[],i=[],s=y>=h?y:-1,n=0,o=x;for(;l.pos>t;)s>=0&&l.id==s&&l.size>=0?(l.end<=o-r&&(p(e,i,M,n,l.end,o,s,A),n=e.length,o=l.end),l.next()):k>2500?c(M,t,e,i):a(M,t,e,i,s,k+1);if(s>=0&&n>0&&n<e.length&&p(e,i,M,n,M,o,s,A),e.reverse(),i.reverse(),s>-1&&n>0){let t=d(D);C=ll(D,e,i,0,e.length,0,x-M,t,t)}else C=m(D,e,i,x-M,A-x)}i.push(C),b.push(E)}function c(t,e,i,n){let h=[],o=0,u=-1;for(;l.pos>e;){let{id:t,start:e,end:i,size:s}=l;if(s>4)l.next();else{if(u>-1&&e<u)break;u<0&&(u=i-r),h.push(t,e,i),o++,l.next()}}if(o){let e=new Uint16Array(4*o),r=h[h.length-2];for(let t=h.length-3,i=0;t>=0;t-=3)e[i++]=h[t],e[i++]=h[t+1]-r,e[i++]=h[t+2]-r,e[i++]=i;i.push(new Jh(e,h[2]-r,s)),n.push(r-t)}}function d(t){return(e,i,s)=>{let r,n,h=0,l=e.length-1;if(l>=0&&(r=e[l])instanceof qh){if(!l&&r.type==t&&r.length==s)return r;(n=r.prop(jh.lookAhead))&&(h=i[l]+r.length+n)}return m(t,e,i,s,h)}}function p(t,e,i,r,n,h,l,o){let u=[],f=[];for(;t.length>r;)u.push(t.pop()),f.push(e.pop()+i-n);t.push(m(s.types[l],u,f,h-n,o-h)),e.push(n-i)}function m(t,e,i,s,r=0,n){if(u){let t=[jh.contextHash,u];n=n?[t].concat(n):[t]}if(r>25){let t=[jh.lookAhead,r];n=n?[t].concat(n):[t]}return new qh(t,e,i,s,n)}function g(t,e){let i=l.fork(),s=0,n=0,o=0,u=i.end-r,f={size:0,start:0,skip:0};t:for(let r=i.pos-t;i.pos>r;){let t=i.size;if(i.id==e&&t>=0){f.size=s,f.start=n,f.skip=o,o+=4,s+=4,i.next();continue}let l=i.pos-t;if(t<0||l<r||i.start<u)break;let a=i.id>=h?4:0,c=i.start;for(i.next();i.pos>l;){if(i.size<0){if(-3!=i.size)break t;a+=4}else i.id>=h&&(a+=4);i.next()}n=c,s+=t,o+=a}return(e<0||s==t)&&(f.size=s,f.start=n,f.skip=o),f.size>4?f:void 0}function w(t,e,i){let{id:s,start:r,end:n,size:o}=l;if(l.next(),o>=0&&s<h){let h=i;if(o>4){let s=l.pos-(o-4);for(;l.pos>s;)i=w(t,e,i)}e[--i]=h,e[--i]=n-t,e[--i]=r-t,e[--i]=s}else-3==o?u=s:-4==o&&(f=s);return i}let b=[],v=[];for(;l.pos>0;)a(t.start||0,t.bufferStart||0,b,v,-1,0);let k=null!==(e=t.length)&&void 0!==e?e:b.length?v[0]+b[0].length:0;return new qh(o[t.topID],b.reverse(),v.reverse(),k)}(t)}}qh.empty=new qh(Ph.none,[],[],0);class Uh{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 Uh(this.buffer,this.index)}}class Jh{constructor(t,e,i){this.buffer=t,this.length=e,this.set=i}get type(){return Ph.none}toString(){let t=[];for(let e=0;e<this.buffer.length;)t.push(this.childString(e)),e=this.buffer[e+3];return t.join(",")}childString(t){let e=this.buffer[t],i=this.buffer[t+3],s=this.set.types[e],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),i==(t+=4))return r;let n=[];for(;t<i;)n.push(this.childString(t)),t=this.buffer[t+3];return r+"("+n.join(",")+")"}findChild(t,e,i,s,r){let{buffer:n}=this,h=-1;for(let l=t;l!=e&&!(Gh(r,s,n[l+1],n[l+2])&&(h=l,i>0));l=n[l+3]);return h}slice(t,e,i){let s=this.buffer,r=new Uint16Array(e-t),n=0;for(let h=t,l=0;h<e;){r[l++]=s[h++],r[l++]=s[h++]-i;let e=r[l++]=s[h++]-i;r[l++]=s[h++]-t,n=Math.max(n,e)}return new Jh(r,n,this.set)}}function Gh(t,e,i,s){switch(t){case-2:return i<e;case-1:return s>=e&&i<e;case 0:return i<e&&s>e;case 1:return i<=e&&s>e;case 2:return s>e;case 4:return!0}}function Kh(t,e,i,s){for(var r;t.from==t.to||(i<1?t.from>=e:t.from>e)||(i>-1?t.to<=e:t.to<e);){let e=!s&&t instanceof Xh&&t.index<0?null:t.parent;if(!e)return t;t=e}let n=s?0:Fh.IgnoreOverlays;if(s)for(let s=t,h=s.parent;h;s=h,h=s.parent)s instanceof Xh&&s.index<0&&(null===(r=h.enter(e,i,n))||void 0===r?void 0:r.from)!=s.from&&(t=h);for(;;){let s=t.enter(e,i,n);if(!s)return t;t=s}}class _h{cursor(t=0){return new sl(this,t)}getChild(t,e=null,i=null){let s=Yh(this,t,e,i);return s.length?s[0]:null}getChildren(t,e=null,i=null){return Yh(this,t,e,i)}resolve(t,e=0){return Kh(this,t,e,!1)}resolveInner(t,e=0){return Kh(this,t,e,!0)}matchContext(t){return Qh(this,t)}enterUnfinishedNodesBefore(t){let e=this.childBefore(t),i=this;for(;e;){let t=e.lastChild;if(!t||t.to!=e.to)break;t.type.isError&&t.from==t.to?(i=e,e=t.prevSibling):e=t}return i}get node(){return this}get next(){return this.parent}}class Xh extends _h{constructor(t,e,i,s){super(),this._tree=t,this.from=e,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,e,i,s,r=0){for(let n=this;;){for(let{children:h,positions:l}=n._tree,o=e>0?h.length:-1;t!=o;t+=e){let o=h[t],u=l[t]+n.from;if(Gh(s,i,u,u+o.length))if(o instanceof Jh){if(r&Fh.ExcludeBuffers)continue;let h=o.findChild(0,o.buffer.length,e,i-u,s);if(h>-1)return new tl(new Zh(n,o,t,u),null,h)}else if(r&Fh.IncludeAnonymous||!o.type.isAnonymous||rl(o)){let h;if(!(r&Fh.IgnoreMounts)&&(h=$h.get(o))&&!h.overlay)return new Xh(h.tree,u,t,n);let l=new Xh(o,u,t,n);return r&Fh.IncludeAnonymous||!l.type.isAnonymous?l:l.nextChild(e<0?o.children.length-1:0,e,i,s)}}if(r&Fh.IncludeAnonymous||!n.type.isAnonymous)return null;if(t=n.index>=0?n.index+e:e<0?-1:n._parent._tree.children.length,n=n._parent,!n)return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(t){return this.nextChild(0,1,t,2)}childBefore(t){return this.nextChild(this._tree.children.length-1,-1,t,-2)}enter(t,e,i=0){let s;if(!(i&Fh.IgnoreOverlays)&&(s=$h.get(this._tree))&&s.overlay){let i=t-this.from;for(let{from:t,to:r}of s.overlay)if((e>0?t<=i:t<i)&&(e<0?r>=i:r>i))return new Xh(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,e,i)}nextSignificantParent(){let t=this;for(;t.type.isAnonymous&&t._parent;)t=t._parent;return t}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function Yh(t,e,i,s){let r=t.cursor(),n=[];if(!r.firstChild())return n;if(null!=i)for(let t=!1;!t;)if(t=r.type.is(i),!r.nextSibling())return n;for(;;){if(null!=s&&r.type.is(s))return n;if(r.type.is(e)&&n.push(r.node),!r.nextSibling())return null==s?n:[]}}function Qh(t,e,i=e.length-1){for(let s=t.parent;i>=0;s=s.parent){if(!s)return!1;if(!s.type.isAnonymous){if(e[i]&&e[i]!=s.name)return!1;i--}}return!0}class Zh{constructor(t,e,i,s){this.parent=t,this.buffer=e,this.index=i,this.start=s}}class tl extends _h{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(t,e,i){super(),this.context=t,this._parent=e,this.index=i,this.type=t.buffer.set.types[t.buffer.buffer[i]]}child(t,e,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.context.start,i);return r<0?null:new tl(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&Fh.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e>0?1:-1,t-this.context.start,e);return r<0?null:new tl(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 tl(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 tl(this.context,this._parent,t.findChild(e,this.index,-1,0,4))}get tree(){return null}toTree(){let t=[],e=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let n=i.buffer[this.index+1];t.push(i.slice(s,r,n)),e.push(0)}return new qh(this.type,t,e,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function el(t){if(!t.length)return null;let e=0,i=t[0];for(let s=1;s<t.length;s++){let r=t[s];(r.from>i.from||r.to<i.to)&&(i=r,e=s)}let s=i instanceof Xh&&i.index<0?null:i.parent,r=t.slice();return s?r[e]=s:r.splice(e,1),new il(r,i)}class il{constructor(t,e){this.heads=t,this.node=e}get next(){return el(this.heads)}}class sl{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 Xh)this.yieldNode(t);else{this._tree=t.context.parent,this.buffer=t.context;for(let e=t._parent;e;e=e._parent)this.stack.unshift(e.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)}yieldBuf(t,e){this.index=t;let{start:i,buffer:s}=this.buffer;return this.type=e||s.set.types[s.buffer[t]],this.from=i+s.buffer[t+1],this.to=i+s.buffer[t+2],!0}yield(t){return!!t&&(t instanceof Xh?(this.buffer=null,this.yieldNode(t)):(this.buffer=t.context,this.yieldBuf(t.index,t.type)))}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(t,e,i){if(!this.buffer)return this.yield(this._tree.nextChild(t<0?this._tree._tree.children.length-1:0,t,e,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],t,e-this.buffer.start,i);return!(r<0)&&(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&Fh.ExcludeBuffers)&&this.enterChild(1,t,e):this.yield(this._tree.enter(t,e,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&Fh.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let t=this.mode&Fh.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));let{buffer:e}=this.buffer,i=this.stack.length-1;if(t<0){let t=i<0?0:this.stack[i]+4;if(this.index!=t)return this.yieldBuf(e.findChild(t,this.index,-1,0,4))}else{let t=e.buffer[this.index+3];if(t<(i<0?e.buffer.length:e.buffer[this.stack[i]+3]))return this.yieldBuf(t)}return i<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+t,t,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(t){let e,i,{buffer:s}=this;if(s){if(t>0){if(this.index<s.buffer.buffer.length)return!1}else for(let t=0;t<this.index;t++)if(s.buffer.buffer[t+3]<this.index)return!1;({index:e,parent:i}=s)}else({index:e,_parent:i}=this._tree);for(;i;({index:e,_parent:i}=i))if(e>-1)for(let s=e+t,r=t<0?-1:i._tree.children.length;s!=r;s+=t){let t=i._tree.children[s];if(this.mode&Fh.IncludeAnonymous||t instanceof Jh||!t.type.isAnonymous||rl(t))return!1}return!0}move(t,e){if(e&&this.enterChild(t,0,4))return!0;for(;;){if(this.sibling(t))return!0;if(this.atLastNode(t)||!this.parent())return!1}}next(t=!0){return this.move(1,t)}prev(t=!0){return this.move(-1,t)}moveTo(t,e=0){for(;(this.from==this.to||(e<1?this.from>=t:this.from>t)||(e>-1?this.to<=t:this.to<t))&&this.parent(););for(;this.enterChild(1,t,e););return this}get node(){if(!this.buffer)return this._tree;let t=this.bufferNode,e=null,i=0;if(t&&t.context==this.buffer)t:for(let s=this.index,r=this.stack.length;r>=0;){for(let n=t;n;n=n._parent)if(n.index==s){if(s==this.index)return n;e=n,i=r+1;break t}s=this.stack[--r]}for(let t=i;t<this.stack.length;t++)e=new tl(this.buffer,e,this.stack[t]);return this.bufferNode=new tl(this.buffer,e,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(t,e){for(let i=0;;){let s=!1;if(this.type.isAnonymous||!1!==t(this)){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;s&&e&&e(this),s=this.type.isAnonymous,!this.nextSibling();){if(!i)return;this.parent(),i--,s=!0}}}matchContext(t){if(!this.buffer)return Qh(this.node,t);let{buffer:e}=this.buffer,{types:i}=e.set;for(let s=t.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return Qh(this.node,t,s);let n=i[e.buffer[this.stack[r]]];if(!n.isAnonymous){if(t[s]&&t[s]!=n.name)return!1;s--}}return!0}}function rl(t){return t.children.some((t=>t instanceof Jh||!t.type.isAnonymous||rl(t)))}const nl=new WeakMap;function hl(t,e){if(!t.isAnonymous||e instanceof Jh||e.type!=t)return 1;let i=nl.get(e);if(null==i){i=1;for(let s of e.children){if(s.type!=t||!(s instanceof qh)){i=1;break}i+=hl(t,s)}nl.set(e,i)}return i}function ll(t,e,i,s,r,n,h,l,o){let u=0;for(let i=s;i<r;i++)u+=hl(t,e[i]);let f=Math.ceil(1.5*u/8),a=[],c=[];return function e(i,s,r,h,l){for(let u=r;u<h;){let r=u,d=s[u],p=hl(t,i[u]);for(u++;u<h;u++){let e=hl(t,i[u]);if(p+e>=f)break;p+=e}if(u==r+1){if(p>f){let t=i[r];e(t.children,t.positions,0,t.children.length,s[r]+l);continue}a.push(i[r])}else{let e=s[u-1]+i[u-1].length-d;a.push(ll(t,i,s,r,u,d,e,null,o))}c.push(d+l-n)}}(e,i,s,r,0),(l||o)(a,c,h)}class ol{constructor(){this.map=new WeakMap}setBuffer(t,e,i){let s=this.map.get(t);s||this.map.set(t,s=new Map),s.set(e,i)}getBuffer(t,e){let i=this.map.get(t);return i&&i.get(e)}set(t,e){t instanceof tl?this.setBuffer(t.context.buffer,t.index,e):t instanceof Xh&&this.map.set(t.tree,e)}get(t){return t instanceof tl?this.getBuffer(t.context.buffer,t.index):t instanceof Xh?this.map.get(t.tree):void 0}cursorSet(t,e){t.buffer?this.setBuffer(t.buffer.buffer,t.index,e):this.map.set(t.tree,e)}cursorGet(t){return t.buffer?this.getBuffer(t.buffer.buffer,t.index):this.map.get(t.tree)}}class ul{constructor(t,e,i,s,r=!1,n=!1){this.from=t,this.to=e,this.tree=i,this.offset=s,this.open=(r?1:0)|(n?2:0)}get openStart(){return(1&this.open)>0}get openEnd(){return(2&this.open)>0}static addTree(t,e=[],i=!1){let s=[new ul(0,t.length,t,0,!1,i)];for(let i of e)i.to>t.length&&s.push(i);return s}static applyChanges(t,e,i=128){if(!e.length)return t;let s=[],r=1,n=t.length?t[0]:null;for(let h=0,l=0,o=0;;h++){let u=h<e.length?e[h]:null,f=u?u.fromA:1e9;if(f-l>=i)for(;n&&n.from<f;){let e=n;if(l>=e.from||f<=e.to||o){let t=Math.max(e.from,l)-o,i=Math.min(e.to,f)-o;e=t>=i?null:new ul(t,i,e.tree,e.offset+o,h>0,!!u)}if(e&&s.push(e),n.to>f)break;n=r<t.length?t[r++]:null}if(!u)break;l=u.toA,o=u.toA-u.toB}return s}}class fl{startParse(t,e,i){return"string"==typeof t&&(t=new al(t)),i=i?i.length?i.map((t=>new Nh(t.from,t.to))):[new Nh(0,0)]:[new Nh(0,t.length)],this.createParse(t,e||[],i)}parse(t,e,i){let s=this.startParse(t,e,i);for(;;){let t=s.advance();if(t)return t}}}class al{constructor(t){this.string=t}get length(){return this.string.length}chunk(t){return this.string.slice(t)}get lineChunks(){return!1}read(t,e){return this.string.slice(t,e)}}function cl(t){return(e,i,s,r)=>new wl(e,t,i,s,r)}class dl{constructor(t,e,i,s,r){this.parser=t,this.parse=e,this.overlay=i,this.target=s,this.from=r}}function pl(t){if(!t.length||t.some((t=>t.from>=t.to)))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(t))}class ml{constructor(t,e,i,s,r,n,h){this.parser=t,this.predicate=e,this.mounts=i,this.index=s,this.start=r,this.target=n,this.prev=h,this.depth=0,this.ranges=[]}}const gl=new jh({perNode:!0});class wl{constructor(t,e,i,s,r){this.nest=e,this.input=i,this.fragments=s,this.ranges=r,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=t}advance(){if(this.baseParse){let t=this.baseParse.advance();if(!t)return null;if(this.baseParse=null,this.baseTree=t,this.startInner(),null!=this.stoppedAt)for(let t of this.inner)t.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let t=this.baseTree;return null!=this.stoppedAt&&(t=new qh(t.type,t.children,t.positions,t.length,t.propValues.concat([[gl,this.stoppedAt]]))),t}let t=this.inner[this.innerDone],e=t.parse.advance();if(e){this.innerDone++;let i=Object.assign(Object.create(null),t.target.props);i[jh.mounted.id]=new $h(e,t.overlay,t.parser),t.target.props=i}return null}get parsedPos(){if(this.baseParse)return 0;let t=this.input.length;for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].from<t&&(t=Math.min(t,this.inner[e].parse.parsedPos));return t}stopAt(t){if(this.stoppedAt=t,this.baseParse)this.baseParse.stopAt(t);else for(let e=this.innerDone;e<this.inner.length;e++)this.inner[e].parse.stopAt(t)}startInner(){let t=new Ml(this.fragments),e=null,i=null,s=new sl(new Xh(this.baseTree,this.ranges[0].from,0,null),Fh.IncludeAnonymous|Fh.IgnoreMounts);t:for(let r,n;;){let h,l=!0;if(null!=this.stoppedAt&&s.from>=this.stoppedAt)l=!1;else if(t.hasNode(s)){if(e){let t=e.mounts.find((t=>t.frag.from<=s.from&&t.frag.to>=s.to&&t.mount.overlay));if(t)for(let i of t.mount.overlay){let r=i.from+t.pos,n=i.to+t.pos;r>=s.from&&n<=s.to&&!e.ranges.some((t=>t.from<n&&t.to>r))&&e.ranges.push({from:r,to:n})}}l=!1}else if(i&&(n=bl(i.ranges,s.from,s.to)))l=2!=n;else if(!s.type.isAnonymous&&(r=this.nest(s,this.input))&&(s.from<s.to||!r.overlay)){s.tree||kl(s);let n=t.findMounts(s.from,r.parser);if("function"==typeof r.overlay)e=new ml(r.parser,r.overlay,n,this.inner.length,s.from,s.tree,e);else{let t=xl(this.ranges,r.overlay||(s.from<s.to?[new Nh(s.from,s.to)]:[]));t.length&&pl(t),!t.length&&r.overlay||this.inner.push(new dl(r.parser,t.length?r.parser.startParse(this.input,Al(n,t),t):r.parser.startParse(""),r.overlay?r.overlay.map((t=>new Nh(t.from-s.from,t.to-s.from))):null,s.tree,t.length?t[0].from:s.from)),r.overlay?t.length&&(i={ranges:t,depth:0,prev:i}):l=!1}}else e&&(h=e.predicate(s))&&(!0===h&&(h=new Nh(s.from,s.to)),h.from<h.to&&e.ranges.push(h));if(l&&s.firstChild())e&&e.depth++,i&&i.depth++;else for(;!s.nextSibling();){if(!s.parent())break t;if(e&&! --e.depth){let t=xl(this.ranges,e.ranges);t.length&&(pl(t),this.inner.splice(e.index,0,new dl(e.parser,e.parser.startParse(this.input,Al(e.mounts,t),t),e.ranges.map((t=>new Nh(t.from-e.start,t.to-e.start))),e.target,t[0].from))),e=e.prev}i&&! --i.depth&&(i=i.prev)}}}}function bl(t,e,i){for(let s of t){if(s.from>=i)break;if(s.to>e)return s.from<=e&&s.to>=i?2:1}return 0}function vl(t,e,i,s,r,n){if(e<i){let h=t.buffer[e+1];s.push(t.slice(e,i,h)),r.push(h-n)}}function kl(t){let{node:e}=t,i=[],s=e.context.buffer;do{i.push(t.index),t.parent()}while(!t.tree);let r=t.tree,n=r.children.indexOf(s),h=r.children[n],l=h.buffer,o=[n];r.children[n]=function t(s,r,n,u,f,a){let c=i[a],d=[],p=[];vl(h,s,c,d,p,u);let m=l[c+1],g=l[c+2];o.push(d.length);let w=a?t(c+4,l[c+3],h.set.types[l[c]],m,g-m,a-1):e.toTree();return d.push(w),p.push(m-u),vl(h,l[c+3],r,d,p,u),new qh(n,d,p,f)}(0,l.length,Ph.none,0,h.length,i.length-1);for(let e of o){let i=t.tree.children[e],s=t.tree.positions[e];t.yield(new Xh(i,s+t.from,e,t._tree))}}class yl{constructor(t,e){this.offset=e,this.done=!1,this.cursor=t.cursor(Fh.IncludeAnonymous|Fh.IgnoreMounts)}moveTo(t){let{cursor:e}=this,i=t-this.offset;for(;!this.done&&e.from<i;)e.to>=t&&e.enter(i,1,Fh.IgnoreOverlays|Fh.ExcludeBuffers)||e.next(!1)||(this.done=!0)}hasNode(t){if(this.moveTo(t.from),!this.done&&this.cursor.from+this.offset==t.from&&this.cursor.tree)for(let e=this.cursor.tree;;){if(e==t.tree)return!0;if(!(e.children.length&&0==e.positions[0]&&e.children[0]instanceof qh))break;e=e.children[0]}return!1}}class Ml{constructor(t){var e;if(this.fragments=t,this.curTo=0,this.fragI=0,t.length){let i=this.curFrag=t[0];this.curTo=null!==(e=i.tree.prop(gl))&&void 0!==e?e:i.to,this.inner=new yl(i.tree,-i.offset)}else this.curFrag=this.inner=null}hasNode(t){for(;this.curFrag&&t.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=t.from&&this.curTo>=t.to&&this.inner.hasNode(t)}nextFrag(){var t;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let e=this.curFrag=this.fragments[this.fragI];this.curTo=null!==(t=e.tree.prop(gl))&&void 0!==t?t:e.to,this.inner=new yl(e.tree,-e.offset)}}findMounts(t,e){var i;let s=[];if(this.inner){this.inner.cursor.moveTo(t,1);for(let t=this.inner.cursor.node;t;t=t.parent){let r=null===(i=t.tree)||void 0===i?void 0:i.prop(jh.mounted);if(r&&r.parser==e)for(let e=this.fragI;e<this.fragments.length;e++){let i=this.fragments[e];if(i.from>=t.to)break;i.tree==this.curFrag.tree&&s.push({frag:i,pos:t.from-i.offset,mount:r})}}}return s}}function xl(t,e){let i=null,s=e;for(let r=1,n=0;r<t.length;r++){let h=t[r-1].to,l=t[r].from;for(;n<s.length;n++){let t=s[n];if(t.from>=l)break;t.to<=h||(i||(s=i=e.slice()),t.from<h?(i[n]=new Nh(t.from,h),t.to>l&&i.splice(n+1,0,new Nh(l,t.to))):t.to>l?i[n--]=new Nh(l,t.to):i.splice(n--,1))}}return s}function Sl(t,e,i,s){let r=0,n=0,h=!1,l=!1,o=-1e9,u=[];for(;;){let f=r==t.length?1e9:h?t[r].to:t[r].from,a=n==e.length?1e9:l?e[n].to:e[n].from;if(h!=l){let t=Math.max(o,i),e=Math.min(f,a,s);t<e&&u.push(new Nh(t,e))}if(o=Math.min(f,a),1e9==o)break;f==o&&(h?(h=!1,r++):h=!0),a==o&&(l?(l=!1,n++):l=!0)}return u}function Al(t,e){let i=[];for(let{pos:s,mount:r,frag:n}of t){let t=s+(r.overlay?r.overlay[0].from:0),h=t+r.tree.length,l=Math.max(n.from,t),o=Math.min(n.to,h);if(r.overlay){let h=Sl(e,r.overlay.map((t=>new Nh(t.from+s,t.to+s))),l,o);for(let e=0,s=l;;e++){let l=e==h.length,u=l?o:h[e].from;if(u>s&&i.push(new ul(s,u,r.tree,-t,n.from>=s||n.openStart,n.to<=u||n.openEnd)),l)break;s=h[e].to}}else i.push(new ul(l,o,r.tree,-t,n.from>=t||n.openStart,n.to<=h||n.openEnd))}return i}let Cl=0;class Ol{constructor(t,e,i){this.set=t,this.base=e,this.modified=i,this.id=Cl++}static define(t){if(null==t?void 0:t.base)throw new Error("Can not derive from a modified tag");let e=new Ol([],null,[]);if(e.set.push(e),t)for(let i of t.set)e.set.push(i);return e}static defineModifier(){let t=new El;return e=>e.modified.indexOf(t)>-1?e:El.get(e.base||e,e.modified.concat(t).sort(((t,e)=>t.id-e.id)))}}let Dl=0;class El{constructor(){this.instances=[],this.id=Dl++}static get(t,e){if(!e.length)return t;let i=e[0].instances.find((i=>{return i.base==t&&(s=e,r=i.modified,s.length==r.length&&s.every(((t,e)=>t==r[e])));var s,r}));if(i)return i;let s=[],r=new Ol(s,t,e);for(let t of e)t.instances.push(r);let n=function(t){let e=[[]];for(let i=0;i<t.length;i++)for(let s=0,r=e.length;s<r;s++)e.push(e[s].concat(t[i]));return e.sort(((t,e)=>e.length-t.length))}(e);for(let e of t.set)if(!e.modified.length)for(let t of n)s.push(El.get(e,t));return r}}function Il(t){let e=Object.create(null);for(let i in t){let s=t[i];Array.isArray(s)||(s=[s]);for(let t of i.split(" "))if(t){let i=[],r=2,n=t;for(let e=0;;){if("..."==n&&e>0&&e+3==t.length){r=1;break}let s=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(n);if(!s)throw new RangeError("Invalid path: "+t);if(i.push("*"==s[0]?"":'"'==s[0][0]?JSON.parse(s[0]):s[0]),e+=s[0].length,e==t.length)break;let h=t[e++];if(e==t.length&&"!"==h){r=0;break}if("/"!=h)throw new RangeError("Invalid path: "+t);n=t.slice(e)}let h=i.length-1,l=i[h];if(!l)throw new RangeError("Invalid path: "+t);let o=new Tl(s,r,h>0?i.slice(0,h):null);e[l]=o.sort(e[l])}}return Rl.add(e)}const Rl=new jh;class Tl{constructor(t,e,i,s){this.tags=t,this.mode=e,this.context=i,this.next=s}get opaque(){return 0==this.mode}get inherit(){return 1==this.mode}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}}function Bl(t,e){let i=Object.create(null);for(let e of t)if(Array.isArray(e.tag))for(let t of e.tag)i[t.id]=e.class;else i[e.tag.id]=e.class;let{scope:s,all:r=null}=e||{};return{style:t=>{let e=r;for(let s of t)for(let t of s.set){let s=i[t.id];if(s){e=e?e+" "+s:s;break}}return e},scope:s}}function Ll(t,e,i,s=0,r=t.length){let n=new Nl(s,Array.isArray(e)?e:[e],i);n.highlightRange(t.cursor(),s,r,"",n.highlighters),n.flush(r)}Tl.empty=new Tl([],2,null);class Nl{constructor(t,e,i){this.at=t,this.highlighters=e,this.span=i,this.class=""}startSpan(t,e){e!=this.class&&(this.flush(t),t>this.at&&(this.at=t),this.class=e)}flush(t){t>this.at&&this.class&&this.span(this.at,t,this.class)}highlightRange(t,e,i,s,r){let{type:n,from:h,to:l}=t;if(h>=i||l<=e)return;n.isTop&&(r=this.highlighters.filter((t=>!t.scope||t.scope(n))));let o=s,u=function(t){let e=t.type.prop(Rl);for(;e&&e.context&&!t.matchContext(e.context);)e=e.next;return e||null}(t)||Tl.empty,f=function(t,e){let i=null;for(let s of t){let t=s.style(e);t&&(i=i?i+" "+t:t)}return i}(r,u.tags);if(f&&(o&&(o+=" "),o+=f,1==u.mode&&(s+=(s?" ":"")+f)),this.startSpan(Math.max(e,h),o),u.opaque)return;let a=t.tree&&t.tree.prop(jh.mounted);if(a&&a.overlay){let n=t.node.enter(a.overlay[0].from+h,1),u=this.highlighters.filter((t=>!t.scope||t.scope(a.tree.type))),f=t.firstChild();for(let c=0,d=h;;c++){let p=c<a.overlay.length?a.overlay[c]:null,m=p?p.from+h:l,g=Math.max(e,d),w=Math.min(i,m);if(g<w&&f)for(;t.from<w&&(this.highlightRange(t,g,w,s,r),this.startSpan(Math.min(w,t.to),o),!(t.to>=m)&&t.nextSibling()););if(!p||m>i)break;d=p.to+h,d>e&&(this.highlightRange(n.cursor(),Math.max(e,p.from+h),Math.min(i,d),"",u),this.startSpan(Math.min(i,d),o))}f&&t.parent()}else if(t.firstChild()){a&&(s="");do{if(!(t.to<=e)){if(t.from>=i)break;this.highlightRange(t,e,i,s,r),this.startSpan(Math.min(i,t.to),o)}}while(t.nextSibling());t.parent()}}}const jl=Ol.define,$l=jl(),zl=jl(),Pl=jl(zl),Hl=jl(zl),Wl=jl(),Vl=jl(Wl),Fl=jl(Wl),ql=jl(),Ul=jl(ql),Jl=jl(),Gl=jl(),Kl=jl(),_l=jl(Kl),Xl=jl(),Yl={comment:$l,lineComment:jl($l),blockComment:jl($l),docComment:jl($l),name:zl,variableName:jl(zl),typeName:Pl,tagName:jl(Pl),propertyName:Hl,attributeName:jl(Hl),className:jl(zl),labelName:jl(zl),namespace:jl(zl),macroName:jl(zl),literal:Wl,string:Vl,docString:jl(Vl),character:jl(Vl),attributeValue:jl(Vl),number:Fl,integer:jl(Fl),float:jl(Fl),bool:jl(Wl),regexp:jl(Wl),escape:jl(Wl),color:jl(Wl),url:jl(Wl),keyword:Jl,self:jl(Jl),null:jl(Jl),atom:jl(Jl),unit:jl(Jl),modifier:jl(Jl),operatorKeyword:jl(Jl),controlKeyword:jl(Jl),definitionKeyword:jl(Jl),moduleKeyword:jl(Jl),operator:Gl,derefOperator:jl(Gl),arithmeticOperator:jl(Gl),logicOperator:jl(Gl),bitwiseOperator:jl(Gl),compareOperator:jl(Gl),updateOperator:jl(Gl),definitionOperator:jl(Gl),typeOperator:jl(Gl),controlOperator:jl(Gl),punctuation:Kl,separator:jl(Kl),bracket:_l,angleBracket:jl(_l),squareBracket:jl(_l),paren:jl(_l),brace:jl(_l),content:ql,heading:Ul,heading1:jl(Ul),heading2:jl(Ul),heading3:jl(Ul),heading4:jl(Ul),heading5:jl(Ul),heading6:jl(Ul),contentSeparator:jl(ql),list:jl(ql),quote:jl(ql),emphasis:jl(ql),strong:jl(ql),link:jl(ql),monospace:jl(ql),strikethrough:jl(ql),inserted:jl(),deleted:jl(),changed:jl(),invalid:jl(),meta:Xl,documentMeta:jl(Xl),annotation:jl(Xl),processingInstruction:jl(Xl),definition:Ol.defineModifier(),constant:Ol.defineModifier(),function:Ol.defineModifier(),standard:Ol.defineModifier(),local:Ol.defineModifier(),special:Ol.defineModifier()};var Ql;Bl([{tag:Yl.link,class:"tok-link"},{tag:Yl.heading,class:"tok-heading"},{tag:Yl.emphasis,class:"tok-emphasis"},{tag:Yl.strong,class:"tok-strong"},{tag:Yl.keyword,class:"tok-keyword"},{tag:Yl.atom,class:"tok-atom"},{tag:Yl.bool,class:"tok-bool"},{tag:Yl.url,class:"tok-url"},{tag:Yl.labelName,class:"tok-labelName"},{tag:Yl.inserted,class:"tok-inserted"},{tag:Yl.deleted,class:"tok-deleted"},{tag:Yl.literal,class:"tok-literal"},{tag:Yl.string,class:"tok-string"},{tag:Yl.number,class:"tok-number"},{tag:[Yl.regexp,Yl.escape,Yl.special(Yl.string)],class:"tok-string2"},{tag:Yl.variableName,class:"tok-variableName"},{tag:Yl.local(Yl.variableName),class:"tok-variableName tok-local"},{tag:Yl.definition(Yl.variableName),class:"tok-variableName tok-definition"},{tag:Yl.special(Yl.variableName),class:"tok-variableName2"},{tag:Yl.definition(Yl.propertyName),class:"tok-propertyName tok-definition"},{tag:Yl.typeName,class:"tok-typeName"},{tag:Yl.namespace,class:"tok-namespace"},{tag:Yl.className,class:"tok-className"},{tag:Yl.macroName,class:"tok-macroName"},{tag:Yl.propertyName,class:"tok-propertyName"},{tag:Yl.operator,class:"tok-operator"},{tag:Yl.comment,class:"tok-comment"},{tag:Yl.meta,class:"tok-meta"},{tag:Yl.invalid,class:"tok-invalid"},{tag:Yl.punctuation,class:"tok-punctuation"}]);const Zl=new jh;function to(t){return j.define({combine:t?e=>e.concat(t):void 0})}const eo=new jh;class io{constructor(t,e,i=[],s=""){this.data=t,this.name=s,St.prototype.hasOwnProperty("tree")||Object.defineProperty(St.prototype,"tree",{get(){return no(this)}}),this.parser=e,this.extension=[mo.of(this),St.languageData.of(((t,e,i)=>{let s=so(t,e,i),r=s.type.prop(Zl);if(!r)return[];let n=t.facet(r),h=s.type.prop(eo);if(h){let r=s.resolve(e-s.from,i);for(let e of h)if(e.test(r,t)){let i=t.facet(e.facet);return"replace"==e.type?i:i.concat(n)}}return n}))].concat(i)}isActiveAt(t,e,i=-1){return so(t,e,i).type.prop(Zl)==this.data}findRegions(t){let e=t.facet(mo);if((null==e?void 0:e.data)==this.data)return[{from:0,to:t.doc.length}];if(!e||!e.allowsNesting)return[];let i=[],s=(t,e)=>{if(t.prop(Zl)==this.data)return void i.push({from:e,to:e+t.length});let r=t.prop(jh.mounted);if(r){if(r.tree.prop(Zl)==this.data){if(r.overlay)for(let t of r.overlay)i.push({from:t.from+e,to:t.to+e});else i.push({from:e,to:e+t.length});return}if(r.overlay){let t=i.length;if(s(r.tree,r.overlay[0].from+e),i.length>t)return}}for(let i=0;i<t.children.length;i++){let r=t.children[i];r instanceof qh&&s(r,t.positions[i]+e)}};return s(no(t),0),i}get allowsNesting(){return!0}}function so(t,e,i){let s=t.facet(mo),r=no(t).topNode;if(!s||s.allowsNesting)for(let t=r;t;t=t.enter(e,i,Fh.ExcludeBuffers))t.type.isTop&&(r=t);return r}io.setState=ct.define();class ro extends io{constructor(t,e,i){super(t,e,[],i),this.parser=e}static define(t){let e=to(t.languageData);return new ro(e,t.parser.configure({props:[Zl.add((t=>t.isTop?e:void 0))]}),t.name)}configure(t,e){return new ro(this.data,this.parser.configure(t),e||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function no(t){let e=t.field(io.state,!1);return e?e.tree:qh.empty}class ho{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 lo=null;class oo{constructor(t,e,i=[],s,r,n,h,l){this.parser=t,this.state=e,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=n,this.skipped=h,this.scheduleOn=l,this.parse=null,this.tempSkipped=[]}static create(t,e,i){return new oo(t,e,[],qh.empty,0,i,[],null)}startParse(){return this.parser.startParse(new ho(this.state.doc),this.fragments)}work(t,e){return null!=e&&e>=this.state.doc.length&&(e=void 0),this.tree!=qh.empty&&this.isDone(null!=e?e:this.state.doc.length)?(this.takeTree(),!0):this.withContext((()=>{var i;if("number"==typeof t){let e=Date.now()+t;t=()=>Date.now()>e}for(this.parse||(this.parse=this.startParse()),null!=e&&(null==this.parse.stoppedAt||this.parse.stoppedAt>e)&&e<this.state.doc.length&&this.parse.stopAt(e);;){let s=this.parse.advance();if(s){if(this.fragments=this.withoutTempSkipped(ul.addTree(s,this.fragments,null!=this.parse.stoppedAt)),this.treeLen=null!==(i=this.parse.stoppedAt)&&void 0!==i?i:this.state.doc.length,this.tree=s,this.parse=null,!(this.treeLen<(null!=e?e:this.state.doc.length)))return!0;this.parse=this.startParse()}if(t())return!1}}))}takeTree(){let t,e;this.parse&&(t=this.parse.parsedPos)>=this.treeLen&&((null==this.parse.stoppedAt||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(ul.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(t){let e=lo;lo=this;try{return t()}finally{lo=e}}withoutTempSkipped(t){for(let e;e=this.tempSkipped.pop();)t=uo(t,e.from,e.to);return t}changes(t,e){let{fragments:i,tree:s,treeLen:r,viewport:n,skipped:h}=this;if(this.takeTree(),!t.empty){let e=[];if(t.iterChangedRanges(((t,i,s,r)=>e.push({fromA:t,toA:i,fromB:s,toB:r}))),i=ul.applyChanges(i,e),s=qh.empty,r=0,n={from:t.mapPos(n.from,-1),to:t.mapPos(n.to,1)},this.skipped.length){h=[];for(let e of this.skipped){let i=t.mapPos(e.from,1),s=t.mapPos(e.to,-1);i<s&&h.push({from:i,to:s})}}}return new oo(this.parser,e,i,s,r,n,h,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 e=0;e<this.skipped.length;e++){let{from:i,to:s}=this.skipped[e];i<t.to&&s>t.from&&(this.fragments=uo(this.fragments,i,s),this.skipped.splice(e--,1))}return!(this.skipped.length>=e)&&(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 fl{createParse(e,i,s){let r=s[0].from,n=s[s.length-1].to;return{parsedPos:r,advance(){let e=lo;if(e){for(let t of s)e.tempSkipped.push(t);t&&(e.scheduleOn=e.scheduleOn?Promise.all([e.scheduleOn,t]):t)}return this.parsedPos=n,new qh(Ph.none,[],[],n-r)},stoppedAt:null,stopAt(){}}}}}isDone(t){t=Math.min(t,this.state.doc.length);let e=this.fragments;return this.treeLen>=t&&e.length&&0==e[0].from&&e[0].to>=t}static get(){return lo}}function uo(t,e,i){return ul.applyChanges(t,[{fromA:e,toA:i,fromB:e,toB:i}])}class fo{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 fo(e)}static init(t){let e=Math.min(3e3,t.doc.length),i=oo.create(t.facet(mo).parser,t,{from:0,to:e});return i.work(20,e)||i.takeTree(),new fo(i)}}io.state=F.define({create:fo.init,update(t,e){for(let t of e.effects)if(t.is(io.setState))return t.value;return e.startState.facet(mo)!=e.state.facet(mo)?fo.init(e.state):t.apply(e)}});let ao=t=>{let e=setTimeout((()=>t()),500);return()=>clearTimeout(e)};"undefined"!=typeof requestIdleCallback&&(ao=t=>{let e=-1,i=setTimeout((()=>{e=requestIdleCallback(t,{timeout:400})}),100);return()=>e<0?clearTimeout(i):cancelIdleCallback(e)});const co="undefined"!=typeof navigator&&(null===(Ql=navigator.scheduling)||void 0===Ql?void 0:Ql.isInputPending)?()=>navigator.scheduling.isInputPending():null,po=_i.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(io.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(io.state);e.tree==e.context.tree&&e.context.isDone(t.doc.length)||(this.working=ao(this.work))}work(t){this.working=null;let e=Date.now();if(this.chunkEnd<e&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=e+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(io.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let n=Date.now()+Math.min(this.chunkBudget,100,t&&!co?Math.max(25,t.timeRemaining()-5):1e9),h=r.context.treeLen<s&&i.doc.length>s+1e3,l=r.context.work((()=>co&&co()||Date.now()>n),s+(h?0:1e5));this.chunkBudget-=Date.now()-e,(l||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:io.setState.of(new fo(r.context))})),this.chunkBudget>0&&(!l||h)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(t){t.scheduleOn&&(this.workScheduled++,t.scheduleOn.then((()=>this.scheduleWork())).catch((t=>Ui(this.view.state,t))).then((()=>this.workScheduled--)),t.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),mo=j.define({combine:t=>t.length?t[0]:null,enables:t=>[io.state,po,Ur.contentAttributes.compute([t],(e=>{let i=e.facet(t);return i&&i.name?{"data-language":i.name}:{}}))]});class go{constructor(t,e=[]){this.language=t,this.support=e,this.extension=[t,e]}}const wo=j.define(),bo=j.define({combine:t=>{if(!t.length)return" ";let e=t[0];if(!e||/\S/.test(e)||Array.from(e).some((t=>t!=e[0])))throw new Error("Invalid indent unit: "+JSON.stringify(t[0]));return e}});function vo(t){let e=t.facet(bo);return 9==e.charCodeAt(0)?t.tabSize*e.length:e.length}function ko(t,e){let i="",s=t.tabSize,r=t.facet(bo)[0];if("\t"==r){for(;e>=s;)i+="\t",e-=s;r=" "}for(let t=0;t<e;t++)i+=r;return i}function yo(t,e){t instanceof St&&(t=new Mo(t));for(let i of t.state.facet(wo)){let s=i(t,e);if(void 0!==s)return s}let i=no(t.state);return i.length>=e?function(t,e,i){let s=e.resolveStack(i),r=s.node.enterUnfinishedNodesBefore(i);if(r!=s.node){let t=[];for(let e=r;e!=s.node;e=e.parent)t.push(e);for(let e=t.length-1;e>=0;e--)s={node:t[e],next:s}}return So(s,t,i)}(t,i,e):null}class Mo{constructor(t,e={}){this.state=t,this.options=e,this.unit=vo(t)}lineAt(t,e=1){let i=this.state.doc.lineAt(t),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return null!=s&&s>=i.from&&s<=i.to?r&&s==t?{text:"",from:t}:(e<0?s<t:s<=t)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(t,e=1){if(this.options.simulateDoubleBreak&&t==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(t,e);return i.slice(t-s,Math.min(i.length,t+100-s))}column(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.countColumn(i,t-s),n=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return n>-1&&(r+=n-this.countColumn(i,i.search(/\S|$/))),r}countColumn(t,e=t.length){return Vt(t,this.state.tabSize,e)}lineIndent(t,e=1){let{text:i,from:s}=this.lineAt(t,e),r=this.options.overrideIndentation;if(r){let t=r(s);if(t>-1)return t}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const xo=new jh;function So(t,e,i){for(let s=t;s;s=s.next){let t=Ao(s.node);if(t)return t(Oo.create(e,i,s))}return 0}function Ao(t){let e=t.type.prop(xo);if(e)return e;let i,s=t.firstChild;if(s&&(i=s.type.prop(jh.closedBy))){let e=t.lastChild,s=e&&i.indexOf(e.name)>-1;return t=>Io(t,!0,1,void 0,s&&!function(t){return t.pos==t.options.simulateBreak&&t.options.simulateDoubleBreak}(t)?e.from:void 0)}return null==t.parent?Co:null}function Co(){return 0}class Oo extends Mo{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 Oo(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(Do(i,t))break;e=this.state.doc.lineAt(i.from)}return this.lineIndent(e.from)}continue(){return So(this.context.next,this.base,this.pos)}}function Do(t,e){for(let i=e;i;i=i.parent)if(t==i)return!0;return!1}function Eo({closing:t,align:e=!0,units:i=1}){return s=>Io(s,e,i,t)}function Io(t,e,i,s,r){let n=t.textAfter,h=n.match(/^\s*/)[0].length,l=s&&n.slice(h,h+s.length)==s||r==t.pos+h,o=e?function(t){let e=t.node,i=e.childAfter(e.from),s=e.lastChild;if(!i)return null;let r=t.options.simulateBreak,n=t.state.doc.lineAt(i.from),h=null==r||r<=n.from?n.to:Math.min(n.to,r);for(let t=i.to;;){let r=e.childAfter(t);if(!r||r==s)return null;if(!r.type.isSkipped)return r.from<h?i:null;t=r.to}}(t):null;return o?l?t.column(o.from):t.column(o.to):t.baseIndent+(l?0:t.unit*i)}const Ro=t=>t.baseIndent;function To({except:t,units:e=1}={}){return i=>{let s=t&&t.test(i.textAfter);return i.baseIndent+(s?0:e*i.unit)}}const Bo=j.define(),Lo=new jh;function No(t){let e=t.firstChild,i=t.lastChild;return e&&e.to<i.from?{from:e.to,to:i.type.isError?t.to:i.from}:null}function jo(t){let e=t.lastChild;return e&&e.to==t.to&&e.type.isError}function $o(t,e,i){for(let s of t.facet(Bo)){let r=s(t,e,i);if(r)return r}return function(t,e,i){let s=no(t);if(s.length<i)return null;let r=null;for(let n=s.resolveStack(i,1);n;n=n.next){let h=n.node;if(h.to<=i||h.from>i)continue;if(r&&h.from<e)break;let l=h.type.prop(Lo);if(l&&(h.to<s.length-50||s.length==t.doc.length||!jo(h))){let s=l(h,t);s&&s.from<=i&&s.from>=e&&s.to>i&&(r=s)}}return r}(t,e,i)}function zo(t,e){let i=e.mapPos(t.from,1),s=e.mapPos(t.to,-1);return i>=s?void 0:{from:i,to:s}}const Po=ct.define({map:zo}),Ho=ct.define({map:zo});function Wo(t){let e=[];for(let{head:i}of t.state.selection.ranges)e.some((t=>t.from<=i&&t.to>=i))||e.push(t.lineBlockAt(i));return e}const Vo=F.define({create:()=>ni.none,update(t,e){t=t.map(e.changes);for(let i of e.effects)if(i.is(Po)&&!qo(t,i.value.from,i.value.to)){let{preparePlaceholder:s}=e.state.facet(_o),r=s?ni.replace({widget:new Zo(s(e.state,i.value))}):Qo;t=t.update({add:[r.range(i.value.from,i.value.to)]})}else i.is(Ho)&&(t=t.update({filter:(t,e)=>i.value.from!=t||i.value.to!=e,filterFrom:i.value.from,filterTo:i.value.to}));if(e.selection){let i=!1,{head:s}=e.selection.main;t.between(s,s,((t,e)=>{t<s&&e>s&&(i=!0)})),i&&(t=t.update({filterFrom:s,filterTo:s,filter:(t,e)=>e<=s||t>=s}))}return t},provide:t=>Ur.decorations.from(t),toJSON(t,e){let i=[];return t.between(0,e.doc.length,((t,e)=>{i.push(t,e)})),i},fromJSON(t){if(!Array.isArray(t)||t.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let i=0;i<t.length;){let s=t[i++],r=t[i++];if("number"!=typeof s||"number"!=typeof r)throw new RangeError("Invalid JSON for fold state");e.push(Qo.range(s,r))}return ni.set(e,!0)}});function Fo(t,e,i){var s;let r=null;return null===(s=t.field(Vo,!1))||void 0===s||s.between(e,i,((t,e)=>{(!r||r.from>t)&&(r={from:t,to:e})})),r}function qo(t,e,i){let s=!1;return t.between(e,e,((t,r)=>{t==e&&r==i&&(s=!0)})),s}function Uo(t,e){return t.field(Vo,!1)?e:e.concat(ct.appendConfig.of(Xo()))}function Jo(t,e,i=!0){let s=t.state.doc.lineAt(e.from).number,r=t.state.doc.lineAt(e.to).number;return Ur.announce.of(`${t.state.phrase(i?"Folded lines":"Unfolded lines")} ${s} ${t.state.phrase("to")} ${r}.`)}const Go=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:t=>{for(let e of Wo(t)){let i=$o(t.state,e.from,e.to);if(i)return t.dispatch({effects:Uo(t.state,[Po.of(i),Jo(t,i)])}),!0}return!1}},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:t=>{if(!t.state.field(Vo,!1))return!1;let e=[];for(let i of Wo(t)){let s=Fo(t.state,i.from,i.to);s&&e.push(Ho.of(s),Jo(t,s,!1))}return e.length&&t.dispatch({effects:e}),e.length>0}},{key:"Ctrl-Alt-[",run:t=>{let{state:e}=t,i=[];for(let s=0;s<e.doc.length;){let r=t.lineBlockAt(s),n=$o(e,r.from,r.to);n&&i.push(Po.of(n)),s=(n?t.lineBlockAt(n.to):r).to+1}return i.length&&t.dispatch({effects:Uo(t.state,i)}),!!i.length}},{key:"Ctrl-Alt-]",run:t=>{let e=t.state.field(Vo,!1);if(!e||!e.size)return!1;let i=[];return e.between(0,t.state.doc.length,((t,e)=>{i.push(Ho.of({from:t,to:e}))})),t.dispatch({effects:i}),!0}}],Ko={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},_o=j.define({combine:t=>At(t,Ko)});function Xo(t){let e=[Vo,iu];return t&&e.push(_o.of(t)),e}function Yo(t,e){let{state:i}=t,s=i.facet(_o),r=e=>{let i=t.lineBlockAt(t.posAtDOM(e.target)),s=Fo(t.state,i.from,i.to);s&&t.dispatch({effects:Ho.of(s)}),e.preventDefault()};if(s.placeholderDOM)return s.placeholderDOM(t,r,e);let n=document.createElement("span");return n.textContent=s.placeholderText,n.setAttribute("aria-label",i.phrase("folded code")),n.title=i.phrase("unfold"),n.className="cm-foldPlaceholder",n.onclick=r,n}const Qo=ni.replace({widget:new class extends si{toDOM(t){return Yo(t,null)}}});class Zo extends si{constructor(t){super(),this.value=t}eq(t){return this.value==t.value}toDOM(t){return Yo(t,this.value)}}const tu={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class eu extends ah{constructor(t,e){super(),this.config=t,this.open=e}eq(t){return this.config==t.config&&this.open==t.open}toDOM(t){if(this.config.markerDOM)return this.config.markerDOM(this.open);let e=document.createElement("span");return e.textContent=this.open?this.config.openText:this.config.closedText,e.title=t.state.phrase(this.open?"Fold line":"Unfold line"),e}}const iu=Ur.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class su{constructor(t,e){let i;function s(t){let e=Gt.newName();return(i||(i=Object.create(null)))["."+e]=t,e}this.specs=t;const r="string"==typeof e.all?e.all:e.all?s(e.all):void 0,n=e.scope;this.scope=n instanceof io?t=>t.prop(Zl)==n.data:n?t=>t==n:void 0,this.style=Bl(t.map((t=>({tag:t.tag,class:t.class||s(Object.assign({},t,{tag:null}))}))),{all:r}).style,this.module=i?new Gt(i):null,this.themeType=e.themeType}static define(t,e){return new su(t,e||{})}}const ru=j.define(),nu=j.define({combine:t=>t.length?[t[0]]:null});function hu(t){let e=t.facet(ru);return e.length?e:t.facet(nu)}function lu(t,e){let i,s=[uu];return t instanceof su&&(t.module&&s.push(Ur.styleModule.of(t.module)),i=t.themeType),(null==e?void 0:e.fallback)?s.push(nu.of(t)):i?s.push(ru.computeN([Ur.darkTheme],(e=>e.facet(Ur.darkTheme)==("dark"==i)?[t]:[]))):s.push(ru.of(t)),s}class ou{constructor(t){this.markCache=Object.create(null),this.tree=no(t.state),this.decorations=this.buildDeco(t,hu(t.state)),this.decoratedTo=t.viewport.to}update(t){let e=no(t.state),i=hu(t.state),s=i!=hu(t.startState),{viewport:r}=t.view,n=t.changes.mapPos(this.decoratedTo,1);e.length<r.to&&!s&&e.type==this.tree.type&&n>=r.to?(this.decorations=this.decorations.map(t.changes),this.decoratedTo=n):(e!=this.tree||t.viewportChanged||s)&&(this.tree=e,this.decorations=this.buildDeco(t.view,i),this.decoratedTo=r.to)}buildDeco(t,e){if(!e||!this.tree.length)return ni.none;let i=new Rt;for(let{from:s,to:r}of t.visibleRanges)Ll(this.tree,e,((t,e,s)=>{i.add(t,e,this.markCache[s]||(this.markCache[s]=ni.mark({class:s})))}),s,r);return i.finish()}}const uu=_.high(_i.fromClass(ou,{decorations:t=>t.decorations})),fu=su.define([{tag:Yl.meta,color:"#404740"},{tag:Yl.link,textDecoration:"underline"},{tag:Yl.heading,textDecoration:"underline",fontWeight:"bold"},{tag:Yl.emphasis,fontStyle:"italic"},{tag:Yl.strong,fontWeight:"bold"},{tag:Yl.strikethrough,textDecoration:"line-through"},{tag:Yl.keyword,color:"#708"},{tag:[Yl.atom,Yl.bool,Yl.url,Yl.contentSeparator,Yl.labelName],color:"#219"},{tag:[Yl.literal,Yl.inserted],color:"#164"},{tag:[Yl.string,Yl.deleted],color:"#a11"},{tag:[Yl.regexp,Yl.escape,Yl.special(Yl.string)],color:"#e40"},{tag:Yl.definition(Yl.variableName),color:"#00f"},{tag:Yl.local(Yl.variableName),color:"#30a"},{tag:[Yl.typeName,Yl.namespace],color:"#085"},{tag:Yl.className,color:"#167"},{tag:[Yl.special(Yl.variableName),Yl.macroName],color:"#256"},{tag:Yl.definition(Yl.propertyName),color:"#00c"},{tag:Yl.comment,color:"#940"},{tag:Yl.invalid,color:"#f00"}]),au=Ur.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),cu=1e4,du="()[]{}",pu=j.define({combine:t=>At(t,{afterCursor:!0,brackets:du,maxScanDistance:cu,renderMatch:wu})}),mu=ni.mark({class:"cm-matchingBracket"}),gu=ni.mark({class:"cm-nonmatchingBracket"});function wu(t){let e=[],i=t.matched?mu:gu;return e.push(i.range(t.start.from,t.start.to)),t.end&&e.push(i.range(t.end.from,t.end.to)),e}const bu=F.define({create:()=>ni.none,update(t,e){if(!e.docChanged&&!e.selection)return t;let i=[],s=e.state.facet(pu);for(let t of e.state.selection.ranges){if(!t.empty)continue;let r=xu(e.state,t.head,-1,s)||t.head>0&&xu(e.state,t.head-1,1,s)||s.afterCursor&&(xu(e.state,t.head,1,s)||t.head<e.state.doc.length&&xu(e.state,t.head+1,-1,s));r&&(i=i.concat(s.renderMatch(r,e.state)))}return ni.set(i,!0)},provide:t=>Ur.decorations.from(t)}),vu=[bu,au];const ku=new jh;function yu(t,e,i){let s=t.prop(e<0?jh.openedBy:jh.closedBy);if(s)return s;if(1==t.name.length){let s=i.indexOf(t.name);if(s>-1&&s%2==(e<0?1:0))return[i[s+e]]}return null}function Mu(t){let e=t.type.prop(ku);return e?e(t.node):t}function xu(t,e,i,s={}){let r=s.maxScanDistance||cu,n=s.brackets||du,h=no(t),l=h.resolveInner(e,i);for(let s=l;s;s=s.parent){let r=yu(s.type,i,n);if(r&&s.from<s.to){let h=Mu(s);if(h&&(i>0?e>=h.from&&e<h.to:e>h.from&&e<=h.to))return Su(t,e,i,s,h,r,n)}}return function(t,e,i,s,r,n,h){let l=i<0?t.sliceDoc(e-1,e):t.sliceDoc(e,e+1),o=h.indexOf(l);if(o<0||o%2==0!=i>0)return null;let u={from:i<0?e-1:e,to:i>0?e+1:e},f=t.doc.iterRange(e,i>0?t.doc.length:0),a=0;for(let t=0;!f.next().done&&t<=n;){let n=f.value;i<0&&(t+=n.length);let l=e+t*i;for(let t=i>0?0:n.length-1,e=i>0?n.length:-1;t!=e;t+=i){let e=h.indexOf(n[t]);if(!(e<0||s.resolveInner(l+t,1).type!=r))if(e%2==0==i>0)a++;else{if(1==a)return{start:u,end:{from:l+t,to:l+t+1},matched:e>>1==o>>1};a--}}i>0&&(t+=n.length)}return f.done?{start:u,matched:!1}:null}(t,e,i,h,l.type,r,n)}function Su(t,e,i,s,r,n,h){let l=s.parent,o={from:r.from,to:r.to},u=0,f=null==l?void 0:l.cursor();if(f&&(i<0?f.childBefore(s.from):f.childAfter(s.to)))do{if(i<0?f.to<=s.from:f.from>=s.to){if(0==u&&n.indexOf(f.type.name)>-1&&f.from<f.to){let t=Mu(f);return{start:o,end:t?{from:t.from,to:t.to}:void 0,matched:!0}}if(yu(f.type,i,h))u++;else if(yu(f.type,-i,h)){if(0==u){let t=Mu(f);return{start:o,end:t&&t.from<t.to?{from:t.from,to:t.to}:void 0,matched:!1}}u--}}}while(i<0?f.prevSibling():f.nextSibling());return{start:o,matched:!1}}const Au=Object.create(null),Cu=[Ph.none],Ou=[],Du=Object.create(null),Eu=Object.create(null);for(let[t,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])Eu[t]=Ru(Au,e);function Iu(t,e){Ou.indexOf(t)>-1||(Ou.push(t),console.warn(e))}function Ru(t,e){let i=[];for(let s of e.split(" ")){let e=[];for(let i of s.split(".")){let s=t[i]||Yl[i];s?"function"==typeof s?e.length?e=e.map(s):Iu(i,`Modifier ${i} used at start of tag`):e.length?Iu(i,`Tag ${i} used as modifier`):e=Array.isArray(s)?s:[s]:Iu(i,`Unknown highlighting tag ${i}`)}for(let t of e)i.push(t)}if(!i.length)return 0;let s=e.replace(/ /g,"_"),r=s+" "+i.map((t=>t.id)),n=Du[r];if(n)return n.id;let h=Du[r]=Ph.define({id:Cu.length,name:s,props:[Il({[s]:i})]});return Cu.push(h),h.id}pi.RTL,pi.LTR;function Tu(t,e){return({state:i,dispatch:s})=>{if(i.readOnly)return!1;let r=t(e,i);return!!r&&(s(i.update(r)),!0)}}const Bu=Tu(Pu,0),Lu=Tu(zu,0),Nu=Tu(((t,e)=>zu(t,e,function(t){let e=[];for(let i of t.selection.ranges){let s=t.doc.lineAt(i.from),r=i.to<=s.to?s:t.doc.lineAt(i.to),n=e.length-1;n>=0&&e[n].to>s.from?e[n].to=r.to:e.push({from:s.from+/^\s*/.exec(s.text)[0].length,to:r.to})}return e}(e))),0);function ju(t,e){let i=t.languageDataAt("commentTokens",e);return i.length?i[0]:{}}const $u=50;function zu(t,e,i=e.selection.ranges){let s=i.map((t=>ju(e,t.from).block));if(!s.every((t=>t)))return null;let r=i.map(((t,i)=>function(t,{open:e,close:i},s,r){let n,h,l=t.sliceDoc(s-$u,s),o=t.sliceDoc(r,r+$u),u=/\s*$/.exec(l)[0].length,f=/^\s*/.exec(o)[0].length,a=l.length-u;if(l.slice(a-e.length,a)==e&&o.slice(f,f+i.length)==i)return{open:{pos:s-u,margin:u&&1},close:{pos:r+f,margin:f&&1}};r-s<=2*$u?n=h=t.sliceDoc(s,r):(n=t.sliceDoc(s,s+$u),h=t.sliceDoc(r-$u,r));let c=/^\s*/.exec(n)[0].length,d=/\s*$/.exec(h)[0].length,p=h.length-d-i.length;return n.slice(c,c+e.length)==e&&h.slice(p,p+i.length)==i?{open:{pos:s+c+e.length,margin:/\s/.test(n.charAt(c+e.length))?1:0},close:{pos:r-d-i.length,margin:/\s/.test(h.charAt(p-1))?1:0}}:null}(e,s[i],t.from,t.to)));if(2!=t&&!r.every((t=>t)))return{changes:e.changes(i.map(((t,e)=>r[e]?[]:[{from:t.from,insert:s[e].open+" "},{from:t.to,insert:" "+s[e].close}])))};if(1!=t&&r.some((t=>t))){let t=[];for(let e,i=0;i<r.length;i++)if(e=r[i]){let r=s[i],{open:n,close:h}=e;t.push({from:n.pos-r.open.length,to:n.pos+n.margin},{from:h.pos-h.margin,to:h.pos+r.close.length})}return{changes:t}}return null}function Pu(t,e,i=e.selection.ranges){let s=[],r=-1;for(let{from:t,to:n}of i){let i=s.length,h=1e9,l=ju(e,t).line;if(l){for(let i=t;i<=n;){let o=e.doc.lineAt(i);if(o.from>r&&(t==n||n>o.from)){r=o.from;let t=/^\s*/.exec(o.text)[0].length,e=t==o.length,i=o.text.slice(t,t+l.length)==l?t:-1;t<o.text.length&&t<h&&(h=t),s.push({line:o,comment:i,token:l,indent:t,empty:e,single:!1})}i=o.to+1}if(h<1e9)for(let t=i;t<s.length;t++)s[t].indent<s[t].line.text.length&&(s[t].indent=h);s.length==i+1&&(s[i].single=!0)}}if(2!=t&&s.some((t=>t.comment<0&&(!t.empty||t.single)))){let t=[];for(let{line:e,token:i,indent:r,empty:n,single:h}of s)!h&&n||t.push({from:e.from+r,insert:i+" "});let i=e.changes(t);return{changes:i,selection:e.selection.map(i,1)}}if(1!=t&&s.some((t=>t.comment>=0))){let t=[];for(let{line:e,comment:i,token:r}of s)if(i>=0){let s=e.from+i,n=s+r.length;" "==e.text[n-e.from]&&n++,t.push({from:s,to:n})}return{changes:t}}return null}const Hu=ut.define(),Wu=ut.define(),Vu=j.define(),Fu=j.define({combine:t=>At(t,{minDepth:100,newGroupDelay:500,joinToEvent:(t,e)=>e},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,e)=>(i,s)=>t(i,s)||e(i,s)})}),qu=F.define({create:()=>lf.empty,update(t,e){let i=e.state.facet(Fu),s=e.annotation(Hu);if(s){let r=Xu.fromTransaction(e,s.selection),n=s.side,h=0==n?t.undone:t.done;return h=r?Yu(h,h.length,i.minDepth,r):ef(h,e.startState.selection),new lf(0==n?s.rest:h,0==n?h:s.rest)}let r=e.annotation(Wu);if("full"!=r&&"before"!=r||(t=t.isolate()),!1===e.annotation(dt.addToHistory))return e.changes.empty?t:t.addMapping(e.changes.desc);let n=Xu.fromTransaction(e),h=e.annotation(dt.time),l=e.annotation(dt.userEvent);return n?t=t.addChanges(n,h,l,i,e):e.selection&&(t=t.addSelection(e.startState.selection,h,l,i.newGroupDelay)),"full"!=r&&"after"!=r||(t=t.isolate()),t},toJSON:t=>({done:t.done.map((t=>t.toJSON())),undone:t.undone.map((t=>t.toJSON()))}),fromJSON:t=>new lf(t.done.map(Xu.fromJSON),t.undone.map(Xu.fromJSON))});function Uu(t,e){return function({state:i,dispatch:s}){if(!e&&i.readOnly)return!1;let r=i.field(qu,!1);if(!r)return!1;let n=r.pop(t,i,e);return!!n&&(s(n),!0)}}const Ju=Uu(0,!1),Gu=Uu(1,!1),Ku=Uu(0,!0),_u=Uu(1,!0);class Xu{constructor(t,e,i,s,r){this.changes=t,this.effects=e,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(t){return new Xu(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,e,i;return{changes:null===(t=this.changes)||void 0===t?void 0:t.toJSON(),mapped:null===(e=this.mapped)||void 0===e?void 0:e.toJSON(),startSelection:null===(i=this.startSelection)||void 0===i?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map((t=>t.toJSON()))}}static fromJSON(t){return new Xu(t.changes&&A.fromJSON(t.changes),[],t.mapped&&S.fromJSON(t.mapped),t.startSelection&&B.fromJSON(t.startSelection),t.selectionsAfter.map(B.fromJSON))}static fromTransaction(t,e){let i=Zu;for(let e of t.startState.facet(Vu)){let s=e(t);s.length&&(i=i.concat(s))}return!i.length&&t.changes.empty?null:new Xu(t.changes.invert(t.startState.doc),i,void 0,e||t.startState.selection,Zu)}static selection(t){return new Xu(void 0,Zu,void 0,void 0,t)}}function Yu(t,e,i,s){let r=e+1>i+20?e-i-1:0,n=t.slice(r,e);return n.push(s),n}function Qu(t,e){return t.length?e.length?t.concat(e):t:e}const Zu=[],tf=200;function ef(t,e){if(t.length){let i=t[t.length-1],s=i.selectionsAfter.slice(Math.max(0,i.selectionsAfter.length-tf));return s.length&&s[s.length-1].eq(e)?t:(s.push(e),Yu(t,t.length-1,1e9,i.setSelAfter(s)))}return[Xu.selection([e])]}function sf(t){let e=t[t.length-1],i=t.slice();return i[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),i}function rf(t,e){if(!t.length)return t;let i=t.length,s=Zu;for(;i;){let r=nf(t[i-1],e,s);if(r.changes&&!r.changes.empty||r.effects.length){let e=t.slice(0,i);return e[i-1]=r,e}e=r.mapped,i--,s=r.selectionsAfter}return s.length?[Xu.selection(s)]:Zu}function nf(t,e,i){let s=Qu(t.selectionsAfter.length?t.selectionsAfter.map((t=>t.map(e))):Zu,i);if(!t.changes)return Xu.selection(s);let r=t.changes.map(e),n=e.mapDesc(t.changes,!0),h=t.mapped?t.mapped.composeDesc(n):n;return new Xu(r,ct.mapEffects(t.effects,e),h,t.startSelection.map(n),s)}const hf=/^(input\.type|delete)($|\.)/;class lf{constructor(t,e,i=0,s=void 0){this.done=t,this.undone=e,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new lf(this.done,this.undone):this}addChanges(t,e,i,s,r){let n=this.done,h=n[n.length-1];return n=h&&h.changes&&!h.changes.empty&&t.changes&&(!i||hf.test(i))&&(!h.selectionsAfter.length&&e-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,function(t,e){let i=[],s=!1;return t.iterChangedRanges(((t,e)=>i.push(t,e))),e.iterChangedRanges(((t,e,r,n)=>{for(let t=0;t<i.length;){let e=i[t++],h=i[t++];n>=e&&r<=h&&(s=!0)}})),s}(h.changes,t.changes))||"input.type.compose"==i)?Yu(n,n.length-1,s.minDepth,new Xu(t.changes.compose(h.changes),Qu(t.effects,h.effects),h.mapped,h.startSelection,Zu)):Yu(n,n.length,s.minDepth,t),new lf(n,Zu,e,i)}addSelection(t,e,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Zu;return r.length>0&&e-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&(n=r[r.length-1],h=t,n.ranges.length==h.ranges.length&&0===n.ranges.filter(((t,e)=>t.empty!=h.ranges[e].empty)).length)?this:new lf(ef(this.done,t),this.undone,e,i);var n,h}addMapping(t){return new lf(rf(this.done,t),rf(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,e,i){let s=0==t?this.done:this.undone;if(0==s.length)return null;let r=s[s.length-1],n=r.selectionsAfter[0]||e.selection;if(i&&r.selectionsAfter.length)return e.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:Hu.of({side:t,rest:sf(s),selection:n}),userEvent:0==t?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let i=1==s.length?Zu:s.slice(0,s.length-1);return r.mapped&&(i=rf(i,r.mapped)),e.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:Hu.of({side:t,rest:i,selection:n}),filter:!1,userEvent:0==t?"undo":"redo",scrollIntoView:!0})}return null}}lf.empty=new lf(Zu,Zu);const of=[{key:"Mod-z",run:Ju,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Gu,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Gu,preventDefault:!0},{key:"Mod-u",run:Ku,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:_u,preventDefault:!0}];function uf(t,e){return B.create(t.ranges.map(e),t.mainIndex)}function ff(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function af({state:t,dispatch:e},i){let s=uf(t.selection,i);return!s.eq(t.selection,!0)&&(e(ff(t,s)),!0)}function cf(t,e){return B.cursor(e?t.to:t.from)}function df(t,e){return af(t,(i=>i.empty?t.moveByChar(i,e):cf(i,e)))}function pf(t){return t.textDirectionAt(t.state.selection.main.head)==pi.LTR}const mf=t=>df(t,!pf(t)),gf=t=>df(t,pf(t));function wf(t,e){return af(t,(i=>i.empty?t.moveByGroup(i,e):cf(i,e)))}function bf(t,e,i){if(e.type.prop(i))return!0;let s=e.to-e.from;return s&&(s>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function vf(t,e,i){let s,r,n=no(t).resolveInner(e.head),h=i?jh.closedBy:jh.openedBy;for(let s=e.head;;){let e=i?n.childAfter(s):n.childBefore(s);if(!e)break;bf(t,e,h)?n=e:s=i?e.to:e.from}return r=n.type.prop(h)&&(s=i?xu(t,n.from,1):xu(t,n.to,-1))&&s.matched?i?s.end.to:s.end.from:i?n.to:n.from,B.cursor(r,i?-1:1)}function kf(t,e){return af(t,(i=>{if(!i.empty)return cf(i,e);let s=t.moveVertically(i,e);return s.head!=i.head?s:t.moveToLineBoundary(i,e)}))}const yf=t=>kf(t,!1),Mf=t=>kf(t,!0);function xf(t){let e,i=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,s=0,r=0;if(i){for(let e of t.state.facet(Ur.scrollMargins)){let i=e(t);(null==i?void 0:i.top)&&(s=Math.max(null==i?void 0:i.top,s)),(null==i?void 0:i.bottom)&&(r=Math.max(null==i?void 0:i.bottom,r))}e=t.scrollDOM.clientHeight-s-r}else e=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:s,marginBottom:r,selfScroll:i,height:Math.max(t.defaultLineHeight,e-5)}}function Sf(t,e){let i,s=xf(t),{state:r}=t,n=uf(r.selection,(i=>i.empty?t.moveVertically(i,e,s.height):cf(i,e)));if(n.eq(r.selection))return!1;if(s.selfScroll){let e=t.coordsAtPos(r.selection.main.head),h=t.scrollDOM.getBoundingClientRect(),l=h.top+s.marginTop,o=h.bottom-s.marginBottom;e&&e.top>l&&e.bottom<o&&(i=Ur.scrollIntoView(n.main.head,{y:"start",yMargin:e.top-l}))}return t.dispatch(ff(r,n),{effects:i}),!0}const Af=t=>Sf(t,!1),Cf=t=>Sf(t,!0);function Of(t,e,i){let s=t.lineBlockAt(e.head),r=t.moveToLineBoundary(e,i);if(r.head==e.head&&r.head!=(i?s.to:s.from)&&(r=t.moveToLineBoundary(e,i,!1)),!i&&r.head==s.from&&s.length){let i=/^\s*/.exec(t.state.sliceDoc(s.from,Math.min(s.from+100,s.to)))[0].length;i&&e.head!=s.from+i&&(r=B.cursor(s.from+i))}return r}function Df(t,e){let i=uf(t.state.selection,(t=>{let i=e(t);return B.range(t.anchor,i.head,i.goalColumn,i.bidiLevel||void 0)}));return!i.eq(t.state.selection)&&(t.dispatch(ff(t.state,i)),!0)}function Ef(t,e){return Df(t,(i=>t.moveByChar(i,e)))}const If=t=>Ef(t,!pf(t)),Rf=t=>Ef(t,pf(t));function Tf(t,e){return Df(t,(i=>t.moveByGroup(i,e)))}function Bf(t,e){return Df(t,(i=>t.moveVertically(i,e)))}const Lf=t=>Bf(t,!1),Nf=t=>Bf(t,!0);function jf(t,e){return Df(t,(i=>t.moveVertically(i,e,xf(t).height)))}const $f=t=>jf(t,!1),zf=t=>jf(t,!0),Pf=({state:t,dispatch:e})=>(e(ff(t,{anchor:0})),!0),Hf=({state:t,dispatch:e})=>(e(ff(t,{anchor:t.doc.length})),!0),Wf=({state:t,dispatch:e})=>(e(ff(t,{anchor:t.selection.main.anchor,head:0})),!0),Vf=({state:t,dispatch:e})=>(e(ff(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0);function Ff(t,e){if(t.state.readOnly)return!1;let i="delete.selection",{state:s}=t,r=s.changeByRange((s=>{let{from:r,to:n}=s;if(r==n){let h=e(s);h<r?(i="delete.backward",h=qf(t,h,!1)):h>r&&(i="delete.forward",h=qf(t,h,!0)),r=Math.min(r,h),n=Math.max(n,h)}else r=qf(t,r,!1),n=qf(t,n,!0);return r==n?{range:s}:{changes:{from:r,to:n},range:B.cursor(r,r<s.head?-1:1)}}));return!r.changes.empty&&(t.dispatch(s.update(r,{scrollIntoView:!0,userEvent:i,effects:"delete.selection"==i?Ur.announce.of(s.phrase("Selection deleted")):void 0})),!0)}function qf(t,e,i){if(t instanceof Ur)for(let s of t.state.facet(Ur.atomicRanges).map((e=>e(t))))s.between(e,e,((t,s)=>{t<e&&s>e&&(e=i?s:t)}));return e}const Uf=(t,e,i)=>Ff(t,(s=>{let r,n,h=s.from,{state:l}=t,o=l.doc.lineAt(h);if(i&&!e&&h>o.from&&h<o.from+200&&!/[^ \t]/.test(r=o.text.slice(0,h-o.from))){if("\t"==r[r.length-1])return h-1;let t=Vt(r,l.tabSize)%vo(l)||vo(l);for(let e=0;e<t&&" "==r[r.length-1-e];e++)h--;n=h}else n=p(o.text,h-o.from,e,e)+o.from,n==h&&o.number!=(e?l.doc.lines:1)?n+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(n-o.from,h-o.from))&&(n=p(o.text,n-o.from,!1,!1)+o.from);return n})),Jf=t=>Uf(t,!1,!0),Gf=t=>Uf(t,!0,!1),Kf=(t,e)=>Ff(t,(i=>{let s=i.head,{state:r}=t,n=r.doc.lineAt(s),h=r.charCategorizer(s);for(let t=null;;){if(s==(e?n.to:n.from)){s==i.head&&n.number!=(e?r.doc.lines:1)&&(s+=e?1:-1);break}let l=p(n.text,s-n.from,e)+n.from,o=n.text.slice(Math.min(s,l)-n.from,Math.max(s,l)-n.from),u=h(o);if(null!=t&&u!=t)break;" "==o&&s==i.head||(t=u),s=l}return s})),_f=t=>Kf(t,!1);function Xf(t){let e=[],i=-1;for(let s of t.selection.ranges){let r=t.doc.lineAt(s.from),n=t.doc.lineAt(s.to);if(s.empty||s.to!=n.from||(n=t.doc.lineAt(s.to-1)),i>=r.number){let t=e[e.length-1];t.to=n.to,t.ranges.push(s)}else e.push({from:r.from,to:n.to,ranges:[s]});i=n.number+1}return e}function Yf(t,e,i){if(t.readOnly)return!1;let s=[],r=[];for(let e of Xf(t)){if(i?e.to==t.doc.length:0==e.from)continue;let n=t.doc.lineAt(i?e.to+1:e.from-1),h=n.length+1;if(i){s.push({from:e.to,to:n.to},{from:e.from,insert:n.text+t.lineBreak});for(let i of e.ranges)r.push(B.range(Math.min(t.doc.length,i.anchor+h),Math.min(t.doc.length,i.head+h)))}else{s.push({from:n.from,to:e.from},{from:e.to,insert:t.lineBreak+n.text});for(let t of e.ranges)r.push(B.range(t.anchor-h,t.head-h))}}return!!s.length&&(e(t.update({changes:s,scrollIntoView:!0,selection:B.create(r,t.selection.mainIndex),userEvent:"move.line"})),!0)}function Qf(t,e,i){if(t.readOnly)return!1;let s=[];for(let e of Xf(t))i?s.push({from:e.from,insert:t.doc.slice(e.from,e.to)+t.lineBreak}):s.push({from:e.to,insert:t.lineBreak+t.doc.slice(e.from,e.to)});return e(t.update({changes:s,scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Zf=ta(!1);function ta(e){return({state:i,dispatch:s})=>{if(i.readOnly)return!1;let r=i.changeByRange((s=>{let{from:r,to:n}=s,h=i.doc.lineAt(r),l=!e&&r==n&&function(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let i,s=no(t).resolveInner(e),r=s.childBefore(e),n=s.childAfter(e);return r&&n&&r.to<=e&&n.from>=e&&(i=r.type.prop(jh.closedBy))&&i.indexOf(n.name)>-1&&t.doc.lineAt(r.to).from==t.doc.lineAt(n.from).from&&!/\S/.test(t.sliceDoc(r.to,n.from))?{from:r.to,to:n.from}:null}(i,r);e&&(r=n=(n<=h.to?h:i.doc.lineAt(n)).to);let o=new Mo(i,{simulateBreak:r,simulateDoubleBreak:!!l}),u=yo(o,r);for(null==u&&(u=Vt(/^\s*/.exec(i.doc.lineAt(r).text)[0],i.tabSize));n<h.to&&/\s/.test(h.text[n-h.from]);)n++;l?({from:r,to:n}=l):r>h.from&&r<h.from+100&&!/\S/.test(h.text.slice(0,r))&&(r=h.from);let f=["",ko(i,u)];return l&&f.push(ko(i,o.lineIndent(h.from,-1))),{changes:{from:r,to:n,insert:t.of(f)},range:B.cursor(r+1+f[1].length)}}));return s(i.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}function ea(t,e){let i=-1;return t.changeByRange((s=>{let r=[];for(let n=s.from;n<=s.to;){let h=t.doc.lineAt(n);h.number>i&&(s.empty||s.to>h.from)&&(e(h,r,s),i=h.number),n=h.to+1}let n=t.changes(r);return{changes:r,range:B.range(n.mapPos(s.anchor,1),n.mapPos(s.head,1))}}))}const ia=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:t=>af(t,(e=>vf(t.state,e,!pf(t)))),shift:t=>Df(t,(e=>vf(t.state,e,!pf(t))))},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:t=>af(t,(e=>vf(t.state,e,pf(t)))),shift:t=>Df(t,(e=>vf(t.state,e,pf(t))))},{key:"Alt-ArrowUp",run:({state:t,dispatch:e})=>Yf(t,e,!1)},{key:"Shift-Alt-ArrowUp",run:({state:t,dispatch:e})=>Qf(t,e,!1)},{key:"Alt-ArrowDown",run:({state:t,dispatch:e})=>Yf(t,e,!0)},{key:"Shift-Alt-ArrowDown",run:({state:t,dispatch:e})=>Qf(t,e,!0)},{key:"Escape",run:({state:t,dispatch:e})=>{let i=t.selection,s=null;return i.ranges.length>1?s=B.create([i.main]):i.main.empty||(s=B.create([B.cursor(i.main.head)])),!!s&&(e(ff(t,s)),!0)}},{key:"Mod-Enter",run:ta(!0)},{key:"Alt-l",mac:"Ctrl-l",run:({state:t,dispatch:e})=>{let i=Xf(t).map((({from:e,to:i})=>B.range(e,Math.min(i+1,t.doc.length))));return e(t.update({selection:B.create(i),userEvent:"select"})),!0}},{key:"Mod-i",run:({state:t,dispatch:e})=>{let i=uf(t.selection,(e=>{var i;for(let s=no(t).resolveStack(e.from,1);s;s=s.next){let{node:t}=s;if((t.from<e.from&&t.to>=e.to||t.to>e.to&&t.from<=e.from)&&(null===(i=t.parent)||void 0===i?void 0:i.parent))return B.range(t.to,t.from)}return e}));return e(ff(t,i)),!0},preventDefault:!0},{key:"Mod-[",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(ea(t,((e,i)=>{let s=/^\s*/.exec(e.text)[0];if(!s)return;let r=Vt(s,t.tabSize),n=0,h=ko(t,Math.max(0,r-vo(t)));for(;n<s.length&&n<h.length&&s.charCodeAt(n)==h.charCodeAt(n);)n++;i.push({from:e.from+n,to:e.from+s.length,insert:h.slice(n)})})),{userEvent:"delete.dedent"})),!0)},{key:"Mod-]",run:({state:t,dispatch:e})=>!t.readOnly&&(e(t.update(ea(t,((e,i)=>{i.push({from:e.from,insert:t.facet(bo)})})),{userEvent:"input.indent"})),!0)},{key:"Mod-Alt-\\",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=Object.create(null),s=new Mo(t,{overrideIndentation:t=>{let e=i[t];return null==e?-1:e}}),r=ea(t,((e,r,n)=>{let h=yo(s,e.from);if(null==h)return;/\S/.test(e.text)||(h=0);let l=/^\s*/.exec(e.text)[0],o=ko(t,h);(l!=o||n.from<e.from+l.length)&&(i[e.from]=h,r.push({from:e.from,to:e.from+l.length,insert:o}))}));return r.changes.empty||e(t.update(r,{userEvent:"indent"})),!0}},{key:"Shift-Mod-k",run:t=>{if(t.state.readOnly)return!1;let{state:e}=t,i=e.changes(Xf(e).map((({from:t,to:i})=>(t>0?t--:i<e.doc.length&&i++,{from:t,to:i})))),s=uf(e.selection,(e=>{let i;if(t.lineWrapping){let s=t.lineBlockAt(e.head),r=t.coordsAtPos(e.head,e.assoc||1);r&&(i=s.bottom+t.documentTop-r.bottom+t.defaultLineHeight/2)}return t.moveVertically(e,!0,i)})).map(i);return t.dispatch({changes:i,selection:s,scrollIntoView:!0,userEvent:"delete.line"}),!0}},{key:"Shift-Mod-\\",run:({state:t,dispatch:e})=>function(t,e,i){let s=!1,r=uf(t.selection,(e=>{let r=xu(t,e.head,-1)||xu(t,e.head,1)||e.head>0&&xu(t,e.head-1,1)||e.head<t.doc.length&&xu(t,e.head+1,-1);if(!r||!r.end)return e;s=!0;let n=r.start.from==e.head?r.end.to:r.end.from;return i?B.range(e.anchor,n):B.cursor(n)}));return!!s&&(e(ff(t,r)),!0)}(t,e,!1)},{key:"Mod-/",run:t=>{let{state:e}=t,i=e.doc.lineAt(e.selection.main.from),s=ju(t.state,i.from);return s.line?Bu(t):!!s.block&&Nu(t)}},{key:"Alt-A",run:Lu}].concat([{key:"ArrowLeft",run:mf,shift:If,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:t=>wf(t,!pf(t)),shift:t=>Tf(t,!pf(t)),preventDefault:!0},{mac:"Cmd-ArrowLeft",run:t=>af(t,(e=>Of(t,e,!pf(t)))),shift:t=>Df(t,(e=>Of(t,e,!pf(t)))),preventDefault:!0},{key:"ArrowRight",run:gf,shift:Rf,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:t=>wf(t,pf(t)),shift:t=>Tf(t,pf(t)),preventDefault:!0},{mac:"Cmd-ArrowRight",run:t=>af(t,(e=>Of(t,e,pf(t)))),shift:t=>Df(t,(e=>Of(t,e,pf(t)))),preventDefault:!0},{key:"ArrowUp",run:yf,shift:Lf,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Pf,shift:Wf},{mac:"Ctrl-ArrowUp",run:Af,shift:$f},{key:"ArrowDown",run:Mf,shift:Nf,preventDefault:!0},{mac:"Cmd-ArrowDown",run:Hf,shift:Vf},{mac:"Ctrl-ArrowDown",run:Cf,shift:zf},{key:"PageUp",run:Af,shift:$f},{key:"PageDown",run:Cf,shift:zf},{key:"Home",run:t=>af(t,(e=>Of(t,e,!1))),shift:t=>Df(t,(e=>Of(t,e,!1))),preventDefault:!0},{key:"Mod-Home",run:Pf,shift:Wf},{key:"End",run:t=>af(t,(e=>Of(t,e,!0))),shift:t=>Df(t,(e=>Of(t,e,!0))),preventDefault:!0},{key:"Mod-End",run:Hf,shift:Vf},{key:"Enter",run:Zf},{key:"Mod-a",run:({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0)},{key:"Backspace",run:Jf,shift:Jf},{key:"Delete",run:Gf},{key:"Mod-Backspace",mac:"Alt-Backspace",run:_f},{key:"Mod-Delete",mac:"Alt-Delete",run:t=>Kf(t,!0)},{mac:"Mod-Backspace",run:t=>Ff(t,(e=>{let i=t.moveToLineBoundary(e,!1).head;return e.head>i?i:Math.max(0,e.head-1)}))},{mac:"Mod-Delete",run:t=>Ff(t,(e=>{let i=t.moveToLineBoundary(e,!0).head;return e.head<i?i:Math.min(t.state.doc.length,e.head+1)}))}].concat([{key:"Ctrl-b",run:mf,shift:If,preventDefault:!0},{key:"Ctrl-f",run:gf,shift:Rf},{key:"Ctrl-p",run:yf,shift:Lf},{key:"Ctrl-n",run:Mf,shift:Nf},{key:"Ctrl-a",run:t=>af(t,(e=>B.cursor(t.lineBlockAt(e.head).from,1))),shift:t=>Df(t,(e=>B.cursor(t.lineBlockAt(e.head).from)))},{key:"Ctrl-e",run:t=>af(t,(e=>B.cursor(t.lineBlockAt(e.head).to,-1))),shift:t=>Df(t,(e=>B.cursor(t.lineBlockAt(e.head).to)))},{key:"Ctrl-d",run:Gf},{key:"Ctrl-h",run:Jf},{key:"Ctrl-k",run:t=>Ff(t,(e=>{let i=t.lineBlockAt(e.head).to;return e.head<i?i:Math.min(t.state.doc.length,e.head+1)}))},{key:"Ctrl-Alt-h",run:_f},{key:"Ctrl-o",run:({state:e,dispatch:i})=>{if(e.readOnly)return!1;let s=e.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t.of(["",""])},range:B.cursor(e.from)})));return i(e.update(s,{scrollIntoView:!0,userEvent:"input"})),!0}},{key:"Ctrl-t",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=t.changeByRange((e=>{if(!e.empty||0==e.from||e.from==t.doc.length)return{range:e};let i=e.from,s=t.doc.lineAt(i),r=i==s.from?i-1:p(s.text,i-s.from,!1)+s.from,n=i==s.to?i+1:p(s.text,i-s.from,!0)+s.from;return{changes:{from:r,to:n,insert:t.doc.slice(i,n).append(t.doc.slice(r,i))},range:B.cursor(n)}}));return!i.changes.empty&&(e(t.update(i,{scrollIntoView:!0,userEvent:"move.character"})),!0)}},{key:"Ctrl-v",run:Cf}].map((t=>({mac:t.key,run:t.run,shift:t.shift})))));function sa(){var t=arguments[0];"string"==typeof t&&(t=document.createElement(t));var e=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var r=i[s];"string"==typeof r?t.setAttribute(s,r):null!=r&&(t[s]=r)}e++}for(;e<arguments.length;e++)ra(t,arguments[e]);return t}function ra(t,e){if("string"==typeof e)t.appendChild(document.createTextNode(e));else if(null==e);else if(null!=e.nodeType)t.appendChild(e);else{if(!Array.isArray(e))throw new RangeError("Unsupported child node: "+e);for(var i=0;i<e.length;i++)ra(t,e[i])}}const na="function"==typeof String.prototype.normalize?t=>t.normalize("NFKD"):t=>t;class ha{constructor(t,e,i=0,s=t.length,r,n){this.test=n,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(i,s),this.bufferStart=i,this.normalize=r?t=>r(na(t)):na,this.query=this.normalize(e)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return v(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let e=k(t),i=this.bufferStart+this.bufferPos;this.bufferPos+=y(t);let s=this.normalize(e);for(let t=0,r=i;;t++){let n=s.charCodeAt(t),h=this.match(n,r,this.bufferPos+this.bufferStart);if(t==s.length-1){if(h)return this.value=h,this;break}r==i&&t<e.length&&e.charCodeAt(t)==n&&r++}}}match(t,e,i){let s=null;for(let e=0;e<this.matches.length;e+=2){let r=this.matches[e],n=!1;this.query.charCodeAt(r)==t&&(r==this.query.length-1?s={from:this.matches[e+1],to:i}:(this.matches[e]++,n=!0)),n||(this.matches.splice(e,2),e-=2)}return this.query.charCodeAt(0)==t&&(1==this.query.length?s={from:e,to:i}:this.matches.push(1,e)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}"undefined"!=typeof Symbol&&(ha.prototype[Symbol.iterator]=function(){return this});const la={from:-1,to:-1,match:/.*/.exec("")},oa="gm"+(null==/x/.unicode?"":"u");class ua{constructor(t,e,i,s=0,r=t.length){if(this.text=t,this.to=r,this.curLine="",this.done=!1,this.value=la,/\\[sWDnr]|\n|\r|\[\^/.test(e))return new ca(t,e,i,s,r);this.re=new RegExp(e,oa+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.iter=t.iter();let n=t.lineAt(s);this.curLineStart=n.from,this.matchPos=da(t,s),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let e=this.matchPos<=this.to&&this.re.exec(this.curLine);if(e){let i=this.curLineStart+e.index,s=i+e[0].length;if(this.matchPos=da(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,e)))return this.value={from:i,to:s,match:e},this;t=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),t=0}}}}const fa=new WeakMap;class aa{constructor(t,e){this.from=t,this.text=e}get to(){return this.from+this.text.length}static get(t,e,i){let s=fa.get(t);if(!s||s.from>=i||s.to<=e){let s=new aa(e,t.sliceString(e,i));return fa.set(t,s),s}if(s.from==e&&s.to==i)return s;let{text:r,from:n}=s;return n>e&&(r=t.sliceString(e,n)+r,n=e),s.to<i&&(r+=t.sliceString(s.to,i)),fa.set(t,new aa(n,r)),new aa(e,r.slice(e-n,i-n))}}class ca{constructor(t,e,i,s,r){this.text=t,this.to=r,this.done=!1,this.value=la,this.matchPos=da(t,s),this.re=new RegExp(e,oa+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.flat=aa.get(t,s,this.chunkEnd(s+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,e=this.re.exec(this.flat.text);if(e&&!e[0]&&e.index==t&&(this.re.lastIndex=t+1,e=this.re.exec(this.flat.text)),e){let t=this.flat.from+e.index,i=t+e[0].length;if((this.flat.to>=this.to||e.index+e[0].length<=this.flat.text.length-10)&&(!this.test||this.test(t,i,e)))return this.value={from:t,to:i,match:e},this.matchPos=da(this.text,i+(t==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=aa.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function da(t,e){if(e>=t.length)return e;let i,s=t.lineAt(e);for(;e<s.to&&(i=s.text.charCodeAt(e-s.from))>=56320&&i<57344;)e++;return e}function pa(t){let e=sa("input",{class:"cm-textfield",name:"line",value:String(t.state.doc.lineAt(t.state.selection.main.head).number)});function i(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(e.value);if(!i)return;let{state:s}=t,r=s.doc.lineAt(s.selection.main.head),[,n,h,l,o]=i,u=l?+l.slice(1):0,f=h?+h:r.number;if(h&&o){let t=f/100;n&&(t=t*("-"==n?-1:1)+r.number/s.doc.lines),f=Math.round(s.doc.lines*t)}else h&&n&&(f=f*("-"==n?-1:1)+r.number);let a=s.doc.line(Math.max(1,Math.min(s.doc.lines,f))),c=B.cursor(a.from+Math.max(0,Math.min(u,a.length)));t.dispatch({effects:[ma.of(!1),Ur.scrollIntoView(c.from,{y:"center"})],selection:c}),t.focus()}return{dom:sa("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:ma.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),i())},onsubmit:t=>{t.preventDefault(),i()}},sa("label",t.state.phrase("Go to line"),": ",e)," ",sa("button",{class:"cm-button",type:"submit"},t.state.phrase("go")))}}"undefined"!=typeof Symbol&&(ua.prototype[Symbol.iterator]=ca.prototype[Symbol.iterator]=function(){return this});const ma=ct.define(),ga=F.define({create:()=>!0,update(t,e){for(let i of e.effects)i.is(ma)&&(t=i.value);return t},provide:t=>fh.from(t,(t=>t?pa:null))}),wa=Ur.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),ba={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},va=j.define({combine:t=>At(t,ba,{highlightWordAroundCursor:(t,e)=>t||e,minSelectionLength:Math.min,maxMatches:Math.min})});const ka=ni.mark({class:"cm-selectionMatch"}),ya=ni.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Ma(t,e,i,s){return!(0!=i&&t(e.sliceDoc(i-1,i))==kt.Word||s!=e.doc.length&&t(e.sliceDoc(s,s+1))==kt.Word)}const xa=_i.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(va),{state:i}=t,s=i.selection;if(s.ranges.length>1)return ni.none;let r,n=s.main,h=null;if(n.empty){if(!e.highlightWordAroundCursor)return ni.none;let t=i.wordAt(n.head);if(!t)return ni.none;h=i.charCategorizer(n.head),r=i.sliceDoc(t.from,t.to)}else{let t=n.to-n.from;if(t<e.minSelectionLength||t>200)return ni.none;if(e.wholeWords){if(r=i.sliceDoc(n.from,n.to),h=i.charCategorizer(n.head),!Ma(h,i,n.from,n.to)||!function(t,e,i,s){return t(e.sliceDoc(i,i+1))==kt.Word&&t(e.sliceDoc(s-1,s))==kt.Word}(h,i,n.from,n.to))return ni.none}else if(r=i.sliceDoc(n.from,n.to),!r)return ni.none}let l=[];for(let s of t.visibleRanges){let t=new ha(i.doc,r,s.from,s.to);for(;!t.next().done;){let{from:s,to:r}=t.value;if((!h||Ma(h,i,s,r))&&(n.empty&&s<=n.from&&r>=n.to?l.push(ya.range(s,r)):(s>=n.to||r<=n.from)&&l.push(ka.range(s,r)),l.length>e.maxMatches))return ni.none}}return ni.set(l)}},{decorations:t=>t.decorations}),Sa=Ur.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const Aa=j.define({combine:t=>At(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new tc(t),scrollToMatch:t=>Ur.scrollIntoView(t)})});class Ca{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||function(t){try{return new RegExp(t,oa),!0}catch(t){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,((t,e)=>"n"==e?"\n":"r"==e?"\r":"t"==e?"\t":"\\"))}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord}create(){return this.regexp?new Ba(this):new Ea(this)}getCursor(t,e=0,i){let s=t.doc?t:St.create({doc:t});return null==i&&(i=s.doc.length),this.regexp?Ia(this,s,e,i):Da(this,s,e,i)}}class Oa{constructor(t){this.spec=t}}function Da(t,e,i,s){return new ha(e.doc,t.unquoted,i,s,t.caseSensitive?void 0:t=>t.toLowerCase(),t.wholeWord?function(t,e){return(i,s,r,n)=>((n>i||n+r.length<s)&&(n=Math.max(0,i-2),r=t.sliceString(n,Math.min(t.length,s+2))),!(e(Ra(r,i-n))==kt.Word&&e(Ta(r,i-n))==kt.Word||e(Ta(r,s-n))==kt.Word&&e(Ra(r,s-n))==kt.Word))}(e.doc,e.charCategorizer(e.selection.main.head)):void 0)}class Ea extends Oa{constructor(t){super(t)}nextMatch(t,e,i){let s=Da(this.spec,t,i,t.doc.length).nextOverlapping();return s.done&&(s=Da(this.spec,t,0,e).nextOverlapping()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=i;;){let i=Math.max(e,s-1e4-this.spec.unquoted.length),r=Da(this.spec,t,i,s),n=null;for(;!r.nextOverlapping().done;)n=r.value;if(n)return n;if(i==e)return null;s-=1e4}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,e){let i=Da(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Da(this.spec,t,Math.max(0,e-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ia(t,e,i,s){return new ua(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:t.wholeWord?(r=e.charCategorizer(e.selection.main.head),(t,e,i)=>!i[0].length||(r(Ra(i.input,i.index))!=kt.Word||r(Ta(i.input,i.index))!=kt.Word)&&(r(Ta(i.input,i.index+i[0].length))!=kt.Word||r(Ra(i.input,i.index+i[0].length))!=kt.Word)):void 0},i,s);var r}function Ra(t,e){return t.slice(p(t,e,!1),e)}function Ta(t,e){return t.slice(e,p(t,e))}class Ba extends Oa{nextMatch(t,e,i){let s=Ia(this.spec,t,i,t.doc.length).next();return s.done&&(s=Ia(this.spec,t,0,e).next()),s.done?null:s.value}prevMatchInRange(t,e,i){for(let s=1;;s++){let r=Math.max(e,i-1e4*s),n=Ia(this.spec,t,r,i),h=null;for(;!n.next().done;)h=n.value;if(h&&(r==e||h.from>r+10))return h;if(r==e)return null}}prevMatch(t,e,i){return this.prevMatchInRange(t,0,e)||this.prevMatchInRange(t,i,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&\d+])/g,((e,i)=>"$"==i?"$":"&"==i?t.match[0]:"0"!=i&&+i<t.match.length?t.match[i]:e))}matchAll(t,e){let i=Ia(this.spec,t,0,t.doc.length),s=[];for(;!i.next().done;){if(s.length>=e)return null;s.push(i.value)}return s}highlight(t,e,i,s){let r=Ia(this.spec,t,Math.max(0,e-250),Math.min(i+250,t.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const La=ct.define(),Na=ct.define(),ja=F.define({create:t=>new $a(Ka(t).create(),null),update(t,e){for(let i of e.effects)i.is(La)?t=new $a(i.value.create(),t.panel):i.is(Na)&&(t=new $a(t.query,i.value?Ga:null));return t},provide:t=>fh.from(t,(t=>t.panel))});class $a{constructor(t,e){this.query=t,this.panel=e}}const za=ni.mark({class:"cm-searchMatch"}),Pa=ni.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Ha=_i.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(ja))}update(t){let e=t.state.field(ja);(e!=t.startState.field(ja)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return ni.none;let{view:i}=this,s=new Rt;for(let e=0,r=i.visibleRanges,n=r.length;e<n;e++){let{from:h,to:l}=r[e];for(;e<n-1&&l>r[e+1].from-500;)l=r[++e].to;t.highlight(i.state,h,l,((t,e)=>{let r=i.state.selection.ranges.some((i=>i.from==t&&i.to==e));s.add(t,e,r?Pa:za)}))}return s.finish()}},{decorations:t=>t.decorations});function Wa(t){return e=>{let i=e.state.field(ja,!1);return i&&i.query.spec.valid?t(e,i):Ya(e)}}const Va=Wa(((t,{query:e})=>{let{to:i}=t.state.selection.main,s=e.nextMatch(t.state,i,i);if(!s)return!1;let r=B.single(s.from,s.to),n=t.state.facet(Aa);return t.dispatch({selection:r,effects:[rc(t,s),n.scrollToMatch(r.main,t)],userEvent:"select.search"}),Xa(t),!0})),Fa=Wa(((t,{query:e})=>{let{state:i}=t,{from:s}=i.selection.main,r=e.prevMatch(i,s,s);if(!r)return!1;let n=B.single(r.from,r.to),h=t.state.facet(Aa);return t.dispatch({selection:n,effects:[rc(t,r),h.scrollToMatch(n.main,t)],userEvent:"select.search"}),Xa(t),!0})),qa=Wa(((t,{query:e})=>{let i=e.matchAll(t.state,1e3);return!(!i||!i.length)&&(t.dispatch({selection:B.create(i.map((t=>B.range(t.from,t.to)))),userEvent:"select.search.matches"}),!0)})),Ua=Wa(((t,{query:e})=>{let{state:i}=t,{from:s,to:r}=i.selection.main;if(i.readOnly)return!1;let n=e.nextMatch(i,s,s);if(!n)return!1;let h,l,o=[],u=[];if(n.from==s&&n.to==r&&(l=i.toText(e.getReplacement(n)),o.push({from:n.from,to:n.to,insert:l}),n=e.nextMatch(i,n.from,n.to),u.push(Ur.announce.of(i.phrase("replaced match on line $",i.doc.lineAt(s).number)+"."))),n){let e=0==o.length||o[0].from>=n.to?0:n.to-n.from-l.length;h=B.single(n.from-e,n.to-e),u.push(rc(t,n)),u.push(i.facet(Aa).scrollToMatch(h.main,t))}return t.dispatch({changes:o,selection:h,effects:u,userEvent:"input.replace"}),!0})),Ja=Wa(((t,{query:e})=>{if(t.state.readOnly)return!1;let i=e.matchAll(t.state,1e9).map((t=>{let{from:i,to:s}=t;return{from:i,to:s,insert:e.getReplacement(t)}}));if(!i.length)return!1;let s=t.state.phrase("replaced $ matches",i.length)+".";return t.dispatch({changes:i,effects:Ur.announce.of(s),userEvent:"input.replace.all"}),!0}));function Ga(t){return t.state.facet(Aa).createPanel(t)}function Ka(t,e){var i,s,r,n,h;let l=t.selection.main,o=l.empty||l.to>l.from+100?"":t.sliceDoc(l.from,l.to);if(e&&!o)return e;let u=t.facet(Aa);return new Ca({search:(null!==(i=null==e?void 0:e.literal)&&void 0!==i?i:u.literal)?o:o.replace(/\n/g,"\\n"),caseSensitive:null!==(s=null==e?void 0:e.caseSensitive)&&void 0!==s?s:u.caseSensitive,literal:null!==(r=null==e?void 0:e.literal)&&void 0!==r?r:u.literal,regexp:null!==(n=null==e?void 0:e.regexp)&&void 0!==n?n:u.regexp,wholeWord:null!==(h=null==e?void 0:e.wholeWord)&&void 0!==h?h:u.wholeWord})}function _a(t){let e=hh(t,Ga);return e&&e.dom.querySelector("[main-field]")}function Xa(t){let e=_a(t);e&&e==t.root.activeElement&&e.select()}const Ya=t=>{let e=t.state.field(ja,!1);if(e&&e.panel){let i=_a(t);if(i&&i!=t.root.activeElement){let s=Ka(t.state,e.query.spec);s.valid&&t.dispatch({effects:La.of(s)}),i.focus(),i.select()}}else t.dispatch({effects:[Na.of(!0),e?La.of(Ka(t.state,e.query.spec)):ct.appendConfig.of(hc)]});return!0},Qa=t=>{let e=t.state.field(ja,!1);if(!e||!e.panel)return!1;let i=hh(t,Ga);return i&&i.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Na.of(!1)}),!0},Za=[{key:"Mod-f",run:Ya,scope:"editor search-panel"},{key:"F3",run:Va,shift:Fa,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:Va,shift:Fa,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Qa,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:t,dispatch:e})=>{let i=t.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:s,to:r}=i.main,n=[],h=0;for(let e=new ha(t.doc,t.sliceDoc(s,r));!e.next().done;){if(n.length>1e3)return!1;e.value.from==s&&(h=n.length),n.push(B.range(e.value.from,e.value.to))}return e(t.update({selection:B.create(n,h),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:t=>{let e=hh(t,pa);if(!e){let i=[ma.of(!0)];null==t.state.field(ga,!1)&&i.push(ct.appendConfig.of([ga,wa])),t.dispatch({effects:i}),e=hh(t,pa)}return e&&e.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:t,dispatch:e})=>{let{ranges:i}=t.selection;if(i.some((t=>t.from===t.to)))return(({state:t,dispatch:e})=>{let{selection:i}=t,s=B.create(i.ranges.map((e=>t.wordAt(e.head)||B.cursor(e.head))),i.mainIndex);return!s.eq(i)&&(e(t.update({selection:s})),!0)})({state:t,dispatch:e});let s=t.sliceDoc(i[0].from,i[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=s)))return!1;let r=function(t,e){let{main:i,ranges:s}=t.selection,r=t.wordAt(i.head),n=r&&r.from==i.from&&r.to==i.to;for(let i=!1,r=new ha(t.doc,e,s[s.length-1].to);;){if(r.next(),!r.done){if(i&&s.some((t=>t.from==r.value.from)))continue;if(n){let e=t.wordAt(r.value.from);if(!e||e.from!=r.value.from||e.to!=r.value.to)continue}return r.value}if(i)return null;r=new ha(t.doc,e,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(t,s);return!!r&&(e(t.update({selection:t.selection.addRange(B.range(r.from,r.to),!1),effects:Ur.scrollIntoView(r.to)})),!0)},preventDefault:!0}];class tc{constructor(t){this.view=t;let e=this.query=t.state.field(ja).query.spec;function i(t,e,i){return sa("button",{class:"cm-button",name:t,onclick:e,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=sa("input",{value:e.search,placeholder:ec(t,"Find"),"aria-label":ec(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=sa("input",{value:e.replace,placeholder:ec(t,"Replace"),"aria-label":ec(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=sa("input",{type:"checkbox",name:"case",form:"",checked:e.caseSensitive,onchange:this.commit}),this.reField=sa("input",{type:"checkbox",name:"re",form:"",checked:e.regexp,onchange:this.commit}),this.wordField=sa("input",{type:"checkbox",name:"word",form:"",checked:e.wholeWord,onchange:this.commit}),this.dom=sa("div",{onkeydown:t=>this.keydown(t),class:"cm-search"},[this.searchField,i("next",(()=>Va(t)),[ec(t,"next")]),i("prev",(()=>Fa(t)),[ec(t,"previous")]),i("select",(()=>qa(t)),[ec(t,"all")]),sa("label",null,[this.caseField,ec(t,"match case")]),sa("label",null,[this.reField,ec(t,"regexp")]),sa("label",null,[this.wordField,ec(t,"by word")]),...t.state.readOnly?[]:[sa("br"),this.replaceField,i("replace",(()=>Ua(t)),[ec(t,"replace")]),i("replaceAll",(()=>Ja(t)),[ec(t,"replace all")])],sa("button",{name:"close",onclick:()=>Qa(t),"aria-label":ec(t,"close"),type:"button"},["×"])])}commit(){let t=new Ca({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:La.of(t)}))}keydown(t){var e,i,s;e=this.view,i=t,s="search-panel",nn(en(e.state),i,e,s)?t.preventDefault():13==t.keyCode&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?Fa:Va)(this.view)):13==t.keyCode&&t.target==this.replaceField&&(t.preventDefault(),Ua(this.view))}update(t){for(let e of t.transactions)for(let t of e.effects)t.is(La)&&!t.value.eq(this.query)&&this.setQuery(t.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Aa).top}}function ec(t,e){return t.state.phrase(e)}const ic=30,sc=/[\s\.,:;?!]/;function rc(t,{from:e,to:i}){let s=t.state.doc.lineAt(e),r=t.state.doc.lineAt(i).to,n=Math.max(s.from,e-ic),h=Math.min(r,i+ic),l=t.state.sliceDoc(n,h);if(n!=s.from)for(let t=0;t<ic;t++)if(!sc.test(l[t+1])&&sc.test(l[t])){l=l.slice(t);break}if(h!=r)for(let t=l.length-1;t>l.length-ic;t--)if(!sc.test(l[t-1])&&sc.test(l[t])){l=l.slice(0,t);break}return Ur.announce.of(`${t.state.phrase("current match")}. ${l} ${t.state.phrase("on line")} ${s.number}.`)}const nc=Ur.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),hc=[ja,_.low(Ha),nc];class lc{constructor(t,e,i){this.state=t,this.pos=e,this.explicit=i,this.abortListeners=[]}tokenBefore(t){let e=no(this.state).resolveInner(this.pos,-1);for(;e&&t.indexOf(e.name)<0;)e=e.parent;return e?{from:e.from,to:this.pos,text:this.state.sliceDoc(e.from,this.pos),type:e.type}:null}matchBefore(t){let e=this.state.doc.lineAt(this.pos),i=Math.max(e.from,this.pos-250),s=e.text.slice(i-e.from,this.pos-e.from),r=s.search(dc(t,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return null==this.abortListeners}addEventListener(t,e){"abort"==t&&this.abortListeners&&this.abortListeners.push(e)}}function oc(t){let e=Object.keys(t).join(""),i=/\w/.test(e);return i&&(e=e.replace(/\w/g,"")),`[${i?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function uc(t){let e=t.map((t=>"string"==typeof t?{label:t}:t)),[i,s]=e.every((t=>/^\w+$/.test(t.label)))?[/\w*$/,/\w+$/]:function(t){let e=Object.create(null),i=Object.create(null);for(let{label:s}of t){e[s[0]]=!0;for(let t=1;t<s.length;t++)i[s[t]]=!0}let s=oc(e)+oc(i)+"*$";return[new RegExp("^"+s),new RegExp(s)]}(e);return t=>{let r=t.matchBefore(s);return r||t.explicit?{from:r?r.from:t.pos,options:e,validFor:i}:null}}function fc(t,e){return i=>{for(let e=no(i.state).resolveInner(i.pos,-1);e;e=e.parent){if(t.indexOf(e.name)>-1)return null;if(e.type.isTop)break}return e(i)}}class ac{constructor(t,e,i,s){this.completion=t,this.source=e,this.match=i,this.score=s}}function cc(t){return t.selection.main.from}function dc(t,e){var i;let{source:s}=t,r=e&&"^"!=s[0],n="$"!=s[s.length-1];return r||n?new RegExp(`${r?"^":""}(?:${s})${n?"$":""}`,null!==(i=t.flags)&&void 0!==i?i:t.ignoreCase?"i":""):t}const pc=ut.define();const mc=new WeakMap;function gc(t){if(!Array.isArray(t))return t;let e=mc.get(t);return e||mc.set(t,e=uc(t)),e}const wc=ct.define(),bc=ct.define();class vc{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=v(t,e),s=y(i);this.chars.push(i);let r=t.slice(e,e+s),n=r.toUpperCase();this.folded.push(v(n==r?r.toLowerCase():n,0)),e+=s}this.astral=t.length!=this.chars.length}ret(t,e){return this.score=t,this.matched=e,this}match(t){if(0==this.pattern.length)return this.ret(-100,[]);if(t.length<this.pattern.length)return null;let{chars:e,folded:i,any:s,precise:r,byWord:n}=this;if(1==e.length){let s=v(t,0),r=y(s),n=r==t.length?0:-100;if(s==e[0]);else{if(s!=i[0])return null;n+=-200}return this.ret(n,[0,r])}let h=t.indexOf(this.pattern);if(0==h)return this.ret(t.length==this.pattern.length?0:-100,[0,this.pattern.length]);let l=e.length,o=0;if(h<0){for(let r=0,n=Math.min(t.length,200);r<n&&o<l;){let n=v(t,r);n!=e[o]&&n!=i[o]||(s[o++]=r),r+=y(n)}if(o<l)return null}let u=0,f=0,a=!1,c=0,d=-1,p=-1,m=/[a-z]/.test(t),g=!0;for(let s=0,o=Math.min(t.length,200),w=0;s<o&&f<l;){let o=v(t,s);h<0&&(u<l&&o==e[u]&&(r[u++]=s),c<l&&(o==e[c]||o==i[c]?(0==c&&(d=s),p=s+1,c++):c=0));let b,M=o<255?o>=48&&o<=57||o>=97&&o<=122?2:o>=65&&o<=90?1:0:(b=k(o))!=b.toLowerCase()?1:b!=b.toUpperCase()?2:0;(!s||1==M&&m||0==w&&0!=M)&&(e[f]==o||i[f]==o&&(a=!0)?n[f++]=s:n.length&&(g=!1)),w=M,s+=y(o)}return f==l&&0==n[0]&&g?this.result((a?-200:0)-100,n,t):c==l&&0==d?this.ret(-200-t.length+(p==t.length?0:-100),[0,p]):h>-1?this.ret(-700-t.length,[h,h+this.pattern.length]):c==l?this.ret(-900-t.length,[d,p]):f==l?this.result((a?-200:0)-100-700+(g?0:-1100),n,t):2==e.length?null:this.result((s[0]?-700:0)-200-1100,s,t)}result(t,e,i){let s=[],r=0;for(let t of e){let e=t+(this.astral?y(v(i,t)):1);r&&s[r-1]==t?s[r-1]=e:(s[r++]=t,s[r++]=e)}return this.ret(t-i.length,s)}}class kc{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 null==i?null:(this.matched=[0,e.length],this.score=i+(t.length==this.pattern.length?0:-100),this)}}const yc=j.define({combine:t=>At(t,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:xc,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=>Mc(t(i),e(i)),optionClass:(t,e)=>i=>Mc(t(i),e(i)),addToOptions:(t,e)=>t.concat(e),filterStrict:(t,e)=>t||e})});function Mc(t,e){return t?e?t+" "+e:t:e}function xc(t,e,i,s,r,n){let h,l,o=t.textDirection==pi.RTL,u=o,f=!1,a="top",c=e.left-r.left,d=r.right-e.right,p=s.right-s.left,m=s.bottom-s.top;if(u&&c<Math.min(p,d)?u=!1:!u&&d<Math.min(p,c)&&(u=!0),p<=(u?c:d))h=Math.max(r.top,Math.min(i.top,r.bottom-m))-e.top,l=Math.min(400,u?c:d);else{f=!0,l=Math.min(400,(o?e.right:r.right-e.left)-30);let t=r.bottom-e.bottom;t>=m||t>e.top?h=i.bottom-e.top:(a="bottom",h=e.bottom-i.top)}return{style:`${a}: ${h/((e.bottom-e.top)/n.offsetHeight)}px; max-width: ${l/((e.right-e.left)/n.offsetWidth)}px`,class:"cm-completionInfo-"+(f?o?"left-narrow":"right-narrow":u?"left":"right")}}function Sc(t,e,i){if(t<=i)return{from:0,to:t};if(e<0&&(e=0),e<=t>>1){let t=Math.floor(e/i);return{from:t*i,to:(t+1)*i}}let s=Math.floor((t-e)/i);return{from:t-(s+1)*i,to:t-s*i}}class Ac{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:t=>this.placeInfo(t),key:this},this.space=null,this.currentClass="";let s=t.state.field(e),{options:r,selected:n}=s.open,h=t.state.facet(yc);this.optionContent=function(t){let e=t.addToOptions.slice();return t.icons&&e.push({render(t){let e=document.createElement("div");return e.classList.add("cm-completionIcon"),t.type&&e.classList.add(...t.type.split(/\s+/g).map((t=>"cm-completionIcon-"+t))),e.setAttribute("aria-hidden","true"),e},position:20}),e.push({render(t,e,i,s){let r=document.createElement("span");r.className="cm-completionLabel";let n=t.displayLabel||t.label,h=0;for(let t=0;t<s.length;){let e=s[t++],i=s[t++];e>h&&r.appendChild(document.createTextNode(n.slice(h,e)));let l=r.appendChild(document.createElement("span"));l.appendChild(document.createTextNode(n.slice(e,i))),l.className="cm-completionMatchedText",h=i}return h<n.length&&r.appendChild(document.createTextNode(n.slice(h))),r},position:50},{render(t){if(!t.detail)return null;let e=document.createElement("span");return e.className="cm-completionDetail",e.textContent=t.detail,e},position:80}),e.sort(((t,e)=>t.position-e.position)).map((t=>t.render))}(h),this.optionClass=h.optionClass,this.tooltipClass=h.tooltipClass,this.range=Sc(r.length,n,h.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(t.state),this.dom.addEventListener("mousedown",(i=>{let{options:s}=t.state.field(e).open;for(let e,r=i.target;r&&r!=this.dom;r=r.parentNode)if("LI"==r.nodeName&&(e=/-(\d+)$/.exec(r.id))&&+e[1]<s.length)return this.applyCompletion(t,s[+e[1]]),void i.preventDefault()})),this.dom.addEventListener("focusout",(e=>{let i=t.state.field(this.stateField,!1);i&&i.tooltip&&t.state.facet(yc).closeOnBlur&&e.relatedTarget!=t.contentDOM&&t.dispatch({effects:bc.of(null)})})),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(t,e){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(t,e,this.range)),this.list.addEventListener("scroll",(()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)}))}update(t){var e;let i=t.state.field(this.stateField),s=t.startState.field(this.stateField);if(this.updateTooltipClass(t.state),i!=s){let{options:r,selected:n,disabled:h}=i.open;s.open&&s.open.options==r||(this.range=Sc(r.length,n,t.state.facet(yc).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),h!=(null===(e=s.open)||void 0===e?void 0:e.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!h)}}updateTooltipClass(t){let e=this.tooltipClass(t);if(e!=this.currentClass){for(let t of this.currentClass.split(" "))t&&this.dom.classList.remove(t);for(let t of e.split(" "))t&&this.dom.classList.add(t);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=Sc(e.options.length,e.selected,this.view.state.facet(yc).maxRenderedOptions),this.showOptions(e.options,t.id)),this.updateSelectedOption(e.selected)){this.destroyInfo();let{completion:i}=e.options[e.selected],{info:s}=i;if(!s)return;let r="string"==typeof s?document.createTextNode(s):s(i);if(!r)return;"then"in r?r.then((e=>{e&&this.view.state.field(this.stateField,!1)==t&&this.addInfoPane(e,i)})).catch((t=>Ui(this.view.state,t,"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",null!=t.nodeType)i.appendChild(t),this.infoDestroy=null;else{let{dom:e,destroy:s}=t;i.appendChild(e),this.infoDestroy=s||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(t){let e=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)"LI"==i.nodeName&&i.id?s==t?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),e=i):i.hasAttribute("aria-selected")&&i.removeAttribute("aria-selected"):s--;return e&&function(t,e){let i=t.getBoundingClientRect(),s=e.getBoundingClientRect(),r=i.height/t.offsetHeight;s.top<i.top?t.scrollTop-=(i.top-s.top)/r:s.bottom>i.bottom&&(t.scrollTop+=(s.bottom-i.bottom)/r)}(this.list,e),e}measureInfo(){let t=this.dom.querySelector("[aria-selected]");if(!t||!this.info)return null;let e=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=t.getBoundingClientRect(),r=this.space;if(!r){let t=this.dom.ownerDocument.defaultView||window;r={left:0,top:0,right:t.innerWidth,bottom:t.innerHeight}}return s.top>Math.min(r.bottom,e.bottom)-10||s.bottom<Math.max(r.top,e.top)+10?null:this.view.state.facet(yc).positionInfo(this.view,e,s,i,r,this.dom)}placeInfo(t){this.info&&(t?(t.style&&(this.info.style.cssText=t.style),this.info.className="cm-tooltip cm-completionInfo "+(t.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(t,e,i){const s=document.createElement("ul");s.id=e,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions"));let r=null;for(let n=i.from;n<i.to;n++){let{completion:h,match:l}=t[n],{section:o}=h;if(o){let t="string"==typeof o?o:o.name;if(t!=r&&(n>i.from||0==i.from))if(r=t,"string"!=typeof o&&o.header)s.appendChild(o.header(o));else{s.appendChild(document.createElement("completion-section")).textContent=t}}const u=s.appendChild(document.createElement("li"));u.id=e+"-"+n,u.setAttribute("role","option");let f=this.optionClass(h);f&&(u.className=f);for(let t of this.optionContent){let e=t(h,this.view.state,this.view,l);e&&u.appendChild(e)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<t.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Cc(t,e){return i=>new Ac(i,t,e)}function Oc(t){return 100*(t.boost||0)+(t.apply?10:0)+(t.info?5:0)+(t.type?1:0)}class Dc{constructor(t,e,i,s,r,n){this.options=t,this.attrs=e,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=n}setSelected(t,e){return t==this.selected||t>=this.options.length?this:new Dc(this.options,Rc(e,t),this.tooltip,this.timestamp,t,this.disabled)}static build(t,e,i,s,r){let n=function(t,e){let i=[],s=null,r=t=>{i.push(t);let{section:e}=t.completion;if(e){s||(s=[]);let t="string"==typeof e?e:e.name;s.some((e=>e.name==t))||s.push("string"==typeof e?{name:t}:e)}},n=e.facet(yc);for(let s of t)if(s.hasResult()){let t=s.result.getMatch;if(!1===s.result.filter)for(let e of s.result.options)r(new ac(e,s.source,t?t(e):[],1e9-i.length));else{let i,h=e.sliceDoc(s.from,s.to),l=n.filterStrict?new kc(h):new vc(h);for(let e of s.result.options)if(i=l.match(e.label)){let n=e.displayLabel?t?t(e,i.matched):[]:i.matched;r(new ac(e,s.source,n,i.score+(e.boost||0)))}}}if(s){let t=Object.create(null),e=0,r=(t,e)=>{var i,s;return(null!==(i=t.rank)&&void 0!==i?i:1e9)-(null!==(s=e.rank)&&void 0!==s?s:1e9)||(t.name<e.name?-1:1)};for(let i of s.sort(r))e-=1e5,t[i.name]=e;for(let e of i){let{section:i}=e.completion;i&&(e.score+=t["string"==typeof i?i:i.name])}}let h=[],l=null,o=n.compareCompletions;for(let t of i.sort(((t,e)=>e.score-t.score||o(t.completion,e.completion)))){let e=t.completion;!l||l.label!=e.label||l.detail!=e.detail||null!=l.type&&null!=e.type&&l.type!=e.type||l.apply!=e.apply||l.boost!=e.boost?h.push(t):Oc(t.completion)>Oc(l)&&(h[h.length-1]=t),l=t.completion}return h}(t,e);if(!n.length)return s&&t.some((t=>1==t.state))?new Dc(s.options,s.attrs,s.tooltip,s.timestamp,s.selected,!0):null;let h=e.facet(yc).selectOnOpen?0:-1;if(s&&s.selected!=h&&-1!=s.selected){let t=s.options[s.selected].completion;for(let e=0;e<n.length;e++)if(n[e].completion==t){h=e;break}}return new Dc(n,Rc(i,h),{pos:t.reduce(((t,e)=>e.hasResult()?Math.min(t,e.from):t),1e8),create:Hc,above:r.aboveCursor},s?s.timestamp:Date.now(),h,!1)}map(t){return new Dc(this.options,this.attrs,Object.assign(Object.assign({},this.tooltip),{pos:t.mapPos(this.tooltip.pos)}),this.timestamp,this.selected,this.disabled)}}class Ec{constructor(t,e,i){this.active=t,this.id=e,this.open=i}static start(){return new Ec(Tc,"cm-ac-"+Math.floor(2e6*Math.random()).toString(36),null)}update(t){let{state:e}=t,i=e.facet(yc),s=(i.override||e.languageDataAt("autocomplete",cc(e)).map(gc)).map((e=>(this.active.find((t=>t.source==e))||new Lc(e,this.active.some((t=>0!=t.state))?1:0)).update(t,i)));s.length==this.active.length&&s.every(((t,e)=>t==this.active[e]))&&(s=this.active);let r=this.open;r&&t.docChanged&&(r=r.map(t.changes)),t.selection||s.some((e=>e.hasResult()&&t.changes.touchesRange(e.from,e.to)))||!function(t,e){if(t==e)return!0;for(let i=0,s=0;;){for(;i<t.length&&!t[i].hasResult;)i++;for(;s<e.length&&!e[s].hasResult;)s++;let r=i==t.length,n=s==e.length;if(r||n)return r==n;if(t[i++].result!=e[s++].result)return!1}}(s,this.active)?r=Dc.build(s,e,this.id,r,i):r&&r.disabled&&!s.some((t=>1==t.state))&&(r=null),!r&&s.every((t=>1!=t.state))&&s.some((t=>t.hasResult()))&&(s=s.map((t=>t.hasResult()?new Lc(t.source,0):t)));for(let e of t.effects)e.is($c)&&(r=r&&r.setSelected(e.value,this.id));return s==this.active&&r==this.open?this:new Ec(s,this.id,r)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:Ic}}const Ic={"aria-autocomplete":"list"};function Rc(t,e){let i={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":t};return e>-1&&(i["aria-activedescendant"]=t+"-"+e),i}const Tc=[];function Bc(t,e){if(t.isUserEvent("input.complete")){let i=t.annotation(pc);if(i&&e.activateOnCompletion(i))return"input"}return t.isUserEvent("input.type")?"input":t.isUserEvent("delete.backward")?"delete":null}class Lc{constructor(t,e,i=-1){this.source=t,this.state=e,this.explicitPos=i}hasResult(){return!1}update(t,e){let i=Bc(t,e),s=this;i?s=s.handleUserEvent(t,i,e):t.docChanged?s=s.handleChange(t):t.selection&&0!=s.state&&(s=new Lc(s.source,0));for(let e of t.effects)if(e.is(wc))s=new Lc(s.source,1,e.value?cc(t.state):-1);else if(e.is(bc))s=new Lc(s.source,0);else if(e.is(jc))for(let t of e.value)t.source==s.source&&(s=t);return s}handleUserEvent(t,e,i){return"delete"!=e&&i.activateOnTyping?new Lc(this.source,1):this.map(t.changes)}handleChange(t){return t.changes.touchesRange(cc(t.startState))?new Lc(this.source,0):this.map(t.changes)}map(t){return t.empty||this.explicitPos<0?this:new Lc(this.source,this.state,t.mapPos(this.explicitPos))}}class Nc extends Lc{constructor(t,e,i,s,r){super(t,2,e),this.result=i,this.from=s,this.to=r}hasResult(){return!0}handleUserEvent(t,e,i){var s;let r=this.result;r.map&&!t.changes.empty&&(r=r.map(r,t.changes));let n=t.changes.mapPos(this.from),h=t.changes.mapPos(this.to,1),l=cc(t.state);if((this.explicitPos<0?l<=n:l<this.from)||l>h||!r||"delete"==e&&cc(t.startState)==this.from)return new Lc(this.source,"input"==e&&i.activateOnTyping?1:0);let o=this.explicitPos<0?-1:t.changes.mapPos(this.explicitPos);return function(t,e,i,s){if(!t)return!1;let r=e.sliceDoc(i,s);return"function"==typeof t?t(r,i,s,e):dc(t,!0).test(r)}(r.validFor,t.state,n,h)?new Nc(this.source,o,r,n,h):r.update&&(r=r.update(r,n,h,new lc(t.state,l,o>=0)))?new Nc(this.source,o,r,r.from,null!==(s=r.to)&&void 0!==s?s:cc(t.state)):new Lc(this.source,1,o)}handleChange(t){return t.changes.touchesRange(this.from,this.to)?new Lc(this.source,0):this.map(t.changes)}map(t){if(t.empty)return this;return(this.result.map?this.result.map(this.result,t):this.result)?new Nc(this.source,this.explicitPos<0?-1:t.mapPos(this.explicitPos),this.result,t.mapPos(this.from),t.mapPos(this.to,1)):new Lc(this.source,0)}}const jc=ct.define({map:(t,e)=>t.map((t=>t.map(e)))}),$c=ct.define(),zc=F.define({create:()=>Ec.start(),update:(t,e)=>t.update(e),provide:t=>[Xn.from(t,(t=>t.tooltip)),Ur.contentAttributes.from(t,(t=>t.attrs))]});function Pc(t,e){const i=e.completion.apply||e.completion.label;let s=t.state.field(zc).active.find((t=>t.source==e.source));return s instanceof Nc&&("string"==typeof i?t.dispatch(Object.assign(Object.assign({},function(t,e,i,s){let{main:r}=t.selection,n=i-r.from,h=s-r.from;return Object.assign(Object.assign({},t.changeByRange((l=>l!=r&&i!=s&&t.sliceDoc(l.from+n,l.from+h)!=t.sliceDoc(i,s)?{range:l}:{changes:{from:l.from+n,to:s==r.from?l.to:l.from+h,insert:e},range:B.cursor(l.from+n+e.length)}))),{scrollIntoView:!0,userEvent:"input.complete"})}(t.state,i,s.from,s.to)),{annotations:pc.of(e.completion)})):i(t,e.completion,s.from,s.to),!0)}const Hc=Cc(zc,Pc);function Wc(t,e="option"){return i=>{let s=i.state.field(zc,!1);if(!s||!s.open||s.open.disabled||Date.now()-s.open.timestamp<i.state.facet(yc).interactionDelay)return!1;let r,n=1;"page"==e&&(r=sh(i,s.open.tooltip))&&(n=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:h}=s.open.options,l=s.open.selected>-1?s.open.selected+n*(t?1:-1):t?0:h-1;return l<0?l="page"==e?0:h-1:l>=h&&(l="page"==e?h-1:0),i.dispatch({effects:$c.of(l)}),!0}}class Vc{constructor(t,e){this.active=t,this.context=e,this.time=Date.now(),this.updates=[],this.done=void 0}}const Fc=_i.fromClass(class{constructor(t){this.view=t,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of t.state.field(zc).active)1==e.state&&this.startQuery(e)}update(t){let e=t.state.field(zc),i=t.state.facet(yc);if(!t.selectionSet&&!t.docChanged&&t.startState.field(zc)==e)return;let s=t.transactions.some((t=>(t.selection||t.docChanged)&&!Bc(t,i)));for(let e=0;e<this.running.length;e++){let i=this.running[e];if(s||i.updates.length+t.transactions.length>50&&Date.now()-i.time>1e3){for(let t of i.context.abortListeners)try{t()}catch(t){Ui(this.view.state,t)}i.context.abortListeners=null,this.running.splice(e--,1)}else i.updates.push(...t.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),t.transactions.some((t=>t.effects.some((t=>t.is(wc)))))&&(this.pendingStart=!0);let r=this.pendingStart?50:i.activateOnTypingDelay;if(this.debounceUpdate=e.active.some((t=>1==t.state&&!this.running.some((e=>e.active.source==t.source))))?setTimeout((()=>this.startUpdate()),r):-1,0!=this.composing)for(let e of t.transactions)"input"==Bc(e,i)?this.composing=2:2==this.composing&&e.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:t}=this.view,e=t.field(zc);for(let t of e.active)1!=t.state||this.running.some((e=>e.active.source==t.source))||this.startQuery(t)}startQuery(t){let{state:e}=this.view,i=cc(e),s=new lc(e,i,t.explicitPos==i),r=new Vc(t,s);this.running.push(r),Promise.resolve(t.source(s)).then((t=>{r.context.aborted||(r.done=t||null,this.scheduleAccept())}),(t=>{this.view.dispatch({effects:bc.of(null)}),Ui(this.view.state,t)}))}scheduleAccept(){this.running.every((t=>void 0!==t.done))?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout((()=>this.accept()),this.view.state.facet(yc).updateSyncTime))}accept(){var t;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],i=this.view.state.facet(yc);for(let s=0;s<this.running.length;s++){let r=this.running[s];if(void 0===r.done)continue;if(this.running.splice(s--,1),r.done){let s=new Nc(r.active.source,r.active.explicitPos,r.done,r.done.from,null!==(t=r.done.to)&&void 0!==t?t:cc(r.updates.length?r.updates[0].startState:this.view.state));for(let t of r.updates)s=s.update(t,i);if(s.hasResult()){e.push(s);continue}}let n=this.view.state.field(zc).active.find((t=>t.source==r.active.source));if(n&&1==n.state)if(null==r.done){let t=new Lc(r.active.source,0);for(let e of r.updates)t=t.update(e,i);1!=t.state&&e.push(t)}else this.startQuery(n)}e.length&&this.view.dispatch({effects:jc.of(e)})}},{eventHandlers:{blur(t){let e=this.view.state.field(zc,!1);if(e&&e.tooltip&&this.view.state.facet(yc).closeOnBlur){let i=e.open&&sh(this.view,e.open.tooltip);i&&i.dom.contains(t.relatedTarget)||setTimeout((()=>this.view.dispatch({effects:bc.of(null)})),10)}},compositionstart(){this.composing=1},compositionend(){3==this.composing&&setTimeout((()=>this.view.dispatch({effects:wc.of(!1)})),20),this.composing=0}}}),qc="object"==typeof navigator&&/Win/.test(navigator.platform),Uc=_.highest(Ur.domEventHandlers({keydown(t,e){let i=e.state.field(zc,!1);if(!i||!i.open||i.open.disabled||i.open.selected<0||t.key.length>1||t.ctrlKey&&(!qc||!t.altKey)||t.metaKey)return!1;let s=i.open.options[i.open.selected],r=i.active.find((t=>t.source==s.source)),n=s.completion.commitCharacters||r.result.commitCharacters;return n&&n.indexOf(t.key)>-1&&Pc(e,s),!1}})),Jc=Ur.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class Gc{constructor(t,e,i,s){this.field=t,this.line=e,this.from=i,this.to=s}}class Kc{constructor(t,e,i){this.field=t,this.from=e,this.to=i}map(t){let e=t.mapPos(this.from,-1,x.TrackDel),i=t.mapPos(this.to,1,x.TrackDel);return null==e||null==i?null:new Kc(this.field,e,i)}}class _c{constructor(t,e){this.lines=t,this.fieldPositions=e}instantiate(t,e){let i=[],s=[e],r=t.doc.lineAt(e),n=/^\s*/.exec(r.text)[0];for(let r of this.lines){if(i.length){let i=n,h=/^\t*/.exec(r)[0].length;for(let e=0;e<h;e++)i+=t.facet(bo);s.push(e+i.length-h),r=i+r.slice(h)}i.push(r),e+=r.length+1}let h=this.fieldPositions.map((t=>new Kc(t.field,s[t.line]+t.from,s[t.line]+t.to)));return{text:i,ranges:h}}static parse(t){let e,i=[],s=[],r=[];for(let n of t.split(/\r\n?|\n/)){for(;e=/[#$]\{(?:(\d+)(?::([^}]*))?|([^}]*))\}/.exec(n);){let t=e[1]?+e[1]:null,h=e[2]||e[3]||"",l=-1;for(let e=0;e<i.length;e++)(null!=t?i[e].seq==t:h&&i[e].name==h)&&(l=e);if(l<0){let e=0;for(;e<i.length&&(null==t||null!=i[e].seq&&i[e].seq<t);)e++;i.splice(e,0,{seq:t,name:h}),l=e;for(let t of r)t.field>=l&&t.field++}r.push(new Gc(l,s.length,e.index,e.index+h.length)),n=n.slice(0,e.index)+h+n.slice(e.index+e[0].length)}for(let t;t=/\\([{}])/.exec(n);){n=n.slice(0,t.index)+t[1]+n.slice(t.index+t[0].length);for(let e of r)e.line==s.length&&e.from>t.index&&(e.from--,e.to--)}s.push(n)}return new _c(s,r)}}let Xc=ni.widget({widget:new class extends si{toDOM(){let t=document.createElement("span");return t.className="cm-snippetFieldPosition",t}ignoreEvent(){return!1}}}),Yc=ni.mark({class:"cm-snippetField"});class Qc{constructor(t,e){this.ranges=t,this.active=e,this.deco=ni.set(t.map((t=>(t.from==t.to?Xc:Yc).range(t.from,t.to))))}map(t){let e=[];for(let i of this.ranges){let s=i.map(t);if(!s)return null;e.push(s)}return new Qc(e,this.active)}selectionInsideField(t){return t.ranges.every((t=>this.ranges.some((e=>e.field==this.active&&e.from<=t.from&&e.to>=t.to))))}}const Zc=ct.define({map:(t,e)=>t&&t.map(e)}),td=ct.define(),ed=F.define({create:()=>null,update(t,e){for(let i of e.effects){if(i.is(Zc))return i.value;if(i.is(td)&&t)return new Qc(t.ranges,i.value)}return t&&e.docChanged&&(t=t.map(e.changes)),t&&e.selection&&!t.selectionInsideField(e.selection)&&(t=null),t},provide:t=>Ur.decorations.from(t,(t=>t?t.deco:ni.none))});function id(t,e){return B.create(t.filter((t=>t.field==e)).map((t=>B.range(t.from,t.to))))}function sd(e){let i=_c.parse(e);return(e,s,r,n)=>{let{text:h,ranges:l}=i.instantiate(e.state,r),o={changes:{from:r,to:n,insert:t.of(h)},scrollIntoView:!0,annotations:s?[pc.of(s),dt.userEvent.of("input.complete")]:void 0};if(l.length&&(o.selection=id(l,0)),l.some((t=>t.field>0))){let t=new Qc(l,0),i=o.effects=[Zc.of(t)];void 0===e.state.field(ed,!1)&&i.push(ct.appendConfig.of([ed,ld,ud,Jc]))}e.dispatch(e.state.update(o))}}function rd(t){return({state:e,dispatch:i})=>{let s=e.field(ed,!1);if(!s||t<0&&0==s.active)return!1;let r=s.active+t,n=t>0&&!s.ranges.some((e=>e.field==r+t));return i(e.update({selection:id(s.ranges,r),effects:Zc.of(n?null:new Qc(s.ranges,r)),scrollIntoView:!0})),!0}}const nd=[{key:"Tab",run:rd(1),shift:rd(-1)},{key:"Escape",run:({state:t,dispatch:e})=>!!t.field(ed,!1)&&(e(t.update({effects:Zc.of(null)})),!0)}],hd=j.define({combine:t=>t.length?t[0]:nd}),ld=_.highest(Zr.compute([hd],(t=>t.facet(hd))));function od(t,e){return Object.assign(Object.assign({},e),{apply:sd(t)})}const ud=Ur.domEventHandlers({mousedown(t,e){let i,s=e.state.field(ed,!1);if(!s||null==(i=e.posAtCoords({x:t.clientX,y:t.clientY})))return!1;let r=s.ranges.find((t=>t.from<=i&&t.to>=i));return!(!r||r.field==s.active)&&(e.dispatch({selection:id(s.ranges,r.field),effects:Zc.of(s.ranges.some((t=>t.field>r.field))?new Qc(s.ranges,r.field):null),scrollIntoView:!0}),!0)}}),fd={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},ad=ct.define({map(t,e){let i=e.mapPos(t,-1,x.TrackAfter);return null==i?void 0:i}}),cd=new class extends Ct{};cd.startSide=1,cd.endSide=-1;const dd=F.define({create:()=>It.empty,update(t,e){if(t=t.map(e.changes),e.selection){let i=e.state.doc.lineAt(e.selection.main.head);t=t.update({filter:t=>t>=i.from&&t<=i.to})}for(let i of e.effects)i.is(ad)&&(t=t.update({add:[cd.range(i.value,i.value+1)]}));return t}});const pd="()[]{}<>";function md(t){for(let e=0;e<pd.length;e+=2)if(pd.charCodeAt(e)==t)return pd.charAt(e+1);return k(t<128?t:t+1)}function gd(t,e){return t.languageDataAt("closeBrackets",e)[0]||fd}const wd="object"==typeof navigator&&/Android\b/.test(navigator.userAgent),bd=Ur.inputHandler.of(((t,e,i,s)=>{if((wd?t.composing:t.compositionStarted)||t.state.readOnly)return!1;let r=t.state.selection.main;if(s.length>2||2==s.length&&1==y(v(s,0))||e!=r.from||i!=r.to)return!1;let n=function(t,e){let i=gd(t,t.selection.main.head),s=i.brackets||fd.brackets;for(let r of s){let n=md(v(r,0));if(e==r)return n==r?Sd(t,r,s.indexOf(r+r+r)>-1,i):Md(t,r,n,i.before||fd.before);if(e==n&&kd(t,t.selection.main.from))return xd(t,r,n)}return null}(t.state,s);return!!n&&(t.dispatch(n),!0)})),vd=[{key:"Backspace",run:({state:t,dispatch:e})=>{if(t.readOnly)return!1;let i=gd(t,t.selection.main.head).brackets||fd.brackets,s=null,r=t.changeByRange((e=>{if(e.empty){let s=function(t,e){let i=t.sliceString(e-2,e);return y(v(i,0))==i.length?i:i.slice(1)}(t.doc,e.head);for(let r of i)if(r==s&&yd(t.doc,e.head)==md(v(r,0)))return{changes:{from:e.head-r.length,to:e.head+r.length},range:B.cursor(e.head-r.length)}}return{range:s=e}}));return s||e(t.update(r,{scrollIntoView:!0,userEvent:"delete.backward"})),!s}}];function kd(t,e){let i=!1;return t.field(dd).between(0,t.doc.length,(t=>{t==e&&(i=!0)})),i}function yd(t,e){let i=t.sliceString(e,e+2);return i.slice(0,y(v(i,0)))}function Md(t,e,i,s){let r=null,n=t.changeByRange((n=>{if(!n.empty)return{changes:[{insert:e,from:n.from},{insert:i,from:n.to}],effects:ad.of(n.to+e.length),range:B.range(n.anchor+e.length,n.head+e.length)};let h=yd(t.doc,n.head);return!h||/\s/.test(h)||s.indexOf(h)>-1?{changes:{insert:e+i,from:n.head},effects:ad.of(n.head+e.length),range:B.cursor(n.head+e.length)}:{range:r=n}}));return r?null:t.update(n,{scrollIntoView:!0,userEvent:"input.type"})}function xd(t,e,i){let s=null,r=t.changeByRange((e=>e.empty&&yd(t.doc,e.head)==i?{changes:{from:e.head,to:e.head+i.length,insert:i},range:B.cursor(e.head+i.length)}:s={range:e}));return s?null:t.update(r,{scrollIntoView:!0,userEvent:"input.type"})}function Sd(t,e,i,s){let r=s.stringPrefixes||fd.stringPrefixes,n=null,h=t.changeByRange((s=>{if(!s.empty)return{changes:[{insert:e,from:s.from},{insert:e,from:s.to}],effects:ad.of(s.to+e.length),range:B.range(s.anchor+e.length,s.head+e.length)};let h,l=s.head,o=yd(t.doc,l);if(o==e){if(Ad(t,l))return{changes:{insert:e+e,from:l},effects:ad.of(l+e.length),range:B.cursor(l+e.length)};if(kd(t,l)){let s=i&&t.sliceDoc(l,l+3*e.length)==e+e+e?e+e+e:e;return{changes:{from:l,to:l+s.length,insert:s},range:B.cursor(l+s.length)}}}else{if(i&&t.sliceDoc(l-2*e.length,l)==e+e&&(h=Cd(t,l-2*e.length,r))>-1&&Ad(t,h))return{changes:{insert:e+e+e+e,from:l},effects:ad.of(l+e.length),range:B.cursor(l+e.length)};if(t.charCategorizer(l)(o)!=kt.Word&&Cd(t,l,r)>-1&&!function(t,e,i,s){let r=no(t).resolveInner(e,-1),n=s.reduce(((t,e)=>Math.max(t,e.length)),0);for(let h=0;h<5;h++){let h=t.sliceDoc(r.from,Math.min(r.to,r.from+i.length+n)),l=h.indexOf(i);if(!l||l>-1&&s.indexOf(h.slice(0,l))>-1){let e=r.firstChild;for(;e&&e.from==r.from&&e.to-e.from>i.length+l;){if(t.sliceDoc(e.to-i.length,e.to)==i)return!1;e=e.firstChild}return!0}let o=r.to==e&&r.parent;if(!o)break;r=o}return!1}(t,l,e,r))return{changes:{insert:e+e,from:l},effects:ad.of(l+e.length),range:B.cursor(l+e.length)}}return{range:n=s}}));return n?null:t.update(h,{scrollIntoView:!0,userEvent:"input.type"})}function Ad(t,e){let i=no(t).resolveInner(e+1);return i.parent&&i.from==e}function Cd(t,e,i){let s=t.charCategorizer(e);if(s(t.sliceDoc(e-1,e))!=kt.Word)return e;for(let r of i){let i=e-r.length;if(t.sliceDoc(i,e)==r&&s(t.sliceDoc(i-1,i))!=kt.Word)return i}return-1}function Od(t={}){return[Uc,zc,yc.of(t),Fc,Ed,Jc]}const Dd=[{key:"Ctrl-Space",run:t=>!!t.state.field(zc,!1)&&(t.dispatch({effects:wc.of(!0)}),!0)},{key:"Escape",run:t=>{let e=t.state.field(zc,!1);return!(!e||!e.active.some((t=>0!=t.state)))&&(t.dispatch({effects:bc.of(null)}),!0)}},{key:"ArrowDown",run:Wc(!0)},{key:"ArrowUp",run:Wc(!1)},{key:"PageDown",run:Wc(!0,"page")},{key:"PageUp",run:Wc(!1,"page")},{key:"Enter",run:t=>{let e=t.state.field(zc,!1);return!(t.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<t.state.facet(yc).interactionDelay)&&Pc(t,e.open.options[e.open.selected])}}],Ed=_.highest(Zr.computeN([yc],(t=>t.facet(yc).defaultKeymap?[Dd]:[])));class Id{constructor(t,e,i){this.from=t,this.to=e,this.diagnostic=i}}class Rd{constructor(t,e,i){this.diagnostics=t,this.panel=e,this.selected=i}static init(t,e,i){let s=t,r=i.facet(Vd).markerFilter;r&&(s=r(s,i));let n=ni.set(s.map((t=>t.from==t.to||t.from==t.to-1&&i.doc.lineAt(t.from).to==t.from?ni.widget({widget:new Ud(t),diagnostic:t}).range(t.from):ni.mark({attributes:{class:"cm-lintRange cm-lintRange-"+t.severity+(t.markClass?" "+t.markClass:"")},diagnostic:t,inclusive:!0}).range(t.from,t.to))),!0);return new Rd(n,e,Td(n))}}function Td(t,e=null,i=0){let s=null;return t.between(i,1e9,((t,i,{spec:r})=>{if(!e||r.diagnostic==e)return s=new Id(t,i,r.diagnostic),!1})),s}const Bd=ct.define(),Ld=ct.define(),Nd=ct.define(),jd=F.define({create:()=>new Rd(ni.none,null,null),update(t,e){if(e.docChanged){let i=t.diagnostics.map(e.changes),s=null;if(t.selected){let r=e.changes.mapPos(t.selected.from,1);s=Td(i,t.selected.diagnostic,r)||Td(i,null,r)}t=new Rd(i,t.panel,s)}for(let i of e.effects)i.is(Bd)?t=Rd.init(i.value,t.panel,e.state):i.is(Ld)?t=new Rd(t.diagnostics,i.value?Gd.open:null,t.selected):i.is(Nd)&&(t=new Rd(t.diagnostics,t.panel,i.value));return t},provide:t=>[fh.from(t,(t=>t.panel)),Ur.decorations.from(t,(t=>t.diagnostics))]}),$d=ni.mark({class:"cm-lintRange cm-lintRange-active",inclusive:!0});function zd(t,e,i){let{diagnostics:s}=t.state.field(jd),r=[],n=2e8,h=0;s.between(e-(i<0?1:0),e+(i>0?1:0),((t,s,{spec:l})=>{e>=t&&e<=s&&(t==s||(e>t||i>0)&&(e<s||i<0))&&(r.push(l.diagnostic),n=Math.min(t,n),h=Math.max(s,h))}));let l=t.state.facet(Vd).tooltipFilter;return l&&(r=l(r,t.state)),r.length?{pos:n,end:h,above:t.state.doc.lineAt(n).to<h,create:()=>({dom:Pd(t,r)})}:null}function Pd(t,e){return sa("ul",{class:"cm-tooltip-lint"},e.map((e=>qd(t,e,!1))))}const Hd=t=>{let e=t.state.field(jd,!1);return!(!e||!e.panel)&&(t.dispatch({effects:Ld.of(!1)}),!0)},Wd=[{key:"Mod-Shift-m",run:t=>{let e=t.state.field(jd,!1);var i,s;e&&e.panel||t.dispatch({effects:(i=t.state,s=[Ld.of(!0)],i.field(jd,!1)?s:s.concat(ct.appendConfig.of(Xd)))});let r=hh(t,Gd.open);return r&&r.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:t=>{let e=t.state.field(jd,!1);if(!e)return!1;let i=t.state.selection.main,s=e.diagnostics.iter(i.to+1);return!(!s.value&&(s=e.diagnostics.iter(0),!s.value||s.from==i.from&&s.to==i.to))&&(t.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0}),!0)}}],Vd=j.define({combine:t=>Object.assign({sources:t.map((t=>t.source)).filter((t=>null!=t))},At(t.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 Fd(t){let e=[];if(t)t:for(let{name:i}of t){for(let t=0;t<i.length;t++){let s=i[t];if(/[a-zA-Z]/.test(s)&&!e.some((t=>t.toLowerCase()==s.toLowerCase()))){e.push(s);continue t}}e.push("")}return e}function qd(t,e,i){var s;let r=i?Fd(e.actions):[];return sa("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},sa("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),null===(s=e.actions)||void 0===s?void 0:s.map(((i,s)=>{let n=!1,h=s=>{if(s.preventDefault(),n)return;n=!0;let r=Td(t.state.field(jd).diagnostics,e);r&&i.apply(t,r.from,r.to)},{name:l}=i,o=r[s]?l.indexOf(r[s]):-1,u=o<0?l:[l.slice(0,o),sa("u",l.slice(o,o+1)),l.slice(o+1)];return sa("button",{type:"button",class:"cm-diagnosticAction",onclick:h,onmousedown:h,"aria-label":` Action: ${l}${o<0?"":` (access key "${r[s]})"`}.`},u)})),e.source&&sa("div",{class:"cm-diagnosticSource"},e.source))}class Ud extends si{constructor(t){super(),this.diagnostic=t}eq(t){return t.diagnostic==this.diagnostic}toDOM(){return sa("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class Jd{constructor(t,e){this.diagnostic=e,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=qd(t,e,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Gd{constructor(t){this.view=t,this.items=[];this.list=sa("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:e=>{if(27==e.keyCode)Hd(this.view),this.view.focus();else if(38==e.keyCode||33==e.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==e.keyCode||34==e.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==e.keyCode)this.moveSelection(0);else if(35==e.keyCode)this.moveSelection(this.items.length-1);else if(13==e.keyCode)this.view.focus();else{if(!(e.keyCode>=65&&e.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],s=Fd(i.actions);for(let r=0;r<s.length;r++)if(s[r].toUpperCase().charCodeAt(0)==e.keyCode){let e=Td(this.view.state.field(jd).diagnostics,i);e&&i.actions[r].apply(t,e.from,e.to)}}}e.preventDefault()},onclick:t=>{for(let e=0;e<this.items.length;e++)this.items[e].dom.contains(t.target)&&this.moveSelection(e)}}),this.dom=sa("div",{class:"cm-panel-lint"},this.list,sa("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>Hd(this.view)},"×")),this.update()}get selectedIndex(){let t=this.view.state.field(jd).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(jd),i=0,s=!1,r=null;for(t.between(0,this.view.state.doc.length,((t,n,{spec:h})=>{let l,o=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==h.diagnostic){o=t;break}o<0?(l=new Jd(this.view,h.diagnostic),this.items.splice(i,0,l),s=!0):(l=this.items[o],o>i&&(this.items.splice(i,o-i),s=!0)),e&&l.diagnostic==e.diagnostic?l.dom.hasAttribute("aria-selected")||(l.dom.setAttribute("aria-selected","true"),r=l):l.dom.hasAttribute("aria-selected")&&l.dom.removeAttribute("aria-selected"),i++}));i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();0==this.items.length&&(this.items.push(new Jd(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!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:t,panel:e})=>{let i=e.height/this.list.offsetHeight;t.top<e.top?this.list.scrollTop-=(e.top-t.top)/i:t.bottom>e.bottom&&(this.list.scrollTop+=(t.bottom-e.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let t=this.list.firstChild;function e(){let e=t;t=e.nextSibling,e.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=Td(this.view.state.field(jd).diagnostics,this.items[t].diagnostic);e&&this.view.dispatch({selection:{anchor:e.from,head:e.to},scrollIntoView:!0,effects:Nd.of(e)})}static open(t){return new Gd(t)}}function Kd(t){return function(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const _d=Ur.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:Kd("#d11")},".cm-lintRange-warning":{backgroundImage:Kd("orange")},".cm-lintRange-info":{backgroundImage:Kd("#999")},".cm-lintRange-hint":{backgroundImage:Kd("#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}}}),Xd=[jd,Ur.decorations.compute([jd],(t=>{let{selected:e,panel:i}=t.field(jd);return e&&i&&e.from!=e.to?ni.set([$d.range(e.from,e.to)]):ni.none})),ih(zd,{hideOn:function(t,e){let i=e.pos,s=e.end||i,r=t.state.facet(Vd).hideOn(t,i,s);if(null!=r)return r;let n=t.startState.doc.lineAt(e.pos);return!(!t.effects.some((t=>t.is(Bd)))&&!t.changes.touchesRange(n.from,Math.max(n.to,s)))}}),_d],Yd=t=>void 0===t||t,Qd=(t={})=>{let e=[];Yd(t.defaultKeymap)&&e.push(...ia),Yd(t.closeBracketsKeymap)&&e.push(...vd),Yd(t.searchKeymap)&&e.push(...Za),Yd(t.historyKeymap)&&e.push(...of),Yd(t.foldKeymap)&&e.push(...Go),Yd(t.lintKeymap)&&e.push(...Wd);const i=[];return Yd(t.highlightActiveLineGutter)&&i.push(Th),Yd(t.highlightSpecialChars)&&i.push(function(t={}){return[En.of(t),In||(In=_i.fromClass(class{constructor(t){this.view=t,this.decorations=ni.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(t.state.facet(En)),this.decorations=this.decorator.createDeco(t)}makeDecorator(t){return new Sn({regexp:t.specialChars,decoration:(e,i,s)=>{let{doc:r}=i.state,n=v(e[0],0);if(9==n){let t=r.lineAt(s),e=i.state.tabSize,n=Vt(t.text,e,s-t.from);return ni.replace({widget:new Tn((e-n%e)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[n]||(this.decorationCache[n]=ni.replace({widget:new Rn(t,n)}))},boundary:t.replaceTabs?void 0:/[^]/})}update(t){let e=t.state.facet(En);t.startState.facet(En)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(t.view)):this.decorations=this.decorator.updateDeco(t,this.decorations)}},{decorations:t=>t.decorations}))]}()),Yd(t.history)&&i.push(function(t={}){return[qu,Fu.of(t),Ur.domEventHandlers({beforeinput(t,e){let i="historyUndo"==t.inputType?Ju:"historyRedo"==t.inputType?Gu:null;return!!i&&(t.preventDefault(),i(e))}})]}()),Yd(t.foldGutter)&&i.push(function(t={}){let e=Object.assign(Object.assign({},tu),t),i=new eu(e,!0),s=new eu(e,!1),r=_i.fromClass(class{constructor(t){this.from=t.viewport.from,this.markers=this.buildMarkers(t)}update(t){(t.docChanged||t.viewportChanged||t.startState.facet(mo)!=t.state.facet(mo)||t.startState.field(Vo,!1)!=t.state.field(Vo,!1)||no(t.startState)!=no(t.state)||e.foldingChanged(t))&&(this.markers=this.buildMarkers(t.view))}buildMarkers(t){let e=new Rt;for(let r of t.viewportLineBlocks){let n=Fo(t.state,r.from,r.to)?s:$o(t.state,r.from,r.to)?i:null;n&&e.add(r.from,r.from,n)}return e.finish()}}),{domEventHandlers:n}=e;return[r,mh({class:"cm-foldGutter",markers(t){var e;return(null===(e=t.plugin(r))||void 0===e?void 0:e.markers)||It.empty},initialSpacer:()=>new eu(e,!1),domEventHandlers:Object.assign(Object.assign({},n),{click:(t,e,i)=>{if(n.click&&n.click(t,e,i))return!0;let s=Fo(t.state,e.from,e.to);if(s)return t.dispatch({effects:Ho.of(s)}),!0;let r=$o(t.state,e.from,e.to);return!!r&&(t.dispatch({effects:Po.of(r)}),!0)}})}),Xo()]}()),Yd(t.drawSelection)&&i.push(function(t={}){return[dn.of(t),mn,wn,vn,Wi.of(!0)]}()),Yd(t.dropCursor)&&i.push([yn,Mn]),Yd(t.allowMultipleSelections)&&i.push(St.allowMultipleSelections.of(!0)),Yd(t.indentOnInput)&&i.push(St.transactionFilter.of((t=>{if(!t.docChanged||!t.isUserEvent("input.type")&&!t.isUserEvent("input.complete"))return t;let e=t.startState.languageDataAt("indentOnInput",t.startState.selection.main.head);if(!e.length)return t;let i=t.newDoc,{head:s}=t.newSelection.main,r=i.lineAt(s);if(s>r.from+200)return t;let n=i.sliceString(r.from,s);if(!e.some((t=>t.test(n))))return t;let{state:h}=t,l=-1,o=[];for(let{head:t}of h.selection.ranges){let e=h.doc.lineAt(t);if(e.from==l)continue;l=e.from;let i=yo(h,e.from);if(null==i)continue;let s=/^\s*/.exec(e.text)[0],r=ko(h,i);s!=r&&o.push({from:e.from,to:e.from+s.length,insert:r})}return o.length?[t,{changes:o,sequential:!0}]:t}))),Yd(t.bracketMatching)&&i.push(function(t={}){return[pu.of(t),vu]}()),Yd(t.closeBrackets)&&i.push([bd,dd]),Yd(t.autocompletion)&&i.push(Od()),Yd(t.rectangularSelection)&&i.push(function(t){let e=(null==t?void 0:t.eventFilter)||(t=>t.altKey&&0==t.button);return Ur.mouseSelectionStyle.of(((t,i)=>e(i)?Pn(t,i):null))}()),Yd(t.crosshairCursor)&&i.push(function(t={}){let[e,i]=Hn[t.key||"Alt"],s=_i.fromClass(class{constructor(t){this.view=t,this.isDown=!1}set(t){this.isDown!=t&&(this.isDown=t,this.view.update([]))}},{eventObservers:{keydown(t){this.set(t.keyCode==e||i(t))},keyup(t){t.keyCode!=e&&i(t)||this.set(!1)},mousemove(t){this.set(i(t))}}});return[s,Ur.contentAttributes.of((t=>{var e;return(null===(e=t.plugin(s))||void 0===e?void 0:e.isDown)?Wn:null}))]}()),Yd(t.highlightActiveLine)&&i.push(Ln),Yd(t.highlightSelectionMatches)&&i.push(function(t){let e=[Sa,xa];return t&&e.push(va.of(t)),e}()),t.tabSize&&"number"==typeof t.tabSize&&i.push(bo.of(" ".repeat(t.tabSize))),i.concat([Zr.of(e.flat())]).filter(Boolean)};export{t as A,dt as B,_ as C,Bh as D,Ur as E,j as F,Zr as G,ut as H,Fh as I,Y as J,Qd as K,ro as L,x as M,Hh as N,Od as O,fl as P,Eh as Q,Ct as R,F as S,qh as T,jn as U,_i as V,si as W,lu as X,fu as Y,Ph as a,jh as b,To as c,Eo as d,Lo as e,Ro as f,No as g,go as h,xo as i,fc as j,uc as k,no as l,B as m,od as n,eo as o,to as p,ol as q,cl as r,Il as s,Yl as t,ni as u,pi as v,St as w,ct as x,Ui as y,ul as z};
|