@teipublisher/pb-components
Version:
Collection of webcomponents underlying TEI Publisher
1 lines • 629 kB
JavaScript
class e{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){let s=[];return this.decompose(0,e,s,2),n.length&&n.decompose(0,n.length,s,3),this.decompose(t,this.length,s,1),i.from(s,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){let n=[];return this.decompose(e,t,n,0),i.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),i=this.length-this.scanIdentical(e,-1),n=new o(this),s=new o(e);for(let e=t,r=t;;){if(n.next(e),s.next(e),e=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(r+=n.value.length,n.done||r>=i)return!0}}iter(e=1){return new o(this,e)}iterRange(e,t=this.length){return new a(this,e,t)}iterLines(e,t){let i;if(null==e)i=this.iter();else{null==t&&(t=this.lines+1);let n=this.line(e).from;i=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new l(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(n){if(0==n.length)throw new RangeError("A document must have at least one line");return 1!=n.length||n[0]?n.length<=32?new t(n):i.from(t.split(n,[])):e.empty}}class t extends e{constructor(e,t=n(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,n){for(let s=0;;s++){let r=this.text[s],o=n+r.length;if((t?i:o)>=e)return new h(n,o,i,r);n=o+1,i++}}decompose(e,i,n,o){let a=e<=0&&i>=this.length?this:new t(r(this.text,e,i),Math.min(i,this.length)-Math.max(0,e));if(1&o){let e=n.pop(),i=s(a.text,e.text.slice(),0,a.length);if(i.length<=32)n.push(new t(i,e.length+a.length));else{let e=i.length>>1;n.push(new t(i.slice(0,e)),new t(i.slice(e)))}}else n.push(a)}replace(e,n,o){if(!(o instanceof t))return super.replace(e,n,o);let a=s(this.text,s(o.text,r(this.text,0,e)),n),l=this.length+o.length-(n-e);return a.length<=32?new t(a,l):i.from(t.split(a,[]),l)}sliceString(e,t=this.length,i="\n"){let n="";for(let s=0,r=0;s<=t&&r<this.text.length;r++){let o=this.text[r],a=s+o.length;s>e&&r&&(n+=i),e<a&&t>s&&(n+=o.slice(Math.max(0,e-s),t-s)),s=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,i){let n=[],s=-1;for(let r of e)n.push(r),s+=r.length+1,32==n.length&&(i.push(new t(n,s)),n=[],s=-1);return s>-1&&i.push(new t(n,s)),i}}class i extends e{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,i,n){for(let s=0;;s++){let r=this.children[s],o=n+r.length,a=i+r.lines-1;if((t?a:o)>=e)return r.lineInner(e,t,i,n);n=o+1,i=a+1}}decompose(e,t,i,n){for(let s=0,r=0;r<=t&&s<this.children.length;s++){let o=this.children[s],a=r+o.length;if(e<=a&&t>=r){let s=n&((r<=e?1:0)|(a>=t?2:0));r>=e&&a<=t&&!s?i.push(o):o.decompose(e-r,t-r,i,s)}r=a+1}}replace(e,t,n){if(n.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],a=r+o.length;if(e>=r&&t<=a){let l=o.replace(e-r,t-r,n),h=this.lines-o.lines+l.lines;if(l.lines<h>>4&&l.lines>h>>6){let r=this.children.slice();return r[s]=l,new i(r,this.length-(t-e)+n.length)}return super.replace(r,a,l)}r=a+1}return super.replace(e,t,n)}sliceString(e,t=this.length,i="\n"){let n="";for(let s=0,r=0;s<this.children.length&&r<=t;s++){let o=this.children[s],a=r+o.length;r>e&&s&&(n+=i),e<a&&t>r&&(n+=o.sliceString(e-r,t-r,i)),r=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof i))return 0;let n=0,[s,r,o,a]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==a)return n;let i=this.children[s],l=e.children[r];if(i!=l)return n+i.scanIdentical(l,t);n+=i.length+1}}static from(e,n=e.reduce((e,t)=>e+t.length+1,-1)){let s=0;for(let t of e)s+=t.lines;if(s<32){let i=[];for(let t of e)t.flatten(i);return new t(i,n)}let r=Math.max(32,s>>5),o=r<<1,a=r>>1,l=[],h=0,c=-1,u=[];function f(e){let n;if(e.lines>o&&e instanceof i)for(let t of e.children)f(t);else e.lines>a&&(h>a||!h)?(d(),l.push(e)):e instanceof t&&h&&(n=u[u.length-1])instanceof t&&e.lines+n.lines<=32?(h+=e.lines,c+=e.length+1,u[u.length-1]=new t(n.text.concat(e.text),n.length+1+e.length)):(h+e.lines>r&&d(),h+=e.lines,c+=e.length+1,u.push(e))}function d(){0!=h&&(l.push(1==u.length?u[0]:i.from(u,c)),c=-1,h=u.length=0)}for(let t of e)f(t);return d(),1==l.length?l[0]:new i(l,n)}}function n(e){let t=-1;for(let i of e)t+=i.length+1;return t}function s(e,t,i=0,n=1e9){for(let s=0,r=0,o=!0;r<e.length&&s<=n;r++){let a=e[r],l=s+a.length;l>=i&&(l>n&&(a=a.slice(0,n-s)),s<i&&(a=a.slice(i-s)),o?(t[t.length-1]+=a,o=!1):t.push(a)),s=l+1}return t}function r(e,t,i){return s(e,[""],t,i)}e.empty=new t([""],0);class o{constructor(e,i=1){this.dir=i,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[i>0?1:(e instanceof t?e.text.length:e.children.length)<<1]}nextInner(e,i){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,s=this.nodes[n],r=this.offsets[n],o=r>>1,a=s instanceof t?s.text.length:s.children.length;if(o==(i>0?a:0)){if(0==n)return this.done=!0,this.value="",this;i>0&&this.offsets[n-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(i>0?0:1)){if(this.offsets[n]+=i,0==e)return this.lineBreak=!0,this.value="\n",this;e--}else if(s instanceof t){let t=s.text[o+(i<0?-1:0)];if(this.offsets[n]+=i,t.length>Math.max(0,e))return this.value=0==e?t:i>0?t.slice(e):t.slice(0,t.length-e),this;e-=t.length}else{let r=s.children[o+(i<0?-1:0)];e>r.length?(e-=r.length,this.offsets[n]+=i):(i<0&&this.offsets[n]--,this.nodes.push(r),this.offsets.push(i>0?1:(r instanceof t?r.text.length:r.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class a{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new o(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=i?n:t<0?n.slice(n.length-i):n.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class l{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:n}=this.inner.next(e);return t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}"undefined"!=typeof Symbol&&(e.prototype[Symbol.iterator]=function(){return this.iter()},o.prototype[Symbol.iterator]=a.prototype[Symbol.iterator]=l.prototype[Symbol.iterator]=function(){return this});class h{constructor(e,t,i,n){this.from=e,this.to=t,this.number=i,this.text=n}get length(){return this.to-this.from}}let c="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=1;e<c.length;e++)c[e]+=c[e-1];function u(e){for(let t=1;t<c.length;t+=2)if(c[t]>e)return c[t-1]<=e;return!1}function f(e){return e>=127462&&e<=127487}const d=8205;function p(e,t,i=!0,n=!0){return(i?O:m)(e,t,n)}function O(e,t,i){if(t==e.length)return t;t&&g(e.charCodeAt(t))&&S(e.charCodeAt(t-1))&&t--;let n=b(e,t);for(t+=w(n);t<e.length;){let s=b(e,t);if(n==d||s==d||i&&u(s))t+=w(s),n=s;else{if(!f(s))break;{let i=0,n=t-2;for(;n>=0&&f(b(e,n));)i++,n-=2;if(i%2==0)break;t+=2}}}return t}function m(e,t,i){for(;t>0;){let n=O(e,t-2,i);if(n<t)return n;t--}return 0}function g(e){return e>=56320&&e<57344}function S(e){return e>=55296&&e<56320}function b(e,t){let i=e.charCodeAt(t);if(!S(i)||t+1==e.length)return i;let n=e.charCodeAt(t+1);return g(n)?n-56320+(i-55296<<10)+65536:i}function x(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode(55296+(e>>10),56320+(1023&e)))}function w(e){return e<65536?1:2}const y=/\r\n?|\n/;var v=function(e){return e[e.Simple=0]="Simple",e[e.TrackDel=1]="TrackDel",e[e.TrackBefore=2]="TrackBefore",e[e.TrackAfter=3]="TrackAfter",e}(v||(v={}));class k{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return 0==this.sections.length||2==this.sections.length&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,n=0;t<this.sections.length;){let s=this.sections[t++],r=this.sections[t++];r<0?(e(i,n,s),n+=s):n+=r,i+=s}}iterChangedRanges(e,t=!1){C(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];n<0?e.push(i,n):e.push(n,i)}return new k(e)}composeDesc(e){return this.empty?e:e.empty?this:T(this,e)}mapDesc(e,t=!1){return e.empty?this:X(this,e,t)}mapPos(e,t=-1,i=v.Simple){let n=0,s=0;for(let r=0;r<this.sections.length;){let o=this.sections[r++],a=this.sections[r++],l=n+o;if(a<0){if(l>e)return s+(e-n);s+=o}else{if(i!=v.Simple&&l>=e&&(i==v.TrackDel&&n<e&&l>e||i==v.TrackBefore&&n<e||i==v.TrackAfter&&l>e))return null;if(l>e||l==e&&t<0&&!o)return e==n||t<0?s:s+a;s+=a}n=l}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return s}touchesRange(e,t=e){for(let i=0,n=0;i<this.sections.length&&n<=t;){let s=n+this.sections[i++];if(this.sections[i++]>=0&&n<=t&&s>=e)return!(n<e&&s>t)||"cover";n=s}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+i+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(e=>"number"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeDesc");return new k(e)}static create(e){return new k(e)}}class Q extends k{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return C(this,(t,i,n,s,r)=>e=e.replace(n,n+(i-t),r),!1),e}mapDesc(e,t=!1){return X(this,e,t,!0)}invert(t){let i=this.sections.slice(),n=[];for(let s=0,r=0;s<i.length;s+=2){let o=i[s],a=i[s+1];if(a>=0){i[s]=a,i[s+1]=o;let l=s>>1;for(;n.length<l;)n.push(e.empty);n.push(o?t.slice(r,r+o):e.empty)}r+=o}return new Q(i,n)}compose(e){return this.empty?e:e.empty?this:T(this,e,!0)}map(e,t=!1){return e.empty?this:X(this,e,t,!0)}iterChanges(e,t=!1){C(this,e,t)}get desc(){return k.create(this.sections)}filter(e){let t=[],i=[],n=[],s=new Z(this);e:for(let r=0,o=0;;){let a=r==e.length?1e9:e[r++];for(;o<a||o==a&&0==s.len;){if(s.done)break e;let e=Math.min(s.len,a-o);$(n,e,-1);let r=-1==s.ins?-1:0==s.off?s.ins:0;$(t,e,r),r>0&&P(i,t,s.text),s.forward(e),o+=e}let l=e[r++];for(;o<l;){if(s.done)break e;let e=Math.min(s.len,l-o);$(t,e,-1),$(n,e,-1==s.ins?-1:0==s.off?s.ins:0),s.forward(e),o+=e}}return{changes:new Q(t,i),filtered:k.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],n=this.sections[t+1];n<0?e.push(i):0==n?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(t,i,n){let s=[],r=[],o=0,a=null;function l(e=!1){if(!e&&!s.length)return;o<i&&$(s,i-o,-1);let t=new Q(s,r);a=a?a.compose(t.map(a)):t,s=[],r=[],o=0}function h(t){if(Array.isArray(t))for(let e of t)h(e);else if(t instanceof Q){if(t.length!=i)throw new RangeError(`Mismatched change set length (got ${t.length}, expected ${i})`);l(),a=a?a.compose(t.map(a)):t}else{let{from:a,to:h=a,insert:c}=t;if(a>h||a<0||h>i)throw new RangeError(`Invalid change range ${a} to ${h} (in doc of length ${i})`);let u=c?"string"==typeof c?e.of(c.split(n||y)):c:e.empty,f=u.length;if(a==h&&0==f)return;a<o&&l(),a>o&&$(s,a-o,-1),$(s,h-a,f),P(r,s,u),o=h}}return h(t),l(!a),a}static empty(e){return new Q(e?[e,-1]:[],[])}static fromJSON(t){if(!Array.isArray(t))throw new RangeError("Invalid JSON representation of ChangeSet");let i=[],n=[];for(let s=0;s<t.length;s++){let r=t[s];if("number"==typeof r)i.push(r,-1);else{if(!Array.isArray(r)||"number"!=typeof r[0]||r.some((e,t)=>t&&"string"!=typeof e))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)i.push(r[0],0);else{for(;n.length<s;)n.push(e.empty);n[s]=e.of(r.slice(1)),i.push(r[0],n[s].length)}}}return new Q(i,n)}static createSet(e,t){return new Q(e,t)}}function $(e,t,i,n=!1){if(0==t&&i<=0)return;let s=e.length-2;s>=0&&i<=0&&i==e[s+1]?e[s]+=t:0==t&&0==e[s]?e[s+1]+=i:n?(e[s]+=t,e[s+1]+=i):e.push(t,i)}function P(t,i,n){if(0==n.length)return;let s=i.length-2>>1;if(s<t.length)t[t.length-1]=t[t.length-1].append(n);else{for(;t.length<s;)t.push(e.empty);t.push(n)}}function C(t,i,n){let s=t.inserted;for(let r=0,o=0,a=0;a<t.sections.length;){let l=t.sections[a++],h=t.sections[a++];if(h<0)r+=l,o+=l;else{let c=r,u=o,f=e.empty;for(;c+=l,u+=h,h&&s&&(f=f.append(s[a-2>>1])),!(n||a==t.sections.length||t.sections[a+1]<0);)l=t.sections[a++],h=t.sections[a++];i(r,c,o,u,f),r=c,o=u}}}function X(e,t,i,n=!1){let s=[],r=n?[]:null,o=new Z(e),a=new Z(t);for(let e=-1;;)if(-1==o.ins&&-1==a.ins){let e=Math.min(o.len,a.len);$(s,e,-1),o.forward(e),a.forward(e)}else if(a.ins>=0&&(o.ins<0||e==o.i||0==o.off&&(a.len<o.len||a.len==o.len&&!i))){let t=a.len;for($(s,a.ins,-1);t;){let i=Math.min(o.len,t);o.ins>=0&&e<o.i&&o.len<=i&&($(s,0,o.ins),r&&P(r,s,o.text),e=o.i),o.forward(i),t-=i}a.next()}else{if(!(o.ins>=0)){if(o.done&&a.done)return r?Q.createSet(s,r):k.create(s);throw new Error("Mismatched change set lengths")}{let t=0,i=o.len;for(;i;)if(-1==a.ins){let e=Math.min(i,a.len);t+=e,i-=e,a.forward(e)}else{if(!(0==a.ins&&a.len<i))break;i-=a.len,a.next()}$(s,t,e<o.i?o.ins:0),r&&e<o.i&&P(r,s,o.text),e=o.i,o.forward(o.len-i)}}}function T(e,t,i=!1){let n=[],s=i?[]:null,r=new Z(e),o=new Z(t);for(let e=!1;;){if(r.done&&o.done)return s?Q.createSet(n,s):k.create(n);if(0==r.ins)$(n,r.len,0,e),r.next();else if(0!=o.len||o.done){if(r.done||o.done)throw new Error("Mismatched change set lengths");{let t=Math.min(r.len2,o.len),i=n.length;if(-1==r.ins){let i=-1==o.ins?-1:o.off?0:o.ins;$(n,t,i,e),s&&i&&P(s,n,o.text)}else-1==o.ins?($(n,r.off?0:r.len,t,e),s&&P(s,n,r.textBit(t))):($(n,r.off?0:r.len,o.off?0:o.ins,e),s&&!o.off&&P(s,n,o.text));e=(r.ins>t||o.ins>=0&&o.len>t)&&(e||n.length>i),r.forward2(t),o.forward(t)}}else $(n,0,o.ins,e),s&&P(s,n,o.text),o.next()}}class Z{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-2==this.ins}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length?e.empty:t[i]}textBit(t){let{inserted:i}=this.set,n=this.i-2>>1;return n>=i.length&&!t?e.empty:i[n].slice(this.off,null==t?void 0:this.off+t)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){-1==this.ins?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class A{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return 16&this.flags?this.to:this.from}get head(){return 16&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 4&this.flags?-1:8&this.flags?1:0}get bidiLevel(){let e=3&this.flags;return 3==e?null:e}get goalColumn(){let e=this.flags>>5;return 33554431==e?void 0:e}map(e,t=-1){let i,n;return this.empty?i=n=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),i==this.from&&n==this.to?this:new A(i,n,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return R.range(e,t);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return R.range(this.anchor,i)}eq(e){return this.anchor==e.anchor&&this.head==e.head}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||"number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid JSON representation for SelectionRange");return R.range(e.anchor,e.head)}static create(e,t,i){return new A(e,t,i)}}class R{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:R.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let t=0;t<this.ranges.length;t++)if(!this.ranges[t].eq(e.ranges[t]))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return 1==this.ranges.length?this:new R([this.main],0)}addRange(e,t=!0){return R.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,R.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||"number"!=typeof e.main||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new R(e.ranges.map(e=>A.fromJSON(e)),e.main)}static single(e,t=e){return new R([R.range(e,t)],0)}static create(e,t=0){if(0==e.length)throw new RangeError("A selection needs at least one range");for(let i=0,n=0;n<e.length;n++){let s=e[n];if(s.empty?s.from<=i:s.from<i)return R.normalized(e.slice(),t);i=s.to}return new R(e,t)}static cursor(e,t=0,i,n){return A.create(e,e,(0==t?0:t<0?4:8)|(null==i?3:Math.min(2,i))|(null!=n?n:33554431)<<5)}static range(e,t,i,n){let s=(null!=i?i:33554431)<<5|(null==n?3:Math.min(2,n));return t<e?A.create(t,e,24|s):A.create(e,t,(t>e?4:0)|s)}static normalized(e,t=0){let i=e[t];e.sort((e,t)=>e.from-t.from),t=e.indexOf(i);for(let i=1;i<e.length;i++){let n=e[i],s=e[i-1];if(n.empty?n.from<=s.to:n.from<s.to){let r=s.from,o=Math.max(n.to,s.to);i<=t&&t--,e.splice(--i,2,n.anchor>n.head?R.range(o,r):R.range(r,o))}}return new R(e,t)}}function V(e,t){for(let i of e.ranges)if(i.to>t)throw new RangeError("Selection points outside of document")}let M=0;class Y{constructor(e,t,i,n,s){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=n,this.id=M++,this.default=e([]),this.extensions="function"==typeof s?s(this):s}static define(e={}){return new Y(e.combine||(e=>e),e.compareInput||((e,t)=>e===t),e.compare||(e.combine?(e,t)=>e===t:_),!!e.static,e.enables)}of(e){return new W([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new W(e,this,2,t)}from(e,t){return t||(t=e=>e),this.compute([e],i=>t(i.field(e)))}}function _(e,t){return e==t||e.length==t.length&&e.every((e,i)=>e===t[i])}class W{constructor(e,t,i,n){this.dependencies=e,this.facet=t,this.type=i,this.value=n,this.id=M++}dynamicSlot(e){var t;let i=this.value,n=this.facet.compareInput,s=this.id,r=e[s]>>1,o=2==this.type,a=!1,l=!1,h=[];for(let i of this.dependencies)"doc"==i?a=!0:"selection"==i?l=!0:0==(1&(null!==(t=e[i.id])&&void 0!==t?t:1))&&h.push(e[i.id]);return{create:e=>(e.values[r]=i(e),1),update(e,t){if(a&&t.docChanged||l&&(t.docChanged||t.selection)||z(e,h)){let t=i(e);if(o?!E(t,e.values[r],n):!n(t,e.values[r]))return e.values[r]=t,1}return 0},reconfigure:(e,t)=>{let a,l=t.config.address[s];if(null!=l){let s=K(t,l);if(this.dependencies.every(i=>i instanceof Y?t.facet(i)===e.facet(i):!(i instanceof D)||t.field(i,!1)==e.field(i,!1))||(o?E(a=i(e),s,n):n(a=i(e),s)))return e.values[r]=s,0}else a=i(e);return e.values[r]=a,1}}}}function E(e,t,i){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!i(e[n],t[n]))return!1;return!0}function z(e,t){let i=!1;for(let n of t)1&J(e,n)&&(i=!0);return i}function U(e,t,i){let n=i.map(t=>e[t.id]),s=i.map(e=>e.type),r=n.filter(e=>!(1&e)),o=e[t.id]>>1;function a(e){let i=[];for(let t=0;t<n.length;t++){let r=K(e,n[t]);if(2==s[t])for(let e of r)i.push(e);else i.push(r)}return t.combine(i)}return{create(e){for(let t of n)J(e,t);return e.values[o]=a(e),1},update(e,i){if(!z(e,r))return 0;let n=a(e);return t.compare(n,e.values[o])?0:(e.values[o]=n,1)},reconfigure(e,s){let r=z(e,n),l=s.config.facets[t.id],h=s.facet(t);if(l&&!r&&_(i,l))return e.values[o]=h,0;let c=a(e);return t.compare(c,h)?(e.values[o]=h,0):(e.values[o]=c,1)}}}const q=Y.define({static:!0});class D{constructor(e,t,i,n,s){this.id=e,this.createF=t,this.updateF=i,this.compareF=n,this.spec=s,this.provides=void 0}static define(e){let t=new D(M++,e.create,e.update,e.compare||((e,t)=>e===t),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(q).find(e=>e.field==this);return((null==t?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:e=>(e.values[t]=this.create(e),1),update:(e,i)=>{let n=e.values[t],s=this.updateF(n,i);return this.compareF(n,s)?0:(e.values[t]=s,1)},reconfigure:(e,i)=>null!=i.config.address[this.id]?(e.values[t]=i.field(this),0):(e.values[t]=this.create(e),1)}}init(e){return[this,q.of({field:this,create:e})]}get extension(){return this}}const I={lowest:4,low:3,default:2,high:1,highest:0};function j(e){return t=>new L(t,e)}const B={highest:j(I.highest),high:j(I.high),default:j(I.default),low:j(I.low),lowest:j(I.lowest)};class L{constructor(e,t){this.inner=e,this.prec=t}}class N{of(e){return new G(this,e)}reconfigure(e){return N.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class G{constructor(e,t){this.compartment=e,this.inner=t}}class F{constructor(e,t,i,n,s,r){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=n,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return null==t?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let n=[],s=Object.create(null),r=new Map;for(let i of H(e,t,r))i instanceof D?n.push(i):(s[i.facet.id]||(s[i.facet.id]=[])).push(i);let o=Object.create(null),a=[],l=[];for(let e of n)o[e.id]=l.length<<1,l.push(t=>e.slot(t));let h=null==i?void 0:i.config.facets;for(let e in s){let t=s[e],n=t[0].facet,r=h&&h[e]||[];if(t.every(e=>0==e.type))if(o[n.id]=a.length<<1|1,_(r,t))a.push(i.facet(n));else{let e=n.combine(t.map(e=>e.value));a.push(i&&n.compare(e,i.facet(n))?i.facet(n):e)}else{for(let e of t)0==e.type?(o[e.id]=a.length<<1|1,a.push(e.value)):(o[e.id]=l.length<<1,l.push(t=>e.dynamicSlot(t)));o[n.id]=l.length<<1,l.push(e=>U(e,n,t))}}let c=l.map(e=>e(o));return new F(e,r,c,o,a,s)}}function H(e,t,i){let n=[[],[],[],[],[]],s=new Map;function r(e,o){let a=s.get(e);if(null!=a){if(a<=o)return;let t=n[a].indexOf(e);t>-1&&n[a].splice(t,1),e instanceof G&&i.delete(e.compartment)}if(s.set(e,o),Array.isArray(e))for(let t of e)r(t,o);else if(e instanceof G){if(i.has(e.compartment))throw new RangeError("Duplicate use of compartment in extensions");let n=t.get(e.compartment)||e.inner;i.set(e.compartment,n),r(n,o)}else if(e instanceof L)r(e.inner,e.prec);else if(e instanceof D)n[o].push(e),e.provides&&r(e.provides,o);else if(e instanceof W)n[o].push(e),e.facet.extensions&&r(e.facet.extensions,I.default);else{let t=e.extension;if(!t)throw new Error(`Unrecognized extension value in extension set (${e}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(t,o)}}return r(e,I.default),n.reduce((e,t)=>e.concat(t))}function J(e,t){if(1&t)return 2;let i=t>>1,n=e.status[i];if(4==n)throw new Error("Cyclic dependency between fields and/or facets");if(2&n)return n;e.status[i]=4;let s=e.computeSlot(e,e.config.dynamicSlots[i]);return e.status[i]=2|s}function K(e,t){return 1&t?e.config.staticValues[t>>1]:e.values[t>>1]}const ee=Y.define(),te=Y.define({combine:e=>e.some(e=>e),static:!0}),ie=Y.define({combine:e=>e.length?e[0]:void 0,static:!0}),ne=Y.define(),se=Y.define(),re=Y.define(),oe=Y.define({combine:e=>!!e.length&&e[0]});class ae{constructor(e,t){this.type=e,this.value=t}static define(){return new le}}class le{of(e){return new ae(this,e)}}class he{constructor(e){this.map=e}of(e){return new ce(this,e)}}class ce{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return void 0===t?void 0:t==this.value?this:new ce(this.type,t)}is(e){return this.type==e}static define(e={}){return new he(e.map||(e=>e))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let n of e){let e=n.map(t);e&&i.push(e)}return i}}ce.reconfigure=ce.define(),ce.appendConfig=ce.define();class ue{constructor(e,t,i,n,s,r){this.startState=e,this.changes=t,this.selection=i,this.effects=n,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,i&&V(i,t.newLength),s.some(e=>e.type==ue.time)||(this.annotations=s.concat(ue.time.of(Date.now())))}static create(e,t,i,n,s,r){return new ue(e,t,i,n,s,r)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(ue.userEvent);return!(!t||!(t==e||t.length>e.length&&t.slice(0,e.length)==e&&"."==t[e.length]))}}function fe(e,t){let i=[];for(let n=0,s=0;;){let r,o;if(n<e.length&&(s==t.length||t[s]>=e[n]))r=e[n++],o=e[n++];else{if(!(s<t.length))return i;r=t[s++],o=t[s++]}!i.length||i[i.length-1]<r?i.push(r,o):i[i.length-1]<o&&(i[i.length-1]=o)}}function de(e,t,i){var n;let s,r,o;return i?(s=t.changes,r=Q.empty(t.changes.length),o=e.changes.compose(t.changes)):(s=t.changes.map(e.changes),r=e.changes.mapDesc(t.changes,!0),o=e.changes.compose(s)),{changes:o,selection:t.selection?t.selection.map(r):null===(n=e.selection)||void 0===n?void 0:n.map(s),effects:ce.mapEffects(e.effects,s).concat(ce.mapEffects(t.effects,r)),annotations:e.annotations.length?e.annotations.concat(t.annotations):t.annotations,scrollIntoView:e.scrollIntoView||t.scrollIntoView}}function pe(e,t,i){let n=t.selection,s=be(t.annotations);return t.userEvent&&(s=s.concat(ue.userEvent.of(t.userEvent))),{changes:t.changes instanceof Q?t.changes:Q.of(t.changes||[],i,e.facet(ie)),selection:n&&(n instanceof R?n:R.single(n.anchor,n.head)),effects:be(t.effects),annotations:s,scrollIntoView:!!t.scrollIntoView}}function Oe(e,t,i){let n=pe(e,t.length?t[0]:{},e.doc.length);t.length&&!1===t[0].filter&&(i=!1);for(let s=1;s<t.length;s++){!1===t[s].filter&&(i=!1);let r=!!t[s].sequential;n=de(n,pe(e,t[s],r?n.changes.newLength:e.doc.length),r)}let s=ue.create(e,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return ge(i?me(s):s)}function me(e){let t=e.startState,i=!0;for(let n of t.facet(ne)){let t=n(e);if(!1===t){i=!1;break}Array.isArray(t)&&(i=!0===i?t:fe(i,t))}if(!0!==i){let n,s;if(!1===i)s=e.changes.invertedDesc,n=Q.empty(t.doc.length);else{let t=e.changes.filter(i);n=t.changes,s=t.filtered.mapDesc(t.changes).invertedDesc}e=ue.create(t,n,e.selection&&e.selection.map(s),ce.mapEffects(e.effects,s),e.annotations,e.scrollIntoView)}let n=t.facet(se);for(let i=n.length-1;i>=0;i--){let s=n[i](e);e=s instanceof ue?s:Array.isArray(s)&&1==s.length&&s[0]instanceof ue?s[0]:Oe(t,be(s),!1)}return e}function ge(e){let t=e.startState,i=t.facet(re),n=e;for(let s=i.length-1;s>=0;s--){let r=i[s](e);r&&Object.keys(r).length&&(n=de(n,pe(t,r,e.changes.newLength),!0))}return n==e?e:ue.create(t,e.changes,e.selection,n.effects,n.annotations,n.scrollIntoView)}ue.time=ae.define(),ue.userEvent=ae.define(),ue.addToHistory=ae.define(),ue.remote=ae.define();const Se=[];function be(e){return null==e?Se:Array.isArray(e)?e:[e]}var xe=function(e){return e[e.Word=0]="Word",e[e.Space=1]="Space",e[e.Other=2]="Other",e}(xe||(xe={}));const we=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let ye;try{ye=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(e){}function ve(e){if(ye)return ye.test(e);for(let t=0;t<e.length;t++){let i=e[t];if(/\w/.test(i)||i>""&&(i.toUpperCase()!=i.toLowerCase()||we.test(i)))return!0}return!1}function ke(e){return t=>{if(!/\S/.test(t))return xe.Space;if(ve(t))return xe.Word;for(let i=0;i<e.length;i++)if(t.indexOf(e[i])>-1)return xe.Word;return xe.Other}}class Qe{constructor(e,t,i,n,s,r){this.config=e,this.doc=t,this.selection=i,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let e=0;e<this.config.dynamicSlots.length;e++)J(this,e<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(null!=i)return J(this,i),K(this,i);if(t)throw new RangeError("Field is not present in this state")}update(...e){return Oe(this,e,!0)}applyTransaction(e){let t,i=this.config,{base:n,compartments:s}=i;for(let t of e.effects)t.is(N.reconfigure)?(i&&(s=new Map,i.compartments.forEach((e,t)=>s.set(t,e)),i=null),s.set(t.value.compartment,t.value.extension)):t.is(ce.reconfigure)?(i=null,n=t.value):t.is(ce.appendConfig)&&(i=null,n=be(n).concat(t.value));if(i)t=e.startState.values.slice();else{i=F.resolve(n,s,this),t=new Qe(i,this.doc,this.selection,i.dynamicSlots.map(()=>null),(e,t)=>t.reconfigure(e,this),null).values}new Qe(i,e.newDoc,e.newSelection,t,(t,i)=>i.update(t,e),e)}replaceSelection(e){return"string"==typeof e&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:R.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),n=this.changes(i.changes),s=[i.range],r=be(i.effects);for(let i=1;i<t.ranges.length;i++){let o=e(t.ranges[i]),a=this.changes(o.changes),l=a.map(n);for(let e=0;e<i;e++)s[e]=s[e].map(l);let h=n.mapDesc(a,!0);s.push(o.range.map(h)),n=n.compose(l),r=ce.mapEffects(r,l).concat(ce.mapEffects(be(o.effects),h))}return{changes:n,selection:R.create(s,t.mainIndex),effects:r}}changes(e=[]){return e instanceof Q?e:Q.of(e,this.doc.length,this.facet(Qe.lineSeparator))}toText(t){return e.of(t.split(this.facet(Qe.lineSeparator)||y))}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 null==t?e.default:(J(this,t),K(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let n=e[i];n instanceof D&&null!=this.config.address[n.id]&&(t[i]=n.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||"string"!=typeof e.doc)throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(i)for(let t in i)if(Object.prototype.hasOwnProperty.call(e,t)){let s=i[t],r=e[t];n.push(s.init(e=>s.spec.fromJSON(r,e)))}return Qe.create({doc:e.doc,selection:R.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(t={}){let i=F.resolve(t.extensions||[],new Map),n=t.doc instanceof e?t.doc:e.of((t.doc||"").split(i.staticFacet(Qe.lineSeparator)||y)),s=t.selection?t.selection instanceof R?t.selection:R.single(t.selection.anchor,t.selection.head):R.single(0);return V(s,n.length),i.staticFacet(te)||(s=s.asSingle()),new Qe(i,n,s,i.dynamicSlots.map(()=>null),(e,t)=>t.create(e),null)}get tabSize(){return this.facet(Qe.tabSize)}get lineBreak(){return this.facet(Qe.lineSeparator)||"\n"}get readOnly(){return this.facet(oe)}phrase(e,...t){for(let t of this.facet(Qe.phrases))if(Object.prototype.hasOwnProperty.call(t,e)){e=t[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(e,i)=>{if("$"==i)return"$";let n=+(i||1);return!n||n>t.length?e:t[n-1]})),e}languageDataAt(e,t,i=-1){let n=[];for(let s of this.facet(ee))for(let r of s(this,t,i))Object.prototype.hasOwnProperty.call(r,e)&&n.push(r[e]);return n}charCategorizer(e){return ke(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:i,length:n}=this.doc.lineAt(e),s=this.charCategorizer(e),r=e-i,o=e-i;for(;r>0;){let e=p(t,r,!1);if(s(t.slice(e,r))!=xe.Word)break;r=e}for(;o<n;){let e=p(t,o);if(s(t.slice(o,e))!=xe.Word)break;o=e}return r==o?null:R.range(r+i,o+i)}}function $e(e,t,i={}){let n={};for(let t of e)for(let e of Object.keys(t)){let s=t[e],r=n[e];if(void 0===r)n[e]=s;else if(r===s||void 0===s);else{if(!Object.hasOwnProperty.call(i,e))throw new Error("Config merge conflict for field "+e);n[e]=i[e](r,s)}}for(let e in t)void 0===n[e]&&(n[e]=t[e]);return n}Qe.allowMultipleSelections=te,Qe.tabSize=Y.define({combine:e=>e.length?e[0]:4}),Qe.lineSeparator=ie,Qe.readOnly=oe,Qe.phrases=Y.define({compare(e,t){let i=Object.keys(e),n=Object.keys(t);return i.length==n.length&&i.every(i=>e[i]==t[i])}}),Qe.languageData=ee,Qe.changeFilter=ne,Qe.transactionFilter=se,Qe.transactionExtender=re,N.reconfigure=ce.define();class Pe{eq(e){return this==e}range(e,t=e){return Ce.create(e,t,this)}}Pe.prototype.startSide=Pe.prototype.endSide=0,Pe.prototype.point=!1,Pe.prototype.mapMode=v.TrackDel;class Ce{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Ce(e,t,i)}}function Xe(e,t){return e.from-t.from||e.value.startSide-t.value.startSide}class Te{constructor(e,t,i,n){this.from=e,this.to=t,this.value=i,this.maxPoint=n}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,n=0){let s=i?this.to:this.from;for(let r=n,o=s.length;;){if(r==o)return r;let n=r+o>>1,a=s[n]-e||(i?this.value[n].endSide:this.value[n].startSide)-t;if(n==r)return a>=0?r:o;a>=0?o=n:r=n+1}}between(e,t,i,n){for(let s=this.findIndex(t,-1e9,!0),r=this.findIndex(i,1e9,!1,s);s<r;s++)if(!1===n(this.from[s]+e,this.to[s]+e,this.value[s]))return!1}map(e,t){let i=[],n=[],s=[],r=-1,o=-1;for(let a=0;a<this.value.length;a++){let l,h,c=this.value[a],u=this.from[a]+e,f=this.to[a]+e;if(u==f){let e=t.mapPos(u,c.startSide,c.mapMode);if(null==e)continue;if(l=h=e,c.startSide!=c.endSide&&(h=t.mapPos(u,c.endSide),h<l))continue}else if(l=t.mapPos(u,c.startSide),h=t.mapPos(f,c.endSide),l>h||l==h&&c.startSide>0&&c.endSide<=0)continue;(h-l||c.endSide-c.startSide)<0||(r<0&&(r=l),c.point&&(o=Math.max(o,h-l)),i.push(c),n.push(l-r),s.push(h-r))}return{mapped:i.length?new Te(n,s,i,o):null,pos:r}}}class Ze{constructor(e,t,i,n){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=n}static create(e,t,i,n){return new Ze(e,t,i,n)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:n=0,filterTo:s=this.length}=e,r=e.filter;if(0==t.length&&!r)return this;if(i&&(t=t.slice().sort(Xe)),this.isEmpty)return t.length?Ze.of(t):this;let o=new Me(this,null,-1).goto(0),a=0,l=[],h=new Re;for(;o.value||a<t.length;)if(a<t.length&&(o.from-t[a].from||o.startSide-t[a].value.startSide)>=0){let e=t[a++];h.addInner(e.from,e.to,e.value)||l.push(e)}else 1==o.rangeIndex&&o.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(o.chunkIndex)<t[a].from)&&(!r||n>this.chunkEnd(o.chunkIndex)||s<this.chunkPos[o.chunkIndex])&&h.addChunk(this.chunkPos[o.chunkIndex],this.chunk[o.chunkIndex])?o.nextChunk():((!r||n>o.to||s<o.from||r(o.from,o.to,o.value))&&(h.addInner(o.from,o.to,o.value)||l.push(Ce.create(o.from,o.to,o.value))),o.next());return h.finishInner(this.nextLayer.isEmpty&&!l.length?Ze.empty:this.nextLayer.update({add:l,filter:r,filterFrom:n,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],n=-1;for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s],a=e.touchesRange(r,r+o.length);if(!1===a)n=Math.max(n,o.maxPoint),t.push(o),i.push(e.mapPos(r));else if(!0===a){let{mapped:s,pos:a}=o.map(r,e);s&&(n=Math.max(n,s.maxPoint),t.push(s),i.push(a))}}let s=this.nextLayer.map(e);return 0==t.length?s:new Ze(i,t,s||Ze.empty,n)}between(e,t,i){if(!this.isEmpty){for(let n=0;n<this.chunk.length;n++){let s=this.chunkPos[n],r=this.chunk[n];if(t>=s&&e<=s+r.length&&!1===r.between(s,e-s,t-s,i))return}this.nextLayer.between(e,t,i)}}iter(e=0){return Ye.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ye.from(e).goto(t)}static compare(e,t,i,n,s=-1){let r=e.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=s),o=t.filter(e=>e.maxPoint>0||!e.isEmpty&&e.maxPoint>=s),a=Ve(r,o,i),l=new We(r,a,s),h=new We(o,a,s);i.iterGaps((e,t,i)=>Ee(l,e,h,t,i,n)),i.empty&&0==i.length&&Ee(l,0,h,0,0,n)}static eq(e,t,i=0,n){null==n&&(n=999999999);let s=e.filter(e=>!e.isEmpty&&t.indexOf(e)<0),r=t.filter(t=>!t.isEmpty&&e.indexOf(t)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let o=Ve(s,r),a=new We(s,o,0).goto(i),l=new We(r,o,0).goto(i);for(;;){if(a.to!=l.to||!ze(a.active,l.active)||a.point&&(!l.point||!a.point.eq(l.point)))return!1;if(a.to>n)return!0;a.next(),l.next()}}static spans(e,t,i,n,s=-1){let r=new We(e,null,s).goto(t),o=t,a=r.openStart;for(;;){let e=Math.min(r.to,i);if(r.point){let i=r.activeForPoint(r.to),s=r.pointFrom<t?i.length+1:Math.min(i.length,a);n.point(o,e,r.point,i,s,r.pointRank),a=Math.min(r.openEnd(e),i.length)}else e>o&&(n.span(o,e,r.active,a),a=r.openEnd(e));if(r.to>i)return a+(r.point&&r.to>i?1:0);o=r.to,r.next()}}static of(e,t=!1){let i=new Re;for(let n of e instanceof Ce?[e]:t?Ae(e):e)i.add(n.from,n.to,n.value);return i.finish()}}function Ae(e){if(e.length>1)for(let t=e[0],i=1;i<e.length;i++){let n=e[i];if(Xe(t,n)>0)return e.slice().sort(Xe);t=n}return e}Ze.empty=new Ze([],[],null,-1),Ze.empty.nextLayer=Ze.empty;class Re{finishChunk(e){this.chunks.push(new Te(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new Re)).add(e,t,i)}addInner(e,t,i){let n=e-this.lastTo||i.startSide-this.last.endSide;if(n<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(n<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(Ze.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return e;let t=Ze.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function Ve(e,t,i){let n=new Map;for(let t of e)for(let e=0;e<t.chunk.length;e++)t.chunk[e].maxPoint<=0&&n.set(t.chunk[e],t.chunkPos[e]);let s=new Set;for(let e of t)for(let t=0;t<e.chunk.length;t++){let r=n.get(e.chunk[t]);null==r||(i?i.mapPos(r):r)!=e.chunkPos[t]||(null==i?void 0:i.touchesRange(r,r+e.chunk[t].length))||s.add(e.chunk[t])}return s}class Me{constructor(e,t,i,n=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=n}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let 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++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let n=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<n)&&this.setRangeIndex(n)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;){if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class Ye{constructor(e){this.heap=e}static from(e,t=null,i=-1){let n=[];for(let s=0;s<e.length;s++)for(let r=e[s];!r.isEmpty;r=r.nextLayer)r.maxPoint>=i&&n.push(new Me(r,t,i,s));return 1==n.length?n[0]:new Ye(n)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let e=this.heap.length>>1;e>=0;e--)_e(this.heap,e);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let e=this.heap.length>>1;e>=0;e--)_e(this.heap,e);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(0==this.heap.length)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(),_e(this.heap,0)}}}function _e(e,t){for(let i=e[t];;){let n=1+(t<<1);if(n>=e.length)break;let s=e[n];if(n+1<e.length&&s.compare(e[n+1])>=0&&(s=e[n+1],n++),i.compare(s)<0)break;e[n]=i,e[t]=s,t=n}}class We{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ye.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){Ue(this.active,e),Ue(this.activeTo,e),Ue(this.activeRank,e),this.minActive=De(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:n,rank:s}=this.cursor;for(;t<this.activeRank.length&&this.activeRank[t]<=s;)t++;qe(this.active,t,i),qe(this.activeTo,t,n),qe(this.activeRank,t,s),e&&qe(e,t,this.cursor.from),this.minActive=De(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let n=this.minActive;if(n>-1&&(this.activeTo[n]-this.cursor.from||this.active[n].endSide-this.cursor.startSide)<0){if(this.activeTo[n]>e){this.to=this.activeTo[n],this.endSide=this.active[n].endSide;break}this.removeActive(n),i&&Ue(i,n)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let e=this.cursor.value;if(e.point){if(!(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)){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}this.cursor.next()}else this.addActive(i),this.cursor.next()}}}if(i){this.openStart=0;for(let t=i.length-1;t>=0&&i[t]<e;t--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function Ee(e,t,i,n,s,r){e.goto(t),i.goto(n);let o=n+s,a=n,l=n-t;for(;;){let t=e.to+l-i.to||e.endSide-i.endSide,n=t<0?e.to+l:i.to,s=Math.min(n,o);if(e.point||i.point?e.point&&i.point&&(e.point==i.point||e.point.eq(i.point))&&ze(e.activeForPoint(e.to),i.activeForPoint(i.to))||r.comparePoint(a,s,e.point,i.point):s>a&&!ze(e.active,i.active)&&r.compareRange(a,s,e.active,i.active),n>o)break;a=n,t<=0&&e.next(),t>=0&&i.next()}}function ze(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++)if(e[i]!=t[i]&&!e[i].eq(t[i]))return!1;return!0}function Ue(e,t){for(let i=t,n=e.length-1;i<n;i++)e[i]=e[i+1];e.pop()}function qe(e,t,i){for(let i=e.length-1;i>=t;i--)e[i+1]=e[i];e[t]=i}function De(e,t){let i=-1,n=1e9;for(let s=0;s<t.length;s++)(t[s]-n||e[s].endSide-e[i].endSide)<0&&(i=s,n=t[s]);return i}function Ie(e,t,i=e.length){let n=0;for(let s=0;s<i;)9==e.charCodeAt(s)?(n+=t-n%t,s++):(n++,s=p(e,s));return n}function je(e,t,i,n){for(let n=0,s=0;;){if(s>=t)return n;if(n==e.length)break;s+=9==e.charCodeAt(n)?i-s%i:1,n=p(e,n)}return!0===n?-1:e.length}const Be="ͼ",Le="undefined"==typeof Symbol?"__"+Be:Symbol.for(Be),Ne="undefined"==typeof Symbol?"__styleSet"+Math.floor(1e8*Math.random()):Symbol("styleSet"),Ge="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:{};class Fe{constructor(e,t){this.rules=[];let{finish:i}=t||{};function n(e){return/^@/.test(e)?[e]:e.split(/,\s*/)}function s(e,t,r,o){let a=[],l=/^@(\w+)\b/.exec(e[0]),h=l&&"keyframes"==l[1];if(l&&null==t)return r.push(e[0]+";");for(let i in t){let o=t[i];if(/&/.test(i))s(i.split(/,\s*/).map(t=>e.map(e=>t.replace(/&/,e))).reduce((e,t)=>e.concat(t)),o,r);else if(o&&"object"==typeof o){if(!l)throw new RangeError("The value of a property ("+i+") should be a primitive value.");s(n(i),o,a,h)}else null!=o&&a.push(i.replace(/_.*/,"").replace(/[A-Z]/g,e=>"-"+e.toLowerCase())+": "+o+";")}(a.length||h)&&r.push((!i||l||o?e:e.map(i)).join(", ")+" {"+a.join(" ")+"}")}for(let t in e)s(n(t),e[t],this.rules)}getRules(){return this.rules.join("\n")}static newName(){let e=Ge[Le]||1;return Ge[Le]=e+1,Be+e.toString(36)}static mount(e,t){(e[Ne]||new Je(e)).mount(Array.isArray(t)?t:[t])}}let He=new Map;class Je{constructor(e){let t=e.ownerDocument||e,i=t.defaultView;if(!e.head&&e.adoptedStyleSheets&&i.CSSStyleSheet){let n=He.get(t);if(n)return e.adoptedStyleSheets=[n.sheet,...e.adoptedStyleSheets],e[Ne]=n;this.sheet=new i.CSSStyleSheet,e.adoptedStyleSheets=[this.sheet,...e.adoptedStyleSheets],He.set(t,this)}else{this.styleTag=t.createElement("style");let i=e.head||e;i.insertBefore(this.styleTag,i.firstChild)}this.modules=[],e[Ne]=this}mount(e){let t=this.sheet,i=0,n=0;for(let s=0;s<e.length;s++){let r=e[s],o=this.modules.indexOf(r);if(o<n&&o>-1&&(this.modules.splice(o,1),n--,o=-1),-1==o){if(this.modules.splice(n++,0,r),t)for(let e=0;e<r.rules.length;e++)t.insertRule(r.rules[e],i++)}else{for(;n<o;)i+=this.modules[n++].rules.length;i+=r.rules.length,n++}}if(!t){let e="";for(let t=0;t<this.modules.length;t++)e+=this.modules[t].getRules()+"\n";this.styleTag.textContent=e}}}for(var Ke={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:"'"},et={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},tt="undefined"!=typeof navigator&&/Mac/.test(navigator.platform),it="undefined"!=typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),nt=0;nt<10;nt++)Ke[48+nt]=Ke[96+nt]=String(nt);for(nt=1;nt<=24;nt++)Ke[nt+111]="F"+nt;for(nt=65;nt