trustycsv 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,538 @@
1
+ import{n as e}from"./zip--IbYBxOO.js";import t from"node:fs";import n from"node:fs/promises";import r from"node:path";import{parseArgs as i,promisify as a}from"node:util";import o from"node:crypto";import{execFile as s}from"node:child_process";var c=class extends Error{},l=[],u=[];(()=>{let e=`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,1n,9,16,o,,x,1i,3,,i,,7,a,2,t,3,1k,,,7,2,2,2,3,9,,a,2,q,,2,3,1k,,,5,4,2,2,3,3,,u,2,3,,b,3,1k,,,8,,3,,3,k,2,m,6,,3,1k,,,7,2,2,2,3,7,3,a,2,u,,1n,5,3,3,,4,9,,14,5,1j,,,7,,3,,4,7,2,b,2,t,3,1k,,,7,,3,,4,7,2,b,2,f,,c,4,1j,2,,7,,3,,4,9,,a,2,t,3,1y,,4,6,,,,8,i,2,1p,,,8,c,8,2q,,,a,b,7,21,2,r,,,,,,4,2,1d,k,,2,5,b,,10,9,,2u,b,,6,n,4,4,3,g,4,d,,,3,6,,f,,jj,3,qa,4,s,3,t,2,u,2,1s,w,9,,19,3,,,39,2,y,,3a,c,4,c,63,5,1l,a,,,,,2,o,2,,1c,1a,2,c,k,5,1b,h,12,9,c,3,u,d,1k,e,1c,k,48,3,,l,4,,6,,2,3,5i,1s,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,n,5,4,,2b,2,1e,i,q,i,d,,12,8,p,d,18,4,1b,e,10,,1v,e,c,,8,2,1a,,1f,,,3,2,2,5,2,,,15,5,5,2,6k,8,,2,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,1t,5,8t,2,25,6,1y,b,1d,4,3e,3,1h,f,15,,2,2,a,4,19,b,7,,1p,3,10,e,g,2,18,,c,3,1c,e,8,4,,2,2k,c,6,,2,,4d,c,l,4,1j,2,,7,2,2,2,3,9,,a,2,2,7,3,5,1v,9,,,2,,,4,,5,,,e,2,2a,i,n,,29,k,6j,7,2,9,r,2,2a,h,2y,d,2t,3,2,a,74,f,6t,6,,2,2,4,,,,2,3x,7,2,7,3,,s,a,14,7,,4,8,,9,b,1a,g,5i,8,5j,8,,8,2a,m,,e,3e,6,3,,,2,,7,,,1u,5,,2,,5,9n,4,9,2,,,1c,7,3,5,n,,44l,,6,f,8ug,i,1xc,5,1n,7,t4,,,1j,7,4,29,,b,2,f57,2,3mp,1a,2,n,f2,5,3,6,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,2s,,4g,7,af,,1p,4,e4,4,72,2,6r,,2,,7,2,5,,d6,7,31,7,240,5`.split(`,`).map(e=>e?parseInt(e,36):1);for(let t=0,n=0;t<e.length;t++)(t%2?u:l).push(n+=e[t])})();function d(e){if(e<768)return!1;for(let t=0,n=l.length;;){let r=t+n>>1;if(e<l[r])n=r;else if(e>=u[r])t=r+1;else return!0;if(t==n)return!1}}function f(e){return e>=127462&&e<=127487}var p=8205;function m(e,t,n=!0,r=!0){return(n?h:g)(e,t,r)}function h(e,t,n){if(t==e.length)return t;t&&v(e.charCodeAt(t))&&y(e.charCodeAt(t-1))&&t--;let r=_(e,t);for(t+=b(r);t<e.length;){let i=_(e,t);if(r==p||i==p||n&&d(i))t+=b(i),r=i;else if(f(i)){let n=0,r=t-2;for(;r>=0&&f(_(e,r));)n++,r-=2;if(n%2==0)break;t+=2}else break}return t}function g(e,t,n){for(;t>1;){let r=h(e,t-2,n);if(r<t)return r;t--}return 0}function _(e,t){let n=e.charCodeAt(t);if(!y(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return v(r)?(n-55296<<10)+(r-56320)+65536:n}function v(e){return e>=56320&&e<57344}function y(e){return e>=55296&&e<56320}function b(e){return e<65536?1:2}var x=class e{lineAt(e){if(e<0||e>this.length)throw RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=D(this,e,t);let r=[];return this.decompose(0,e,r,2),n.length&&n.decompose(0,n.length,r,3),this.decompose(t,this.length,r,1),C.from(r,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=D(this,e,t);let n=[];return this.decompose(e,t,n,0),C.from(n,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),n=this.length-this.scanIdentical(e,-1),r=new te(this),i=new te(e);for(let e=t,a=t;;){if(r.next(e),i.next(e),e=0,r.lineBreak!=i.lineBreak||r.done!=i.done||r.value!=i.value)return!1;if(a+=r.value.length,r.done||a>=n)return!0}}iter(e=1){return new te(this,e)}iterRange(e,t=this.length){return new E(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t??=this.lines+1;let r=this.line(e).from;n=this.iterRange(r,Math.max(r,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new ne(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(t){if(t.length==0)throw RangeError(`A document must have at least one line`);return t.length==1&&!t[0]?e.empty:t.length<=32?new S(t):C.from(S.split(t,[]))}},S=class e extends x{constructor(e,t=w(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.text[i],o=r+a.length;if((t?n:o)>=e)return new re(r,o,n,a);r=o+1,n++}}decompose(t,n,r,i){let a=t<=0&&n>=this.length?this:new e(T(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(i&1){let t=r.pop(),n=ee(a.text,t.text.slice(),0,a.length);if(n.length<=32)r.push(new e(n,t.length+a.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(a)}replace(t,n,r){if(!(r instanceof e))return super.replace(t,n,r);[t,n]=D(this,t,n);let i=ee(this.text,ee(r.text,T(this.text,0,t)),n),a=this.length+r.length-(n-t);return i.length<=32?new e(i,a):C.from(e.split(i,[]),a)}sliceString(e,t=this.length,n=`
2
+ `){[e,t]=D(this,e,t);let r=``;for(let i=0,a=0;i<=t&&a<this.text.length;a++){let o=this.text[a],s=i+o.length;i>e&&a&&(r+=n),e<s&&t>i&&(r+=o.slice(Math.max(0,e-i),t-i)),i=s+1}return r}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(t,n){let r=[],i=-1;for(let a of t)r.push(a),i+=a.length+1,r.length==32&&(n.push(new e(r,i)),r=[],i=-1);return i>-1&&n.push(new e(r,i)),n}},C=class e extends x{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let t of e)this.lines+=t.lines}lineInner(e,t,n,r){for(let i=0;;i++){let a=this.children[i],o=r+a.length,s=n+a.lines-1;if((t?s:o)>=e)return a.lineInner(e,t,n,r);r=o+1,n=s+1}}decompose(e,t,n,r){for(let i=0,a=0;a<=t&&i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(e<=s&&t>=a){let i=r&(a<=e|(s>=t?2:0));a>=e&&s<=t&&!i?n.push(o):o.decompose(e-a,t-a,n,i)}a=s+1}}replace(t,n,r){if([t,n]=D(this,t,n),r.lines<this.lines)for(let i=0,a=0;i<this.children.length;i++){let o=this.children[i],s=a+o.length;if(t>=a&&n<=s){let c=o.replace(t-a,n-a,r),l=this.lines-o.lines+c.lines;if(c.lines<l>>4&&c.lines>l>>6){let a=this.children.slice();return a[i]=c,new e(a,this.length-(n-t)+r.length)}return super.replace(a,s,c)}a=s+1}return super.replace(t,n,r)}sliceString(e,t=this.length,n=`
3
+ `){[e,t]=D(this,e,t);let r=``;for(let i=0,a=0;i<this.children.length&&a<=t;i++){let o=this.children[i],s=a+o.length;a>e&&i&&(r+=n),e<s&&t>a&&(r+=o.sliceString(e-a,t-a,n)),a=s+1}return r}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(t,n){if(!(t instanceof e))return 0;let r=0,[i,a,o,s]=n>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;i+=n,a+=n){if(i==o||a==s)return r;let e=this.children[i],c=t.children[a];if(e!=c)return r+e.scanIdentical(c,n);r+=e.length+1}}static from(t,n=t.reduce((e,t)=>e+t.length+1,-1)){let r=0;for(let e of t)r+=e.lines;if(r<32){let e=[];for(let n of t)n.flatten(e);return new S(e,n)}let i=Math.max(32,r>>5),a=i<<1,o=i>>1,s=[],c=0,l=-1,u=[];function d(t){let n;if(t.lines>a&&t instanceof e)for(let e of t.children)d(e);else t.lines>o&&(c>o||!c)?(f(),s.push(t)):t instanceof S&&c&&(n=u[u.length-1])instanceof S&&t.lines+n.lines<=32?(c+=t.lines,l+=t.length+1,u[u.length-1]=new S(n.text.concat(t.text),n.length+1+t.length)):(c+t.lines>i&&f(),c+=t.lines,l+=t.length+1,u.push(t))}function f(){c!=0&&(s.push(u.length==1?u[0]:e.from(u,l)),l=-1,c=u.length=0)}for(let e of t)d(e);return f(),s.length==1?s[0]:new e(s,n)}};x.empty=new S([``],0);function w(e){let t=-1;for(let n of e)t+=n.length+1;return t}function ee(e,t,n=0,r=1e9){for(let i=0,a=0,o=!0;a<e.length&&i<=r;a++){let s=e[a],c=i+s.length;c>=n&&(c>r&&(s=s.slice(0,r-i)),i<n&&(s=s.slice(n-i)),o?(t[t.length-1]+=s,o=!1):t.push(s)),i=c+1}return t}function T(e,t,n){return ee(e,[``],t,n)}var te=class{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value=``,this.nodes=[e],this.offsets=[t>0?1:(e instanceof S?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,r=this.nodes[n],i=this.offsets[n],a=i>>1,o=r instanceof S?r.text.length:r.children.length;if(a==(t>0?o:0)){if(n==0)return this.done=!0,this.value=``,this;t>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((i&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
4
+ `,this;e--}else if(r instanceof S){let i=r.text[a+(t<0?-1:0)];if(this.offsets[n]+=t,i.length>Math.max(0,e))return this.value=e==0?i:t>0?i.slice(e):i.slice(0,i.length-e),this;e-=i.length}else{let i=r.children[a+(t<0?-1:0)];e>i.length?(e-=i.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(i),this.offsets.push(t>0?1:(i instanceof S?i.text.length:i.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}},E=class{constructor(e,t,n){this.value=``,this.done=!1,this.cursor=new te(e,t>n?-1:1),this.pos=t>n?e.length:0,this.from=Math.min(t,n),this.to=Math.max(t,n)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value=``,this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let n=t<0?this.pos-this.from:this.to-this.pos;e>n&&(e=n),n-=e;let{value:r}=this.cursor.next(e);return this.pos+=(r.length+e)*t,this.value=r.length<=n?r:t<0?r.slice(r.length-n):r.slice(0,n),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=``}},ne=class{constructor(e){this.inner=e,this.afterBreak=!0,this.value=``,this.done=!1}next(e=0){let{done:t,lineBreak:n,value:r}=this.inner.next(e);return t&&this.afterBreak?(this.value=``,this.afterBreak=!1):t?(this.done=!0,this.value=``):n?this.afterBreak?this.value=``:(this.afterBreak=!0,this.next()):(this.value=r,this.afterBreak=!1),this}get lineBreak(){return!1}};typeof Symbol<`u`&&(x.prototype[Symbol.iterator]=function(){return this.iter()},te.prototype[Symbol.iterator]=E.prototype[Symbol.iterator]=ne.prototype[Symbol.iterator]=function(){return this});var re=class{constructor(e,t,n,r){this.from=e,this.to=t,this.number=n,this.text=r}get length(){return this.to-this.from}};function D(e,t,n){return t=Math.max(0,Math.min(e.length,t)),[t,Math.max(t,Math.min(e.length,n))]}function ie(e,t,n=!0,r=!0){return m(e,t,n,r)}function ae(e){return e>=56320&&e<57344}function oe(e){return e>=55296&&e<56320}function se(e,t){let n=e.charCodeAt(t);if(!oe(n)||t+1==e.length)return n;let r=e.charCodeAt(t+1);return ae(r)?(n-55296<<10)+(r-56320)+65536:n}function ce(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}function le(e){return e<65536?1:2}var ue=/\r\n?|\n/,de=(function(e){return e[e.Simple=0]=`Simple`,e[e.TrackDel=1]=`TrackDel`,e[e.TrackBefore=2]=`TrackBefore`,e[e.TrackAfter=3]=`TrackAfter`,e})(de||={}),fe=class e{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t+1];e+=n<0?this.sections[t]:n}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,n=0,r=0;t<this.sections.length;){let i=this.sections[t++],a=this.sections[t++];a<0?(e(n,r,i),r+=i):r+=a,n+=i}}iterChangedRanges(e,t=!1){ge(this,e,t)}get invertedDesc(){let t=[];for(let e=0;e<this.sections.length;){let n=this.sections[e++],r=this.sections[e++];r<0?t.push(n,r):t.push(r,n)}return new e(t)}composeDesc(e){return this.empty?e:e.empty?this:ve(this,e)}mapDesc(e,t=!1){return e.empty?this:_e(this,e,t)}mapPos(e,t=-1,n=de.Simple){let r=0,i=0;for(let a=0;a<this.sections.length;){let o=this.sections[a++],s=this.sections[a++],c=r+o;if(s<0){if(c>e)return i+(e-r);i+=o}else{if(n!=de.Simple&&c>=e&&(n==de.TrackDel&&r<e&&c>e||n==de.TrackBefore&&r<e||n==de.TrackAfter&&c>e))return null;if(c>e||c==e&&t<0&&!o)return e==r||t<0?i:i+s;i+=s}r=c}if(e>r)throw RangeError(`Position ${e} is out of range for changeset of length ${r}`);return i}touchesRange(e,t=e){for(let n=0,r=0;n<this.sections.length&&r<=t;){let i=this.sections[n++],a=this.sections[n++],o=r+i;if(a>=0&&r<=t&&o>=e)return r<e&&o>t?`cover`:!0;r=o}return!1}toString(){let e=``;for(let t=0;t<this.sections.length;){let n=this.sections[t++],r=this.sections[t++];e+=(e?` `:``)+n+(r>=0?`:`+r:``)}return e}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some(e=>typeof e!=`number`))throw RangeError(`Invalid JSON representation of ChangeDesc`);return new e(t)}static create(t){return new e(t)}},pe=class e extends fe{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw RangeError(`Applying change set to a document with the wrong length`);return ge(this,(t,n,r,i,a)=>e=e.replace(r,r+(n-t),a),!1),e}mapDesc(e,t=!1){return _e(this,e,t,!0)}invert(t){let n=this.sections.slice(),r=[];for(let e=0,i=0;e<n.length;e+=2){let a=n[e],o=n[e+1];if(o>=0){n[e]=o,n[e+1]=a;let s=e>>1;for(;r.length<s;)r.push(x.empty);r.push(a?t.slice(i,i+a):x.empty)}i+=a}return new e(n,r)}compose(e){return this.empty?e:e.empty?this:ve(this,e,!0)}map(e,t=!1){return e.empty?this:_e(this,e,t,!0)}iterChanges(e,t=!1){ge(this,e,t)}get desc(){return fe.create(this.sections)}filter(t){let n=[],r=[],i=[],a=new ye(this);done:for(let e=0,o=0;;){let s=e==t.length?1e9:t[e++];for(;o<s||o==s&&a.len==0;){if(a.done)break done;let e=Math.min(a.len,s-o);me(i,e,-1);let t=a.ins==-1?-1:a.off==0?a.ins:0;me(n,e,t),t>0&&he(r,n,a.text),a.forward(e),o+=e}let c=t[e++];for(;o<c;){if(a.done)break done;let e=Math.min(a.len,c-o);me(n,e,-1),me(i,e,a.ins==-1?-1:a.off==0?a.ins:0),a.forward(e),o+=e}}return{changes:new e(n,r),filtered:fe.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],r=this.sections[t+1];r<0?e.push(n):r==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,n,r){let i=[],a=[],o=0,s=null;function c(t=!1){if(!t&&!i.length)return;o<n&&me(i,n-o,-1);let r=new e(i,a);s=s?s.compose(r.map(s)):r,i=[],a=[],o=0}function l(t){if(Array.isArray(t))for(let e of t)l(e);else if(t instanceof e){if(t.length!=n)throw RangeError(`Mismatched change set length (got ${t.length}, expected ${n})`);c(),s=s?s.compose(t.map(s)):t}else{let{from:e,to:s=e,insert:l}=t;if(e>s||e<0||s>n)throw RangeError(`Invalid change range ${e} to ${s} (in doc of length ${n})`);let u=l?typeof l==`string`?x.of(l.split(r||ue)):l:x.empty,d=u.length;if(e==s&&d==0)return;e<o&&c(),e>o&&me(i,e-o,-1),me(i,s-e,d),he(a,i,u),o=s}}return l(t),c(!s),s}static empty(t){return new e(t?[t,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw RangeError(`Invalid JSON representation of ChangeSet`);let n=[],r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i==`number`)n.push(i,-1);else if(!Array.isArray(i)||typeof i[0]!=`number`||i.some((e,t)=>t&&typeof e!=`string`))throw RangeError(`Invalid JSON representation of ChangeSet`);else if(i.length==1)n.push(i[0],0);else{for(;r.length<e;)r.push(x.empty);r[e]=x.of(i.slice(1)),n.push(i[0],r[e].length)}}return new e(n,r)}static createSet(t,n){return new e(t,n)}};function me(e,t,n,r=!1){if(t==0&&n<=0)return;let i=e.length-2;i>=0&&n<=0&&n==e[i+1]?e[i]+=t:i>=0&&t==0&&e[i]==0?e[i+1]+=n:r?(e[i]+=t,e[i+1]+=n):e.push(t,n)}function he(e,t,n){if(n.length==0)return;let r=t.length-2>>1;if(r<e.length)e[e.length-1]=e[e.length-1].append(n);else{for(;e.length<r;)e.push(x.empty);e.push(n)}}function ge(e,t,n){let r=e.inserted;for(let i=0,a=0,o=0;o<e.sections.length;){let s=e.sections[o++],c=e.sections[o++];if(c<0)i+=s,a+=s;else{let l=i,u=a,d=x.empty;for(;l+=s,u+=c,c&&r&&(d=d.append(r[o-2>>1])),!(n||o==e.sections.length||e.sections[o+1]<0);)s=e.sections[o++],c=e.sections[o++];t(i,l,a,u,d),i=l,a=u}}}function _e(e,t,n,r=!1){let i=[],a=r?[]:null,o=new ye(e),s=new ye(t);for(let e=-1;;)if(o.done&&s.len||s.done&&o.len)throw Error(`Mismatched change set lengths`);else if(o.ins==-1&&s.ins==-1){let e=Math.min(o.len,s.len);me(i,e,-1),o.forward(e),s.forward(e)}else if(s.ins>=0&&(o.ins<0||e==o.i||o.off==0&&(s.len<o.len||s.len==o.len&&!n))){let t=s.len;for(me(i,s.ins,-1);t;){let n=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=n&&(me(i,0,o.ins),a&&he(a,i,o.text),e=o.i),o.forward(n),t-=n}s.next()}else if(o.ins>=0){let t=0,n=o.len;for(;n;)if(s.ins==-1){let e=Math.min(n,s.len);t+=e,n-=e,s.forward(e)}else if(s.ins==0&&s.len<n)n-=s.len,s.next();else break;me(i,t,e<o.i?o.ins:0),a&&e<o.i&&he(a,i,o.text),e=o.i,o.forward(o.len-n)}else if(o.done&&s.done)return a?pe.createSet(i,a):fe.create(i);else throw Error(`Mismatched change set lengths`)}function ve(e,t,n=!1){let r=[],i=n?[]:null,a=new ye(e),o=new ye(t);for(let e=!1;;)if(a.done&&o.done)return i?pe.createSet(r,i):fe.create(r);else if(a.ins==0)me(r,a.len,0,e),a.next();else if(o.len==0&&!o.done)me(r,0,o.ins,e),i&&he(i,r,o.text),o.next();else if(a.done||o.done)throw Error(`Mismatched change set lengths`);else{let t=Math.min(a.len2,o.len),n=r.length;if(a.ins==-1){let n=o.ins==-1?-1:o.off?0:o.ins;me(r,t,n,e),i&&n&&he(i,r,o.text)}else o.ins==-1?(me(r,a.off?0:a.len,t,e),i&&he(i,r,a.textBit(t))):(me(r,a.off?0:a.len,o.off?0:o.ins,e),i&&!o.off&&he(i,r,o.text));e=(a.ins>t||o.ins>=0&&o.len>t)&&(e||r.length>n),a.forward2(t),o.forward(t)}}var ye=class{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?x.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?x.empty:t[n].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}},be=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.flags=n,this.goalColumn=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get undirectional(){return(this.flags&64)>0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}map(t,n=-1){let r,i;return this.empty?r=i=t.mapPos(this.from,n):(r=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new e(r,i,this.flags,this.goalColumn)}extend(e,t=e,n=0){if(e<=this.anchor&&t>=this.anchor)return O.range(e,t,void 0,void 0,n);let r=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return O.range(this.anchor,r,void 0,void 0,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!=`number`||typeof e.head!=`number`)throw RangeError(`Invalid JSON representation for SelectionRange`);return O.range(e.anchor,e.head)}static create(t,n,r,i){return new e(t,n,r,i)}},O=class e{constructor(e,t){this.ranges=e,this.mainIndex=t}map(t,n=-1){return t.empty?this:e.create(this.ranges.map(e=>e.map(t,n)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let n=0;n<this.ranges.length;n++)if(!this.ranges[n].eq(e.ranges[n],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new e([this.main],0)}addRange(t,n=!0){return e.create([t].concat(this.ranges),n?0:this.mainIndex+1)}replaceRange(t,n=this.mainIndex){let r=this.ranges.slice();return r[n]=t,e.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||typeof t.main!=`number`||t.main>=t.ranges.length)throw RangeError(`Invalid JSON representation for EditorSelection`);return new e(t.ranges.map(e=>be.fromJSON(e)),t.main)}static single(t,n=t){return new e([e.range(t,n)],0)}static create(t,n=0){if(t.length==0)throw RangeError(`A selection needs at least one range`);for(let r=0,i=0;i<t.length;i++){let a=t[i];if(a.empty?a.from<=r:a.from<r)return e.normalized(t.slice(),n);r=a.to}return new e(t,n)}static cursor(e,t=0,n,r){return be.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n)),r)}static range(e,t,n,r,i){let a=r==null?7:Math.min(6,r);return!i&&e!=t&&(i=t<e?1:-1),i&&(a|=i<0?8:16),t<e?be.create(t,e,a|32,n):be.create(e,t,a,n)}static undirectionalRange(e,t){return be.create(e,t,64,void 0)}static normalized(t,n=0){let r=t[n];t.sort((e,t)=>e.from-t.from),n=t.indexOf(r);for(let r=1;r<t.length;r++){let i=t[r],a=t[r-1];if(i.empty?i.from<=a.to:i.from<a.to){let o=a.from,s=Math.max(i.to,a.to);r<=n&&n--,t.splice(--r,2,i.anchor>i.head?e.range(s,o):e.range(o,s))}}return new e(t,n)}};function xe(e,t){for(let n of e.ranges)if(n.to>t)throw RangeError(`Selection points outside of document`)}var Se=0,k=class e{constructor(e,t,n,r,i){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=r,this.id=Se++,this.default=e([]),this.extensions=typeof i==`function`?i(this):i}get reader(){return this}static define(t={}){return new e(t.combine||(e=>e),t.compareInput||((e,t)=>e===t),t.compare||(t.combine?(e,t)=>e===t:Ce),!!t.static,t.enables)}of(e){return new we([],this,0,e)}compute(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new we(e,this,1,t)}computeN(e,t){if(this.isStatic)throw Error(`Can't compute a static facet`);return new we(e,this,2,t)}from(e,t){return t||=e=>e,this.compute([e],n=>t(n.field(e)))}};function Ce(e,t){return e==t||e.length==t.length&&e.every((e,n)=>e===t[n])}var we=class{constructor(e,t,n,r){this.dependencies=e,this.facet=t,this.type=n,this.value=r,this.id=Se++}dynamicSlot(e){let t=this.value,n=this.facet.compareInput,r=this.id,i=e[r]>>1,a=this.type==2,o=!1,s=!1,c=[];for(let t of this.dependencies)t==`doc`?o=!0:t==`selection`?s=!0:(e[t.id]??1)&1||c.push(e[t.id]);return{create(e){return e.values[i]=t(e),1},update(e,r){if(o&&r.docChanged||s&&(r.docChanged||r.selection)||Ee(e,c)){let r=t(e);if(a?!Te(r,e.values[i],n):!n(r,e.values[i]))return e.values[i]=r,1}return 0},reconfigure:(e,o)=>{let s,c=o.config.address[r];if(c!=null){let r=ze(o,c);if(this.dependencies.every(t=>t instanceof k?o.facet(t)===e.facet(t):t instanceof ke?o.field(t,!1)==e.field(t,!1):!0)||(a?Te(s=t(e),r,n):n(s=t(e),r)))return e.values[i]=r,0}else s=t(e);return e.values[i]=s,1}}}get extension(){return this}};function Te(e,t,n){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1;return!0}function Ee(e,t){let n=!1;for(let r of t)Re(e,r)&1&&(n=!0);return n}function De(e,t,n){let r=n.map(t=>e[t.id]),i=n.map(e=>e.type),a=r.filter(e=>!(e&1)),o=e[t.id]>>1;function s(e){let n=[];for(let t=0;t<r.length;t++){let a=ze(e,r[t]);if(i[t]==2)for(let e of a)n.push(e);else n.push(a)}return t.combine(n)}return{create(e){for(let t of r)Re(e,t);return e.values[o]=s(e),1},update(e,n){if(!Ee(e,a))return 0;let r=s(e);return t.compare(r,e.values[o])?0:(e.values[o]=r,1)},reconfigure(e,i){let a=Ee(e,r),c=i.config.facets[t.id],l=i.facet(t);if(c&&!a&&Ce(n,c))return e.values[o]=l,0;let u=s(e);return t.compare(u,l)?(e.values[o]=l,0):(e.values[o]=u,1)}}}var Oe=k.define({static:!0}),ke=class e{constructor(e,t,n,r,i){this.id=e,this.createF=t,this.updateF=n,this.compareF=r,this.spec=i,this.provides=void 0}static define(t){let n=new e(Se++,t.create,t.update,t.compare||((e,t)=>e===t),t);return t.provide&&(n.provides=t.provide(n)),n}create(e){return(e.facet(Oe).find(e=>e.field==this)?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,n)=>{let r=e.values[t],i=this.updateF(r,n);return this.compareF(r,i)?0:(e.values[t]=i,1)},reconfigure:(e,n)=>{let r=e.facet(Oe),i=n.facet(Oe),a;return(a=r.find(e=>e.field==this))&&a!=i.find(e=>e.field==this)?(e.values[t]=a.create(e),1):n.config.address[this.id]==null?(e.values[t]=this.create(e),1):(e.values[t]=n.field(this),0)}}}init(e){return[this,Oe.of({field:this,create:e})]}get extension(){return this}},Ae={lowest:4,low:3,default:2,high:1,highest:0};function je(e){return t=>new Ne(t,e)}var Me={highest:je(Ae.highest),high:je(Ae.high),default:je(Ae.default),low:je(Ae.low),lowest:je(Ae.lowest)},Ne=class{constructor(e,t){this.inner=e,this.prec=t}get extension(){return this}},Pe=class e{of(e){return new Fe(this,e)}reconfigure(t){return e.reconfigure.of({compartment:this,extension:t})}get(e){return e.config.compartments.get(this)}},Fe=class{constructor(e,t){this.compartment=e,this.inner=t}get extension(){return this}},Ie=class e{constructor(e,t,n,r,i,a){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=r,this.staticValues=i,this.facets=a,this.statusTemplate=[];this.statusTemplate.length<n.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(t,n,r){let i=[],a=Object.create(null),o=new Map;for(let e of Le(t,n,o))e instanceof ke?i.push(e):(a[e.facet.id]||(a[e.facet.id]=[])).push(e);let s=Object.create(null),c=[],l=[];for(let e of i)s[e.id]=l.length<<1,l.push(t=>e.slot(t));let u=r?.config.facets;for(let e in a){let t=a[e],n=t[0].facet,i=u&&u[e]||[];if(t.every(e=>e.type==0)){if(s[n.id]=c.length<<1|1,Ce(i,t))c.push(r.facet(n));else{let e=n.combine(t.map(e=>e.value));c.push(r&&n.compare(e,r.facet(n))?r.facet(n):e)}}else{for(let e of t)e.type==0?(s[e.id]=c.length<<1|1,c.push(e.value)):(s[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));s[n.id]=l.length<<1,l.push(e=>De(e,n,t))}}let d=l.map(e=>e(s));return new e(t,o,d,s,c,a)}};function Le(e,t,n){let r=[[],[],[],[],[]],i=new Map;function a(e,o){let s=i.get(e);if(s!=null){if(s<=o)return;let t=r[s].indexOf(e);t>-1&&r[s].splice(t,1),e instanceof Fe&&n.delete(e.compartment)}if(i.set(e,o),Array.isArray(e))for(let t of e)a(t,o);else if(e instanceof Fe){if(n.has(e.compartment))throw RangeError(`Duplicate use of compartment in extensions`);let r=t.get(e.compartment)||e.inner;n.set(e.compartment,r),a(r,o)}else if(e instanceof Ne)a(e.inner,e.prec);else if(e instanceof ke)r[o].push(e),e.provides&&a(e.provides,o);else if(e instanceof we)r[o].push(e),e.facet.extensions&&a(e.facet.extensions,Ae.default);else{let t=e.extension;if(!t)throw Error(`Unrecognized extension value in extension set (${e}).`);if(t==e)throw Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);a(t,o)}}return a(e,Ae.default),r.reduce((e,t)=>e.concat(t))}function Re(e,t){if(t&1)return 2;let n=t>>1,r=e.status[n];if(r==4)throw Error(`Cyclic dependency between fields and/or facets`);if(r&2)return r;e.status[n]=4;let i=e.computeSlot(e,e.config.dynamicSlots[n]);return e.status[n]=2|i}function ze(e,t){return t&1?e.config.staticValues[t>>1]:e.values[t>>1]}var Be=k.define(),Ve=k.define({combine:e=>e.some(e=>e),static:!0}),He=k.define({combine:e=>e.length?e[0]:void 0,static:!0}),Ue=k.define(),We=k.define(),Ge=k.define(),Ke=k.define({combine:e=>e.length?e[0]:!1}),qe=class{constructor(e,t){this.type=e,this.value=t}static define(){return new Je}},Je=class{of(e){return new qe(this,e)}},Ye=class{constructor(e){this.map=e}of(e){return new A(this,e)}},A=class e{constructor(e,t){this.type=e,this.value=t}map(t){let n=this.type.map(this.value,t);return n===void 0?void 0:n==this.value?this:new e(this.type,n)}is(e){return this.type==e}static define(e={}){return new Ye(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let r of e){let e=r.map(t);e&&n.push(e)}return n}};A.reconfigure=A.define(),A.appendConfig=A.define();var Xe=class e{constructor(t,n,r,i,a,o){this.startState=t,this.changes=n,this.selection=r,this.effects=i,this.annotations=a,this.scrollIntoView=o,this._doc=null,this._state=null,r&&xe(r,n.newLength),a.some(t=>t.type==e.time)||(this.annotations=a.concat(e.time.of(Date.now())))}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}get newDoc(){return this._doc||=this.changes.apply(this.startState.doc)}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let n=this.annotation(e.userEvent);return!!(n&&(n==t||n.length>t.length&&n.slice(0,t.length)==t&&n[t.length]==`.`))}};Xe.time=qe.define(),Xe.userEvent=qe.define(),Xe.addToHistory=qe.define(),Xe.remote=qe.define();function Ze(e,t){let n=[];for(let r=0,i=0;;){let a,o;if(r<e.length&&(i==t.length||t[i]>=e[r]))a=e[r++],o=e[r++];else if(i<t.length)a=t[i++],o=t[i++];else return n;!n.length||n[n.length-1]<a?n.push(a,o):n[n.length-1]<o&&(n[n.length-1]=o)}}function Qe(e,t,n){let r,i,a;return n?(r=t.changes,i=pe.empty(t.changes.length),a=e.changes.compose(t.changes)):(r=t.changes.map(e.changes),i=e.changes.mapDesc(t.changes,!0),a=e.changes.compose(r)),{changes:a,selection:t.selection?t.selection.map(i):e.selection?.map(r),effects:A.mapEffects(e.effects,r).concat(A.mapEffects(t.effects,i)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function $e(e,t,n){let r=t.selection,i=it(t.annotations);return t.userEvent&&(i=i.concat(Xe.userEvent.of(t.userEvent))),{changes:t.changes instanceof pe?t.changes:pe.of(t.changes||[],n,e.facet(He)),selection:r&&(r instanceof O?r:O.single(r.anchor,r.head)),effects:it(t.effects),annotations:i,scrollIntoView:!!t.scrollIntoView}}function et(e,t,n){let r=$e(e,t.length?t[0]:{},e.doc.length);t.length&&t[0].filter===!1&&(n=!1);for(let i=1;i<t.length;i++){t[i].filter===!1&&(n=!1);let a=!!t[i].sequential;r=Qe(r,$e(e,t[i],a?r.changes.newLength:e.doc.length),a)}let i=Xe.create(e,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return nt(n?tt(i):i)}function tt(e){let t=e.startState,n=!0;for(let r of t.facet(Ue)){let t=r(e);if(t===!1){n=!1;break}Array.isArray(t)&&(n=n===!0?t:Ze(n,t))}if(n!==!0){let r,i;if(n===!1)i=e.changes.invertedDesc,r=pe.empty(t.doc.length);else{let t=e.changes.filter(n);r=t.changes,i=t.filtered.mapDesc(t.changes).invertedDesc}e=Xe.create(t,r,e.selection&&e.selection.map(i),A.mapEffects(e.effects,i),e.annotations,e.scrollIntoView)}let r=t.facet(We);for(let n=r.length-1;n>=0;n--){let i=r[n](e);e=i instanceof Xe?i:Array.isArray(i)&&i.length==1&&i[0]instanceof Xe?i[0]:et(t,it(i),!1)}return e}function nt(e){let t=e.startState,n=t.facet(Ge),r=e;for(let i=n.length-1;i>=0;i--){let a=n[i](e);a&&Object.keys(a).length&&(r=Qe(r,$e(t,a,e.changes.newLength),!0))}return r==e?e:Xe.create(t,e.changes,e.selection,r.effects,r.annotations,r.scrollIntoView)}var rt=[];function it(e){return e==null?rt:Array.isArray(e)?e:[e]}var at=(function(e){return e[e.Word=0]=`Word`,e[e.Space=1]=`Space`,e[e.Other=2]=`Other`,e})(at||={}),ot=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,st;try{st=RegExp(`[\\p{Alphabetic}\\p{Number}_]`,`u`)}catch{}function ct(e){if(st)return st.test(e);for(let t=0;t<e.length;t++){let n=e[t];if(/\w/.test(n)||n>`€`&&(n.toUpperCase()!=n.toLowerCase()||ot.test(n)))return!0}return!1}function lt(e){return t=>{if(!/\S/.test(t))return at.Space;if(ct(t))return at.Word;for(let n=0;n<e.length;n++)if(t.indexOf(e[n])>-1)return at.Word;return at.Other}}var j=class e{constructor(e,t,n,r,i,a){this.config=e,this.doc=t,this.selection=n,this.values=r,this.status=e.statusTemplate.slice(),this.computeSlot=i,a&&(a._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)Re(this,e<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw RangeError(`Field is not present in this state`)}else return Re(this,n),ze(this,n)}update(...e){return et(this,e,!0)}applyTransaction(t){let n=this.config,{base:r,compartments:i}=n;for(let e of t.effects)e.is(Pe.reconfigure)?(n&&=(i=new Map,n.compartments.forEach((e,t)=>i.set(t,e)),null),i.set(e.value.compartment,e.value.extension)):e.is(A.reconfigure)?(n=null,r=e.value):e.is(A.appendConfig)&&(n=null,r=it(r).concat(e.value));let a;n?a=t.startState.values.slice():(n=Ie.resolve(r,i,this),a=new e(n,this.doc,this.selection,n.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values);let o=t.startState.facet(Ve)?t.newSelection:t.newSelection.asSingle();new e(n,t.newDoc,o,a,(e,n)=>n.update(e,t),t)}replaceSelection(e){return typeof e==`string`&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:O.cursor(t.from+e.length,-1)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),r=this.changes(n.changes),i=[n.range],a=it(n.effects);for(let n=1;n<t.ranges.length;n++){let o=e(t.ranges[n]),s=this.changes(o.changes),c=s.map(r);for(let e=0;e<n;e++)i[e]=i[e].map(c);let l=r.mapDesc(s,!0);i.push(o.range.map(l)),r=r.compose(c),a=A.mapEffects(a,c).concat(A.mapEffects(it(o.effects),l))}return{changes:r,selection:O.create(i,t.mainIndex),effects:a}}changes(t=[]){return t instanceof pe?t:pe.of(t,this.doc.length,this.facet(e.lineSeparator))}toText(t){return x.of(t.split(this.facet(e.lineSeparator)||ue))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Re(this,t),ze(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let r=e[n];r instanceof ke&&this.config.address[r.id]!=null&&(t[n]=r.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(t,n={},r){if(!t||typeof t.doc!=`string`)throw RangeError(`Invalid JSON representation for EditorState`);let i=[];if(r){for(let e in r)if(Object.prototype.hasOwnProperty.call(t,e)){let n=r[e],a=t[e];i.push(n.init(e=>n.spec.fromJSON(a,e)))}}return e.create({doc:t.doc,selection:O.fromJSON(t.selection),extensions:n.extensions?i.concat([n.extensions]):i})}static create(t={}){let n=Ie.resolve(t.extensions||[],new Map),r=t.doc instanceof x?t.doc:x.of((t.doc||``).split(n.staticFacet(e.lineSeparator)||ue)),i=t.selection?t.selection instanceof O?t.selection:O.single(t.selection.anchor,t.selection.head):O.single(0);return xe(i,r.length),n.staticFacet(Ve)||(i=i.asSingle()),new e(n,r,i,n.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(e.tabSize)}get lineBreak(){return this.facet(e.lineSeparator)||`
5
+ `}get readOnly(){return this.facet(Ke)}phrase(t,...n){for(let n of this.facet(e.phrases))if(Object.prototype.hasOwnProperty.call(n,t)){t=n[t];break}return n.length&&(t=t.replace(/\$(\$|\d*)/g,(e,t)=>{if(t==`$`)return`$`;let r=+(t||1);return!r||r>n.length?e:n[r-1]})),t}languageDataAt(e,t,n=-1){let r=[];for(let i of this.facet(Be))for(let a of i(this,t,n))Object.prototype.hasOwnProperty.call(a,e)&&r.push(a[e]);return r}charCategorizer(e){let t=this.languageDataAt(`wordChars`,e);return lt(t.length?t[0]:``)}wordAt(e){let{text:t,from:n,length:r}=this.doc.lineAt(e),i=this.charCategorizer(e),a=e-n,o=e-n;for(;a>0;){let e=ie(t,a,!1);if(i(t.slice(e,a))!=at.Word)break;a=e}for(;o<r;){let e=ie(t,o);if(i(t.slice(o,e))!=at.Word)break;o=e}return a==o?null:O.range(a+n,o+n)}};j.allowMultipleSelections=Ve,j.tabSize=k.define({combine:e=>e.length?e[0]:4}),j.lineSeparator=He,j.readOnly=Ke,j.phrases=k.define({compare(e,t){let n=Object.keys(e),r=Object.keys(t);return n.length==r.length&&n.every(n=>e[n]==t[n])}}),j.languageData=Be,j.changeFilter=Ue,j.transactionFilter=We,j.transactionExtender=Ge,Pe.reconfigure=A.define();var ut=class{eq(e){return this==e}range(e,t=e){return ft.create(e,t,this)}};ut.prototype.startSide=ut.prototype.endSide=0,ut.prototype.point=!1,ut.prototype.mapMode=de.TrackDel;function dt(e,t){return e==t||e.constructor==t.constructor&&e.eq(t)}var ft=class e{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(t,n,r){return new e(t,n,r)}};function pt(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}var mt=class e{constructor(e,t,n,r){this.from=e,this.to=t,this.value=n,this.maxPoint=r}get length(){return ht(this.to)}findIndex(e,t,n,r=0){let i=n?this.to:this.from;for(let a=r,o=i.length;;){if(a==o)return a;let r=a+o>>1,s=i[r]-e||(n?this.value[r].endSide:this.value[r].startSide)-t;if(r==a)return s>=0?a:o;s>=0?o=r:a=r+1}}between(e,t,n,r){for(let i=this.findIndex(t,-1e9,!0),a=this.findIndex(n,1e9,!1,i);i<a;i++)if(r(this.from[i]+e,this.to[i]+e,this.value[i])===!1)return!1}map(t,n,r,i,a){let o=[],s=[],c=[],l=-1,u=-1;iter:for(let e=0;e<this.value.length;e++){let d=this.value[e],f=this.from[e]+t,p=this.to[e]+t,m,h;if(f==p){let e=n.mapPos(f,d.startSide,d.mapMode);if(e==null||(m=h=e,d.startSide!=d.endSide&&(h=n.mapPos(f,d.endSide),h<m)))continue}else if(m=n.mapPos(f,d.startSide),h=n.mapPos(p,d.endSide),m>h||m==h&&d.startSide>0&&d.endSide<=0)continue;if(!((h-m||d.endSide-d.startSide)<0)){if(l<0&&(l=m),d.point&&(u=Math.max(u,h-m)),(m-r||d.startSide-i)>=0)o.push(d),s.push(m-l),c.push(h-l),r=h,i=d.endSide;else{if(m==h)for(let e=o.length;e>0;e--){if((m-(c[e-1]+l)||d.startSide-o[e-1].endSide)>=0){o.splice(e,0,d),s.splice(e,0,m-l),c.splice(e,0,h-l);continue iter}if((m-(s[e-1]+l)||d.endSide-o[e-1].startSide)>0)break}a(m,h,d)}}}return{mapped:o.length?new e(s,c,o,u):null,pos:l}}},M=class e{constructor(e,t,n,r){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=r}static create(t,n,r,i){return new e(t,n,r,i)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(t){let{add:n=[],sort:r=!1,filterFrom:i=0,filterTo:a=this.length}=t,o=t.filter;if(n.length==0&&!o)return this;if(r&&(n=n.slice().sort(pt)),this.isEmpty)return n.length?e.of(n):this;let s=new yt(this,null,-1).goto(0),c=0,l=[],u=new _t;for(;s.value||c<n.length;)if(c<n.length&&(s.from-n[c].from||s.startSide-n[c].value.startSide)>=0){let e=n[c++];u.addInner(e.from,e.to,e.value,!1)||l.push(e)}else s.rangeIndex==1&&s.chunkIndex<this.chunk.length&&(c==n.length||this.chunkEnd(s.chunkIndex)<n[c].from)&&(!o||i>this.chunkEnd(s.chunkIndex)||a<this.chunkPos[s.chunkIndex])&&u.addChunk(this.chunkPos[s.chunkIndex],this.chunk[s.chunkIndex])?s.nextChunk():((!o||i>s.to||a<s.from||o(s.from,s.to,s.value))&&(u.addInner(s.from,s.to,s.value,!1)||l.push(ft.create(s.from,s.to,s.value))),s.next());return u.finishInner(this.nextLayer.isEmpty&&!l.length?e.empty:this.nextLayer.update({add:l,filter:o,filterFrom:i,filterTo:a}))}map(t){if(t.empty||this.isEmpty)return this;let n=[],r=[],i=-1,a,o=(e,t,n)=>{a||=new _t,a.addRange(e,t,n,!1)};for(let e=0;e<this.chunk.length;e++){let a=this.chunkPos[e],s=this.chunk[e],c=t.touchesRange(a,a+s.length);if(c===!1)i=Math.max(i,s.maxPoint),n.push(s),r.push(t.mapPos(a));else if(c===!0){let[e,c]=n.length?[ht(r)+ht(n).length,ht(ht(n).value).endSide]:[-1,-1],{mapped:l,pos:u}=s.map(a,t,e,c,o);l&&(i=Math.max(i,l.maxPoint),n.push(l),r.push(u))}}let s=this.nextLayer.map(t);return a&&(s=a.finishInner(s)),n.length==0?s:new e(r,n,s||e.empty,i)}between(e,t,n){if(!this.isEmpty){for(let r=0;r<this.chunk.length;r++){let i=this.chunkPos[r],a=this.chunk[r];if(t>=i&&e<=i+a.length&&a.between(i,e-i,t-i,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return bt.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return bt.from(e).goto(t)}static compare(e,t,n,r,i=-1){let a=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),o=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=i),s=vt(a,o,n),c=new St(a,s,i),l=new St(o,s,i);n.iterGaps((e,t,n)=>Ct(c,e,l,t,n,r)),n.empty&&n.length==0&&Ct(c,0,l,0,0,r)}static eq(e,t,n=0,r){r??=1e9-1;let i=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),a=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(i.length!=a.length)return!1;if(!i.length)return!0;let o=vt(i,a),s=new St(i,o,0).goto(n),c=new St(a,o,0).goto(n);for(;;){if(s.to!=c.to||!wt(s.active,c.active)||s.point&&(!c.point||!dt(s.point,c.point)))return!1;if(s.to>r)return!0;s.next(),c.next()}}static spans(e,t,n,r,i=-1){let a=new St(e,null,i).goto(t),o=t,s=a.openStart;for(;;){let e=Math.min(a.to,n);if(a.point){let n=a.activeForPoint(a.to),i=a.pointFrom<t?n.length+1:a.point.startSide<0?n.length:Math.min(n.length,s);r.point(o,e,a.point,n,i,a.pointRank),s=Math.min(a.openEnd(e),n.length)}else e>o&&(r.span(o,e,a.active,s),s=a.openEnd(e));if(a.to>n)return s+(a.point&&a.to>n?1:0);o=a.to,a.next()}}static of(e,t=!1){let n=new _t;for(let r of e instanceof ft?[e]:t?gt(e):e)n.add(r.from,r.to,r.value);return n.finish()}static join(t){if(!t.length)return e.empty;let n=ht(t);for(let r=t.length-2;r>=0;r--)for(let i=t[r];i!=e.empty;i=i.nextLayer)n=new e(i.chunkPos,i.chunk,n,Math.max(i.maxPoint,n.maxPoint));return n}};M.empty=new M([],[],null,-1);function ht(e){return e[e.length-1]}function gt(e){if(e.length>1)for(let t=e[0],n=1;n<e.length;n++){let r=e[n];if(pt(t,r)>0)return e.slice().sort(pt);t=r}return e}M.empty.nextLayer=M.empty;var _t=class e{finishChunk(e){this.chunks.push(new mt(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,n){this.addRange(e,t,n,!0)}addRange(t,n,r,i){this.addInner(t,n,r,i)||(this.nextLayer||=new e).addRange(t,n,r,i)}addInner(e,t,n,r){let i=e-this.lastTo||n.startSide-this.last.endSide;if(r&&i<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw Error("Ranges must be added sorted by `from` position and `startSide`");return i<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=n,this.lastFrom=e,this.lastTo=t,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let n=t.value.length-1;return this.last=t.value[n],this.lastFrom=t.from[n]+e,this.lastTo=t.to[n]+e,!0}finish(){return this.finishInner(M.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=M.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}};function vt(e,t,n){let r=new Map;for(let t of e)for(let e=0;e<t.chunk.length;e++)t.chunk[e].maxPoint<=0&&r.set(t.chunk[e],t.chunkPos[e]);let i=new Set;for(let e of t)for(let t=0;t<e.chunk.length;t++){let a=r.get(e.chunk[t]);a!=null&&(n?n.mapPos(a):a)==e.chunkPos[t]&&!n?.touchesRange(a,a+e.chunk[t].length)&&i.add(e.chunk[t])}return i}var yt=class{constructor(e,t,n,r=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=r}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,n){for(;this.chunkIndex<this.layer.chunk.length;){let t=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(t)||this.layer.chunkEnd(this.chunkIndex)<e||t.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let r=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<r)&&this.setRangeIndex(r)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],n=e+t.from[this.rangeIndex];if(this.from=n,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}},bt=class e{constructor(e){this.heap=e}static from(t,n=null,r=-1){let i=[];for(let e=0;e<t.length;e++)for(let a=t[e];!a.isEmpty;a=a.nextLayer)a.maxPoint>=r&&i.push(new yt(a,n,r,e));return i.length==1?i[0]:new e(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let n of this.heap)n.goto(e,t);for(let e=this.heap.length>>1;e>=0;e--)xt(this.heap,e);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let e=this.heap.length>>1;e>=0;e--)xt(this.heap,e);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),xt(this.heap,0)}}};function xt(e,t){for(let n=e[t];;){let r=(t<<1)+1;if(r>=e.length)break;let i=e[r];if(r+1<e.length&&i.compare(e[r+1])>=0&&(i=e[r+1],r++),n.compare(i)<0)break;e[r]=n,e[t]=i,t=r}}var St=class{constructor(e,t,n){this.minPoint=n,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=bt.from(e,t,n)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Tt(this.active,e),Tt(this.activeTo,e),Tt(this.activeRank,e),this.minActive=Dt(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:r,rank:i}=this.cursor;for(;t<this.activeRank.length&&(i-this.activeRank[t]||r-this.activeTo[t])>0;)t++;Et(this.active,t,n),Et(this.activeTo,t,r),Et(this.activeRank,t,i),e&&Et(e,t,this.cursor.from),this.minActive=Dt(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let r=this.minActive;if(r>-1&&(this.activeTo[r]-this.cursor.from||this.active[r].endSide-this.cursor.startSide)<0){if(this.activeTo[r]>e){this.to=this.activeTo[r],this.endSide=this.active[r].endSide;break}this.removeActive(r),n&&Tt(n,r)}else if(!this.cursor.value){this.to=this.endSide=1e9;break}else if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let e=this.cursor.value;if(!e.point)this.addActive(n),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=e,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=e.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}}if(n){this.openStart=0;for(let t=n.length-1;t>=0&&n[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let n=this.active.length-1;n>=0&&!(this.activeRank[n]<this.pointRank);n--)(this.activeTo[n]>e||this.activeTo[n]==e&&this.active[n].endSide>=this.point.endSide)&&t.push(this.active[n]);return t.reverse()}openEnd(e){let t=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>e;n--)t++;return t}};function Ct(e,t,n,r,i,a){e.goto(t),n.goto(r);let o=r+i,s=r,c=r-t,l=!!a.boundChange;for(let t=!1;;){let r=e.to+c-n.to,i=r||e.endSide-n.endSide,u=i<0?e.to+c:n.to,d=Math.min(u,o);if(e.point||n.point?(e.point&&n.point&&dt(e.point,n.point)&&wt(e.activeForPoint(e.to),n.activeForPoint(n.to))||a.comparePoint(s,d,e.point,n.point),t=!1):(t&&=(a.boundChange(s),!1),d>s&&!wt(e.active,n.active)&&a.compareRange(s,d,e.active,n.active),l&&d<o&&(r||e.openEnd(u)!=n.openEnd(u))&&(t=!0)),u>o)break;s=u,i<=0&&e.next(),i>=0&&n.next()}}function wt(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n]&&!dt(e[n],t[n]))return!1;return!0}function Tt(e,t){for(let n=t,r=e.length-1;n<r;n++)e[n]=e[n+1];e.pop()}function Et(e,t,n){for(let n=e.length-1;n>=t;n--)e[n+1]=e[n];e[t]=n}function Dt(e,t){let n=-1,r=1e9;for(let i=0;i<t.length;i++)(t[i]-r||e[i].endSide-e[n].endSide)<0&&(n=i,r=t[i]);return n}function Ot(e,t,n,r){for(let r=0,i=0;;){if(i>=t)return r;if(r==e.length)break;i+=e.charCodeAt(r)==9?n-i%n:1,r=ie(e,r)}return r===!0?-1:e.length}var kt=class{constructor(){this.cap=32,this.start=new Int32Array(this.cap),this.end=new Int32Array(this.cap),this.flags=new Uint8Array(this.cap),this.count=0,this.endsInQuote=!1,this.openAt=-1}grow(){let e=this.cap*2,t=new Int32Array(e);t.set(this.start),this.start=t;let n=new Int32Array(e);n.set(this.end),this.end=n;let r=new Uint8Array(e);r.set(this.flags),this.flags=r,this.cap=e}push(e,t,n){this.count===this.cap&&this.grow(),this.start[this.count]=e,this.end[this.count]=t,this.flags[this.count]=n,this.count++}scan(e,t,n,r=null){this.count=0,this.endsInQuote=!1,this.openAt=-1;let i=e.length,a=0,o=0,s=0,c=!1;for(n&&(s=3,c=!0);;){if(!c){if(a===o&&a<i&&e.charCodeAt(a)===34&&!(r&&r.includes(a))){s|=1,c=!0,a++;continue}let n=e.indexOf(t,a);if(n===-1)return this.push(o,i,s),this;this.push(o,n,s),a=o=n+1,s=0;continue}let n=e.indexOf(`"`,a);if(n===-1)return this.push(o,i,s|4),this.endsInQuote=!0,this.openAt=s&2?-1:o,this;if(n+1<i&&e.charCodeAt(n+1)===34){a=n+2;continue}c=!1,a=n+1;let l=e.indexOf(t,a);if(l===-1)return this.push(o,i,s),this;this.push(o,l,s),a=o=l+1,s=0}}};function At(e,t,n,r,i){let a=0,o=Math.min(n,t+r-1);for(let n=t;n<=o;n++){let t=e(n),r=0;for(;;){let e=t.indexOf(`"`,r);if(e===-1)break;if(e+1<t.length&&t.charCodeAt(e+1)===34)r=e+2;else return n}if(a+=t.length+1,a>i)return-1}return-1}function jt(e,t,n,r){if(!(r&1))return e.slice(t,n);let i=r&2?t:t+1,a=``,o=i;for(;;){let t=e.indexOf(`"`,o);if(t===-1||t>=n)return a+=e.slice(o,n),a;if(a+=e.slice(o,t),t+1<n&&e.charCodeAt(t+1)===34)a+=`"`,o=t+2;else return a+=e.slice(t+1,n),a}}var Mt=new Set,Nt=Object.freeze({delimiter:`,`,hasHeader:!1,align:!0,rainbow:!0,faint:!0,collapse:!0,cap:32,gap:0,menuRoom:0,expanded:new Set,hidden:Mt}),Pt=A.define(),Ft=A.define(),It=A.define(),Lt=new kt;function Rt(e,t){let{text:n}=e.line(1);Lt.scan(n,t,!1,null);let r=[];for(let e=0;e<Lt.count;e++)r.push(n.slice(Lt.start[e],Lt.end[e]));return r}function zt(e,t,n){let r=Rt(e,n),i=Rt(t,n);if(r.length!==i.length)return!0;if(r.every((e,t)=>e===i[t]))return!1;let a=e=>[...e].sort(),o=a(r),s=a(i);return o.every((e,t)=>e===s[t])}for(var N=ke.define({create:()=>Nt,update(e,t){let n=!1;for(let r of t.effects)if(r.is(Pt)){let t=r.value.delimiter!=null&&r.value.delimiter!==e.delimiter||r.value.hasHeader!=null&&r.value.hasHeader!==e.hasHeader;e={...e,...r.value},t&&!r.value.hidden&&e.hidden.size&&(e.hidden=Mt),r.value.hidden&&(n=!0)}else if(r.is(It)){let t=new Set(r.value);n=!0,(t.size!==e.hidden.size||[...t].some(t=>!e.hidden.has(t)))&&(e={...e,hidden:t.size?t:Mt})}else if(r.is(Ft)){let{col:t}=r.value,n=e.expanded.has(t),i=r.value.expanded??!n;if(i!==n){let n=new Set(e.expanded);i?n.add(t):n.delete(t),e={...e,expanded:n}}}return e.hidden.size&&!n&&t.docChanged&&(t.isUserEvent(`input.data`)||t.isUserEvent(`input.reload`)||t.isUserEvent(`undo`)||t.isUserEvent(`redo`))&&zt(t.startState.doc,t.newDoc,e.delimiter)&&(e={...e,hidden:Mt}),e}}),Bt=(e={})=>N.init(()=>({...Nt,...e})),Vt=`ͼ`,Ht=typeof Symbol>`u`?`__ͼ`:Symbol.for(Vt),Ut=typeof Symbol>`u`?`__styleSet`+Math.floor(Math.random()*1e8):Symbol(`styleSet`),Wt=typeof globalThis<`u`?globalThis:typeof window<`u`?window:{},Gt=class{constructor(e,t){this.rules=[];let{finish:n}=t||{};function r(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function i(e,t,a,o){let s=[],c=/^@(\w+)\b/.exec(e[0]),l=c&&c[1]==`keyframes`;if(c&&t==null)return a.push(e[0]+`;`);for(let n in t){let o=t[n];if(/&/.test(n))i(n.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),o,a);else if(o&&typeof o==`object`){if(!c)throw RangeError(`The value of a property (`+n+`) should be a primitive value.`);i(r(n),o,s,l)}else o!=null&&s.push(n.replace(/_.*/,``).replace(/[A-Z]/g,e=>`-`+e.toLowerCase())+`: `+o+`;`)}(s.length||l)&&a.push((n&&!c&&!o?e.map(n):e).join(`, `)+` {`+s.join(` `)+`}`)}for(let t in e)i(r(t),e[t],this.rules)}getRules(){return this.rules.join(`
6
+ `)}static newName(){let e=Wt[Ht]||1;return Wt[Ht]=e+1,Vt+e.toString(36)}static mount(e,t,n){let r=e[Ut],i=n&&n.nonce;r?i&&r.setNonce(i):r=new qt(e,i),r.mount(Array.isArray(t)?t:[t],e)}},Kt=new Map,qt=class{constructor(e,t){let n=e.ownerDocument||e,r=n.defaultView;if(!e.head&&e.adoptedStyleSheets&&r.CSSStyleSheet){let t=Kt.get(n);if(t)return e[Ut]=t;this.sheet=new r.CSSStyleSheet,Kt.set(n,this)}else this.styleTag=n.createElement(`style`),t&&this.styleTag.setAttribute(`nonce`,t);this.modules=[],e[Ut]=this}mount(e,t){let n=this.sheet,r=0,i=0,a=!1;for(let t=0;t<e.length;t++){let o=e[t],s=this.modules.indexOf(o);if(s<i&&s>-1&&(this.modules.splice(s,1),a=!0,i--,s=-1),s==-1){if(this.modules.splice(i++,0,o),a=!0,n)for(let e=0;e<o.rules.length;e++)n.insertRule(o.rules[e],r++)}else{for(;i<s;)r+=this.modules[i++].rules.length;r+=o.rules.length,i++}}if(n)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{if(a){let e=``;for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+`
7
+ `;this.styleTag.textContent=e}let e=t.head||t;this.styleTag.parentNode!=e&&e.insertBefore(this.styleTag,e.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute(`nonce`)!=e&&this.styleTag.setAttribute(`nonce`,e)}},Jt={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:`"`},Xt=typeof navigator<`u`&&/Mac/.test(navigator.platform),Zt=typeof navigator<`u`&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Qt=0;Qt<10;Qt++)Jt[48+Qt]=Jt[96+Qt]=String(Qt);for(var Qt=1;Qt<=24;Qt++)Jt[Qt+111]=`F`+Qt;for(var Qt=65;Qt<=90;Qt++)Jt[Qt]=String.fromCharCode(Qt+32),Yt[Qt]=String.fromCharCode(Qt);for(var $t in Jt)Yt.hasOwnProperty($t)||(Yt[$t]=Jt[$t]);function en(e){var t=!(Xt&&e.metaKey&&e.shiftKey&&!e.ctrlKey&&!e.altKey||Zt&&e.shiftKey&&e.key&&e.key.length==1||e.key==`Unidentified`)&&e.key||(e.shiftKey?Yt:Jt)[e.keyCode]||e.key||`Unidentified`;return t==`Esc`&&(t=`Escape`),t==`Del`&&(t=`Delete`),t==`Left`&&(t=`ArrowLeft`),t==`Up`&&(t=`ArrowUp`),t==`Right`&&(t=`ArrowRight`),t==`Down`&&(t=`ArrowDown`),t}var tn=typeof navigator<`u`?navigator:{userAgent:``,vendor:``,platform:``},nn=typeof document<`u`?document:{documentElement:{style:{}}},rn=/Edge\/(\d+)/.exec(tn.userAgent),an=/MSIE \d/.test(tn.userAgent),on=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(tn.userAgent),sn=!!(an||on||rn),cn=!sn&&/gecko\/(\d+)/i.test(tn.userAgent),ln=!sn&&/Chrome\/(\d+)/.exec(tn.userAgent),un=`webkitFontSmoothing`in nn.documentElement.style,dn=!sn&&/Apple Computer/.test(tn.vendor),fn=dn&&(/Mobile\/\w+/.test(tn.userAgent)||tn.maxTouchPoints>2),P={mac:fn||/Mac/.test(tn.platform),windows:/Win/.test(tn.platform),linux:/Linux|X11/.test(tn.platform),ie:sn,ie_version:an?nn.documentMode||6:on?+on[1]:rn?+rn[1]:0,gecko:cn,gecko_version:cn?+(/Firefox\/(\d+)/.exec(tn.userAgent)||[0,0])[1]:0,chrome:!!ln,chrome_version:ln?+ln[1]:0,ios:fn,android:/Android\b/.test(tn.userAgent),webkit:un,webkit_version:un?+(/\bAppleWebKit\/(\d+)/.exec(tn.userAgent)||[0,0])[1]:0,safari:dn,safari_version:dn?+(/\bVersion\/(\d+(\.\d+)?)/.exec(tn.userAgent)||[0,0])[1]:0,tabSize:nn.documentElement.style.tabSize==null?`-moz-tab-size`:`tab-size`};function pn(e,t){for(let n in e)n==`class`&&t.class?t.class+=` `+e.class:n==`style`&&t.style?t.style+=`;`+e.style:t[n]=e[n];return t}var mn=Object.create(null);function hn(e,t,n){if(e==t)return!0;e||=mn,t||=mn;let r=Object.keys(e),i=Object.keys(t);if(r.length-0!=i.length-0)return!1;for(let a of r)if(a!=n&&(i.indexOf(a)==-1||e[a]!==t[a]))return!1;return!0}function gn(e,t){for(let n=e.attributes.length-1;n>=0;n--){let r=e.attributes[n].name;t[r]??e.removeAttribute(r)}for(let n in t){let r=t[n];n==`style`?e.style.cssText=r:e.getAttribute(n)!=r&&e.setAttribute(n,r)}}function _n(e,t,n){let r=!1;if(t)for(let i in t)n&&i in n||(r=!0,i==`style`?e.style.cssText=``:e.removeAttribute(i));if(n)for(let i in n)t&&t[i]==n[i]||(r=!0,i==`style`?e.style.cssText=n[i]:e.setAttribute(i,n[i]));return r}function vn(e){let t=Object.create(null);for(let n=0;n<e.attributes.length;n++){let r=e.attributes[n];t[r.name]=r.value}return t}var yn=class{eq(e){return!1}updateDOM(e,t,n){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,n){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}},bn=(function(e){return e[e.Text=0]=`Text`,e[e.WidgetBefore=1]=`WidgetBefore`,e[e.WidgetAfter=2]=`WidgetAfter`,e[e.WidgetRange=3]=`WidgetRange`,e})(bn||={}),F=class extends ut{constructor(e,t,n,r){super(),this.startSide=e,this.endSide=t,this.widget=n,this.spec=r}get heightRelevant(){return!1}static mark(e){return new xn(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),n=!!e.block;return t+=n&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Cn(e,t,t,n,e.widget||null,!1)}static replace(e){let t=!!e.block,n,r;if(e.isBlockGap)n=-5e8,r=4e8;else{let{start:i,end:a}=wn(e,t);n=(i?t?-3e8:-1:5e8)-1,r=(a?t?2e8:1:-6e8)+1}return new Cn(e,n,r,t,e.widget||null,!0)}static line(e){return new Sn(e)}static set(e,t=!1){return M.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}};F.none=M.empty;var xn=class e extends F{constructor(e){let{start:t,end:n}=wn(e);super(t?-1:5e8,n?1:-6e8,null,e),this.tagName=e.tagName||`span`,this.attrs=e.class&&e.attributes?pn(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||mn}eq(t){return this==t||t instanceof e&&this.tagName==t.tagName&&hn(this.attrs,t.attrs)}range(e,t=e){if(e>=t)throw RangeError(`Mark decorations may not be empty`);return super.range(e,t)}};xn.prototype.point=!1;var Sn=class e extends F{constructor(e){super(-2e8,-2e8,null,e)}eq(t){return t instanceof e&&this.spec.class==t.spec.class&&hn(this.spec.attributes,t.spec.attributes)}range(e,t=e){if(t!=e)throw RangeError(`Line decoration ranges must be zero-length`);return super.range(e,t)}};Sn.prototype.mapMode=de.TrackBefore,Sn.prototype.point=!0;var Cn=class e extends F{constructor(e,t,n,r,i,a){super(t,n,i,e),this.block=r,this.isReplace=a,this.mapMode=r?t<=0?de.TrackBefore:de.TrackAfter:de.TrackDel}get type(){return this.startSide==this.endSide?this.startSide<=0?bn.WidgetBefore:bn.WidgetAfter:bn.WidgetRange}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(t){return t instanceof e&&Tn(this.widget,t.widget)&&this.block==t.block&&this.startSide==t.startSide&&this.endSide==t.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw RangeError(`Invalid range for replacement decoration`);if(!this.isReplace&&t!=e)throw RangeError(`Widget decorations can only have zero-length ranges`);return super.range(e,t)}};Cn.prototype.point=!0;function wn(e,t=!1){let{inclusiveStart:n,inclusiveEnd:r}=e;return n??=e.inclusive,r??=e.inclusive,{start:n??t,end:r??t}}function Tn(e,t){return e==t||!!(e&&t&&e.compare(t))}function En(e,t,n,r=0){let i=n.length-1;i>=0&&n[i]+r>=e?n[i]=Math.max(n[i],t):n.push(e,t)}var Dn=class e extends ut{constructor(e,t,n){super(),this.tagName=e,this.attributes=t,this.rank=n}eq(t){return t==this||t instanceof e&&this.tagName==t.tagName&&hn(this.attributes,t.attributes)}static create(t){return new e(t.tagName,t.attributes||mn,t.rank==null?50:Math.max(0,Math.min(t.rank,100)))}static set(e,t=!1){return M.of(e,t)}};Dn.prototype.startSide=Dn.prototype.endSide=-1;var I=e=>e.nodeType==1,On=e=>e.nodeType==3;function kn(e){let t;return t=e.nodeType==11?e.getSelection?e:e.ownerDocument:e,t.getSelection()}function An(e,t){return t?e==t||e.contains(t.nodeType==1?t:t.parentNode):!1}function jn(e,t){if(!t.anchorNode)return!1;try{return An(e,t.anchorNode)}catch{return!1}}function Mn(e){return On(e)?Yn(e,0,e.nodeValue.length).getClientRects():I(e)?e.getClientRects():[]}function Nn(e,t,n,r){return n?In(e,t,n,r,-1)||In(e,t,n,r,1):!1}function Pn(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t}function Fn(e){return I(e)&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(e.nodeName)}function In(e,t,n,r,i){for(;;){if(e==n&&t==r)return!0;if(t==(i<0?0:Ln(e))){if(e.nodeName==`DIV`)return!1;let n=e.parentNode;if(!n||!I(n))return!1;t=Pn(e)+(i<0?0:1),e=n}else if(I(e)){if(e=e.childNodes[t+(i<0?-1:0)],I(e)&&(e.nodeName==`IMG`||e.nodeName==`BR`||e.contentEditable==`false`))return!1;t=i<0?Ln(e):0}else return!1}}function Ln(e){return On(e)?e.nodeValue.length:e.childNodes.length}function Rn(e,t){let{left:n,right:r}=e;if(n==r)return e;let i=t?n:r;return{left:i,right:i,top:e.top,bottom:e.bottom}}function zn(e){let t=e.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.innerWidth,top:0,bottom:e.innerHeight}}function Bn(e,t){let n=t.width/e.offsetWidth,r=t.height/e.offsetHeight;return(n>.995&&n<1.005||!isFinite(n)||Math.abs(t.width-e.offsetWidth)<1)&&(n=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(t.height-e.offsetHeight)<1)&&(r=1),{scaleX:n,scaleY:r}}function Vn(e,t,n,r,i,a,o,s){let c=e.ownerDocument,l=c.defaultView||window;for(let u=e,d=!1;u&&!d;)if(I(u)){let e,f=u==c.body,p=1,m=1,h=!0,g=!0;if(f)e=zn(l);else{let t=getComputedStyle(u);if(/^(fixed|sticky)$/.test(t.position)&&(d=!0),(u.scrollHeight<=u.clientHeight||!/auto|scroll/.test(t.overflowY))&&(g=!1),(u.scrollWidth<=u.clientWidth||!/auto|scroll/.test(t.overflowX))&&(h=!1),!h&&!g){u=u.assignedSlot||u.parentNode;continue}let n=u.getBoundingClientRect();({scaleX:p,scaleY:m}=Bn(u,n)),e={left:n.left,right:n.left+u.clientWidth*p,top:n.top,bottom:n.top+u.clientHeight*m}}let _=0,v=0;if(g){if(i==`nearest`)t.top<e.top+o?(v=t.top-(e.top+o),n>0&&t.bottom>e.bottom+v&&(v=t.bottom-e.bottom+o)):t.bottom>e.bottom-o&&(v=t.bottom-e.bottom+o,n<0&&t.top-v<e.top&&(v=t.top-(e.top+o)));else{let r=t.bottom-t.top,a=e.bottom-e.top;v=(i==`center`&&r<=a?t.top+r/2-a/2:i==`start`||i==`center`&&n<0?t.top-o:t.bottom-a+o)-e.top}}if(h&&(r==`nearest`?t.left<e.left+a?(_=t.left-(e.left+a),n>0&&t.right>e.right+_&&(_=t.right-e.right+a)):t.right>e.right-a&&(_=t.right-e.right+a,n<0&&t.left<e.left+_&&(_=t.left-(e.left+a))):_=(r==`center`?t.left+(t.right-t.left)/2-(e.right-e.left)/2:r==`start`==s?t.left-a:t.right-(e.right-e.left)+a)-e.left),_||v){if(f)l.scrollBy(_,v);else{let e=0,n=0;if(v){let e=u.scrollTop;u.scrollTop+=v/m,n=(u.scrollTop-e)*m}if(_){let t=u.scrollLeft;u.scrollLeft+=_/p,e=(u.scrollLeft-t)*p}t={left:t.left-e,top:t.top-n,right:t.right-e,bottom:t.bottom-n},e&&Math.abs(e-_)<1&&(r=`nearest`),n&&Math.abs(n-v)<1&&(i=`nearest`)}}if(f)break;(t.top<e.top||t.bottom>e.bottom||t.left<e.left||t.right>e.right)&&(t={left:Math.max(t.left,e.left),right:Math.min(t.right,e.right),top:Math.max(t.top,e.top),bottom:Math.min(t.bottom,e.bottom)}),u=u.assignedSlot||u.parentNode}else if(u.nodeType==11)u=u.host;else break}function Hn(e,t=!0){let n=e.ownerDocument,r=null,i=null;for(let a=e.parentNode;a&&!(a==n.body||(!t||r)&&i);)if(I(a))!i&&a.scrollHeight>a.clientHeight&&/scroll|auto/.test(getComputedStyle(a).overflowY)&&(i=a),t&&!r&&a.scrollWidth>a.clientWidth&&/scroll|auto/.test(getComputedStyle(a).overflowX)&&(r=a),a=a.assignedSlot||a.parentNode;else if(a.nodeType==11)a=a.host;else break;return{x:r,y:i}}var Un=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:n}=e;this.set(t,Math.min(e.anchorOffset,t?Ln(t):0),n,Math.min(e.focusOffset,n?Ln(n):0))}set(e,t,n,r){this.anchorNode=e,this.anchorOffset=t,this.focusNode=n,this.focusOffset=r}};function Wn(e){let t=[];for(let n=e;n;n=n.nodeType==11?n.host:n.parentNode)I(n)&&t.push({node:n,left:n.scrollLeft,top:n.scrollTop});return t}function Gn(e,t=!0){for(let{node:n,left:r,top:i}of e)t&&n.scrollTop!=i&&(n.scrollTop=i),n.scrollLeft!=r&&(n.scrollLeft=r)}var Kn=null;P.safari&&P.safari_version>=26&&(Kn=!1);function qn(e){if(e.setActive)return e.setActive();if(Kn)return e.focus(Kn);let t=Wn(e);e.focus(Kn==null?{get preventScroll(){return Kn={preventScroll:!0},!0}}:void 0),Kn||(Kn=!1,Gn(t))}var Jn;function Yn(e,t,n=t){let r=Jn||=document.createRange();return r.setEnd(e,n),r.setStart(e,t),r}function Xn(e,t,n,r){let i={key:t,code:t,keyCode:n,which:n,cancelable:!0};r&&({altKey:i.altKey,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,metaKey:i.metaKey}=r);let a=new KeyboardEvent(`keydown`,i);a.synthetic=!0,e.dispatchEvent(a);let o=new KeyboardEvent(`keyup`,i);return o.synthetic=!0,e.dispatchEvent(o),a.defaultPrevented||o.defaultPrevented}function Zn(e){for(;e;){if(e&&(e.nodeType==9||e.nodeType==11&&e.host))return e;e=e.assignedSlot||e.parentNode}return null}function Qn(e,t){let n=t.focusNode,r=t.focusOffset;if(!n||t.anchorNode!=n||t.anchorOffset!=r)return!1;for(r=Math.min(r,Ln(n));;)if(r){if(!I(n))return!1;let e=n.childNodes[r-1];e.contentEditable==`false`?r--:(n=e,r=Ln(n))}else if(n==e)return!0;else r=Pn(n),n=n.parentNode}function $n(e){return e instanceof Window?e.pageYOffset>Math.max(0,e.document.documentElement.scrollHeight-e.innerHeight-4):e.scrollTop>Math.max(1,e.scrollHeight-e.clientHeight-4)}function er(e,t){for(let n=e,r=t;;)if(On(n)&&r>0)return{node:n,offset:r};else if(I(n)&&r>0){if(n.contentEditable==`false`)return null;n=n.childNodes[r-1],r=Ln(n)}else if(n.parentNode&&!Fn(n))r=Pn(n),n=n.parentNode;else return null}function tr(e,t){for(let n=e,r=t;;)if(On(n)&&r<n.nodeValue.length)return{node:n,offset:r};else if(I(n)&&r<n.childNodes.length){if(n.contentEditable==`false`)return null;n=n.childNodes[r],r=0}else if(n.parentNode&&!Fn(n))r=Pn(n)+1,n=n.parentNode;else return null}var nr=class e{constructor(e,t,n=!0){this.node=e,this.offset=t,this.precise=n}static before(t,n){return new e(t.parentNode,Pn(t),n)}static after(t,n){return new e(t.parentNode,Pn(t)+1,n)}},rr=(function(e){return e[e.LTR=0]=`LTR`,e[e.RTL=1]=`RTL`,e})(rr||={}),ir=rr.LTR,ar=rr.RTL;function or(e){let t=[];for(let n=0;n<e.length;n++)t.push(1<<e[n]);return t}var sr=or(`88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008`),cr=or(`4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333`),lr=Object.create(null),ur=[];for(let e of[`()`,`[]`,`{}`]){let t=e.charCodeAt(0),n=e.charCodeAt(1);lr[t]=n,lr[n]=-t}function dr(e){return e<=247?sr[e]:1424<=e&&e<=1524?2:1536<=e&&e<=1785?cr[e-1536]:1774<=e&&e<=2220?4:8192<=e&&e<=8204?256:64336<=e&&e<=65023?4:1}var fr=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/,pr=class{get dir(){return this.level%2?ar:ir}constructor(e,t,n){this.from=e,this.to=t,this.level=n}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,n,r){let i=-1;for(let a=0;a<e.length;a++){let o=e[a];if(o.from<=t&&o.to>=t){if(o.level==n)return a;(i<0||(r==0?e[i].level>o.level:r<0?o.from<t:o.to>t))&&(i=a)}}if(i<0)throw RangeError(`Index out of range`);return i}};function mr(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.from!=i.from||r.to!=i.to||r.direction!=i.direction||!mr(r.inner,i.inner))return!1}return!0}var L=[];function hr(e,t,n,r,i){for(let a=0;a<=r.length;a++){let o=a?r[a-1].to:t,s=a<r.length?r[a].from:n,c=a?256:i;for(let t=o,n=c,r=c;t<s;t++){let i=dr(e.charCodeAt(t));i==512?i=n:i==8&&r==4&&(i=16),L[t]=i==4?2:i,i&7&&(r=i),n=i}for(let e=o,t=c,r=c;e<s;e++){let i=L[e];if(i==128)e<s-1&&t==L[e+1]&&t&24?i=L[e]=t:L[e]=256;else if(i==64){let i=e+1;for(;i<s&&L[i]==64;)i++;let a=e&&t==8||i<n&&L[i]==8?r==1?1:8:256;for(let t=e;t<i;t++)L[t]=a;e=i-1}else i==8&&r==1&&(L[e]=1);t=i,i&7&&(r=i)}}}function gr(e,t,n,r,i){let a=i==1?2:1;for(let o=0,s=0,c=0;o<=r.length;o++){let l=o?r[o-1].to:t,u=o<r.length?r[o].from:n;for(let t=l,n,r,o;t<u;t++)if(r=lr[n=e.charCodeAt(t)]){if(r<0){for(let e=s-3;e>=0;e-=3)if(ur[e+1]==-r){let n=ur[e+2],r=n&2?i:n&4?n&1?a:i:0;r&&(L[t]=L[ur[e]]=r),s=e;break}}else if(ur.length==189)break;else ur[s++]=t,ur[s++]=n,ur[s++]=c}else if((o=L[t])==2||o==1){let e=o==i;c=+!e;for(let t=s-3;t>=0;t-=3){let n=ur[t+2];if(n&2)break;if(e)ur[t+2]|=2;else{if(n&4)break;ur[t+2]|=4}}}}}function _r(e,t,n,r){for(let i=0,a=r;i<=n.length;i++){let o=i?n[i-1].to:e,s=i<n.length?n[i].from:t;for(let c=o;c<s;){let o=L[c];if(o==256){let o=c+1;for(;;)if(o==s){if(i==n.length)break;o=n[i++].to,s=i<n.length?n[i].from:t}else if(L[o]==256)o++;else break;let l=a==1,u=l==((o<t?L[o]:r)==1)?l?1:2:r;for(let t=o,r=i,a=r?n[r-1].to:e;t>c;)t==a&&(t=n[--r].from,a=r?n[r-1].to:e),L[--t]=u;c=o}else a=o,c++}}}function vr(e,t,n,r,i,a,o){let s=r%2?2:1;if(r%2==i%2)for(let c=t,l=0;c<n;){let t=!0,u=!1;if(l==a.length||c<a[l].from){let e=L[c];e!=s&&(t=!1,u=e==16)}let d=!t&&s==1?[]:null,f=t?r:r+1,p=c;run:for(;;)if(l<a.length&&p==a[l].from){if(u)break run;let m=a[l];if(!t)for(let e=m.to,t=l+1;;){if(e==n)break run;if(t<a.length&&a[t].from==e)e=a[t++].to;else if(L[e]==s)break run;else break}l++,d?d.push(m):(m.from>c&&o.push(new pr(c,m.from,f)),yr(e,m.direction==ir==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.to),p=m.to}else if(p==n||(t?L[p]!=s:L[p]==s))break;else p++;d?vr(e,c,p,r+1,i,d,o):c<p&&o.push(new pr(c,p,f)),c=p}else for(let c=n,l=a.length;c>t;){let n=!0,u=!1;if(!l||c>a[l-1].to){let e=L[c-1];e!=s&&(n=!1,u=e==16)}let d=!n&&s==1?[]:null,f=n?r:r+1,p=c;run:for(;;)if(l&&p==a[l-1].to){if(u)break run;let m=a[--l];if(!n)for(let e=m.from,n=l;;){if(e==t)break run;if(n&&a[n-1].to==e)e=a[--n].from;else if(L[e-1]==s)break run;else break}d?d.push(m):(m.to<c&&o.push(new pr(m.to,c,f)),yr(e,m.direction==ir==!(f%2)?r:r+1,i,m.inner,m.from,m.to,o),c=m.from),p=m.from}else if(p==t||(n?L[p-1]!=s:L[p-1]==s))break;else p--;d?vr(e,p,c,r+1,i,d,o):p<c&&o.push(new pr(p,c,f)),c=p}}function yr(e,t,n,r,i,a,o){let s=t%2?2:1;hr(e,i,a,r,s),gr(e,i,a,r,s),_r(i,a,r,s),vr(e,i,a,t,n,r,o)}function br(e,t,n){if(!e)return[new pr(0,0,+(t==ar))];if(t==ir&&!n.length&&!fr.test(e))return xr(e.length);if(n.length)for(;e.length>L.length;)L[L.length]=256;let r=[],i=t==ir?0:1;return yr(e,i,i,n,0,e.length,r),r}function xr(e){return[new pr(0,e,0)]}var Sr=``;function Cr(e,t,n,r,i){if(!e.length)return null;let a=r.head-e.from,o;if(r.head==e.from&&r.assoc<0){if(!i)return null;a=t[o=0].side(!1,n)}else if(r.head==e.to&&r.assoc>0){if(i)return null;a=t[o=t.length-1].side(!0,n)}else o=pr.find(t,a,r.bidiLevel??-1,r.assoc);let s=t[o],c=s.side(i,n);if(a==c){let e=o+=i?1:-1;if(e<0||e>=t.length)return null;s=t[o=e],a=s.side(!i,n),c=s.side(i,n)}let l=ie(e.text,a,s.forward(i,n));(l<s.from||l>s.to)&&(l=c),Sr=e.text.slice(Math.min(a,l),Math.max(a,l));let u=o==(i?t.length-1:0)?null:t[o+(i?1:-1)];if(l==c){if(!u)return i?O.cursor(e.to,1):O.cursor(e.from,-1);if(u.level+ +!i<s.level)return O.cursor(u.side(!i,n)+e.from,u.forward(i,n)?1:-1,u.level)}return O.cursor(l+e.from,s.forward(i,n)?-1:1,s.level)}function wr(e,t,n){for(let r=t;r<n;r++){let t=dr(e.charCodeAt(r));if(t==1)return ir;if(t==2||t==4)return ar}}var Tr=k.define(),Er=k.define(),Dr=k.define(),Or=k.define(),kr=k.define(),Ar=k.define(),jr=k.define(),Mr=k.define(),Nr=k.define(),Pr=k.define({combine:e=>e.some(e=>e)}),Fr=k.define({combine:e=>e.some(e=>e)}),Ir=k.define(),Lr=class e{constructor(e,t,n,r,i,a=!1){this.range=e,this.y=t,this.x=n,this.yMargin=r,this.xMargin=i,this.isSnapshot=a}map(t){return t.empty?this:new e(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 e(O.cursor(t.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}},Rr=A.define({map:(e,t)=>e.map(t)}),zr=A.define();function Br(e,t,n){let r=e.facet(Or);r.length?r[0](t):window.onerror&&window.onerror(String(t),n,void 0,void 0,t)||(n?console.error(n+`:`,t):console.error(t))}var Vr=k.define({combine:e=>!e.length||e[0]}),Hr=0,Ur=k.define({combine(e){return e.filter((t,n)=>{for(let r=0;r<n;r++)if(e[r].plugin==t.plugin)return!1;return!0})}}),Wr=class e{constructor(e,t,n,r,i){this.id=e,this.create=t,this.domEventHandlers=n,this.domEventObservers=r,this.baseExtensions=i(this),this.extension=this.baseExtensions.concat(Ur.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Ur.of({plugin:this,arg:e}))}static define(t,n){let{eventHandlers:r,eventObservers:i,provide:a,decorations:o}=n||{};return new e(Hr++,t,r,i,e=>{let t=[];return o&&t.push(Jr.of(t=>{let n=t.plugin(e);return n?o(n):F.none})),a&&t.push(a(e)),t})}static fromClass(t,n){return e.define((e,n)=>new t(e,n),n)}},Gr=class{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(!this.value){if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Br(e.state,t,`CodeMirror plugin crashed`),this.deactivate()}}else if(this.mustUpdate){let e=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(e)}catch(t){if(Br(e.state,t,`CodeMirror plugin crashed`),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}return this}destroy(e){if(this.value?.destroy)try{this.value.destroy()}catch(t){Br(e.state,t,`CodeMirror plugin crashed`)}}deactivate(){this.spec=this.value=null}},Kr=k.define(),qr=k.define(),Jr=k.define(),Yr=k.define(),Xr=k.define(),Zr=k.define(),Qr=k.define();function $r(e,t){let n=e.state.facet(Qr);if(!n.length)return n;let r=n.map(t=>t instanceof Function?t(e):t),i=[];return M.spans(r,t.from,t.to,{point(){},span(e,n,r,a){let o=e-t.from,s=n-t.from,c=i;for(let e=r.length-1;e>=0;e--,a--){let t=r[e].spec.bidiIsolate,n;if(a>0&&c.length&&(n=c[c.length-1]).to==o&&n.direction==t)n.to=s,c=n.inner;else{let e={from:o,to:s,direction:t,inner:[]};c.push(e),c=e.inner}}}}),ei(t.text,i)}function ei(e,t){for(let n of t){if(n.direction==null){for(let t=n.from,r=0;t<n.to;r++){let i=r<n.inner.length?n.inner[r]:null,a=wr(e,t,i?i.from:n.to);if(a){n.direction=a;break}if(!i)break;t=i.to}n.direction??=rr.LTR}ei(e,n.inner)}return t}var ti=k.define();function ni(e){let t=0,n=0,r=0,i=0;for(let a of e.state.facet(ti)){let o=a(e);o&&(o.left!=null&&(t=Math.max(t,o.left)),o.right!=null&&(n=Math.max(n,o.right)),o.top!=null&&(r=Math.max(r,o.top)),o.bottom!=null&&(i=Math.max(i,o.bottom)))}return{left:t,right:n,top:r,bottom:i}}var ri=k.define(),ii=class e{constructor(e,t,n,r){this.fromA=e,this.toA=t,this.fromB=n,this.toB=r}join(t){return new e(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(e){let t=e.length,n=this;for(;t>0;t--){let r=e[t-1];if(!(r.fromA>n.toA)){if(r.toA<n.fromA)break;n=n.join(r),e.splice(t-1,1)}}return e.splice(t,0,n),e}static extendWithRanges(t,n){if(n.length==0)return t;let r=[];for(let i=0,a=0,o=0;;){let s=i<t.length?t[i].fromB:1e9,c=a<n.length?n[a]:1e9,l=Math.min(s,c);if(l==1e9)break;let u=l+o,d=l,f=u;for(;;)if(a<n.length&&n[a]<=d){let e=n[a+1];a+=2,d=Math.max(d,e);for(let e=i;e<t.length&&t[e].fromB<=d;e++)o=t[e].toA-t[e].toB;f=Math.max(f,e+o)}else if(i<t.length&&t[i].fromB<=d){let e=t[i++];d=Math.max(d,e.toB),f=Math.max(f,e.toA),o=e.toA-e.toB}else break;r.push(new e(u,f,l,d))}return r}},ai=class e{constructor(e,t,n){this.view=e,this.state=t,this.transactions=n,this.flags=0,this.startState=e.state,this.changes=pe.empty(this.startState.doc.length);for(let e of n)this.changes=this.changes.compose(e.changes);let r=[];this.changes.iterChangedRanges((e,t,n,i)=>r.push(new ii(e,t,n,i))),this.changedRanges=r}static create(t,n,r){return new e(t,n,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}},oi=[],R=class{constructor(e,t,n=0){this.dom=e,this.length=t,this.flags=n,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return oi}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let e=this.domAttrs;e&&gn(this.dom,e)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:``)+(this.breakAfter?`#`:``)}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let n=t;for(let t of this.children){if(t==e)return n;n+=t.length+t.breakAfter}throw RangeError(`Invalid child in posBefore`)}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t,n){return null}domPosFor(e,t){let n=Pn(this.dom),r=this.length?e>0:t>0;return new nr(this.parent.dom,n+ +!!r,e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof li)return e;return null}static get(e){return e.cmTile}},si=class extends R{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,n=null,r,i=e?.node==t?e:null,a=0;for(let o of this.children){if(o.sync(e),a+=o.length+o.breakAfter,r=n?n.nextSibling:t.firstChild,i&&r!=o.dom&&(i.written=!0),o.dom.parentNode==t)for(;r&&r!=o.dom;)r=ci(r);else t.insertBefore(o.dom,r);n=o.dom}for(r=n?n.nextSibling:t.firstChild,i&&r&&(i.written=!0);r;)r=ci(r);this.length=a}};function ci(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var li=class extends si{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=R.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],n=this,r=0,i=0;;)if(r==n.children.length){if(!t.length)return;n=n.parent,n.breakAfter&&i++,r=t.pop()}else{let a=n.children[r++];if(a instanceof ui)t.push(r),n=a,r=0;else{let t=i+a.length,n=e(a,i);if(n!==void 0)return n;i=t+a.breakAfter}}}resolveBlock(e,t){let n,r=-1,i,a=-1;if(this.blockTiles((o,s)=>{let c=s+o.length;if(e>=s&&e<=c){if(o.isWidget()&&t>=-1&&t<=1){if(o.flags&32)return!0;o.flags&16&&(n=void 0)}(s<e||e==c&&(t<-1?o.length:o.covers(1)))&&(!n||!o.isWidget()&&n.isWidget())&&(n=o,r=e-s),(c>e||e==s&&(t>1?o.length:o.covers(-1)))&&(!i||!o.isWidget()&&i.isWidget())&&(i=o,a=e-s)}}),!n&&!i)throw Error(`No tile at position `+e);return n&&t<0||!i?{tile:n,offset:r}:{tile:i,offset:a}}},ui=class e extends si{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(t,n){let r=new e(n||document.createElement(t.tagName),t);return n||(r.flags|=4),r}},di=class e extends si{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(t,n,r){let i=new e(n||document.createElement(`div`),t);return n&&r||(i.flags|=4),i}get domAttrs(){return this.attrs}resolveInline(e,t,n=!1){let r=null,i=-1,a=null,o=-1;function s(e,c){for(let l=0,u=0;l<e.children.length&&u<=c;l++){let d=e.children[l],f=u+d.length;f>=c&&(d.isComposite()?s(d,c-u):(!a||n&&a.isHidden&&(t>0&&!(a.flags&32)||n&&pi(a,d)))&&(f>c||d.flags&32&&t<=1)?(a=d,o=c-u):(u<c||d.flags&16&&!(n&&d.isHidden)&&t>=-1)&&(r=d,i=c-u)),u=f}}s(this,e);let c=(t<0?r:a)||r||a;return c?{tile:c,offset:c==r?i:o}:null}coordsIn(e,t,n){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t,n):fi(this)}domIn(e,t){let n=this.resolveInline(e,t);if(n){let{tile:e,offset:r}=n;if(this.dom.contains(e.dom))return e.isText()?new nr(e.dom,Math.min(e.dom.nodeValue.length,r)):e.domPosFor(r,e.flags&16?1:e.flags&32?-1:t);let i=n.tile.parent,a=!1;for(let e of i.children){if(a)return new nr(e.dom,0);e==n.tile&&(a=!0)}}return new nr(this.dom,0)}};function fi(e){let t=e.dom.lastChild;if(!t)return e.dom.getBoundingClientRect();let n=Mn(t);return n[n.length-1]||null}function pi(e,t){let n=e.coordsIn(0,1),r=t.coordsIn(0,1);return n&&r&&r.top<n.bottom}var mi=class e extends si{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(t,n){let r=new e(n||document.createElement(t.tagName),t);return n||(r.flags|=4),r}},hi=class e extends R{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t,n){let r=this.dom.nodeValue.length;e>r&&(e=r);let i=e,a=e,o=0;e==0&&t<0||e==r&&t>=0?P.chrome||P.gecko||(e?(i--,o=1):a<r&&(a++,o=-1)):t<0?i--:a<r&&a++;let s=Yn(this.dom,i,a).getClientRects();if(!s.length)return null;let c=s[(o?o<0:t>=0)?0:s.length-1];return P.safari&&!o&&c.width==0&&(c=Array.prototype.find.call(s,e=>e.width)||c),n==null?c:Rn(c,(o?o>0:t<0)==n)}static of(t,n){let r=new e(n||document.createTextNode(t),t);return n||(r.flags|=2),r}},gi=class e extends R{constructor(e,t,n,r){super(e,t,r),this.widget=n}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,n){let r=this.widget.coordsAt(this.dom,e,t);if(r)return r;if(n)return Rn(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let t=this.dom.getClientRects(),n=null;if(!t.length)return null;let r=this.flags&16?!0:this.flags&32?!1:e>0;for(let i=r?t.length-1:0;n=t[i],!(e>0?i==0:i==t.length-1||n.top<n.bottom);i+=r?-1:1);return Rn(n,!r)}}get overrideDOMText(){if(!this.length)return x.empty;let{root:e}=this;if(!e)return x.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(t,n,r,i,a){return a||(a=t.toDOM(n),t.editable||(a.contentEditable=`false`)),new e(a,r,t,i)}},_i=class extends R{constructor(e){let t=document.createElement(`img`);t.className=`cm-widgetBuffer`,t.setAttribute(`aria-hidden`,`true`),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return x.empty}coordsIn(e,t,n){let r=this.dom.getBoundingClientRect();return n==null?r:Rn(r,t>0==n)}},vi=class{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,n){let{tile:r,index:i,beforeBreak:a,parents:o}=this;for(;e||t>0;)if(!r.isComposite()){let t=r.length;if(i<t&&e){let a=Math.min(e,t-i);n&&n.skip(r,i,i+a),e-=a,i+=a}if(i==t)a=!!r.breakAfter,{tile:r,index:i}=o.pop(),i++;else if(!e)break}else if(a){if(!e)break;n&&n.break(),e--,a=!1}else if(i==r.children.length){if(!e&&!o.length)break;n&&n.leave(r),a=!!r.breakAfter,{tile:r,index:i}=o.pop(),i++}else{let s=r.children[i],c=s.breakAfter;(t>0?s.length<=e:s.length<e)&&(!n||n.skip(s,0,s.length)!==!1||!s.isComposite)?(a=!!c,i++,e-=s.length):(o.push({tile:r,index:i}),r=s,i=0,n&&s.isComposite()&&n.enter(s))}return this.tile=r,this.index=i,this.beforeBreak=a,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}},yi=class{constructor(e,t,n,r){this.from=e,this.to=t,this.wrapper=n,this.rank=r}},bi=class{constructor(e,t,n){this.cache=e,this.root=t,this.blockWrappers=n,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,n,r){this.flushBuffer();let i=this.ensureMarks(t,n),a=i.lastChild;if(a&&a.isText()&&!(a.flags&8)&&a.length+e.length<512){this.cache.reused.set(a,2);let t=i.children[i.children.length-1]=new hi(a.dom,a.text+e);t.parent=i}else i.append(r||hi.of(e,this.cache.find(hi)?.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let n=this.curLine;n.dom!=t.line.dom&&(n.setDOM(this.cache.reused.has(t.line)?Ai(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let r=n;for(let e=t.marks.length-1;e>=0;e--){let n=t.marks[e],i=r.lastChild;if(i instanceof mi&&i.mark.eq(n.mark))i.dom!=n.dom&&i.setDOM(Ai(n.dom)),r=i;else{let{dom:e}=n;this.cache.reused.get(n)&&R.get(n.dom)&&(e=Ai(n.dom));let t=mi.of(n.mark,e);r.append(t),r=t}this.cache.reused.set(n,2)}let i=R.get(e.text);i&&this.cache.reused.set(i,2);let a=new hi(e.text,e.text.nodeValue);a.flags|=8,this.pos=e.range.toB,r.append(a)}addInlineWidget(e,t,n){let r=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);r||this.flushBuffer();let i=this.ensureMarks(t,n);!r&&!(e.flags&16)&&i.append(this.getBuffer(1)),i.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,n){this.flushBuffer(),this.ensureMarks(t,n).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){e||=Di;let n=di.start(e,t||this.cache.find(di)?.dom,!!t);this.getBlockPos().append(this.lastBlock=this.curLine=n)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){let n=this.curLine;for(let r=e.length-1;r>=0;r--){let i=e[r],a;if(t>0&&(a=n.lastChild)&&a instanceof mi&&a.mark.eq(i))n=a,t--;else{let e=mi.of(i,this.cache.find(mi,e=>e.mark.eq(i))?.dom);n.append(e),n=e,t=0}}return n}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Ti(this.curLine,!1)||e.dom.nodeName!=`BR`&&e.isWidget()&&!(P.ios&&Ti(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(Mi,0,32)||new gi(Mi.toDOM(),0,Mi,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,n=new yi(e.from,e.to,e.value,t),r=this.wrappers.length;for(;r>0&&(this.wrappers[r-1].rank-n.rank||this.wrappers[r-1].to-n.to)<0;)r--;this.wrappers.splice(r,0,n)}this.wrapperPos=this.pos}getBlockPos(){this.updateBlockWrappers();let e=this.root;for(let t of this.wrappers){let n=e.lastChild;if(t.from<this.pos&&n instanceof ui&&n.wrapper.eq(t.wrapper))e=n;else{let n=ui.of(t.wrapper,this.cache.find(ui,e=>e.wrapper.eq(t.wrapper))?.dom);e.append(n),e=n}}return e}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),n=this.cache.find(_i,void 0,1);return n&&(n.flags=t),n||new _i(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}},xi=class{constructor(e){this.skipCount=0,this.text=``,this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text=``,this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:t,lineBreak:n,done:r}=this.cursor.next(this.skipCount);if(this.skipCount=0,r)throw Error(`Ran out of text content when drawing inline views`);this.text=t;let i=this.textOff=Math.min(e,t.length);return n?null:t.slice(0,i)}let t=Math.min(this.text.length,this.textOff+e),n=this.text.slice(this.textOff,t);return this.textOff=t,n}},Si=[gi,di,hi,mi,_i,ui,li];for(let e=0;e<Si.length;e++)Si[e].bucket=e;var Ci=class{constructor(e){this.view=e,this.buckets=Si.map(()=>[]),this.index=Si.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,n=this.buckets[t];n.length<6?n.push(e):n[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,n=2){let r=e.bucket,i=this.buckets[r],a=this.index[r];for(let e=0;e<i.length;e++){let o=(e+a)%i.length,s=i[o];if((!t||t(s))&&!this.reused.has(s))return i.splice(o,1),o<a&&this.index[r]--,this.reused.set(s,n),s}return null}findWidget(e,t,n){let r=this.buckets[0];if(r.length)for(let i=0,a=0;;i++){if(i==r.length){if(a)return null;a=1,i=0}let o=r[i];if(!this.reused.has(o)&&(a==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return r.splice(i,1),i<this.index[0]&&this.index[0]--,o.widget==e&&o.length==t&&(o.flags&497)==n?(this.reused.set(o,1),o):(this.reused.set(o,2),new gi(o.dom,t,e,o.flags&-498|n))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}},wi=class{constructor(e,t,n,r,i){this.view=e,this.decorations=r,this.disallowBlockEffectsFor=i,this.openWidget=!1,this.openMarks=0,this.cache=new Ci(e),this.text=new xi(e.state.doc),this.builder=new bi(this.cache,new li(e,e.contentDOM),M.iter(n)),this.cache.reused.set(t,2),this.old=new vi(t),this.reuseWalker={skip:(e,t,n)=>{if(this.cache.add(e),e.isComposite())return!1},enter:e=>this.cache.add(e),leave:()=>{},break:()=>{}}}run(e,t){let n=t&&this.getCompositionContext(t.text);for(let r=0,i=0,a=0;;){let o=a<e.length?e[a++]:null,s=o?o.fromA:this.old.root.length;if(s>r){let e=s-r;this.preserve(e,!a,!o),r=s,i+=e}if(!o)break;t&&o.fromA<=t.range.fromA&&o.toA>=t.range.toA?(this.forward(o.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(i,t.range.fromB),this.builder.flushBuffer(),this.cache.clear(),this.builder.addComposition(t,n),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,o.toA),this.emit(t.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(i,o.toB)),i=o.toB,r=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,n){let r=ki(this.old),i=this.openMarks;this.old.advance(e,n?1:-1,{skip:(e,t,n)=>{if(e.isWidget()){if(this.openWidget)this.builder.continueWidget(n-t);else{let a=n>0||t<e.length?gi.of(e.widget,this.view,n-t,e.flags&496,this.cache.maybeReuse(e)):this.cache.reuse(e);a.flags&256?(a.flags&=-2,this.builder.addBlockWidget(a)):(this.builder.ensureLine(null),this.builder.addInlineWidget(a,r,i),i=r.length)}}else if(e.isText())this.builder.ensureLine(null),!t&&n==e.length&&!this.cache.reused.has(e)?this.builder.addText(e.text,r,i,this.cache.reuse(e)):(this.cache.add(e),this.builder.addText(e.text.slice(t,n),r,i)),i=r.length;else if(e.isLine())e.flags&=-2,this.cache.reused.set(e,1),this.builder.addLine(e);else if(e instanceof _i)this.cache.add(e);else if(e instanceof mi)this.builder.ensureLine(null),this.builder.addMark(e,r,i),this.cache.reused.set(e,1),i=r.length;else return!1;this.openWidget=!1},enter:e=>{e.isLine()?this.builder.addLineStart(e.attrs,this.cache.maybeReuse(e)):(this.cache.add(e),e instanceof mi&&r.unshift(e.mark)),this.openWidget=!1},leave:e=>{e.isLine()?r.length&&=i=0:e instanceof mi&&(r.shift(),i=Math.min(i,r.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let n=null,r=this.builder,i=-1,a=M.spans(this.decorations,e,t,{point:(e,t,a,o,s,c)=>{if(a instanceof Cn){if(this.disallowBlockEffectsFor[c]){if(a.block)throw RangeError(`Block decorations may not be specified via plugins`);if(t>this.view.state.doc.lineAt(e).to)throw RangeError(`Decorations that replace line breaks may not be specified via plugins`)}if(i=o.length,s>o.length)r.continueWidget(t-e);else{let i=a.widget||(a.block?ji.block:ji.inline),c=Ei(a),l=this.cache.findWidget(i,t-e,c)||gi.of(i,this.view,t-e,c);a.block?(a.startSide>0&&r.addLineStartIfNotCovered(n),r.addBlockWidget(l)):(r.ensureLine(n),r.addInlineWidget(l,o,s))}n=null}else n=Oi(n,a);t>e&&this.text.skip(t-e)},span:(e,t,a,o)=>{for(let i=e;i<t;){let s=this.text.next(Math.min(512,t-i));s==null?(r.addLineStartIfNotCovered(n),r.addBreak(),i++):(r.ensureLine(n),r.addText(s,a,i==e?o:a.length),i+=s.length),n=null}i=a.length}});i>-1&&(this.openWidget=a>i),this.openWidget||r.addLineStartIfNotCovered(n),this.openMarks=a}forward(e,t,n=1){t-e<=10?this.old.advance(t-e,n,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,n,this.reuseWalker))}getCompositionContext(e){let t=[],n=null;for(let r=e.parentNode;;r=r.parentNode){let e=R.get(r);if(r==this.view.contentDOM)break;e instanceof mi?t.push(e):e?.isLine()?n=e:e instanceof ui||(r.nodeName==`DIV`&&!n?n=new di(r,Di):n||t.push(mi.of(new xn({tagName:r.nodeName.toLowerCase(),attributes:vn(r)}),r)))}return n?{line:n,marks:t}:null}};function Ti(e,t){let n=e=>{for(let r of e.children)if((t?r.isText():r.length)||n(r))return!0;return!1};return n(e)}function Ei(e){let t=e.isReplace?(e.startSide<0?64:0)|(e.endSide>0?128:0):e.startSide>0?32:16;return e.block&&(t|=256),t}var Di={class:`cm-line`};function Oi(e,t){let n=t.spec.attributes,r=t.spec.class;return!n&&!r||(e||={class:`cm-line`},n&&pn(n,e),r&&(e.class+=` `+r)),e}function ki(e){let t=[];for(let n=e.parents.length;n>1;n--){let r=n==e.parents.length?e.tile:e.parents[n].tile;r instanceof mi&&t.push(r.mark)}return t}function Ai(e){let t=R.get(e);return t&&t.setDOM(e.cloneNode()),e}var ji=class extends yn{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}};ji.inline=new ji(`span`),ji.block=new ji(`div`);var Mi=new class extends yn{toDOM(){return document.createElement(`br`)}get isHidden(){return!0}get editable(){return!0}},Ni=class{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=F.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new li(e,e.contentDOM),this.updateInner([new ii(0,0,0,e.state.doc.length)],null)}update(e){let t=e.changedRanges;this.minWidth>0&&t.length&&(t.every(({fromA:e,toA:t})=>t<this.minWidthFrom||e>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let n=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(this.domChanged?.newSel?n=this.domChanged.newSel.head:!Wi(e.changes,this.hasComposition)&&!e.selectionSet&&(n=e.state.selection.main.head));let r=n>-1?Li(this.view,e.changes,n):null;if(this.domChanged=null,this.hasComposition){let{from:n,to:r}=this.hasComposition;t=new ii(n,r,e.changes.mapPos(n,-1),e.changes.mapPos(r,1)).addToSet(t.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(P.ie||P.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let i=this.decorations,a=this.blockWrappers;this.updateDeco();let o=Bi(i,this.decorations,e.changes);o.length&&(t=ii.extendWithRanges(t,o));let s=Hi(a,this.blockWrappers,e.changes);return s.length&&(t=ii.extendWithRanges(t,s)),r&&!t.some(e=>e.fromA<=r.range.fromA&&e.toA>=r.range.toA)&&(t=r.range.addToSet(t.slice())),this.tile.flags&2&&t.length==0?!1:(this.updateInner(t,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:n}=this.view;n.ignore(()=>{if(t||e.length){let n=this.tile,r=new wi(this.view,n,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&R.get(t.text)&&r.cache.reused.set(R.get(t.text),2),this.tile=r.run(e,t),Pi(n,r.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+`px`,this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+`px`:``;let r=P.chrome||P.ios?{node:n.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||n.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=``});let r=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let e of this.tile.children)e.isWidget()&&e.widget instanceof Gi&&r.push(e.dom);n.updateGaps(r)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let e of t.effects)e.is(zr)&&(this.editContextFormatting=e.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:n}=this.tile,r=this.view.root.activeElement,i=r==n,a=!i&&!(this.view.state.facet(Vr)||n.tabIndex>-1)&&jn(n,this.view.observer.selectionRange)&&!(r&&n.contains(r));if(!(i||t||a))return;let o=this.forceSelection;this.forceSelection=!1;let s=this.view.state.selection.main,c,l;if(s.empty?l=c=this.inlineDOMNearPos(s.anchor,s.assoc||1):(l=this.inlineDOMNearPos(s.head,s.head==s.from?1:-1),c=this.inlineDOMNearPos(s.anchor,s.anchor==s.from?1:-1)),P.gecko&&s.empty&&!this.hasComposition&&Fi(c)){let e=document.createTextNode(``);this.view.observer.ignore(()=>c.node.insertBefore(e,c.node.childNodes[c.offset]||null)),c=l=new nr(e,0),o=!0}let u=this.view.observer.selectionRange;!o&&u.focusNode&&(Nn(c.node,c.offset,u.anchorNode,u.anchorOffset)&&Nn(l.node,l.offset,u.focusNode,u.focusOffset)||this.suppressWidgetCursorChange(u,s))||(this.view.observer.ignore(()=>{P.android&&P.chrome&&n.contains(u.focusNode)&&Ui(u.focusNode,n)&&(n.blur(),n.focus({preventScroll:!0}));let e=kn(this.view.root);if(e){if(s.empty){if(P.gecko){let e=Ri(c.node,c.offset);if(e&&e!=3){let t=(e==1?er:tr)(c.node,c.offset);t&&(c=new nr(t.node,t.offset))}}e.collapse(c.node,c.offset),s.bidiLevel!=null&&e.caretBidiLevel!==void 0&&(e.caretBidiLevel=s.bidiLevel)}else if(e.extend){e.collapse(c.node,c.offset);try{e.extend(l.node,l.offset)}catch{}}else{let t=document.createRange();s.anchor>s.head&&([c,l]=[l,c]),t.setEnd(l.node,l.offset),t.setStart(c.node,c.offset),e.removeAllRanges(),e.addRange(t)}}a&&this.view.root.activeElement==n&&(n.blur(),r&&r.focus())}),this.view.observer.setSelectionRange(c,l)),this.impreciseAnchor=c.precise?null:new nr(u.anchorNode,u.anchorOffset),this.impreciseHead=l.precise?null:new nr(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Nn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,n=kn(e.root),{anchorNode:r,anchorOffset:i}=e.observer.selectionRange;if(!n||!t.empty||!t.assoc||!n.modify)return;let a=this.lineAt(t.head,t.assoc);if(!a)return;let o=a.posAtStart;if(t.head==o||t.head==o+a.length)return;let s=this.coordsAt(t.head,-1),c=this.coordsAt(t.head,1);if(!s||!c||s.bottom>c.top)return;let l=this.domAtPos(t.head+t.assoc,t.assoc);n.collapse(l.node,l.offset),n.modify(`move`,t.assoc<0?`forward`:`backward`,`lineboundary`),e.observer.readSelectionRange();let u=e.observer.selectionRange;e.docView.posFromDOM(u.anchorNode,u.anchorOffset)!=t.from&&n.collapse(r,i)}posFromDOM(e,t){let n=this.tile.nearest(e);if(!n)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let r=n.posAtStart;if(n.isComposite()){let i;if(e==n.dom)i=n.dom.childNodes[t];else{let r=Ln(e)==0?0:t==0?-1:1;for(;;){let t=e.parentNode;if(t==n.dom)break;r==0&&t.firstChild!=t.lastChild&&(r=e==t.firstChild?-1:1),e=t}i=r<0?e:e.nextSibling}if(i==n.dom.firstChild)return r;for(;i&&!R.get(i);)i=i.nextSibling;if(!i)return r+n.length;for(let e=0,t=r;;e++){let r=n.children[e];if(r.dom==i)return t;t+=r.length+r.breakAfter}}else if(n.isText())return e==n.dom?r+t:r+(t?n.length:0);else return r}domAtPos(e,t){let{tile:n,offset:r}=this.tile.resolveBlock(e,t);return n.isWidget()?n.domPosFor(r,t):n.domIn(r,t)}inlineDOMNearPos(e,t){let n,r=-1,i=!1,a,o=-1,s=!1;return this.tile.blockTiles((t,c)=>{if(t.isWidget()){if(t.flags&32&&c>=e)return!0;t.flags&16&&(i=!0)}else{let l=c+t.length;if(c<=e&&(n=t,r=e-c,i=l<e),l>=e&&!a&&(a=t,o=e-c,s=c>e),c>e&&a)return!0}}),!n&&!a?this.domAtPos(e,t):(i&&a?n=null:s&&n&&(a=null),n&&t<0||!a?n.domIn(r,t):a.domIn(o,t))}coordsAt(e,t,n){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof Gi?null:r.coordsInWidget(i,t,!0):r.coordsIn(i,t,n)}lineAt(e,t){let{tile:n}=this.tile.resolveBlock(e,t);return n.isLine()?n:null}coordsForChar(e){let{tile:t,offset:n}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function r(e,t){if(e.isComposite())for(let n of e.children){if(n.length>=t){let e=r(n,t);if(e)return e}if(t-=n.length,t<0)break}else if(e.isText()&&t<e.length){let n=ie(e.text,t);if(n==t)return null;let r=Yn(e.dom,t,n).getClientRects();for(let e=0;e<r.length;e++){let t=r[e];if(e==r.length-1||t.top<t.bottom&&t.left<t.right)return t}}return null}return r(t,n)}measureVisibleLineHeights(e){let t=[],{from:n,to:r}=e,i=this.view.contentDOM.clientWidth,a=i>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,s=this.view.textDirection==rr.LTR,c=0,l=(e,u,d)=>{for(let f=0;f<e.children.length&&!(u>r);f++){let r=e.children[f],p=u+r.length,m=r.dom.getBoundingClientRect(),{height:h}=m;if(d&&!f&&(c+=m.top-d.top),r instanceof ui)p>n&&l(r,u,m);else if(u>=n&&(c>0&&t.push(-c),t.push(h+c),c=0,a)){let e=r.dom.lastChild,t=e?Mn(e):[];if(t.length){let e=t[t.length-1],n=s?e.right-m.left:m.right-e.left;n>o&&(o=n,this.minWidth=i,this.minWidthFrom=u,this.minWidthTo=p)}}d&&f==e.children.length-1&&(c+=d.bottom-m.bottom),u=p+r.breakAfter}};return l(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction==`rtl`?rr.RTL:rr.LTR}measureTextSize(){let e=this.tile.blockTiles(e=>{if(e.isLine()&&e.children.length&&e.length<=20){let t=0,n;for(let r of e.children){if(!r.isText()||/[^ -~]/.test(r.text))return;let e=Mn(r.dom);if(e.length!=1)return;t+=e[0].width,n=e[0].height}if(t)return{lineHeight:e.dom.getBoundingClientRect().height,charWidth:t/e.length,textHeight:n}}});if(e)return e;let t=document.createElement(`div`),n,r,i;return t.className=`cm-line`,t.style.width=`99999px`,t.style.position=`absolute`,t.textContent=`abc def ghi jkl mno pqr stu`,this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let e=Mn(t.firstChild)[0];n=t.getBoundingClientRect().height,r=e&&e.width?e.width/27:7,i=e&&e.height?e.height:n,t.remove()}),{lineHeight:n,charWidth:r,textHeight:i}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let n=0,r=0;;r++){let i=r==t.viewports.length?null:t.viewports[r],a=i?i.from-1:this.view.state.doc.length;if(a>n){let r=(t.lineBlockAt(a).bottom-t.lineBlockAt(n).top)/this.view.scaleY;e.push(F.replace({widget:new Gi(r),block:!0,inclusive:!0,isBlockGap:!0}).range(n,a))}if(!i)break;n=i.to+1}return F.set(e)}updateDeco(){let e=1,t=this.view.state.facet(Jr).map(t=>(this.dynamicDecorationMap[e++]=typeof t==`function`)?t(this.view):t),n=!1,r=this.view.state.facet(Xr).map((e,t)=>{let r=typeof e==`function`;return r&&(n=!0),r?e(this.view):e});for(r.length&&(this.dynamicDecorationMap[e++]=n,t.push(M.join(r))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(Yr).map(e=>typeof e==`function`?e(this.view):e)}scrollIntoView(e){if(e.isSnapshot){let t=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=t.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let t of this.view.state.facet(Ir))try{if(t(this.view,e.range,e))return!0}catch(e){Br(this.view.state,e,`scroll handler`)}let{range:t}=e,n=this.coordsAt(t.head,t.assoc||(t.head>t.anchor?-1:1)),r;if(!n)return;!t.empty&&(r=this.coordsAt(t.anchor,t.anchor>t.head?-1:1))&&(n={left:Math.min(n.left,r.left),top:Math.min(n.top,r.top),right:Math.max(n.right,r.right),bottom:Math.max(n.bottom,r.bottom)});let i=ni(this.view),a={left:n.left-i.left,top:n.top-i.top,right:n.right+i.right,bottom:n.bottom+i.bottom},{offsetWidth:o,offsetHeight:s}=this.view.scrollDOM;if(Vn(this.view.scrollDOM,a,t.head<t.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,o),-o),Math.max(Math.min(e.yMargin,s),-s),this.view.textDirection==rr.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(n.top>window.visualViewport.offsetTop+window.visualViewport.height||n.bottom<window.visualViewport.offsetTop)){let e=this.view.docView.lineAt(t.head,1);if(e){let t=Wn(e.dom);e.dom.scrollIntoView({block:`nearest`}),Gn(t,!1)}}}lineHasWidget(e){let t=e=>e.isWidget()||e.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){Pi(this.tile)}};function Pi(e,t){let n=t?.get(e);if(n!=1){n??e.destroy();for(let n of e.children)Pi(n,t)}}function Fi(e){return I(e.node)&&e.node.firstChild&&(e.offset==0||e.node.childNodes[e.offset-1].contentEditable==`false`)&&(e.offset==e.node.childNodes.length||e.node.childNodes[e.offset].contentEditable==`false`)}function Ii(e,t){let n=e.observer.selectionRange;if(!n.focusNode)return null;let r=er(n.focusNode,n.focusOffset),i=tr(n.focusNode,n.focusOffset),a=r||i;if(i&&r&&i.node!=r.node){let t=R.get(i.node);if(!t||t.isText()&&t.text!=i.node.nodeValue)a=i;else if(e.docView.lastCompositionAfterCursor){let e=R.get(r.node);!e||e.isText()&&e.text!=r.node.nodeValue||(a=i)}}if(e.docView.lastCompositionAfterCursor=a!=r,!a)return null;let o=t-a.offset;return{from:o,to:o+a.node.nodeValue.length,node:a.node}}function Li(e,t,n){let r=Ii(e,n);if(!r)return null;let{node:i,from:a,to:o}=r,s=i.nodeValue;if(/[\n\r]/.test(s)||e.state.doc.sliceString(r.from,r.to)!=s)return null;let c=t.invertedDesc;return{range:new ii(c.mapPos(a),c.mapPos(o),a,o),text:i}}function Ri(e,t){return I(e)?(t&&e.childNodes[t-1].contentEditable==`false`?1:0)|(t<e.childNodes.length&&e.childNodes[t].contentEditable==`false`?2:0):0}var zi=class{constructor(){this.changes=[]}compareRange(e,t){En(e,t,this.changes)}comparePoint(e,t){En(e,t,this.changes)}boundChange(e){En(e,e,this.changes)}};function Bi(e,t,n){let r=new zi;return M.compare(e,t,n,r),r.changes}var Vi=class{constructor(){this.changes=[]}compareRange(e,t){En(e,t,this.changes)}comparePoint(){}boundChange(e){En(e,e,this.changes)}};function Hi(e,t,n){let r=new Vi;return M.compare(e,t,n,r),r.changes}function Ui(e,t){for(let n=e;n&&n!=t;n=n.assignedSlot||n.parentNode)if(I(n)&&n.contentEditable==`false`)return!0;return!1}function Wi(e,t){let n=!1;return t&&e.iterChangedRanges((e,r)=>{e<t.to&&r>t.from&&(n=!0)}),n}var Gi=class extends yn{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement(`div`);return e.className=`cm-gap`,this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+`px`,!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}};function Ki(e,t,n=1){let r=e.charCategorizer(t),i=e.doc.lineAt(t),a=t-i.from;if(i.length==0)return O.cursor(t);a==0?n=1:a==i.length&&(n=-1);let o=a,s=a;n<0?o=ie(i.text,a,!1):s=ie(i.text,a);let c=r(i.text.slice(o,s));for(;o>0;){let e=ie(i.text,o,!1);if(r(i.text.slice(e,o))!=c)break;o=e}for(;s<i.length;){let e=ie(i.text,s);if(r(i.text.slice(s,e))!=c)break;s=e}return O.undirectionalRange(o+i.from,s+i.from)}function qi(e,t,n,r,i){let a=Math.round((r-t.left)*e.defaultCharacterWidth);if(e.lineWrapping&&n.height>e.defaultLineHeight*1.5){let t=e.viewState.heightOracle.textHeight,r=Math.floor((i-n.top-(e.defaultLineHeight-t)*.5)/t);a+=r*e.viewState.heightOracle.lineLength}let o=e.state.sliceDoc(n.from,n.to);return n.from+Ot(o,a,e.state.tabSize)}function Ji(e,t,n){let r=e.lineBlockAt(t);if(Array.isArray(r.type)){let e;for(let i of r.type){if(i.from>t)break;if(!(i.to<t)){if(i.from<t&&i.to>t)return i;(!e||i.type==bn.Text&&(e.type!=i.type||(n<0?i.from<t:i.to>t)))&&(e=i)}}return e||r}return r}function Yi(e,t,n,r){let i=Ji(e,t.head,t.assoc||-1),a=!r||i.type!=bn.Text||!(e.lineWrapping||i.widgetLineBreaks)?null:e.coordsAtPos(t.assoc<0&&t.head>i.from?t.head-1:t.head);if(a){let t=e.dom.getBoundingClientRect(),r=e.textDirectionAt(i.from),o=e.posAndSideAtCoords({x:n==(r==rr.LTR)?t.right-1:t.left+1,y:(a.top+a.bottom)/2});if(o)return O.cursor(o.pos,o.assoc)}return O.cursor(n?i.to:i.from,n?1:-1)}function Xi(e,t,n,r){let i=e.state.doc.lineAt(t.head),a=e.bidiSpans(i),o=e.textDirectionAt(i.from);for(let s=t,c=null;;){let t=Cr(i,a,o,s,n),l=Sr;if(!t){if(i.number==(n?e.state.doc.lines:1))return s;l=`
8
+ `,i=e.state.doc.line(i.number+(n?1:-1)),a=e.bidiSpans(i),t=n?O.cursor(i.from,-1):O.cursor(i.to,1)}if(!c){if(!r)return t;c=r(l)}else if(!c(l))return s;s=t}}function Zi(e,t,n){let r=e.state.charCategorizer(t),i=r(n);return e=>{let t=r(e);return i==at.Space&&(i=t),i==t}}function Qi(e,t,n,r){let i=t.head,a=n?1:-1;if(i==(n?e.state.doc.length:0))return O.cursor(i,t.assoc);let o=t.goalColumn,s,c=e.contentDOM.getBoundingClientRect(),l=e.coordsAtPos(i,t.assoc||((t.empty?n:t.head==t.from)?1:-1)),u=e.documentTop;if(l)o??=l.left-c.left,s=a<0?l.top:l.bottom;else{let t=e.viewState.lineBlockAt(i);o??=Math.min(c.right-c.left,e.defaultCharacterWidth*(i-t.from)),s=(a<0?t.top:t.bottom)+u}let d=c.left+o,f=e.viewState.heightOracle.textHeight>>1,p=r??f;for(let t=0;;t+=f){let r=s+(p+t)*a,i=ra(e,{x:d,y:r},!1,a);if(n?r>c.bottom:r<c.top)return O.cursor(i.pos,i.assoc);let l=e.coordsAtPos(i.pos,i.assoc),u=l?(l.top+l.bottom)/2:0;if(!l||(n?u>s:u<s))return O.cursor(i.pos,i.assoc,void 0,o)}}function $i(e,t,n){for(;;){let r=0;for(let i of e)i.between(t-1,t+1,(e,i,a)=>{if(t>e&&t<i){let a=r||n||(t-e<i-t?-1:1);t=a<0?e:i,r=a}});if(!r)return t}}function ea(e,t){let n=null;for(let r=0;r<t.ranges.length;r++){let i=t.ranges[r],a=null;if(i.empty){let t=$i(e,i.from,0);t!=i.from&&(a=O.cursor(t,-1))}else{let t=$i(e,i.from,-1),n=$i(e,i.to,1);(t!=i.from||n!=i.to)&&(a=i.undirectional?O.undirectionalRange(i.from,i.to):O.range(i.from==i.anchor?t:n,i.from==i.head?t:n))}a&&(n||=t.ranges.slice(),n[r]=a)}return n?O.create(n,t.mainIndex):t}function ta(e,t,n){let r=$i(e.state.facet(Zr).map(t=>t(e)),n.from,t.head>n.from?-1:1);return r==n.from?n:O.cursor(r,r<n.from?1:-1)}var na=class{constructor(e,t){this.pos=e,this.assoc=t}};function ra(e,t,n,r){let i=e.contentDOM.getBoundingClientRect(),a=i.top+e.viewState.paddingTop,{x:o,y:s}=t,c=s-a,l;for(;;){if(c<0)return new na(0,1);if(c>e.viewState.docHeight)return new na(e.state.doc.length,-1);if(l=e.elementAtHeight(c),r==null)break;if(l.type==bn.Text){if(r<0?l.to<e.viewport.from:l.from>e.viewport.to)break;let t=e.docView.coordsAt(r<0?l.from:l.to,r>0?-1:1);if(t&&(r<0?t.top<=c+a:t.bottom>=c+a))break}let t=e.viewState.heightOracle.textHeight/2;c=r>0?l.bottom+t:l.top-t}if(e.viewport.from>=l.to||e.viewport.to<=l.from){if(n)return null;if(l.type==bn.Text){let t=qi(e,i,l,o,s);return new na(t,t==l.from?1:-1)}}if(l.type!=bn.Text)return c<(l.top+l.bottom)/2?new na(l.from,1):new na(l.to,-1);let u=e.docView.lineAt(l.from,2);return u&&u.length==l.length||(u=e.docView.lineAt(l.from,-2)),new ia(e,o,s,e.textDirectionAt(l.from)).scanTile(u,l.from)}var ia=class{constructor(e,t,n,r){this.view=e,this.x=t,this.y=n,this.baseDir=r,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[pr.find(r,e-n.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:n,spans:r}=this.bidiSpansAt(e);return r[pr.find(r,e-n.from,-1,t)].dir}bidiIn(e,t){let{spans:n,line:r}=this.bidiSpansAt(e);return n.length>1||n.length&&(n[0].level!=this.baseDir||n[0].to+r.from<t)}scan(e,t,n=!1){let r=0,i=e.length-1,a=new Set,o=this.bidiIn(e[0],e[i]),s,c,l=-1,u=1e9,d;search:for(;r<i;){let n=i-r,f=r+i>>1;adjust:if(a.has(f)){for(let e=1;e<n;e++){let t=f+e;if(t>=i&&(t-=n),!a.has(t)){f=t;break adjust}}break search}a.add(f);let p=t(f),m=0;if(p)for(let e=0;e<p.length;e++){let t=p[e];if(!(t.width==0&&p.length>1)){if(t.bottom<this.y)(!s||s.bottom<t.bottom)&&(s=t),m=1;else if(t.top>this.y)(!c||c.top>t.top)&&(c=t),m=-1;else{let e=t.left>this.x?this.x-t.left:t.right<this.x?this.x-t.right:0,n=Math.abs(e);n<u&&(l=f,u=n,d=t),e&&(m=e<0==(this.baseDir==rr.LTR)?-1:1)}}}m==-1&&(!o||this.baseDirAt(e[f],1))?i=f:m==1&&(!o||this.baseDirAt(e[f+1],-1))&&(r=f+1)}if(!d){if(!c&&!s)return{i:0,after:!1};let n=s&&(!c||this.y-s.bottom<c.top-this.y)?s:c;return this.y=(n.top+n.bottom)/2,this.scan(e,t,!0)}if(u&&!n){let{top:n,bottom:r}=d;if(s&&s.bottom>(n+n+r)/3)return this.y=s.bottom-1,this.scan(e,t,!0);if(c&&c.top<(n+r+r)/3)return this.y=c.top+1,this.scan(e,t,!0)}let f=(o?this.dirAt(e[l],1):this.baseDir)==rr.LTR;return{i:l,after:this.x>(d.left+d.right)/2==f}}scanText(e,t){let n=[];for(let r=0;r<e.length;r=ie(e.text,r))n.push(t+r);n.push(t+e.length);let r=this.scan(n,r=>{let i=n[r]-t,a=n[r+1]-t;return Yn(e.dom,i,a).getClientRects()});return r.after?new na(n[r.i+1],-1):new na(n[r.i],1)}scanTile(e,t){if(!e.length)return new na(t,1);if(e.children.length==1){let n=e.children[0];if(n.isText())return this.scanText(n,t);if(n.isComposite())return this.scanTile(n,t)}let n=[t];for(let r=0,i=t;r<e.children.length;r++)n.push(i+=e.children[r].length);let r=this.scan(n,t=>{let n=e.children[t];return n.flags&48?null:(I(n.dom)?n.dom:Yn(n.dom,0,n.length)).getClientRects()}),i=e.children[r.i],a=n[r.i];return i.isText()?this.scanText(i,a):i.isComposite()?this.scanTile(i,a):r.after?new na(n[r.i+1],-1):new na(a,1)}},aa=`￿`,oa=class{constructor(e,t){this.points=e,this.view=t,this.text=``,this.lineSeparator=t.state.facet(j.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=aa}readRange(e,t){if(!e)return this;let n=e.parentNode;for(let r=e;;){this.findPointBefore(n,r);let e=this.text.length;this.readNode(r);let i=R.get(r),a=r.nextSibling;if(a==t){i?.breakAfter&&!a&&n!=this.view.contentDOM&&this.lineBreak();break}let o=R.get(a);(i&&o?i.breakAfter:(i?i.breakAfter:Fn(r))||Fn(a)&&(r.nodeName!=`BR`||i?.isWidget())&&this.text.length>e)&&!ca(a,t)&&this.lineBreak(),r=a}return this.findPointBefore(n,t),this}readTextNode(e){let t=e.nodeValue;for(let n of this.points)n.node==e&&(n.pos=this.text.length+Math.min(n.offset,t.length));for(let n=0,r=this.lineSeparator?null:/\r\n?|\n/g;;){let i=-1,a=1,o;if(this.lineSeparator?(i=t.indexOf(this.lineSeparator,n),a=this.lineSeparator.length):(o=r.exec(t))&&(i=o.index,a=o[0].length),this.append(t.slice(n,i<0?t.length:i)),i<0)break;if(this.lineBreak(),a>1)for(let t of this.points)t.node==e&&t.pos>this.text.length&&(t.pos-=a-1);n=i+a}}readNode(e){let t=R.get(e),n=t&&t.overrideDOMText;if(n!=null){this.findPointInside(e,n.length);for(let e=n.iter();!e.next().done;)e.lineBreak?this.lineBreak():this.append(e.value)}else On(e)?this.readTextNode(e):e.nodeName==`BR`?e.nextSibling&&this.lineBreak():I(e)&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let n of this.points)n.node==e&&e.childNodes[n.offset]==t&&(n.pos=this.text.length)}findPointInside(e,t){for(let n of this.points)(On(e)?n.node==e:e.contains(n.node))&&(n.pos=this.text.length+(sa(e,n.node,n.offset)?t:0))}};function sa(e,t,n){for(;;){if(!t||n<Ln(t))return!1;if(t==e)return!0;n=Pn(t)+1,t=t.parentNode}}function ca(e,t){let n;for(;e!=t&&e;e=e.nextSibling){let t=R.get(e);if(!t?.isWidget())return!1;t&&(n||=[]).push(t)}if(n){for(let e of n)if(e.overrideDOMText?.length)return!1}return!0}var la=class{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}},ua=class{constructor(e,t,n,r){this.typeOver=r,this.bounds=null,this.text=``,this.domChanged=t>-1;let{impreciseHead:i,impreciseAnchor:a}=e.docView,o=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=da(e.docView.tile,t,n,0))){let t=i||a?[]:ga(e),n=new oa(t,e);n.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=n.text,this.newSel=_a(t,this.bounds.from)}else{let t=e.observer.selectionRange,n=i&&i.node==t.focusNode&&i.offset==t.focusOffset||!An(e.contentDOM,t.focusNode)?o.main.head:e.docView.posFromDOM(t.focusNode,t.focusOffset),r=a&&a.node==t.anchorNode&&a.offset==t.anchorOffset||!An(e.contentDOM,t.anchorNode)?o.main.anchor:e.docView.posFromDOM(t.anchorNode,t.anchorOffset),s=e.viewport;if((P.ios||P.chrome)&&n!=r&&Math.min(n,r)<=o.main.from&&Math.max(n,r)>=o.main.to&&(s.from>0||s.to<e.state.doc.length)){let t=Math.min(n,r),i=Math.max(n,r),a=s.from-t,o=s.to-i;a!=0&&a!=1&&t!=0||o!=0&&o!=-1&&i!=e.state.doc.length||(n=0,r=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(O.range(r,n));else if(e.lineWrapping&&r==n&&!(o.main.empty&&o.main.head==n)&&e.inputState.lastTouchTime>Date.now()-100){let t=e.coordsAtPos(n,-1),r=0;t&&(r=e.inputState.lastTouchY<=t.bottom?-1:1),this.newSel=O.create([O.cursor(n,r)])}else this.newSel=O.single(r,n)}}};function da(e,t,n,r){if(e.isComposite()){let i=-1,a=-1,o=-1,s=-1;for(let c=0,l=r,u=r;c<e.children.length;c++){let r=e.children[c],d=l+r.length;if(l<t&&d>n)return da(r,t,n,l);if(d>=t&&i==-1&&(i=c,a=l),l>n&&r.dom.parentNode==e.dom){o=c,s=u;break}u=d,l=d+r.breakAfter}return{from:a,to:s<0?r+e.length:s,startDOM:(i?e.children[i-1].dom.nextSibling:null)||e.dom.firstChild,endDOM:o<e.children.length&&o>=0?e.children[o].dom:null}}return e.isText()?{from:r,to:r+e.length,startDOM:e.dom,endDOM:e.dom.nextSibling}:null}function fa(e,t){let n,{newSel:r}=t,{state:i}=e,a=i.selection.main,o=e.inputState.lastKeyTime>Date.now()-100?e.inputState.lastKeyCode:-1;if(t.bounds){let{from:e,to:r}=t.bounds,s=a.from,c=null;(o===8||P.android&&t.text.length<r-e)&&(s=a.to,c=`end`);let l=i.doc.sliceString(e,r,aa),u,d;!a.empty&&a.from>=e&&a.to<=r&&(t.typeOver||l!=t.text)&&l.slice(0,a.from-e)==t.text.slice(0,a.from-e)&&l.slice(a.to-e)==t.text.slice(u=t.text.length-(l.length-(a.to-e)))?n={from:a.from,to:a.to,insert:x.of(t.text.slice(a.from-e,u).split(aa))}:(d=ha(l,t.text,s-e,c))&&(P.chrome&&o==13&&d.toB==d.from+2&&t.text.slice(d.from,d.toB)==`￿￿`&&d.toB--,n={from:e+d.from,to:e+d.toA,insert:x.of(t.text.slice(d.from,d.toB).split(aa))})}else r&&(!e.hasFocus&&i.facet(Vr)||va(r,a))&&(r=null);if(!n&&!r)return!1;if((P.mac||P.android)&&n&&n.from==n.to&&n.from==a.head-1&&/^\. ?$/.test(n.insert.toString())&&e.contentDOM.getAttribute(`autocorrect`)==`off`?(r&&n.insert.length==2&&(r=O.single(r.main.anchor-1,r.main.head-1)),n={from:n.from,to:n.to,insert:x.of([n.insert.toString().replace(`.`,` `)])}):i.doc.lineAt(a.from).to<a.to&&e.docView.lineHasWidget(a.to)&&e.inputState.insertingTextAt>Date.now()-50?n={from:a.from,to:a.to,insert:i.toText(e.inputState.insertingText)}:P.chrome&&n&&n.from==n.to&&n.from==a.head&&n.insert.toString()==`
9
+ `&&e.lineWrapping&&(r&&=O.single(r.main.anchor-1,r.main.head-1),n={from:a.from,to:a.to,insert:x.of([` `])}),n)return pa(e,n,r,o);if(r&&!va(r,a)){let t=!1,n=`select`;return e.inputState.lastSelectionTime>Date.now()-50&&(e.inputState.lastSelectionOrigin==`select`&&(t=!0),n=e.inputState.lastSelectionOrigin,n==`select.pointer`&&(r=ea(i.facet(Zr).map(t=>t(e)),r))),e.dispatch({selection:r,scrollIntoView:t,userEvent:n}),!0}return!1}function pa(e,t,n,r=-1){if(P.ios&&e.inputState.flushIOSKey(t))return!0;let i=e.state.selection.main;if(P.android&&(t.to==i.to&&(t.from==i.from||t.from==i.from-1&&e.state.sliceDoc(t.from,i.from)==` `)&&t.insert.length==1&&t.insert.lines==2&&Xn(e.contentDOM,`Enter`,13)||(t.from==i.from-1&&t.to==i.to&&t.insert.length==0||r==8&&t.insert.length<t.to-t.from&&t.to>i.head)&&Xn(e.contentDOM,`Backspace`,8)||t.from==i.from&&t.to==i.to+1&&t.insert.length==0&&Xn(e.contentDOM,`Delete`,46)))return!0;let a=t.insert.toString();e.inputState.composing>=0&&e.inputState.composing++;let o,s=()=>o||=ma(e,t,n);return e.state.facet(Ar).some(n=>n(e,t.from,t.to,a,s))||e.dispatch(s()),!0}function ma(e,t,n){let r,i=e.state,a=i.selection.main,o=-1;if(t.from==t.to&&t.from<a.from||t.from>a.to){let n=t.from<a.from?-1:1,r=n<0?a.from:a.to,s=$i(i.facet(Zr).map(t=>t(e)),r,n);t.from==s&&(o=s)}if(o>-1)r={changes:t,selection:O.cursor(t.from+t.insert.length,-1)};else if(t.from>=a.from&&t.to<=a.to&&t.to-t.from>=(a.to-a.from)/3&&(!n||n.main.empty&&n.main.from==t.from+t.insert.length)&&e.inputState.composing<0){let n=a.from<t.from?i.sliceDoc(a.from,t.from):``,o=a.to>t.to?i.sliceDoc(t.to,a.to):``;r=i.replaceSelection(e.state.toText(n+t.insert.sliceString(0,void 0,e.state.lineBreak)+o))}else{let o=i.changes(t),s=n&&n.main.to<=o.newLength?n.main:void 0;if(i.selection.ranges.length>1&&(e.inputState.composing>=0||e.inputState.compositionPendingChange)&&t.to<=a.to+10&&t.to>=a.to-10){let c=e.state.sliceDoc(t.from,t.to),l,u=n&&Ii(e,n.main.head);if(u){let e=t.insert.length-(t.to-t.from);l={from:u.from,to:u.to-e}}else l=e.state.doc.lineAt(a.head);let d=a.to-t.to;r=i.changeByRange(n=>{if(n.from==a.from&&n.to==a.to)return{changes:o,range:s||n.map(o)};let r=n.to-d,u=r-c.length;if(e.state.sliceDoc(u,r)!=c||r>=l.from&&u<=l.to)return{range:n};let f=i.changes({from:u,to:r,insert:t.insert}),p=n.to-a.to;return{changes:f,range:s?O.range(Math.max(0,s.anchor+p),Math.max(0,s.head+p)):n.map(f)}})}else r={changes:o,selection:s&&i.selection.replaceRange(s)}}let s=`input.type`;return(e.composing||e.inputState.compositionPendingChange&&e.inputState.compositionEndedAt>Date.now()-50)&&(e.inputState.compositionPendingChange=!1,s+=`.compose`,e.inputState.compositionFirstChange&&(s+=`.start`,e.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:s,scrollIntoView:!0})}function ha(e,t,n,r){let i=Math.min(e.length,t.length),a=0;for(;a<i&&e.charCodeAt(a)==t.charCodeAt(a);)a++;if(a==i&&e.length==t.length)return null;let o=e.length,s=t.length;for(;o>0&&s>0&&e.charCodeAt(o-1)==t.charCodeAt(s-1);)o--,s--;if(r==`end`){let e=Math.max(0,a-Math.min(o,s));n-=o+e-a}if(o<a&&e.length<t.length){let e=n<=a&&n>=o?a-n:0;a-=e,s=a+(s-o),o=a}else if(s<a){let e=n<=a&&n>=s?a-n:0;a-=e,o=a+(o-s),s=a}return{from:a,toA:o,toB:s}}function ga(e){let t=[];if(e.root.activeElement!=e.contentDOM)return t;let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=e.observer.selectionRange;return n&&(t.push(new la(n,r)),(i!=n||a!=r)&&t.push(new la(i,a))),t}function _a(e,t){if(e.length==0)return null;let n=e[0].pos,r=e.length==2?e[1].pos:n;return n<0||r<0?null:n==r?O.create([O.cursor(r+t,-1)]):O.single(n+t,r+t)}function va(e,t){return t.head==e.main.head&&t.anchor==e.main.anchor}var ya=class{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.touchActive=!1,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.lastIOSMomentumScroll=0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText=``,this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,P.safari&&e.contentDOM.addEventListener(`input`,()=>null),P.gecko&&no(e.contentDOM.ownerDocument)}handleEvent(e){Na(this.view,e)&&!this.ignoreDuringComposition(e)&&(e.type==`keydown`&&this.keydown(e)||(this.view.updateState==0?this.runHandlers(e.type,e):Promise.resolve().then(()=>this.runHandlers(e.type,e))))}runHandlers(e,t){let n=this.handlers[e];if(n){for(let e of n.observers)e(this.view,t);for(let e of n.handlers){if(t.defaultPrevented)break;if(e(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=Sa(e),n=this.handlers,r=this.view.contentDOM;for(let e in t)if(e!=`scroll`){let i=!t[e].handlers.length,a=n[e];a&&i!=!a.handlers.length&&(r.removeEventListener(e,this.handleEvent),a=null),a||r.addEventListener(e,this.handleEvent,{passive:i})}for(let e in n)e!=`scroll`&&!t[e]&&r.removeEventListener(e,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&Ta.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),P.android&&P.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;if(P.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&(Ca.some(t=>t.keyCode==e.keyCode)&&!e.ctrlKey||wa.indexOf(e.key)>-1&&e.ctrlKey)){let t={ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,shiftKey:e.shiftKey};t.shiftKey&&P.ios&&!/^(off|none)$/.test(this.view.contentDOM.autocapitalize)&&ba(this.view.win)&&(t.shiftKey=!1);let n=this.pendingIOSKey={key:e.key,keyCode:e.keyCode,mods:t};return setTimeout(()=>{this.pendingIOSKey==n&&this.flushIOSKey()},50),!0}return e.keyCode!=229&&this.view.observer.forceFlush(),!1}flushIOSKey(e){let t=this.pendingIOSKey;return!t||this.view.observer.pendingRecords().length||t.key==`Enter`&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,Xn(this.view.contentDOM,t.key,t.keyCode,t.mods))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:P.safari&&!P.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}};function ba(e){return e.visualViewport?e.visualViewport.height*e.visualViewport.scale/e.document.documentElement.clientHeight<.85:!1}function xa(e,t){return(n,r)=>{try{return t.call(e,r,n)}catch(e){Br(n.state,e)}}}function Sa(e){let t=Object.create(null);function n(e){return t[e]||(t[e]={observers:[],handlers:[]})}for(let t of e){let e=t.spec,r=e&&e.plugin.domEventHandlers,i=e&&e.plugin.domEventObservers;if(r)for(let e in r){let i=r[e];i&&n(e).handlers.push(xa(t.value,i))}if(i)for(let e in i){let r=i[e];r&&n(e).observers.push(xa(t.value,r))}}for(let e in Pa)n(e).handlers.push(Pa[e]);for(let e in Fa)n(e).observers.push(Fa[e]);return t}var Ca=[{key:`Backspace`,keyCode:8,inputType:`deleteContentBackward`},{key:`Enter`,keyCode:13,inputType:`insertParagraph`},{key:`Enter`,keyCode:13,inputType:`insertLineBreak`},{key:`Delete`,keyCode:46,inputType:`deleteContentForward`}],wa=`dthko`,Ta=[16,17,18,20,91,92,224,225],Ea=6;function Da(e){return Math.max(0,e)*.7+8}function Oa(e,t){return Math.max(Math.abs(e.clientX-t.clientX),Math.abs(e.clientY-t.clientY))}var ka=class{constructor(e,t,n,r){this.view=e,this.startEvent=t,this.style=n,this.mustSelect=r,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Hn(e.contentDOM),this.atoms=e.state.facet(Zr).map(t=>t(e));let i=e.contentDOM.ownerDocument;i.addEventListener(`mousemove`,this.move=this.move.bind(this)),i.addEventListener(`mouseup`,this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(j.allowMultipleSelections)&&Aa(e,t),this.dragging=Ma(e,t)&&Ga(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Oa(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,n=0,r=0,i=0,a=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:r,right:a}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:i,bottom:o}=this.scrollParents.y.getBoundingClientRect());let s=ni(this.view);e.clientX-s.left<=r+Ea?t=-Da(r-e.clientX):e.clientX+s.right>=a-Ea&&(t=Da(e.clientX-a)),e.clientY-s.top<=i+Ea?n=-Da(i-e.clientY):e.clientY+s.bottom>=o-Ea&&(n=Da(e.clientY-o)),this.setScrollSpeed(t,n)}up(e){this.dragging??this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener(`mousemove`,this.move),e.removeEventListener(`mouseup`,this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,n=ea(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!n.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:n,userEvent:`select.pointer`}),this.mustSelect=!1}update(e){e.transactions.some(e=>e.isUserEvent(`input.type`))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}};function Aa(e,t){let n=e.state.facet(Tr);return n.length?n[0](t):P.mac?t.metaKey:t.ctrlKey}function ja(e,t){let n=e.state.facet(Er);return n.length?n[0](t):P.mac?!t.altKey:!t.ctrlKey}function Ma(e,t){let{main:n}=e.state.selection;if(n.empty)return!1;let r=kn(e.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let e=0;e<i.length;e++){let n=i[e];if(n.left<=t.clientX&&n.right>=t.clientX&&n.top<=t.clientY&&n.bottom>=t.clientY)return!0}return!1}function Na(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target,r;n!=e.contentDOM;n=n.parentNode)if(!n||n.nodeType==11||(r=R.get(n))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(t))return!1;return!0}var Pa=Object.create(null),Fa=Object.create(null),Ia=P.ie&&P.ie_version<15||P.ios&&P.webkit_version<604;function La(e){let t=e.dom.parentNode;if(!t)return;let n=t.appendChild(document.createElement(`textarea`));n.style.cssText=`position: fixed; left: -10000px; top: 10px`,n.focus(),setTimeout(()=>{e.focus(),n.remove(),za(e,n.value)},50)}function Ra(e,t,n){for(let r of e.facet(t))n=r(n,e);return n}function za(e,t){t=Ra(e.state,Mr,t);let{state:n}=e,r,i=1,a=n.toText(t),o=a.lines==n.selection.ranges.length;if(Za!=null&&n.selection.ranges.every(e=>e.empty)&&Za==a.toString()){let e=-1;r=n.changeByRange(r=>{let s=n.doc.lineAt(r.from);if(s.from==e)return{range:r};e=s.from;let c=n.toText((o?a.line(i++).text:t)+n.lineBreak);return{changes:{from:s.from,insert:c},range:O.cursor(r.from+c.length,-1)}})}else r=o?n.changeByRange(e=>{let t=a.line(i++);return{changes:{from:e.from,to:e.to,insert:t.text},range:O.cursor(e.from+t.length,-1)}}):n.replaceSelection(a);e.dispatch(r,{userEvent:`input.paste`,scrollIntoView:!0})}Fa.scroll=e=>{let t=e.inputState;t.lastScrollTop=e.scrollDOM.scrollTop,t.lastScrollLeft=e.scrollDOM.scrollLeft,P.ios&&!t.touchActive&&(t.lastIOSMomentumScroll=Date.now())},Fa.wheel=Fa.mousewheel=e=>{e.inputState.lastWheelEvent=Date.now()},Pa.keydown=(e,t)=>(e.inputState.setSelectionOrigin(`select`),t.keyCode==27&&e.inputState.tabFocusMode!=0&&(e.inputState.tabFocusMode=Date.now()+2e3),!1),Fa.touchstart=(e,t)=>{let n=e.inputState,r=t.targetTouches[0];n.touchActive=!0,n.lastTouchTime=Date.now(),r&&(n.lastTouchX=r.clientX,n.lastTouchY=r.clientY),n.setSelectionOrigin(`select.pointer`)},Fa.touchmove=e=>{e.inputState.setSelectionOrigin(`select.pointer`)},Fa.touchend=(e,t)=>{e.inputState.touchActive=!1},Pa.mousedown=(e,t)=>{if(e.observer.flush(),e.inputState.lastTouchTime>Date.now()-2e3)return!1;let n=null;for(let r of e.state.facet(Dr))if(n=r(e,t),n)break;if(!n&&t.button==0&&(n=Ka(e,t)),n){let r=!e.hasFocus;e.inputState.startMouseSelection(new ka(e,t,n,r)),r&&e.observer.ignore(()=>{qn(e.contentDOM);let t=e.root.activeElement;t&&!t.contains(e.contentDOM)&&t.blur()});let i=e.inputState.mouseSelection;if(i)return i.start(t),i.dragging===!1}else e.inputState.setSelectionOrigin(`select.pointer`);return!1};function Ba(e,t,n,r){if(r==1)return O.cursor(t,n);if(r==2)return Ki(e.state,t,n);{let r=e.docView.lineAt(t,n),i=e.state.doc.lineAt(r?r.posAtEnd:t),a=r?r.posAtStart:i.from,o=r?r.posAtEnd:i.to;return o<e.state.doc.length&&o==i.to&&o++,O.undirectionalRange(a,o)}}var Va=P.ie&&P.ie_version<=11,Ha=null,Ua=0,Wa=0;function Ga(e){if(!Va)return e.detail;let t=Ha,n=Wa;return Ha=e,Wa=Date.now(),Ua=!t||n>Date.now()-400&&Math.abs(t.clientX-e.clientX)<2&&Math.abs(t.clientY-e.clientY)<2?(Ua+1)%3:1}function Ka(e,t){let n=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),r=Ga(t),i=e.state.selection;return{update(e){e.docChanged&&(n.pos=e.changes.mapPos(n.pos),i=i.map(e.changes))},get(t,a,o){let s=e.posAndSideAtCoords({x:t.clientX,y:t.clientY},!1),c,l=Ba(e,s.pos,s.assoc,r);if(n.pos!=s.pos&&!a){let t=Ba(e,n.pos,n.assoc,r),i=Math.min(t.from,l.from),a=Math.max(t.to,l.to);l=i<l.from?O.range(i,a,l.assoc):O.range(a,i,l.assoc)}return a?i.replaceRange(i.main.extend(l.from,l.to,l.assoc)):o&&r==1&&i.ranges.length>1&&(c=qa(i,s.pos))?c:o?i.addRange(l):O.create([l])}}}function qa(e,t){for(let n=0;n<e.ranges.length;n++){let{from:r,to:i}=e.ranges[n];if(r<=t&&i>=t)return O.create(e.ranges.slice(0,n).concat(e.ranges.slice(n+1)),e.mainIndex==n?0:e.mainIndex-+(e.mainIndex>n))}return null}Pa.dragstart=(e,t)=>{let{selection:{main:n}}=e.state;if(t.target.draggable){let r=e.docView.tile.nearest(t.target);if(r&&r.isWidget()){let e=r.posAtStart,t=e+r.length;(e>=n.to||t<=n.from)&&(n=O.undirectionalRange(e,t))}}let{inputState:r}=e;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=n,t.dataTransfer&&(t.dataTransfer.setData(`Text`,Ra(e.state,Nr,e.state.sliceDoc(n.from,n.to))),t.dataTransfer.effectAllowed=`copyMove`),!1},Pa.dragend=e=>(e.inputState.draggedContent=null,!1);function Ja(e,t,n,r){if(n=Ra(e.state,Mr,n),!n)return;let i=e.posAtCoords({x:t.clientX,y:t.clientY},!1),{draggedContent:a}=e.inputState,o=r&&a&&ja(e,t)?{from:a.from,to:a.to}:null,s={from:i,insert:n},c=e.state.changes(o?[o,s]:s);e.focus(),e.dispatch({changes:c,selection:{anchor:c.mapPos(i,-1),head:c.mapPos(i,1)},userEvent:o?`move.drop`:`input.drop`}),e.inputState.draggedContent=null}Pa.drop=(e,t)=>{if(!t.dataTransfer)return!1;if(e.state.readOnly)return!0;let n=t.dataTransfer.files;if(n&&n.length){let r=Array(n.length),i=0,a=()=>{++i==n.length&&Ja(e,t,r.filter(e=>e!=null).join(e.state.lineBreak),!1)};for(let e=0;e<n.length;e++){let t=new FileReader;t.onerror=a,t.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(t.result)||(r[e]=t.result),a()},t.readAsText(n[e])}return!0}{let n=t.dataTransfer.getData(`Text`);if(n)return Ja(e,t,n,!0),!0}return!1},Pa.paste=(e,t)=>{if(e.state.readOnly)return!0;e.observer.flush();let n=Ia?null:t.clipboardData;return n?(za(e,n.getData(`text/plain`)||n.getData(`text/uri-list`)),!0):(La(e),!1)};function Ya(e,t){let n=e.dom.parentNode;if(!n)return;let r=n.appendChild(document.createElement(`textarea`));r.style.cssText=`position: fixed; left: -10000px; top: 10px`,r.value=t,r.focus(),r.selectionEnd=t.length,r.selectionStart=0,setTimeout(()=>{r.remove(),e.focus()},50)}function Xa(e){let t=[],n=[],r=!1;for(let r of e.selection.ranges)r.empty||(t.push(e.sliceDoc(r.from,r.to)),n.push(r));if(!t.length){let i=-1;for(let{from:r}of e.selection.ranges){let a=e.doc.lineAt(r);a.number>i&&(t.push(a.text),n.push({from:a.from,to:Math.min(e.doc.length,a.to+1)})),i=a.number}r=!0}return{text:Ra(e,Nr,t.join(e.lineBreak)),ranges:n,linewise:r}}var Za=null;Pa.copy=Pa.cut=(e,t)=>{if(!jn(e.contentDOM,e.observer.selectionRange))return!1;let{text:n,ranges:r,linewise:i}=Xa(e.state);if(!n&&!i)return!1;Za=i?n:null,t.type==`cut`&&!e.state.readOnly&&e.dispatch({changes:r,scrollIntoView:!0,userEvent:`delete.cut`});let a=Ia?null:t.clipboardData;return a?(a.clearData(),a.setData(`text/plain`,n),!0):(Ya(e,n),!1)};var Qa=qe.define();function $a(e,t){let n=[];for(let r of e.facet(jr)){let i=r(e,t);i&&n.push(i)}return n.length?e.update({effects:n,annotations:Qa.of(!0)}):null}function eo(e){setTimeout(()=>{let t=e.hasFocus;if(t!=e.inputState.notifiedFocused){let n=$a(e.state,t);n?e.dispatch(n):e.update([])}},10)}Fa.focus=e=>{e.inputState.lastFocusTime=Date.now(),!e.scrollDOM.scrollTop&&(e.inputState.lastScrollTop||e.inputState.lastScrollLeft)&&(e.scrollDOM.scrollTop=e.inputState.lastScrollTop,e.scrollDOM.scrollLeft=e.inputState.lastScrollLeft),eo(e)},Fa.blur=e=>{e.observer.clearSelectionRange(),eo(e)},Fa.compositionstart=Fa.compositionupdate=(e,t)=>{if(!e.observer.editContext&&(e.inputState.compositionFirstChange??(e.inputState.compositionFirstChange=!0),e.inputState.composing<0)){let{main:t}=e.state.selection;!t.empty&&e.lineBlockAt(t.from).from!=e.lineBlockAt(t.to).from&&!e.state.readOnly&&e.dispatch({changes:e.state.selection.ranges.filter(e=>!e.empty).map(e=>({from:e.from,to:e.to})),userEvent:`input`}),e.inputState.composing=0}},Fa.compositionend=e=>{e.observer.editContext||(e.inputState.composing=-1,e.inputState.compositionEndedAt=Date.now(),e.inputState.compositionPendingKey=!0,e.inputState.compositionPendingChange=e.observer.pendingRecords().length>0,e.inputState.compositionFirstChange=null,P.chrome&&P.android?e.observer.flushSoon():e.inputState.compositionPendingChange?Promise.resolve().then(()=>e.observer.flush()):setTimeout(()=>{e.inputState.composing<0&&e.docView.hasComposition&&e.update([])},50))},Fa.contextmenu=e=>{e.inputState.lastContextMenu=Date.now()},Pa.beforeinput=(e,t)=>{if((t.inputType==`insertText`||t.inputType==`insertCompositionText`)&&(e.inputState.insertingText=t.data,e.inputState.insertingTextAt=Date.now()),t.inputType==`insertReplacementText`&&e.observer.editContext){let n=t.dataTransfer?.getData(`text/plain`),r=t.getTargetRanges();if(n&&r.length){let t=r[0];return pa(e,{from:e.posAtDOM(t.startContainer,t.startOffset),to:e.posAtDOM(t.endContainer,t.endOffset),insert:e.state.toText(n)},null),!0}}let n;if(P.chrome&&P.android&&(n=Ca.find(e=>e.inputType==t.inputType))&&(e.observer.delayAndroidKey(n.key,n.keyCode),n.key==`Backspace`||n.key==`Delete`)){let t=window.visualViewport?.height||0;setTimeout(()=>{(window.visualViewport?.height||0)>t+10&&e.hasFocus&&(e.contentDOM.blur(),e.focus())},100)}return P.ios&&t.inputType==`deleteContentForward`&&e.observer.flushSoon(),P.safari&&t.inputType==`insertText`&&e.inputState.composing>=0&&setTimeout(()=>Fa.compositionend(e,t),20),!1};var to=new Set;function no(e){to.has(e)||(to.add(e),e.addEventListener(`copy`,()=>{}),e.addEventListener(`cut`,()=>{}))}var ro=[`pre-wrap`,`normal`,`pre-line`,`break-spaces`],io=!1;function ao(){io=!1}var oo=class{constructor(e){this.lineWrapping=e,this.doc=x.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let n=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(n+=Math.max(0,Math.ceil((t-e-n*this.lineLength*.5)/this.lineLength))),this.lineHeight*n}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return ro.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];r<0?n++:this.heightSamples[Math.floor(r*10)]||(t=!0,this.heightSamples[Math.floor(r*10)]=!0)}return t}refresh(e,t,n,r,i,a){let o=ro.indexOf(e)>-1,s=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=n,this.textHeight=r,this.lineLength=i,s){this.heightSamples={};for(let e=0;e<a.length;e++){let t=a[e];t<0?e++:this.heightSamples[Math.floor(t*10)]=!0}}return s}},so=class{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}},co=class e{constructor(e,t,n,r,i){this.from=e,this.length=t,this.top=n,this.height=r,this._content=i}get type(){return typeof this._content==`number`?bn.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 Cn?this._content.widget:null}get widgetLineBreaks(){return typeof this._content==`number`?this._content:0}join(t){let n=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(t._content)?t._content:[t]);return new e(this.from,this.length+t.length,this.top,this.height+t.height,n)}},z=(function(e){return e[e.ByPos=0]=`ByPos`,e[e.ByHeight=1]=`ByHeight`,e[e.ByPosNoHeight=2]=`ByPosNoHeight`,e})(z||={}),lo=.001,uo=class e{constructor(e,t,n=2){this.length=e,this.height=t,this.flags=n}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>lo&&(io=!0),this.height=e)}replace(t,n,r){return e.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,n,r){let i=this,a=n.doc;for(let o=r.length-1;o>=0;o--){let{fromA:s,toA:c,fromB:l,toB:u}=r[o],d=i.lineAt(s,z.ByPosNoHeight,n.setDoc(t),0,0),f=d.to>=c?d:i.lineAt(c,z.ByPosNoHeight,n,0,0);for(u+=f.to-c,c=f.to;o>0&&d.from<=r[o-1].toA;)s=r[o-1].fromA,l=r[o-1].fromB,o--,s<d.from&&(d=i.lineAt(s,z.ByPosNoHeight,n,0,0));l+=d.from-s,s=d.from;let p=bo.build(n.setDoc(a),e,l,u);i=fo(i,i.replace(s,c,p))}return i.updateHeight(n,0)}static empty(){return new ho(0,0,0)}static of(t){if(t.length==1)return t[0];let n=0,r=t.length,i=0,a=0;for(;;)if(n==r){if(i>a*2){let e=t[n-1];e.break?t.splice(--n,1,e.left,null,e.right):t.splice(--n,1,e.left,e.right),r+=1+e.break,i-=e.size}else if(a>i*2){let e=t[r];e.break?t.splice(r,1,e.left,null,e.right):t.splice(r,1,e.left,e.right),r+=2+e.break,a-=e.size}else break}else if(i<a){let e=t[n++];e&&(i+=e.size)}else{let e=t[--r];e&&(a+=e.size)}let o=!1;return t[n-1]==null?(o=!0,n--):t[n]??(o=!0,r++),new _o(e.of(t.slice(0,n)),o,e.of(t.slice(r)))}};function fo(e,t){return e==t?e:(e.constructor!=t.constructor&&(io=!0),t)}uo.prototype.size=1;var po=F.replace({}),mo=class extends uo{constructor(e,t,n){super(e,t),this.deco=n,this.spaceAbove=0}mainBlock(e,t){return new co(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,n,r){return this.spaceAbove&&e<n+this.spaceAbove?new co(r,0,n,this.spaceAbove,po):this.mainBlock(n,r)}lineAt(e,t,n,r,i){let a=this.mainBlock(r,i);return this.spaceAbove?this.blockAt(0,n,r,i).join(a):a}forEachLine(e,t,n,r,i,a){e<=i+this.length&&t>=i&&a(this.lineAt(0,z.ByPos,n,r,i))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more&&this.setMeasuredHeight(r),this.outdated=!1,this}toString(){return`block(${this.length})`}},ho=class e extends mo{constructor(e,t,n){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=n}mainBlock(e,t){return new co(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(t,n,r){let i=r[0];return r.length==1&&(i instanceof e||i instanceof go&&i.flags&4)&&Math.abs(this.length-i.length)<10?(i instanceof go?i=new e(i.length,this.height,this.spaceAbove):i.height=this.height,this.outdated||(i.outdated=!1),i):uo.of(r)}updateHeight(e,t=0,n=!1,r){return r&&r.from<=t&&r.more?this.setMeasuredHeight(r):(n||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:``}${this.widgetHeight?`:`+this.widgetHeight:``})`}},go=class e extends uo{constructor(e){super(e,0)}heightMetrics(e,t){let n=e.doc.lineAt(t).number,r=e.doc.lineAt(t+this.length).number,i=r-n+1,a,o=0;if(e.lineWrapping){let t=Math.min(this.height,e.lineHeight*i);a=t/i,this.length>i+1&&(o=(this.height-t)/(this.length-i-1))}else a=this.height/i;return{firstLine:n,lastLine:r,perLine:a,perChar:o}}blockAt(e,t,n,r){let{firstLine:i,lastLine:a,perLine:o,perChar:s}=this.heightMetrics(t,r);if(t.lineWrapping){let i=r+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-n)/this.height))*this.length)),a=t.doc.lineAt(i),c=o+a.length*s,l=Math.max(n,e-c/2);return new co(a.from,a.length,l,c,0)}{let r=Math.max(0,Math.min(a-i,Math.floor((e-n)/o))),{from:s,length:c}=t.doc.line(i+r);return new co(s,c,n+o*r,o,0)}}lineAt(e,t,n,r,i){if(t==z.ByHeight)return this.blockAt(e,n,r,i);if(t==z.ByPosNoHeight){let{from:t,to:r}=n.doc.lineAt(e);return new co(t,r-t,0,0,0)}let{firstLine:a,perLine:o,perChar:s}=this.heightMetrics(n,i),c=n.doc.lineAt(e),l=o+c.length*s,u=c.number-a,d=r+o*u+s*(c.from-i-u);return new co(c.from,c.length,Math.max(r,Math.min(d,r+this.height-l)),l,0)}forEachLine(e,t,n,r,i,a){e=Math.max(e,i),t=Math.min(t,i+this.length);let{firstLine:o,perLine:s,perChar:c}=this.heightMetrics(n,i);for(let l=e,u=r;l<=t;){let t=n.doc.lineAt(l);if(l==e){let n=t.number-o;u+=s*n+c*(e-i-n)}let r=s+c*t.length;a(new co(t.from,t.length,u,r,0)),u+=r,l=t.to+1}}replace(t,n,r){let i=this.length-n;if(i>0){let t=r[r.length-1];t instanceof e?r[r.length-1]=new e(t.length+i):r.push(null,new e(i-1))}if(t>0){let n=r[0];n instanceof e?r[0]=new e(t+n.length):r.unshift(new e(t-1),null)}return uo.of(r)}decomposeLeft(t,n){n.push(new e(t-1),null)}decomposeRight(t,n){n.push(null,new e(this.length-t-1))}updateHeight(t,n=0,r=!1,i){let a=n+this.length;if(i&&i.from<=n+this.length&&i.more){let r=[],o=Math.max(n,i.from),s=-1;for(i.from>n&&r.push(new e(i.from-n-1).updateHeight(t,n));o<=a&&i.more;){let e=t.doc.lineAt(o).length;r.length&&r.push(null);let n=i.heights[i.index++],a=0;n<0&&(a=-n,n=i.heights[i.index++]),s==-1?s=n:Math.abs(n-s)>=lo&&(s=-2);let c=new ho(e,n,a);c.outdated=!1,r.push(c),o+=e+1}o<=a&&r.push(null,new e(a-o).updateHeight(t,o));let c=uo.of(r);return(s<0||Math.abs(c.height-this.height)>=lo||Math.abs(s-this.heightMetrics(t,n).perLine)>=lo)&&(io=!0),fo(this,c)}return(r||this.outdated)&&(this.setHeight(t.heightForGap(n,n+this.length)),this.outdated=!1),this}toString(){return`gap(${this.length})`}},_o=class extends uo{constructor(e,t,n){super(e.length+ +!!t+n.length,e.height+n.height,+!!t|(e.outdated||n.outdated?2:0)),this.left=e,this.right=n,this.size=e.size+n.size}get break(){return this.flags&1}blockAt(e,t,n,r){let i=n+this.left.height;return e<i?this.left.blockAt(e,t,n,r):this.right.blockAt(e,t,i,r+this.left.length+this.break)}lineAt(e,t,n,r,i){let a=r+this.left.height,o=i+this.left.length+this.break,s=t==z.ByHeight?e<a:e<o,c=s?this.left.lineAt(e,t,n,r,i):this.right.lineAt(e,t,n,a,o);if(this.break||(s?c.to<o:c.from>o))return c;let l=t==z.ByPosNoHeight?z.ByPosNoHeight:z.ByPos;return s?c.join(this.right.lineAt(o,l,n,a,o)):this.left.lineAt(o,l,n,r,i).join(c)}forEachLine(e,t,n,r,i,a){let o=r+this.left.height,s=i+this.left.length+this.break;if(this.break)e<s&&this.left.forEachLine(e,t,n,r,i,a),t>=s&&this.right.forEachLine(e,t,n,o,s,a);else{let c=this.lineAt(s,z.ByPos,n,r,i);e<c.from&&this.left.forEachLine(e,Math.min(t,c.from-1),n,r,i,a),c.to>=e&&c.from<=t&&a(c),t>c.to&&this.right.forEachLine(Math.max(e,c.to+1),t,n,o,s,a)}}replace(e,t,n){let r=this.left.length+this.break;if(t<r)return this.balanced(this.left.replace(e,t,n),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-r,t-r,n));let i=[];e>0&&this.decomposeLeft(e,i);let a=i.length;for(let e of n)i.push(e);if(e>0&&vo(i,a-1),t<this.length){let e=i.length;this.decomposeRight(t,i),vo(i,e)}return uo.of(i)}decomposeLeft(e,t){let n=this.left.length;if(e<=n)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(n++,e>=n&&t.push(null)),e>n&&this.right.decomposeLeft(e-n,t)}decomposeRight(e,t){let n=this.left.length,r=n+this.break;if(e>=r)return this.right.decomposeRight(e-r,t);e<n&&this.left.decomposeRight(e,t),this.break&&e<r&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?uo.of(this.break?[e,null,t]:[e,t]):(this.left=fo(this.left,e),this.right=fo(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,n=!1,r){let{left:i,right:a}=this,o=t+i.length+this.break,s=null;return r&&r.from<=t+i.length&&r.more?s=i=i.updateHeight(e,t,n,r):i.updateHeight(e,t,n),r&&r.from<=o+a.length&&r.more?s=a=a.updateHeight(e,o,n,r):a.updateHeight(e,o,n),s?this.balanced(i,a):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?` `:`-`)+this.right}};function vo(e,t){let n,r;e[t]==null&&(n=e[t-1])instanceof go&&(r=e[t+1])instanceof go&&e.splice(t-1,3,new go(n.length+1+r.length))}var yo=5,bo=class e{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let e=Math.min(t,this.lineEnd),n=this.nodes[this.nodes.length-1];n instanceof ho?n.length+=e-this.pos:(e>this.pos||!this.isCovered)&&this.nodes.push(new ho(e-this.pos,-1,0)),this.writtenTo=e,t>e&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,n){if(e<t||n.heightRelevant){let r=n.widget?n.widget.estimatedHeight:0,i=n.widget?n.widget.lineBreaks:0;r<0&&(r=this.oracle.lineHeight);let a=t-e;n.block?this.addBlock(new mo(a,r,n)):(a||i||r>=yo)&&this.addLineDeco(r,i,a)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new ho(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let n=new go(t-e);return this.oracle.doc.lineAt(e).to==t&&(n.flags|=4),n}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof ho)return e;let t=new ho(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos+=e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,n){let r=this.ensureLine();r.length+=n,r.collapsed+=n,r.widgetHeight=Math.max(r.widgetHeight,e),r.breaks+=t,this.writtenTo=this.pos+=n}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof ho)&&!this.isCovered?this.nodes.push(new ho(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let n=e;for(let e of this.nodes)e instanceof ho&&e.updateHeight(this.oracle,n),n+=e?e.length:1;return this.nodes}static build(t,n,r,i){let a=new e(r,t);return M.spans(n,r,i,a,0),a.finish(r)}};function xo(e,t,n){let r=new So;return M.compare(e,t,n,r,0),r.changes}var So=class{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,n,r){(e<t||n&&n.heightRelevant||r&&r.heightRelevant)&&En(e,t,this.changes,5)}};function Co(e,t){let n=e.getBoundingClientRect(),r=e.ownerDocument,i=r.defaultView||window,a=Math.max(0,n.left),o=Math.min(i.innerWidth,n.right),s=Math.max(0,n.top),c=Math.min(i.innerHeight,n.bottom);for(let t=e.parentNode;t&&t!=r.body;)if(I(t)){let n=window.getComputedStyle(t);if((t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth)&&n.overflow!=`visible`){let n=t.getBoundingClientRect();a=Math.max(a,n.left),o=Math.min(o,n.right),s=Math.max(s,n.top),c=Math.min(t==e.parentNode?i.innerHeight:c,n.bottom)}t=n.position==`absolute`||n.position==`fixed`?t.offsetParent:t.parentNode}else if(t.nodeType==11)t=t.host;else break;return{left:a-n.left,right:Math.max(a,o)-n.left,top:s-(n.top+t),bottom:Math.max(s,c)-(n.top+t)}}function wo(e){let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView||window;return t.left<n.innerWidth&&t.right>0&&t.top<n.innerHeight&&t.bottom>0}function To(e,t){let n=e.getBoundingClientRect();return{left:0,right:n.right-n.left,top:t,bottom:n.bottom-(n.top+t)}}var Eo=class{constructor(e,t,n,r){this.from=e,this.to=t,this.size=n,this.displaySize=r}static same(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r.from!=i.from||r.to!=i.to||r.size!=i.size)return!1}return!0}draw(e,t){return F.replace({widget:new Do(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}},Do=class extends yn{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement(`div`);return this.vertical?e.style.height=this.size+`px`:(e.style.width=this.size+`px`,e.style.height=`2px`,e.style.display=`inline-block`),e}get estimatedHeight(){return this.vertical?this.size:-1}},Oo=class{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Po,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=rr.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let n=t.facet(qr).some(e=>typeof e!=`function`&&e.class==`cm-lineWrapping`);this.heightOracle=new oo(n),this.stateDeco=Fo(t),this.heightMap=uo.empty().applyChanges(this.stateDeco,x.empty,this.heightOracle.setDoc(t.doc),[new ii(0,0,0,t.doc.length)]);for(let e=0;e<2&&(this.viewport=this.getViewport(0,null),this.updateForViewport());e++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=F.set(this.lineGaps.map(e=>e.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let n=0;n<=1;n++){let r=n?t.head:t.anchor;if(!e.some(({from:e,to:t})=>r>=e&&r<=t)){let{from:t,to:n}=this.lineBlockAt(r);e.push(new ko(t,n))}}return this.viewports=e.sort((e,t)=>e.from-t.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Po:Io.get(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Lo(e,this.scaler))})}update(e,t=null){this.state=e.state;let n=this.stateDeco;this.stateDeco=Fo(this.state);let r=e.changedRanges,i=ii.extendWithRanges(r,xo(n,this.stateDeco,e?e.changes:pe.empty(this.state.doc.length))),a=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);ao(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),i),(this.heightMap.height!=a||io)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=a);let s=i.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<s.from||t.range.head>s.to)||!this.viewportIsAppropriate(s))&&(s=this.getViewport(0,t));let c=s.from!=this.viewport.from||s.to!=this.viewport.to;this.viewport=s,e.flags|=this.updateForViewport(),(c||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Fr)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,n=window.getComputedStyle(t),r=this.heightOracle,i=n.whiteSpace;this.defaultTextDirection=n.direction==`rtl`?rr.RTL:rr.LTR;let a=this.heightOracle.mustRefreshForWrapping(i)||this.mustMeasureContent===`refresh`,o=t.getBoundingClientRect(),s=a||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let c=0,l=0;if(o.width&&o.height){let{scaleX:e,scaleY:n}=Bn(t,o);(e>.005&&Math.abs(this.scaleX-e)>.005||n>.005&&Math.abs(this.scaleY-n)>.005)&&(this.scaleX=e,this.scaleY=n,c|=16,a=s=!0)}let u=(parseInt(n.paddingTop)||0)*this.scaleY,d=(parseInt(n.paddingBottom)||0)*this.scaleY;(this.paddingTop!=u||this.paddingBottom!=d)&&(this.paddingTop=u,this.paddingBottom=d,c|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(r.lineWrapping&&(s=!0),this.editorWidth=e.scrollDOM.clientWidth,c|=16);let f=Hn(this.view.contentDOM,!1).y;f!=this.scrollParent&&(this.scrollParent=f,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=$n(this.scrollParent||e.win);let m=(this.printing?To:Co)(t,this.paddingTop),h=m.top-this.pixelViewport.top,g=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let _=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(_!=this.inView&&(this.inView=_,_&&(s=!0)),!this.inView&&!this.scrollTarget&&!wo(e.dom))return 0;let v=o.width;if((this.contentDOMWidth!=v||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,c|=16),s){let t=e.docView.measureVisibleLineHeights(this.viewport);if(r.mustRefreshForHeights(t)&&(a=!0),a||r.lineWrapping&&Math.abs(v-this.contentDOMWidth)>r.charWidth){let{lineHeight:n,charWidth:o,textHeight:s}=e.docView.measureTextSize();a=n>0&&r.refresh(i,n,o,s,Math.max(5,v/o),t),a&&(e.docView.minWidth=0,c|=16)}h>0&&g>0?l=Math.max(h,g):h<0&&g<0&&(l=Math.min(h,g)),ao();for(let n of this.viewports){let i=n.from==this.viewport.from?t:e.docView.measureVisibleLineHeights(n);this.heightMap=(a?uo.empty().applyChanges(this.stateDeco,x.empty,this.heightOracle,[new ii(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(r,0,a,new so(n.from,i))}io&&(c|=2)}let y=!this.viewportIsAppropriate(this.viewport,l)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return y&&(c&2&&(c|=this.updateScaler()),this.viewport=this.getViewport(l,this.scrollTarget),c|=this.updateForViewport()),(c&2||y)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(a?[]:this.lineGaps,e)),c|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),c}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let n=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),r=this.heightMap,i=this.heightOracle,{visibleTop:a,visibleBottom:o}=this,s=new ko(r.lineAt(a-n*1e3,z.ByHeight,i,0,0).from,r.lineAt(o+(1-n)*1e3,z.ByHeight,i,0,0).to);if(t){let{head:e}=t.range;if(e<s.from||e>s.to){let n=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),a=r.lineAt(e,z.ByPos,i,0,0),o;o=t.y==`center`?(a.top+a.bottom)/2-n/2:t.y==`start`||t.y==`nearest`&&e<s.from?a.top:a.bottom-n,s=new ko(r.lineAt(o-500,z.ByHeight,i,0,0).from,r.lineAt(o+n+500,z.ByHeight,i,0,0).to)}}return s}mapViewport(e,t){let n=t.mapPos(e.from,-1),r=t.mapPos(e.to,1);return new ko(this.heightMap.lineAt(n,z.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(r,z.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},n=0){if(!this.inView)return!0;let{top:r}=this.heightMap.lineAt(e,z.ByPos,this.heightOracle,0,0),{bottom:i}=this.heightMap.lineAt(t,z.ByPos,this.heightOracle,0,0),{visibleTop:a,visibleBottom:o}=this;return(e==0||r<=a-Math.max(10,Math.min(-n,250)))&&(t==this.state.doc.length||i>=o+Math.max(10,Math.min(n,250)))&&r>a-2e3&&i<o+2e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let n=[];for(let r of e)t.touchesRange(r.from,r.to)||n.push(new Eo(t.mapPos(r.from),t.mapPos(r.to),r.size,r.displaySize));return n}ensureLineGaps(e,t){let n=this.heightOracle.lineWrapping,r=n?1e4:2e3,i=r>>1,a=r<<1;if(this.defaultTextDirection!=rr.LTR&&!n)return[];let o=[],s=(r,a,c,l)=>{if(a-r<i)return;let u=this.state.selection.main,d=[u.from];u.empty||d.push(u.to);for(let e of d)if(e>r&&e<a){s(r,e-10,c,l),s(e+10,a,c,l);return}let f=No(e,e=>e.from>=c.from&&e.to<=c.to&&Math.abs(e.from-r)<i&&Math.abs(e.to-a)<i&&!d.some(t=>e.from<t&&e.to>t));if(!f){if(a<c.to&&t&&n&&t.visibleRanges.some(e=>e.from<=a&&e.to>=a)){let e=t.moveToLineBoundary(O.cursor(a),!1,!0).head;e>r&&(a=e)}let e=this.gapSize(c,r,a,l);f=new Eo(r,a,e,n||e<2e6?e:2e6)}o.push(f)},c=t=>{if(t.length<a||t.type!=bn.Text)return;let i=Ao(t.from,t.to,this.stateDeco);if(i.total<a)return;let o=this.scrollTarget?this.scrollTarget.range.head:null,c,l;if(n){let e=r/this.heightOracle.lineLength*this.heightOracle.lineHeight,n,a;if(o!=null){let r=Mo(i,o),s=((this.visibleBottom-this.visibleTop)/2+e)/t.height;n=r-s,a=r+s}else n=(this.visibleTop-t.top-e)/t.height,a=(this.visibleBottom-t.top+e)/t.height;c=jo(i,n),l=jo(i,a)}else{let n=i.total*this.heightOracle.charWidth,a=r*this.heightOracle.charWidth,s=0;if(n>2e6)for(let n of e)n.from>=t.from&&n.from<t.to&&n.size!=n.displaySize&&n.from*this.heightOracle.charWidth+s<this.pixelViewport.left&&(s=n.size-n.displaySize);let u=this.pixelViewport.left+s,d=this.pixelViewport.right+s,f,p;if(o!=null){let e=Mo(i,o),t=((d-u)/2+a)/n;f=e-t,p=e+t}else f=(u-a)/n,p=(d+a)/n;c=jo(i,f),l=jo(i,p)}c>t.from&&s(t.from,c,t,i),l<t.to&&s(l,t.to,t,i)};for(let e of this.viewportLines)Array.isArray(e.type)?e.type.forEach(c):c(e);return o}gapSize(e,t,n,r){let i=Mo(r,n)-Mo(r,t);return this.heightOracle.lineWrapping?e.height*i:r.total*this.heightOracle.charWidth*i}updateLineGaps(e){Eo.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=F.set(e.map(e=>e.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let n=[];M.spans(t,this.viewport.from,this.viewport.to,{span(e,t){n.push({from:e,to:t})},point(){}},20);let r=0;if(n.length!=this.visibleRanges.length)r=12;else for(let t=0;t<n.length&&!(r&8);t++){let i=this.visibleRanges[t],a=n[t];(i.from!=a.from||i.to!=a.to)&&(r|=4,e&&e.mapPos(i.from,-1)==a.from&&e.mapPos(i.to,1)==a.to||(r|=8))}return this.visibleRanges=n,r}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Lo(this.heightMap.lineAt(e,z.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Lo(this.heightMap.lineAt(this.scaler.fromDOM(e),z.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop*this.scaleY:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+12-this.paddingTop);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Lo(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}},ko=class{constructor(e,t){this.from=e,this.to=t}};function Ao(e,t,n){let r=[],i=e,a=0;return M.spans(n,e,t,{span(){},point(e,t){e>i&&(r.push({from:i,to:e}),a+=e-i),i=t}},20),i<t&&(r.push({from:i,to:t}),a+=t-i),{total:a,ranges:r}}function jo({total:e,ranges:t},n){if(n<=0)return t[0].from;if(n>=1)return t[t.length-1].to;let r=Math.floor(e*n);for(let e=0;;e++){let{from:n,to:i}=t[e],a=i-n;if(r<=a)return n+r;r-=a}}function Mo(e,t){let n=0;for(let{from:r,to:i}of e.ranges){if(t<=i){n+=t-r;break}n+=i-r}return n/e.total}function No(e,t){for(let n of e)if(t(n))return n}var Po={toDOM(e){return e},fromDOM(e){return e},scale:1,eq(e){return e==this}};function Fo(e){let t=e.facet(Jr).filter(e=>typeof e!=`function`),n=e.facet(Xr).filter(e=>typeof e!=`function`);return n.length&&t.push(M.join(n)),t}var Io=class e{constructor(e,t){this.scale=e,this.viewports=t}static get(t,n,r){let i=0,a=0,o=0,s=r.map(({from:e,to:r})=>{let a=n.lineAt(e,z.ByPos,t,0,0).top,o=n.lineAt(r,z.ByPos,t,0,0).bottom;return i+=o-a,{from:e,to:r,top:a,bottom:o,domTop:0,domBottom:0}});if(n.height-i<10)return Po;let c=(7e6-i)/(n.height-i);for(let e of s)e.domTop=o+(e.top-a)*c,o=e.domBottom=e.domTop+(e.bottom-e.top),a=e.bottom;return new e(c,s)}toDOM(e){for(let t=0,n=0,r=0;;t++){let i=t<this.viewports.length?this.viewports[t]:null;if(!i||e<i.top)return r+(e-n)*this.scale;if(e<=i.bottom)return i.domTop+(e-i.top);n=i.bottom,r=i.domBottom}}fromDOM(e){for(let t=0,n=0,r=0;;t++){let i=t<this.viewports.length?this.viewports[t]:null;if(!i||e<i.domTop)return n+(e-r)/this.scale;if(e<=i.domBottom)return i.top+(e-i.domTop);n=i.bottom,r=i.domBottom}}eq(t){return t instanceof e&&this.scale==t.scale&&this.viewports.length==t.viewports.length&&this.viewports.every((e,n)=>e.from==t.viewports[n].from&&e.to==t.viewports[n].to)}};function Lo(e,t){if(t.scale==1)return e;let n=t.toDOM(e.top),r=t.toDOM(e.bottom);return new co(e.from,e.length,n,r-n,Array.isArray(e._content)?e._content.map(e=>Lo(e,t)):e._content)}var Ro=k.define({combine:e=>e.join(` `)}),zo=k.define({combine:e=>e.indexOf(!0)>-1}),Bo=Gt.newName(),Vo=Gt.newName(),Ho=Gt.newName(),Uo={"&light":`.`+Vo,"&dark":`.`+Ho};function Wo(e,t,n){return new Gt(t,{finish(t){return/&/.test(t)?t.replace(/&\w*/,t=>{if(t==`&`)return e;if(!n||!n[t])throw RangeError(`Unsupported selector: ${t}`);return n[t]}):e+` `+t}})}var Go=Wo(`.`+Bo,{"&":{position:`relative !important`,boxSizing:`border-box`,"&.cm-focused":{outline:`1px dotted #212121`},display:`flex !important`,flexDirection:`column`},".cm-scroller":{display:`flex !important`,alignItems:`flex-start !important`,fontFamily:`monospace`,lineHeight:1.4,height:`100%`,overflowX:`auto`,position:`relative`,zIndex:0,overflowAnchor:`none`},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:`block`,whiteSpace:`pre`,wordWrap:`normal`,boxSizing:`border-box`,minHeight:`100%`,padding:`4px 0`,outline:`none`,"&[contenteditable=true]":{WebkitUserModify:`read-write-plaintext-only`}},".cm-lineWrapping":{whiteSpace_fallback:`pre-wrap`,whiteSpace:`break-spaces`,wordBreak:`break-word`,overflowWrap:`anywhere`,flexShrink:1},"&light .cm-content":{caretColor:`black`},"&dark .cm-content":{caretColor:`white`},".cm-line":{display:`block`,padding:`0 2px 0 6px`},".cm-layer":{userSelect:`none`,position:`absolute`,left:0,top:0,contain:`size style`,"& > *":{position:`absolute`}},"&light .cm-selectionBackground":{background:`#d9d9d9`},"&dark .cm-selectionBackground":{background:`#222`},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#d7d4f0`},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:`#233`},".cm-cursorLayer":{pointerEvents:`none`},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:`steps(1) cm-blink 1.2s infinite`},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:`1.2px solid black`,marginLeft:`-0.6px`,pointerEvents:`none`},".cm-cursor":{display:`none`},"&dark .cm-cursor":{borderLeftColor:`#ddd`},".cm-selectionHandle":{backgroundColor:`currentColor`,width:`1.5px`},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:`""`,backgroundColor:`inherit`,borderRadius:`50%`,width:`8px`,height:`8px`,position:`absolute`,left:`-3.25px`},".cm-selectionHandle-start::before":{top:`-8px`},".cm-selectionHandle-end::before":{bottom:`-8px`},".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`,zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:`#f5f5f5`,color:`#6c6c6c`,border:`0px solid #ddd`,"&.cm-gutters-before":{borderRightWidth:`1px`},"&.cm-gutters-after":{borderLeftWidth:`1px`}},"&dark .cm-gutters":{backgroundColor:`#333338`,color:`#ccc`},".cm-gutter":{display:`flex !important`,flexDirection:`column`,flexShrink:0,boxSizing:`border-box`,minHeight:`100%`,overflow:`hidden`},".cm-gutterElement":{boxSizing:`border-box`},".cm-lineNumbers .cm-gutterElement":{padding:`0 3px 0 5px`,minWidth:`20px`,textAlign:`right`,whiteSpace:`nowrap`},"&light .cm-activeLineGutter":{backgroundColor:`#e2f2ff`},"&dark .cm-activeLineGutter":{backgroundColor:`#222227`},".cm-panels":{boxSizing:`border-box`,position:`sticky`,left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:`#f5f5f5`,color:`black`},".cm-panels-top":{top:`0`},".cm-panels-bottom":{bottom:`0`},"&light .cm-panels-top":{borderBottom:`1px solid #ddd`},"&light .cm-panels-bottom":{borderTop:`1px solid #ddd`},"&dark .cm-panels":{backgroundColor:`#333338`,color:`white`},".cm-dialog":{padding:`2px 19px 4px 6px`,position:`relative`,"& label":{fontSize:`80%`}},".cm-dialog-close":{position:`absolute`,top:`3px`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,fontSize:`14px`,padding:`0`},".cm-tab":{display:`inline-block`,overflow:`hidden`,verticalAlign:`bottom`},".cm-widgetBuffer":{verticalAlign:`baseline`,height:`1em`,width:0,display:`inline`},".cm-placeholder":{color:`#888`,display:`inline-block`,verticalAlign:`top`,userSelect:`none`},".cm-highlightSpace":{background:`radial-gradient(circle at 50% 55%, #aaa 20%, transparent 0) no-repeat`,backgroundSize:`.4em`,backgroundPosition:`calc(min(50%, 0px)) center`},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:`auto 100%`,backgroundPosition:`right 90%`,backgroundRepeat:`no-repeat`},".cm-trailingSpace":{backgroundColor:`#ff332255`},".cm-button":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,padding:`.2em 1em`,borderRadius:`1px`},"&light .cm-button":{backgroundImage:`linear-gradient(#eff1f5, #d9d9df)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#b4b4b4, #d0d3d6)`}},"&dark .cm-button":{backgroundImage:`linear-gradient(#393939, #111)`,border:`1px solid #888`,"&:active":{backgroundImage:`linear-gradient(#111, #333)`}},".cm-textfield":{verticalAlign:`middle`,color:`inherit`,fontSize:`70%`,border:`1px solid silver`,padding:`.2em .5em`},"&light .cm-textfield":{backgroundColor:`white`},"&dark .cm-textfield":{border:`1px solid #555`,backgroundColor:`inherit`}},Uo),Ko={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},qo=P.ie&&P.ie_version<=11,Jo=class{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Un,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=e.contentDOM,this.observer=new MutationObserver(t=>{for(let e of t)this.queue.push(e);(P.ie&&P.ie_version<=11||P.ios&&e.composing)&&t.some(e=>e.type==`childList`&&e.removedNodes.length||e.type==`characterData`&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&P.android&&e.constructor.EDIT_CONTEXT!==!1&&!(P.chrome&&P.chrome_version<126)&&(this.editContext=new Qo(e),e.state.facet(Vr)&&(e.contentDOM.editContext=this.editContext.editContext)),qo&&(this.onCharData=e=>{this.queue.push({target:e.target,type:`characterData`,oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia(`print`)),typeof ResizeObserver==`function`&&(this.resizeScroll=new ResizeObserver(()=>{this.view.docView?.lastUpdate<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver==`function`&&(this.intersection=new IntersectionObserver(e=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),e.length>0&&e[e.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent(`Event`)))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(e=>{e.length>0&&e[e.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent(`Event`))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers(`scroll`,e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(this.pendingRecords().length>0),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type!=`change`&&e.type||e.matches)&&(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,n)=>t!=e[n]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:n}=this,r=this.selectionRange;if(n.state.facet(Vr)?n.root.activeElement!=this.dom:!jn(this.dom,r))return;let i=r.anchorNode&&n.docView.tile.nearest(r.anchorNode);i&&i.isWidget()&&i.widget.ignoreEvent(e)?t||(this.selectionChanged=!1):(P.ie&&P.ie_version<=11||P.android&&P.chrome)&&!n.state.selection.main.empty&&r.focusNode&&Nn(r.focusNode,r.focusOffset,r.anchorNode,r.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=kn(e.root);if(!t)return!1;let n=P.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Zo(this.view,t)||t;if(!n||this.selectionRange.eq(n))return!1;let r=jn(this.dom,n);return r&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&Qn(this.dom,n)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(n),r&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let n=this.dom;n;)if(I(n))!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==n?e++:t||=this.scrollTargets.slice(0,e),t&&t.push(n),n=n.assignedSlot||n.parentNode;else if(n.nodeType==11)n=n.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let e of this.scrollTargets)e.removeEventListener(`scroll`,this.onScroll);for(let e of this.scrollTargets=t)e.addEventListener(`scroll`,this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||=(this.observer.observe(this.dom,Ko),qo&&this.dom.addEventListener(`DOMCharacterDataModified`,this.onCharData),!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),qo&&this.dom.removeEventListener(`DOMCharacterDataModified`,this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){if(!this.delayedAndroidKey){let e=()=>{let e=this.delayedAndroidKey;e&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=e.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&e.force&&Xn(this.dom,e.key,e.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(e)}this.delayedAndroidKey&&e!=`Enter`||(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!this.delayedAndroidKey?.force})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,n=-1,r=!1;for(let i of e){let e=this.readMutation(i);e&&(e.typeOver&&(r=!0),t==-1?{from:t,to:n}=e:(t=Math.min(e.from,t),n=Math.max(e.to,n)))}return{from:t,to:n,typeOver:r}}readChange(){let{from:e,to:t,typeOver:n}=this.processRecords(),r=this.selectionChanged&&jn(this.dom,this.selectionRange);if(e<0&&!r)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let i=new ua(this.view,e,t,n);return this.view.docView.domChanged={newSel:i.newSel?i.newSel.main:null},i}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.selectionChanged,n=this.readChange();if(!n)return this.view.requestMeasure(),!1;let r=this.view.state,i=fa(this.view,n);return this.view.state==r&&(n.domChanged||t)&&this.view.update([]),i}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type==`attributes`),e.type==`childList`){let n=Yo(t,e.previousSibling||e.target.previousSibling,-1),r=Yo(t,e.nextSibling||e.target.nextSibling,1);return{from:n?t.posAfter(n):t.posAtStart,to:r?t.posBefore(r):t.posAtEnd,typeOver:!1}}return e.type==`characterData`?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener(`resize`,this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener(`change`,this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener(`beforeprint`,this.onPrint),e.addEventListener(`scroll`,this.onScroll),e.document.addEventListener(`selectionchange`,this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener(`scroll`,this.onScroll),e.removeEventListener(`resize`,this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener(`change`,this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener(`beforeprint`,this.onPrint),e.document.removeEventListener(`selectionchange`,this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Vr)!=e.state.facet(Vr)&&(e.view.contentDOM.editContext=e.state.facet(Vr)?this.editContext.editContext:null))}destroy(){var e,t,n;this.stop(),(e=this.intersection)==null||e.disconnect(),(t=this.gapIntersection)==null||t.disconnect(),(n=this.resizeScroll)==null||n.disconnect();for(let e of this.scrollTargets)e.removeEventListener(`scroll`,this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}};function Yo(e,t,n){for(;t;){let r=R.get(t);if(r&&r.parent==e)return r;let i=t.parentNode;t=i==e.dom?n>0?t.nextSibling:t.previousSibling:i}return null}function Xo(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,a=t.endOffset,o=e.docView.domAtPos(e.state.selection.main.anchor,1);return Nn(o.node,o.offset,i,a)&&([n,r,i,a]=[i,a,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}}function Zo(e,t){if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return Xo(e,n)}let n=null;function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.contentDOM.addEventListener(`beforeinput`,r,!0),e.dom.ownerDocument.execCommand(`indent`),e.contentDOM.removeEventListener(`beforeinput`,r,!0),n?Xo(e,n):null}var Qo=class{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=n=>{let r=e.state.selection.main,{anchor:i,head:a}=r,o=this.toEditorPos(n.updateRangeStart),s=this.toEditorPos(n.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:n.updateRangeStart,editorBase:o,drifted:!1});let c=s-o>n.text.length;o==this.from&&i<this.from?o=i:s==this.to&&i>this.to&&(s=i);let l=ha(e.state.sliceDoc(o,s),n.text,(c?r.from:r.to)-o,c?`end`:null);if(!l){let t=O.single(this.toEditorPos(n.selectionStart),this.toEditorPos(n.selectionEnd));va(t,r)||e.dispatch({selection:t,userEvent:`select`});return}let u={from:l.from+o,to:l.toA+o,insert:x.of(n.text.slice(l.from,l.toB).split(`
10
+ `))};if((P.mac||P.android)&&u.from==a-1&&/^\. ?$/.test(n.text)&&e.contentDOM.getAttribute(`autocorrect`)==`off`&&(u={from:o,to:s,insert:x.of([n.text.replace(`.`,` `)])}),this.pendingContextChange=u,!e.state.readOnly){let t=this.to-this.from+(u.to-u.from+u.insert.length);pa(e,u,O.single(this.toEditorPos(n.selectionStart,t),this.toEditorPos(n.selectionEnd,t)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),u.from<u.to&&!u.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,n.updateRangeStart-1),Math.min(t.text.length,n.updateRangeStart+1)))&&this.handlers.compositionend(n)},this.handlers.characterboundsupdate=n=>{let r=[],i=null;for(let t=this.toEditorPos(n.rangeStart),a=this.toEditorPos(n.rangeEnd);t<a;t++){let n=e.coordsForChar(t);i=n&&new DOMRect(n.left,n.top,n.right-n.left,n.bottom-n.top)||i||new DOMRect,r.push(i)}t.updateCharacterBounds(n.rangeStart,r)},this.handlers.textformatupdate=t=>{let n=[];for(let e of t.getTextFormats()){let t=e.underlineStyle,r=e.underlineThickness;if(!/none/i.test(t)&&!/none/i.test(r)){let i=this.toEditorPos(e.rangeStart),a=this.toEditorPos(e.rangeEnd);if(i<a){let e=`text-decoration: underline ${/^[a-z]/.test(t)?t+` `:t==`Dashed`?`dashed `:t==`Squiggle`?`wavy `:``}${/thin/i.test(r)?1:2}px`;n.push(F.mark({attributes:{style:e}}).range(i,a))}}}e.dispatch({effects:zr.of(F.set(n))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:t}=this.composing;this.composing=null,t&&this.reset(e.state)}};for(let e in this.handlers)t.addEventListener(e,this.handlers[e]);this.measureReq={read:e=>{let t=kn(e.root);t&&t.rangeCount&&this.editContext.updateSelectionBounds(t.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,n=!1,r=this.pendingContextChange;return e.changes.iterChanges((i,a,o,s,c)=>{if(n)return;let l=c.length-(a-i);if(r&&a>=r.to){if(r.from==i&&r.to==a&&r.insert.eq(c)){r=this.pendingContextChange=null,t+=l,this.to+=l;return}r=null,this.revertPending(e.state)}if(i+=t,a+=t,a<=this.from)this.from+=l,this.to+=l;else if(i<this.to){if(i<this.from||a>this.to||this.to-this.from+c.length>3e4){n=!0;return}this.editContext.updateText(this.toContextPos(i),this.toContextPos(a),c.toString()),this.to+=l}t+=l}),r&&!n&&this.revertPending(e.state),!n}update(e){let t=this.pendingContextChange,n=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(n.from,n.to)&&e.transactions.some(e=>!e.isUserEvent(`input.type`)&&e.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,n=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),r=this.toContextPos(t.head);(this.editContext.selectionStart!=n||this.editContext.selectionEnd!=r)&&this.editContext.updateSelection(n,r)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>3e4)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let n=this.composing;return n&&n.drifted?n.editorBase+(e-n.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}},B=class e{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&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.clearAnnouncement=-1,this.contentDOM=document.createElement(`div`),this.scrollDOM=document.createElement(`div`),this.scrollDOM.tabIndex=-1,this.scrollDOM.className=`cm-scroller`,this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement(`div`),this.announceDOM.className=`cm-announced`,this.announceDOM.setAttribute(`aria-live`,`polite`),this.dom=document.createElement(`div`),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:t}=e;this.dispatchTransactions=e.dispatchTransactions||t&&(e=>e.forEach(e=>t(e,this)))||(e=>this.update(e)),this.dispatch=this.dispatch.bind(this),this._root=e.root||Zn(e.parent)||document,this.viewState=new Oo(this,e.state||j.create(e)),e.scrollTo&&e.scrollTo.is(Rr)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Ur).map(e=>new Gr(e));for(let e of this.plugins)e.update(this);this.observer=new Jo(this),this.inputState=new ya(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Ni(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),document.fonts?.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent=`refresh`,this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof Xe?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(t){if(this.updateState!=0)throw Error(`Calls to EditorView.update are not allowed while an update is in progress`);let n=!1,r=!1,i,a=this.state;for(let e of t){if(e.startState!=a)throw RangeError(`Trying to update state with a transaction that doesn't start from the previous state.`);a=e.state}if(this.destroyed){this.viewState.state=a;return}let o=this.hasFocus,s=0,c=null;t.some(e=>e.annotation(Qa))?(this.inputState.notifiedFocused=o,s=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,c=$a(a,o),c||(s=1));let l=this.observer.delayedAndroidKey,u=null;if(l?(this.observer.clearDelayedAndroidKey(),u=this.observer.readChange(),(u&&!this.state.doc.eq(a.doc)||!this.state.selection.eq(a.selection))&&(u=null)):this.observer.clear(),a.facet(j.phrases)!=this.state.facet(j.phrases))return this.setState(a);i=ai.create(this,a,t),i.flags|=s;let d=this.viewState.scrollTarget;try{this.updateState=2;for(let n of t){if(d&&=d.map(n.changes),n.scrollIntoView){let{main:t}=n.state.selection,{x:r,y:i}=this.state.facet(e.cursorScrollMargin);d=new Lr(t.empty?t:O.cursor(t.head,t.head>t.anchor?-1:1),`nearest`,`nearest`,i,r)}for(let e of n.effects)e.is(Rr)&&(d=e.value.clip(this.state))}this.viewState.update(i,d),this.bidiCache=ts.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),n=this.docView.update(i),this.state.facet(ri)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(t),this.docView.updateSelection(n,t.some(e=>e.isUserEvent(`select.pointer`)))}finally{this.updateState=0}if(i.startState.facet(Ro)!=i.state.facet(Ro)&&(this.viewState.mustMeasureContent=!0),(n||r||d||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),n&&this.docViewUpdate(),!i.empty)for(let e of this.state.facet(kr))try{e(i)}catch(e){Br(this.state,e,`update listener`)}(c||u)&&Promise.resolve().then(()=>{c&&this.state==c.startState&&this.dispatch(c),u&&!fa(this,u)&&l.force&&Xn(this.contentDOM,l.key,l.keyCode)})}setState(e){if(this.updateState!=0)throw Error(`Calls to EditorView.setState are not allowed while an update is in progress`);if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let e of this.plugins)e.destroy(this);this.viewState=new Oo(this,e),this.plugins=e.facet(Ur).map(e=>new Gr(e)),this.pluginMap.clear();for(let e of this.plugins)e.update(this);this.docView.destroy(),this.docView=new Ni(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Ur),n=e.state.facet(Ur);if(t!=n){let r=[];for(let i of n){let n=t.indexOf(i);if(n<0)r.push(new Gr(i));else{let t=this.plugins[n];t.mustUpdate=e,r.push(t)}}for(let t of this.plugins)t.mustUpdate!=e&&t.destroy(this);this.plugins=r,this.pluginMap.clear()}else for(let t of this.plugins)t.mustUpdate=e;for(let e=0;e<this.plugins.length;e++)this.plugins[e].update(this);t!=n&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(e){Br(this.state,e,`doc view update listener`)}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,n=this.viewState.scrollParent,r=this.viewState.getScrollOffset(),{scrollAnchorPos:i,scrollAnchorHeight:a,scaleY:o}=this.viewState;Math.abs(r-this.viewState.scrollOffset)>1&&(a=-1),this.viewState.scrollAnchorHeight=-1;try{for(let e=0;;e++){if(a<0){if($n(n||this.win))i=-1,a=this.viewState.heightMap.height/this.viewState.scaleY;else{let e=this.viewState.scrollAnchorAt(r);i=e.from,a=e.top}o=this.viewState.scaleY}this.updateState=1;let s=this.viewState.measure();if(!s&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(e>5){console.warn(this.measureRequests.length?`Measure loop restarted more than 5 times`:`Viewport failed to stabilize`);break}let c=[];s&4||([this.measureRequests,c]=[c,this.measureRequests]);let l=c.map(e=>{try{return e.read(this)}catch(e){return Br(this.state,e),es}}),u=ai.create(this,this.state,[]),d=!1;u.flags|=s,t?t.flags|=s:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),d=this.docView.update(u),d&&this.docViewUpdate());for(let e=0;e<c.length;e++)if(l[e]!=es)try{let t=c[e];t.write&&t.write(l[e],this)}catch(e){Br(this.state,e)}if(d&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight){if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,a=-1;continue}{let e=(i<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(i).top)/this.viewState.scaleY-a/o;if((e>1||e<-1)&&!(P.ios&&this.inputState.lastIOSMomentumScroll>Date.now()-100)&&(n==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){r+=e,n?i<0?n.scrollTop=n.scrollHeight:n.scrollTop+=e:this.win.scrollBy(0,e),a=-1;continue}}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let e of this.state.facet(kr))e(t)}get themeClasses(){return Bo+` `+(this.state.facet(zo)?Ho:Vo)+` `+this.state.facet(Ro)}updateAttrs(){let e=ns(this,Kr,{class:`cm-editor`+(this.hasFocus?` cm-focused `:` `)+this.themeClasses}),t={spellcheck:`false`,autocorrect:`off`,autocapitalize:`off`,writingsuggestions:`false`,translate:`no`,contenteditable:this.state.facet(Vr)?`true`:`false`,class:`cm-content`,style:`${P.tabSize}: ${this.state.tabSize}`,role:`textbox`,"aria-multiline":`true`};this.state.readOnly&&(t[`aria-readonly`]=`true`),ns(this,qr,t);let n=this.observer.ignore(()=>{let n=_n(this.contentDOM,this.contentAttrs,t),r=_n(this.dom,this.editorAttrs,e);return n||r});return this.editorAttrs=e,this.contentAttrs=t,n}showAnnouncements(t){let n=!0;for(let r of t)for(let t of r.effects)if(t.is(e.announce)){n&&=(this.announceDOM.textContent=``,this.win.clearTimeout(this.clearAnnouncement),this.clearAnnouncement=this.win.setTimeout(()=>{this.announceDOM.textContent=`\xA0`},200),!1);let e=this.announceDOM.appendChild(document.createElement(`div`));e.textContent=t.value}}mountStyles(){this.styleModules=this.state.facet(ri);let t=this.state.facet(e.cspNonce);Gt.mount(this.root,this.styleModules.concat(Go).reverse(),t?{nonce:t}:void 0)}readMeasured(){if(this.updateState==2)throw Error(`Reading the editor layout isn't allowed during an update`);this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(t=>t.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,n){return ta(this,e,Xi(this,e,t,n))}moveByGroup(e,t){return ta(this,e,Xi(this,e,t,t=>Zi(this,e.head,t)))}visualLineSide(e,t){return t?O.cursor(e.to,1):O.cursor(e.from,-1)}moveToLineBoundary(e,t,n=!0){return Yi(this,e,t,n)}moveVertically(e,t,n){return ta(this,e,Qi(this,e,t,n))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let n=ra(this,e,t);return n&&n.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),ra(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let n=this.state.doc.lineAt(e),r=this.bidiSpans(n),i=r[pr.find(r,e-n.from,-1,t)];return n.length&&(e==n.from&&t<0||e==n.to&&t>0)&&i.dir!=this.textDirectionAt(n.from)&&(e==n.to?(e=n.from+i.from,t=1):(e=n.from+i.to,t=-1)),this.docView.coordsAt(e,t,i.dir==rr.RTL)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Pr)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>$o)return xr(e.length);let t=this.textDirectionAt(e.from),n;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||mr(r.isolates,n=$r(this,e))))return r.order;n||=$r(this,e);let r=br(e.text,t,n);return this.bidiCache.push(new ts(e.from,e.to,t,n,!0,r)),r}get hasFocus(){return(this.dom.ownerDocument.hasFocus()||P.safari&&this.inputState?.lastContextMenu>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{qn(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.win.clearTimeout(this.clearAnnouncement),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){return Rr.of(new Lr(typeof e==`number`?O.cursor(e):e,t.y??`nearest`,t.x??`nearest`,t.yMargin??5,t.xMargin??5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,n=this.viewState.scrollAnchorAt(e);return Rr.of(new Lr(O.cursor(n.from),`start`,`start`,n.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e==`boolean`?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Wr.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Wr.define(()=>({}),{eventObservers:e})}static theme(e,t){let n=Gt.newName(),r=[Ro.of(n),ri.of(Wo(`.${n}`,e))];return t&&t.dark&&r.push(zo.of(!0)),r}static baseTheme(e){return Me.lowest(ri.of(Wo(`.`+Bo,e,Uo)))}static findFromDOM(e){let t=e.querySelector(`.cm-content`);return(t&&R.get(t)||R.get(e))?.root?.view||null}};B.styleModule=ri,B.inputHandler=Ar,B.clipboardInputFilter=Mr,B.clipboardOutputFilter=Nr,B.scrollHandler=Ir,B.focusChangeEffect=jr,B.perLineTextDirection=Pr,B.exceptionSink=Or,B.updateListener=kr,B.editable=Vr,B.mouseSelectionStyle=Dr,B.dragMovesSelection=Er,B.clickAddsSelectionRange=Tr,B.decorations=Jr,B.blockWrappers=Yr,B.outerDecorations=Xr,B.atomicRanges=Zr,B.bidiIsolatedRanges=Qr,B.cursorScrollMargin=k.define({combine:e=>{let t=5,n=5;for(let r of e)typeof r==`number`?t=n=r:{x:t,y:n}=r;return{x:t,y:n}}}),B.scrollMargins=ti,B.darkTheme=zo,B.cspNonce=k.define({combine:e=>e.length?e[0]:``}),B.contentAttributes=qr,B.editorAttributes=Kr,B.lineWrapping=B.contentAttributes.of({class:`cm-lineWrapping`}),B.announce=A.define();var $o=4096,es={},ts=class e{constructor(e,t,n,r,i,a){this.from=e,this.to=t,this.dir=n,this.isolates=r,this.fresh=i,this.order=a}static update(t,n){if(n.empty&&!t.some(e=>e.fresh))return t;let r=[],i=t.length?t[t.length-1].dir:rr.LTR;for(let a=Math.max(0,t.length-10);a<t.length;a++){let o=t[a];o.dir==i&&!n.touchesRange(o.from,o.to)&&r.push(new e(n.mapPos(o.from,1),n.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return r}};function ns(e,t,n){for(let r=e.state.facet(t),i=r.length-1;i>=0;i--){let t=r[i],a=typeof t==`function`?t(e):t;a&&pn(a,n)}return n}var rs=P.mac?`mac`:P.windows?`win`:P.linux?`linux`:`key`;function is(e,t){let n=e.split(/-(?!$)/),r=n[n.length-1];r==`Space`&&(r=` `);let i,a,o,s;for(let e=0;e<n.length-1;++e){let r=n[e];if(/^(cmd|meta|m)$/i.test(r))s=!0;else if(/^a(lt)?$/i.test(r))i=!0;else if(/^(c|ctrl|control)$/i.test(r))a=!0;else if(/^s(hift)?$/i.test(r))o=!0;else if(/^mod$/i.test(r))t==`mac`?s=!0:a=!0;else throw Error(`Unrecognized modifier name: `+r)}return i&&(r=`Alt-`+r),a&&(r=`Ctrl-`+r),s&&(r=`Meta-`+r),o&&(r=`Shift-`+r),r}function as(e,t,n){return t.altKey&&(e=`Alt-`+e),t.ctrlKey&&(e=`Ctrl-`+e),t.metaKey&&(e=`Meta-`+e),n!==!1&&t.shiftKey&&(e=`Shift-`+e),e}var os=Me.default(B.domEventHandlers({keydown(e,t){return ms(ls(t.state),e,t,`editor`)}})),ss=k.define({enables:os}),cs=new WeakMap;function ls(e){let t=e.facet(ss),n=cs.get(t);return n||cs.set(t,n=fs(t.reduce((e,t)=>e.concat(t),[]))),n}var us=null,ds=4e3;function fs(e,t=rs){let n=Object.create(null),r=Object.create(null),i=(e,t)=>{let n=r[e];if(n==null)r[e]=t;else if(n!=t)throw Error(`Key binding `+e+` is used both as a regular binding and as a multi-stroke prefix`)},a=(e,r,a,o,s)=>{let c=n[e]||(n[e]=Object.create(null)),l=r.split(/ (?!$)/).map(e=>is(e,t));for(let t=1;t<l.length;t++){let n=l.slice(0,t).join(` `);i(n,!0),c[n]||(c[n]={preventDefault:!0,stopPropagation:!1,run:[t=>{let r=us={view:t,prefix:n,scope:e};return setTimeout(()=>{us==r&&(us=null)},ds),!0}]})}let u=l.join(` `);i(u,!1);let d=c[u]||(c[u]={preventDefault:!1,stopPropagation:!1,run:(c._any?.run)?.slice()||[]});a&&d.run.push(a),o&&(d.preventDefault=!0),s&&(d.stopPropagation=!0)};for(let r of e){let e=r.scope?r.scope.split(` `):[`editor`];if(r.any)for(let t of e){let e=n[t]||(n[t]=Object.create(null));e._any||={preventDefault:!1,stopPropagation:!1,run:[]};let{any:i}=r;for(let t in e)e[t].run.push(e=>i(e,ps))}let i=r[t]||r.key;if(i)for(let t of e)a(t,i,r.run,r.preventDefault,r.stopPropagation),r.shift&&a(t,`Shift-`+i,r.shift,r.preventDefault,r.stopPropagation)}return n}var ps=null;function ms(e,t,n,r){ps=t;let i=en(t),a=le(se(i,0))==i.length&&i!=` `,o=``,s=!1,c=!1,l=!1;us&&us.view==n&&us.scope==r&&(o=us.prefix+` `,Ta.indexOf(t.keyCode)<0&&(c=!0,us=null));let u=new Set,d=e=>{if(e){for(let t of e.run)if(!u.has(t)&&(u.add(t),t(n)))return e.stopPropagation&&(l=!0),!0;e.preventDefault&&(e.stopPropagation&&(l=!0),c=!0)}return!1},f=e[r],p,m;return f&&(d(f[o+as(i,t,!a)])?s=!0:a&&(t.altKey||t.metaKey||t.ctrlKey)&&!(P.windows&&t.ctrlKey&&t.altKey)&&!(P.mac&&t.altKey&&!(t.ctrlKey||t.metaKey))&&(p=Jt[t.keyCode])&&p!=i?(d(f[o+as(p,t,!0)])||t.shiftKey&&(m=Yt[t.keyCode])!=i&&m!=p&&d(f[o+as(m,t,!1)]))&&(s=!0):a&&t.shiftKey&&d(f[o+as(i,t,!0)])&&(s=!0),!s&&d(f._any)&&(s=!0)),c&&(s=!0),s&&l&&t.stopPropagation(),ps=null,s}var hs=!P.ios,gs=P.gecko&&P.gecko_version==153?`#ffffff01`:`transparent`;({...hs?{"& ::selection, &::selection":{backgroundColor:`${gs} !important`}}:{}}),{...hs?{"&::selection, & ::selection":{backgroundColor:`Highlight !important`}}:{}},/x/.unicode;var _s=class extends ut{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}};_s.prototype.elementClass=``,_s.prototype.toDOM=void 0,_s.prototype.mapMode=de.TrackBefore,_s.prototype.startSide=_s.prototype.endSide=-1,_s.prototype.point=!0;var vs=k.define(),ys=1024,bs=0,V=class{constructor(e={}){this.id=bs++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw Error(`This node type doesn't define a deserialize function`)}),this.combine=e.combine||null}add(e){if(this.perNode)throw RangeError(`Can't add per-node props to node types`);return typeof e!=`function`&&(e=Cs.match(e)),t=>{let n=e(t);return n===void 0?null:[this,n]}}};V.closedBy=new V({deserialize:e=>e.split(` `)}),V.openedBy=new V({deserialize:e=>e.split(` `)}),V.group=new V({deserialize:e=>e.split(` `)}),V.isolate=new V({deserialize:e=>{if(e&&e!=`rtl`&&e!=`ltr`&&e!=`auto`)throw RangeError(`Invalid value for isolate: `+e);return e||`auto`}}),V.contextHash=new V({perNode:!0}),V.lookAhead=new V({perNode:!0}),V.mounted=new V({perNode:!0});var xs=class{constructor(e,t,n,r=!1){this.tree=e,this.overlay=t,this.parser=n,this.bracketed=r}static get(e){return e&&e.props&&e.props[V.mounted.id]}},Ss=Object.create(null),Cs=class e{constructor(e,t,n,r=0){this.name=e,this.props=t,this.id=n,this.flags=r}static define(t){let n=t.props&&t.props.length?Object.create(null):Ss,r=+!!t.top|(t.skipped?2:0)|(t.error?4:0)|(t.name==null?8:0),i=new e(t.name||``,n,t.id,r);if(t.props){for(let e of t.props)if(Array.isArray(e)||(e=e(i)),e){if(e[0].perNode)throw RangeError(`Can't store a per-node prop on a node type`);n[e[0].id]=e[1]}}return i}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e==`string`){if(this.name==e)return!0;let t=this.prop(V.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let n in e)for(let r of n.split(` `))t[r]=e[n];return e=>{for(let n=e.prop(V.group),r=-1;r<(n?n.length:0);r++){let i=t[r<0?e.name:n[r]];if(i)return i}}}};Cs.none=new Cs(``,Object.create(null),0,8);var ws=new WeakMap,Ts=new WeakMap,H;(function(e){e[e.ExcludeBuffers=1]=`ExcludeBuffers`,e[e.IncludeAnonymous=2]=`IncludeAnonymous`,e[e.IgnoreMounts=4]=`IgnoreMounts`,e[e.IgnoreOverlays=8]=`IgnoreOverlays`,e[e.EnterBracketed=16]=`EnterBracketed`})(H||={});var Es=class e{constructor(e,t,n,r,i){if(this.type=e,this.children=t,this.positions=n,this.length=r,this.props=null,i&&i.length){this.props=Object.create(null);for(let[e,t]of i)this.props[typeof e==`number`?e:e.id]=t}}toString(){let e=xs.get(this);if(e&&!e.overlay)return e.tree.toString();let t=``;for(let e of this.children){let n=e.toString();n&&(t&&(t+=`,`),t+=n)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?`(`+t+`)`:``):t}cursor(e=0){return new Bs(this.topNode,e)}cursorAt(e,t=0,n=0){let r=new Bs(ws.get(this)||this.topNode);return r.moveTo(e,t),ws.set(this,r._tree),r}get topNode(){return new Ms(this,0,0,null)}resolve(e,t=0){let n=As(ws.get(this)||this.topNode,e,t,!1);return ws.set(this,n),n}resolveInner(e,t=0){let n=As(Ts.get(this)||this.topNode,e,t,!0);return Ts.set(this,n),n}resolveStack(e,t=0){return zs(this,e,t)}iterate(e){let{enter:t,leave:n,from:r=0,to:i=this.length}=e,a=e.mode||0,o=(a&H.IncludeAnonymous)>0;for(let e=this.cursor(a|H.IncludeAnonymous);;){let a=!1;if(e.from<=i&&e.to>=r&&(!o&&e.type.isAnonymous||t(e)!==!1)){if(e.firstChild())continue;a=!0}for(;a&&n&&(o||!e.type.isAnonymous)&&n(e),!e.nextSibling();){if(!e.parent())return;a=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(t={}){return this.children.length<=8?this:Gs(Cs.none,this.children,this.positions,0,this.children.length,0,this.length,(t,n,r)=>new e(this.type,t,n,r,this.propValues),t.makeTree||((t,n,r)=>new e(Cs.none,t,n,r)))}static build(e){return Hs(e)}};Es.empty=new Es(Cs.none,[],[],0);var Ds=class e{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new e(this.buffer,this.index)}},Os=class e{constructor(e,t,n){this.buffer=e,this.length=t,this.set=n}get type(){return Cs.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(`,`)}childString(e){let t=this.buffer[e],n=this.buffer[e+3],r=this.set.types[t],i=r.name;if(/\W/.test(i)&&!r.isError&&(i=JSON.stringify(i)),e+=4,n==e)return i;let a=[];for(;e<n;)a.push(this.childString(e)),e=this.buffer[e+3];return i+`(`+a.join(`,`)+`)`}findChild(e,t,n,r,i){let{buffer:a}=this,o=-1;for(let s=e;s!=t&&!(ks(i,r,a[s+1],a[s+2])&&(o=s,n>0));s=a[s+3]);return o}slice(t,n,r){let i=this.buffer,a=new Uint16Array(n-t),o=0;for(let e=t,s=0;e<n;){a[s++]=i[e++],a[s++]=i[e++]-r;let n=a[s++]=i[e++]-r;a[s++]=i[e++]-t,o=Math.max(o,n)}return new e(a,o,this.set)}};function ks(e,t,n,r){switch(e){case-2:return n<t;case-1:return r>=t&&n<t;case 0:return n<t&&r>t;case 1:return n<=t&&r>t;case 2:return r>t;case 4:return!0}}function As(e,t,n,r){for(;e.from==e.to||(n<1?e.from>=t:e.from>t)||(n>-1?e.to<=t:e.to<t);){let t=!r&&e instanceof Ms&&e.index<0?null:e.parent;if(!t)return e;e=t}let i=r?0:H.IgnoreOverlays;if(r)for(let r=e,a=r.parent;a;r=a,a=r.parent)r instanceof Ms&&r.index<0&&a.enter(t,n,i)?.from!=r.from&&(e=a);for(;;){let r=e.enter(t,n,i);if(!r)return e;e=r}}var js=class{cursor(e=0){return new Bs(this,e)}getChild(e,t=null,n=null){let r=Ns(this,e,t,n);return r.length?r[0]:null}getChildren(e,t=null,n=null){return Ns(this,e,t,n)}resolve(e,t=0){return As(this,e,t,!1)}resolveInner(e,t=0){return As(this,e,t,!0)}matchContext(e){return Ps(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),n=this;for(;t;){let e=t.lastChild;if(!e||e.to!=t.to)break;e.type.isError&&e.from==e.to?(n=t,t=e.prevSibling):t=e}return n}get node(){return this}get next(){return this.parent}},Ms=class e extends js{constructor(e,t,n,r){super(),this._tree=e,this.from=t,this.index=n,this._parent=r}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(t,n,r,i,a=0){for(let o=this;;){for(let{children:s,positions:c}=o._tree,l=n>0?s.length:-1;t!=l;t+=n){let l=s[t],u=c[t]+o.from,d;if(a&H.EnterBracketed&&l instanceof Es&&(d=xs.get(l))&&!d.overlay&&d.bracketed&&r>=u&&r<=u+l.length||ks(i,r,u,u+l.length)){if(l instanceof Os){if(a&H.ExcludeBuffers)continue;let e=l.findChild(0,l.buffer.length,n,r-u,i);if(e>-1)return new Is(new Fs(o,l,t,u),null,e)}else if(a&H.IncludeAnonymous||!l.type.isAnonymous||Vs(l)){let s;if(!(a&H.IgnoreMounts)&&(s=xs.get(l))&&!s.overlay)return new e(s.tree,u,t,o);let c=new e(l,u,t,o);return a&H.IncludeAnonymous||!c.type.isAnonymous?c:c.nextChild(n<0?l.children.length-1:0,n,r,i,a)}}}if(a&H.IncludeAnonymous||!o.type.isAnonymous||(t=o.index>=0?o.index+n:n<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(t,n,r=0){let i;if(!(r&H.IgnoreOverlays)&&(i=xs.get(this._tree))&&i.overlay){let a=t-this.from,o=r&H.EnterBracketed&&i.bracketed;for(let{from:t,to:r}of i.overlay)if((n>0||o?t<=a:t<a)&&(n<0||o?r>=a:r>a))return new e(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,t,n,r)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}};function Ns(e,t,n,r){let i=e.cursor(),a=[];if(!i.firstChild())return a;if(n!=null){for(let e=!1;!e;)if(e=i.type.is(n),!i.nextSibling())return a}for(;;){if(r!=null&&i.type.is(r))return a;if(i.type.is(t)&&a.push(i.node),!i.nextSibling())return r==null?a:[]}}function Ps(e,t,n=t.length-1){for(let r=e;n>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(t[n]&&t[n]!=r.name)return!1;n--}}return!0}var Fs=class{constructor(e,t,n,r){this.parent=e,this.buffer=t,this.index=n,this.start=r}},Is=class e extends js{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,n){super(),this.context=e,this._parent=t,this.index=n,this.type=e.buffer.set.types[e.buffer.buffer[n]]}child(t,n,r){let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],t,n-this.context.start,r);return a<0?null:new e(this.context,this,a)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(t,n,r=0){if(r&H.ExcludeBuffers)return null;let{buffer:i}=this.context,a=i.findChild(this.index+4,i.buffer[this.index+3],n>0?1:-1,t-this.context.start,n);return a<0?null:new e(this.context,this,a)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:t}=this.context,n=t.buffer[this.index+3];return n<(this._parent?t.buffer[this._parent.index+3]:t.buffer.length)?new e(this.context,this._parent,n):this.externalSibling(1)}get prevSibling(){let{buffer:t}=this.context,n=this._parent?this._parent.index+4:0;return this.index==n?this.externalSibling(-1):new e(this.context,this._parent,t.findChild(n,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:n}=this.context,r=this.index+4,i=n.buffer[this.index+3];if(i>r){let a=n.buffer[this.index+1];e.push(n.slice(r,i,a)),t.push(0)}return new Es(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}};function Ls(e){if(!e.length)return null;let t=0,n=e[0];for(let r=1;r<e.length;r++){let i=e[r];(i.from>n.from||i.to<n.to)&&(n=i,t=r)}let r=n instanceof Ms&&n.index<0?null:n.parent,i=e.slice();return r?i[t]=r:i.splice(t,1),new Rs(i,n)}var Rs=class{constructor(e,t){this.heads=e,this.node=t}get next(){return Ls(this.heads)}};function zs(e,t,n){let r=e.resolveInner(t,n),i=null;for(let e=r instanceof Ms?r:r.context.parent;e;e=e.parent)if(e.index<0){let a=e.parent;(i||=[r]).push(a.resolve(t,n)),e=a}else{let a=xs.get(e.tree);if(a&&a.overlay&&a.overlay[0].from<=t&&a.overlay[a.overlay.length-1].to>=t){let o=new Ms(a.tree,a.overlay[0].from+e.from,-1,e);(i||=[r]).push(As(o,t,n,!1))}}return i?Ls(i):r}var Bs=class{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~H.EnterBracketed,e instanceof Ms)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let t=e._parent;t;t=t._parent)this.stack.unshift(t.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:n,buffer:r}=this.buffer;return this.type=t||r.set.types[r.buffer[e]],this.from=n+r.buffer[e+1],this.to=n+r.buffer[e+2],!0}yield(e){return e?e instanceof Ms?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,n){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,n,this.mode));let{buffer:r}=this.buffer,i=r.findChild(this.index+4,r.buffer[this.index+3],e,t-this.buffer.start,n);return i<0?!1:(this.stack.push(this.index),this.yieldBuf(i))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,n=this.mode){return this.buffer?n&H.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,n))}parent(){if(!this.buffer)return this.yieldNode(this.mode&H.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&H.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,n=this.stack.length-1;if(e<0){let e=n<0?0:this.stack[n]+4;if(this.index!=e)return this.yieldBuf(t.findChild(e,this.index,-1,0,4))}else{let e=t.buffer[this.index+3];if(e<(n<0?t.buffer.length:t.buffer[this.stack[n]+3]))return this.yieldBuf(e)}return n<0&&this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode))}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,n,{buffer:r}=this;if(r){if(e>0){if(this.index<r.buffer.buffer.length)return!1}else for(let e=0;e<this.index;e++)if(r.buffer.buffer[e+3]<this.index)return!1;({index:t,parent:n}=r)}else({index:t,_parent:n}=this._tree);for(;n;{index:t,_parent:n}=n)if(t>-1)for(let r=t+e,i=e<0?-1:n._tree.children.length;r!=i;r+=e){let e=n._tree.children[r];if(this.mode&H.IncludeAnonymous||e instanceof Os||!e.type.isAnonymous||Vs(e))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,n=0;if(e&&e.context==this.buffer)scan:for(let r=this.index,i=this.stack.length;i>=0;){for(let a=e;a;a=a._parent)if(a.index==r){if(r==this.index)return a;t=a,n=i+1;break scan}r=this.stack[--i]}for(let e=n;e<this.stack.length;e++)t=new Is(this.buffer,t,this.stack[e]);return this.bufferNode=new Is(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let n=0;;){let r=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){n++;continue}this.type.isAnonymous||(r=!0)}for(;;){if(r&&t&&t(this),r=this.type.isAnonymous,!n)return;if(this.nextSibling())break;this.parent(),n--,r=!0}}}matchContext(e){if(!this.buffer)return Ps(this.node.parent,e);let{buffer:t}=this.buffer,{types:n}=t.set;for(let r=e.length-1,i=this.stack.length-1;r>=0;i--){if(i<0)return Ps(this._tree,e,r);let a=n[t.buffer[this.stack[i]]];if(!a.isAnonymous){if(e[r]&&e[r]!=a.name)return!1;r--}}return!0}};function Vs(e){return e.children.some(e=>e instanceof Os||!e.type.isAnonymous||Vs(e))}function Hs(e){let{buffer:t,nodeSet:n,maxBufferLength:r=ys,reused:i=[],minRepeatType:a=n.types.length}=e,o=Array.isArray(t)?new Ds(t,t.length):t,s=n.types,c=0,l=0;function u(e,t,_,v,y,b){let{id:x,start:S,end:C,size:w}=o,ee=l,T=c;if(w<0){if(o.next(),w==-1){let t=i[x];_.push(t),v.push(S-e);return}if(w==-3){c=x;return}if(w==-4){l=x;return}throw RangeError(`Unrecognized record size: ${w}`)}let te=s[x],E,ne,re=S-e;if(C-S<=r&&(ne=h(o.pos-t,y))){let t=new Uint16Array(ne.size-ne.skip),r=o.pos-ne.size,i=t.length;for(;o.pos>r;)i=g(ne.start,t,i);E=new Os(t,C-ne.start,n),re=ne.start-e}else{let e=o.pos-w;o.next();let t=[],s=[],c=x>=a?x:-1,h=0,g=C,_=ee;for(;o.pos>e;)c>=0&&o.id==c&&o.size>=0?(o.end<=g-r&&(p(t,s,S,h,o.end,g,c,_,T),h=t.length,g=o.end,_=l),o.next()):b>2500?d(S,e,t,s):(c>=0&&o.size==-1&&i[o.id].type==n.types[c]&&(h<t.length&&p(t,s,S,h,o.end,g,c,_,T),h=t.length+1,g=o.start,_=l),u(S,e,t,s,c,b+1));if(c>=0&&h>0&&h<t.length&&p(t,s,S,h,S,g,c,_,T),t.reverse(),s.reverse(),c>-1&&h>0){let e=f(te,T);E=Gs(te,t,s,0,t.length,0,C-S,e,e)}else E=m(te,t,s,C-S,ee-C,T)}_.push(E),v.push(re)}function d(e,t,i,a){let s=[],c=0,l=-1;for(;o.pos>t;){let{id:e,start:t,end:n,size:i}=o;if(i>4)o.next();else if(l>-1&&t<l)break;else l<0&&(l=n-r),s.push(e,t,n),c++,o.next()}if(c){let t=new Uint16Array(c*4),r=s[s.length-2];for(let e=s.length-3,n=0;e>=0;e-=3)t[n++]=s[e],t[n++]=s[e+1]-r,t[n++]=s[e+2]-r,t[n++]=n;i.push(new Os(t,s[2]-r,n)),a.push(r-e)}}function f(e,t){return(n,r,i)=>{let a=0,o=n.length-1,s,c;if(o>=0&&(s=n[o])instanceof Es){if(!o&&s.type==e&&s.length==i)return s;(c=s.prop(V.lookAhead))&&(a=r[o]+s.length+c-i)}return m(e,n,r,i,a,t)}}function p(e,t,r,i,a,o,s,c,l){let u=[],d=[];for(;e.length>i;)u.push(e.pop()),d.push(t.pop()+r-a);e.push(m(n.types[s],u,d,o-a,c-o,l)),t.push(a-r)}function m(e,t,n,r,i,a,o){if(a){let e=[V.contextHash,a];o=o?[e].concat(o):[e]}if(i>25){let e=[V.lookAhead,i];o=o?[e].concat(o):[e]}return new Es(e,t,n,r,o)}function h(e,t){let n=o.fork(),i=0,s=0,c=0,l=n.end-r,u={size:0,start:0,skip:0};scan:for(let r=n.pos-e;n.pos>r;){let e=n.size;if(n.id==t&&e>=0){u.size=i,u.start=s,u.skip=c,c+=4,i+=4,n.next();continue}let o=n.pos-e;if(e<0||o<r||n.start<l)break;let d=n.id>=a?4:0,f=n.start;for(n.next();n.pos>o;){if(n.size<0){if(n.size==-3||n.size==-4)d+=4;else break scan}else n.id>=a&&(d+=4);n.next()}s=f,i+=e,c+=d}return(t<0||i==e)&&(u.size=i,u.start=s,u.skip=c),u.size>4?u:void 0}function g(e,t,n){let{id:r,start:i,end:s,size:u}=o;if(o.next(),u>=0&&r<a){let a=n;if(u>4){let r=o.pos-(u-4);for(;o.pos>r;)n=g(e,t,n)}t[--n]=a,t[--n]=s-e,t[--n]=i-e,t[--n]=r}else u==-3?c=r:u==-4&&(l=r);return n}let _=[],v=[];for(;o.pos>0;)u(e.start||0,e.bufferStart||0,_,v,-1,0);let y=e.length??(_.length?v[0]+_[0].length:0);return new Es(s[e.topID],_.reverse(),v.reverse(),y)}var Us=new WeakMap;function Ws(e,t){if(!e.isAnonymous||t instanceof Os||t.type!=e)return 1;let n=Us.get(t);if(n==null){n=1;for(let r of t.children){if(r.type!=e||!(r instanceof Es)){n=1;break}n+=Ws(e,r)}Us.set(t,n)}return n}function Gs(e,t,n,r,i,a,o,s,c){let l=0;for(let n=r;n<i;n++)l+=Ws(e,t[n]);let u=Math.ceil(l*1.5/8),d=[],f=[];function p(t,n,r,i,o){for(let s=r;s<i;){let r=s,l=n[s],m=Ws(e,t[s]);for(s++;s<i;s++){let n=Ws(e,t[s]);if(m+n>=u)break;m+=n}if(s==r+1){if(m>u){let e=t[r];p(e.children,e.positions,0,e.children.length,n[r]+o);continue}d.push(t[r])}else{let i=n[s-1]+t[s-1].length-l;d.push(Gs(e,t,n,r,s,l,i,null,c))}f.push(l+o-a)}}return p(t,n,r,i,0),(s||c)(d,f,o)}new V({perNode:!0});var Ks=qe.define(),qs=qe.define(),Js=k.define(),Ys=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&pe.fromJSON(t.changes),[],t.mapped&&fe.fromJSON(t.mapped),t.startSelection&&O.fromJSON(t.startSelection),t.selectionsAfter.map(O.fromJSON))}static fromTransaction(t,n){let r=ec;for(let e of t.startState.facet(Js)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,ec)}static selection(t){return new e(void 0,ec,void 0,void 0,t)}};function Xs(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function Zs(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function Qs(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function $s(e,t){return e.length?t.length?e.concat(t):e:t}var ec=[],tc=200;function nc(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-tc));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),Xs(e,e.length-1,1e9,n.setSelAfter(r)))}return[Ys.selection([t])]}function rc(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function ic(e,t){if(!e.length)return e;let n=e.length,r=ec;for(;n;){let i=ac(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}t=i.mapped,n--,r=i.selectionsAfter}return r.length?[Ys.selection(r)]:ec}function ac(e,t,n){let r=$s(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):ec,n);if(!e.changes)return Ys.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new Ys(i,A.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var oc=/^(input\.type|delete)($|\.)/,sc=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||oc.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,Zs(s.changes,t.changes))||r==`input.type.compose`)?Xs(o,o.length-1,i.minDepth,new Ys(t.changes.compose(s.changes),$s(A.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,ec)):Xs(o,o.length,i.minDepth,t),new e(o,ec,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:ec;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&Qs(a[a.length-1],t)?this:new e(nc(this.done,t),this.undone,n,r)}addMapping(t){return new e(ic(this.done,t),ic(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:Ks.of({side:e,rest:rc(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?ec:r.slice(0,r.length-1);return i.mapped&&(n=ic(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:Ks.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}return null}};sc.empty=new sc(ec,ec),typeof Intl<`u`&&Intl.Segmenter;var cc=/\p{M}/u;function lc(e){return e<768?1:e<=879?0:e<4352?e>=1155&&cc.test(String.fromCodePoint(e))?0:1:e<=4447?2:e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e===8204||e===8205||e>=65024&&e<=65039||e>=65056&&e<=65071?0:e<11904?e===8986||e===8987||e===9193||e===9194||e===9195||e===9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e===10067||e===10068||e===10069||e===10071||e===10133||e===10134||e===10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093?2:1:e<=12350||e>=12353&&e<=13311||e>=13312&&e<=19903||e>=19968&&e<=40959||e>=40960&&e<=42191||e>=43360&&e<=43391||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65072&&e<=65103||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=127744&&e<=128591||e>=128640&&e<=128767||e>=129280&&e<=129535||e>=129648&&e<=129791?2:e>=127462&&e<=127487?1:e>=131072&&e<=262141?2:1}function uc(e,t=0,n=e.length){let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i);if(t<768)r++;else{if(t>=55296&&t<=56319&&i+1<n){let n=e.charCodeAt(i+1);if(n>=56320&&n<=57343){r+=lc((t-55296<<10)+(n-56320)+65536),i++;continue}}r+=lc(t)}}return r}var U={kind:0,dot:-1,comma:-1},dc=new Set([`na`,`n/a`,`nan`,`null`,`none`,`nil`,`\\n`,`-`,`--`,`—`,`–`,`#n/a`,`?`,`.`]),fc=`USD.EUR.GBP.JPY.CNY.RMB.CHF.CAD.AUD.NZD.HKD.SGD.TWD.KRW.INR.PKR.BDT.LKR.IDR.MYR.THB.VND.PHP.SEK.NOK.DKK.ISK.PLN.CZK.HUF.RON.BGN.RSD.RUB.UAH.TRY.ILS.AED.SAR.QAR.KWD.EGP.MAD.ZAR.NGN.KES.MXN.BRL.ARS.CLP.COP.PEN.UYU.BOB.PYG.VES.CRC.GTQ.DOP.BTC.ETH`.split(`.`),pc=[`k`,`m`,`mm`,`mn`,`b`,`bn`,`st`,`nd`,`rd`,`th`,`º`,`ª`,`pp`,`pts`,`bps`,`pcs`,`nm`,`µm`,`μm`,`cm`,`dm`,`km`,`in`,`ft`,`yd`,`mi`,`nmi`,`m²`,`m2`,`km²`,`km2`,`cm²`,`cm2`,`ft²`,`ft2`,`sq ft`,`sq m`,`ha`,`ac`,`m³`,`m3`,`cm³`,`cm3`,`cc`,`l`,`ml`,`cl`,`dl`,`hl`,`gal`,`qt`,`fl oz`,`µg`,`μg`,`mg`,`g`,`kg`,`t`,`lb`,`lbs`,`oz`,`ns`,`µs`,`μs`,`ms`,`s`,`sec`,`secs`,`min`,`mins`,`h`,`hr`,`hrs`,`d`,`wk`,`wks`,`mo`,`yr`,`yrs`,`kb`,`mb`,`gb`,`tb`,`pb`,`kib`,`mib`,`gib`,`tib`,`bit`,`bits`,`kbit`,`mbit`,`kbps`,`mbps`,`gbps`,`kb/s`,`mb/s`,`hz`,`khz`,`mhz`,`ghz`,`rpm`,`fps`,`dpi`,`ppi`,`px`,`pt`,`w`,`kw`,`mw`,`gw`,`wh`,`kwh`,`mwh`,`gwh`,`j`,`kj`,`mj`,`cal`,`kcal`,`hp`,`cv`,`btu`,`v`,`mv`,`kv`,`a`,`ma`,`mah`,`ω`,`kω`,`va`,`kva`,`°`,`°c`,`°f`,`ºc`,`ºf`,`km/h`,`kmh`,`kph`,`mph`,`m/s`,`kn`,`kt`,`kts`,`pa`,`kpa`,`hpa`,`mpa`,`bar`,`mbar`,`psi`,`atm`,`mmhg`,`db`,`ppm`,`ppb`,`mol`,`lm`,`lx`,`kr`,`zł`,`kč`,`lei`,`r$`,...fc.map(e=>e.toLowerCase())],mc=new Uint8Array(17576);for(let e of fc)mc[vc(e,0)]=1;var hc=new Set,gc=new Set;for(let e of pc){let t=yc(e,0,e.length);t>=0?hc.add(t):gc.add(e)}var _c=Math.max(...pc.map(e=>e.length));function vc(e,t){return(e.charCodeAt(t)-65)*676+(e.charCodeAt(t+1)-65)*26+e.charCodeAt(t+2)-65}function yc(e,t,n){if(n-t>4)return-1;let r=0;for(let i=t;i<n;i++){let t=e.charCodeAt(i),n=t|32,a=n>=97&&n<=122?n-96:t>=48&&t<=57?t-21:-1;if(a<0)return-1;r=r*37+a}return r}var bc=e=>e>=48&&e<=57||e>=1632&&(e<=1641||e>=1776&&e<=1785),xc=e=>e>=65&&e<=90,Sc=e=>e===32,Cc=e=>e===45||e===43||e===8722,wc=e=>e===36||e===162||e===163||e===165||e>=8352&&e<=8384||e===65020,Tc=1643,Ec=1644,Dc=1642,Oc=e=>e===160||e===8239||e===8201,kc=e=>e===32||Oc(e),Ac=e=>(e>=65&&e<=90||e>=97&&e<=122)&&e!==78&&e!==110,jc=e=>e===78||e===110||e===45||e===8212||e===8211||e===35||e===63||e===46||e===92;function Mc(e,t,n){let r=t;for(;r<n&&r-t<3&&xc(e.charCodeAt(r));)r++;return r===t?0:r<n&&e.charCodeAt(r)===36?r+1-t:r-t===3&&mc[vc(e,t)]?3:0}function Nc(e,t,n){let r=e.charCodeAt(t);if(!((r|32)>=97&&(r|32)<=122)&&r<128)return 0;let i=n;for(;i>t&&kc(e.charCodeAt(i-1));)i--;let a=yc(e,t,i);return a>=0?hc.has(a)?i-t:0:i-t<=_c&&gc.has(e.slice(t,i).toLowerCase())?i-t:0}function Pc(e,t,n,r,i){let a=t,o=0,s=0,c=!1;for(;a<n;a++){let t=e.charCodeAt(a);if(bc(t))o++,s++;else{if(t===r)break;if(t!==i&&!Oc(t)||(c?o!==3:o<1||o>3))return-1;c=!0,o=0}}if(c&&o!==3)return-1;let l=a;if(a<n){let t=0;for(a++;a<n;a++){if(!bc(e.charCodeAt(a)))return-1;t++}if(!t&&!s)return-1}else if(!s)return-1;return l}function Fc(e,t,n,r=!1){if(U.kind=1,U.dot=U.comma=-1,r&&(n-t<2||e.charCodeAt(n-1)!==34||(t++,n--,e.indexOf(`"`,t)<n)))return U;let i=t,a=i<n?e.charCodeAt(i):-1;for(;Sc(a);)a=++i<n?e.charCodeAt(i):-1;if(i===n)return U.kind=0,U;let o=i;if(Ac(a)&&!(xc(a)&&Mc(e,i,n)))return U;let s=!1;if(!bc(a)){let t=!1;for(;;)if(!t&&Cc(a))t=!0,a=++i<n?e.charCodeAt(i):-1;else{if(!s){let t=wc(a)?1:xc(a)?Mc(e,i,n):0;if(t){for(s=!0,i+=t,a=i<n?e.charCodeAt(i):-1;kc(a);)a=++i<n?e.charCodeAt(i):-1;continue}}break}}let c=i,l=0,u=-1,d=!1,f=!1;for(;i<n;a=++i<n?e.charCodeAt(i):-1)if(!bc(a)){if(a===46||a===44)l++,u=i;else if(a===Tc||a===Ec)l++,f=!0;else if(Oc(a)&&i+1<n&&bc(e.charCodeAt(i+1)))l++,d=!0;else break}let p=i;if(p>c){if(i<n){if((a===101||a===69)&&i+1<n){let t=i+1;if(Cc(e.charCodeAt(t))&&t++,t<n&&bc(e.charCodeAt(t))){for(;t<n&&bc(e.charCodeAt(t));)t++;i=t,a=i<n?e.charCodeAt(i):-1}}for(;kc(a);)a=++i<n?e.charCodeAt(i):-1;for(a===37||a===8240||a===Dc||!s&&wc(a)?i++:i<n&&(i+=Nc(e,i,n));i<n&&kc(e.charCodeAt(i));)i++;if(i<n)return U}if(i===n){if(!l)return U.kind=2,U.dot=U.comma=p,U;if(f)U.dot=U.comma=Pc(e,c,p,Tc,Ec);else if(l===1&&!d){let t=u-c,n=p-u-1,r=n>0||t>0?u:-1,i=t>=1&&t<=3&&n===3?p:-1,a=e.charCodeAt(u)===46;U.dot=a?r:i,U.comma=a?i:r}else U.dot=Pc(e,c,p,46,44),U.comma=Pc(e,c,p,44,46);if(U.dot>=0||U.comma>=0)return U.kind=2,U}}if(!jc(e.charCodeAt(o)))return U;let m=n;for(;m>o&&Sc(e.charCodeAt(m-1));)m--;return m-o<=4&&dc.has(e.slice(o,m).toLowerCase())&&(U.kind=0),U}var Ic=e=>e===32,Lc=e=>e>=48&&e<=57||(e|32)>=97&&(e|32)<=122||e>=128,Rc=e=>Lc(e)||e===46||e===95||e===45||e===43||e===39||e===33||e===35||e===36||e===37||e===38||e===42||e===47||e===61||e===63||e===94||e===96||e===123||e===124||e===125||e===126;function zc(e,t,n,r=!1,i=e.indexOf(`@`,t)){if(i<t||i>=n||r&&(n-t<2||e.charCodeAt(n-1)!==34||(t++,n--,e.indexOf(`"`,t)<n)))return-1;for(;t<i&&Ic(e.charCodeAt(t));)t++;for(;n>i&&Ic(e.charCodeAt(n-1));)n--;for(let n=t;n<i;n++)if(!Rc(e.charCodeAt(n)))return-1;let a=!1;for(let t=i+1;t<n;t++){let n=e.charCodeAt(t);if(n===46)a=!0;else if(!Lc(n)&&n!==45)return-1}return i>t||a?i:-1}var Bc=e=>e>=48&&e<=57||e>=1632&&(e<=1641||e>=1776&&e<=1785),Vc=new Set([`am`,`pm`,`a.m.`,`p.m.`,`h`]);function Hc(e,t,n,r=!1,i=e.indexOf(`:`,t)){if(i<t||i>=n||r&&(n-t<2||e.charCodeAt(n-1)!==34||(t++,n--,e.indexOf(`"`,t)<n)))return-1;for(;t<i&&e.charCodeAt(t)===32;)t++;for(;n>i&&e.charCodeAt(n-1)===32;)n--;let a=e.charCodeAt(t);if((a===45||a===43||a===8722)&&t++,t===i)return-1;for(let n=t;n<i;n++)if(!Bc(e.charCodeAt(n)))return-1;let o=i,s=0,c=i;for(;o<n&&e.charCodeAt(o)===58;){if(++s>3)return-1;c=o,o++;let t=o;for(;o<n&&o-t<2&&Bc(e.charCodeAt(o));)o++;if(o===t&&o<n)return-1}if(o<n&&(e.charCodeAt(o)===46||e.charCodeAt(o)===44)&&Bc(e.charCodeAt(o-1)))for(o++;o<n&&Bc(e.charCodeAt(o));)o++;if(o===n)return c;for(;o<n&&e.charCodeAt(o)===32;)o++;return n-o<=4&&Vc.has(e.slice(o,n).toLowerCase())?c:-1}var Uc={n:0,w:new Int32Array(8),at:new Int32Array(8),len:new Int32Array(8),val:new Int32Array(8),sep:new Int32Array(8),tail:0,suffix:!1},Wc=e=>e>=48&&e<=57?e-48:e>=1632&&(e<=1641||e>=1776&&e<=1785)?e&15:-1,Gc=e=>Wc(e)>=0,Kc=e=>e===47||e===46||e===45||e===58||e===32||e===84,qc=new Set([`am`,`pm`,`a.m.`,`p.m.`,`z`]);function Jc(e,t,n,r=!1){let i=t,a=n;if(r&&(n-t<2||e.charCodeAt(n-1)!==34||(t++,n--,e.indexOf(`"`,t)<n)))return!1;for(;t<n&&e.charCodeAt(t)===32;)t++;let o=n;for(;o>t&&e.charCodeAt(o-1)===32;)o--;let s=Uc,c=0,l=t,u=!1;for(;;){if(c===8)return!1;let t=l,n=0,r=-1;for(;l<o;l++){r=e.charCodeAt(l);let t=Wc(r);if(t<0)break;n<1e4&&(n=n*10+t)}if(s.at[c]=t,s.len[c]=l-t,s.val[c]=n,s.w[c]=c?l-t:l-i,s.sep[c]=0,c++,l===t&&(l<o||c===1))return!1;if(l===o)break;if(Kc(r)&&l>t&&!(r===32&&l+1<o&&!Gc(e.charCodeAt(l+1)))){s.sep[c-1]=r,l++;continue}let a=l;for(;a<o&&e.charCodeAt(a)===32;)a++;if(o-a>4||!qc.has(e.slice(a,o).toLowerCase()))return!1;u=!0;break}return c<2?!1:(s.n=c,s.tail=a-(s.at[c-1]+s.len[c-1]),s.suffix=u,!0)}function Yc(e,t,n,r=!1){if(!Jc(e,t,n,r))return!1;let i=Uc,a=i.n,o=i.len,s=i.val;if(a<3||a>7||i.sep[0]!==i.sep[1]||i.sep[0]===58||i.sep[0]===32||i.sep[0]===84)return!1;let c=s[0],l=s[1],u=s[2];if(o[0]===4){if(o[1]>2||o[2]>2||!o[1]||!o[2]||l<1||l>12||u<1||u>31)return!1}else if(!o[0]||o[0]>2||!o[1]||o[1]>2||o[2]!==2&&o[2]!==4||c<1||l<1||c>31||l>31||c>12&&l>12)return!1;return a===3?!i.suffix:!(i.sep[2]!==32&&i.sep[2]!==84||a<5||!o[3]||o[3]>2||s[3]>24||i.sep[3]!==58||o[4]!==2||s[4]>59||a>=6&&(i.sep[4]!==58||o[5]!==2||s[5]>60)||a===7&&(i.sep[5]!==46||!o[6]))}var Xc=/[̀-￿]/,Zc=1e3;function Qc(e,t,n,r={}){let i=r.from??1,a=r.stop,o=r.maxLines??1e3,s=r.maxChars??65536,{lineCount:c,getLine:l}=e,u=e.peekLine??l,d=new kt,f=!1,p=0,m=null;for(let e=i;e<=c;e++){if(!f&&e>i&&a&&a(e))return e;let r=l(e),h=null;for(;d.scan(r,t,f,h),d.endsInQuote&&d.openAt>=0&&At(u,e+1,c,o,s)===-1;)n.failed?.(e,d.openAt),(h??=[]).push(d.openAt);if(n.line?.(e,d,p,r,f),f&&!(d.flags[0]&4)&&(n.multi?.(m.line,m.offset,e,d.end[0],m.col),m=null),d.endsInQuote){let t=d.count-1;f&&t===0||(m={line:e,offset:d.openAt,col:p+t},p+=t),f=!0}else f=!1,p=0}return c+1}function $c(e,t,n,r){let i=!Xc.test(t),a=t.indexOf(`@`),o=t.indexOf(`:`);for(let s=0;s<e.count;s++){let c=e.flags[s];if(c&2)continue;let l=e.start[s],u=e.end[s],d=i?u-l:uc(t,l,u);if(c&4){r(n+s,d+1,1,-1,-1,-1,-1,null);continue}let f=!!(c&1);if(a>=0&&a<l&&(a=t.indexOf(`@`,l)),a>=0&&a<u){let e=zc(t,l,u,f,a);e>=0?r(n+s,d,3,-1,-1,i?e-l:uc(t,l,e),-1,null):r(n+s,d,1,-1,-1,-1,-1,null);continue}if(o>=0&&o<l&&(o=t.indexOf(`:`,l)),o>=0&&o<u){let e=Hc(t,l,u,f,o);e>=0?r(n+s,d,4,-1,-1,-1,e-l,null):Yc(t,l,u,f)?r(n+s,d,5,-1,-1,-1,-1,Uc):r(n+s,d,1,-1,-1,-1,-1,null);continue}let p=l<u?t.charCodeAt(l):0,m=p|32;if(m>=97&&m<=122&&m!==110){let e=p<97&&l+1<u?t.charCodeAt(l+1):0;if(!(e>=65&&e<=90||e===36)){r(n+s,d,1,-1,-1,-1,-1,null);continue}}el(t,l,u)&&Yc(t,l,u,f)?r(n+s,d,5,-1,-1,-1,-1,Uc):(Fc(t,l,u,f),U.kind===2?r(n+s,d,2,U.dot>=0?U.dot-l:-1,U.comma>=0?U.comma-l:-1,-1,-1,null):r(n+s,d,U.kind,-1,-1,-1,-1,null))}}function el(e,t,n){let r=t;for(r<n&&e.charCodeAt(r)===34&&r++;r<n&&e.charCodeAt(r)===32;)r++;let i=r+5>n?0:e.charCodeAt(r);if(!(i>=48&&i<=57||i>=1632&&(i<=1641||i>=1776&&i<=1785)))return!1;let a=tl(e.charCodeAt(r+1))?r+1:tl(e.charCodeAt(r+2))?r+2:tl(e.charCodeAt(r+4))?r+4:-1;if(a<0)return!1;let o=e.indexOf(e[a],a+1);return o>0&&o<n}var tl=e=>e===47||e===46||e===45;function nl(e){let t=e.split(/\r\n|\n|\r/);return{lineCount:t.length,getLine:e=>t[e-1],lines:t}}function rl(e,t,n,r={}){let i=null,a=0,o=!1,s=e.lineCount;Qc(e,t,{line(e,t,r,c,l){if(!l){if(e===s&&c===``&&s>1)return;i=[],a=e}for(let e=0;e<t.count;e++){let n=jt(c,t.start[e],t.end[e],t.flags[e]);t.flags[e]&2?i[i.length-1]+=`
11
+ `+n:i.push(n)}!t.endsInQuote&&n(i,a,e)===!0&&(o=!0)}},{...r,stop:e=>o||(r.stop?r.stop(e):!1)})}var W=e=>e.from===e.to;function il(e,t,n,r={}){let i=r.values??null,a=r.until??1/0,o=e.lineCount,s=r.fromPos??0,c=null,l=!1;Qc(e,t,{line(e,t,r,a,u){if(u)c.text=null;else{if(e===o&&a===``&&o>1)return;c={line:e,lastLine:e,from:s,to:s,starts:[],ends:[],quoted:[],values:[],text:a}}for(let e=0;e<t.count;e++){let n=t.flags[e];if(n&2){let r=c.ends.length-1;c.ends[r]=s+t.end[e],c.values[r]!==void 0&&(c.values[r]+=`
12
+ `+jt(a,t.start[e],t.end[e],n))}else{let r=c.starts.length;c.starts.push(s+t.start[e]),c.ends.push(s+t.end[e]),c.quoted.push(!!(n&1)),c.values.push(!i||i(r)?jt(a,t.start[e],t.end[e],n):void 0)}}c.lastLine=e,c.to=s+a.length,s+=a.length+1,!t.endsInQuote&&n(c)===!0&&(l=!0)}},{from:r.from,stop:()=>l||s>a})}var al=2e3;function*G(e,t,n,r={}){let i=r.from??1,a=r.fromPos??0;for(;;){let o=0,s=!1;if(il(e,t,e=>o>=al?(i=e.line,a=e.from,s=!0,!0):(o++,n(e)),{...r,from:i,fromPos:a}),!s)return;yield Math.min(.98,i/e.lineCount)}}function ol(e){for(;;){let t=e.next();if(t.done)return t.value}}function sl(e,t){return e.includes(t)||e.includes(`"`)||e.includes(`
13
+ `)||e.includes(`\r`)}function K(e,t,n=!1){return n||sl(e,t)?`"`+e.replaceAll(`"`,`""`)+`"`:e}function cl(e,t){let{delimiter:n,recordEol:r=`
14
+ `,inCellEol:i=`
15
+ `,quoteAll:a=!1,finalEol:o=!0}=t,s=[];for(let t of e){let e=``;for(let r=0;r<t.length;r++){let o=t[r]??``;i!==`
16
+ `&&o.includes(`
17
+ `)&&(o=o.replaceAll(`
18
+ `,i)),r&&(e+=n),e+=K(o,n,a)}s.push(e)}let c=s.join(r);return o&&s.length&&(c+=r),c}function ll(e,t,n,r){let i=[],a=0;for(let o of e)a&&i.push(t(a)?r:n),i.push(o),a++;return i.join(``)}var ul=class e{constructor(e,t=new Uint32Array(e),n=null){this.counts=t,this.big=n,this.cachedMax=-1}clone(){return new e(this.counts.length,this.counts.slice(),this.big?new Map(this.big):null)}add(e,t){if(e<this.counts.length)this.counts[e]+=t;else{let n=this.big??=new Map,r=(n.get(e)||0)+t;r?n.set(e,r):n.delete(e)}this.cachedMax=-1}count(e){return e<this.counts.length?this.counts[e]:this.big?.get(e)??0}max(){if(this.cachedMax>=0)return this.cachedMax;let e=0;if(this.big&&this.big.size)for(let t of this.big.keys())t>e&&(e=t);if(!e){for(let t=this.counts.length-1;t>0;t--)if(this.counts[t]){e=t;break}}return this.cachedMax=e}maxWithout(e){let t=this.max();if(e!==t||this.count(t)>1)return t;let n=0;if(this.big)for(let e of this.big.keys())e<t&&e>n&&(n=e);if(n)return n;for(let e=Math.min(t,this.counts.length)-1;e>0;e--)if(this.counts[e])return e;return 0}get total(){let e=0;for(let t=0;t<this.counts.length;t++)e+=this.counts[t];if(this.big)for(let t of this.big.values())e+=t;return e}},dl=256,fl=64,pl=4,ml=class e{constructor(e=0,t=new ul(fl),n=new ul(fl)){this.count=e,this.before=t,this.after=n}clone(){return new e(this.count,this.before.clone(),this.after.clone())}},hl=class e{constructor(e=0,t=[],n=new ul(fl)){this.count=e,this.parts=t,this.tail=n}clone(){return new e(this.count,this.parts.map(e=>e.clone()),this.tail.clone())}part(e){return this.parts[e]??=new ul(fl)}},gl=class e{constructor(){this.width=new ul(dl),this.text=0,this.values=0,this.reads=[null,null,null,null],this.date=null}clone(){let t=new e;return t.width=this.width.clone(),t.text=this.text,t.values=this.values,t.reads=this.reads.map(e=>e&&e.clone()),t.date=this.date&&this.date.clone(),t}add(e,t,n,r,i,a,o,s){if(this.width.add(e,s),t===1)this.text+=s;else if(t>=2&&(this.values+=s,n>=0&&this.read(0,n,e,s),r>=0&&this.read(1,r,e,s),i>=0&&this.read(2,i,e,s),a>=0&&this.read(3,a,e,s),o)){let e=this.date??=new hl;e.count+=s;for(let t=0;t<o.n;t++)e.part(t).add(o.w[t],s);e.tail.add(o.tail,s)}}read(e,t,n,r){let i=this.reads[e]??=new ml;i.count+=r,i.before.add(t,r),i.after.add(n-t,r)}apply(e){for(let[t,n]of e.width)n&&this.width.add(t,n);this.text+=e.text,this.values+=e.values;for(let t=0;t<pl;t++){let n=e.reads[t];if(!n)continue;let r=this.reads[t]??=new ml;r.count+=n.count;for(let[e,t]of n.before)t&&r.before.add(e,t);for(let[e,t]of n.after)t&&r.after.add(e,t)}let t=e.date;if(t){let e=this.date??=new hl;e.count+=t.count,t.parts.forEach((t,n)=>{for(let[r,i]of t)i&&e.part(n).add(r,i)});for(let[n,r]of t.tail)r&&e.tail.add(n,r)}}get total(){return this.width.total}},_l=(e,t,n)=>e.set(t,(e.get(t)||0)+n),vl=()=>({count:0,before:new Map,after:new Map}),yl=()=>({count:0,parts:[],tail:new Map}),bl=class{constructor(){this.width=new Map,this.text=0,this.values=0,this.reads=[null,null,null,null],this.date=null}add(e,t,n,r,i,a,o,s){if(_l(this.width,e,s),t===1)this.text+=s;else if(t>=2&&(this.values+=s,n>=0&&this.read(0,n,e,s),r>=0&&this.read(1,r,e,s),i>=0&&this.read(2,i,e,s),a>=0&&this.read(3,a,e,s),o)){let e=this.date??=yl();e.count+=s;for(let t=0;t<o.n;t++)_l(e.parts[t]??=new Map,o.w[t],s);_l(e.tail,o.tail,s)}}read(e,t,n,r){let i=this.reads[e]??=vl();i.count+=r,_l(i.before,t,r),_l(i.after,n-t,r)}merge(e){for(let[t,n]of e.width)_l(this.width,t,n);this.text+=e.text,this.values+=e.values;for(let t=0;t<pl;t++){let n=e.reads[t];if(!n)continue;let r=this.reads[t]??=vl();r.count+=n.count;for(let[e,t]of n.before)_l(r.before,e,t);for(let[e,t]of n.after)_l(r.after,e,t)}let t=e.date;if(t){let e=this.date??=yl();e.count+=t.count,t.parts.forEach((t,n)=>{let r=e.parts[n]??=new Map;for(let[e,n]of t)_l(r,e,n)});for(let[n,r]of t.tail)_l(e.tail,n,r)}}get zero(){let e=e=>{for(let t of e.values())if(t)return!1;return!0};return!this.text&&!this.values&&e(this.width)&&this.reads.every(t=>!t||!t.count&&e(t.before)&&e(t.after))&&(!this.date||!this.date.count&&e(this.date.tail)&&this.date.parts.every(t=>!t||e(t)))}},xl=class e{constructor(e){this.cols=e}get columns(){return this.cols.length}max(e){let t=this.cols[e];return t?t.width.max():0}col(e){return this.cols[e]}withDeltas(t){let n=this.cols.slice();for(let[e,r]of t){if(r.zero)continue;for(;n.length<=e;)n.push(new gl);let t=n[e]===this.cols[e]?n[e].clone():n[e];t.apply(r),n[e]=t}for(;n.length&&n[n.length-1].total===0;)n.pop();return new e(n)}},Sl=class extends ut{constructor(e){super(),this.col=e}eq(e){return e.col===this.col}},Cl=new class extends ut{eq(){return!0}},wl=class{constructor(e,t,n,r,i=0){this.delim=e,this.multi=t,this.failed=n,this.stats=r,this.multiVersion=i}};function Tl(e){let t=null,n=0,r=``;return{lineCount:e.lines,getLine(i){return t&&i===n||(t&&i===n+1||(t=e.iterLines(i),n=i-1),t.next(),n=i,r=t.value),r},peekLine:t=>e.line(t).text}}function El(e,t,n,r,i){let a=Tl(e),o=[],s=[];return{end:Qc({lineCount:a.lineCount,getLine:a.getLine,peekLine:a.peekLine},t,{line:(e,t,n,r)=>$c(t,r,n,i),multi(t,n,r,i,a){let s=e.line(t).from+n,c=e.line(r).from+i;o.push(new Sl(a).range(s,c))},failed(t,n){let r=e.line(t),i=e.line(Math.min(e.lines,t+Zc)).to;s.push(Cl.range(r.from+n,Math.max(r.from+n+1,i)))}},{from:n,stop:r}),multi:o,failed:s}}function Dl(e,t){let n=[],r=[],i=[],a=1,o=(e,t,r,i,a,o,s,c)=>{for(;n.length<=e;)n.push(new gl);n[e].add(t,r,i,a,o,s,c,1)};return{get finished(){return a>e.lines},run(n){let s=El(e,t,a,n,o);for(let e of s.multi)r.push(e);for(let e of s.failed)i.push(e);a=s.end},index(){for(;n.length&&n[n.length-1].total===0;)n.pop();return new wl(t,M.of(r),M.of(i),new xl(n),0)}}}function Ol(e,t){let n=Dl(e,t);return n.run(null),n.index()}function kl(e,t){let n=[];return El(e,t,1,()=>!0,(e,t,r,i,a,o,s,c)=>{n[e]=Al(t,r,i,a,o,s,c)}),n}function Al(e,t,n,r,i,a,o){return{w:e,kind:t,reads:[n,r,i,a],date:o?{n:o.n,w:Array.from(o.w.subarray(0,o.n)),tail:o.tail}:null}}function jl(e,t){let n=null;return e.multi.between(t,t,(e,r,i)=>{if(e<t&&r>=t)return n={from:e,to:r,col:i.col},!1}),n}function Ml(e,t){let n=null;return e.failed.between(t.from,t.to,e=>{e>=t.from&&e<=t.to&&(n??=[]).push(e-t.from)}),n}function Nl(e,t){let n=jl(e,t.from);return n?{inQuote:!0,col:n.col,multi:n}:{inQuote:!1,col:0,multi:null}}function Pl(e,t,n){for(;;){let r=t.lineAt(n).from,i=-1,a=e=>{e<r&&(i<0||e<i)&&(i=e)};if(e.multi.between(r,Math.max(r,n),(e,t)=>{t>=r&&a(e)}),e.failed.between(r,Math.max(r,n),(e,t)=>{t>=n&&a(e)}),i<0)return r;n=i}}function Fl(e,t,n){let r=t.line(n);for(;;){let n=jl(e,r.from);if(!n)return r.number;r=t.lineAt(n.from)}}function Il(e,t,n){for(;n<t.lines;){let r=jl(e,t.line(n+1).from);if(!r)return n;n=t.lineAt(r.to).number}return n}function Ll(e,t){let n=t.startState.doc,r=t.state.doc,i=e.delim,a=[];t.changes.iterChangedRanges((e,t,n,r)=>a.push([e,t,n,r]));let o=[],s=0;for(;s<a.length;){let t=Pl(e,n,a[s][0]),c=s;for(;o.length&&t<o[o.length-1].stopA;){let e=o.pop();t=Math.min(t,e.startA),c=e.first}let l=c>0?a[c-1][3]-a[c-1][1]:0,u=t+l,d=s,f=[],p=[],m=new Map,h=n.length+1,g=El(r,i,r.lineAt(u).number,t=>{let n=r.line(t).from;for(;d+1<a.length&&a[d+1][2]<n;)d++;if(n<=a[d][3]||d+1<a.length&&a[d+1][2]===n)return!1;let i=n-(a[d][3]-a[d][1]);return!jl(e,i)&&(h=i,!0)},(e,t,n,r,i,a,o,s)=>zl(m,e,t,n,r,i,a,o,s,1));f.push(...g.multi),p.push(...g.failed);let _=g.end>r.lines?r.length+1:r.line(g.end).from;o.push({startA:t,startB:u,stopA:h,stopB:_,first:c,last:d,newMulti:f,newFailed:p,deltas:m}),s=d+1}let c=new Map,l=!1;for(let r of o){let a=r.stopA>n.length?n.lines+1:n.lineAt(r.stopA).number;El(n,i,n.lineAt(r.startA).number,e=>e>=a,(e,t,n,r,i,a,o,s)=>zl(c,e,t,n,r,i,a,o,s,-1));for(let[e,t]of r.deltas)Bl(c,e,t);!l&&!Rl(e,r,t.changes)&&(l=!0)}let u=e=>{let t=0,n=o.length-1;for(;t<=n;){let r=t+n>>1,i=o[r];if(e<i.startB)n=r-1;else if(e>=i.stopB)t=r+1;else return!0}return!1},d=o[0].startB,f=o[o.length-1].stopB;return new wl(i,e.multi.map(t.changes).update({filter:e=>!u(e),filterFrom:d,filterTo:f,add:o.flatMap(e=>e.newMulti)}),e.failed.map(t.changes).update({filter:e=>!u(e),filterFrom:d,filterTo:f,add:o.flatMap(e=>e.newFailed)}),c.size?e.stats.withDeltas(c):e.stats,e.multiVersion+ +!!l)}function Rl(e,t,n){let r=[];e.multi.between(t.startA,t.stopA,(e,i,a)=>{e>=t.startA&&e<t.stopA&&r.push([n.mapPos(e,1),n.mapPos(i,-1),a.col])});let i=t.newMulti;if(r.length!==i.length)return!1;for(let e=0;e<r.length;e++){let[t,n,a]=r[e];if(i[e].from!==t||i[e].to!==n||i[e].value.col!==a)return!1}return!0}function zl(e,t,n,r,i,a,o,s,c,l){let u=e.get(t);u||e.set(t,u=new bl),u.add(n,r,i,a,o,s,c,l)}function Bl(e,t,n){let r=e.get(t);r||e.set(t,r=new bl),r.merge(n)}var Vl=65536;function Hl(e){let t=e.state.doc.length;if(t<Vl)return!1;let n=-1,r=0,i=0,a=0;return e.changes.iterChangedRanges((e,t,o,s)=>{n<0&&(n=e,i=o),r=t,a=s}),r-n+(a-i)>t}var Ul=qe.define(),Wl=A.define({map:(e,t)=>t.empty?e:void 0});function Gl(e,t){let n=e.length,r=new Int32Array(n),i=new Int32Array(n),a=new Int32Array(n);for(let t=0;t<n;t++){let n=e[t];r[t]=n.from,i[t]=n.to-n.from,a[t]=n.insert.length}return{from:r,was:i,now:a,cols:Int32Array.from(t)}}function Kl(e){let t=e.annotation(Ul);if(t)return t;for(let t of e.effects)if(t.is(Wl))return t.value;return null}function ql(e){let t=e.from.length,n=new Int32Array(t);for(let r=0,i=0;r<t;r++)n[r]=e.from[r]+i,i+=e.now[r]-e.was[r];return{from:n,was:e.now,now:e.was,cols:e.cols}}var Jl=class{constructor(e){this.lines=e.iterLines(),this.text=this.lines.next().value,this.from=0,this.number=1}next(){let e=this.from+this.text.length+1;return!this.lines.next().done&&(this.from=e,this.text=this.lines.value,this.number++,!0)}seek(e){for(;e>this.from+this.text.length;)if(!this.next())return!1;return!0}},Yl=(e,t,n,r)=>(t===0||e.charCodeAt(t-1)===r)&&(n===e.length||e.charCodeAt(n)===r);function Xl(e,t,n,r,i){if(n<e.length){let t=e.sliceString(n,n+1);if(t!==`
19
+ `&&t!==r)return!1}let a=e.sliceString(t,n),o=0;for(let e=0;;o++){let t=a.indexOf(`
20
+ `,e);if(i.scan(t<0?a.slice(e):a.slice(e,t),r,!0,null),i.count!==1)return!1;if(t<0)return!i.endsInQuote&&o<1e3;if(!i.endsInQuote)return!1;e=t+1}}function*Zl(e,t,n){let r=n.from.length;if(!r||n.was.length!==r||n.now.length!==r||n.cols.length!==r||e.failed.size)return null;let i=t.state.doc,a=e.delim,o=a.charCodeAt(0),s=0,c=0,l=0,u=0;if(t.changes.iterChangedRanges((e,t,n,r)=>{s++,c=e,l=t,u=r-n}),s!==1||c!==n.from[0]||l!==n.from[r-1]+n.was[r-1])return null;let d=e.stats.cols.slice(),f=new Uint8Array(d.length),p=null,m=1,h=(e,t,n,r,i,a,o,s)=>p.add(t,n,r,i,a,o,s,m),g=new kt,_=(e,t,n,r,i,s)=>{if(!Yl(e,t,n,o)||r<0||r>=d.length)return!1;let c=t===0&&n===e.length?e:e.slice(t,n);return g.scan(c,a,!1,null),g.count!==1||g.endsInQuote!==i?!1:(f[r]||(d[r]=d[r].clone(),f[r]=1),p=d[r],m=s,$c(g,c,r,h),!0)},v=[],y=e.multi.iter(),b=new Jl(t.startState.doc),x=new Jl(i),S=0,C=c;for(let e=0;e<r;e++){let t=n.from[e],r=n.was[e],o=n.now[e],s=n.cols[e],c=t+S;if((e&8191)==8191&&(yield .99),t<C||r<0||o<0||!b.seek(t)||!x.seek(c))return null;for(C=t+r;y.value&&y.from<t;){if(y.to>=t)return null;v.push(y.value.range(y.from+S,y.to+S)),y.next()}let l=C>b.from+b.text.length,u=y.value!==null&&y.from===t;if(u!==l||u&&y.to!==C)return null;u&&y.next();let d=t-b.from;if(!_(b.text,d,l?b.text.length:d+r,s,l,-1)||(l=c+o>x.from+x.text.length,d=c-x.from,!_(x.text,d,l?x.text.length:d+o,s,l,1)))return null;if(l){if(o>65536||!Xl(i,x.from+x.text.length+1,c+o,a,g))return null;v.push(new Sl(s).range(c,c+o))}S+=o-r}for(;y.value;y.next())v.push(y.value.range(y.from+S,y.to+S));if(u!==l-c+S)return null;for(;d.length&&d[d.length-1].total===0;)d.pop();return new wl(a,M.of(v),e.failed,new xl(d),e.multiVersion+1)}var Ql=(e,t,n)=>ol(Zl(e,t,n));function $l(e){let t=0,n=0,r=0,i=0;return e.changes.iterChangedRanges((e,a,o,s)=>{t++,n=e,r=a,i=s-o}),t===1?{fromA:n,toA:r,lengthB:i}:null}var eu=qe.define();function tu(e,t){let n=e.length,r=new Int32Array(n),i=new Int32Array(n);for(let t=0;t<n;t++)r[t]=e[t].from,i[t]=e[t].to-e[t].from;return{from:r,len:i,order:t instanceof Int32Array?t:Int32Array.from(t)}}var nu=512;function*ru(e,t,n){let r=n.from.length;if(r<2||n.len.length!==r||n.order.length!==r||e.failed.size)return null;let i=$l(t);if(!i||i.fromA!==n.from[0]||i.toA!==n.from[r-1]+n.len[r-1]||i.lengthB!==i.toA-i.fromA)return null;let a=t.startState.doc,o=t.state.doc,s=new Int32Array(r),c=new Int32Array(r).fill(-1),l=new Jl(a),u=0,d=-1;for(let e=0;e<r;e++){let t=n.from[e],i=n.len[e],a=n.order[e];if((e&16383)==16383&&(yield .99),t<=d||i<0||a<0||a>=r||c[a]>=0||!l.seek(t)||l.from!==t||!l.seek(t+i)||l.from+l.text.length!==t+i)return null;d=t+i,c[a]=e,s[e]=t+u,u+=n.len[a]-i}if(u)return null;for(let e=0,t=Math.ceil(r/nu);e<r;e=e+t<r||e===r-1?e+t:r-1){let t=n.order[e];if(o.sliceString(s[e],s[e]+n.len[t])!==a.sliceString(n.from[t],n.from[t]+n.len[t]))return null}let f=[],p=0;for(let t=e.multi.iter();t.value;t.next()){for(;p<r&&n.from[p]+n.len[p]<t.from;)p++;let e=0;if(p<r&&t.from>=n.from[p]){if(t.to>n.from[p]+n.len[p])return null;e=s[c[p]]-n.from[p]}else if(p<r){if(t.to>=n.from[p])return null;e=s[p]-n.from[p]}f.push(t.value.range(t.from+e,t.to+e))}return new wl(e.delim,M.of(f,!0),e.failed,e.stats,e.multiVersion+1)}var iu=(e,t,n)=>ol(ru(e,t,n)),au=qe.define();function ou(e,t,n=[]){let r=e.length,i=new Int32Array(r),a=new Int32Array(r),o=new Int32Array(r);for(let t=0;t<r;t++){let n=e[t];i[t]=n.from,a[t]=n.to-n.from,o[t]=n.insert.length}return{from:i,was:a,now:o,sources:Int32Array.from(t),rewritten:Int32Array.from(n)}}var su=()=>{};function*cu(e,t,n){let r=n.from.length;if(!r||n.was.length!==r||n.now.length!==r||e.failed.size)return null;let i=$l(t);if(!i||i.fromA!==n.from[0]||i.toA!==n.from[r-1]+n.was[r-1])return null;let a=t.startState.doc,o=t.state.doc,s=e.delim,c=e.stats.cols,l=c.length,u=n.sources,d=Array.from({length:l},()=>[]);for(let e=0;e<u.length;e++){let t=u[e];if(t<-1||t>=l)return null;t>=0&&d[t].push(e)}let f=d.map((e,t)=>e.length===1&&e[0]===t),p=new Map,m=new kt,h=!0,g=!1,_=(e,t,n,r,i,a,o,s)=>{if(e>=l)h=!1;else if(g||!f[e]){for(let c of d[e])zl(p,c,t,n,r,i,a,o,s,-1);g||zl(p,e,t,n,r,i,a,o,s,1)}},v=(e,t,n,r,i,a,o,s)=>zl(p,e,t,n,r,i,a,o,s,1),y=(e,t,n)=>{let r=El(e,s,t,()=>!0,n);return r.failed.length?null:r},b=(e,t)=>{if(m.scan(e,s,!1,null),m.endsInQuote)return!1;let n=[];for(let t=0;t<u.length;t++){let r=u[t];r<0?n.push(``):r<m.count&&n.push(e.slice(m.start[r],m.end[r]))}return n.join(s)===t},x=[],S=e.multi.iter(),C=new Jl(a),w=new Jl(o),ee=Math.ceil(r/nu),T=0,te=0,E=0,ne=0;for(;;){(C.number&8191)==8191&&(yield .99);let e=C.from,t=C.number,i=C.text,c=e+i.length,l=null;for(;S.value&&S.from<=c;){if((l??=[]).push(S.value.range(S.from,S.to)),!C.seek(S.to))return null;c=C.from+C.text.length,S.next()}let u=T<r&&n.from[T]===e;if(u?n.was[T]!==c-e:T<r&&n.from[T]<=c)return null;let d=u&&te<n.rewritten.length&&n.rewritten[te]===T;d&&te++;let f=u&&n.now[T]===0,p=d||f;if(u&&!p){if(ne++,l){let t=o.lineAt(e+E),r=t.from===e+E?y(o,t.number,su):null;if(!r||(r.end>o.lines?o.length:o.line(r.end).from-1)!==e+E+n.now[T])return null;for(let e of r.multi)x.push(e)}else if((T%ee===0||T===r-1)&&(!w.seek(e+E)||w.from!==e+E||w.text.length!==n.now[T]||!b(i,w.text)))return null}else{if(g=p,l){if(!y(a,t,_))return null}else{if(m.scan(i,s,!1,null),m.endsInQuote)return null;$c(m,i,0,_)}if(!h)return null;if(f){if(!w.seek(e+E)||w.from!==e+E||w.text.length)return null;$c(m.scan(``,s,!1,null),``,0,v)}else if(p){let t=o.lineAt(e+E),r=t.from===e+E?y(o,t.number,v):null;if(!r||(r.end>o.lines?o.length:o.line(r.end).from-1)!==e+E+n.now[T])return null;for(let e of r.multi)x.push(e)}else if(l)for(let e of l)x.push(e.value.range(e.from+E,e.to+E))}if(u&&(E+=n.now[T]-n.was[T++]),!C.next())break}if(T!==r||te!==n.rewritten.length||i.lengthB!==i.toA-i.fromA+E)return null;let re=new gl;m.scan(``,s,!1,null),$c(m,``,0,(e,t,n,r,i,a,o,s)=>re.add(t,n,r,i,a,o,s,ne));let D=Array.from(u,e=>e<0?re:c[e]);return new wl(s,M.of(x,!0),e.failed,new xl(D).withDeltas(p),e.multiVersion+1)}var lu=(e,t,n)=>ol(cu(e,t,n)),uu=A.define({map:(e,t)=>t.empty?e:void 0});function du(e){for(let t of e.effects)if(t.is(uu))return t.value;return null}var fu=qe.define();function pu(e){let t=e.length,n=new Int32Array(t),r=new Int32Array(t);for(let i=0;i<t;i++)n[i]=e[i].from,r[i]=e[i].to;return{from:n,to:r}}function*mu(e,t,n){let r=n.from.length;if(!r||n.to.length!==r||e.failed.size)return null;let i=0;for(let e=0;e<r;e++)i+=n.to[e]-n.from[e];let a=$l(t);if(!a||a.fromA!==n.from[0]||a.toA!==n.to[r-1]||a.lengthB!==a.toA-a.fromA-i)return null;let o=t.startState.doc,s=e.delim,c=new Map,l=new kt,u=(e,t,n,r,i,a,o,s)=>zl(c,e,t,n,r,i,a,o,s,-1),d=[],f=e.multi.iter(),p=new Jl(o),m=0,h=-1;for(let e=0;e<r;e++){let t=n.from[e],r=n.to[e];if((e&2047)==2047&&(yield .99),t<=h||r<=t||!p.seek(t))return null;for(h=r;f.value&&f.from<t;){if(f.to>t)return null;d.push(f.value.range(f.from+m,f.to+m)),f.next()}let i=p.from===t;if(!i&&(p.from+p.text.length!==t||!p.next()))return null;for(let e=!0;r!==p.from||!i||e;e=!1){let e=p.from+p.text.length;if(f.value&&f.from<=e){if(El(o,s,p.number,()=>!0,u).failed.length)return null;for(;f.value&&f.from<=e;){if(!p.seek(f.to))return null;e=p.from+p.text.length,f.next()}}else{if(l.scan(p.text,s,!1,null),l.endsInQuote)return null;$c(l,p.text,0,u)}if(e>r)return null;if(e===r){i&&$c(l.scan(``,s,!1,null),``,0,(e,t,n,r,i,a,o,s)=>zl(c,e,t,n,r,i,a,o,s,1));break}if(!p.next())return null}m-=r-t}for(;f.value;f.next())d.push(f.value.range(f.from+m,f.to+m));return new wl(s,M.of(d),e.failed,e.stats.withDeltas(c),e.multiVersion+1)}var hu=(e,t,n)=>ol(mu(e,t,n)),gu=qe.define(),q=ke.define({create:e=>Ol(e.doc,e.field(N).delimiter),update(e,t){let n=t.state.field(N).delimiter;if(n!==e.delim)return Ol(t.state.doc,n);if(!t.docChanged)return e;let r=du(t);if(r&&r.from===e&&r.to.delim===n&&r.length===t.state.doc.length&&r.lines===t.state.doc.lines)return r.to;let i=t.annotation(gu);if(i&&i.from===e&&i.changes===t.changes&&i.index.delim===n)return i.index;let a=Kl(t),o=a?null:t.annotation(eu),s=a||o?null:t.annotation(au),c=a||o||s?null:t.annotation(fu),l=a?Ql(e,t,a):o?iu(e,t,o):s?lu(e,t,s):c?hu(e,t,c):null;if(l)return l;if(Hl(t)){let r=Ol(t.state.doc,n);return r.multiVersion=e.multiVersion+1,r}return Ll(e,t)},provide:e=>Js.of(t=>{if(!t.docChanged)return[];let n=[],r=Kl(t);r&&n.push(Wl.of(ql(r)));let i=t.startState.field(e,!1),a=t.state.field(e,!1);if(i&&a&&i.delim===a.delim&&i.multiVersion!==a.multiVersion){let e=du(t);(e?e.to===a:t.annotation(qs)===`full`&&(Hl(t)||r||t.annotation(eu)||t.annotation(au)||t.annotation(fu)||t.annotation(gu)))&&n.push(uu.of({from:a,to:i,length:t.startState.doc.length,lines:t.startState.doc.lines}))}return n})});function _u(e,{record:t,inCell:n}){let r=e.doc;if(t===n)return r.sliceString(0,r.length,t);let i=new Set;return e.field(q).multi.between(0,r.length,(e,t)=>{let n=r.lineAt(e).number,a=r.lineAt(t).number;for(let e=n;e<a;e++)i.add(e)}),ll(r.iterLines(),e=>i.has(e),t,n)}var vu=new WeakMap,yu=new WeakMap;k.define({combine:e=>e.length?e[0]:-1});var bu=[`.`,`,`,`@`,`:`];function xu(e,t,n){let r=t?.date,i=0;e.parts.forEach((e,t)=>{e.total-(r&&t<r.n?1:0)>0&&(i=t+1)});let a=[];for(let t=0;t<i;t++){let n=e.parts[t];a.push(n?r&&t<r.n?n.maxWithout(r.w[t]):n.max():0)}let o=r?e.tail.maxWithout(r.tail):e.tail.max();for(let e of n??[])if(e.kind!==5&&e.kind!==0){if(e.loose){for(let t=0;t<e.loose.n;t++)a[t]=Math.max(a[t]??0,e.loose.w[t]);o=Math.max(o,e.loose.tail)}else a[0]=Math.max(a[0]??0,e.w)}let s=o;for(let e=1;e<a.length;e++)s+=1+a[e];return{sep:`date`,before:a[0]??0,after:s,slots:a.slice(1)}}var Su=()=>({n:Uc.n,w:Array.from(Uc.w.subarray(0,Uc.n)),tail:Uc.tail});function Cu(e,t,n,r=null){let i=e.columns,a=new Uint8Array(i),o=0,s=0;for(let n=0;n<i;n++){let i=e.col(n),c=i.text,l=i.values,u=i.reads[0]?.count??0,d=i.reads[1]?.count??0,f=i.reads[2]?.count??0,p=i.reads[3]?.count??0,m=i.date?.count??0,h=e=>{e.kind===1?c--:e.kind>=2&&l--,e.reads[0]>=0&&u--,e.reads[1]>=0&&d--,e.reads[2]>=0&&f--,e.reads[3]>=0&&p--,e.kind===5&&m--};t[n]&&h(t[n]),r?.get(n)?.forEach(h),!l||c>0||(a[n]=u===l|(d===l?2:0)|(f===l?4:0)|(p===l?8:0)|(m===l?16:0),a[n]===1?o++:a[n]===2&&s++)}let c=s>o||s===o&&n===`;`,l=Array(i).fill(null);for(let n=0;n<i;n++){let i=a[n];if(!i)continue;if(i&16){l[n]=xu(e.col(n).date,t[n],r?.get(n));continue}let o=i&4?2:i&8?3:i===1||i&1&&!c?0:1,s=e.col(n).reads[o],u=t[n],d=u?.kind>=2?u.reads[o]:-1,f=d>=0?s.before.maxWithout(d):s.before.max();for(let e of r?.get(n)??[])e.reads[o]<0&&e.kind!==0&&(f=Math.max(f,e.w));l[n]={sep:bu[o],before:f,after:d>=0?s.after.maxWithout(u.w-d):s.after.max()}}return l}function wu(e){let t=e.field(q),n=e.field(N),r=yu.get(t.stats);if(r&&r.doc===e.doc&&r.hasHeader===n.hasHeader)return r;let i=n.hasHeader?kl(e.doc,t.delim):[],a={doc:e.doc,hasHeader:n.hasHeader,header:i,anchors:Cu(t.stats,i,t.delim)};return yu.set(t.stats,a),a}function Tu(e,t){let{doc:n}=e,r=e.field(q),i=e.field(N).hasHeader,a=new Map,o=new Set,s=new kt,c=0,l=null,u=null;for(let d of e.selection.ranges){let e=n.lineAt(d.head);if(e.number!==c){if(c=e.number,u=null,i&&Fl(r,n,c)===1)continue;l=jl(r,e.from),s.scan(e.text,r.delim,!!l,Ml(r,e)),u=[],$c(s,e.text,l?l.col:0,(e,...t)=>{u[e]=Al(...t)})}if(!u)continue;let f=d.head-e.from,p=0;for(;p<s.count-1&&f>s.end[p];)p++;let m=(l?l.col:0)+p,h=!!(s.flags[p]&2),g=h?l.from:e.from+s.start[p];if(!t.has(m)||o.has(g))continue;o.add(g);let _=h?{w:0,kind:1,reads:[-1,-1,-1,-1],date:null}:u[m];if(!_)continue;!h&&_.kind!==5&&_.kind!==0&&Jc(e.text,s.start[p],s.end[p],!!(s.flags[p]&1))&&(_={..._,loose:Su()});let v=a.get(m);v?v.push(_):a.set(m,[_])}return a}var Eu=new Map,Du=(e,t)=>e===t||!!e&&!!t&&e.length===t.length&&e.every((e,n)=>e===t[n]),Ou=(e,t)=>e.size===t.size&&[...e].every(([e,n])=>{let r=t.get(e);return r&&r.sep===n.sep&&r.before===n.before&&r.after===n.after&&Du(n.slots,r.slots)}),ku=ke.define({create:()=>Eu,update(e,t){if(!t.docChanged&&(e===Eu||!t.selection&&t.state.field(q)===t.startState.field(q)&&t.state.field(N)===t.startState.field(N)))return e;let n=t.state,r=wu(n),i=Au(t.startState),a=null;for(let e=0;e<r.anchors.length;e++)!r.anchors[e]&&i.anchored(e)&&(a??=new Set).add(e);if(!a)return Eu;let o=Tu(n,a);if(!o.size)return Eu;let s=n.field(q),c=Cu(s.stats,r.header,s.delim,o),l=new Map;for(let e of a)c[e]&&l.set(e,c[e]);return l.size?Ou(l,e)?e:l:Eu}});function Au(e){let t=e.field(q).stats,n=e.field(N),r=e.field(ku,!1)??Eu,i=vu.get(t);if(i&&i.doc===e.doc&&i.hold===r&&i.cfg.cap===n.cap&&i.cfg.expanded===n.expanded&&i.cfg.collapse===n.collapse&&i.cfg.gap===n.gap&&i.cfg.hasHeader===n.hasHeader&&i.cfg.menuRoom===n.menuRoom&&i.cfg.hidden===n.hidden)return i.layout;let a=t.columns,o=null,s=0;if(n.hidden.size){o=new Uint8Array(a);for(let e of n.hidden)e>=0&&e<a&&(o[e]=1,s++);s!==a&&s||(o=null,s=0)}let c=0,l=Math.max(0,a-1);if(o){for(;o[c];)c++;for(;o[l];)l--}let{header:u,anchors:d}=wu(e),f=r.size?d.map((e,t)=>r.get(t)??e):d,p=new Int32Array(a),m=new Int32Array(a+1),h=new Int32Array(a),g=1+n.gap;for(let e=0;e<a;e++){let r=t.max(e);h[e]=r,p[e]=!n.collapse||n.expanded.has(e)?r:Math.min(r,n.cap),f[e]&&(p[e]=Math.max(p[e],f[e].before+f[e].after)),p[e]=Math.max(p[e],n.menuRoom?String(e+1).length+n.menuRoom:String(e+1).length-1),o&&o[e]&&(p[e]=0),m[e+1]=o&&o[e]?m[e]:m[e]+p[e]+g}let _=null,v={columns:a,get signature(){return _??=m.join(`,`)+`|`+f.map(e=>e?e.sep+e.before+`:`+e.after+(e.slots?`/`+e.slots:``):``).join(`,`)+(o?`|`+o.join(``):``)},hidden:e=>!!o&&e<a&&o[e]===1,hiddenCount:s,firstShown:c,lastShown:l,width:e=>e<a?p[e]:0,x:e=>e<=a?m[e]:m[a]+(e-a)*g,end:e=>e<a?m[e]+p[e]:m[a]+(e-a)*g,collapsible:e=>e<a&&(f[e]?(u[e]?.w??0)>n.cap:h[e]>n.cap),anchored:e=>e<a?f[e]:null};return vu.set(t,{cfg:n,doc:e.doc,hold:r,layout:v}),v}var ju=A.define(),Mu=ke.define({create:()=>null,update(e,t){let n=!1;for(let r of t.effects)r.is(ju)&&(e=r.value,n=!0);if(n||!e)return e;let r=t.startState.field(N),i=t.state.field(N);return r.delimiter!==i.delimiter||r.hasHeader!==i.hasHeader||t.selection&&!t.isUserEvent(`input.data`)?null:e}}),Nu=e=>e>=48&&e<=57||e>=1632&&e<=1641||e>=1776&&e<=1785,Pu=e=>e<=57?e-48:e<=1641?e-1632:e-1776;function Fu(e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=1632&&Nu(e.charCodeAt(t)))return e.replace(/[٠-٩۰-۹]/g,e=>String(e.charCodeAt(0)&15));return e}var Iu=new Set([` `,`\xA0`,` `,` `,`'`]);function Lu(e,t){if(Fc(e,0,e.length),U.kind!==2||(t===`,`?U.comma:U.dot)<0)return null;let n=e.length,r=0;for(;r<n&&!Nu(e.charCodeAt(r));)r++;let i=r>0&&(e[r-1]===t||e[r-1]===`٫`),a=i?r-1:r,o=i?`0.`:``;for(;r<n;r++){let i=e[r];if(Nu(e.charCodeAt(r)))o+=Pu(e.charCodeAt(r));else if(i===t||i===`٫`)o+=`.`;else if((i===`.`||i===`,`||i===`٬`||Iu.has(i))&&r+1<n&&Nu(e.charCodeAt(r+1)))continue;else break}o.endsWith(`.`)&&(o=o.slice(0,-1));let s=/^[eE][+-]?\d+/.exec(e.slice(r));s&&(o+=s[0],r+=s[0].length);let c=e.slice(0,a);return{neg:/[-−]/.test(c),digits:o,before:c,after:e.slice(r)}}function Ru(e,t){let n=Lu(e,t);if(!n)return NaN;let r=Number(n.digits);return n.neg?-r:r}function zu(e){return Fc(e,0,e.length),U.kind===0}var Bu={".":/^[-+]?(?:0|[1-9]\d{0,2}(?:,\d{3})+|[1-9]\d*)(?:\.\d+)?(?:[eE][-+]?\d+)?$/,",":/^[-+]?(?:0|[1-9]\d{0,2}(?:\.\d{3})+|[1-9]\d*)(?:,\d+)?(?:[eE][-+]?\d+)?$/};function Vu(e,t){let n=e.trim();return!Bu[t].test(n)||n.replace(/[eE].*$/,``).replace(/\D/g,``).replace(/^0+/,``).length>15?null:Ru(n,t)}function Hu(e){return Fc(e,0,e.length),U.kind===2?U.dot>=0&&U.comma>=0?`both`:U.dot>=0?`.`:U.comma>=0?`,`:null:null}function Uu(e,t,{to:n=`.`,keep:r=!1}={}){let i=Lu(e,t);if(!i)return null;let a=n===`,`?i.digits.replace(`.`,`,`):i.digits,o=i.neg?`-`:``;return r?o+i.before.replace(/[-−+]/g,``).trimStart()+a+i.after.trimEnd():o+a}var Wu=[`january`,`february`,`march`,`april`,`may`,`june`,`july`,`august`,`september`,`october`,`november`,`december`],Gu=Wu.map(e=>e[0].toUpperCase()+e.slice(1));function Ku(e){let t=e.toLowerCase();return t.length<3?0:Wu.findIndex(e=>e===t||t.length<=4&&e.startsWith(t))+1}var qu=(e,t)=>t===2?e%4==0&&(e%100!=0||e%400==0)?29:28:[4,6,9,11].includes(t)?30:31,Ju=e=>e.length===2?(+e<50?2e3:1900)+ +e:+e,Yu={a:0,aLen:0,b:0,c:0,cLen:0,sep:0},Xu=e=>e>=48&&e<=57?e-48:e>=1632&&(e<=1641||e>=1776&&e<=1785)?e&15:-1;function Zu(e){let t=e.length,n=0,r=0,i=0;for(;n<t&&((r=e.charCodeAt(n))===32||r===9||r===160);)n++;let a=0,o=0;for(;n<t&&o<4&&(i=Xu(e.charCodeAt(n)))>=0;)a=a*10+i,o++,n++;if(!o)return!1;Yu.a=a,Yu.aLen=o;let s=n<t?e.charCodeAt(n):-1;if(s!==47&&s!==46&&s!==45)return!1;for(n++,a=0,o=0;n<t&&o<2&&(i=Xu(e.charCodeAt(n)))>=0;n++)a=a*10+i,o++;if(!o||n>=t||e.charCodeAt(n)!==s)return!1;for(Yu.b=a,n++,a=0,o=0;n<t&&o<4&&(i=Xu(e.charCodeAt(n)))>=0;n++)a=a*10+i,o++;return!o||n<t&&Xu(e.charCodeAt(n))>=0?!1:(Yu.c=a,Yu.cLen=o,Yu.sep=s,!0)}function Qu(e){return Zu(e)?(Yu.sep===47?0:Yu.sep===46?3:6)+(Yu.aLen===4?0:Yu.cLen===4?1:2):-1}var $u=(e,t,n)=>t>=1&&t<=12&&n>=1&&n<=qu(e,t),ed=(e,t)=>t===2?(e<50?2e3:1900)+e:e;function td(e){if(!Zu(e))return!1;let{a:t,aLen:n,b:r,c:i,cLen:a}=Yu;if(n===3||a===3)return!1;if(n===4)return t<1e3||!$u(t,r,i);if(a===4&&i<1e3)return!0;let o=ed(i,a);return!$u(o,r,t)&&!$u(o,t,r)&&!(a<=2&&$u(ed(t,n),r,i))}var nd=/^(?:(?:[ T]|, ?)\s*\d{1,2}:\d{2}(?::\d{2}(?:[.,]\d+)?)?\s*(?:[ap]\.?m\.?|z|[+-]\d{2}(?::?\d{2})?)?)?\s*$/i,rd=/^\s*(\d{1,4})([/.-])(\d{1,2})\2(\d{1,4})(?!\d)([^]*)$/,id=/^\s*(\d{1,2})(?:st|nd|rd|th)?[\s./-]+([A-Za-z]{3,9})\.?,?[\s./-]+(\d{4}|\d{2})(?!\d)([^]*)$/,ad=/^\s*([A-Za-z]{3,9})\.?\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+(\d{4})(?!\d)([^]*)$/;function od(e,t=`dmy`){e=Fu(e);let n=rd.exec(e);if(!n)return sd(e);let[,r,,i,a,o]=n;return r.length===4||t===`ymd`&&r.length===2&&a.length<=2?a.length>2?null:cd(Ju(r),+i,+a,o):r.length>2||a.length!==2&&a.length!==4?null:t===`mdy`?cd(Ju(a),+r,+i,o):cd(Ju(a),+i,+r,o)}function sd(e){let t=id.exec(e);return t?cd(Ju(t[3]),Ku(t[2]),+t[1],t[4]):(t=ad.exec(e),t?cd(+t[3],Ku(t[1]),+t[2],t[4]):null)}function cd(e,t,n,r){return!nd.test(r)||t<1||t>12||n<1||n>qu(e,t)?null:{y:e,m:t,d:n,rest:r.trimEnd()}}var ld=e=>e.length>=8&&e.length<=64&&sd(e)!==null,ud=/^\s*\d{1,4}[/.-]\d/;function dd(e,t=`dmy`){e=Fu(e);let n=od(e,t);if(!n&&ud.test(e)){for(let r of[`dmy`,`mdy`,`ymd`])if(r!==t&&(n=od(e,r)))break}return n}var fd=/(\d{1,2}):(\d{2})(?::(\d{2})(?:[.,](\d+))?)?\s*(?:([ap])\.?m\.?)?/i;function pd(e){let t=e&&fd.exec(e);if(!t)return 0;let n=+t[1];return t[5]&&(n=n%12+(t[5].toLowerCase()===`p`?12:0)),n*3600+t[2]*60+(t[3]?+t[3]:0)+(t[4]?+`0.${t[4]}`:0)}function md(e,t=`dmy`){let n=dd(e,t);return n?((n.y*12+n.m-1)*31+n.d-1)*86400+pd(n.rest):NaN}function hd(){let e=0,t=0,n=0,r=0;return{add(i){let a=rd.exec(Fu(i));if(!a)return;let o=a[1],s=+a[3];r++,o.length===4?n++:+o>12&&s<=12?e++:s>12&&+o<=12&&t++},result(i=`dmy`){return e&&!t?{order:`dmy`,sure:!0,dates:r}:t&&!e?{order:`mdy`,sure:!0,dates:r}:r&&n===r?{order:`ymd`,sure:!0,dates:r}:{order:i,sure:!1,dates:r}}}}var gd=[`YYYY-MM-DD`,`DD/MM/YYYY`,`MM/DD/YYYY`,`DD.MM.YYYY`,`DD-MM-YYYY`,`D/M/YYYY`,`M/D/YYYY`,`D MMM YYYY`,`MMMM D, YYYY`,`YYYY-MM`,`YYYY`],_d=(e,t)=>String(e).padStart(t,`0`);function vd({y:e,m:t,d:n},r){return r.replace(/YYYY|YY|MMMM|MMM|MM|M|DD|D/g,r=>{switch(r){case`YYYY`:return _d(e,4);case`YY`:return _d(e%100,2);case`MMMM`:return Gu[t-1];case`MMM`:return Gu[t-1].slice(0,3);case`MM`:return _d(t,2);case`M`:return String(t);case`DD`:return _d(n,2);default:return String(n)}})}function yd(e,t,n){let r=od(e,t);return r?vd(r,n)+(/D/.test(n)?r.rest:``):null}var bd=[{id:`contains`,label:`contains`,takes:1},{id:`notContains`,label:`doesn’t contain`,takes:1},{id:`is`,label:`is`,takes:1},{id:`isNot`,label:`isn’t`,takes:1},{id:`starts`,label:`starts with`,takes:1},{id:`ends`,label:`ends with`,takes:1},{id:`matches`,label:`matches the pattern`,takes:1},{id:`empty`,label:`is empty`,takes:0},{id:`notEmpty`,label:`isn’t empty`,takes:0},{id:`gt`,label:`is greater than`,takes:1,number:!0},{id:`ge`,label:`is at least`,takes:1,number:!0},{id:`lt`,label:`is less than`,takes:1,number:!0},{id:`le`,label:`is at most`,takes:1,number:!0},{id:`between`,label:`is between`,takes:2,number:!0},{id:`before`,label:`is before`,takes:1,date:!0},{id:`after`,label:`is after`,takes:1,date:!0},{id:`betweenDates`,label:`is between dates`,takes:2,date:!0}],xd=new Map(bd.map(e=>[e.id,e]));function Sd(e){let t=Hu(e);return t?Ru(e,t===`,`?`,`:`.`):NaN}function Cd(e,t=`dmy`){let n=dd(e,t);return n?n.y*1e4+n.m*100+n.d:NaN}function wd(e){let t=e&&xd.get(e.op);if(!t)return!1;if(t.takes===0)return!0;if(t.number)return!Number.isNaN(Sd(e.a??``))&&(t.takes<2||!Number.isNaN(Sd(e.b??``)));if(t.date)return!Number.isNaN(Cd(e.a??``,e.order))&&(t.takes<2||!Number.isNaN(Cd(e.b??``,e.order)));if(!e.a)return!1;if(e.op===`matches`)try{new RegExp(e.a)}catch{return!1}return!0}function Td(e,t=null){if(!wd(e))return()=>!0;let{op:n}=e;if(n===`empty`)return e=>e.trim()===``;if(n===`notEmpty`)return e=>e.trim()!==``;if(xd.get(n).number){let r=Sd(e.a),i=n===`between`?Sd(e.b):0,a=Math.min(r,i),o=Math.max(r,i),s=e=>{if(t)return Ru(e,t);let n=Hu(e);return n?Ru(e,n===`,`?`,`:`.`):NaN};return e=>{let t=s(e);return Number.isNaN(t)?!1:n===`gt`?t>r:n===`ge`?t>=r:n===`lt`?t<r:n===`le`?t<=r:t>=a&&t<=o}}if(xd.get(n).date){let{order:t}=e,r=Cd(e.a,t),i=n===`betweenDates`?Cd(e.b,t):0,a=Math.min(r,i),o=Math.max(r,i);return e=>{let i=Cd(e,t);return Number.isNaN(i)?!1:n===`before`?i<r:n===`after`?i>r:i>=a&&i<=o}}if(n===`matches`){let t=new RegExp(e.a,`i`);return e=>t.test(e)}let r=e.a.trim().toLowerCase(),i=e=>e.trim().toLowerCase();switch(n){case`contains`:return e=>i(e).includes(r);case`notContains`:return e=>!i(e).includes(r);case`is`:return e=>i(e)===r;case`isNot`:return e=>i(e)!==r;case`starts`:return e=>i(e).startsWith(r);default:return e=>i(e).endsWith(r)}}var Ed=e=>wd(e.cond)||!!e.only||!!e.except&&e.except.size>0;function Dd(e,t=null){let n=wd(e.cond)?Td(e.cond,t):null,{only:r,except:i}=e;return e=>(!n||n(e))&&(!r||r.has(e))&&(!i||!i.has(e))}function Od(e,t=()=>null){let n=e.filter(Ed).map(e=>[e.col,Dd(e,t(e.col))]);return e=>{for(let[t,r]of n)if(!r(e[t]??``))return!1;return!0}}function kd(e,t){let n=[];if(wd(e.cond)){let t=xd.get(e.cond.op);n.push(t.takes===0?t.label:t.takes===2?`${t.label} ${e.cond.a} and ${e.cond.b}`:`${t.label} “${e.cond.a}”`)}return e.only?n.push(e.only.size===1?`is “${[...e.only][0]}”`:`is one of ${e.only.size.toLocaleString(`en`)} values`):e.except?.size&&n.push(e.except.size===1?`isn’t “${[...e.except][0]}”`:`isn’t one of ${e.except.size.toLocaleString(`en`)} values`),`${t} ${n.join(`, and `)}`}function Ad(e,t,{sepOf:n,keep:r}={}){let i=t.filter(Ed),a=Od(i,n),o=new Set(i.map(e=>e.col)),s=[],c=[],l=[],u=null,d=0,f=0,p=0,m=!0,h=1,g=0,_=!1;return{get done(){return _},get progress(){return e.length?Math.min(1,g/e.length):1},step(t=2e4){if(_)return!0;let n=0,i=!1;return il(e.lines,e.delim,o=>{if(h=o.lastLine+1,g=o.to+1,W(o))u&&(u.to=o.to);else if(m&&e.hasHeader)m=!1;else{m=!1,d++;let e=a(o.values);if(e&&f++,e)u=null;else if(r?.(o))u=null,l.push(o.from,o.to);else{p++,u?u.to=o.to:s.push(u={from:o.from,to:o.to});let e=c.length-3;o.lastLine>o.line?c.push(o.line,1,1):e>=0&&!c[e+2]&&c[e]+c[e+1]===o.line?c[e+1]++:c.push(o.line,1,0)}}if(++n>=t)return i=!0,!0},{from:h,fromPos:g,values:e=>o.has(e)}),i||(_=!0),_},result:()=>({runs:s,segs:c,kept:l,total:d,shown:f,hidden:p})}}function jd(e,t,n){let r=Ad(e,t,n);for(;!r.step(1/0););return r.result()}var Md=1<<20,Nd=300,Pd=800,Fd=12,Id=A.define(),Ld=A.define(),Rd=A.define(),zd=(e,t)=>t<e.map.length?e.map[t]:e.extra==null?-1:t+e.extra;function Bd(e){let t=e.extra==null?Math.max(0,...e.map)+1:e.map.length+e.extra,n=Array(Math.max(0,t)).fill(-1);return e.map.forEach((e,t)=>{e>=0&&e<n.length&&(n[e]=t)}),{map:n,extra:e.extra==null?null:-e.extra}}var Vd=Js.of(e=>{let t=[];for(let n of e.effects){if(!n.is(Rd))continue;let r=e.startState.field(ef,!1)?.filters??[];t.push(Rd.of({...Bd(n.value),restore:r.filter(e=>zd(n.value,e.col)<0)}))}return t}),Hd=A.define(),Ud=F.replace({}),Wd=F.replace({first:!0}),Gd=F.replace({first:!0,all:!0}),Kd={filters:[],deco:F.none,ghost:null,kept:[],total:0,shown:0,hidden:0,rev:0,reads:0,stale:!1,soon:!1};function qd(e){let{doc:t}=e;return{lines:Tl(t),slice:(e,n)=>t.sliceString(e,n),length:t.length,delim:e.field(q).delim,hasHeader:e.field(N).hasHeader}}function Jd(e){let t=Au(e);return e=>{let n=t.anchored(e)?.sep;return n===`.`||n===`,`?n:null}}function Yd(e){let t=[];for(let n of e.selection.ranges.slice(0,200))t.push(n.from,n.to);t.sort((e,t)=>e-t);let n=0;return e=>{for(;n<t.length&&t[n]<e.from;)n++;return n<t.length&&t[n]<=e.to}}function Xd(e,t){let n=[];for(let r of t)r.from>0?n.push(Ud.range(r.from-1,r.to)):r.to<e.length?n.push(Wd.range(0,r.to+1)):r.to>0&&n.push(Gd.range(0,r.to));return F.set(n)}function Zd(e){let t=e.length/3,n=new Int32Array(t),r=new Float64Array(t+1),i=new Uint8Array(t);for(let a=0;a<t;a++)n[a]=e[3*a],r[a+1]=r[a]+e[3*a+1],i[a]=e[3*a+2];return{n:t,line:n,cum:r,more:i}}function Qd(e,t,n){let r=Ad(qd(e),t,{sepOf:Jd(e),keep:n?void 0:Yd(e)});for(;!r.step(1/0););let{runs:i,segs:a,kept:o,total:s,shown:c,hidden:l}=r.result();return{deco:Xd(e.doc,i),ghost:Zd(a),kept:o,total:s,shown:c,hidden:l}}function $d(e,t){for(let n=0;n<e.length;n+=2)if(!t.ranges.some(t=>t.from>=e[n]&&t.from<=e[n+1]||t.to>=e[n]&&t.to<=e[n+1]))return!0;return!1}var ef=ke.define({create:()=>Kd,update(e,t){let{filters:n,deco:r,ghost:i,kept:a,total:o,shown:s,hidden:c,rev:l,reads:u,stale:d,soon:f}=e,p=!1,m=!1;for(let e of t.effects)e.is(Id)?(n=e.value.filter(Ed),l++,p=m=!0):e.is(Ld)?p=m=!0:e.is(Rd)&&(n.length||e.value.restore?.length)?(n=[...n.map(t=>({...t,col:zd(e.value,t.col)})).filter(e=>e.col>=0),...e.value.restore??[]],l++,p=!0):e.is(Hd)&&!t.docChanged&&(r=Xd(t.state.doc,e.value.runs),i=Zd(e.value.segs),{kept:a,total:o,shown:s,hidden:c}=e.value,u++,d=f=!1);if(!n.length)return l===e.rev&&e.filters.length===0?e:{...Kd,rev:l,reads:u+1};let h=t.state.field(N),g=t.startState.field(N);(h.delimiter!==g.delimiter||h.hasHeader!==g.hasHeader)&&(p=!0),!t.docChanged&&t.selection&&!d&&a.length&&$d(a,t.state.selection)&&(p=!0);let _=t.docChanged&&(t.isUserEvent(`input.data`)||t.isUserEvent(`undo`)||t.isUserEvent(`redo`));return p||_?t.state.doc.length<=Md?{filters:n,rev:l,reads:u+1,stale:!1,soon:!1,...Qd(t.state,n,m)}:{filters:n,deco:t.docChanged?r.map(t.changes):r,ghost:i,kept:a,total:o,shown:s,hidden:c,rev:l,reads:u,stale:!0,soon:!0}:t.docChanged?{filters:n,deco:r.map(t.changes),ghost:i,kept:a,total:o,shown:s,hidden:c,rev:l,reads:u,stale:!0,soon:!1}:r===e.deco&&d===e.stale&&u===e.reads?e:{filters:n,deco:r,ghost:i,kept:a,total:o,shown:s,hidden:c,rev:l,reads:u,stale:d,soon:f}},provide:e=>[B.decorations.from(e,e=>e.deco),B.atomicRanges.of(t=>t.state.field(e).deco)]}),tf=class extends _s{constructor(e){super(),this.text=e}eq(e){return e.text===this.text}toDOM(){return document.createTextNode(this.text)}},nf=vs.compute([ef],e=>{let t=e.field(ef).deco.iter();if(!t.value?.spec.first)return M.empty;let n=t.value.spec.all?``:String(e.doc.lineAt(t.to).number);return M.of(new tf(n).range(0))}),rf=j.changeFilter.of(e=>{let{deco:t}=e.startState.field(ef);if(!t.size)return!0;let n=e.startState.doc.length,r=[];return e.changes.iterChangedRanges((e,i)=>{t.between(Math.max(0,e-1),i,(t,a,o)=>{let s=o.spec.first?a:Math.min(n,a+1);r.length&&r[r.length-2]===t||i>=t&&e<=s&&r.push(t,s)})}),!r.length||r}),af=-1,of=-2;function sf(e,t,n,r){let i=r===of,a=t;for(let o=0;o<50;o++){let o=t;if(e.between(t,t,(e,s,c)=>{o===t&&(c.spec.first?t<s&&(o=s):t>e&&t<=s&&(!i&&r>=0&&a>r&&r>=e&&(i=!0),o=i&&s<n?s+1:e))}),o===t)break;t=o}return t}function cf(e,t,n,r=-1){let i=!1,a=[],o=e.mainIndex,s=e.ranges.length>1;return e.ranges.forEach((c,l)=>{let u=sf(t,c.anchor,n,r),d=sf(t,c.head,n,r);u===c.anchor&&d===c.head?a.push(c):(i=!0,s&&u===d?l<e.mainIndex?o--:l===e.mainIndex&&(o=Math.max(0,a.length-1)):a.push(O.range(u,d)))}),i?(a.length||a.push(O.cursor(sf(t,e.main.head,n,af))),O.create(a,Math.min(Math.max(o,0),a.length-1))):null}var lf=[ef,rf,j.transactionFilter.of(e=>{if(!e.selection)return e;let{deco:t}=e.startState.field(ef);if(!t.size||e.docChanged&&(e.isUserEvent(`input`)||e.isUserEvent(`delete`)))return e;e.docChanged&&(t=t.map(e.changes));let n=e.isUserEvent(`select`)&&!e.isUserEvent(`select.pointer`),r=cf(e.selection,t,e.newDoc.length,n?e.changes.mapPos(e.startState.selection.main.head):-1);return r?[e,{selection:r}]:e}),Wr.fromClass(class{constructor(e){this.view=e,this.timer=0,this.job=null,this.plan(e.state.field(ef))}update(e){let t=e.state.field(ef);(t!==e.startState.field(ef)||e.docChanged)&&this.plan(t)}plan(e){if(clearTimeout(this.timer),this.timer=0,this.job=null,!e.stale)return;let t=this.view.state.doc.length>Md;this.timer=setTimeout(()=>this.start(),e.soon?0:t?Pd:Nd)}start(){let{view:e}=this,{state:t}=e,n=t.field(ef);if(this.timer=0,!n.stale)return;let r=Ad(qd(t),n.filters,{sepOf:Jd(t),keep:Yd(t)}),i=this.job={reader:r},a=()=>{if(this.job!==i||e.state.doc!==t.doc||e.state.field(ef)!==n)return;let o=performance.now();for(;!r.done&&performance.now()-o<Fd;)r.step(500);r.done?(this.timer=0,this.job=null,e.dispatch({effects:Hd.of(r.result())})):this.timer=setTimeout(a,0)};a()}get progress(){return this.job?this.job.reader.progress:null}destroy(){clearTimeout(this.timer),this.job=null}}),nf,Vd],uf=new WeakMap;function df(e){let t=e.field(ef,!1);if(!t||!t.deco.size)return null;let n=uf.get(t.deco);if(!n){let r=[],i=[],a=t.deco.iter();for(;a.value;a.next())r.push(a.value.spec.first?0:a.from+1),i.push(a.value.spec.first&&a.to>0&&e.doc.sliceString(a.to-1,a.to)===`
21
+ `?a.to-1:a.to);n=e=>{let t=0,n=r.length-1;for(;t<=n;){let a=t+n>>1;if(e<r[a])n=a-1;else if(e>i[a])t=a+1;else return!0}return!1},uf.set(t.deco,n)}return n}var ff=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,pf=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(ff(e)):ff,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return se(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=ce(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=le(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n,a=!0;;e++){let n=r.charCodeAt(e),o=this.match(n,i,a,this.bufferPos+this.bufferStart,e==r.length-1);if(o)return this.value=o,this;if(e==r.length-1)break;a&&e<t.length&&t.charCodeAt(e)==n?i++:a=!1}}}match(e,t,n,r,i){let a=null;for(let t=0;t<this.matches.length;){let n=this.matches[t],o=!1;this.query.charCodeAt(n.index)==e&&(n.index==this.query.length-1?a={from:n.from,to:r,precise:i&&n.precise}:(n.index++,o=!0)),o?t++:this.matches.splice(t,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?a={from:t,to:r,precise:n&&i}:this.matches.push({from:t,index:1,precise:n})),a&&this.test&&!this.test(a.from,a.to,this.buffer,this.bufferStart)&&(a=null),a}};typeof Symbol<`u`&&(pf.prototype[Symbol.iterator]=function(){return this});var mf={from:-1,to:-1,match:/.*/.exec(``),precise:!0},hf=`gm`+(/x/.unicode==null?``:`u`),gf=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=mf,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new yf(e,t,n,r,i);this.re=new RegExp(t,hf+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter();let a=e.lineAt(r);this.curLineStart=a.from,this.matchPos=xf(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=xf(this.text,r+ +(n==r)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},_f=new WeakMap,vf=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=_f.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return _f.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),_f.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},yf=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=mf,this.matchPos=xf(e,r),this.re=new RegExp(t,hf+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=vf.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,precise:!0,match:t},this.matchPos=xf(this.text,n+ +(e==n)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=vf.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(gf.prototype[Symbol.iterator]=yf.prototype[Symbol.iterator]=function(){return this});function bf(e){try{return new RegExp(e,hf),!0}catch{return!1}}function xf(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var Sf=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||bf(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
22
+ `:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Nf(this):new Df(this)}getCursor(e,t=0,n){let r=e.doc?e:j.create({doc:e});return n??=r.doc.length,this.regexp?kf(this,r,t,n):Tf(this,r,t,n)}},Cf=class{constructor(e){this.spec=e}};function wf(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function Tf(e,t,n,r){let i;return e.wholeWord&&(i=Ef(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=wf(e.test,t,i)),new pf(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function Ef(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(Af(i,n-a))!=at.Word||t(jf(i,n-a))!=at.Word)&&(t(jf(i,r-a))!=at.Word||t(Af(i,r-a))!=at.Word))}var Df=class extends Cf{constructor(e){super(e)}nextMatch(e,t,n){let r=Tf(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=Tf(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=Tf(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=Tf(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=Tf(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function Of(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function kf(e,t,n,r){let i;return e.wholeWord&&(i=Mf(t.charCategorizer(t.selection.main.head))),e.test&&(i=Of(e.test,t,i)),new gf(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function Af(e,t){return e.slice(ie(e,t,!1),t)}function jf(e,t){return e.slice(t,ie(e,t))}function Mf(e){return(t,n,r)=>!r[0].length||(e(Af(r.input,r.index))!=at.Word||e(jf(r.input,r.index))!=at.Word)&&(e(jf(r.input,r.index+r[0].length))!=at.Word||e(Af(r.input,r.index+r[0].length))!=at.Word)}var Nf=class extends Cf{nextMatch(e,t,n){let r=kf(this.spec,e,n,e.doc.length).next();return r.done&&(r=kf(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=kf(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=kf(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=kf(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},Pf=new kt,Ff=new kt;function If(e,t){let n=null;return e.multi.between(t,t,(e,r,i)=>{if(e===t)return n={from:e,to:r,col:i.col},!1}),n}function Lf(e,t,n){let r=e.field(q);for(let i=0;n&&i<50;i++){let i=e.doc.lineAt(n.to);Ff.scan(i.text,r.delim,!0,Ml(r,i));for(let e=1;e<Ff.count;e++)if(!t.hidden(n.col+e))return!0;let a=Ff.count-1;if(a===0||!(Ff.flags[a]&4))return!1;n=If(r,i.from+Ff.start[a])}return!1}function Rf(e,t,n,r,i){if(!t.hiddenCount)return-1;let a=i?i.col:0,o=r.count,s=!1,c=-1;for(let e=0;e<o;e++)t.hidden(a+e)?s=!0:c=e;if(!s)return-1;let l=!!(r.flags[o-1]&4);return!i&&!l&&c<0?-1:l&&c<o-1&&Lf(e,t,r.flags[o-1]&2?i:If(e.field(q),n.from+r.start[o-1]))?o:c+1}function zf(e,t,n){let r=e.field(q),i=jl(r,t.from);return n.scan(t.text,r.delim,!!i,Ml(r,t)),i}function Bf(e,t){let n=0;for(;n<e.count-1&&t>e.end[n];)n++;return n}function Vf(e,t,n){let{doc:r}=e,i=e.field(q),a=r.lineAt(n),o=zf(e,a,Pf),s=Bf(Pf,n-a.from);if(!t.hidden((o?o.col:0)+s)||Rf(e,t,a,Pf,o)<0)return null;let c=a,l=o,u=-1;for(let n=s,c=0;c<50;c++){let s=o?o.col:0,c=Pf.count-1,l=n+1;for(;l<=c&&t.hidden(s+l);)l++;if(l<=c){u=a.from+Pf.start[l];break}if(!(Pf.flags[c]&4))break;let d=Pf.flags[c]&2?o:If(i,a.from+Pf.start[c]);if(!d)break;a=r.lineAt(d.to),o=zf(e,a,Pf),n=0}a=c,o=zf(e,a,Pf);let d=-1;for(let n=s,i=0;i<50;i++){let i=o?o.col:0,s=n-1;for(;s>=0&&t.hidden(i+s);)s--;if(s>=0){d=a.from+Pf.end[s];break}if(!o)break;a=r.lineAt(o.from),o=zf(e,a,Pf),n=Pf.count-1}return{left:d,right:u,line:l?r.line(Fl(i,r,c.number)):c}}function Hf(e,t){let{doc:n}=e,r=e.field(q);for(;t<n.lines;){let e=jl(r,n.line(t+1).from);if(!e)return t;t=n.lineAt(e.to).number}return t}function Uf(e,t,n=0){let r=Au(e);if(!r.hiddenCount)return t;let{doc:i}=e;for(let a=0;a<4;a++){let a=Vf(e,r,t);if(!a)return t;if(n>=0&&a.right>=0)return a.right;if(n<=0&&a.left>=0)return a.left;if(n===0)return t;if(n>0){let n=i.line(Hf(e,i.lineAt(t).number)).to;if(n>=i.length)return a.left>=0?a.left:t;t=n+1}else{if(a.line.from===0)return a.right>=0?a.right:t;t=a.line.from-1}}return t}var Wf=(e,t)=>{let n=Au(e);return n.hiddenCount>0&&Vf(e,n,t)!=null};function Gf(e,t){let n=Au(e);if(!n.hiddenCount||n.firstShown===0)return t.from;let r=Vf(e,n,t.from);return r&&r.right>=0?r.right:t.from}function Kf(e,t){let n=Au(e);if(!n.hiddenCount||n.lastShown>=n.columns-1)return t.to;let r=Vf(e,n,t.to);return r&&r.left>=0?r.left:t.to}function qf(e,t,n){let r=Au(e);if(!r.hiddenCount||n<=t||r.firstShown===0&&r.lastShown>=r.columns-1)return null;let{doc:i}=e,a=e.field(q),o=i.lineAt(t),s=i.lineAt(n);if(o.number===s.number)return null;let c=(e,r)=>e===t&&r===n?null:{from:e,to:r},l=!jl(a,o.from)&&Gf(e,o)===t,u=!jl(a,s.from)&&Gf(e,s)===n;if(l&&u)return c(o.from,s.from);let d=(t,n)=>Hf(e,t.number)===t.number&&Kf(e,t)===n,f=d(s,n);return f&&d(o,t)?c(o.to,s.to):l&&f&&Fl(a,i,s.number)!==o.number?c(o.from,s.to):null}function Jf(e,t,n){return qf(e,t,n)??{from:t,to:n}}function Yf(e,t){let n=e.doc.length;if(t>=n)return n+1;let r=Uf(e,t+1,1);return r<=t||Wf(e,r)?n+1:r}function Xf(e,t,n){if(qf(e,t,n))return!0;let{doc:r}=e,i=r.lineAt(t),a=r.lineAt(n);return i.number!==a.number&&(i.from===t&&a.from===n||i.to===t&&a.to===n||i.from===t&&a.to===n)}j.changeFilter.of(e=>{let t=e.startState;if(!Au(t).hiddenCount)return!0;let n=[];return e.changes.iterChangedRanges((e,r)=>{r<=e||(r>e+1?Yf(t,e)>=r:Wf(t,e)||Wf(t,r))&&!Xf(t,e,r)&&n.push(e,r)}),!n.length||n}),j.transactionFilter.of(e=>{if(!e.docChanged)return e;let t=e.startState,n=Au(t);if(!n.hiddenCount||n.firstShown===0&&n.lastShown>=n.columns-1)return e;let{doc:r}=t,i=t.field(q),a=[];e.changes.iterChanges((e,t,n,r,i)=>a.push({fromA:e,toA:t,fromB:n,toB:r,lines:i.lines>1,first:i.lines>1&&i.line(1).length===0,last:i.lines>1&&i.line(i.lines).length===0}));let o=[],s=!0;return a.forEach((e,n)=>{if(e.toA===e.fromA){if(!e.first&&!e.last)return;let s=r.lineAt(e.fromA);if(n>0&&a[n-1].toA>s.from||n+1<a.length&&a[n+1].fromA<s.to)return;if(e.first&&e.fromA<s.to&&Hf(t,s.number)===s.number&&Kf(t,s)===e.fromA){let t=r.sliceString(e.fromA,s.to);o.push({from:e.fromB,insert:t},{from:e.toB,to:e.toB+t.length})}else if(e.last&&e.fromA>s.from&&!jl(i,s.from)&&Gf(t,s)===e.fromA){let t=r.sliceString(s.from,e.fromA);o.push({from:e.fromB-t.length,to:e.fromB},{from:e.toB,insert:t})}return}let c=qf(t,e.fromA,e.toA);if(!c)return;if(n>0&&c.from<a[n-1].toA||n+1<a.length&&c.to>a[n+1].fromA){s=!1;return}let l=c.from<e.fromA?e.fromA-c.from:0,u=c.to>e.toA?c.to-e.toA:0,d=c.from>e.fromA?r.sliceString(e.fromA,c.from):``,f=c.to<e.toA?r.sliceString(c.to,e.toA):``,p=e.lines?d:f,m=e.lines?f:d;e.fromB===e.toB?o.push({from:e.fromB-l,to:e.toB+u,insert:d+f}):((l||p)&&o.push({from:e.fromB-l,to:e.fromB,insert:p}),(u||m)&&o.push({from:e.toB,to:e.toB+u,insert:m}))}),s&&o.length?[e,{changes:o,sequential:!0}]:e});function Zf(e,t,n=()=>0){let r=!1,i=[],a=t.mainIndex,o=t.ranges.length>1;return t.ranges.forEach((s,c)=>{let l=Uf(e,s.head,n(s.head,c)),u=s.empty?l:Uf(e,s.anchor,n(s.anchor,c));u===s.anchor&&l===s.head?i.push(s):(r=!0,o&&!s.empty&&u===l?c<t.mainIndex?a--:c===t.mainIndex&&(a=Math.max(0,i.length-1)):i.push(u===l?O.cursor(l,0,void 0,s.goalColumn):O.range(u,l,s.goalColumn)))}),r?(i.length||i.push(O.cursor(Uf(e,t.main.head,0))),O.create(i,Math.min(Math.max(a,0),i.length-1))):null}j.transactionFilter.of(e=>{if(!e.selection||e.docChanged)return e;let t=e.startState;if(!Au(t).hiddenCount||e.effects.some(e=>e.is(It)||e.is(Pt)))return e;let n=e.isUserEvent(`select`)&&!e.isUserEvent(`select.pointer`),r=t.selection,i=r.ranges.length===e.selection.ranges.length,a=n?(e,n)=>{let a=i?r.ranges[n].head:r.main.head;return e===a||t.doc.lineAt(e).number!==t.doc.lineAt(a).number?0:e>a?1:-1}:void 0,o=Zf(t,e.selection,a);return o?[e,{selection:o}]:e}),B.updateListener.of(e=>{let{state:t,view:n}=e;Au(t).hiddenCount&&(e.docChanged||e.selectionSet||t.field(N).hidden!==e.startState.field(N).hidden)&&Zf(t,t.selection)&&queueMicrotask(()=>{if(n.state!==t)return;let e=Zf(t,t.selection);e&&!Zf(t,e)&&n.dispatch({selection:e})})});function Qf(e,t){return n=>{let{state:r}=n,i=Au(r);if(!i.hiddenCount||(e?i.lastShown>=i.columns-1:i.firstShown===0))return!1;let a=r.selection.ranges.map(n=>{let i=r.doc.lineAt(n.head),a=e?Kf(r,i):Gf(r,i);return t?O.range(n.anchor,a):O.cursor(a)});return n.dispatch({selection:O.create(a,r.selection.mainIndex),scrollIntoView:!0,userEvent:`select`}),!0}}Me.high(ss.of([{key:`Home`,run:Qf(!1,!1),shift:Qf(!1,!0)},{key:`End`,run:Qf(!0,!1),shift:Qf(!0,!0)},{mac:`Cmd-ArrowLeft`,run:Qf(!1,!1),shift:Qf(!1,!0)},{mac:`Cmd-ArrowRight`,run:Qf(!0,!1),shift:Qf(!0,!0)}]));var $f=new kt;function ep(e,t,n){let r=e.field(q),i=Nl(r,t);return n.scan(t.text,e.field(N).delimiter,i.inQuote,Ml(r,t)),i}function tp(e,t,n,r){let i=r-n.from,a=0,o=e.count-1;for(;a<o;){let t=a+o>>1;e.end[t]<i?a=t+1:o=t}if(!e.count||i<e.start[a]||i>e.end[a])return null;let s=e.flags[a]&2&&t.multi&&a===0?t.multi.from:n.from+e.start[a];return{col:t.col+a,from:s,to:n.from+e.end[a],line:n.number}}function np(e,t){let n=e.doc.lineAt(t);return tp($f,ep(e,n,$f),n,t)}function rp(e){let t=new kt,n=null,r=null;return i=>((!n||i<n.from||i>n.to)&&(n=e.doc.lineAt(i),r=ep(e,n,t)),tp(t,r,n,i))}function ip(e,t,n){let r=e(t);if(!r||n<=r.to)return r;let i=e(n);return i&&i.col===r.col&&i.from===r.from?r:null}function ap(e){if(!e.field(N).hasHeader)return 0;let{doc:t}=e,n=e.field(q),r=1;for(let e;r<t.lines&&(e=jl(n,t.line(r+1).from));)r=t.lineAt(e.to).number;return t.line(r).to}var op=new WeakMap;function sp(e){let t=e.field(N);if(!t.hasHeader||e.doc.length===0)return[];let n=e.doc.line(1),r=t.delimiter+`\0`+n.text,i=op.get(e.doc);if(i&&i.key===r)return i.names;let a=[];return Qc(Tl(e.doc),t.delimiter,{line(e,t,n,r){for(let e=0;e<t.count;e++){let n=jt(r,t.start[e],t.end[e],t.flags[e]);t.flags[e]&2?a[a.length-1]+=` `+n:a.push(n)}}},{stop:()=>!0}),op.set(e.doc,{key:r,names:a}),a}function cp(e,t,n=df(e)){let r=rp(e),i=ap(e);return(e,a)=>{if(e<i||n&&n(e))return!1;let o=ip(r,e,a);return!!o&&o.col===t}}var lp=/[^\x00-\x7f]/,up=/\p{L}\p{M}*/gu,dp=/\p{N}\p{M}*/gu,fp=/[\p{P}\p{S}](?:\p{M}|‍(?=[\p{P}\p{S}]))*/gu,pp=e=>e.replace(up,``),mp=e=>e.replace(dp,``),hp=e=>e.replace(fp,``),gp={ł:`l`,Ł:`L`,ø:`o`,Ø:`O`,đ:`d`,Đ:`D`,ħ:`h`,Ħ:`H`};function _p(e){return lp.test(e)?e.normalize(`NFD`).replace(/([\p{Script=Latin}\p{Script=Greek}])[̀-ͯ]+/gu,`$1`).replace(/[łŁøØđĐħĦ]/g,e=>gp[e]).normalize(`NFC`):e}function vp(e){return lp.test(e)?e.replace(/[‘-‛]/g,`'`).replace(/[“-‟]/g,`"`):e}var yp=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f­؜᠎​‎‏‪-‮⁠-⁤⁦--]/g,bp=e=>e.replace(yp,``),xp=e=>lp.test(e)?e.normalize(`NFC`):e,Sp=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xa0­؜᠎ -​‎‏‪-  -⁤⁦--�]/,Cp=e=>Sp.test(e),wp=`nbsp iexcl cent pound curren yen brvbar sect uml copy ordf laquo not shy reg macr deg plusmn sup2 sup3 acute micro para middot cedil sup1 ordm raquo frac14 frac12 frac34 iquest Agrave Aacute Acirc Atilde Auml Aring AElig Ccedil Egrave Eacute Ecirc Euml Igrave Iacute Icirc Iuml ETH Ntilde Ograve Oacute Ocirc Otilde Ouml times Oslash Ugrave Uacute Ucirc Uuml Yacute THORN szlig agrave aacute acirc atilde auml aring aelig ccedil egrave eacute ecirc euml igrave iacute icirc iuml eth ntilde ograve oacute ocirc otilde ouml divide oslash ugrave uacute ucirc uuml yacute thorn yuml`.split(` `),Tp=new Map([...wp.map((e,t)=>[e,String.fromCharCode(160+t)]),...Object.entries({quot:`"`,amp:`&`,lt:`<`,gt:`>`,apos:`'`,OElig:`Œ`,oelig:`œ`,Scaron:`Š`,scaron:`š`,Yuml:`Ÿ`,fnof:`ƒ`,circ:`ˆ`,tilde:`˜`,ensp:` `,emsp:` `,thinsp:` `,zwnj:`‌`,zwj:`‍`,lrm:`‎`,rlm:`‏`,ndash:`–`,mdash:`—`,lsquo:`‘`,rsquo:`’`,sbquo:`‚`,ldquo:`“`,rdquo:`”`,bdquo:`„`,dagger:`†`,Dagger:`‡`,bull:`•`,hellip:`…`,permil:`‰`,prime:`′`,Prime:`″`,lsaquo:`‹`,rsaquo:`›`,euro:`€`,trade:`™`,larr:`←`,uarr:`↑`,rarr:`→`,darr:`↓`,harr:`↔`,minus:`−`,le:`≤`,ge:`≥`,ne:`≠`,asymp:`≈`,infin:`∞`})]),Ep=[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376],Dp=/&(?:#(\d{1,7})|#[xX]([0-9a-fA-F]{1,6})|([A-Za-z][A-Za-z0-9]{1,7}));/g;function Op(e){return e.includes(`&`)?e.replace(Dp,(e,t,n,r)=>{if(r)return Tp.get(r)??e;let i=t?parseInt(t,10):parseInt(n,16);return i>=128&&i<=159&&(i=Ep[i-128]),i===0||i>1114111||i>=55296&&i<=57343?e:String.fromCodePoint(i)}):e}var kp=/\S {2,}\S/,Ap=e=>e.replace(/(\S) {2,}(?=\S)/g,`$1 `),jp=/[\u00a0\u2000-\u200a\u202f\u205f]/g,Mp=e=>Up(e)===e?bp(e).replace(jp,` `):e,Np=e=>Up(e)===e?e.trim():e,Pp=new Map;for(let e=128;e<=191;e++)Pp.set(String.fromCharCode(e),e);Ep.forEach((e,t)=>Pp.set(String.fromCharCode(e),128+t));var Fp=`[${[...Pp.keys()].join(``)}]`,Ip=RegExp(`[\u00c2-\u00df]${Fp}|[\u00e0-\u00ef]${Fp}{2}|[\u00f0-\u00f4]${Fp}{3}`,`g`),Lp=/[\u00c2-\u00f4]/,Rp=new Set(`\xA0­»”’…–—›™®©°ªº¹²³·†‡ŠŽŒŸšžœƒ`),zp=/\p{Ll}/u,Bp=/\p{L}/u;function Vp(e){let t=e.charCodeAt(0),n=Pp.get(e[1]),r;if(e.length===2)r=(t&31)<<6|n&63;else if(e.length===3){if(t===224&&n<160||t===237&&n>159)return null;r=(t&15)<<12|(n&63)<<6|Pp.get(e[2])&63}else{if(t===240&&n<144||t===244&&n>143)return null;r=(t&7)<<18|(n&63)<<12|(Pp.get(e[2])&63)<<6|Pp.get(e[3])&63}return r>=128&&r<=159&&(r=Ep[r-128]),String.fromCodePoint(r)}function Hp(e,t,n){for(let e=1;e<n.length;e++)if(!Rp.has(n[e]))return!0;if(n.length>2)return!1;let r=t>0?e[t-1]:``;return zp.test(r)||(n[0]===`Ã`||n[0]===`Â`)&&!Bp.test(r)?!0:n[0]===`Ã`&&(t<2||!Bp.test(e[t-2]))&&zp.test(e[t+2]??``)}function Up(e){if(!Lp.test(e))return e;let t=!1,n=e.replace(Ip,(n,r)=>{let i=Vp(n);return i===null?n:(!t&&Hp(e,r,n)&&(t=!0),i)});return t?n:e}var Wp=new Set(fc),Gp=new Set([`kr`,`zł`,`kč`,`lei`]),Kp=e=>e===36||e===162||e===163||e===165||e>=8352&&e<=8384||e===65020;function qp(e){if(e=e.replace(/[\s   +\-−]/g,``),!e)return``;if(e.length===1&&Kp(e.charCodeAt(0))||/^[A-Z]{1,3}\$$/.test(e))return e;let t=e.toUpperCase();return Wp.has(t)?t:Gp.has(e.toLowerCase())?e.toLowerCase():null}var Jp=[`USD`,`CAD`,`AUD`,`NZD`,`HKD`,`SGD`,`TWD`,`MXN`,`ARS`,`CLP`,`COP`,`UYU`],Yp={$:Jp,US$:[`USD`],C$:[`CAD`],CA$:[`CAD`],A$:[`AUD`],AU$:[`AUD`],NZ$:[`NZD`],HK$:[`HKD`],S$:[`SGD`],SG$:[`SGD`],NT$:[`TWD`],MX$:[`MXN`],R$:[`BRL`],"€":[`EUR`],"£":[`GBP`],"¥":[`JPY`,`CNY`],RMB:[`CNY`],"₹":[`INR`],"₽":[`RUB`],"₩":[`KRW`],"₺":[`TRY`],"₪":[`ILS`],"₫":[`VND`],"₱":[`PHP`],"₦":[`NGN`],"₴":[`UAH`],"₸":[`KZT`],"₿":[`BTC`],"﷼":[`SAR`,`QAR`,`IRR`,`OMR`,`YER`],kr:[`SEK`,`NOK`,`DKK`,`ISK`],zł:[`PLN`],kč:[`CZK`],lei:[`RON`]};function Xp(e){return Yp[e]??(/\$$/.test(e)?Jp:[e])}var Zp=(e,t)=>{let n=Xp(e);return!Xp(t).some(e=>n.includes(e))},J={currency:``,ok:[!1,!1],grouped:[!1,!1],big:[!1,!1]};function Qp(e,t=!0){t&&Fc(e,0,e.length);let n=U.kind===2&&U.dot>=0,r=U.kind===2&&U.comma>=0;J.ok[0]=n,J.ok[1]=r;let i=e.length,a=e.charCodeAt(0),o=+(a===45||a===43),s=o;for(;s<i&&e.charCodeAt(s)>=48&&e.charCodeAt(s)<=57;)s++;let c=s-o,l=0,u=0;if(c&&s<i){l=e.charCodeAt(s);let t=s+1;for(;t<i&&e.charCodeAt(t)>=48&&e.charCodeAt(t)<=57;)t++;u=t-s-1,(l!==46&&l!==44||t<i||!u)&&(l=-1)}if(c&&l>=0){J.currency=``;for(let e=0;e<2;e++){let t=l!==0&&l!==(e===0?46:44)&&u===3;J.grouped[e]=t,J.big[e]=!t&&c>=4}}else{J.currency=null;for(let t=0;t<2;t++){if(J.grouped[t]=J.big[t]=!1,!J.ok[t])continue;let n=t===0?`.`:`,`,r=Lu(e,n);if(!r)continue;let i=qp(r.before),a=qp(r.after);J.currency=i===null||a===null?null:i||a;let o=e.slice(r.before.length,e.length-r.after.length),s=o.indexOf(n),c=(s<0?o:o.slice(0,s)).replace(/[eE].*$/,``),l=/[^0-9٠-٩۰-۹]/.test(c);J.grouped[t]=l,J.big[t]=!l&&c.length>=4}}}function $p(e,t){let n=e.trim();if(!n)return e;Qp(n);let r=t.sep===`.`?0:1;if(!J.ok[r]||J.currency===null)return e;let i=t.cur&&J.currency!==``;if(!i&&!(t.grp&&J.grouped[r]))return e;let a=Uu(n,t.sep,{to:t.sep,keep:!i});return a===null?e:e.replace(n,a)}var em=[[`no`,`yes`],[`n`,`y`],[`false`,`true`],[`f`,`t`],[`0`,`1`]],tm=new Map(em.flatMap((e,t)=>e.map((e,n)=>[e,t*2+n])));function nm(e){return e.length>5?-1:tm.get(e.toLowerCase())??-1}function rm(e,t){return t===t.toUpperCase()&&t!==t.toLowerCase()?e.toUpperCase():t[0]===t[0].toUpperCase()&&t.slice(1)===t.slice(1).toLowerCase()&&t!==t.toLowerCase()?e[0].toUpperCase()+e.slice(1):e}var im=class{constructor(e){this.r=e,this.i=0}field(e,t){let n=this.r;for(;this.i<n.length&&n[this.i].to<e;)this.i++;for(let r=this.i;r<n.length&&n[r].from<=t;r++){let{from:i,to:a}=n[r];if(i===a?i>=e:t>e?i<t&&a>e:i<=e&&a>e)return!0}return!1}record(e,t){let n=this.r;for(;this.i<n.length&&n[this.i].to<e;)this.i++;for(let r=this.i;r<n.length&&n[r].from<=t;r++){let{from:t,to:i}=n[r];if(i>e||t===i&&i>=e)return!0}return!1}},am=(e,t)=>e.hasHeader&&t.line===1,om=(e,t,n)=>!!e.hidden&&!n?.everyRow&&e.hidden(t.from);function sm(e){return e.columns?t=>e.columns.includes(t):e.column==null?null:t=>t===e.column}function cm(e,t,n){if(sm(t)||!t.ranges.length)return{values:n};let r=e.recordAt(t.ranges[0].from);return{from:r.line,fromPos:r.from,until:t.ranges[t.ranges.length-1].to,values:n}}var lm=(e,t,n,r)=>({from:t.starts[n],to:t.ends[n],insert:K(r,e.delim,t.quoted[n])}),um=new WeakMap,dm=e=>um.get(e),fm=/[\p{L}\p{N}][\p{L}\p{N}\p{M}]*(?:['’][\p{L}\p{M}]+)*/gu;function pm(e){return e.replace(fm,e=>{let t=String.fromCodePoint(e.codePointAt(0));return t.toUpperCase()+e.slice(t.length).toLowerCase()})}var mm={trim:e=>e.trim(),collapseSpaces:e=>e.replace(/\s+/g,` `).trim(),removeSpaces:e=>e.replace(/\s+/g,``),upper:e=>e.toUpperCase(),lower:e=>e.toLowerCase(),title:pm,clear:()=>``,missingToEmpty:e=>zu(e)?``:e,fillEmpty:(e,t)=>e.trim()===``?t.text:e,singleSpaces:Ap,cleanChars:Mp,trimValue:Np,fixEncoding:Up,decimalLike(e,t,n){let r=t.to(n);return!r||Hu(e)!==(r===`.`?`,`:`.`)?e:Uu(e,r===`.`?`,`:`.`,{to:r,keep:!0})??e},padZeros(e,t,n){let r=t.width(n),i=e.trim();return r&&i.length<r&&/^[0-9]+$/.test(i)?e.replace(i,i.padStart(r,`0`)):e},unformatNumber(e,t,n){let r=t.how(n);return r?$p(e,r):e},boolLike(e,t,n){let r=t.how(n),i=e.trim(),a=nm(i);return r&&a>=0&&a>>1!==r.pair?e.replace(i,r.words[a&1]):e},countryLike(e,t,n){let r=e.trim(),i=t.how(n)?.get(r);return i?e.replace(r,i):e},replaceValue:(e,t)=>e===t.from?t.to:e,mapValues:(e,t)=>t.map.get(e)??e,convertNumber(e,t,n){let r=Uu(e,t.from(n),t);return r===null?(zu(e)||t.stats.other++,e):(t.stats.found++,r)},convertDate(e,t,n){let r=yd(e,t.order(n),t.format);return r===null?(zu(e)||t.stats.other++,e):(t.stats.found++,r)},removeLetters:pp,removeDigits:mp,removePunctuation:hp,removeAccents:_p,straightenQuotes:vp,decodeHtml:Op,removeInvisible:bp,normalizeUnicode:xp},hm=new Set([`convertNumber`,`convertDate`,`decimalLike`,`unformatNumber`]);function*gm(e,t,n,r={}){let i=mm[n],a=[],o=[],s=0,c=sm(t),l=c?null:new im(t.ranges);return yield*G(e.lines,e.delim,u=>{if(!(W(u)||om(e,u,t)||t.header!==`too`&&am(e,u)!==t.header))for(let t=0;t<u.starts.length;t++){if(l?!l.field(u.starts[t],u.ends[t]):!c(t))continue;s++;let d=u.values[t],f=i(d,r,t);f!==d&&(a.push(hm.has(n)?{from:u.starts[t],to:u.ends[t],insert:K(f,e.delim)}:lm(e,u,t,f)),o.push(t))}},cm(e,t,c??void 0)),um.set(a,{fields:o}),{edits:a,cells:s}}function*_m(e,t,n){let r=sm(t),i=r?null:new im(t.ranges);yield*G(e.lines,e.delim,a=>{if(!(W(a)||om(e,a,t)||am(e,a)!==t.header))for(let e=0;e<a.starts.length;e++)(i?i.field(a.starts[e],a.ends[e]):r(e))&&n(a.values[e],e)},cm(e,t,r??void 0))}function*vm(e,t,n=!1){let r=[],i=[],a=0,o=[],s=sm(t),c=s?null:new im(t.ranges),l=cm(e,t,s??void 0);return yield*G(e.lines,e.delim,l=>{if(!(W(l)||om(e,l,t)||am(e,l)))for(let t=0;t<l.starts.length;t++){let u=l.values[t];if(u===void 0)continue;let d=u.trim()===``;if(c?c.field(l.starts[t],l.ends[t]):s(t)){a++;let s=!n&&d&&o[t]!==void 0?o[t]:n&&!d&&o[t]===u?``:null;s!==null&&(r.push(lm(e,l,t,s)),i.push(t))}(n||!d)&&(o[t]=u)}},{values:l.values,until:l.until}),um.set(r,{fields:i}),{edits:r,cells:t.header?0:a}}function*ym(e,t,n,r=0){let i=t[0],a=t[t.length-1];new Set(t);let{delim:o}=e,s=[],c=[],l=0,u=new Map,d=e=>{let o=u.get(e);if(o!==void 0)return o;let s=n===`insertLeft`?e>=i:n===`insertRight`?e>=a+1:n===`duplicate`?e>a:n===`delete`||n===`keepOnly`?e>i:n===`moveLeft`?i>=1&&e>a:n===`moveRight`?e>a+1:n===`moveTo`&&e>a&&e>=r;o=null;let c=s?bm(e,t,n,r):null;if(c&&(c.length!==e||c.some((e,t)=>e!==t))){o=[];for(let e of c){let t=o[o.length-1];e>=0&&t&&t[1]===e-1?t[1]=e:o.push(e<0?null:[e,e])}}return u.set(e,o),o};return yield*G(e.lines,o,t=>{if(W(t))return;let r=d(t.starts.length);if(!r)return;let u=t.text??e.slice(t.from,t.to),f=``;if(n===`duplicate`&&am(e,t)){let e=t.starts.map((e,n)=>u.slice(e-t.from,t.ends[n]-t.from)),n=[];for(let e=i;e<=a;e++)n.push(K(t.values[e]+` copy`,o,t.quoted[e]));e.splice(a+1,0,...n),c.push(s.length),f=e.join(o)}else for(let e=0;e<r.length;e++){let n=r[e];e&&(f+=o),n&&(f+=u.slice(t.starts[n[0]]-t.from,t.ends[n[1]]-t.from))}l++,s.push({from:t.from,to:t.to,insert:f})},{values:n===`duplicate`&&e.hasHeader?e=>e>=i&&e<=a:()=>!1}),um.set(s,{columns:{cols:t,action:n,to:r,rewritten:c}}),{edits:s,rows:l}}function bm(e,t,n,r=0){let i=t[0],a=t[t.length-1],o=Sm(e),s=o.slice(i,a+1);switch(n){case`insertLeft`:return[...o.slice(0,i),-1,...o.slice(i)];case`insertRight`:return[...o.slice(0,a+1),-1,...o.slice(a+1)];case`duplicate`:return[...o.slice(0,a+1),...s,...o.slice(a+1)];case`delete`:{let e=new Set(t);return o.filter(t=>!e.has(t))}case`keepOnly`:return t.filter(t=>t<e);case`moveLeft`:return xm(e,s,i-1);case`moveRight`:return xm(e,s,a+2);case`moveTo`:return xm(e,t,r);default:return o}}function xm(e,t,n){let r=new Set(t),i=[];for(let t=0;t<e;t++)r.has(t)||i.push(t);let a=0;for(;a<i.length&&i[a]<n;)a++;return i.splice(a,0,...t.filter(t=>t<e)),i}var Sm=e=>Array.from({length:e},(e,t)=>t);function Cm(e){let t=null;return il(e.lines,e.delim,e=>(t=e,!0)),t}var wm=e=>e.trim().toLowerCase();function Tm(e,t){let n=e;for(let r=2;t.has(wm(n));r++)n=`${e}_${r}`;return n}function*Em(e){let t=e.hasHeader?Cm(e):null,n=t?K(Tm(`row`,new Set(t.values.map(wm))),e.delim,!1):``,r=[],i=0;return yield*G(e.lines,e.delim,t=>{W(t)||r.push({from:t.from,to:t.from,insert:(am(e,t)?n:String(++i))+e.delim})},{values:()=>!1}),{edits:r,rows:i,name:n}}function Dm(e){return e.replace(/['’]/g,``).replace(/(\p{Ll}|\p{N})(?=\p{Lu})/gu,`$1 `).replace(/(\p{Lu})(?=\p{Lu}\p{Ll})/gu,`$1 `).split(/[^\p{L}\p{N}\p{M}]+/u).filter(Boolean)}var Om=e=>{let t=String.fromCodePoint(e.codePointAt(0));return t.toUpperCase()+e.slice(t.length).toLowerCase()},km={snake:e=>{let t=Dm(e);return t.length?t.map(e=>e.toLowerCase()).join(`_`):e},camel:e=>{let t=Dm(e);return t.length?t.map((e,t)=>t?Om(e):e.toLowerCase()).join(``):e}};function Am(e){let t=new Set,n=e.map(e=>{let n=wm(e);return!n||t.has(n)?!1:(t.add(n),!0)});return e.map((e,r)=>{if(n[r])return e;let i=Tm(e.trim()||`column${r+1}`,t);return t.add(wm(i)),i})}function jm(e,t){let n=e.hasHeader?Cm(e):null;if(!n||W(n))return{edits:[],names:0};let r=n.values,i=t===`unique`?Am(r):r.map(km[t]),a=[];for(let t=0;t<r.length;t++)i[t]!==r[t]&&a.push(lm(e,n,t,i[t]));return{edits:a,names:r.length}}function Mm(e,t){if(sm(t)||!t.ranges.length)return`all`;let n=new im(t.ranges),r=0,i=cm(e,t,()=>!1);return il(e.lines,e.delim,i=>{if(!(W(i)||om(e,i,t)||am(e,i)))return n.record(i.from,i.to)&&r++,r>=2},i),r>=2?`touched`:`all`}function*Nm(e,t,n,r){let i=Mm(e,t)===`touched`,a=i?new im(t.ranges):null,o=[];return yield*G(e.lines,e.delim,n=>{W(n)||om(e,n,t)||am(e,n)||(!a||a.record(n.from,n.to))&&o.push(r(n))},i?cm(e,t,n):{values:n}),{rows:o,touched:i}}var Pm=8;function*Fm(e,t,n,r={}){let i=typeof n==`number`?[{col:n,...r}]:n,a=[],o=[],s=[],c=i.map(()=>[]),l=new Set(i.map(e=>e.col)),{rows:u,touched:d}=yield*Nm(e,t,e=>l.has(e),e=>{s.push(e.text);for(let t=0;t<i.length;t++){let n=i[t],r=e.values[n.col],a=null;r!==void 0&&!zu(r)&&(n.sep?(a=Ru(r,n.sep),Number.isNaN(a)&&(a=null)):a=n.length?Um(r):r),c[t].push(a)}return a.push(e.from),o.push(e.to),a.length-1});i.forEach((e,t)=>{if(!e.dates||e.sep||e.length)return;let n=c[t],r=hd();for(let e of n)e!==null&&r.add(e);let{order:i}=r.result(e.dates);for(let e=0;e<n.length;e++){if(n[e]===null)continue;let t=md(n[e],i);n[e]=Number.isNaN(t)?null:t}});let f=new Intl.Collator(`en`,{numeric:!0}),p=i.map(e=>!e.sep&&!e.dates&&!e.length);i.forEach((e,t)=>{if(!p[t])return;let n=c[t],r=new Map,i=new Set,a=Math.max(1,Math.floor(n.length/2e3));for(let e=0;e<n.length;e+=a)i.add(n[e]);if(i.size*2>Math.ceil(n.length/a))return;p[t]=!1;for(let e of n)e!==null&&!r.has(e)&&r.set(e,0);let o=[...r.keys()].sort(f.compare);for(let e=0,t=0;e<o.length;e++)e&&f.compare(o[e-1],o[e])!==0&&t++,r.set(o[e],t);for(let e=0;e<n.length;e++)n[e]!==null&&(n[e]=r.get(n[e]))});let m=i.map((e,t)=>{let n=c[t],r=e.desc?-1:1,i=p[t];return(e,t)=>{let a=n[e],o=n[t];return a===null||o===null?a===o?0:a===null?1:-1:(i?f.compare(a,o):a-o)*r}});yield 1;let h=u.slice().sort((e,t)=>{for(let n=0;n<m.length;n++){let r=m[n](e,t);if(r)return r}return e-t}),g=[],_=new Int32Array(u.length);for(let t=0;t<u.length;t++){let n=h[t];n!==t&&(_[t]=g.length,g.push({from:a[t],to:o[t],insert:s[n]??e.slice(a[n],o[n])}))}let v=new Int32Array(g.length);for(let e=0,t=0;e<u.length;e++)h[e]!==e&&(v[t++]=_[h[e]]);um.set(g,{rows:v});let y=e.hasHeader?Cm(e):null,b=y&&!W(y)?[y.values]:[],x=h.slice(0,Pm).map(t=>e.slice(a[t],o[t])).join(`
23
+ `).split(`
24
+ `);return u.length&&il({lineCount:x.length,getLine:e=>x[e-1]},e.delim,e=>{b.push(e.values)}),{edits:g,rows:u.length,touched:d,head:b}}var Im=e=>e.replace(/\s+/g,` `).trim().toLowerCase(),Lm=e=>{let t=e.toLowerCase();return/\s/.test(t)?t.replace(/\s+/g,` `).replace(/ ?\u0001 ?/g,``).trim():t},Rm=(e,t)=>{let n=e.values.join(``);return t?Lm(n):n},zm=(e,t,n)=>{let r=e.values[t]??``;return n?Im(r):r};function*Bm(e,t,{col:n=null,loose:r=!1}={}){let{rows:i}=yield*Nm(e,t,n==null?void 0:e=>e===n,e=>({from:e.from,to:e.to,key:n==null?Rm(e,r):zm(e,n,r)})),a=new Set,o=[];for(let e of i)a.has(e.key)?o.push([e.from-1,e.to]):a.add(e.key);let s=[];for(let[e,t]of o){let n=s[s.length-1];n&&e<=n.to?n.to=Math.max(n.to,t):s.push({from:e,to:t,insert:``})}return{edits:s,removed:o.length,rows:i.length}}function*Vm(e,t){let n=Mm(e,t)===`touched`?new im(t.ranges):null,r=[],i=0;yield*G(e.lines,e.delim,a=>{am(e,a)||om(e,a,t)||n&&!n.record(a.from,a.to)||a.values.every(e=>e.trim()===``)&&(a.from===i?(r.push([a.from,Math.min(a.to+1,e.length)]),i=a.to+1):r.push([a.from-1,a.to]))},n?cm(e,t):{});let a=[];for(let[e,t]of r){let n=a[a.length-1];n&&e<=n.to?n.to=Math.max(n.to,t):a.push({from:e,to:t,insert:``})}return{edits:a,removed:r.length}}function Hm(e){let t=e.length;if(e.includes(`
25
+ `))return 1;if(e.includes(`@`))return zc(e,0,t)>=0?3:1;if(e.includes(`:`))return Hc(e,0,t)>=0?4:Yc(e,0,t)||ld(e)?5:1;if(Yc(e,0,t))return 5;let n=Fc(e,0,t).kind;return n===1&&ld(e)?5:n}function Um(e){let t=0;for(let n of e)t++;return t}function Wm(e){let t=e.field(q).stats,n=+!!e.field(N).hasHeader,r=[];for(let e=0;e<t.columns;e++){let i=t.col(e),a=i.reads[2]?.count??0,o=i.reads[3]?.count??0,s=i.date?.count??0,c={number:i.values-a-o-s,email:a,time:o,date:s},l=`number`;for(let e of[`email`,`time`,`date`])c[e]>c[l]&&(l=e);let u=Math.max(0,i.text-n)+i.values,d=u-c[l];r.push(c[l]>=2&&d<=Math.max(1,Math.floor(u/10))?l:null)}return r}function Gm(e){let t=[];return e.field(q).failed.between(0,e.doc.length,e=>{t.push(e)}),t}var Km=A.define(),qm=new Map;function Jm(e){let t=qm.get(e);return t||qm.set(e,t=F.mark({class:`cm-csv-problem`,attributes:{title:e}})),t}ke.define({create:()=>F.none,update(e,t){for(let e of t.effects){if(!e.is(Km))continue;let n=t.state.doc.length;return F.set(e.value.filter(e=>e.to>e.from&&e.to<=n).map(e=>Jm(e.title).range(e.from,e.to)),!0)}return t.docChanged?e.map(t.changes):e},provide:e=>B.decorations.from(e)});var Ym=/[\u2010-\u2015\u2212]/g,Xm=e=>e.replace(Ym,`-`);function Zm(e,t,n=1/0,r=!0){let i=Xm(t),a=i.includes(`-`)?Xm(e):e,o=[],s=0;for(;o.length<n-1;){let t=a.indexOf(i,s);if(t<0)break;o.push(e.slice(s,t)),s=t+i.length}return o.push(e.slice(s)),r?o.map(e=>e.trim()):o}var Qm=(e,t)=>e.hasHeader&&t.line===1;function*$m(e,t,{sep:n,max:r=1/0,keep:i=!1,trim:a=!0}){let o=Math.max(1,Math.min(r,50)),s=e=>e===t,c=0,l=0;if(n&&(yield*G(e.lines,e.delim,r=>{let i=r.values[t];if(i===void 0||W(r)||Qm(e,r))return;let a=Zm(i,n,o,!1).length;a>1&&l++,a>c&&(c=a)},{values:s})),c<2)return{edits:[],columns:c,rows:0,split:l};let u=[],d=0;return yield*G(e.lines,e.delim,r=>{let s=r.values[t];if(s===void 0||W(r))return;let l;if(Qm(e,r)){let e=s.trim();l=Array.from({length:c},(t,n)=>e?`${e} ${n+1}`:``)}else for(l=Zm(s,n,o,a);l.length<c;)l.push(``);let f=l.map(t=>K(t,e.delim)).join(e.delim);i?u.push({from:r.ends[t],to:r.ends[t],insert:e.delim+f}):u.push({from:r.starts[t],to:r.ends[t],insert:f}),d++},{values:s}),{edits:u,columns:c,rows:d-+!!e.hasHeader,split:l}}function eh(e,t,n,r){let i=n[0],a=Math.min(n[n.length-1],t.starts.length-1),o=new Set(n),s=[r];for(let n=i+1;n<=a;n++)o.has(n)||s.push(e.slice(t.starts[n],t.ends[n]));return{from:t.starts[i],to:t.ends[a],insert:s.join(e.delim)}}function*th(e,t,{sep:n=` `,skipEmpty:r=!0}={}){let i=new Set(t),a=[],o=0;return yield*G(e.lines,e.delim,i=>{if(W(i)||i.starts.length<=t[0])return;let s=t.map(e=>i.values[e]??``);r&&(s=s.filter(e=>e.trim()!==``)),a.push(eh(e,i,t,K(s.join(n),e.delim,i.quoted[t[0]]&&s.length>0))),Qm(e,i)||o++},{values:e=>i.has(e)}),{edits:a,rows:o}}function*nh(e,t){let n=new Set(t),r=[],i=[],a=0,o=0,s=0;return yield*G(e.lines,e.delim,n=>{if(W(n)||n.starts.length<=t[0])return;let c=Qm(e,n),l=t[0];if(!c){let e=t.filter(e=>(n.values[e]??``).trim()!==``);e.length&&(l=e[0]);let c=l!==t[0],u=e.some(e=>n.values[e]!==n.values[l]);c&&o++,u&&s++,(c||u)&&i.length<50&&i.push(r.length),a++}let u=e.slice(n.starts[l],n.ends[l]);r.push(eh(e,n,t,u))},{values:e=>n.has(e)}),{edits:r,rows:a,filled:o,conflicts:s,notable:i}}var rh=e=>String(e??``).trim().toLowerCase(),ih=e=>e.field(N,!1)?.hasHeader?sp(e):[];function ah(e,t){let n=rh(e[t]);if(!n)return{index:t};let r=0;for(let i=0;i<t;i++)rh(e[i])===n&&r++;return r?{name:e[t].trim(),nth:r}:{name:e[t].trim()}}var oh=(e,t)=>ah(ih(e),t),sh=(e,t)=>t.map(t=>oh(e,t));function ch(e,t,n){if(!t)return-1;if(`index`in t)return t.index<n?t.index:-1;let r=ih(e),i=rh(t.name),a=t.nth??0;for(let e=0;e<r.length;e++)if(rh(r[e])===i&&a--===0)return e;return-1}function Y(e){return`index`in e?`column ${e.index+1}`:e.nth?`“${e.name}” (${e.nth+1})`:`“${e.name}”`}function lh(e){let t=e.field(ef,!1);if(t?.filters.length)return t.filters.map(t=>({col:oh(e,t.col),...t.cond?{cond:{...t.cond}}:{},...t.only?{only:[...t.only]}:{},...t.except?.size?{except:[...t.except]}:{}}))}Math.random().toString(36).slice(2,8);var uh=A.define(),dh=A.define(),fh=A.define(),ph=ke.define({create:()=>[],update(e,t){let n=0;for(let e of t.effects)e.is(uh)&&n++;for(let r of t.effects)if(r.is(uh)){if(e.some(e=>e.id===r.value.id))continue;let i=n===1&&!(`hb`in r.value);e=[...e,i?{...r.value,hb:ih(t.startState),ha:ih(t.state)}:{hb:null,ha:null,...r.value}]}else r.is(dh)?e=e.filter(e=>e.id!==r.value.id):r.is(fh)&&(e=r.value);return e}});Js.of(e=>{let t=[],n=e.startState.field(ph,!1)??[];for(let r of e.effects)r.is(uh)?t.push(dh.of(r.value)):r.is(dh)?t.push(uh.of(n.find(e=>e.id===r.value.id)??r.value)):r.is(fh)&&t.push(fh.of(n));return t});var mh=6,hh=(e,t)=>e.hasHeader&&t.line===1;function gh(e,t){let n=t.text??e.slice(t.from,t.to);return t.starts.map((e,r)=>n.slice(e-t.from,t.ends[r]-t.from))}function _h(e,t){let n=e.split(`
26
+ `),r=[];return il({lineCount:n.length,getLine:e=>n[e-1]},t,e=>{r.push(e.values)}),r}function vh(e,t){let n=0;return r=>{let i=r.from-1,a=r.to;r.from===n&&(i=r.from,a=n=Math.min(r.to+1,e.length));let o=t[t.length-1];o&&i<=o.to?o.to=Math.max(o.to,a):t.push({from:i,to:a,insert:``})}}function*yh(e,t,{nameCol:n=`name`,valueCol:r=`value`,skipEmpty:i=!1}={}){let{delim:a}=e;if(!t.length)return{edits:[],rows:0,made:0,skipped:0,head:[]};let o=t[0],s=new Set(t),c=[],l=[],u=vh(e,c),d=t.map(e=>K(`Column ${e+1}`,a)),f=0,p=0,m=0;return yield*G(e.lines,a,h=>{if(W(h))return;let g=gh(e,h);for(;g.length<o;)g.push(``);let _=g.filter((e,t)=>!s.has(t)),v=_.slice(0,o).map(e=>e+a).join(``),y=_.slice(o).map(e=>a+e).join(``);if(hh(e,h)){d=t.map(e=>K((h.values[e]??``).trim()||`Column ${e+1}`,a));let e=v+K(n,a)+a+K(r,a)+y;c.push({from:h.from,to:h.to,insert:e}),l.push(e);return}f++;let b=[];t.forEach((e,t)=>{let n=h.values[e];i&&(n===void 0||n.trim()===``)?m++:b.push(v+d[t]+a+(g[e]??``)+y)}),p+=b.length;for(let e of b)l.length<mh&&l.push(e);b.length?c.push({from:h.from,to:h.to,insert:b.join(`
27
+ `)}):u(h)},{values:e=>s.has(e)}),{edits:c,rows:f,made:p,skipped:m,head:_h(l.join(`
28
+ `),a)}}var bh=[`all`,`first`,`last`];function*xh(e,t,n,{keep:r=`all`,sep:i=`; `,joinApart:a=!1,max:o=200}={}){let{delim:s}=e,c={edits:[],rows:0,made:0,names:[],clashes:0,apart:0,tooMany:!1,head:[]};if(t===n||t<0||n<0)return c;let l=t-+(n<t),u=new Map,d=[],f=new Map,p=null,m=0,h=0,g=null,_=null,v=!1,y=e=>{let r=e.filter((e,r)=>r!==t&&r!==n);for(;r.length<l;)r.push(``);return r};yield*G(e.lines,s,i=>{if(W(i))return;if(hh(e,i)){p=y(gh(e,i));return}m++;let s=``;for(let e=0;e<i.values.length;e++)e!==t&&e!==n&&(s+=``+i.values[e]);let c=null;if(s===g)c=_;else{let e=f.get(s);v=e!==void 0,a&&(c=e??null)}v&&h++,c||(c={rest:y(gh(e,i)),cells:new Map},d.push(c),f.has(s)||f.set(s,c)),g=s,_=c;let l=(i.values[t]??``).trim(),b=i.values[n]??``;if(l===``&&b.trim()===``)return;let x=u.get(l);if(x===void 0&&u.set(l,x=u.size),u.size>o)return;let S=i.starts.length>n?e.slice(i.starts[n],i.ends[n]):``,C=b.trim()!==``,w=c.cells.get(x);w?C&&(w.n++,(w.n===1||r===`last`)&&(w.raw=S),r===`all`&&w.values.push(b.trim())):c.cells.set(x,{raw:S,values:C?[b.trim()]:[],n:+!!C})});let b=[...u.keys()];if(!m)return c;if(b.length>o)return{...c,rows:m,names:b,tooMany:!0};let x=0,S=e=>{let t=b.map((t,n)=>{let a=e.cells.get(n);return a?(a.n>1&&x++,r!==`all`||a.n<2?a.raw:K(a.values.join(i),s)):``});return[...e.rest.slice(0,l),...t,...e.rest.slice(l)].join(s)},C=[];p&&C.push([...p.slice(0,l),...b.map(e=>K(e,s)),...p.slice(l)].join(s));for(let e of d)C.push(S(e));let w=e.length>0&&e.slice(e.length-1,e.length)===`
29
+ `?`
30
+ `:``;return{edits:[{from:0,to:e.length,insert:C.join(`
31
+ `)+w}],rows:m,made:d.length,names:b,clashes:x,apart:h,tooMany:!1,head:_h(C.slice(0,mh).join(`
32
+ `),s)}}var Sh=1e3;function Ch(e,{max:t=Sh}={}){let{delim:n}=e,r=[],i=0,a=!1;if(il(e.lines,n,n=>{if(W(n))return;if(r.length===t)return a=!0,!0;let o=gh(e,n);o.length>i&&(i=o.length),r.push(o)},{values:()=>!1}),a)return{edits:[],rows:t+1,columns:i,tooMany:a};if(!r.length)return{edits:[],rows:0,columns:0,tooMany:a};let o=r.length===1,s=[];for(let e=0;e<i;e++)s.push(r.map(t=>{let n=t[e]??``;return o&&n===``?`""`:n}).join(n));let c=e.slice(e.length-1,e.length)===`
33
+ `?`
34
+ `:``,l=s.join(`
35
+ `)+c;return{edits:l===e.slice(0,e.length)?[]:[{from:0,to:e.length,insert:l}],rows:r.length,columns:i,tooMany:a}}function*wh(e,t,{sep:n,repeat:r=!0}){let{delim:i}=e,a=[],o=[],s=0,c=0,l=0,u=null;if(!n)return{edits:a,rows:s,split:c,made:l,head:[]};yield*G(e.lines,i,d=>{if(W(d))return;if(hh(e,d)){u=e.slice(d.from,d.to);return}let f=d.values[t];if(f===void 0)return;s++;let p=Zm(f,n,1/0,!0);if(p.length<2)return;let m=p.filter(e=>e!==``);m.length||(m=[``]),c++,l+=m.length;let h=gh(e,d),g=h.slice(0,t).map(e=>e+i).join(``),_=h.slice(t+1).map(e=>i+e).join(``),v=r?g:i.repeat(t),y=r?_:i.repeat(h.length-t-1),b=m.map((e,t)=>(t?v:g)+K(e,i)+(t?y:_));for(let e of b)o.length<mh&&o.push(e);a.push({from:d.from,to:d.to,insert:b.join(`
36
+ `)})},{values:e=>e===t});let d=_h((u==null?o:[u,...o]).join(`
37
+ `),i);return{edits:a,rows:s,split:c,made:l,head:d}}function*Th(e,t,{sep:n=`; `,below:r=!0}={}){let{delim:i}=e,a=new Map,o=[],s=0,c=null,l=0,u=null;yield*G(e.lines,i,n=>{if(W(n))return;if(hh(e,n)){c=e.slice(n.from,n.to);return}if(n.starts.length<=t){u=null;return}s++;let i=n.values[t],d=``,f=!0;for(let e=0;e<n.values.length;e++)e!==t&&(d+=``+n.values[e],f&&n.values[e].trim()!==``&&(f=!1));let p=r&&f&&u&&i.trim()!==``,m=p?u:a.get(d);p&&l++,m?o.push({from:n.from,to:n.to}):(m={n:0,vals:[],seen:new Set,value:i,from:n.starts[t],to:n.ends[t],quoted:n.quoted[t],recFrom:n.from,recTo:n.to},a.set(d,m),o.push(m)),f||(u=m),m.n++;let h=i.trim();h!==``&&!m.seen.has(h)&&(m.seen.add(h),m.vals.push(h))});let d=[],f=[],p=0,m=0;for(let t of o){if(t.vals){if(t.n<2)continue;p++;let r=K(t.vals.join(n),i,t.quoted);f.length<5&&f.push(e.slice(t.recFrom,t.from)+r+e.slice(t.to,t.recTo)),t.vals.join(n)!==t.value&&d.push({from:t.from,to:t.to,insert:r});continue}m++;let r=d[d.length-1];r&&t.from-1<=r.to?r.to=t.to:d.push({from:t.from-1,to:t.to,insert:``})}let h=_h((c==null?f:[c,...f]).join(`
38
+ `),i);return{edits:d,rows:s,groups:p,removed:m,below:l,head:h}}var Eh=[`count`,`distinct`,`sum`,`average`,`min`,`max`,`first`,`last`,`all`],Dh=new Intl.Collator(`en`,{numeric:!0});function Oh(e,t){if(/[eE]/.test(e))return 15;let n=e.lastIndexOf(t);return n<0?0:/^\d*/.exec(e.slice(n+1))[0].length}function kh(e,t,n){let r=String(Number(e.toFixed(Math.min(t,15))));return n===`,`?r.replace(`.`,`,`):r}function Ah(e,t){let n=t?.sep??null;if(e===`count`)return{make:()=>({n:0}),add:(e,t)=>{zu(t)||e.n++},out:e=>String(e.n)};if(e===`distinct`)return{make:()=>new Set,add:(e,t)=>{zu(t)||e.add(t)},out:e=>String(e.size)};if(e===`all`)return{make:()=>new Set,add:(e,t)=>{zu(t)||e.add(t.trim())},out:e=>[...e].join(`, `)};if(e===`first`)return{make:()=>({v:``}),add:(e,t)=>{e.v===``&&!zu(t)&&(e.v=t)},out:e=>e.v};if(e===`last`)return{make:()=>({v:``}),add:(e,t)=>{zu(t)||(e.v=t)},out:e=>e.v};if(e===`sum`||e===`average`)return{make:()=>({sum:0,n:0,places:0,commas:0}),add(e,t){let r=Hu(t);if(!r||n&&r!==`both`&&r!==n)return;let i=n??(r===`both`?`.`:r),a=Ru(t,i);if(Number.isNaN(a))return;e.sum+=a,e.n++,r===`,`&&e.commas++;let o=Oh(t,i);o>e.places&&(e.places=o)},out(t){if(!t.n)return``;let r=n??(t.commas?`,`:`.`);return e===`sum`?kh(t.sum,t.places,r):kh(t.sum/t.n,t.places>=6?t.places:Math.min(t.places+2,6),r)}};let r=e===`min`?-1:1,i=n?e=>Ru(e,n):t?.order?e=>md(e,t.order):null;return{make:()=>({v:``,key:null}),add(e,t){if(zu(t))return;let n=i?i(t):t;i&&Number.isNaN(n)||(e.key===null||(i?(n-e.key)*r>0:Dh.compare(n,e.key)*r>0))&&(e.key=n,e.v=t)},out:e=>e.v}}function*jh(e,t,{count:n=null,kindOf:r=()=>null}={}){let{delim:i}=e,a=[],o=[];t.forEach((e,t)=>{e===`group`?a.push(t):Eh.includes(e)&&o.push(t)});let s={edits:[],rows:0,groups:0,head:[]};if(!a.length&&!o.length&&n==null)return s;let c=o.map(e=>Ah(t[e],r(e))),l=new Set([...a,...o]),u=new Map,d=null,f=0;if(yield*G(e.lines,i,t=>{if(W(t))return;if(hh(e,t)){d=t.values.slice();return}f++;let n=``;for(let e of a)n+=``+(t.values[e]??``);let r=u.get(n);r||(r={values:a.map(e=>t.values[e]??``),states:c.map(e=>e.make()),n:0},u.set(n,r)),r.n++;for(let e=0;e<o.length;e++){let n=t.values[o[e]];n!==void 0&&c[e].add(r.states[e],n)}},{values:e=>l.has(e)}),!f)return s;let p=[...a.map((e,t)=>({k:e,group:t})),...o.map((e,t)=>({k:e,sum:t}))].sort((e,t)=>e.k-t.k),m=[];if(e.hasHeader){let e=p.map(e=>d?.[e.k]??``);n!=null&&e.push(n),m.push(e)}for(let e of u.values()){let t=p.map(t=>t.group==null?c[t.sum].out(e.states[t.sum]):e.values[t.group]);n!=null&&t.push(String(e.n)),m.push(t)}let h=m.map(e=>e.map(e=>K(e,i)).join(i)).join(`
39
+ `),g=e.length>0&&e.slice(e.length-1,e.length)===`
40
+ `?`
41
+ `:``;return{edits:[{from:0,to:e.length,insert:h+g}],rows:f,groups:u.size,head:m.slice(0,mh)}}var Mh=[`,`,` `,`;`,`|`],Nh=200;function Ph(e,t,n=Nh){let r=[];return rl(nl(e),t,e=>(r.push(e),r.length>=n)),r}function Fh(e,t,n=Nh){let r=[];return rl(e,t,(e,t,i)=>(r.push({values:e,first:t,last:i}),r.length>=n)),r}var Ih=e=>e.every(e=>e.trim()===``),Lh=e=>e.trim().split(/\s+/).length>=3,Rh=e=>e.reduce((e,t)=>e+(t.trim()===``?0:1),0);function zh(e){let t=e.filter(e=>!Ih(e.values));if(t.length<3)return 0;let n=new Map;for(let e of t)n.set(e.values.length,(n.get(e.values.length)||0)+1);let r=0,i=0;for(let[e,t]of n)(t>i||t===i&&e>r)&&(r=e,i=t);if(r<2)return 0;let a=e.findIndex(e=>e.values.length===r&&Rh(e.values)>=2&&Rh(e.values)>r/2);if(a<0)return 0;let o=e[a].first;if(o===1||o-1>30)return 0;let s=e.slice(a+1).filter(e=>!Ih(e.values)).slice(0,20);if(s.length<2)return 0;let c=s.filter(e=>e.values.length===r).length;if(s.length<5?c<s.length:c<s.length*.8)return 0;let l=e.slice(0,a),u=l.filter(e=>!Ih(e.values));if(!u.length)return o-1;let d=u.length<l.length,f=!0,p=!1,m=!1;for(let{values:e}of u){if(!e.some(e=>Kh(e)===`text`))return 0;let t=Rh(e);if(e.length===r&&(t>Math.floor(r/2)||!e.some(e=>/[\s:]/.test(e.trim()))))return 0;t>1&&(f=!1),e.some((t,n)=>/:$/.test(t.trim())&&e.slice(n+1).some(e=>e.trim()!==``))&&(p=!0),e.length<r&&e.some(Lh)&&(m=!0)}return!d&&!f&&!p&&!m?0:qh([e[a].values,...s.map(e=>e.values)])?o-1:0}var Bh=(e,t)=>zh(Fh(e,t));function Vh(e,t){if(!t)return e;let n=Math.max(e.lastIndexOf(`
42
+ `),e.lastIndexOf(`\r`));return n>0?e.slice(0,n):e}function Hh(e){let t={delimiter:`,`,columns:1,consistency:0},n=nl(e);for(let e of Mh){let r=[],i=Fh(n,e),a=zh(i);for(let{values:e,first:t}of i)t<=a||(e.length!==1||e[0].trim()!==``)&&r.push(e.length);if(!r.length)continue;let o=new Map;for(let e of r)o.set(e,(o.get(e)||0)+1);let s=0,c=0;for(let[e,t]of o)(t>c||t===c&&e>s)&&(s=e,c=t);if(s<2)continue;let l=c/r.length;(l>t.consistency+.05||Math.abs(l-t.consistency)<=.05&&s>t.columns)&&(t={delimiter:e,columns:s,consistency:l})}return t}var Uh=/^[-+]?(?:\d+(?:[.,]\d+)?|\d{1,3}(?:[,.  ]\d{3})+(?:[.,]\d+)?|[.,]\d+)(?:[eE][-+]?\d+)?%?$/,Wh=/^(?:\d{4}-\d{1,2}-\d{1,2}(?:[ T]\d{1,2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?|\d{1,2}[/.-]\d{1,2}[/.-]\d{2,4}(?: \d{1,2}:\d{2}(?::\d{2})?)?|\d{1,2}:\d{2}(?::\d{2})?)$/,Gh=/^(?:true|false|yes|no)$/i;function Kh(e){let t=e.trim().replace(/^[$€£¥]\s?|\s?[$€£¥]$/g,``);return t===``?`empty`:Uh.test(t)?`number`:Wh.test(t)?`date`:Gh.test(t)?`bool`:`text`}function qh(e){let t=e.filter(e=>e.length!==1||e[0].trim()!==``);if(t.length===0)return!1;let n=t[0],r=n.every(e=>Kh(e)===`text`);if(t.length===1){let e=n.length;for(;e>1&&n[e-1].trim()===``;)e--;return n.slice(0,e).every(e=>Kh(e)===`text`)}let i=t.slice(1),a=n.map(e=>e.trim().toLowerCase()),o=0;a.some(e=>e===``)&&--o,new Set(a.filter(Boolean)).size<a.filter(Boolean).length&&--o;for(let e=0;e<n.length;e++){let t=[];for(let n of i){let r=n[e];r!==void 0&&r.trim()!==``&&t.push(r)}if(!t.length)continue;let r={number:0,date:0,bool:0,text:0};for(let e of t)r[Kh(e)]++;let a=`text`;for(let e of[`number`,`date`,`bool`])r[e]>=t.length*.8&&(a=e);let s=n[e],c=Kh(s);if(a!==`text`){c===a?--o:c===`text`&&(o+=1);continue}if(c!==`text`)continue;let l=t[0].length;t.length>=2&&t.every(e=>e.length===l)&&s.length!==l&&(o+=1),t.includes(s)&&(o-=.5)}return o>0?!0:o<0?!1:r&&!a.some(e=>e===``)&&new Set(a).size===a.length}function Jh(e,t={}){let n=Vh(e,t.truncated),{delimiter:r}=Hh(n),i=Fh(nl(n),r),a=zh(i);return{delimiter:r,hasHeader:qh(i.filter(e=>e.first>a).slice(0,50).map(e=>e.values)),...a?{preamble:a}:{}}}function Yh(e,t){let n=e.lines.peekLine??e.lines.getLine,r=0;for(let e=1;e<=t;e++)r+=n(e).length+1;return Math.min(r,e.length)}function Xh(e,t){let n=Math.min(t,e.lines.lineCount),r=n>0?Yh(e,n):0;return r>0?{edits:[{from:0,to:r,insert:``}],lines:n}:{edits:[],lines:0}}var Zh=e=>Xh(e,Bh(e.lines,e.delim));function Qh(e,{rows:t=2,sep:n=` `,carry:r=!0}={}){let i=[],a=[];if(il(e.lines,e.delim,e=>{if(!W(e))return i.length<t?i.push(e):a.push(e.values),a.length>=5}),t<2||i.length<t||!a.length)return{edits:[],rows:0,names:[],head:[]};let o=Math.max(...i.map(e=>e.values.length)),s=i.map((e,t)=>{let n=Array.from({length:o},(t,n)=>(e.values[n]??``).trim());if(r&&t<i.length-1)for(let e=1;e<o;e++)n[e]===``&&(n[e]=n[e-1]);return n}),c=[];for(let e=0;e<o;e++){let t=[];for(let n of s)n[e]!==``&&n[e]!==t[t.length-1]&&t.push(n[e]);c.push(t.join(n))}let l=c.map(t=>K(t,e.delim)).join(e.delim);return{edits:[{from:i[0].from,to:i[i.length-1].to,insert:l}],rows:t,names:c,head:[c,...a]}}var $h=2e3;function X(e,t){let{doc:n}=e,r=e.field(q);return{lines:Tl(n),slice:(e,t)=>n.sliceString(e,t),length:n.length,delim:r.delim,hasHeader:e.field(N).hasHeader,hidden:t===void 0?df(e):t,recordAt(e){let t=Fl(r,n,n.lineAt(e).number);return{line:t,from:n.line(t).from}}}}function eg(e){if(!e.field(N).hasHeader)return-1;let{doc:t}=e;return t.line(Il(e.field(q),t,1)).to}function tg(e){let t=e.field(Mu,!1);if(t)return{column:null,columns:t.cols,ranges:[],header:!1};let n=e.selection;if(n.ranges.length===1&&n.main.empty)return{column:np(e,n.main.head)?.col??0,ranges:[],header:!1};let r=eg(e),i=r>=0&&n.ranges.every(e=>e.empty?e.head<=r:e.to<=r+1);return{column:null,ranges:n.ranges.map(t=>Jf(e,t.from,t.to)),header:i}}var ng=(e,t)=>ol(rg(e,t));function*rg(e,t){let n=t.length;if(n<=$h)return t;let r=t[0].from,i=t[n-1].to,a=[],o=``,s=e=>{let t=e.indexOf(`
43
+ `);if(t<0){o+=e;return}let n=0;do a.push(o+e.slice(n,t)),o=``,n=t+1,t=e.indexOf(`
44
+ `,n);while(t>=0);o=e.slice(n)},c=e=>{e.insert&&s(e.insert.indexOf(`\r`)<0?e.insert:e.insert.replace(/\r\n?/g,`
45
+ `))},l=0,u=r,d=r,f=0;for(let a=e.doc.iterRange(r,i);!a.next().done;){let e=a.value,r=e.length,i=0;for(;i<r;){let a=u+i;if(d<=a&&l<n&&t[l].from===a){let e=t[l++];c(e),d=e.to;continue}if(d>a){i+=Math.min(r-i,d-a);continue}if(l<n&&t[l].from<a)throw Error(`Edits out of order.`);let o=l<n?Math.min(r,t[l].from-u):r;s(i===0&&o===r?e:e.slice(i,o)),i=o}u+=r,++f&16383||(yield .99)}for(;l<n&&t[l].from===u&&d<=u;)c(t[l++]);return a.push(o),yield .99,[{from:r,to:i,insert:x.of(a)}]}var ig=60;function ag(e,t){let n=og.get(t);return n||og.set(t,n=sg(e,t)),n}var og=new WeakMap;function sg(e,t){let n=t.length;if(n<=$h)return[];let r=dm(t);if(!r){let n=0;for(let e of t){if(e.insert!==``||e.to<=e.from)return[];n+=e.to-e.from}return n*2<e.doc.length?[fu.of(pu(t))]:[]}if(r.fields)return n*ig<e.doc.length?[Ul.of(Gl(t,r.fields))]:[];if(r.rows)return[eu.of(tu(t,r.rows))];let{cols:i,action:a,to:o,rewritten:s}=r.columns;return[au.of(ou(t,bm(e.field(q).stats.columns,i,a,o),s))]}function cg(e,t){if(t.columns)return{cols:sh(e,t.columns)};if(t.column!=null)return{cols:[oh(e,t.column)]};let n=t.ranges;return!t.header&&n.length===1&&n[0].from===0&&n[0].to===e.doc.length?{all:!0}:null}function lg(e,t,n,r=!0){let i=r?cg(e,t):null;if(!i)return{title:n.title,why:`selection`};let a=lh(e);return{...n,in:i,...a?{where:a}:{}}}var ug={insertLeft:`Insert Column Left`,insertRight:`Insert Column Right`,duplicate:`Duplicate Column`,delete:`Delete Column`,keepOnly:`Delete Other Columns`,moveLeft:`Move Column Left`,moveRight:`Move Column Right`};function dg(e,t){let n=Au(e).anchored(t)?.sep;return n===`.`||n===`,`?n:null}function*fg(e,t,n,r=X(e)){let i=n.map(({col:t,desc:n=!1,as:r=`auto`})=>{if(r===`length`)return{col:t,desc:n,length:!0};let i=r===`auto`?dg(e,t):null;return{col:t,desc:n,sep:i,dates:r===`auto`&&!i&&Sg(e,t)?yg(e,t).order:null}}),{edits:a,rows:o,touched:s,head:c}=yield*Fm(r,t,i),l={title:`Sort`,why:`selection`};if(!s){let t=lh(e);l={title:`Sort`,op:`sort`,in:{all:!0},...t?{where:t}:{},keys:n.map(({col:t,desc:n=!1,as:r=`auto`})=>({by:oh(e,t),desc:n,...r===`auto`?{}:{as:r}}))}}return{edits:a,rows:o,touched:s,head:c,step:l,keys:i.map(e=>({col:e.col,desc:e.desc,numeric:!!e.sep,dates:!!e.dates,length:!!e.length}))}}var pg={snake:`Header Names to snake_case`,camel:`Header Names to camelCase`,unique:`Make Header Names Unique`};function mg(e){let t=Au(e),n=0,r=0;for(let e=0;e<t.columns;e++){let i=t.anchored(e)?.sep;i===`.`?n++:i===`,`&&r++}return r>n||r===n&&e.field(q).delim===`;`?`,`:`.`}function*hg(e,t,n){let r=e.hidden??(()=>!1),i=t===`visible`,a=[],o=0,s=0;if(yield*G(e.lines,e.delim,t=>{if(t.from===t.to||e.hasHeader&&t.line===1||r(t.from)===i||(o++,!i))return;let n=t.from-1,c=t.to;t.from===s&&(n=t.from,c=s=Math.min(t.to+1,e.length));let l=a[a.length-1];l&&n<=l.to?l.to=Math.max(l.to,c):a.push({from:n,to:c,insert:``})},{values:()=>!1}),!i)for(let e of n)a.push({from:e.from,to:e.to,insert:``});return{edits:a,removed:o}}function gg(e,t,n=6,r=0){let i=new Set,a=[];for(let o=r;o<t.length&&a.length<n&&o<r+2e3;o++){let n=t[o],r=e.doc.sliceString(n.from,n.to);i.has(r)||(i.add(r),a.push({from:r,to:n.insert}))}return a}function*_g(e,{read:t=`auto`,to:n=`.`,keep:r=!1}={},i=tg(e),a=X(e)){let o=new Map,s=()=>t;if(t===`auto`){let t=new Map;yield*_m(a,i,(e,n)=>{let r=Hu(e);if(r!==`.`&&r!==`,`)return;let i=t.get(n);i||t.set(n,i=[0,0]),i[r===`.`?0:1]++});let n=null;s=r=>{let i=o.get(r);if(!i){let[a,s]=t.get(r)??[0,0];i=dg(e,r)??(a>s?`.`:s>a?`,`:n??=mg(e)),o.set(r,i)}return i}}let c={found:0,other:0},{edits:l,cells:u}=yield*gm(a,i,`convertNumber`,{from:s,to:n,keep:r,stats:c}),d=lg(e,i,{title:`Reformat Numbers`,op:`numbers`,read:t,to:n,keep:r});return{edits:l,cells:u,found:c.found,other:c.other,scope:i,sample:gg(e,l),step:d}}function*vg(e,{read:t=`auto`,format:n=`YYYY-MM-DD`}={},r=tg(e),i=X(e)){let a=new Map,o=[];if(t===`auto`){let t=new Map;yield*_m(i,r,(e,n)=>{let r=t.get(n);r||t.set(n,r=hd()),r.add(e)});let n=mg(e)===`,`?`dmy`:`mdy`;for(let[e,r]of t){let t=r.result(n);a.set(e,t.order),!t.sure&&t.dates&&o.push({col:e,order:t.order})}}let s={found:0,other:0},{edits:c,cells:l}=yield*gm(i,r,`convertDate`,{order:t===`auto`?e=>a.get(e)??`dmy`:()=>t,format:n,stats:s}),u=lg(e,r,{title:`Reformat Dates`,op:`dates`,read:t,format:n});return{edits:c,cells:l,found:s.found,other:s.other,scope:r,unsure:o,sample:gg(e,c),step:u}}function yg(e,t,n){let r=hd();if(n)for(let e of n)r.add(e);else{let n=X(e),i=0;il(n.lines,n.delim,e=>(e.values[t]!==void 0&&r.add(e.values[t]),++i>=2e3),{values:e=>e===t})}return r.result(mg(e)===`,`?`dmy`:`mdy`)}var bg=2e3,xg=new WeakMap;function Sg(e,t){let n=Wm(e)[t];return n?n===`date`:wg(e,t)}function Cg(e){return Wm(e).map((t,n)=>t??(wg(e,n)?`date`:null))}function wg(e,t){let n=e.field(N).hasHeader,r=e.field(q),i=r.stats.col(t);if(!i||i.text-+!!n<=0)return!1;let a=xg.get(e.doc);a||xg.set(e.doc,a=new Map);let o=n?-1-t:t,s=a.get(o);if(s===void 0){let i=0,c=0,l=0;il(Tl(e.doc),r.delim,e=>{if(n&&e.line===1)return!1;let r=Hm(e.values[t]??``);return r===5?i++:r!==0&&c++,++l>=bg||c>=10&&!i||c>bg/10},{values:e=>e===t}),s=i>=2&&c<=Math.max(1,Math.floor((i+c)/10)),a.set(o,s)}return s}function Tg(e,t){let n=dg(e,t);return n?{sep:n}:Sg(e,t)?{order:yg(e,t).order}:null}var Eg=e=>Au(e).columns,Dg=[[`utf-8`,`UTF-8`],[`windows-1252`,`Western (Windows 1252)`],[`utf-16le`,`UTF-16 LE`],[`utf-16be`,`UTF-16 BE`]],Og=e=>(Dg.find(([t])=>t===e)||[e,e])[1];function kg(e,t){let n=e[0],r=e[1],i=e[2],a=t,o=!1,s=0;n===239&&r===187&&i===191?(o=!0,s=3,a??=`utf-8`):n===255&&r===254?(o=!0,s=2,a??=`utf-16le`):n===254&&r===255&&(o=!0,s=2,a??=`utf-16be`),o&&t&&!Ag(t,n,r)&&(o=!1,s=0);let c=e.subarray(s);if(!a&&(a=Mg(c),!a)){let e=jg(c);if(e!==null)return{text:e,encoding:`utf-8`,bom:o};a=`windows-1252`}return{text:a===`windows-1252`?Fg(c):new TextDecoder(a,{ignoreBOM:!0}).decode(c),encoding:a,bom:o}}function Ag(e,t,n){return e===`utf-8`?t===239:e===`utf-16le`?t===255&&n===254:e===`utf-16be`&&t===254&&n===255}function jg(e){try{return new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(e)}catch{return null}}function Mg(e){let t=Math.min(e.length,4096)&-2;if(t<8)return null;let n=0,r=0;for(let i=0;i<t;i+=2)e[i]===0&&n++,e[i+1]===0&&r++;let i=t/2;return r>i*.6&&n<i*.05?`utf-16le`:n>i*.6&&r<i*.05?`utf-16be`:null}var Ng=[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376],Pg=new Map(Ng.map((e,t)=>[e,128+t]));function Fg(e){let t=8192,n=[],r=new Uint16Array(Math.min(t,e.length));for(let i=0;i<e.length;i+=t){let a=Math.min(e.length,i+t);for(let t=i;t<a;t++){let n=e[t];r[t-i]=n>=128&&n<160?Ng[n-128]:n}n.push(String.fromCharCode.apply(null,r.subarray(0,a-i)))}return n.join(``)}function Ig(e,t,n){if(t===`utf-8`){let t=new TextEncoder().encode(e);if(!n)return{bytes:t,unencodable:0};let r=new Uint8Array(t.length+3);return r.set([239,187,191]),r.set(t,3),{bytes:r,unencodable:0}}if(t===`utf-16le`||t===`utf-16be`){let r=t===`utf-16le`,i=n?2:0,a=new Uint8Array(i+e.length*2);n&&a.set(r?[255,254]:[254,255]);for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);a[i+2*t+ +!r]=n&255,a[i+2*t+ +!!r]=n>>8}return{bytes:a,unencodable:0}}let r=new Uint8Array(e.length),i=0,a=0;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<128||n>=160&&n<=255)r[i++]=n;else{let e=Pg.get(n);e===void 0?(r[i++]=63,a++,n>=55296&&n<=56319&&t++):r[i++]=e}}return{bytes:r.subarray(0,i),unencodable:a}}function Lg(e,t){if(t!==`windows-1252`)return 0;let n=0;for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);r<128||r>=160&&r<=255||Pg.has(r)||(n++,r>=55296&&r<=56319&&t++)}return n}function Rg(e,t){let n={crlf:0,lf:0,cr:0},r={crlf:0,lf:0,cr:0},i=t.charCodeAt(0),a=e.length,o=!1,s=!0;if(e.indexOf(`"`)===-1){for(let t=e.indexOf(`\r`);t!==-1;t=e.indexOf(`\r`,t+1))e.charCodeAt(t+1)===10?n.crlf++:n.cr++;let t=0;for(let n=e.indexOf(`
46
+ `);n!==-1;n=e.indexOf(`
47
+ `,n+1))t++;n.lf=t-n.crlf}else for(let t=0;t<a;t++){let a=e.charCodeAt(t);o?a===34?e.charCodeAt(t+1)===34?t++:o=!1:(a===13||a===10)&&(a===13&&e.charCodeAt(t+1)===10?(r.crlf++,t++):a===13?r.cr++:r.lf++):a===34&&s?(o=!0,s=!1):a===i?s=!0:a===13||a===10?(a===13&&e.charCodeAt(t+1)===10?(n.crlf++,t++):a===13?n.cr++:n.lf++,s=!0):s=!1}let c=(e,t)=>{let n=Math.max(e.crlf,e.lf,e.cr);return n===0?t:e.crlf===n?`\r
48
+ `:e.lf===n?`
49
+ `:`\r`},l=c(n,`
50
+ `);return{record:l,inCell:c(r,l)}}function zg(e,t=!0){let n=new Set;return e.map((e,r)=>{let i=String(e??``),a=(t?i.trim():i)||`column${r+1}`,o=a;for(let e=2;n.has(a);e++)a=`${o}_${e}`;return n.add(a),a})}function Bg(e,{hasHeader:t,numberSep:n=()=>null,lines:r=!1}){let i=e.filter(e=>e.length!==1||e[0]!==``),a=t?i.shift()??[]:null,o=a?zg(a):null,s=[],c=e=>e in s?s[e]:s[e]=n(e),l=(e,t)=>{let n=c(t);return n?zu(e)?null:Vu(e,n)??e:e},u=i.map(e=>{if(!o)return JSON.stringify(e.map(l));e.length>o.length&&(o=zg([...a,...e.slice(a.length).map(()=>``)]));let t={};return o.forEach((n,r)=>{t[n]=r<e.length?l(e[r],r):null}),JSON.stringify(t)});return r?u.length?u.join(`
51
+ `)+`
52
+ `:``:u.length?`[
53
+ `+u.join(`,
54
+ `)+`
55
+ ]
56
+ `:`[]
57
+ `}var Vg=class{constructor(e){this.text=e}};function Hg(e,t,n){if(typeof t!=`number`)return t;let r=n?.source;return r!==void 0&&r!==String(t)?new Vg(r):t}var Ug=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof Vg);function Wg(e){for(let t in e)return!0;return!1}function Gg(e,t){let n;if(t)n=Kg(e,!0);else try{n=JSON.parse(e)}catch(r){if(n=Kg(e,!1),!(n?.length>1))throw Error(`It isn’t valid JSON (${r.message}).`);t=!0}let r=qg(e);return r.at.size&&(n=Jg(n,r)??(t?Kg(e,!0,Hg):JSON.parse(e,Hg))),{top:n,lines:t}}function Kg(e,t,n){let r=[],i=0;for(let a of e.split(`
58
+ `))if(i++,a.trim())try{r.push(JSON.parse(a,n))}catch(e){if(!t)return null;throw Error(`Line ${i} isn’t valid JSON (${e.message}).`)}return r}function qg(e){let t=new Map,n=0,r=e.length;for(let i=0;i<r;i++){let a=e.charCodeAt(i);if(a===34){let r=i;for(;;){if(r=e.indexOf(`"`,r+1),r<0)return{at:t,count:n};let i=r-1;for(;e.charCodeAt(i)===92;)i--;if((r-1-i)%2==0)break}i=r}else if(a===45||a>=48&&a<=57){let o=i+1,s=-1,c=!1;for(;o<r;o++){let t=e.charCodeAt(o);if(!(t>=48&&t<=57)){if(t===46)s=o;else if(t===101||t===69)c=!0;else if(t!==43&&t!==45)break}}let l=a===45?i+1:i;if(o-i>15||c||s>0&&(e.charCodeAt(o-1)===48||e.charCodeAt(l)===48)||a===45&&o-i===2&&e.charCodeAt(l)===48){let r=e.slice(i,o);String(Number(r))!==r&&t.set(n,r)}n++,i=o-1}}return{at:t,count:n}}function Jg(e,{at:t,count:n}){let r=0,i=!0,a=e=>{if(typeof e==`number`){let n=t.get(r++);return n===void 0?e:(Number(n)!==e&&(i=!1),new Vg(n))}if(typeof e!=`object`||!e)return e;if(Array.isArray(e)){for(let t=0;t<e.length;t++){let n=a(e[t]);n!==e[t]&&(e[t]=n)}return e}let n=Object.keys(e);n.length&&Yg.test(n[0])&&(i=!1);for(let t of n){let n=a(e[t]);n!==e[t]&&(e[t]=n)}return e},o=a(e);return i&&r===n?o:null}var Yg=/^(?:0|[1-9]\d*)$/,Xg=4;function Zg(e){if(Array.isArray(e))return{rows:e};if(!Ug(e))return{rows:[e]};let t=null,n=[[e,``,0]];for(let e=0;e<n.length;e++){let[r,i,a]=n[e];for(let e of Object.keys(r)){let o=r[e],s=i?`${i}.${e}`:e;Array.isArray(o)?o.length>(t?.rows.length??0)&&o.some(e=>e!==null)&&o.every(e=>e===null||Ug(e)||Array.isArray(e))&&(t={rows:o,from:s}):Ug(o)&&a<Xg&&n.push([o,s,a+1])}}if(t)return t;let r=Object.keys(e);return r.length>1&&r.every(t=>Ug(e[t]))?{rows:r.map(t=>e[t]),keys:r}:{rows:[e]}}var Qg=Symbol(`value`),$g=Symbol(`key`),e_=class e{constructor(e){this.name=e,this.label=``,this.kids=null,this.leaf=!1,this.lists=!1,this.plain=!0,this.semi=!1,this.index=-1}kid(t){let n=this.kids?.get(t);return n||(n=new e(t),(this.kids??=new Map).set(t,n)),n}see(e){this.leaf=!0,Array.isArray(e)?(this.lists=!0,this.plain&&!e.every(t_)&&(this.plain=!1)):typeof e==`string`&&!this.semi&&e.includes(`;`)&&(this.semi=!0)}get joins(){return this.lists&&this.plain&&!this.semi}},t_=e=>typeof e==`string`?e!==``&&!e.includes(`;`):typeof e==`number`||typeof e==`boolean`||e instanceof Vg;function n_(e,t){for(let n of Object.keys(t)){let r=t[n],i=e.kid(n);Ug(r)&&Wg(r)?n_(i,r):i.see(Ug(r)?null:r)}}function r_(e,t,n){for(let r of Object.keys(t)){let i=t[r],a=e.kids.get(r);Ug(i)?Wg(i)&&r_(a,i,n):n[a.index]=o_(a,i)}}function i_(e){return e instanceof Vg?e.text:Array.isArray(e)?`[${e.map(i_).join(`,`)}]`:typeof e==`object`&&e?`{${Object.keys(e).map(t=>`${JSON.stringify(t)}:${i_(e[t])}`).join(`,`)}}`:JSON.stringify(e)}function a_(e){return typeof e==`string`?e:e==null?``:e instanceof Vg?e.text:typeof e==`object`?i_(e):String(e)}function o_(e,t){return Array.isArray(t)?e.joins?t.map(a_).join(`; `):i_(t):a_(t)}function s_(e,{lines:t=!1}={}){let n=Gg(e,t),r=n.lines?{rows:n.top}:Zg(n.top),{rows:i}=r,a={from:r.from??null,keyed:!!r.keys,lines:n.lines,rows:i.length},o=(e,t)=>({joined:e.filter(e=>e.lists&&e.joins).map(t),asJson:e.filter(e=>e.lists&&!e.joins).map(t)});if(i.length&&i.every(Array.isArray)){let e=[];for(let t of i)t.forEach((t,n)=>(e[n]??=new e_(n)).see(Ug(t)?null:t));let t=i.map(t=>{let n=Array(e.length).fill(``);return t.forEach((t,r)=>{n[r]=o_(e[r],t)}),n});return{...a,records:t,hasHeader:!1,columns:e.length,...o(e,e=>`column ${e.name+1}`)}}let s=new e_(``),c=r.keys?s.kid($g):null;c&&(c.leaf=!0);for(let e of i)Ug(e)?n_(s,e):e!==null&&s.kid(Qg).see(e);let l=[];(function e(t,n){for(let r of t.kids?.values()??[])r.label=typeof r.name==`symbol`?r.name.description:n+r.name,r.leaf&&(r.index=l.length,l.push(r)),r.kids&&e(r,`${r.label}.`)})(s,``);let u=zg(l.map(e=>e.label),!1),d=[u],f=s.kids?.get(Qg);return i.forEach((e,t)=>{let n=Array(l.length).fill(``);c&&(n[c.index]=r.keys[t]),Ug(e)?r_(s,e,n):e!==null&&(n[f.index]=o_(f,e)),d.push(n)}),{...a,records:d,hasHeader:!0,columns:l.length,...o(l,e=>u[e.index])}}var c_=e=>/\.gz$/i.test(e),l_=e=>/\.zip$/i.test(e),u_=e=>c_(e)||l_(e),d_=e=>e.replace(/\.gz$/i,``);async function f_(e){if(e.length<18||e[0]!==31||e[1]!==139)throw Error(`This file is not a gzip file.`);try{let t=new Blob([e]).stream().pipeThrough(new DecompressionStream(`gzip`));return new Uint8Array(await new Response(t).arrayBuffer())}catch{throw Error(`This gzip file is damaged.`)}}var p_=e=>e.split(/[\\/]/).pop();function m_(e){return e.filter(e=>{if(/[\\/]$/.test(e))return!1;let t=e.split(/[\\/]/);return t[0]!==`__MACOSX`&&!t.some(e=>e.startsWith(`.`))})}var h_=e=>e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.slice().buffer;async function g_(t,n,r=()=>!0){if(c_(t)){if(/\.tar\.gz$/i.test(t))throw Error(`This is a tar archive, which can’t be opened. Extract its files first.`);let e=d_(t),r=await f_(n);return[{name:e,path:e,size:r.length,arrayBuffer:async()=>h_(r)}]}let i=e(n);return m_(i.names).filter(e=>r(p_(e))).map(e=>({name:p_(e),path:e,size:i.size(e),arrayBuffer:async()=>h_(await i.read(e))}))}function __(e){let t=e.header?.length??0;for(let n of e.rows)n.length>t&&(t=n.length);return t}var v_=(e,t)=>e.length>=t?e:[...e,...Array(t-e.length).fill(``)],y_=60;function b_(e){let t=__(e);if(!t)return``;let n=e=>e.replaceAll(`|`,`\\|`).replace(/\r\n?|\n/g,`<br>`),r=(e.header?v_(e.header,t):Array(t).fill(``)).map(n),i=e.rows.map(e=>v_(e,t).map(n)),a=Array.from({length:t},(e,t)=>{let n=3;for(let e of[r,...i])n=Math.max(n,Math.min(y_,uc(e[t])));return n}),o=t=>!!e.numbers[t],s=(e,t)=>{let n=` `.repeat(Math.max(0,a[t]-uc(e)));return o(t)?n+e:e+n},c=e=>`| ${e.map(s).join(` | `)} |`,l=`| ${a.map((e,t)=>o(t)?`-`.repeat(e-1)+`:`:`-`.repeat(e)).join(` | `)} |`;return[c(r),l,...i.map(c)].join(`
59
+ `)+`
60
+ `}var x_=e=>e.replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e]),S_=e=>x_(e).replace(/\r\n?|\n/g,`<br>`);function C_(e,{paste:t=!1}={}){let n=__(e);if(!n)return``;let r=t?Array.from({length:n},(t,n)=>e.kinds?e.kinds[n]===`text`:!e.numbers[n]):[],i=(e,t)=>r[e]?` style="mso-number-format:'\\@'"${t?` data-sheets-value="${x_(JSON.stringify({1:2,2:t}))}"`:``}`:``,a=(e,t)=>` <tr>${v_(e,n).map((e,n)=>`<${t}${t===`td`?i(n,e):``}>${S_(e)}</${t}>`).join(``)}</tr>`,o=[`<table>`];e.header&&o.push(` <thead>`,a(e.header,`th`),` </thead>`),o.push(` <tbody>`,...e.rows.map(e=>a(e,`td`)),` </tbody>`,`</table>`);let s=o.join(`
61
+ `)+`
62
+ `;return t?`<google-sheets-html-origin>${s}</google-sheets-html-origin>`:s}var w_=new Set(`all alter and any as asc between by case check column constraint create cross current
63
+ default delete desc distinct drop else end exists foreign from full grant group having in index inner insert
64
+ into is join key left like limit not null offset on or order outer primary references right select set table
65
+ then to union unique update user using values when where with`.split(/\s+/));function T_(e){return/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)&&!w_.has(e.toLowerCase())?e:`"${e.replaceAll(`"`,`""`)}"`}function E_(e){let t=String(e??``).normalize(`NFKD`).replace(/[̀-ͯ]/g,``).replace(/[^A-Za-z0-9_]+/g,`_`).replace(/^_+|_+$/g,``);return t?/^\d/.test(t)?`t_${t}`:t:`data`}function D_(e,t){let n=e.trim();return t===`,`?n.replaceAll(`.`,``).replace(`,`,`.`):n.replaceAll(`,`,``)}var O_=e=>`'${e.replaceAll(`'`,`''`)}'`;function k_(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim());if(!t)return!1;let n=+t[1],r=+t[2],i=+t[3];return r<1||r>12||i<1?!1:i<=[31,n%4==0&&(n%100!=0||n%400==0)?29:28,31,30,31,30,31,31,30,31,30,31][r-1]&&n>=1}var A_=2147483647;function j_(e){let t=__(e);return Array.from({length:t},(t,n)=>{let r=e.numbers[n],i=!1,a=!!r,o=!0,s=!0,c=!1;for(let t of e.rows){let e=t[n]??``;if(!zu(e)){if(i=!0,a){if(Vu(e,r)===null)a=!1;else{let t=D_(e,r);/^[-+]?\d+$/.test(t)?Math.abs(Number(t))>A_&&(c=!0):s=!1}}if(o&&!k_(e)&&(o=!1),!a&&!o)break}}return i?a?s?c?`BIGINT`:`INTEGER`:`NUMERIC`:o?`DATE`:`TEXT`:`TEXT`})}var M_=500;function N_(e,{createTable:t=!1}={}){let n=__(e);if(!n||!e.rows.length&&!t)return``;let r=zg(e.header?v_(e.header,n):Array.from({length:n},(e,t)=>`column${t+1}`)).map(T_),i=T_(E_(e.name));if(!t){let t=`INSERT INTO ${i} (${r.join(`, `)}) VALUES (`,a=(t,n)=>{let r=e.numbers[n];if(r){if(zu(t))return`NULL`;if(Vu(t,r)!==null)return D_(t,r)}return O_(t)};return e.rows.map(e=>t+v_(e,n).map(a).join(`, `)+`);`).join(`
66
+ `)+`
67
+ `}let a=j_(e),o=(t,n)=>{let r=a[n];return r===`TEXT`?O_(t):zu(t)?`NULL`:r===`DATE`?O_(t.trim()):D_(t,e.numbers[n])},s=[`BEGIN;`,``,`CREATE TABLE ${i} (`,r.map((e,t)=>` ${e} ${a[t]}`).join(`,
68
+ `),`);`],c=`INSERT INTO ${i} (${r.join(`, `)}) VALUES`;for(let t=0;t<e.rows.length;t+=M_){let r=Math.min(e.rows.length,t+M_),i=[];for(let a=t;a<r;a++)i.push(` (${v_(e.rows[a],n).map(o).join(`, `)})`);s.push(``,c,i.join(`,
69
+ `)+`;`)}return s.push(``,`COMMIT;`),s.join(`
70
+ `)+`
71
+ `}function P_(e){let t=(e.name||`Table`).replace(/[&<>"]/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`})[e]),n=[];for(let t=0;t<__(e);t++)e.numbers[t]&&n.push(`td:nth-child(${t+1})`);let r=[`body { font: 14px/1.4 system-ui, sans-serif; margin: 24px; }`,`table { border-collapse: collapse; }`,`th, td { border: 1px solid #ccc; padding: 4px 8px; text-align: left; vertical-align: top; }`,`th { background: #f2f2f2; }`,...n.length?[`${n.join(`, `)} { text-align: right; font-variant-numeric: tabular-nums; }`]:[]];return[`<!doctype html>`,`<html>`,`<head>`,`<meta charset="utf-8">`,`<title>${t}</title>`,`<style>`,...r.map(e=>` `+e),`</style>`,`</head>`,`<body>`,C_(e).trimEnd(),`</body>`,`</html>`].join(`
72
+ `)+`
73
+ `}var F_={"text/csv":[`.csv`],"text/tab-separated-values":[`.tsv`,`.tab`],"text/plain":[`.txt`]},I_={"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":[`.xlsx`,`.xlsm`],"application/vnd.ms-excel":[`.xls`],"application/vnd.oasis.opendocument.spreadsheet":[`.ods`]},L_={"application/json":[`.json`],"application/jsonl":[`.jsonl`,`.ndjson`]},R_={"application/gzip":[`.gz`],"application/zip":[`.zip`]};({...F_,...I_,...L_,...R_});var z_=e=>/\.(xlsx|xlsm|xls|ods)$/i.test(e),B_=e=>/\.(json|jsonl|ndjson)$/i.test(e),V_=e=>/\.(jsonl|ndjson)$/i.test(e),H_=e=>/\.(tsv|tab)$/i.test(e),U_=e=>/\.(csv|tsv|tab|txt|json|jsonl|ndjson)$/i.test(e),W_=65536;function G_(e,t=``){let n=e.length>W_,r=n?e.slice(0,W_):e,{delimiter:i,hasHeader:a,preamble:o=0}=Jh(r,{truncated:n});H_(t)&&i!==` `&&(i=` `,{hasHeader:a,preamble:o=0}=Jh(r.replace(/,/g,` `),{truncated:n}));let s=Rg(e.length>4<<20?e.slice(0,4<<20):e,i);return{delimiter:i,hasHeader:a,eols:s,preamble:o}}var K_=e=>e.replace(/\.[^.]+$/,``),q_={",":`comma`,";":`semicolon`," ":`tab`,"|":`pipe`},J_=e=>q_[e]??`“${e}”`,Y_=e=>e===`\r
74
+ `?`CRLF`:e===`\r`?`CR`:`LF`;function X_(e){if(e==null)return null;let t=String(e),n={tab:` `,"\\t":` `,comma:`,`,semicolon:`;`,pipe:`|`,space:` `}[t.toLowerCase()];if(n)return n;if([...t].length!==1||t===`"`||t===`
75
+ `||t===`\r`)throw new c(`The delimiter must be one character (or tab, comma, semicolon, pipe), not “${t}”.`);return t}function Z_(e){if(e==null)return null;let t={utf8:`utf-8`,"utf-8":`utf-8`,cp1252:`windows-1252`,"windows-1252":`windows-1252`,latin1:`windows-1252`,"iso-8859-1":`windows-1252`,"utf-16le":`utf-16le`,utf16le:`utf-16le`,"utf-16be":`utf-16be`,utf16be:`utf-16be`,"utf-16":`utf-16le`}[String(e).toLowerCase().replace(/_/g,`-`)];if(!t)throw new c(`Unknown encoding “${e}”. Use utf-8, windows-1252, utf-16le or utf-16be.`);return t}function Q_(e){if(e==null)return null;let t={crlf:`\r
76
+ `,"\r\n":`\r
77
+ `,lf:`
78
+ `,"\n":`
79
+ `,cr:`\r`,"\r":`\r`,windows:`\r
80
+ `,unix:`
81
+ `}[String(e).toLowerCase()];if(!t)throw new c(`Unknown line break “${e}”. Use crlf or lf.`);return t}function $_(e,t,n){return j.create({doc:e,extensions:[Bt({delimiter:t,hasHeader:n}),q,ku,Mu,lf]})}async function ev(e,t,n={}){if(u_(t)){let r;try{r=await g_(t,e,U_)}catch(e){throw new c(`Could not read ${t}: ${e.message}`)}if(!r.length)throw new c(`${t} has no CSV, TSV, text or JSON files.`);let i=r[0];if(r.length>1){let e=n.entry?.toLowerCase();if(i=e?r.find(t=>t.path.toLowerCase()===e||t.name.toLowerCase()===e):null,!i){let i=r.map(e=>e.path).join(`, `);throw new c(e?`${t} has no file “${n.entry}”. It has: ${i}.`:`${t} has ${r.length} files: ${i}. Choose one with the entry option.`)}}let a=await ev(new Uint8Array(await i.arrayBuffer()),i.name,{...n,entry:void 0});return a.from.archive=t,a.from.entries=r.map(e=>e.path),a}return z_(t)?nv(e,t,n):B_(t)?rv(e,t,n):tv(e,t,n)}function tv(e,t,n){let{text:r,encoding:i,bom:a}=kg(e,Z_(n.encoding)??void 0),o=G_(r,t),s=X_(n.delimiter)??o.delimiter,{hasHeader:c,preamble:l}=o;s!==o.delimiter&&(c=qh(Ph(r.slice(0,65536),s)),l=0),n.header!=null&&(c=!!n.header);let u=[];return l&&u.push(`${l===1?`The first line is`:`The first ${l} lines are`} above the table (a title or notes), not rows: the fix “preamble” removes them.`),{state:$_(r,s,c),from:{name:t,kind:`text`,encoding:i,bom:a,eols:o.eols,preamble:l,notes:u}}}async function nv(e,t,n){let{readWorkbook:r}=await import(`./excel-pdfNVgvx.js`),i;try{i=r(e)}catch(e){throw new c(`Could not read ${t} as a workbook: ${e.message}`)}if(!i.sheetNames.length)throw new c(`${t} has no sheets.`);let a=i.sheetNames[0];if(n.sheet!=null&&(a=i.sheetNames.find(e=>e.toLowerCase()===String(n.sheet).toLowerCase()),!a))throw new c(`${t} has no sheet “${n.sheet}”. Its sheets: ${i.sheetNames.join(`, `)}.`);let o=cl(i.sheetRecords(a),{delimiter:`,`,recordEol:`
82
+ `,finalEol:!0}),s=G_(o),l=n.header??s.hasHeader,u=[];return i.sheetNames.length>1&&n.sheet==null&&u.push(`${t} has ${i.sheetNames.length} sheets: this is the first, “${a}”. The others: ${i.sheetNames.slice(1).join(`, `)}.`),{state:$_(o,`,`,l),from:{name:t,kind:`excel`,sheet:a,sheets:i.sheetNames,encoding:`utf-8`,bom:!0,eols:{record:`\r
83
+ `,inCell:`
84
+ `},preamble:0,notes:u}}}function rv(e,t,n){let r;try{r=s_(kg(e).text,{lines:V_(t)})}catch(e){throw new c(`Could not read ${t} as JSON: ${e.message}`)}if(!r.rows||!r.columns)throw new c(`${t} has no rows.`);let i=cl(r.records,{delimiter:`,`,recordEol:`
85
+ `,finalEol:!0}),a=n.header??(r.hasHeader||G_(i).hasHeader),o=[];return r.from&&o.push(`The rows are the ${r.rows} items of “${r.from}” in the file; the rest of it is left out.`),r.keyed&&o.push(`A row for each key of the file’s object, in the column “key”.`),r.joined.length&&o.push(`Lists in ${r.joined.map(e=>`“${e}”`).join(`, `)} are joined with “; ”.`),r.asJson.length&&o.push(`Lists in ${r.asJson.map(e=>`“${e}”`).join(`, `)} stay as JSON.`),{state:$_(i,`,`,a),from:{name:t,kind:`json`,encoding:`utf-8`,bom:!1,eols:{record:`
86
+ `,inCell:`
87
+ `},preamble:0,notes:o}}}function iv(e){let t=[];return rl(Tl(e.doc),e.field(N).delimiter,e=>{t.push(e)}),t}function av(e,t){let n=[];return t<=0||rl(Tl(e.doc),e.field(N).delimiter,e=>(n.push(e),n.length>=t)),n}var ov={csv:`.csv`,tsv:`.tsv`,txt:`.txt`,json:`.json`,jsonl:`.jsonl`,xlsx:`.xlsx`,ods:`.ods`,sql:`.sql`,md:`.md`,html:`.html`},sv={csv:`csv`,tsv:`tsv`,tab:`tsv`,txt:`txt`,json:`json`,jsonl:`jsonl`,ndjson:`jsonl`,xlsx:`xlsx`,ods:`ods`,sql:`sql`,md:`md`,markdown:`md`,html:`html`,htm:`html`},cv=e=>e===`xlsx`||e===`ods`;function lv(e){if(e==null)return null;let t=String(e).toLowerCase().replace(/^\./,``),n={excel:`xlsx`,xls:`xlsx`,markdown:`md`,htm:`html`,ndjson:`jsonl`,"json-lines":`jsonl`,tab:`tsv`,text:`txt`}[t]??t;if(!ov[n])throw new c(`Unknown format “${e}”. Use one of: ${Object.keys(ov).join(`, `)}.`);return n}function uv(e){let t=/\.([^./\\]+)$/.exec(e??``);return t?sv[t[1].toLowerCase()]??null:null}function dv(e,t){return t.kind===`text`?H_(t.name)||e.field(N).delimiter===` `?`tsv`:uv(t.name)===`txt`?`txt`:`csv`:`csv`}function fv(e,t,n,r){let i=lv(e.type)??(r&&r!==`-`?uv(r):null)??dv(t,n);return X_(e.delimiter),Z_(e.encoding),Q_(e.eol),{type:i,delimiter:e.delimiter??null,encoding:e.encoding??null,bom:e.bom??null,eol:e.eol??null,quoteAll:!!e.quoteAll}}function pv(e,t,n,i){if(t.kind!==`text`||t.archive||![`csv`,`tsv`,`txt`,null].includes(uv(e)))throw new c(`Only CSV, TSV and text files are written over: ${r.basename(e)} isn’t one. Write the result to another file.`);if(i.type!==dv(n,t))throw new c(`A file is written over in its own format: ${r.basename(e)} can’t become ${i.type}. Write it to another file.`)}async function mv(e,t,n){let{type:r}=n,i=e.field(N),a=n.name??t.sheet??K_(t.name),o=[],s=e=>({bytes:Ig(e,`utf-8`,!1).bytes,notes:o});if(r===`json`||r===`jsonl`)return s(Bg(iv(e),{hasHeader:i.hasHeader,numberSep:t=>dg(e,t),lines:r===`jsonl`}));if(r===`sql`||r===`md`||r===`html`){let t=iv(e),n={header:i.hasHeader&&t.length?t.shift():null,rows:t,name:a,numbers:Array.from({length:Au(e).columns},(t,n)=>dg(e,n))};return s(r===`sql`?N_(n,{createTable:!0}):r===`md`?b_(n):P_(n))}if(cv(r)){let{writeWorkbook:t}=await import(`./excel-pdfNVgvx.js`);return{bytes:t([{name:a,records:iv(e),hasHeader:i.hasHeader}],{bookType:r}),notes:o}}let l=X_(n.delimiter);l||=r===`tsv`?` `:r===`csv`&&i.delimiter===` `?`,`:i.delimiter;let u=Z_(n.encoding),d=u??t.encoding,f=n.bom??(u&&u!==t.encoding?u.startsWith(`utf-16`):t.bom),p=Q_(n.eol)??t.eols.record,m={record:p,inCell:t.eols.record===t.eols.inCell?p:t.eols.inCell},h=l===i.delimiter&&!n.quoteAll?_u(e,m):cl(iv(e),{delimiter:l,recordEol:m.record,inCellEol:m.inCell,quoteAll:!!n.quoteAll}),g=Lg(h,d);if(g){let e=`${g.toLocaleString(`en`)} character${g===1?``:`s`}`;if(u)throw new c(`${e} can’t be written in ${Og(d)}. Write it in UTF-8 instead.`);o.push(`Written in UTF-8: ${e} can’t be written in ${Og(d)}, the file’s encoding.`),d=`utf-8`,f=!1}return{bytes:Ig(h,d,f).bytes,notes:o}}var hv=`AD|AND|Andorra
88
+ AE|ARE|United Arab Emirates|UAE|U.A.E.
89
+ AF|AFG|Afghanistan
90
+ AG|ATG|Antigua and Barbuda
91
+ AI|AIA|Anguilla
92
+ AL|ALB|Albania
93
+ AM|ARM|Armenia
94
+ AO|AGO|Angola
95
+ AQ|ATA|Antarctica
96
+ AR|ARG|Argentina
97
+ AS|ASM|American Samoa
98
+ AT|AUT|Austria
99
+ AU|AUS|Australia
100
+ AW|ABW|Aruba
101
+ AX|ALA|Åland Islands
102
+ AZ|AZE|Azerbaijan
103
+ BA|BIH|Bosnia and Herzegovina|Bosnia
104
+ BB|BRB|Barbados
105
+ BD|BGD|Bangladesh
106
+ BE|BEL|Belgium
107
+ BF|BFA|Burkina Faso
108
+ BG|BGR|Bulgaria
109
+ BH|BHR|Bahrain
110
+ BI|BDI|Burundi
111
+ BJ|BEN|Benin
112
+ BL|BLM|Saint Barthélemy|St. Barthélemy
113
+ BM|BMU|Bermuda
114
+ BN|BRN|Brunei|Brunei Darussalam
115
+ BO|BOL|Bolivia|Bolivia, Plurinational State of|Plurinational State of Bolivia
116
+ BQ|BES|Caribbean Netherlands|Bonaire, Sint Eustatius and Saba
117
+ BR|BRA|Brazil|Brasil
118
+ BS|BHS|Bahamas
119
+ BT|BTN|Bhutan
120
+ BV|BVT|Bouvet Island
121
+ BW|BWA|Botswana
122
+ BY|BLR|Belarus
123
+ BZ|BLZ|Belize
124
+ CA|CAN|Canada
125
+ CC|CCK|Cocos (Keeling) Islands|Cocos Islands
126
+ CD|COD|Democratic Republic of the Congo|DR Congo|DRC|Congo, Democratic Republic of the|Congo-Kinshasa|Congo (Kinshasa)
127
+ CF|CAF|Central African Republic
128
+ CG|COG|Republic of the Congo|Congo|Congo-Brazzaville|Congo (Brazzaville)
129
+ CH|CHE|Switzerland
130
+ CI|CIV|Côte d’Ivoire|Ivory Coast
131
+ CK|COK|Cook Islands
132
+ CL|CHL|Chile
133
+ CM|CMR|Cameroon
134
+ CN|CHN|China|People’s Republic of China|PRC
135
+ CO|COL|Colombia
136
+ CR|CRI|Costa Rica
137
+ CU|CUB|Cuba
138
+ CV|CPV|Cape Verde|Cabo Verde
139
+ CW|CUW|Curaçao
140
+ CX|CXR|Christmas Island
141
+ CY|CYP|Cyprus
142
+ CZ|CZE|Czechia|Czech Republic
143
+ DE|DEU|Germany|Deutschland
144
+ DJ|DJI|Djibouti
145
+ DK|DNK|Denmark
146
+ DM|DMA|Dominica
147
+ DO|DOM|Dominican Republic
148
+ DZ|DZA|Algeria
149
+ EC|ECU|Ecuador
150
+ EE|EST|Estonia
151
+ EG|EGY|Egypt
152
+ EH|ESH|Western Sahara
153
+ ER|ERI|Eritrea
154
+ ES|ESP|Spain|España
155
+ ET|ETH|Ethiopia
156
+ FI|FIN|Finland
157
+ FJ|FJI|Fiji
158
+ FK|FLK|Falkland Islands|Falkland Islands (Malvinas)
159
+ FM|FSM|Micronesia|Federated States of Micronesia|Micronesia, Federated States of
160
+ FO|FRO|Faroe Islands
161
+ FR|FRA|France
162
+ GA|GAB|Gabon
163
+ GB|GBR|United Kingdom|UK|U.K.|Great Britain|Britain|United Kingdom of Great Britain and Northern Ireland
164
+ GD|GRD|Grenada
165
+ GE|GEO|Georgia
166
+ GF|GUF|French Guiana
167
+ GG|GGY|Guernsey
168
+ GH|GHA|Ghana
169
+ GI|GIB|Gibraltar
170
+ GL|GRL|Greenland
171
+ GM|GMB|Gambia
172
+ GN|GIN|Guinea
173
+ GP|GLP|Guadeloupe
174
+ GQ|GNQ|Equatorial Guinea
175
+ GR|GRC|Greece
176
+ GS|SGS|South Georgia and the South Sandwich Islands
177
+ GT|GTM|Guatemala
178
+ GU|GUM|Guam
179
+ GW|GNB|Guinea-Bissau
180
+ GY|GUY|Guyana
181
+ HK|HKG|Hong Kong
182
+ HM|HMD|Heard Island and McDonald Islands
183
+ HN|HND|Honduras
184
+ HR|HRV|Croatia
185
+ HT|HTI|Haiti
186
+ HU|HUN|Hungary
187
+ ID|IDN|Indonesia
188
+ IE|IRL|Ireland|Republic of Ireland
189
+ IL|ISR|Israel
190
+ IM|IMN|Isle of Man
191
+ IN|IND|India
192
+ IO|IOT|British Indian Ocean Territory
193
+ IQ|IRQ|Iraq
194
+ IR|IRN|Iran|Iran, Islamic Republic of|Islamic Republic of Iran
195
+ IS|ISL|Iceland
196
+ IT|ITA|Italy|Italia
197
+ JE|JEY|Jersey
198
+ JM|JAM|Jamaica
199
+ JO|JOR|Jordan
200
+ JP|JPN|Japan
201
+ KE|KEN|Kenya
202
+ KG|KGZ|Kyrgyzstan
203
+ KH|KHM|Cambodia
204
+ KI|KIR|Kiribati
205
+ KM|COM|Comoros
206
+ KN|KNA|Saint Kitts and Nevis|St. Kitts and Nevis
207
+ KP|PRK|North Korea|Korea, Democratic People’s Republic of|Democratic People’s Republic of Korea|DPRK
208
+ KR|KOR|South Korea|Korea, Republic of|Republic of Korea
209
+ KW|KWT|Kuwait
210
+ KY|CYM|Cayman Islands
211
+ KZ|KAZ|Kazakhstan
212
+ LA|LAO|Laos|Lao People’s Democratic Republic|Lao PDR
213
+ LB|LBN|Lebanon
214
+ LC|LCA|Saint Lucia|St. Lucia
215
+ LI|LIE|Liechtenstein
216
+ LK|LKA|Sri Lanka
217
+ LR|LBR|Liberia
218
+ LS|LSO|Lesotho
219
+ LT|LTU|Lithuania
220
+ LU|LUX|Luxembourg
221
+ LV|LVA|Latvia
222
+ LY|LBY|Libya
223
+ MA|MAR|Morocco
224
+ MC|MCO|Monaco
225
+ MD|MDA|Moldova|Moldova, Republic of|Republic of Moldova
226
+ ME|MNE|Montenegro
227
+ MF|MAF|Saint Martin|St. Martin|Saint Martin (French part)
228
+ MG|MDG|Madagascar
229
+ MH|MHL|Marshall Islands
230
+ MK|MKD|North Macedonia|Macedonia
231
+ ML|MLI|Mali
232
+ MM|MMR|Myanmar|Burma
233
+ MN|MNG|Mongolia
234
+ MO|MAC|Macao|Macau
235
+ MP|MNP|Northern Mariana Islands
236
+ MQ|MTQ|Martinique
237
+ MR|MRT|Mauritania
238
+ MS|MSR|Montserrat
239
+ MT|MLT|Malta
240
+ MU|MUS|Mauritius
241
+ MV|MDV|Maldives
242
+ MW|MWI|Malawi
243
+ MX|MEX|Mexico|México
244
+ MY|MYS|Malaysia
245
+ MZ|MOZ|Mozambique
246
+ NA|NAM|Namibia
247
+ NC|NCL|New Caledonia
248
+ NE|NER|Niger
249
+ NF|NFK|Norfolk Island
250
+ NG|NGA|Nigeria
251
+ NI|NIC|Nicaragua
252
+ NL|NLD|Netherlands|The Netherlands|Holland
253
+ NO|NOR|Norway
254
+ NP|NPL|Nepal
255
+ NR|NRU|Nauru
256
+ NU|NIU|Niue
257
+ NZ|NZL|New Zealand
258
+ OM|OMN|Oman
259
+ PA|PAN|Panama|Panamá
260
+ PE|PER|Peru|Perú
261
+ PF|PYF|French Polynesia
262
+ PG|PNG|Papua New Guinea
263
+ PH|PHL|Philippines
264
+ PK|PAK|Pakistan
265
+ PL|POL|Poland
266
+ PM|SPM|Saint Pierre and Miquelon
267
+ PN|PCN|Pitcairn Islands|Pitcairn
268
+ PR|PRI|Puerto Rico
269
+ PS|PSE|Palestine|State of Palestine|Palestine, State of
270
+ PT|PRT|Portugal
271
+ PW|PLW|Palau
272
+ PY|PRY|Paraguay
273
+ QA|QAT|Qatar
274
+ RE|REU|Réunion
275
+ RO|ROU|Romania
276
+ RS|SRB|Serbia
277
+ RU|RUS|Russia|Russian Federation
278
+ RW|RWA|Rwanda
279
+ SA|SAU|Saudi Arabia
280
+ SB|SLB|Solomon Islands
281
+ SC|SYC|Seychelles
282
+ SD|SDN|Sudan
283
+ SE|SWE|Sweden
284
+ SG|SGP|Singapore
285
+ SH|SHN|Saint Helena|Saint Helena, Ascension and Tristan da Cunha
286
+ SI|SVN|Slovenia
287
+ SJ|SJM|Svalbard and Jan Mayen
288
+ SK|SVK|Slovakia|Slovak Republic
289
+ SL|SLE|Sierra Leone
290
+ SM|SMR|San Marino
291
+ SN|SEN|Senegal
292
+ SO|SOM|Somalia
293
+ SR|SUR|Suriname
294
+ SS|SSD|South Sudan
295
+ ST|STP|São Tomé and Príncipe
296
+ SV|SLV|El Salvador
297
+ SX|SXM|Sint Maarten|Sint Maarten (Dutch part)
298
+ SY|SYR|Syria|Syrian Arab Republic
299
+ SZ|SWZ|Eswatini|Swaziland
300
+ TC|TCA|Turks and Caicos Islands
301
+ TD|TCD|Chad
302
+ TF|ATF|French Southern Territories
303
+ TG|TGO|Togo
304
+ TH|THA|Thailand
305
+ TJ|TJK|Tajikistan
306
+ TK|TKL|Tokelau
307
+ TL|TLS|Timor-Leste|East Timor
308
+ TM|TKM|Turkmenistan
309
+ TN|TUN|Tunisia
310
+ TO|TON|Tonga
311
+ TR|TUR|Turkey|Türkiye
312
+ TT|TTO|Trinidad and Tobago
313
+ TV|TUV|Tuvalu
314
+ TW|TWN|Taiwan|Taiwan, Province of China
315
+ TZ|TZA|Tanzania|Tanzania, United Republic of|United Republic of Tanzania
316
+ UA|UKR|Ukraine
317
+ UG|UGA|Uganda
318
+ UM|UMI|United States Minor Outlying Islands
319
+ US|USA|United States|United States of America|U.S.A.|U.S.
320
+ UY|URY|Uruguay
321
+ UZ|UZB|Uzbekistan
322
+ VA|VAT|Vatican City|Holy See|Vatican
323
+ VC|VCT|Saint Vincent and the Grenadines|St. Vincent and the Grenadines
324
+ VE|VEN|Venezuela|Venezuela, Bolivarian Republic of
325
+ VG|VGB|British Virgin Islands|Virgin Islands, British
326
+ VI|VIR|U.S. Virgin Islands|US Virgin Islands|Virgin Islands, U.S.
327
+ VN|VNM|Vietnam|Viet Nam
328
+ VU|VUT|Vanuatu
329
+ WF|WLF|Wallis and Futuna
330
+ WS|WSM|Samoa
331
+ XK|XKX|Kosovo
332
+ YE|YEM|Yemen
333
+ YT|MYT|Mayotte
334
+ ZA|ZAF|South Africa
335
+ ZM|ZMB|Zambia
336
+ ZW|ZWE|Zimbabwe`;function gv(e){let t=e.toLowerCase();return/[^a-z ]/.test(t)&&(t=t.normalize(`NFD`).replace(/\p{M}+/gu,``).replace(/[.'’`]/g,``).replace(/&/g,` and `).replace(/[^\p{L}\p{N}]+/gu,` `)),t=t.replace(/\s+/g,` `).trim(),t.startsWith(`the `)?t.slice(4):t}var _v=new Map,vv=new Map,yv=new Set;for(let e of hv.split(`
337
+ `)){let[t,n,r,...i]=e.split(`|`),a={a2:t,a3:n,name:r};vv.set(t,a),vv.set(n,a);for(let e of[r,...i]){let t=gv(e);_v.set(t,a),/^[A-Z.]+$/.test(e)&&yv.add(t)}}function bv(e){if(e.length>60)return null;if(e.length<=3&&/^[A-Z]+$/.test(e)){let t=vv.get(e);if(t)return{country:t,code:!0}}let t=gv(e),n=_v.get(t);return n?{country:n,code:yv.has(t)}:null}var xv=.1,Sv=10,Cv=`quote.preamble.splitRow.shortRow.longRow.repeatedHeader.emptyRow.duplicateRow.emptyColumn.headerEmpty.headerRepeated.encoding.htmlEntity.chars.unicodeForm.edgeSpace.doubleSpace.mixedMissing.mixedDecimal.mixedNumber.leadingZeros.mixedBoolean.mixedCountry.mixedDate.caseVariant.type.mixedCurrency.badDate.badEmail.excelNumber.excelError.duplicate`.split(`.`),wv={2:`number`,3:`email`,4:`time`,5:`date`},Tv=/(?:^|[^\p{L}])(?:id|key|code|uuid|guid|sku|isbn|e-?mail)(?:[^\p{L}]|$)/iu,Ev=10,Dv=/(?:^|[^\p{L}])(?:zip|zipcode|postal|postcode|plz|cep|cp)(?:[^\p{L}]|$)/iu,Ov=2e4,kv=100,Av=/^[0-9]+$/,jv=/[0-9]/,Mv=/^[1-9][0-9]{14}0+$/,Nv=/^-?[0-9][.,][0-9]{5}E\+([0-9]{2,3})$/,Pv=e=>{let t=e.length;if(t<11||e.charCodeAt(t-4)!==69&&e.charCodeAt(t-5)!==69)return!1;let n=Nv.exec(e);return!!n&&+n[1]>=11},Fv=/[^\x21-\x25\x27-\x7e]/;function Iv(){let e=new Map,t=new Set;return{seen(n){let r=2166136261,i=16777619,a=n.length,o=0;for(;o+1<a;o+=2){let e=n.charCodeAt(o)|n.charCodeAt(o+1)<<16;r=Math.imul(r^e,16777619),i=Math.imul(i^e,2246822519)}if(o<a){let e=n.charCodeAt(o)|65536;r=Math.imul(r^e,16777619),i=Math.imul(i^e,2246822519)}let s=e.get(r);if(s===void 0)return e.set(r,i),!1;if(s===i)return!0;let c=(r>>>0)*4294967296+(i>>>0);return t.has(c)?!0:(t.add(c),!1)}}}var Lv=new Set(`REF!.DIV/0!.VALUE!.NAME?.NUM!.NULL!.SPILL!.CALC!.FIELD!.BLOCKED!.UNKNOWN!.BUSY!.CONNECT!.ERROR!.GETTING_DATA.VALOR!.NOMBRE?.NULO!.DESBORDAMIENTO!.VALEUR!.NOM?.NOMBRE!.NUL!.BEZUG!.WERT!.ZAHL!.RIF!.VALORE!.NOME?.NULLO!.NÚM!.PROPAGACIÓN!.ÜBERLAUF!`.split(`.`)),Rv=e=>/^#{5,}$/.test(e)||Lv.has(e.slice(1).replace(/[¡¿]/g,``).toUpperCase()),zv=/^[^\s@.]+(?:\.[^\s@.]+)*@[^\s@.]+(?:\.[^\s@.]+)*\.[^\s@.0-9]{2,}$/,Bv=/<[a-zA-Z/!]/,Vv=e=>e.includes(`&`)&&!Bv.test(e)&&Op(e)!==e,Hv=new Set([...`nN-—–#?.\\`].map(e=>e.charCodeAt(0))),Uv=(e,t)=>t.length<=4&&Hv.has(t.charCodeAt(0))&&zu(e),Wv=9,Gv=10,Kv=e=>{let t=Qu(e);return t>=0?t:ld(e)?Wv:Gv},qv=e=>Hm(e)===5?Kv(e):-1;function Jv(e,t,n=[]){let r=-1,i=null,a=null,o=e=>e.values.some((e,t)=>{if(!n[t])return!1;let r=Hm(e);return r!==0&&wv[r]!==n[t]}),s=()=>{if(!a)return;let{recs:e,count:n}=a;if(a=null,e.length>1&&n===r&&e.every((e,t)=>t===0||o(e)))t.split?.(e),t.row?.(e[0]);else for(let n of e)n.values.length<r&&t.short?.(n,r),t.row?.(n)};return{get expected(){return r},feed(n){if(W(n))return;let o=n.values.length;r<0&&(r=o,e.hasHeader)?(i=n.values.map(e=>e.trim()),t.header?.(n)):n.values.every(e=>e.trim()===``)?(s(),t.empty?.(n)):i&&o===r&&n.values.every((e,t)=>e.trim()===i[t])?(s(),t.repeated?.(n)):a&&n.line===a.lastLine+1&&a.count+o-1<=r?(a.recs.push(n),a.count+=o-1,a.lastLine=n.lastLine):(s(),o<=r&&r>1?a={recs:[n],count:o,lastLine:n.lastLine}:(o>r&&t.long?.(n,r),t.row?.(n)))},end:s}}function Yv(e,{kinds:t=[],quotes:n=[],max:r=200}={}){let i=new Map(Cv.map(e=>[e,{id:e,count:0,items:[]}])),a=(e,t,n,a,o)=>{let s=i.get(e);s.count++,s.items.length<r&&s.items.push({from:t,to:n,line:a,col:o})};for(let e of n)a(`quote`,e,e+1,0,-1);let o=Bh(e.lines,e.delim);if(o){let t=e.lines.peekLine??e.lines.getLine,n=0;for(let e=1;e<=o;e++){let r=t(e);r.trim()&&a(`preamble`,n,n+r.length,e,-1),n+=r.length+1}i.get(`preamble`).count=o}let s=[];t.forEach((e,t)=>{e===`email`&&(s[t]={seen:new Set,values:0,count:0,items:[]})});let c=null,l=[],u=[],d=0,f=Iv(),p=new Set,m=[],h=e=>m[e]??(m[e]={filled:0,markers:null,dot:0,comma:0,shapes:null,lens:null,zeros:null,other:0,long:0,longRounded:0,lost:0,rounded:!1,forms:void 0,last:null,lastN:null,money:null,bools:void 0,lands:void 0});function g(e,t){if(Qp(t,!1),J.currency===null)return;let n=e.money??={none:0,cur:null,grouped:[0,0],big:[0,0]};J.currency===``?n.none++:(n.cur??=new Map).set(J.currency,(n.cur.get(J.currency)??0)+1);for(let e=0;e<2;e++)J.ok[e]&&(J.grouped[e]?n.grouped[e]++:J.big[e]&&n.big[e]++)}function _(e,t){if(e.bools===null)return;let n=e.bools??={n:0,others:0,forms:new Map};nm(t)<0?++n.others>Sv&&n.others>(n.n+n.others)*xv&&(e.bools=null):(n.n++,n.forms.set(t,(n.forms.get(t)??0)+1))}function v(e,t){if(e.lands===null)return;let n=e.lands??={n:0,others:0,forms:new Map},r=n.forms.get(t);if(!r){let i=bv(t);if(!i){++n.others>Sv&&n.others>(n.n+n.others)*xv&&(e.lands=null);return}if(n.forms.size>=2e3){e.lands=null;return}n.forms.set(t,r={country:i.country,code:i.code,cells:0})}n.n++,r.cells++}function y(e,t,n){e.last||(e.last=Array(64).fill(null),e.lastN=Array(64).fill(0));let r=t.length*7+n*31+t.charCodeAt(t.length-1)&63,i=e.last[r];if(i===t){e.lastN[r]++;return}let a=e.forms??=new Map;if(i!==null&&a.set(i,a.get(i)+e.lastN[r]),e.last[r]=null,!a.has(t)){if(a.size>=Ov){e.forms=null;return}a.set(t,0)}e.last[r]=t,e.lastN[r]=1}function b(e){c=e,l=e.values;let t=new Set;for(let n=0;n<e.values.length;n++){let r=e.values[n],i=r.trim().toLowerCase();i?t.has(i)&&a(`headerRepeated`,e.starts[n],e.ends[n],e.line,n):u.push(n),t.add(i),Tv.test(r)&&!s[n]&&(s[n]={seen:new Set,values:0,count:0,items:[]}),Up(r)!==r&&a(`encoding`,e.starts[n],e.ends[n],e.line,n),Vv(r)&&a(`htmlEntity`,e.starts[n],e.ends[n],e.line,n),xp(r)!==r&&a(`unicodeForm`,e.starts[n],e.ends[n],e.line,n)}}function x(n){c??=n,d++;let i=n.values.length;S.expected>1&&f.seen(n.text??e.slice(n.from,n.to))&&a(`duplicateRow`,n.from,n.to,n.line,-1);for(let e=0;e<i;e++){let i=n.values[e];if(i===``)continue;let o=n.starts[e],c=n.ends[e],l=!Fv.test(i),u=l?i:i.trim();if(!l&&Up(i)!==i?a(`encoding`,o,c,n.line,e):(u.length!==i.length&&a(`edgeSpace`,o,c,n.line,e),!l&&Cp(i)&&a(`chars`,o,c,n.line,e),!l&&xp(i)!==i&&a(`unicodeForm`,o,c,n.line,e)),!l&&kp.test(i)&&a(`doubleSpace`,o,c,n.line,e),!u)continue;let d=h(e);d.filled++,!l&&Vv(i)&&a(`htmlEntity`,o,c,n.line,e);let f=u.charCodeAt(0),p=f>=48&&f<=57,m=t[e],b;if(m){let t=Hm(i);b=t===0,b||(wv[t]===m?t===2?(U.comma<0?d.dot++:U.dot<0&&d.comma++,g(d,u)):t===5?((d.shapes??=Array(11).fill(0))[Kv(i)]++,td(i)&&a(`badDate`,o,c,n.line,e)):t===3&&!zv.test(u)&&a(`badEmail`,o,c,n.line,e):a(`type`,o,c,n.line,e))}else b=Uv(i,u);if(b){(d.markers??=new Map).set(u,(d.markers.get(u)??0)+1);continue}if(m&&m!==`number`||_(d,u),!m&&!p&&v(d,u),p&&(!d.other||u.length>=16)&&Av.test(u)){let e=u.length,t=d.lens??=[];t[e]=(t[e]??0)+1,f===48?(d.zeros??=[])[e]=(d.zeros[e]??0)+1:e>=16&&(d.long++,Mv.test(u)&&(d.longRounded++,d.lost+=e-15))}else d.other++,p||f===45?!d.rounded&&Pv(u)&&(d.rounded=!0):f===35&&Rv(u)&&a(`excelError`,o,c,n.line,e),!p&&d.forms!==null&&(!m||m===`email`)&&u.length<=kv&&y(d,u,f);let x=s[e];x&&(x.values++,x.seen.has(i)?(x.count++,x.items.length<r&&x.items.push({from:o,to:c,line:n.line,col:e}),x.count>50&&x.count>x.values*.1&&(s[e]=void 0)):x.seen.add(i))}}let S=Jv(e,{header:b,row:x,empty(e){c??=e,a(`emptyRow`,e.from,e.to,e.line,-1)},repeated(e){p.add(e.line),a(`repeatedHeader`,e.from,e.to,e.line,-1)},long(e,t){a(`longRow`,e.starts[t],e.to,e.line,-1)},short(e){let t=e.values.length-1;a(`shortRow`,e.ends[t]>e.starts[t]?e.starts[t]:e.from,e.to,e.line,-1)},split(e){a(`splitRow`,e[0].starts[e[0].starts.length-1],e[e.length-1].ends[0],e[0].line,-1);for(let t=1;t<e.length;t++)p.add(e[t].line)}},t);function C(e,t){if(!e.lens||e.other)return 0;let n=0,r=0;e.lens.forEach((e,t)=>{n+=e,t>r&&(r=t)});let i=e.lens[r];return n<Ev||r<2||i===n||i<n/2?0:e.zeros?.[r]||Dv.test(t??``)?r:0}function w(){let t=[],n=!1,r=e=>(n=!0,t[e]??(t[e]={}));return m.forEach((t,n)=>{t.markers&&t.markers.size>1&&(r(n).missing=!0),t.dot&&t.comma&&(r(n).decimal=t.dot<t.comma||t.dot===t.comma&&e.delim===`;`?`.`:`,`),t.shapes&&t.shapes.filter(Boolean).length>1&&(r(n).shape=t.shapes.indexOf(Math.max(...t.shapes))+1);let i=C(t,l[n]);if(i&&(r(n).width=i),t.rounded&&(r(n).rounded=!0),t.long&&t.longRounded===t.long&&t.lost>=3&&(r(n).long=!0),t.forms){t.last.forEach((e,n)=>{e!==null&&t.forms.set(e,t.forms.get(e)+t.lastN[n])});let e=new Map,i=new Set;for(let[n,r]of t.forms){if(jv.test(n))continue;let t=n.toLowerCase();if(t===n&&n.toUpperCase()===n)continue;let a=e.get(t);a?r>a[1]?(i.add(a[0]),e.set(t,[n,r])):i.add(n):e.set(t,[n,r])}i.size&&(r(n).forms=i)}if(t.money){let i=t.money,a=i.cur?[...i.cur].sort((e,t)=>t[1]-e[1]):[],o=a.length>1?a.filter(([e])=>Zp(e,a[0][0])).map(([e])=>e):[];if(o.length)r(n).currency=new Set(o);else{let o=t.dot>t.comma||t.dot===t.comma&&e.delim!==`;`?`.`:`,`,s=o===`.`?0:1,c=a.length>0&&i.none>0,l=i.grouped[s]>0&&i.big[s]>0;(c||l)&&(r(n).money={sep:o,cur:c,grp:l})}}let a=t.bools&&ee(t.bools);a&&(r(n).bool=a);let o=t.lands&&T(t.lands);o&&(r(n).country=o)}),n?t:null}function ee(e){if(e.n<3||e.others>(e.n+e.others)*xv)return null;let t=new Map;for(let[n,r]of e.forms){let e=nm(n)>>1;t.set(e,(t.get(e)??0)+r)}if(t.size<2)return null;let n=-1,r=0;for(let[e,i]of t)i>r&&(n=e,r=i);let i=[null,null],a=[0,0];for(let[t,r]of e.forms){let e=nm(t);e>>1===n&&r>a[e&1]&&(i[e&1]=t,a[e&1]=r)}for(let e=0;e<2;e++)i[e]??=rm(em[n][e],i[1-e]??em[n][1-e]);return{pair:n,words:i}}function T(e){if(e.n<3||e.others>(e.n+e.others)*xv)return null;let t=0,n=0,r=0;for(let[i,a]of e.forms)a.code?(n+=a.cells,i.length===2&&(r+=a.cells)):t+=a.cells;let i=n>t,a=new Map;for(let[t,n]of e.forms){if(n.code!==i)continue;let e=a.get(n.country);(!e||n.cells>e[1])&&a.set(n.country,[t,n.cells])}let o=new Map;for(let[t,s]of e.forms){let e=s.country,c=a.get(e)?.[0]??(i?r*2>=n?e.a2:e.a3:e.name);t!==c&&t.toLowerCase()!==c.toLowerCase()&&o.set(t,c)}return o.size?o:null}function te(e){if(W(e)||e.line===ie||p.has(e.line))return;let t=Math.min(e.values.length,D.length);for(let n=0;n<t;n++){let t=D[n];if(!t)continue;let i=e.values[n],o=i.trim();if(!o)continue;let s=e.starts[n],c=e.ends[n];if(t.missing&&Uv(i,o))a(`mixedMissing`,s,c,e.line,n);else{if(t.decimal&&Hu(i)===t.decimal&&a(`mixedDecimal`,s,c,e.line,n),t.shape){let r=qv(i);r>=0&&r!==t.shape-1&&a(`mixedDate`,s,c,e.line,n)}if(t.width&&o.length<t.width&&Av.test(o)&&a(`leadingZeros`,s,c,e.line,n),(t.rounded&&Pv(o)||t.long&&Mv.test(o))&&a(`excelNumber`,s,c,e.line,n),(t.currency||t.money)&&Hm(i)===2){if(Qp(o),t.currency)J.currency&&t.currency.has(J.currency)&&a(`mixedCurrency`,s,c,e.line,n);else if(J.currency!==null){let r=t.money.sep===`.`?0:1;J.ok[r]&&(t.money.cur&&J.currency!==``||t.money.grp&&J.grouped[r])&&a(`mixedNumber`,s,c,e.line,n)}}if(t.bool){let r=nm(o);r>=0&&r>>1!==t.bool.pair&&a(`mixedBoolean`,s,c,e.line,n)}if(t.country&&t.country.has(o)&&a(`mixedCountry`,s,c,e.line,n),t.forms&&t.forms.has(o)){let i=t.found??={count:0,items:[]};i.count++,i.items.length<r&&i.items.push({from:s,to:c,line:e.line,col:n})}}}}let E=1,ne=0,re=!1,D=null,ie=-1;return{get done(){return re},get progress(){let t=e.length?Math.min(1,ne/e.length):1;return D?.7+.3*t:.7*t},step(t=5e3){if(re)return!0;if(o)return re=!0,!0;let n=0,r=!1,i=D?te:S.feed;return il(e.lines,e.delim,e=>{if(E=e.lastLine+1,ne=e.to+1,i(e),++n>=t)return r=!0,!0},{from:E,fromPos:ne,values:D?e=>!!D[e]:void 0}),r?!1:!D&&(S.end(),D=w(),D)?(ie=e.hasHeader&&c?c.line:-1,E=1,ne=0,!1):(re=!0,!0)},result(){let e=Math.max(0,S.expected),t=i.get(`duplicateRow`);t.count>50&&t.count>d*.1&&(t.count=0,t.items=[]);let n=i.get(`duplicate`);n.count=0,n.items=[];for(let e of s)!e||e.values<Ev||e.count>Math.max(1,Math.floor(e.values*.02))||(n.count+=e.count,n.items.push(...e.items));n.items.sort((e,t)=>e.from-t.from),n.items.length>r&&(n.items.length=r);let a=e=>({from:c.starts[e]??c.to,to:c.ends[e]??c.to,line:c.line,col:e}),o=[];if(d>0)for(let t=0;t<e;t++)m[t]?.filled||o.push(t);let l=(e,t)=>{let n=i.get(e);n.items=t.slice(0,r).map(a),n.count=t.length,n.cols=t};if(l(`emptyColumn`,o),l(`headerEmpty`,u.filter(e=>!o.includes(e))),D){let e=e=>D.flatMap((t,n)=>t&&t[e]?[n]:[]);i.get(`mixedMissing`).cols=e(`missing`),i.get(`mixedDate`).cols=e(`shape`);let t=i.get(`caseVariant`);t.cols=e(`forms`),t.by=Object.fromEntries(t.cols.map(e=>[e,D[e].found??{count:0,items:[]}])),t.count=t.cols.reduce((e,n)=>e+t.by[n].count,0),t.items=t.cols.flatMap(e=>t.by[e].items).sort((e,t)=>e.from-t.from);let n=i.get(`mixedDecimal`),r=i.get(`leadingZeros`);n.cols=e(`decimal`),n.to=Object.fromEntries(n.cols.map(e=>[e,D[e].decimal===`.`?`,`:`.`])),r.cols=e(`width`),r.width=Object.fromEntries(r.cols.map(e=>[e,D[e].width]));for(let[t,n]of[[`mixedNumber`,`money`],[`mixedBoolean`,`bool`],[`mixedCountry`,`country`],[`mixedCurrency`,`currency`]]){let r=i.get(t);r.cols=e(n),r.how=Object.fromEntries(r.cols.map(e=>[e,D[e][n]]))}}let f=Cv.map(e=>i.get(e)).filter(e=>e.count>0);return{problems:f,total:f.reduce((e,t)=>e+t.count,0),columns:e}}}}function*Xv(e,t,n){let r=Jv(e,t,n);yield*G(e.lines,e.delim,e=>{r.feed(e)}),r.end()}var Zv=(e,t,n=t)=>e==null||e>=t.from&&e<=n.to;function*Qv(e,{at:t=null,kinds:n=[]}={}){let r=[];return yield*Xv(e,{short(n,i){Zv(t,n)&&r.push({from:n.to,to:n.to,insert:e.delim.repeat(i-n.values.length)})}},n),{edits:r,rows:r.length}}function*$v(e,{at:t=null,kinds:n=[]}={}){let r=[],i=0;return yield*Xv(e,{split(n){if(!Zv(t,n[0],n[n.length-1]))return;i++;let a=n[0].values.length-1,o=n[0].starts[a],s=n[0].values[a];for(let t=1;t<n.length;t++){let i=n[t];s+=`
338
+ `+i.values[0],a=i.values.length-1,(a>0||t===n.length-1)&&(r.push({from:o,to:i.ends[0],insert:K(s,e.delim,!0)}),o=i.starts[a],s=i.values[a])}}},n),{edits:r,rows:i}}function*ey(e,t,{kinds:n=[]}={}){let r=[],i=0,a=0,o=t=>{i++;let n=t.from-1,o=t.to;t.from===a&&(n=t.from,o=a=Math.min(t.to+1,e.length));let s=r[r.length-1];s&&n<=s.to?s.to=Math.max(s.to,o):r.push({from:n,to:o,insert:``})},s=new Set;return yield*Xv(e,{empty:t===`emptyRow`?o:void 0,repeated:t===`repeatedHeader`?o:void 0,row:t===`duplicateRow`?t=>{let n=t.text??e.slice(t.from,t.to);s.has(n)?o(t):s.add(n)}:void 0},n),{edits:r,rows:i}}var ty=(e,t)=>`${e.toLocaleString(`en`)} ${t}${e===1?``:`s`}`,ny={quote:{title:`Quotes that never close`,tip:`This quote never closes: it is read as a character of the value`},preamble:{title:`Lines above the table`,tip:`This line is above the table: a title or a note, not a row`,fix:`Remove them`,all:`Remove the lines above the table`},shortRow:{title:`Rows with fewer values than the header`,tip:`This row has fewer values than the header`,fix:`Add the missing delimiters`,here:`Add the missing delimiters to this row`,all:`Add the missing delimiters to every short row`},longRow:{title:`Rows with more values than the header`,tip:`These values have no column: the row has more than the header`},splitRow:{title:`Rows cut by a line break`,tip:`A line break cut this row: the value goes on in the next line`,fix:`Join them`,here:`Join this row again`,all:`Join the rows cut by a line break`},emptyRow:{title:`Empty rows`,tip:`This row is empty`,fix:`Remove them`,rows:`empty row`,all:`Remove the empty rows`},duplicateRow:{title:`Rows that repeat an earlier one`,tip:`This row is the same as an earlier one`,fix:`Remove them`,rows:`repeated row`,all:`Remove the rows that repeat an earlier one`},repeatedHeader:{title:`The header row, repeated`,tip:`This row is the header row again`,fix:`Remove them`,rows:`repeated header row`,all:`Remove the repeated header rows`},headerEmpty:{title:`Columns without a name`,tip:`This column has no name`,fix:`Name them`,all:`Name the columns without a name`},headerRepeated:{title:`Column names that repeat another`,tip:`Another column has this name`,fix:`Make them unique`,all:`Make the column names unique`},emptyColumn:{title:`Empty columns`,tip:`This column has no values`,fix:`Delete them`,all:`Delete the empty columns`},type:{title:`Values of another type than their column`,tip:`Not of this column’s type`,select:`values of another type`,one:`value of another type`,all:`Select the values of another type than their column`},mixedDecimal:{title:`Numbers with another decimal separator than their column`,tip:`The other numbers of this column have the other decimal separator`,fix:`Write them like the rest`,here:`Write this number like the rest of its column`,op:`decimalLike`,done:`Decimal separators`,all:`Write the numbers with their column’s decimal separator`},mixedNumber:{title:`Numbers formatted unlike the rest of their column`,tip:`Has a currency sign or thousands separators that other numbers of this column don’t have`,fix:`Write them like the rest`,here:`Write this number like the rest of its column`,op:`unformatNumber`,done:`Numbers written like the rest`,all:`Write the numbers formatted unlike the rest of their column like the rest`},mixedCurrency:{title:`Numbers in another currency than their column`,tip:`In another currency than most numbers of this column`,select:`numbers in another currency`,one:`number in another currency`,all:`Select the numbers in another currency than their column`},mixedBoolean:{title:`Yes/no values written in several ways`,tip:`This column writes its yes/no values another way too`,fix:`Write them one way`,here:`Write this value like most of its column`,op:`boolLike`,done:`Yes/no values written one way`,all:`Write the yes/no values of each column one way`},mixedCountry:{title:`The same country written in different ways`,tip:`This column writes its countries another way`,fix:`Write them one way`,here:`Write this country like the rest of its column`,op:`countryLike`,done:`Countries written one way`,all:`Write the countries of each column one way`},mixedDate:{title:`Dates written another way than their column`,tip:`Most dates of this column are written another way`,fix:`Reformat Dates…`,all:`Reformat the dates of the columns that mix ways of writing them…`},badDate:{title:`Dates that aren’t in the calendar`,tip:`This date isn’t in the calendar`,select:`dates that aren’t in the calendar`,one:`date that isn’t in the calendar`,all:`Select the dates that aren’t in the calendar`},badEmail:{title:`Email addresses with a part missing`,tip:`This address is missing a part`,select:`incomplete addresses`,one:`incomplete address`,all:`Select the email addresses with a part missing`},leadingZeros:{title:`Codes that lost their leading zeros`,tip:`Shorter than the other codes of this column: its zeros in front are gone`,fix:`Add the zeros`,here:`Add this code’s leading zeros`,op:`padZeros`,done:`Leading zeros added`,all:`Add the leading zeros the codes lost`},excelNumber:{title:`Numbers rounded by a spreadsheet`,tip:`A spreadsheet rounded this number: its last digits are lost`,select:`rounded numbers`,one:`rounded number`,all:`Select the numbers rounded by a spreadsheet`},excelError:{title:`Spreadsheet errors`,tip:`An error of the spreadsheet this came from, not a value`,select:`spreadsheet errors`,one:`spreadsheet error`,all:`Select the spreadsheet errors`},mixedMissing:{title:`Missing values written in several ways`,tip:`This column writes its missing values in several ways`,fix:`Empty them`,op:`missingToEmpty`,done:`Missing values emptied`,all:`Empty the missing values of the columns that write them in several ways`},caseVariant:{title:`The same value with other capitals`,tip:`Written with other capitals elsewhere in this column`,fix:`Group Similar Values…`,here:`Group the similar values of this column…`,byColumn:!0,all:`Group the values written with other capitals`},encoding:{title:`Text with a broken encoding`,tip:`Decoded with the wrong encoding`,fix:`Repair them`,here:`Repair this value`,op:`fixEncoding`,header:!0,done:`Encoding repaired`,all:`Repair the text with a broken encoding`},htmlEntity:{title:`HTML entities`,tip:`An HTML entity, not the character it stands for`,fix:`Decode them`,here:`Decode this value’s entities`,op:`decodeHtml`,header:!0,done:`Entities decoded`,all:`Decode the HTML entities`},edgeSpace:{title:`Spaces at the start or end of a value`,tip:`Spaces at the start or end`,fix:`Trim them`,here:`Trim this value`,op:`trimValue`,done:`Trimmed`,all:`Trim every value with spaces at its edges`},doubleSpace:{title:`Repeated spaces inside a value`,tip:`Repeated spaces`,fix:`Make them single`,here:`Make this value’s spaces single`,op:`singleSpaces`,done:`Spaces made single`,all:`Make repeated spaces single in every value`},chars:{title:`Invisible or unusual characters`,tip:`Invisible or unusual characters`,fix:`Clean them`,here:`Clean this value’s characters`,op:`cleanChars`,done:`Characters cleaned`,all:`Clean invisible and unusual characters in every value`},unicodeForm:{title:`Letters written with a separate accent`,tip:`An accent written apart from its letter: it looks the same, but doesn’t match the letter written the usual way`,fix:`Normalize them`,here:`Normalize this value`,op:`normalizeUnicode`,header:!0,done:`Normalized`,all:`Normalize the letters written with a separate accent`},duplicate:{title:`Repeated values in a column of unique ones`,tip:`Repeats an earlier value of this column`,select:`repeated values`,one:`repeated value`,all:`Select the repeated values in columns of unique ones`}},ry=(e,t)=>t?ny[e].title:ny[e].title.replace(`the header`,`the first row`);function*iy(e,t,{result:n,kinds:r,at:i=null}){let a=ny[t],o=n.problems.find(e=>e.id===t),s=X(e),c=(e,t)=>({edits:e.edits,count:e.rows,said:t(e.rows)});if(t===`preamble`){let e=Zh(s);return{edits:e.edits,count:e.lines,said:e.lines?`Removed ${ty(e.lines,`line`)} above the table.`:`Nothing to fix.`}}if(t===`shortRow`)return c(yield*Qv(s,{at:i?.from,kinds:r}),e=>`Added the missing delimiters to ${ty(e,`row`)}.`);if(t===`splitRow`)return c(yield*$v(s,{at:i?.from,kinds:r}),e=>`Joined ${ty(e,`row`)} cut by a line break.`);if(a.rows)return c(yield*ey(s,t,{kinds:r}),e=>`Removed ${ty(e,a.rows)}.`);if(!o)return a.op||t===`emptyColumn`?{edits:[],count:0,said:`Nothing to fix.`}:null;if(t===`emptyColumn`){let{edits:e}=yield*ym(s,o.cols,`delete`);return{edits:e,columns:o.cols,count:o.cols.length,said:`Deleted ${ty(o.cols.length,`empty column`)}.`}}if(a.op){let t=a.header?`too`:!1,{edits:n}=yield*gm(s,i?{column:null,ranges:[{from:i.from,to:i.to}],header:t,everyRow:!0}:o.cols?{column:null,columns:o.cols,ranges:[],header:t,everyRow:!0}:{column:null,ranges:[{from:0,to:e.doc.length}],header:t,everyRow:!0},a.op,{to:e=>o.to?.[e],width:e=>o.width?.[e]??0,how:e=>o.how?.[e]});return{edits:n,count:n.length,said:`${a.done}: ${ty(n.length,`cell`)} changed.`}}return null}var ay=e=>e.trim().toLowerCase();function oy(e,t){let n=e;for(let r=2;t.has(ay(n));r++)n=`${e}_${r}`;return n}var Z=(e,t,n=t+`s`)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`,sy=e=>e.length<=2?e.join(` and `):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`,cy=e=>e===` `?`a tab`:e===`
339
+ `?`a line break`:`“${e}”`,ly=e=>!!e.op&&!!Ty[e.op];function uy(e){return{selection:`It was done on cells selected by hand, which mean nothing in another file.`,file:`It takes its rows from another file.`,clipboard:`It pasted what was on the clipboard.`,place:`It was done at one place of this file.`}[e.why]??`It can’t be done again on another file.`}function dy(e){if(!e||e.all)return`the whole table`;let t=e.cols.map(Y);return t.length>3?`${t.length} columns (${t.slice(0,3).join(`, `)}…)`:sy(t)}function fy(e){return`in the rows where ${e.map(e=>kd({cond:e.cond??null,only:e.only?new Set(e.only):null,except:e.except?new Set(e.except):null},Y(e.col))).join(`, and `)}`}function py(e){if(!ly(e))return e.title;let t=Ty[e.op].text?.(e)??`${e.title} in ${dy(e.in)}`;return e.op===`removeRows`?`${t} ${fy(e.where??[]).replace(/^in /,``)}`:e.where?`${t}, ${fy(e.where)}`:t}var my=e=>({skip:e}),hy=e=>my(e.length===1?`This file has no column ${Y(e[0])}.`:`This file has no columns ${sy(e.map(Y))}.`);function gy(e,t){let n=Eg(e),r=t.map(t=>ch(e,t,n)),i=t.filter((e,t)=>r[t]<0);return i.length?hy(i):{cols:r}}function _y(e,t){if(t.in?.all||!t.in)return{scope:{column:null,ranges:[{from:0,to:e.doc.length}],header:!1}};let n=gy(e,t.in.cols);return n.skip?n:{scope:{column:null,columns:n.cols,ranges:[],header:!1},cols:n.cols}}var vy={column:0,ranges:[],header:!1};function yy(e,t){if(!t)return{hidden:null};let n=gy(e,t.map(e=>e.col));if(n.skip)return my(n.skip.replace(`This file has no`,`Its filter is on a column this file doesn’t have:`).replace(/ columns? /,` `));let r=t.map((e,t)=>({col:n.cols[t],cond:e.cond??null,only:e.only?new Set(e.only):null,except:e.except?new Set(e.except):null})),{doc:i}=e,{runs:a}=jd({lines:Tl(i),slice:(e,t)=>i.sliceString(e,t),length:i.length,delim:e.field(q).delim,hasHeader:e.field(N).hasHeader},r,{sepOf:t=>dg(e,t)}),o=e=>{let t=0,n=a.length-1;for(;t<=n;){let r=t+n>>1;if(e<a[r].from)n=r-1;else if(e>a[r].to)t=r+1;else return!0}return!1},s=a.map(e=>e.from>0?{from:e.from-1,to:e.to}:{from:0,to:Math.min(i.length,e.to+1)});return{hidden:a.length?o:null,ranges:s}}function by(e,t,n){if(!e.field(N).hasHeader)return[];let r=X(e,null),i=[];return il(r.lines,r.delim,e=>(t<e.starts.length&&(i=[{from:e.starts[t],to:e.ends[t],insert:K(n,r.delim)}]),!0),{values:()=>!1}),i}var xy=(e,t)=>({edits:e,said:e.length?`${Z(e.length,`cell`)} changed`:t===0?`No cells there`:`Nothing to change`}),Sy=(e,t)=>({edits:e,said:t?`${Z(t,`row`)} removed`:`No rows to remove`}),Cy=(e,t)=>{let n=gy(e,[t]);return n.skip?n:{col:n.cols[0]}},wy=e=>e.keys??[{by:e.by,desc:e.desc}],Ty={cell:{*run(e,t,n){let r=_y(e,t);if(r.skip)return r;let i=t.params?{...t.params,...t.params.map?{map:new Map(t.params.map)}:{}}:void 0,a=yield*gm(X(e,n.hidden),r.scope,t.name,i);return xy(a.edits,a.cells)},text(e){let t=e.params??{},n=`in ${dy(e.in)}`;if(e.name===`fillEmpty`)return`Fill Empty Cells with “${t.text}” ${n}`;if(e.name===`replaceValue`)return`Replace “${t.from}” with “${t.to}” ${n}`;if(e.name===`mapValues`){let r=new Set(t.map.map(([,e])=>e));return`${e.title}: ${Z(t.map.length,`value`)} ${t.map.length===1?`becomes`:`become`} ${r.size===1?`“${[...r][0]}”`:`${r.size} others`} ${n}`}return`${e.title} ${n}`}},fillDown:{*run(e,t,n){let r=_y(e,t);if(r.skip)return r;let i=yield*vm(X(e,n.hidden),r.scope,t.repeats);return xy(i.edits,i.cells)}},numbers:{*run(e,t,n){let r=_y(e,t);if(r.skip)return r;let i=yield*_g(e,{read:t.read,to:t.to,keep:t.keep},r.scope,X(e,n.hidden));return xy(i.edits,i.found)},text:e=>`Reformat Numbers with a decimal ${e.to===`,`?`comma`:`point`} in ${dy(e.in)}`},dates:{*run(e,t,n){let r=_y(e,t);if(r.skip)return r;let i=yield*vg(e,{read:t.read,format:t.format},r.scope,X(e,n.hidden));return xy(i.edits,i.found)},text:e=>`Reformat Dates as ${e.format} in ${dy(e.in)}`},sort:{*run(e,t,n){let r=wy(t),i=gy(e,r.map(e=>e.by));if(i.skip)return i;let a=yield*fg(e,vy,r.map((e,t)=>({col:i.cols[t],desc:e.desc,as:e.as})),X(e,n.hidden));return{edits:a.edits,said:a.edits.length?`${Z(a.rows,`row`)} sorted`:`Already sorted`}},text(e){let t=wy(e),n=e=>e.as===`length`?`by the length of ${Y(e.by)}`:`by ${Y(e.by)}${e.as===`text`?` as text`:``}`;return t.length===1?`Sort ${n(t[0])}, ${t[0].desc?`descending`:`ascending`}`:`Sort ${t.map(e=>n(e)+(e.desc?` descending`:``)).join(`, then `)}`}},dedupe:{*run(e,t,n){let r=null;if(t.by){let n=Cy(e,t.by);if(n.skip)return n;r=n.col}let i=yield*Bm(X(e,n.hidden),vy,{col:r,loose:t.loose});return Sy(i.edits,i.removed)},text:e=>`Remove Duplicate Rows: ${e.by?`the same ${Y(e.by)}`:`identical rows`}${e.loose?`, ignoring case and spaces`:``}`},emptyRows:{*run(e,t,n){let r=yield*Vm(X(e,n.hidden),vy);return Sy(r.edits,r.removed)},text:()=>`Remove Empty Rows`},removeRows:{*run(e,t,n){let r=yield*hg(X(e,n.hidden),t.which,n.ranges??[]);return Sy(r.edits,r.removed)},text:e=>e.which===`visible`?`Remove`:`Keep only`},columns:{*run(e,t){let n=gy(e,t.in.cols);if(n.skip)return n;let r=[...n.cols].sort((e,t)=>e-t),i=0;if(t.action===`moveTo`){let n=t.to?.before??t.to?.after;if(!n)return{edits:[],said:`Nothing to do`};let r=gy(e,[n]);if(r.skip)return r;i=r.cols[0]+ +!t.to.before}let{edits:a,rows:o}=yield*ym(X(e,null),r,t.action,i),s=t.action===`insertLeft`?r[0]:r[r.length-1]+1,c=t.name&&a.length&&/^insert/.test(t.action);return{edits:a,said:a.length?`In ${Z(o,`row`)}`:`Nothing to do`,...c?{then:e=>by(e,s,t.name)}:{}}},text(e){let t=sy(e.in.cols.map(Y)),n=e.name?`, called “${e.name}”`:``;return{insertLeft:`Insert a Column Left of ${t}${n}`,insertRight:`Insert a Column Right of ${t}${n}`,duplicate:`Duplicate ${t}`,delete:`Delete ${t}`,keepOnly:`Delete Every Column but ${t}`,moveLeft:`Move ${t} Left`,moveRight:`Move ${t} Right`,moveTo:e.to?.before?`Move ${t} Before ${Y(e.to.before)}`:e.to?.after?`Move ${t} After ${Y(e.to.after)}`:`Move ${t}`}[e.action]}},rowNumbers:{*run(e,t){let n=yield*Em(X(e,null));return{edits:n.rows?n.edits:[],said:n.rows?`${Z(n.rows,`row`)} numbered`:`No rows to number`,...t.name&&n.rows?{then:e=>by(e,0,t.name)}:{}}},text:e=>`Insert Row Number Column${e.name?`, called “${e.name}”`:``}`},rename:{*run(e,t){let n=Cy(e,t.col);if(n.skip)return n;if(!e.field(N).hasHeader)return my(`This file has no header row.`);let r=by(e,n.col,t.to).filter(t=>e.doc.sliceString(t.from,t.to)!==t.insert);return{edits:r,said:r.length?`Renamed`:`It has that name already`}},text:e=>`Rename ${Y(e.col)} to “${e.to}”`},replaceAll:{*run(e,t,n){let r=n.hidden?e=>!n.hidden(e):()=>!0;if(t.in?.cols){let i=Cy(e,t.in.cols[0]);if(i.skip)return i;r=cp(e,i.col,n.hidden)}let i=new Sf({search:t.search,replace:t.replace,caseSensitive:t.caseSensitive,regexp:t.regexp,wholeWord:t.wholeWord,literal:t.literal,test:(e,t,n,i)=>r(n,i)});if(!i.valid)return my(`Its search isn’t valid.`);let a=i.create(),o=[];for(let t of a.matchAll(e,1e9)??[])t.precise!==!1&&o.push({from:t.from,to:t.to,insert:a.getReplacement(t)});return{edits:o,said:o.length?`${Z(o.length,`match`,`matches`)} replaced`:`No matches`}},text:e=>`Replace ${e.regexp?`the pattern `:``}“${e.search}” with “${e.replace}” in ${dy(e.in)}`},names:{*run(e,t){let n=jm(X(e,null),t.style);return{edits:n.edits,said:n.edits.length?`${Z(n.edits.length,`name`)} changed`:`Nothing to change`}},text:e=>e.title},split:{*run(e,t){let n=Cy(e,t.col);if(n.skip)return n;let r=yield*$m(X(e,null),n.col,{sep:t.sep,max:t.max||1/0,keep:t.keep});return r.columns<2?{edits:[],said:`No value has the separator`}:{edits:r.edits,said:`${Z(r.columns,`column`)}`}},text:e=>`Split Column ${Y(e.col)} at ${cy(e.sep)}`},join:{*run(e,t){let n=gy(e,t.in.cols);if(n.skip)return n;let r=yield*th(X(e,null),n.cols,{sep:t.sep,skipEmpty:t.skipEmpty});return{edits:r.edits,said:`${Z(r.rows,`row`)}`}},text:e=>`Join Columns ${sy(e.in.cols.map(Y))} with ${cy(e.sep)}`},merge:{*run(e,t){let n=gy(e,t.in.cols);if(n.skip)return n;let r=yield*nh(X(e,null),n.cols);return{edits:r.edits,said:`${Z(r.rows,`row`)}`}},text:e=>`Merge Columns ${sy(e.in.cols.map(Y))}`},unpivot:{*run(e,t){let n=gy(e,t.in.cols);if(n.skip)return n;let r=yield*yh(X(e,null),n.cols,{nameCol:t.nameCol,valueCol:t.valueCol,skipEmpty:t.skipEmpty});return{edits:r.rows?r.edits:[],said:r.rows?`${Z(r.rows,`row`)} → ${r.made.toLocaleString(`en`)}`:`No rows`}},text:e=>`Columns to Rows: ${dy(e.in)}`},pivot:{*run(e,t){let n=Cy(e,t.names),r=Cy(e,t.values);if(n.skip||r.skip)return n.skip?n:r;let i=yield*xh(X(e,null),n.col,r.col,{keep:t.keep,joinApart:t.joinApart});return i.tooMany?my(`${Y(t.names)} has too many different values here to make a column of each.`):{edits:i.edits,said:i.edits.length?`${Z(i.rows,`row`)} → ${i.made.toLocaleString(`en`)}`:`No rows`}},text:e=>`Rows to Columns: names from ${Y(e.names)}, values from ${Y(e.values)}`},transpose:{run(e){let t=Ch(X(e,null));return t.tooMany?my(`This file has more than ${Z(Sh,`row`)}: each would become a column.`):{edits:t.edits,said:t.rows?`${t.rows.toLocaleString(`en`)} × ${t.columns.toLocaleString(`en`)} → ${t.columns.toLocaleString(`en`)} × ${t.rows.toLocaleString(`en`)}`:`No rows`}},text:()=>`Swap Rows and Columns`},splitRows:{*run(e,t){let n=Cy(e,t.col);if(n.skip)return n;let r=yield*wh(X(e,null),n.col,{sep:t.sep,repeat:t.repeat});return{edits:r.edits,said:r.split?`${Z(r.split,`row`)} → ${r.made.toLocaleString(`en`)}`:`No value has the separator`}},text:e=>`Split Values into Rows: ${Y(e.col)} at ${cy(e.sep)}`},combineRows:{*run(e,t){let n=Cy(e,t.col);if(n.skip)return n;let r=yield*Th(X(e,null),n.col,{sep:t.sep,below:t.below});return{edits:r.edits,said:r.groups?`${Z(r.groups+r.removed,`row`)} → ${r.groups.toLocaleString(`en`)}`:`No rows to combine`}},text:e=>`Combine Rows: the values of ${Y(e.col)} with ${cy(e.sep)}`},summarize:{*run(e,t){let n=Eg(e),r=Array(n).fill(null),i=[];for(let a of t.roles){let t=ch(e,a.col,n);t<0?i.push(a.col):r[t]=a.role}if(i.length)return hy(i);let a=new Set(sp(e).map(e=>e.trim().toLowerCase())),o=yield*jh(X(e,null),r,{count:t.count?oy(`count`,a):null,kindOf:t=>Tg(e,t)});return{edits:o.edits,said:o.edits.length?`${Z(o.rows,`row`)} → ${o.groups.toLocaleString(`en`)}`:`No rows`}},text(e){let t=e.roles.filter(e=>e.role===`group`).map(e=>Y(e.col)),n=[...e.roles.filter(e=>e.role!==`group`).map(e=>`${e.role} of ${Y(e.col)}`),...e.count?[`the number of rows`]:[]];return`Summarize${t.length?` by ${sy(t)}`:``}${n.length?`: ${sy(n)}`:``}`}},dropLines:{*run(e,t){let n=X(e,null),r=t.lines;if(n.lines.lineCount<=r)return my(`This file has only ${Z(n.lines.lineCount,`line`)}.`);if(n.recordAt(e.doc.line(r+1).from).line!==r+1)return my(`Line ${r+1} is inside a value of several lines.`);let i=Xh(n,r);return{edits:i.edits,said:`${Z(i.lines,`line`)} deleted`}},text:e=>`Delete the first ${Z(e.lines,`line`)}`},joinHeader:{*run(e,t){let n=Qh(X(e,null),{rows:t.rows,sep:t.sep,carry:t.carry});return n.rows?{edits:n.edits,said:`${Z(n.rows,`row`)} → 1`}:my(`This file doesn’t have ${Z(t.rows,`row`)} and a row after them.`)},text:e=>`Join the first ${Z(e.rows,`row`)} into the header row, with ${cy(e.sep)}${e.carry?``:`, without filling blank cells from the left`}`},fix:{*run(e,t){let n=Cg(e),r=Yv(X(e,null),{kinds:n,quotes:Gm(e),max:1});for(;!r.done;)r.step(5e3);let i=yield*iy(e,t.kind,{result:r.result(),kinds:n});return i?{edits:i.edits,said:i.edits.length?i.said.replace(/\.$/,``):`Nothing to fix`}:my(`This fix can’t be done here.`)},text:e=>e.title}};function*Ey(e,t){let n=e.field(ef,!1)?.filters.length?e.update({effects:Id.of([])}).state:e,r=null,i=0,a=[];for(let e of t){let t;try{if(!ly(e))t=my(uy(e));else{let r=yy(n,e.where),i=r.skip?r:Ty[e.op].run(n,e,r);t=typeof i?.next==`function`?yield*i:i}}catch(e){t=my(`It failed: ${e.message}`)}if(t.skip||!t.edits.length){a.push({step:e,done:!1,skipped:!!t.skip,said:t.skip??t.said});continue}let o=n.update({changes:ng(n,t.edits),annotations:ag(n,t.edits),filter:!1});r=r?r.compose(o.changes):o.changes,n=o.state;let s=t.then?.(n)??[];if(s.length){let e=n.update({changes:s,filter:!1});r=r.compose(e.changes),n=e.state}i++,a.push({step:e,done:!0,skipped:!1,said:t.said})}return{doc:e.doc,changes:r,results:a,done:i,index:r?n.field(q,!1)??null:null}}var Dy=(e,t)=>ol(Ey(e,t)),Oy=4e6,ky=4e3,Ay=8,jy=2e3,My=3,Ny=-1,Py=`\0`,Fy=e=>String(e??``).trim().toLowerCase();function Iy(e,t,n,r){let i=new Int32Array(n).fill(-1),a=new Uint8Array(r),o=[];if(e&&t){let s=new Map;for(let e=0;e<r;e++){let n=Fy(t[e]);s.has(n)||s.set(n,[]),s.get(n).push(e)}for(let t=0;t<n;t++){let n=s.get(Fy(e[t]))?.shift();n!==void 0&&(i[t]=n,a[n]=1)}for(let e=0;e<n;e++)i[e]<0&&e<r&&!a[e]&&(i[e]=e,a[e]=1,o.push(e))}else for(let e=0;e<Math.min(n,r);e++)i[e]=e,a[e]=1;let s=[],c=[];for(let e=0;e<n;e++)i[e]<0&&s.push(e);for(let e=0;e<r;e++)a[e]||c.push(e);return{toOther:i,added:s,removed:c,renamed:o}}function Ly(e,t){let n=3735928559,r=1103547991;for(let i=0;i<t.length;i++){let a=t[i]<e.length?e[t[i]]:Py;for(let e=0;e<a.length;e++){let t=a.charCodeAt(e);n=Math.imul(n^t,2654435761),r=Math.imul(r^t,1597334677)}n=Math.imul(n^31,2654435761),r=Math.imul(r^31,1597334677)}return n=Math.imul(n^n>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),(n&2097151)*4294967296+(r>>>0)}function*Ry(e,t,n){let r=!0,i={line:1,pos:0};for(;r;){r=!1;let a=0;il(e.lines,e.delim,n=>{if(a>=ky)return i={line:n.line,pos:n.from},r=!0,!0;if(a++,!(e.hasHeader&&n.line===1||W(n)))return t(n)},{from:i.line,fromPos:i.pos,values:n}),r&&(yield)}}var zy=e=>e===void 0?``:e.trim(),By=[0];function*Vy(e,t,n,r=-1){let{from:i,to:a,line:o,hash:s}=n;yield*Ry(e,e=>{if(i.push(e.from),a.push(e.to),o.push(e.line),s.push(Ly(e.values,t)),r>=0){let t=zy(e.values[r]);n.key.push(t?Ly([t],By):Ny)}})}function Hy(e){if(!e.hasHeader)return null;let t=null;return il(e.lines,e.delim,e=>(t=e.values,!0)),t??[]}function*Uy(e){let t=0,n=0;return il(e.lines,e.delim,e=>{e.starts.length>t&&(t=e.starts.length),n++},{values:()=>!1}),yield,t}function Wy(e,t){let n=[],r=[],i=[[0,e.length,0,t.length]];for(;i.length;){let[a,o,s,c]=i.pop();for(;a<o&&s<c&&e[a]===t[s];)n.push(a++),r.push(s++);for(;a<o&&s<c&&e[o-1]===t[c-1];)n.push(--o),r.push(--c);if(a>=o||s>=c)continue;let l=new Map;for(let t=a;t<o;t++){let n=l.get(e[t]);n?n.na++:l.set(e[t],{na:1,ia:t,nb:0,ib:-1})}for(let e=s;e<c;e++){let n=l.get(t[e]);n&&(n.nb++,n.ib=e)}let u=[];for(let e of l.values())e.na===1&&e.nb===1&&u.push(e);if(!u.length){(o-a)*(c-s)<=Oy&&Ky(e,t,a,o,s,c,n,r);continue}u.sort((e,t)=>e.ia-t.ia);let d=Gy(u.map(e=>e.ib)),f=a,p=s;for(let e of d){let{ia:t,ib:a}=u[e];i.push([f,t,p,a]),n.push(t),r.push(a),f=t+1,p=a+1}i.push([f,o,p,c])}let a=Array.from(n.keys()).sort((e,t)=>n[e]-n[t]);return{a:Int32Array.from(a,e=>n[e]),b:Int32Array.from(a,e=>r[e])}}function Gy(e){let t=[],n=new Int32Array(e.length).fill(-1);for(let r=0;r<e.length;r++){let i=0,a=t.length;for(;i<a;){let n=i+a>>1;e[t[n]]<e[r]?i=n+1:a=n}i>0&&(n[r]=t[i-1]),t[i]=r}let r=[];for(let e=t.length?t[t.length-1]:-1;e>=0;e=n[e])r.push(e);return r.reverse()}function Ky(e,t,n,r,i,a,o,s){let c=r-n,l=a-i,u=new Uint32Array((c+1)*(l+1)),d=(e,t)=>e*(l+1)+t;for(let r=c-1;r>=0;r--)for(let a=l-1;a>=0;a--)u[d(r,a)]=e[n+r]===t[i+a]?u[d(r+1,a+1)]+1:Math.max(u[d(r+1,a)],u[d(r,a+1)]);let f=0,p=0;for(;f<c&&p<l;)e[n+f]===t[i+p]?(o.push(n+f),s.push(i+p),f++,p++):u[d(f+1,p)]>=u[d(f,p+1)]?f++:p++}function qy(e,t,n,r){let i=[];return n>=r||il(e.lines,e.delim,t=>{if(!(e.hasHeader&&t.line===1||W(t)))return i.push({values:t.values,starts:t.starts,ends:t.ends}),i.length>=r-n},{from:t.line[n],fromPos:t.from[n]}),i}function Jy(e,t,n){let r=e=>e>=0&&e<n.toOther.length&&n.toOther[e]>=0;if(t&&e.name!=null){if(r(e.col)&&Fy(t[e.col])===e.name)return e.col;let i=t.findIndex((t,n)=>r(n)&&Fy(t)===e.name);return i>=0?i:n.renamed.includes(e.col)?e.col:-1}return r(e.col)?e.col:-1}var Yy=(e,t)=>e?Fy(e[t]):null;function*Xy(e,t,n={}){let r=Hy(e),i=Hy(t),a=!!r&&!!i,o=a?r.length:yield*Uy(e),s=a?i.length:yield*Uy(t),c=Iy(a?r:null,a?i:null,o,s),l=[],u=[];for(let e=0;e<o;e++)c.toOther[e]>=0&&(l.push(e),u.push(c.toOther[e]));let d=n.key?Jy(n.key,a?r:null,c):-1,f={from:[],to:[],line:[],hash:[],key:[]},p={from:[],to:[],line:[],hash:[],key:[]};yield*Vy(t,u,f,d<0?-1:c.toOther[d]),yield*Vy(e,l,p,d);let m={changedRows:0,changedCells:0,added:0,removed:0,byColumn:new Map,rows:p.hash.length,otherRows:f.hash.length},h={reordered:!1,key:d<0?null:d,suggest:null,columns:c,names:r,otherNames:i,changed:[],added:[],removed:[],counts:m,capped:!1},g=e.length,_=e=>e<p.from.length?p.from[e]:g,v=0;if(d>=0)return yield*w(),h;if(f.hash.length===p.hash.length&&f.hash.length>1){let e=Float64Array.from(f.hash).sort(),t=Float64Array.from(p.hash).sort(),n=!0,r=!0;for(let r=0;r<e.length&&n;r++)n=e[r]===t[r];for(let e=0;e<f.hash.length&&r;e++)r=f.hash[e]===p.hash[e];if(n&&!r)return h.reordered=!0,h.suggest=yield*ee(),h}yield;let{a:y,b}=Wy(f.hash,p.hash);yield;let x=0,S=0,C=Math.max(1,Math.ceil(l.length/2));for(let e=0;e<=y.length;e++){let t=e<y.length?y[e]:f.hash.length,n=e<b.length?b[e]:p.hash.length;(t>x||n>S)&&(yield*T(x,t,S,n),e&63||(yield)),x=t+1,S=n+1}return Math.min(f.hash.length,p.hash.length)>1&&(m.added+m.removed+v)*2>Math.max(f.hash.length,p.hash.length)&&(h.suggest=yield*ee()),h;function*w(){let n=f.hash.length,r=p.hash.length,i=new Map,a=new Int32Array(n);for(let e=n-1;e>=0;e--){let t=f.key[e];t!==Ny&&(a[e]=i.get(t)??-1,i.set(t,e)),e&65535||(yield)}let o=new Int32Array(n).fill(-1),s=(e,t)=>{let n=0,r=[],i=-2;return a=>((a<n||a>=n+r.length)&&(r=qy(e,t,a,Math.min(t.hash.length,a+(a===i+1?256:1))),n=a),i=a,r[a-n])},c=s(t,f),l=s(e,p),u=0;for(let e=0;e<r;e++){let t=p.key[e],n=t===Ny?-1:i.get(t)??-1;n<0?E(e):(i.set(t,a[n]),o[n]=e,f.hash[n]!==p.hash[e]&&(ne(n,e,c(n),l(e)),u+=63)),++u>=4096&&(u=0,yield)}for(let e=0;e<n;){if(o[e]>=0){e++;continue}let t=e?o[e-1]:-1,r=[];for(;e<n&&o[e]<0;e++)r.push({line:f.line[e],from:f.from[e]});m.removed+=r.length,h.removed.push({at:_(t+1),rows:r})}h.removed.sort((e,t)=>e.at-t.at)}function*ee(){let n=Math.min(l.length,Ay),r=Array(n).fill(!0);function*i(e,t){let i=t.slice(0,n).map(()=>new Set),a=new Set(t.slice(0,n)),o=0;yield*Ry(e,e=>{for(let a=0;a<n;a++){if(!r[a])continue;let n=zy(e.values[t[a]]);!n||i[a].has(n)?r[a]=!1:i[a].add(n)}return++o>=jy},e=>a.has(e))}yield*i(e,l),yield*i(t,u);let a=Math.min(f.hash.length,p.hash.length),o=0;for(let i=0;i<n&&o<My;i++){if(!r[i])continue;o++;let n=new Set,s=new Set,c=!0,d=0;if(yield*Ry(e,e=>{let t=zy(e.values[l[i]]);if(!t||n.has(t))return c=!1,!0;n.add(t)},e=>e===l[i]),c&&(yield*Ry(t,e=>{let t=zy(e.values[u[i]]);if(!t||s.has(t))return c=!1,!0;s.add(t),n.has(t)&&d++},e=>e===u[i])),c&&d*2>=a)return l[i]}return null}function*T(n,r,i,a){let o=r-n,s=a-i,c=[];if(!s)for(let e=n;e<r;e++)c.push([e,a]);else if(o){let l=o===s,u=2e3,d=n,m=i;for(;d<r||m<a;){let n=qy(t,f,d,Math.min(r,d+u)),i=qy(e,p,m,Math.min(a,m+u)),o=0,s=0;for(;o<n.length&&s<i.length;){let e=-1;if(l)e=o;else for(let t=o;t<Math.min(n.length,o+8);t++)if(te(n[t],i[s])>=C){e=t;break}if(e<0)E(m+s),s++;else{for(;o<e;o++)c.push([d+o,m+s]);ne(d+o,m+s,n[o],i[s]),o++,s++}}for(;s<i.length;s++)E(m+s);for(;o<n.length;o++)c.push([d+o,m+s]);if(d+=n.length,m+=i.length,!n.length&&!i.length)break;(d<r||m<a)&&(yield)}}else for(let e=i;e<a;e++)E(e);m.removed+=c.length;for(let e=0;e<c.length;){let t=c[e][1],n=[];for(;e<c.length&&c[e][1]===t;e++)n.push({line:f.line[c[e][0]],from:f.from[c[e][0]]});h.removed.push({at:_(t),rows:n})}}function te(e,t){let n=0;for(let r=0;r<l.length;r++)(l[r]<t.values.length?t.values[l[r]]:Py)===(u[r]<e.values.length?e.values[u[r]]:Py)&&n++;return n}function E(e){m.added++,h.added.push({from:p.from[e],to:p.to[e]})}function ne(e,t,n,r){m.changedRows++;let i=0,a=[],o=[];for(let e=0;e<l.length;e++){let s=l[e];(s<r.values.length?r.values[s]:Py)!==(u[e]<n.values.length?n.values[u[e]]:Py)&&(a.push(s),s<r.starts.length?o.push(r.starts[s],r.ends[s]):o.push(p.to[t],p.to[t]),m.changedCells++,i++,m.byColumn.set(s,(m.byColumn.get(s)??0)+1))}l.length>1&&i*2>l.length&&v++,h.changed.length>=1e5?h.capped=!0:h.changed.push({from:p.from[t],to:p.to[t],line:p.line[t],cols:a,cells:o,otherLine:f.line[e],otherFrom:f.from[e],hash:p.hash[t]})}}function Zy(e){for(;;){let t=e.next();if(t.done)return t.value}}function Qy(e,t,n){let r=[];return il(e.lines,e.delim,e=>(r=e.values,!0),{from:t,fromPos:n}),r}var $y={trim:`Trim Whitespace`,collapseSpaces:`Collapse Whitespace`,removeSpaces:`Remove All Whitespace`,upper:`UPPERCASE`,lower:`lowercase`,title:`Title Case`,removeLetters:`Remove Letters`,removeDigits:`Remove Digits`,removePunctuation:`Remove Punctuation and Symbols`,removeAccents:`Remove Accents`,straightenQuotes:`Straighten Curly Quotes`,decodeHtml:`Decode HTML Entities`,removeInvisible:`Remove Invisible Characters`,normalizeUnicode:`Normalize Unicode (NFC)`,fixEncoding:`Repair Broken Encoding`,missingToEmpty:`Empty Missing Values (NA, null, -…)`,clear:`Clear Cells`,fillEmpty:`Fill Empty Cells`,replaceValue:`Replace Value`,mapValues:`Merge Values`},eb=Cv.filter(e=>ny[e].op||ny[e].rows||[`preamble`,`shortRow`,`splitRow`,`emptyColumn`].includes(e)),tb=[`headerEmpty`,`headerRepeated`],nb=Cv.filter(e=>eb.includes(e)||tb.includes(e));function rb(e){return e===`mixedDate`?`it needs a format: a “dates” step (Reformat Dates) with the format the column should have`:e===`caseVariant`?`which way of writing each value stays is a choice: a “cell” step with “mapValues”, or Group Similar Values in the app`:`its places are to look at, not to change by a rule`}function ib(e){let t=new Set(e),n=[],r=!1;for(let e of Cv)t.has(e)&&(tb.includes(e)?(r||n.push({title:pg.unique,op:`names`,style:`unique`,in:{all:!0}}),r=!0):eb.includes(e)&&n.push({title:ny[e].all??ny[e].fix,op:`fix`,kind:e,in:{all:!0}}));return n}var Q=e=>typeof e==`string`,$=e=>!!e&&typeof e==`object`&&!Array.isArray(e),ab={cell:[`name`,`params`],fillDown:[`repeats`],numbers:[`to`,`read`,`keep`],dates:[`format`,`read`],sort:[`keys`,`by`,`desc`],dedupe:[`by`,`loose`],emptyRows:[],removeRows:[`which`],columns:[`action`,`to`,`name`],rowNumbers:[`name`],rename:[`col`,`to`],replaceAll:[`search`,`replace`,`caseSensitive`,`regexp`,`wholeWord`,`literal`],names:[`style`],split:[`col`,`sep`,`max`,`keep`],join:[`sep`,`skipEmpty`],merge:[],unpivot:[`nameCol`,`valueCol`,`skipEmpty`],pivot:[`names`,`values`,`keep`,`joinApart`],transpose:[],splitRows:[`col`,`sep`,`repeat`],combineRows:[`col`,`sep`,`below`],summarize:[`roles`,`count`],dropLines:[`lines`],joinHeader:[`rows`,`sep`,`carry`],fix:[`kind`]},ob=new Set([`cell`,`fillDown`,`numbers`,`dates`,`sort`,`dedupe`,`emptyRows`,`removeRows`,`replaceAll`]),sb=new Set([`cell`,`fillDown`,`numbers`,`dates`,`columns`,`join`,`merge`,`unpivot`,`replaceAll`]),cb=Object.keys(ab);function lb(e){let t=null,n=e;if($(e)){if(`trustyCsvRecipe`in e&&e.trustyCsvRecipe!==1)throw new c(`This recipe was made by a newer version of Trusty CSV.`);t=Q(e.name)?e.name:null,n=e.steps}if(!Array.isArray(n))throw new c(`A recipe is a list of steps: [{ "op": "cell", "name": "trim", "in": ["city"] }, …].`);if(!n.length)throw new c(`The recipe has no steps.`);let r=[],i=n.map((e,t)=>ub(e,n=>r.push(`Step ${t+1}${$(e)&&Q(e.op)?` (${e.op})`:``}: ${n}`)));if(r.length)throw new c(r.join(`
340
+ `));return{name:t,steps:i}}function ub(e,t){if(!$(e))return t(`a step is an object, with an "op".`),null;if(e.op==null&&Q(e.title)&&e.why)return{...e};let{op:n}=e;if(!Q(n)||!ab[n])return t(`"op" must be one of: ${cb.join(`, `)}.`),null;let r={...e};for(let e of Object.keys(r))[`op`,`title`,`in`,`where`,...ab[n]].includes(e)||t(`it has no field "${e}"${fb(n,e)}.`);if(r.title!=null&&!Q(r.title)&&t(`"title" must be text.`),sb.has(n)){let e=n===`replaceAll`;r.in=r.in==null&&e?{all:!0}:mb(r.in,t,n)}else r.in!=null&&!($(r.in)&&r.in.all===!0)&&r.in!==`all`&&t(`"in" isn’t a field of this step: it is done on the whole table.`),r.in={all:!0};return r.where==null?n===`removeRows`&&t(`"where" says which rows: [{ "col": "country", "only": ["USA"] }].`):ob.has(n)?r.where=gb(r.where,t):t(`"where" isn’t a field of this step: it doesn’t go by a filter.`),Cb[n](r,t),Q(r.title)||(r.title=wb[n](r)),r.op&&!ly(r)&&t(`the app can’t do this step.`),r}var db={column:`col`,columns:`in`,separator:`sep`,delimiter:`sep`,value:`params`,text:`params`,kinds:`kind`,descending:`desc`},fb=(e,t)=>db[t]&&ab[e].concat(`in`).includes(db[t])?` (did you mean "${db[t]}"?)`:``;function pb(e,t,n){if(Q(e)&&e.trim())return{name:e.trim()};if($(e)){if(Q(e.name)&&e.name.trim()&&(e.nth==null||Number.isInteger(e.nth)&&e.nth>=0)&&Object.keys(e).every(e=>e===`name`||e===`nth`))return e.nth?{name:e.name.trim(),nth:e.nth}:{name:e.name.trim()};if(Number.isInteger(e.index)&&e.index>=0&&Object.keys(e).length===1)return{index:e.index}}return t(`${n} must be a column: its name ("city"), { "name": "city", "nth": 1 } for the second one with that name, or { "index": 0 } without a header row.`),{name:`?`}}function mb(e,t,n){if(e===`all`||$(e)&&e.all===!0&&Object.keys(e).length===1)return[`cell`,`fillDown`,`numbers`,`dates`,`replaceAll`].includes(n)||t(`"in" must name its columns.`),{all:!0};let r=Array.isArray(e)?e:$(e)&&Array.isArray(e.cols)&&Object.keys(e).length===1?e.cols:Q(e)&&e.trim()||$(e)&&(`name`in e||`index`in e)?[e]:null;return!r||!r.length?(t(`"in" says where: a list of columns (["city", "country"]) or "all" for every cell but the header row.`),{all:!0}):{cols:r.map((e,n)=>pb(e,t,`"in"[${n}]`))}}var hb=bd.map(e=>e.id);function gb(e,t){if(!Array.isArray(e)||!e.length)t(`"where" is a list of filters: [{ "col": "country", "only": ["USA"] }].`);else return e.map((e,n)=>{let r=`"where"[${n}]`;if(!$(e))return t(`${r} must be an object.`),{};for(let n of Object.keys(e))[`col`,`cond`,`only`,`except`].includes(n)||t(`${r} has no field "${n}".`);let i={col:pb(e.col,t,`${r}.col`)};if(e.cond!=null){let n=e.cond,a=$(n)&&bd.find(e=>e.id===n.op);if(!a)t(`${r}.cond.op must be one of: ${hb.join(`, `)}.`);else{let e={op:n.op};for(let[i,o]of[[`a`,1],[`b`,2]])a.takes<o||(n[i]==null||String(n[i])===``?t(`${r}.cond needs "${i}"${o===2?` (the other end)`:``} for "${n.op}".`):e[i]=String(n[i]));if(a.date&&(n.order!=null&&![`dmy`,`mdy`,`ymd`].includes(n.order)&&t(`${r}.cond.order must be dmy, mdy or ymd.`),e.order=n.order??`dmy`),n.op===`matches`&&e.a)try{new RegExp(e.a)}catch{t(`${r}.cond.a isn’t a valid pattern.`)}i.cond=e}}for(let n of[`only`,`except`])e[n]!=null&&(!Array.isArray(e[n])||!e[n].every(e=>Q(e)||typeof e==`number`)?t(`${r}.${n} must be a list of values.`):i[n]=e[n].map(String));return i.cond||i.only||i.except||t(`${r} needs "cond", "only" or "except".`),i})}var _b=(e,t,n,r)=>{e[t]==null?e[t]=n:typeof e[t]!=`boolean`&&r(`"${t}" must be true or false.`)},vb=(e,t,n,r,i)=>{e[t]==null&&i!==void 0?e[t]=i:n.includes(e[t])||r(`"${t}" must be one of: ${n.map(e=>JSON.stringify(e)).join(`, `)}.`)},yb=(e,t,n,{dflt:r,empty:i=!1}={})=>{e[t]==null&&r!==void 0?e[t]=r:(!Q(e[t])||!i&&e[t]===``)&&n(`"${t}" must be ${i?``:`non-empty `}text.`)},bb=(e,t,n,{min:r=0,dflt:i}={})=>{e[t]==null&&i!==void 0?e[t]=i:(!Number.isInteger(e[t])||e[t]<r)&&n(`"${t}" must be a whole number, ${r} or more.`)},xb=(e,t,n)=>{e[t]=pb(e[t],n,`"${t}"`)},Sb=(e,t,n)=>{e.in.cols&&e.in.cols.length<t&&n(`"in" must name ${t} columns or more.`)},Cb={cell(e,t){vb(e,`name`,Object.keys($y),t);let n=e.params;e.name===`fillEmpty`?$(n)&&Q(n.text)||t(`fillEmpty needs "params": { "text": "what to fill with" }.`):e.name===`replaceValue`?$(n)&&Q(n.from)&&Q(n.to)||t(`replaceValue needs "params": { "from": "exact value", "to": "new value" }.`):e.name===`mapValues`?$(n)&&(Array.isArray(n.map)?n.map.every(e=>Array.isArray(e)&&e.length===2&&e.every(Q)):$(n.map)&&Object.values(n.map).every(Q))?Array.isArray(n.map)||(e.params={map:Object.entries(n.map)}):t(`mapValues needs "params": { "map": { "old value": "new value", … } } (or a list of [old, new] pairs).`):n!=null&&t(`"${e.name}" takes no "params".`)},fillDown:(e,t)=>_b(e,`repeats`,!1,t),numbers(e,t){vb(e,`to`,[`.`,`,`],t,`.`),vb(e,`read`,[`auto`,`.`,`,`],t,`auto`),_b(e,`keep`,!1,t)},dates(e,t){vb(e,`format`,gd,t),vb(e,`read`,[`auto`,`dmy`,`mdy`,`ymd`],t,`auto`)},sort(e,t){e.keys==null&&e.by!=null&&(e.keys=[{by:e.by,desc:e.desc}],delete e.by,delete e.desc),!Array.isArray(e.keys)||!e.keys.length?t(`"keys" is the list of columns to sort by: [{ "by": "date", "desc": false }].`):e.keys=e.keys.map((e,n)=>{if(Q(e)&&(e={by:e}),!$(e))return t(`"keys"[${n}] must be { "by": column, "desc": true | false, "as": "text" | "length" }.`),{};for(let r of Object.keys(e))[`by`,`desc`,`as`].includes(r)||t(`"keys"[${n}] has no field "${r}".`);let r={by:pb(e.by,t,`"keys"[${n}].by`),desc:!!e.desc};return e.desc!=null&&typeof e.desc!=`boolean`&&t(`"keys"[${n}].desc must be true or false.`),e.as!=null&&e.as!==`auto`&&([`text`,`length`].includes(e.as)?r.as=e.as:t(`"keys"[${n}].as must be "auto", "text" or "length".`)),r})},dedupe(e,t){e.by=e.by==null?null:pb(e.by,t,`"by"`),_b(e,`loose`,!1,t)},emptyRows(){},removeRows:(e,t)=>vb(e,`which`,[`visible`,`hidden`],t),columns(e,t){if(vb(e,`action`,[...Object.keys(ug),`moveTo`],t),e.action===`moveTo`){let n=e.to;!$(n)||n.before==null==(n.after==null)||Object.keys(n).length!==1?t(`moveTo needs "to": { "before": column } or { "after": column }.`):e.to=n.before==null?{after:pb(n.after,t,`"to".after`)}:{before:pb(n.before,t,`"to".before`)}}else e.to!=null&&t(`"to" is only for "moveTo".`);e.name!=null&&(/^insert/.test(e.action??``)?Q(e.name)||t(`"name" must be text.`):t(`"name" is only for insertLeft and insertRight.`))},rowNumbers(e,t){e.name!=null&&!Q(e.name)&&t(`"name" must be text.`)},rename(e,t){xb(e,`col`,t),yb(e,`to`,t)},replaceAll(e,t){yb(e,`search`,t),yb(e,`replace`,t,{dflt:``,empty:!0});for(let n of[`caseSensitive`,`regexp`,`wholeWord`,`literal`])_b(e,n,!1,t);if(e.in.cols&&e.in.cols.length!==1&&t(`"in" names one column, or is "all".`),e.regexp&&Q(e.search))try{new RegExp(e.search)}catch{t(`"search" isn’t a valid pattern.`)}},names:(e,t)=>vb(e,`style`,[`snake`,`camel`,`unique`],t),split(e,t){xb(e,`col`,t),yb(e,`sep`,t),bb(e,`max`,t,{dflt:0}),_b(e,`keep`,!1,t)},join(e,t){Sb(e,2,t),yb(e,`sep`,t,{dflt:` `,empty:!0}),_b(e,`skipEmpty`,!0,t)},merge:(e,t)=>Sb(e,2,t),unpivot(e,t){yb(e,`nameCol`,t,{dflt:`name`}),yb(e,`valueCol`,t,{dflt:`value`}),_b(e,`skipEmpty`,!1,t)},pivot(e,t){xb(e,`names`,t),xb(e,`values`,t),vb(e,`keep`,bh,t,`all`),_b(e,`joinApart`,!1,t)},transpose(){},splitRows(e,t){xb(e,`col`,t),yb(e,`sep`,t),_b(e,`repeat`,!0,t)},combineRows(e,t){xb(e,`col`,t),yb(e,`sep`,t,{dflt:`; `,empty:!0}),_b(e,`below`,!0,t)},summarize(e,t){let n=[`group`,...Eh],r=e.roles;$(r)&&(r=Object.entries(r).map(([e,t])=>({col:e,role:t}))),!Array.isArray(r)||!r.length?t(`"roles" says what to do with each column kept: { "country": "group", "amount": "sum" }.`):(e.roles=r.map((e,r)=>$(e)?(n.includes(e.role)||t(`the role of ${JSON.stringify(e.col)} must be one of: ${n.join(`, `)}.`),{col:pb(e.col,t,`"roles"[${r}].col`),role:e.role}):(t(`"roles"[${r}] must be { "col": column, "role": … }.`),{})),_b(e,`count`,!0,t))},dropLines:(e,t)=>bb(e,`lines`,t,{min:1}),joinHeader(e,t){bb(e,`rows`,t,{min:2}),yb(e,`sep`,t,{dflt:` `,empty:!0}),_b(e,`carry`,!0,t)},fix(e,t){tb.includes(e.kind)?(Object.assign(e,{op:`names`,style:`unique`,title:e.title??pg.unique}),delete e.kind):eb.includes(e.kind)||t(ny[e.kind]?`“${e.kind}” can’t be fixed by a step: ${rb(e.kind)}.`:`"kind" must be one of: ${nb.join(`, `)}.`)}},wb={cell:e=>$y[e.name]??`Cells`,fillDown:e=>e.repeats?`Clear Consecutive Repeats`:`Fill Down`,numbers:()=>`Reformat Numbers`,dates:()=>`Reformat Dates`,sort:()=>`Sort`,dedupe:()=>`Remove Duplicate Rows`,emptyRows:()=>`Remove Empty Rows`,removeRows:e=>e.which===`visible`?`Remove Rows Shown by Filter`:`Remove Rows Hidden by Filter`,columns:e=>ug[e.action]??`Move Columns`,rowNumbers:()=>`Insert Row Number Column`,rename:()=>`Rename Column`,replaceAll:()=>`Replace All`,names:e=>pg[e.style]??`Header Names`,split:()=>`Split Column`,join:()=>`Join Columns`,merge:()=>`Merge Columns`,unpivot:()=>`Columns to Rows`,pivot:()=>`Rows to Columns`,transpose:()=>`Swap Rows and Columns`,splitRows:()=>`Split Values into Rows`,combineRows:()=>`Combine Rows`,summarize:()=>`Summarize by Group`,dropLines:()=>`Delete Rows Above the Cursor`,joinHeader:()=>`Join Header Rows`,fix:e=>ny[e.kind]?.all??ny[e.kind]?.fix??`Fix`},Tb=`# Trusty CSV recipe steps
341
+
342
+ A recipe is a JSON list of steps, done in order, each on the table the step before left. A file saved by
343
+ the desktop app (Table › Recipes › Manage Recipes › Export) is { "trustyCsvRecipe": 1, "name": …, "steps": [ … ] };
344
+ a bare list of steps works too. A step whose columns aren't in a file is skipped, with its reason; the
345
+ others go on. Nothing is written until the whole recipe has run.
346
+
347
+ ## Columns
348
+
349
+ By their header name, without telling capitals or the spaces around apart: "city". The second column with
350
+ a name: { "name": "city", "nth": 1 }. In a file without a header row: { "index": 0 } (0 is the first column).
351
+
352
+ ## Where a step is done
353
+
354
+ "in": the columns, ["city", "country"], or "all": every cell but the header row's (cell, fillDown,
355
+ numbers, dates, replaceAll). The other steps are done on the whole table. The header row is never changed
356
+ by cell steps.
357
+
358
+ "where" (cell, fillDown, numbers, dates, sort, dedupe, emptyRows, replaceAll, removeRows): the step is done
359
+ only on the rows that pass every filter of the list; the others are left as they are. A filter:
360
+ { "col": "country", "only": ["USA", "Canada"] } the rows with one of these values (exactly)
361
+ { "col": "country", "except": ["", "n/a"] } the rows without any of these values
362
+ { "col": "amount", "cond": { "op": "gt", "a": "100" } }
363
+ Conditions (text is compared without capitals and without the spaces around):
364
+ contains, notContains, is, isNot, starts, ends, matches (a regular expression), empty, notEmpty ("a")
365
+ gt, ge, lt, le ("a"), between ("a", "b") numbers, read with the column's decimal separator
366
+ before, after ("a"), betweenDates ("a", "b") dates however they are written; "order": "dmy" | "mdy" | "ymd" says how to read 3/5/2026
367
+
368
+ ## The steps
369
+
370
+ { "op": "cell", "name": …, "in": … } a cell operation on every cell in "in"
371
+ trim, collapseSpaces (inner runs of spaces to one, and trim), removeSpaces, upper, lower, title,
372
+ removeLetters, removeDigits, removePunctuation, removeAccents, straightenQuotes, decodeHtml,
373
+ removeInvisible, normalizeUnicode, fixEncoding (UTF-8 read as Windows-1252: "España" → "España"),
374
+ missingToEmpty (NA, null, N/A, - … → empty), clear,
375
+ fillEmpty "params": { "text": "unknown" }
376
+ replaceValue "params": { "from": "exact value", "to": "new value" }
377
+ mapValues "params": { "map": { "USA": "United States", "U.S.": "United States" } } (exact values)
378
+ { "op": "fillDown", "in": …, "repeats": false } empty cells take the value above; "repeats": true is the
379
+ other way round (Clear Consecutive Repeats: a value equal to the one just above is emptied)
380
+ { "op": "numbers", "in": …, "to": "." | ",", "read": "auto" | "." | ",", "keep": false }
381
+ numbers written one way: without thousands separators, with that decimal separator, their digits as
382
+ they are. "read": how to read them (auto: by column). "keep": keep currency signs, units and %
383
+ { "op": "dates", "in": …, "format": …, "read": "auto" | "dmy" | "mdy" | "ymd" }
384
+ dates written one way; a time after the date stays. Formats: ${gd.join(`, `)}
385
+ { "op": "sort", "keys": [{ "by": "country" }, { "by": "amount", "desc": true }] }
386
+ by several columns, the first one first. Each key: "desc" (default false) and "as": "auto" (numbers
387
+ as numbers, dates as dates, text in natural order: the default), "text" or "length". Empty values last.
388
+ Stable. Only the rows that pass "where" move, among their own places.
389
+ { "op": "dedupe", "by": null, "loose": false } remove duplicate rows (the first of each stays): identical
390
+ rows, or with "by": a column, the rows with the same value in it. "loose": capitals and spaces don't count
391
+ { "op": "emptyRows" } remove the rows with nothing in them
392
+ { "op": "removeRows", "which": "visible" | "hidden", "where": [ … ] }
393
+ "visible": remove the rows that pass "where"; "hidden": remove the others (keep only the ones that pass)
394
+ { "op": "columns", "action": …, "in": ["price"] }
395
+ insertLeft, insertRight (an empty column; "name": its header name), duplicate, delete,
396
+ keepOnly (delete every other column), moveLeft, moveRight,
397
+ moveTo with "to": { "before": "qty" } or { "after": "qty" }
398
+ { "op": "rowNumbers", "name": "row" } a first column numbering the rows
399
+ { "op": "rename", "col": "pop", "to": "population" }
400
+ { "op": "replaceAll", "search": "N/A", "replace": "", "in": ["city"] | "all",
401
+ "caseSensitive": false, "regexp": false, "wholeWord": false } as Find and Replace: with "regexp", $1 in
402
+ "replace" is a group. In one column (never its header), or anywhere ("all", the default)
403
+ { "op": "names", "style": "snake" | "camel" | "unique" } every header name to snake_case or camelCase, or
404
+ made unique (repeated names get _2, empty ones column3)
405
+ { "op": "split", "col": "name", "sep": " ", "max": 0, "keep": false } a column into several, at a separator
406
+ (any dash matches any other); "max": at most this many columns (0: as many as needed, the last takes the
407
+ rest); "keep": keep the column too. New columns are "name 1", "name 2"…
408
+ { "op": "join", "in": ["first", "last"], "sep": " ", "skipEmpty": true } columns into the first of them
409
+ { "op": "merge", "in": ["phone", "mobile"] } the first value that isn't empty, into the first column
410
+ { "op": "unpivot", "in": ["2024", "2025"], "nameCol": "year", "valueCol": "sales", "skipEmpty": false }
411
+ columns to rows: those columns become two, a name and a value, and each row one row per column
412
+ { "op": "pivot", "names": "year", "values": "sales", "keep": "all" | "first" | "last", "joinApart": false }
413
+ rows to columns: each value of "names" becomes a column with the values of "values" (at most 200);
414
+ rows next to each other that are the same in the other columns become one ("joinApart": even apart)
415
+ { "op": "transpose" } swap rows and columns (tables of up to 1,000 rows)
416
+ { "op": "splitRows", "col": "tags", "sep": ";", "repeat": true } a row for each value of a cell; "repeat":
417
+ the other columns in each new row (false: only in the first)
418
+ { "op": "combineRows", "col": "tags", "sep": "; ", "below": true } rows the same in every other column
419
+ become one, with their values of "col" joined; "below": rows empty in the other columns go with the row above
420
+ { "op": "summarize", "roles": { "country": "group", "amount": "sum" }, "count": true }
421
+ one row per group of the "group" columns; the others listed become: ${Eh.join(`, `)}; columns not
422
+ listed are left out. "count": a last column with the number of rows of each group
423
+ { "op": "dropLines", "lines": 3 } delete the first lines of the file
424
+ { "op": "joinHeader", "rows": 2, "sep": " ", "carry": true } the first rows become one header row; "carry":
425
+ a blank cell in an upper row takes the value at its left (a merged cell)
426
+ { "op": "fix", "kind": … } the Quality Check's fix of every problem of a kind, found
427
+ again on the table as it is then: ${nb.join(`, `)}
428
+
429
+ Every step may have a "title" (its name in lists); one is given if it has none.
430
+ `,Eb=1e4,Db=120,Ob=e=>e.length>Db?e.slice(0,119)+`…`:e,kb=e=>e.field(N).hasHeader?sp(e):null,Ab=(e,t)=>e?.[t]?.trim()?e[t]:`column ${t+1}`,jb={dmy:`day first`,mdy:`month first`,ymd:`year first`};function Mb(e,t=``){let n=e=>typeof e!=`object`||!e;if(Array.isArray(e)){if(e.every(n)||!e.length)return JSON.stringify(e);let r=t+` `;return`[\n${e.map(e=>r+Mb(e,r)).join(`,
431
+ `)}\n${t}]`}if(e&&typeof e==`object`){let r=Object.keys(e).filter(t=>e[t]!==void 0),i=JSON.stringify(e);if(!r.length||i.length<=120&&r.every(t=>n(e[t])||Array.isArray(e[t])&&e[t].every(n)))return i;let a=t+` `;return`{\n${r.map(t=>`${a}${JSON.stringify(t)}: ${Mb(e[t],a)}`).join(`,
432
+ `)}\n${t}}`}return JSON.stringify(e)}function Nb(e,t){let n=[];if(t<=0)return n;let r=e.field(N).hasHeader;return rl(Tl(e.doc),e.field(N).delimiter,e=>e.length===1&&e[0]===``?!1:r?(r=!1,!1):(n.push(e),n.length>=t)),n}function Pb(e,t,{sampleRows:n=5,cut:r=0}={}){let i=e.field(N),a=kb(e),o=Eg(e),s=Cg(e),c=Array.from({length:o},()=>({empty:0,missing:0,seen:new Set,more:!1})),l=0,u=!0;rl(Tl(e.doc),i.delimiter,e=>{if(e.length!==1||e[0]!==``){if(u&&i.hasHeader)u=!1;else{u=!1,l++;for(let t=0;t<o;t++){let n=e[t]??``,r=c[t];n.trim()===``?r.empty++:zu(n)&&r.missing++,!r.more&&n.trim()!==``&&(r.seen.add(n),r.seen.size>Eb&&(r.more=!0,r.seen=null))}}}});let d=c.map((t,n)=>{let r=s[n]??`text`,i={index:n+1,name:a?a[n]??``:null,type:r};if(r===`number`&&(i.decimalSeparator=dg(e,n)??`.`),r===`date`){let t=yg(e,n);i.dateOrder=t.order,t.sure||(i.dateOrderGuessed=!0)}return i.empty=t.empty,i.missing=t.missing,i.distinct=t.more?`more than ${Eb.toLocaleString(`en`)}`:t.seen.size,i}),f=Nb(e,n);return{file:t.name,...t.archive?{archive:t.archive,filesInArchive:t.entries}:{},format:t.kind===`excel`?`workbook`:t.kind===`json`?`json`:`text`,...t.sheet?{sheet:t.sheet,sheets:t.sheets}:{},encoding:t.encoding,bom:t.bom,delimiter:i.delimiter,delimiterName:J_(i.delimiter),lineBreaks:Y_(t.eols.record),...t.eols.inCell===t.eols.record?{}:{lineBreaksInsideValues:Y_(t.eols.inCell)},headerRow:i.hasHeader,linesAboveTable:t.preamble,rows:l,columns:d,firstRows:r?f.map(e=>e.map(e=>e.length>r?e.slice(0,r-1)+`…`:e)):f,notes:t.notes}}function Fb(e,t,{max:n=5,kinds:r=null}={}){let i=e.field(N),a=kb(e),o=Yv(X(e,null),{kinds:Cg(e),quotes:Gm(e),max:n});for(;!o.step(1e6););let s=o.result(),{doc:c}=e,l=e=>e.line||c.lineAt(Math.min(e.from,c.length)).number,u=s.problems.filter(e=>!r||r.includes(e.id)).map(e=>{let t=ny[e.id],r=e.cols??(e.by?Object.keys(e.by).map(Number):null);return{kind:e.id,title:ry(e.id,i.hasHeader),count:e.count,...r?.length?{columns:r.map(e=>Ab(a,e))}:{},...nb.includes(e.id)?{fix:t.fix}:{fix:null,noFix:rb(e.id)},places:e.items.slice(0,n).map(e=>({line:l(e),...e.col>=0?{column:Ab(a,e.col)}:{},value:Ob(c.sliceString(e.from,e.to))}))}}),d={file:t.name,total:u.reduce((e,t)=>e+t.count,0),problems:u};return s.problems.some(e=>e.id===`preamble`)&&(d.note=`The file has lines above its table: until they are removed (the fix “preamble”), nothing else is looked for.`),d}function Ib(e,t){let n=Dy(e,t);return{after:n.changes?e.update({changes:n.changes,filter:!1,annotations:n.index?[gu.of({from:e.field(q),changes:n.changes,index:n.index})]:[]}).state:e,changed:!!n.changes,done:n.done,results:n.results.map(e=>({step:py(e.step),done:e.done,skipped:e.skipped,said:e.said}))}}function Lb(e,t,{key:n=null,max:r=20,beforeName:i=`before`,afterName:a=`after`}={}){let o=e=>({lines:Tl(e.doc),delim:e.field(q).delim,hasHeader:e.field(N).hasHeader,length:e.doc.length}),s=o(e),l=o(t),u=null;if(n!=null&&n!==``){let e=ch(t,/^#\d+$/.test(n)?{index:n.slice(1)-1}:{name:String(n)},Eg(t));if(e<0)throw new c(`${a} has no column “${n}” to match the rows by.`);u={col:e,name:Yy(kb(t),e)}}let d=Zy(Xy(l,s,{key:u})),f=d.names,p=d.otherNames,m=d.columns.toOther,h=d.counts,g={};for(let[e,t]of[...h.byColumn].sort((e,t)=>e[0]-t[0]))g[Ab(f,e)]=t;let _=d.changed.slice(0,r).map(e=>{let t=Qy(l,e.line,e.from),n=Qy(s,e.otherLine,e.otherFrom);return{line:e.line,lineBefore:e.otherLine,cells:e.cols.map(e=>({column:Ab(f,e),before:n[m[e]]??null,after:t[e]??null}))}}),v=d.added.slice(0,r).map(e=>{let n=t.doc.lineAt(e.from).number;return{line:n,values:Qy(l,n,e.from)}}),y=d.removed.flatMap(e=>e.rows).slice(0,r).map(e=>({lineBefore:e.line,values:Qy(s,e.line,e.from)})),b={added:d.columns.added.map(e=>Ab(f,e)),removed:d.columns.removed.map(e=>Ab(p,e)),renamed:d.columns.renamed.map(e=>({from:Ab(p,m[e]),to:Ab(f,e)}))};return{before:i,after:a,same:!d.reordered&&!h.changedRows&&!h.added&&!h.removed&&!b.added.length&&!b.removed.length&&!b.renamed.length,matchedBy:d.key==null?`content`:Ab(f,d.key),...d.reordered?{reordered:!0,note:`The same rows, in another order.`}:{},...d.suggest==null?{}:{suggestedKey:Ab(f,d.suggest),suggestion:`The rows may be in another order: compare them by the key “${Ab(f,d.suggest)}”.`},rows:{before:h.otherRows,after:h.rows,changed:h.changedRows,added:h.added,removed:h.removed},cellsChanged:h.changedCells,cellsChangedByColumn:g,columns:b,changedRows:_,addedRows:v,removedRows:y,...d.capped||h.changedRows>r||h.added>r||h.removed>r?{shown:`the first ${r} of each`}:{}}}var Rb=a(s);function zb(e,t=process.platform){switch(e.code){case`ENOENT`:return`The file or its folder no longer exists.`;case`EACCES`:return`Permission denied.`;case`EPERM`:return t===`darwin`?`macOS didn’t allow it: the file or its folder is locked, or Trusty CSV has no access to that folder (System Settings › Privacy & Security › Files and Folders).`:t===`linux`?`The system didn’t allow it: the file or its folder is protected against changes.`:`Permission denied, or the file is open in another program.`;case`EBUSY`:return`The file is open in another program.`;case`ENOSPC`:return`The disk is full.`;case`EDQUOT`:return`Your disk quota is used up.`;case`EROFS`:return`The disk is read-only.`;case`EISDIR`:return`That is a folder, not a file.`;case`ENAMETOOLONG`:return`That name is too long.`;case`ENOTCONN`:case`ESTALE`:case`EHOSTDOWN`:case`EHOSTUNREACH`:case`ETIMEDOUT`:case`ECONNRESET`:return`The connection to that folder was lost.`;case`EIO`:return`The disk or the network failed while reading or writing the file.`;case`ENOTSUP`:case`EOPNOTSUPP`:case`ENOSYS`:return`That folder doesn’t allow it.`;case`UNKNOWN`:return t===`win32`?`Windows couldn’t get the file. If it is only online (OneDrive, Dropbox…), that program has to be running and connected.`:e.message;default:return e.message}}var Bb=`The file is read-only. File › Save As… saves it with another name.`;async function Vb(e,t,{platform:r=process.platform}={}){if(r===`win32`){let r=await n.stat(e).catch(()=>null);if(r?.isFile())return Zb(e,t,r)}let i=e,a=null;try{i=await n.realpath(e),a=(await n.stat(i)).mode}catch{}let o=a!==null;if(r===`linux`)return o?Jb(i,t):Xb(e,t,!0);if(r===`darwin`&&o)return $b(i,t);o&&r!==`win32`&&await Wb(i,r);let s=Ub(i),c=()=>n.rm(s,{force:!0}).catch(()=>{}),l=await n.open(s,`wx`);try{for(let e of t)await Kb(l,e);await l.sync()}catch(e){throw await l.close().catch(()=>{}),await c(),e}await l.close();try{o&&r!==`win32`&&await n.chmod(s,a&4095),await n.rename(s,i)}catch(e){throw await c(),e}}var Hb=200;function Ub(e){let t=r.basename(e);if(Buffer.byteLength(t)>Hb){let e=0,n=``;for(let r of t){if(e+=Buffer.byteLength(r),e>Hb)break;n+=r}t=n}return r.join(r.dirname(e),`.${t}.${o.randomBytes(4).toString(`hex`)}.tmp`)}async function Wb(e,t){let r;try{r=await n.open(e,`r+`)}catch(r){if(r.code===`EACCES`)throw Error(Bb);if(t===`linux`&&Gb.has(r.code))return await n.access(e,n.constants.W_OK).catch(e=>{if(e.code===`EACCES`||e.code===`EROFS`)throw Error(Bb)}),`whole`;throw r.code===`EPERM`&&t===`darwin`&&await Qb(e,`r`)?Error(`The file is locked. Unlock it in the Finder (File › Get Info › Locked), or save it with another name.`):r}return await r.close(),`any`}var Gb=new Set([`ENOTSUP`,`EOPNOTSUPP`,`ENOSYS`]);async function Kb(e,t,n=null){for(let r=0;r<t.length;){let{bytesWritten:i}=await e.write(t,r,t.length-r,n===null?null:n+r);if(!i)throw Object.assign(Error(`The file could not be written.`),{code:`EIO`});r+=i}}var qb=`The save was cut short, and the file on disk may be incomplete: save it again. File › Previous Versions… has it as it was.`;async function Jb(e,t){let r=await n.stat(e);if(r.isDirectory())throw Object.assign(Error(),{code:`EISDIR`});if(await Wb(e,`linux`)===`whole`)return Xb(e,t);let i=process.getuid?.();if(!r.isFile()||r.nlink>1||i!==0&&r.uid!==i)return Zb(e,t,r,`linux`);let a=Ub(e),o=()=>n.rm(a,{force:!0}).catch(()=>{}),s=await Yb(e,a,r);if(!s)return Zb(e,t,r,`linux`);try{for(let e of t)await Kb(s,e);await s.sync()}catch(e){throw await s.close().catch(()=>{}),await o(),e}await s.close();try{await n.rename(a,e)}catch{return await o(),Zb(e,t,r,`linux`)}}async function Yb(e,t,r){let i=e=>e.uid===r.uid&&e.gid===r.gid&&(e.mode&4095)==(r.mode&4095),a=null;try{if(await Rb(`cp`,[`--attributes-only`,`--preserve=all`,`--`,e,t],{timeout:1e4}),a=await n.open(t,`r+`),!i(await a.stat()))throw Error(`not its equal`);return await a.truncate(0),a}catch{await a?.close().catch(()=>{}),await n.rm(t,{force:!0}).catch(()=>{})}try{if(a=await n.open(t,`wx`,384),await a.chmod(r.mode&4095),(await a.stat()).gid!==r.gid&&await a.chown(r.uid,r.gid),!i(await a.stat()))throw Error(`not its equal`);return a}catch{return await a?.close().catch(()=>{}),await n.rm(t,{force:!0}).catch(()=>{}),null}}async function Xb(e,t,r=!1){let i=async t=>r?(await n.rm(e,{force:!0}).catch(()=>{}),t):Error(`${zb(t,`linux`)} ${qb}`),a=await n.open(e,`w`);try{for(let e of t)await Kb(a,e);await a.sync().catch(e=>{if(!Gb.has(e.code)&&e.code!==`EINVAL`)throw e})}catch(e){throw await a.close().catch(()=>{}),await i(e)}try{await a.close()}catch(e){throw await i(e)}let o=t.reduce((e,t)=>e+t.length,0);for(let t=0;t<50&&(await n.stat(e).catch(()=>null))?.size!==o;t++)await new Promise(e=>setTimeout(e,100))}async function Zb(e,t,r,i=`win32`){if(i===`win32`&&!(r.mode&128))throw Error(Bb);let a=t.reduce((e,t)=>e+t.length,0),o=await n.open(e,`r+`),s=!1;try{let e=(await o.stat()).size;if(a>e)try{await o.truncate(a)}catch(t){throw await o.truncate(e).catch(()=>{}),t}s=!0;let n=0;for(let e of t)e.length&&await Kb(o,e,n),n+=e.length;a<e&&await o.truncate(a),await o.sync()}catch(e){throw s?Error(`${zb(e,i)} ${qb}`):e}finally{await o.close().catch(()=>{})}}var Qb=(e,t)=>n.open(e,t).then(e=>e.close().then(()=>!0),()=>!1);async function $b(e,t){let r=await n.stat(e);if(r.isDirectory())throw Object.assign(Error(),{code:`EISDIR`});await Wb(e,`darwin`);let i=process.getuid?.();if(!r.isFile()||r.nlink>1||i!==0&&r.uid!==i)return Zb(e,t,r,`darwin`);let a=Ub(e),o=()=>n.rm(a,{force:!0}).catch(()=>{}),s=await ex(e,a,r);if(!s)return Zb(e,t,r,`darwin`);try{for(let e of t)await Kb(s,e);await s.sync()}catch(e){throw await s.close().catch(()=>{}),await o(),e}await s.close();try{await n.rename(a,e)}catch{return await o(),Zb(e,t,r,`darwin`)}}async function ex(e,t,r){let i=e=>e.uid===r.uid&&e.gid===r.gid&&(e.mode&4095)==(r.mode&4095),a=(...n)=>Rb(`/usr/bin/ditto`,[...n,e,t],{timeout:2e4+Math.ceil(r.size/1e3)}),o=null;try{try{await a(`--clone`)}catch(e){if(e.killed)throw e;await n.rm(t,{force:!0}).catch(()=>{}),await a()}o=await n.open(t,`r+`);let e=await o.stat();if(e.gid!==r.gid&&(await o.chown(r.uid,r.gid),await o.chmod(r.mode&4095)),e.birthtimeMs!==r.birthtimeMs&&await o.utimes(r.atimeMs/1e3,r.birthtimeMs/1e3).catch(()=>{}),!i(await o.stat()))throw Error(`not its equal`);return await o.truncate(0),o}catch{return await o?.close().catch(()=>{}),await n.rm(t,{force:!0}).catch(()=>{}),null}}var tx=`0.1.0`,nx=`Trusty CSV on the command line: the Quality Check, recipes and conversions
433
+ of the Trusty CSV app (trustycsv.com), run on your computer. Nothing is uploaded.
434
+
435
+ Usage: trustycsv <command> [options]
436
+
437
+ Commands:
438
+ inspect <file> how the file is written and what its columns hold
439
+ check <file>… the Quality Check: what is wrong in each file, and where
440
+ fix <file> --kinds <k,…|all> fix the problems of these kinds (the kinds that check lists)
441
+ apply <recipe> <file>… do a recipe's steps (a recipe exported by the app, or JSON)
442
+ convert <file> --to <format> write the file in another format
443
+ compare <before> <after> what changed between two versions of a file
444
+ steps the format of a recipe's steps
445
+ mcp run as an MCP server on standard input and output,
446
+ for AI assistants (Claude, Cursor…)
447
+
448
+ Files: CSV, TSV, text, Excel and OpenDocument (.xlsx, .xls, .ods), JSON and
449
+ JSON Lines, and those inside a .gz or a .zip. "-" reads standard input (CSV).
450
+
451
+ Reading:
452
+ --sheet <name> the sheet of a workbook (the first, if not given)
453
+ --entry <name> the file inside a .zip that has several
454
+ --in-encoding <enc> utf-8, windows-1252, utf-16le, utf-16be (detected if not given)
455
+ --in-delimiter <d> , ; tab | … (detected if not given)
456
+ --header, --no-header whether the first row names the columns (detected if not given)
457
+
458
+ Writing (fix, apply, convert):
459
+ -o, --output <file> where to write; "-" is standard output, the default with one file
460
+ --out-dir <folder> where the results of several files go, each with its own name
461
+ --in-place write over the file itself
462
+ --force write over an output file that exists
463
+ --to <format> ${Object.keys(ov).join(`, `)}
464
+ (default: the output's extension, or the file's own format)
465
+ --delimiter <d> the delimiter of a CSV written (default: the file's own)
466
+ --encoding <enc> the encoding of a CSV written (default: the file's own)
467
+ --bom, --no-bom a byte order mark at its start, or not
468
+ --eol <crlf|lf> its line breaks (default: the file's own)
469
+ --quote-all quotes around every value
470
+ --dry-run say what would be done, and write nothing
471
+
472
+ Other options:
473
+ --kinds <k,…> check: only these kinds; fix: the kinds to fix, or "all"
474
+ --ignore <k,…> check: not these kinds
475
+ --key <column> compare: match the rows by this column (an id) instead of their content
476
+ --rows <n> inspect: how many of the first rows to show (5)
477
+ --max <n> check, compare: how many places or rows to list (5, 20)
478
+ --json the report as JSON
479
+ -h, --help this help; "trustycsv <command> --help" for a command's
480
+ -v, --version
481
+
482
+ Exit codes: 0 done; 1 check found problems, or compare found differences;
483
+ 2 it couldn't be done.`,rx={inspect:`trustycsv inspect <file> [--rows 5] [--json]
484
+
485
+ How the file is written (encoding, delimiter, header row, line breaks, lines
486
+ above the table) and what it holds: its rows, each column's type (numbers
487
+ with their decimal separator, dates with their order, times, email
488
+ addresses, text) and how many of its values are empty, missing (NA, null…)
489
+ and different, and its first rows.`,check:`trustycsv check <file>… [--kinds k,…] [--ignore k,…] [--max 5] [--json]
490
+
491
+ Trusty CSV's Quality Check: what is surely wrong in the file, in the order to
492
+ fix it, with the first places of each kind (line, column, value). Exit code 1
493
+ if it finds anything: for scripts and continuous integration.
494
+
495
+ The kinds:
496
+ ${Cv.map(e=>` ${e}${nb.includes(e)?``:` (no automatic fix)`}`).join(`
497
+ `)}`,fix:`trustycsv fix <file> --kinds <k,…|all> [-o <file> | --in-place] [--dry-run]
498
+
499
+ Fixes every problem of these kinds, as the Quality Check's buttons do, in the
500
+ order to fix them; "all": every kind with a fix that the check finds. Then it
501
+ checks again and says what is left. Kinds with a fix:
502
+ ${nb.join(`, `)}`,apply:`trustycsv apply <recipe> <file>… [-o <file> | --out-dir <folder> | --in-place] [--to <format>] [--dry-run]
503
+
504
+ Does a recipe's steps on each file: a recipe exported by the app
505
+ (name.recipe.json), or a JSON list of steps ("trustycsv steps" says how to
506
+ write them). A step whose columns aren't in a file is skipped, and says so.
507
+ With --out-dir every file gets its result, changed or not.`,convert:`trustycsv convert <file> --to <format> [-o <file>] [--delimiter d] [--encoding e] [--eol crlf|lf] [--bom] [--quote-all]
508
+
509
+ Writes the file in another format: ${Object.keys(ov).join(`, `)}.
510
+ CSV keeps the file's text exactly as it is unless the delimiter changes or
511
+ --quote-all is given. JSON writes numbers as numbers in columns of numbers;
512
+ SQL is a CREATE TABLE and INSERT statements (SQLite, PostgreSQL).`,compare:`trustycsv compare <before> <after> [--key <column>] [--max 20] [--json]
513
+
514
+ What changed between two versions of a table: columns added, removed or
515
+ renamed (matched by name), rows changed, added and removed (matched by their
516
+ content, or by --key: the column that identifies a row, wherever it is),
517
+ and every cell that changed. Exit code 1 if they differ.`,steps:`trustycsv steps
518
+
519
+ The format of a recipe's steps, for writing one by hand.`,mcp:`trustycsv mcp
520
+
521
+ An MCP server on standard input and output, for AI assistants. For example,
522
+ in Claude Code: claude mcp add trustycsv -- trustycsv mcp`},ix=[[`sheet`,`string`],[`entry`,`string`],[`in-encoding`,`string`],[`in-delimiter`,`string`],[`header`,`boolean`],[`no-header`,`boolean`]],ax=[[`output`,`string`,`o`],[`out-dir`,`string`],[`in-place`,`boolean`],[`force`,`boolean`],[`to`,`string`],[`delimiter`,`string`],[`encoding`,`string`],[`bom`,`boolean`],[`no-bom`,`boolean`],[`eol`,`string`],[`quote-all`,`boolean`],[`dry-run`,`boolean`]],ox={inspect:[...ix,[`rows`,`string`],[`json`,`boolean`]],check:[...ix,[`kinds`,`string`],[`ignore`,`string`],[`max`,`string`],[`json`,`boolean`]],fix:[...ix,...ax,[`kinds`,`string`],[`json`,`boolean`]],apply:[...ix,...ax,[`json`,`boolean`]],convert:[...ix,...ax,[`json`,`boolean`]],compare:[...ix,[`key`,`string`],[`max`,`string`],[`json`,`boolean`]],steps:[],mcp:[]},sx={stdout:process.stdout,stderr:process.stderr,async stdin(){let e=[];for await(let t of process.stdin)e.push(t);return new Uint8Array(Buffer.concat(e))}};async function cx(e,t=sx){let n=e=>t.stderr.write(e+`
523
+ `),[r,...a]=e;if(!r||r===`-h`||r===`--help`||r===`help`){let e=r===`help`?a[0]:null;return t.stdout.write((e&&rx[e]?rx[e]:nx)+`
524
+ `),0}if(r===`-v`||r===`--version`)return t.stdout.write(`0.1.0
525
+ `),0;if(!ox[r])return n(`trustycsv: there is no command “${r}”. See trustycsv --help.`),2;if(a.includes(`-h`)||a.includes(`--help`))return t.stdout.write(rx[r]+`
526
+ `),0;let o;try{o=i({args:a,allowPositionals:!0,strict:!0,options:Object.fromEntries(ox[r].map(([e,t,n])=>[e,n?{type:t,short:n}:{type:t}]))})}catch(e){return n(`trustycsv ${r}: ${e.message.replace(/^Unknown option '(.+?)'.*$/s,`there is no option $1 for this command`)}. See trustycsv ${r} --help.`),2}try{if(r===`mcp`){let{serve:e}=await import(`./mcp-BtQ-Hy3_.js`);return await e(),0}return r===`steps`?(t.stdout.write(Tb),0):await yx[r](o.values,o.positionals,t)}catch(e){return e instanceof c?n(`trustycsv ${r}: ${e.message}`):n(`trustycsv ${r}: ${e.stack??e}`),2}}var lx=e=>({sheet:e.sheet,entry:e.entry,encoding:e[`in-encoding`],delimiter:e[`in-delimiter`],header:e.header?!0:!e[`no-header`]&&void 0});async function ux(e,t,i){let a;if(e===`-`)a=await i.stdin();else try{a=new Uint8Array(await n.readFile(e))}catch(t){throw new c(`Could not read ${e}: ${zb(t)}`)}let o=await ev(a,e===`-`?``:r.basename(e),lx(t));return e===`-`&&(o.from.name=`standard input`),o}var dx=(e,t,n)=>{if(e==null)return n;let r=Number(e);if(!Number.isInteger(r)||r<0)throw new c(`--${t} must be a whole number.`);return r},fx=e=>e==null?null:String(e).split(`,`).map(e=>e.trim()).filter(Boolean),px=e=>Mb(e)+`
527
+ `,mx=(e,t,n=t+`s`)=>`${e.toLocaleString(`en`)} ${e===1?t:n}`;function hx(e,t,n,r){if(e.bom&&e[`no-bom`])throw new c(`--bom and --no-bom: one or the other.`);return fv({type:e.to,delimiter:e.delimiter,encoding:e.encoding,bom:e.bom?!0:!e[`no-bom`]&&null,eol:e.eol,quoteAll:e[`quote-all`]},t,n,r)}async function gx(e,n,{force:i,io:a,binary:o}){if(e===`-`){if(o&&a.stdout.isTTY)throw new c(`This format isn’t text: write it to a file with -o.`);a.stdout.write(n)}else{if(!i&&t.existsSync(e))throw new c(`${e} exists already: --force writes over it.`);try{await Vb(r.resolve(e),[n])}catch(t){throw new c(`Could not write ${e}: ${zb(t)}`)}}}function _x(e,n){let r=[`output`,`out-dir`,`in-place`].filter(e=>n[e]!=null&&n[e]!==!1);if(r.length>1)throw new c(`--${r.join(` and --`)}: one or the other.`);if(n[`dry-run`])return{kind:`dry`};if(n[`in-place`]){if(e.includes(`-`))throw new c(`--in-place needs a file, not standard input.`);return{kind:`inPlace`}}if(n[`out-dir`]){if(e.includes(`-`))throw new c(`--out-dir needs files, not standard input.`);if(!t.existsSync(n[`out-dir`]))throw new c(`There is no folder ${n[`out-dir`]}.`);return{kind:`dir`,dir:n[`out-dir`],taken:new Set}}if(e.length>1)throw new c(`Several files: say where their results go, with --out-dir <folder> or --in-place.`);return{kind:`out`,path:n.output??`-`}}function vx(e,t,n,i,a){if(e.kind===`dry`)return null;if(e.kind===`out`){if(e.path!==`-`&&r.resolve(e.path)===r.resolve(t))throw new c(`The output is the file itself: --in-place writes over it.`);return e.path}if(e.kind===`inPlace`)return pv(t,n,i,a),t;let o=n.kind===`text`&&a.type===dv(i,n)&&uv(n.name)!=null?n.name:n.name.replace(/\.[^.]*$/,``)+ov[a.type],s=r.join(e.dir,o);if(e.taken.has(s.toLowerCase()))throw new c(`Two files would be written as ${s}.`);return e.taken.add(s.toLowerCase()),s}var yx={async inspect(e,t,n){if(t.length!==1)throw new c(`Give it one file.`);let{state:r,from:i}=await ux(t[0],e,n),a=Pb(r,i,{sampleRows:dx(e.rows,`rows`,5)});return n.stdout.write(e.json?px(a):wx(a)),0},async check(e,t,n){if(!t.length)throw new c(`Give it a file, or several.`);let r=fx(e.kinds),i=fx(e.ignore);for(let e of[...r??[],...i??[]])if(!Cv.includes(e))throw new c(`There is no kind “${e}”. The kinds: ${Cv.join(`, `)}.`);let a=r||i?Cv.filter(e=>(!r||r.includes(e))&&!i?.includes(e)):null,o=dx(e.max,`max`,5),s=[];for(let r of t){let{state:t,from:i}=await ux(r,e,n),c=Fb(t,i,{max:o,kinds:a});s.push(c),e.json||n.stdout.write((s.length>1?`
528
+ `:``)+Tx(c,r))}return e.json&&n.stdout.write(px(t.length===1?s[0]:s)),+!!s.some(e=>e.problems.length)},async fix(e,t,n){if(t.length!==1)throw new c(`Give it one file.`);let r=fx(e.kinds);if(!r?.length)throw new c(`Say which kinds to fix: --kinds edgeSpace,emptyRow… or --kinds all. Kinds with a fix: ${nb.join(`, `)}.`);let i=r.includes(`all`);for(let e of r)if(e!==`all`){if(!Cv.includes(e))throw new c(`There is no kind “${e}”. Kinds with a fix: ${nb.join(`, `)}.`);if(!nb.includes(e))throw new c(`“${e}” can’t be fixed here: ${rb(e)}.`)}return bx(t,e,n,(e,t)=>{let n=Fb(e,t,{max:0}).problems.map(e=>e.kind).filter(e=>nb.includes(e)&&(i||r.includes(e)));return{steps:n.length?ib(n):[],none:`Nothing to fix: the check finds none of those problems.`}},{recheck:!0})},async apply(e,t,r){if(t.length<2)throw new c(`Give it a recipe and one file or more: trustycsv apply recipe.json data.csv.`);let[i,...a]=t,o;try{o=JSON.parse(await n.readFile(i,`utf8`))}catch(e){throw new c(e.code?`Could not read ${i}: ${zb(e)}`:`${i} isn’t JSON: ${e.message}`)}let{steps:s}=lb(o);return bx(a,e,r,()=>({steps:s}))},async convert(e,t,n){if(t.length!==1)throw new c(`Give it one file.`);if(!e.to&&!(e.output&&e.output!==`-`&&uv(e.output)))throw new c(`Say the format: --to ${Object.keys(ov).join(`|`)} (or an output file with its extension).`);return bx(t,e,n,()=>({steps:[]}))},async compare(e,t,n){if(t.length!==2)throw new c(`Give it two files: the version before and the one after.`);let r=await ux(t[0],e,n),i=await ux(t[1],e,n),a=Lb(r.state,i.state,{key:e.key??null,max:dx(e.max,`max`,20),beforeName:t[0],afterName:t[1]});return n.stdout.write(e.json?px(a):Dx(a)),+!a.same}};async function bx(e,t,n,r,{recheck:i=!1}={}){let a=_x(e,t),o=a.kind===`out`&&a.path===`-`;if(o&&t.json)throw new c(`--json with the data on standard output: give it a file with -o.`);let s=e=>(o?n.stderr:n.stdout).write(e+`
529
+ `),l=[];for(let o=0;o<e.length;o++){let{state:c,from:u}=await ux(e[o],t,n),d=hx(t,c,u,a.kind===`out`?a.path:null),f=vx(a,e[o],u,c,d),{steps:p,none:m}=r(c,u),h=p.length?Ib(c,p):{after:c,changed:!1,done:0,results:[]},g={file:e[o],output:f,changed:h.changed,steps:h.results,notes:[...u.notes]};if(!p.length&&m&&g.notes.push(m),i&&(g.left=Fb(h.after,u,{max:0}).problems.map(e=>({kind:e.kind,count:e.count,fix:e.fix}))),f&&(a.kind!==`inPlace`||h.changed)){let{bytes:e,notes:r}=await mv(h.after,u,d);g.notes.push(...r),await gx(f,e,{force:!!t.force||a.kind===`inPlace`,io:n,binary:cv(d.type)}),g.format=d.type}else g.output=null,a.kind===`dry`&&h.changed&&(g.firstRows=av(h.after,6));l.push(g),t.json||s(Ex(g,t))}return t.json&&n.stdout.write(px(e.length===1?l[0]:l)),0}var xx=e=>e==null?`(none)`:JSON.stringify(e),Sx=(e,t)=>e.length>=t?e:e+` `.repeat(t-e.length),Cx=(e,t)=>e.length>t?e.slice(0,t-1)+`…`:e;function wx(e){let t=[],n=e.archive?` (in ${e.archive})`:``;if(t.push(`${e.file}${n}${e.sheet?` · sheet “${e.sheet}” of ${e.sheets.length}`:``}`),e.format===`text`){let n=`${Og(e.encoding)}${e.bom?` with a BOM`:``}`,r=e.lineBreaksInsideValues?`${e.lineBreaks} line breaks (${e.lineBreaksInsideValues} inside values)`:`${e.lineBreaks} line breaks`;t.push(` ${e.delimiterName[0].toUpperCase()}${e.delimiterName.slice(1)}-separated, ${n}, ${r}`)}else t.push(e.format===`workbook`?` A sheet of a workbook`:` JSON`);t.push(` ${mx(e.rows,`row`)} × ${mx(e.columns.length,`column`)}, ${e.headerRow?`with`:`without`} a header row${e.linesAboveTable?`, ${mx(e.linesAboveTable,`line`)} above the table`:``}`);for(let n of e.notes)t.push(` ${n}`);if(e.columns.length){t.push(``,` Columns:`);let n=Math.min(28,Math.max(4,...e.columns.map(e=>(e.name??``).length))),r=e=>e.type===`number`?`numbers (decimal ${e.decimalSeparator===`,`?`comma`:`point`})`:e.type===`date`?`dates (${jb[e.dateOrder]??e.dateOrder}${e.dateOrderGuessed?`?`:``})`:{email:`email addresses`,time:`times`,text:`text`}[e.type]??e.type;for(let i of e.columns){let e=typeof i.distinct==`number`?i.distinct.toLocaleString(`en`):i.distinct,a=[`${i.empty.toLocaleString(`en`)} empty`,...i.missing?[`${i.missing.toLocaleString(`en`)} missing`]:[],`${e} different`];t.push(` ${String(i.index).padStart(4)} ${Sx(Cx(i.name??``,n),n)} ${Sx(r(i),26)} ${a.join(`, `)}`)}}if(e.firstRows.length){t.push(``,` First ${mx(e.firstRows.length,`row`)}:`);for(let n of e.firstRows)t.push(` ${n.map(e=>Cx(JSON.stringify(e),24)).join(` `)}`)}return t.join(`
530
+ `)+`
531
+ `}function Tx(e,t){if(!e.problems.length)return`${e.file}: no problems found.\n`;let n=[`${e.file}: ${mx(e.total,`problem`)} of ${mx(e.problems.length,`kind`)}`];e.note&&n.push(e.note);for(let r of e.problems){n.push(``,` ${r.kind} · ${r.title} · ${r.count.toLocaleString(`en`)}${r.columns?` · in ${r.columns.map(e=>`“${e}”`).join(`, `)}`:``}`),n.push(r.fix?` fix (“${r.fix}”): trustycsv fix ${/[\s"']/.test(t)?JSON.stringify(t):t} --kinds ${r.kind}`:` no automatic fix: ${r.noFix}`);for(let e of r.places)n.push(` line ${e.line}${e.column==null?``:`, ${e.column}`}: ${Cx(JSON.stringify(e.value),80)}`);r.count>r.places.length&&n.push(` and ${mx(r.count-r.places.length,`more`)}`)}return n.join(`
532
+ `)+`
533
+ `}function Ex(e,t){let n=[],r=e.output==null?t[`dry-run`]?` (dry run: nothing written)`:` (unchanged: nothing written)`:e.output===`-`?``:` → ${e.output}`;n.push(`${e.file}${r}`);for(let t of e.steps)n.push(` ${t.done?`✓`:t.skipped?`✗`:`·`} ${t.step}: ${t.said}`);for(let t of e.notes)n.push(` ${t}`);if(e.left&&n.push(e.left.length?` Left: ${e.left.map(e=>`${e.kind} (${e.count.toLocaleString(`en`)})`).join(`, `)}`:` No problems left.`),e.firstRows){n.push(` The first rows would be:`);for(let t of e.firstRows)n.push(` ${t.map(e=>Cx(JSON.stringify(e),24)).join(` `)}`)}return n.join(`
534
+ `)}function Dx(e){let t=[`${e.before} → ${e.after}: rows matched by ${e.matchedBy===`content`?`their content`:`“${e.matchedBy}”`}`];if(e.same)return t[0]+`
535
+ No differences.
536
+ `;e.note&&t.push(` ${e.note}`),e.suggestion&&t.push(` ${e.suggestion} (--key "${e.suggestedKey}")`);let n=e.rows;t.push(` Rows: ${n.before.toLocaleString(`en`)} before, ${n.after.toLocaleString(`en`)} after · ${n.changed.toLocaleString(`en`)} changed, ${n.added.toLocaleString(`en`)} added, ${n.removed.toLocaleString(`en`)} removed`);let r=e.columns,i=[...r.added.map(e=>`“${e}” added`),...r.removed.map(e=>`“${e}” removed`),...r.renamed.map(e=>`“${e.from}” renamed “${e.to}”`)];if(i.length&&t.push(` Columns: ${i.join(`, `)}`),e.cellsChanged&&t.push(` Cells changed: ${e.cellsChanged.toLocaleString(`en`)} (${Object.entries(e.cellsChangedByColumn).map(([e,t])=>`${e}: ${t.toLocaleString(`en`)}`).join(`, `)})`),e.changedRows.length){t.push(``,` Changed rows:`);for(let n of e.changedRows)t.push(` line ${n.line}${n.lineBefore===n.line?``:` (line ${n.lineBefore} before)`}: ${n.cells.map(e=>`${e.column} ${xx(e.before)} → ${xx(e.after)}`).join(`, `)}`)}if(e.addedRows.length){t.push(``,` Added rows:`);for(let n of e.addedRows)t.push(` line ${n.line}: ${Cx(n.values.map(e=>JSON.stringify(e)).join(`, `),120)}`)}if(e.removedRows.length){t.push(``,` Removed rows:`);for(let n of e.removedRows)t.push(` line ${n.lineBefore} before: ${Cx(n.values.map(e=>JSON.stringify(e)).join(`, `),120)}`)}return e.shown&&t.push(``,` (${e.shown}: --max shows more)`),t.join(`
537
+ `)+`
538
+ `}export{c as S,pv as _,Fb as a,fv as b,Pb as c,Tb as d,ib as f,ov as g,Cv as h,Vb as i,Mb as l,rb as m,cx as n,Lb as o,lb as p,zb as r,Ib as s,tx as t,nb as u,av as v,mv as x,ev as y};