Files
conservatorio-tomadini/media/vendor/codemirror/js/codemirror-state.min.js
2024-12-17 17:34:10 +01:00

6 lines
47 KiB
JavaScript

class v{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,n){[e,t]=J(this,e,t);let i=[];return this.decompose(0,e,i,2),n.length&&n.decompose(0,n.length,i,3),this.decompose(t,this.length,i,1),E.from(i,this.length-(t-e)+n.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=J(this,e,t);let n=[];return this.decompose(e,t,n,0),E.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),i=new q(this),s=new q(e);for(let r=t,h=t;;){if(i.next(r),s.next(r),r=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(h+=i.value.length,i.done||h>=n)return!0}}iter(e=1){return new q(this,e)}iterRange(e,t=this.length){return new ke(this,e,t)}iterLines(e,t){let n;if(e==null)n=this.iter();else{t==null&&(t=this.lines+1);let i=this.line(e).from;n=this.iterRange(i,Math.max(i,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new ye(n)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?v.empty:e.length<=32?new m(e):E.from(m.split(e,[]))}}class m extends v{constructor(e,t=He(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,n,i){for(let s=0;;s++){let r=this.text[s],h=i+r.length;if((t?n:h)>=e)return new Se(i,h,n,r);i=h+1,n++}}decompose(e,t,n,i){let s=e<=0&&t>=this.length?this:new m(xe(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(i&1){let r=n.pop(),h=Q(s.text,r.text.slice(),0,s.length);if(h.length<=32)n.push(new m(h,r.length+s.length));else{let a=h.length>>1;n.push(new m(h.slice(0,a)),new m(h.slice(a)))}}else n.push(s)}replace(e,t,n){if(!(n instanceof m))return super.replace(e,t,n);[e,t]=J(this,e,t);let i=Q(this.text,Q(n.text,xe(this.text,0,e)),t),s=this.length+n.length-(t-e);return i.length<=32?new m(i,s):E.from(m.split(i,[]),s)}sliceString(e,t=this.length,n=`
`){[e,t]=J(this,e,t);let i="";for(let s=0,r=0;s<=t&&r<this.text.length;r++){let h=this.text[r],a=s+h.length;s>e&&r&&(i+=n),e<a&&t>s&&(i+=h.slice(Math.max(0,e-s),t-s)),s=a+1}return i}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let n=[],i=-1;for(let s of e)n.push(s),i+=s.length+1,n.length==32&&(t.push(new m(n,i)),n=[],i=-1);return i>-1&&t.push(new m(n,i)),t}}class E extends v{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let n of e)this.lines+=n.lines}lineInner(e,t,n,i){for(let s=0;;s++){let r=this.children[s],h=i+r.length,a=n+r.lines-1;if((t?a:h)>=e)return r.lineInner(e,t,n,i);i=h+1,n=a+1}}decompose(e,t,n,i){for(let s=0,r=0;r<=t&&s<this.children.length;s++){let h=this.children[s],a=r+h.length;if(e<=a&&t>=r){let o=i&((r<=e?1:0)|(a>=t?2:0));r>=e&&a<=t&&!o?n.push(h):h.decompose(e-r,t-r,n,o)}r=a+1}}replace(e,t,n){if([e,t]=J(this,e,t),n.lines<this.lines)for(let i=0,s=0;i<this.children.length;i++){let r=this.children[i],h=s+r.length;if(e>=s&&t<=h){let a=r.replace(e-s,t-s,n),o=this.lines-r.lines+a.lines;if(a.lines<o>>4&&a.lines>o>>6){let f=this.children.slice();return f[i]=a,new E(f,this.length-(t-e)+n.length)}return super.replace(s,h,a)}s=h+1}return super.replace(e,t,n)}sliceString(e,t=this.length,n=`
`){[e,t]=J(this,e,t);let i="";for(let s=0,r=0;s<this.children.length&&r<=t;s++){let h=this.children[s],a=r+h.length;r>e&&s&&(i+=n),e<a&&t>r&&(i+=h.sliceString(e-r,t-r,n)),r=a+1}return i}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof E))return 0;let n=0,[i,s,r,h]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;i+=t,s+=t){if(i==r||s==h)return n;let a=this.children[i],o=e.children[s];if(a!=o)return n+a.scanIdentical(o,t);n+=a.length+1}}static from(e,t=e.reduce((n,i)=>n+i.length+1,-1)){let n=0;for(let c of e)n+=c.lines;if(n<32){let c=[];for(let p of e)p.flatten(c);return new m(c,t)}let i=Math.max(32,n>>5),s=i<<1,r=i>>1,h=[],a=0,o=-1,f=[];function u(c){let p;if(c.lines>s&&c instanceof E)for(let b of c.children)u(b);else c.lines>r&&(a>r||!a)?(d(),h.push(c)):c instanceof m&&a&&(p=f[f.length-1])instanceof m&&c.lines+p.lines<=32?(a+=c.lines,o+=c.length+1,f[f.length-1]=new m(p.text.concat(c.text),p.length+1+c.length)):(a+c.lines>i&&d(),a+=c.lines,o+=c.length+1,f.push(c))}function d(){a!=0&&(h.push(f.length==1?f[0]:E.from(f,o)),o=-1,a=f.length=0)}for(let c of e)u(c);return d(),h.length==1?h[0]:new E(h,t)}}v.empty=new m([""],0);function He(l){let e=-1;for(let t of l)e+=t.length+1;return e}function Q(l,e,t=0,n=1e9){for(let i=0,s=0,r=!0;s<l.length&&i<=n;s++){let h=l[s],a=i+h.length;a>=t&&(a>n&&(h=h.slice(0,n-i)),i<t&&(h=h.slice(t-i)),r?(e[e.length-1]+=h,r=!1):e.push(h)),i=a+1}return e}function xe(l,e,t){return Q(l,[""],e,t)}class q{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 m?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let n=this.nodes.length-1,i=this.nodes[n],s=this.offsets[n],r=s>>1,h=i instanceof m?i.text.length:i.children.length;if(r==(t>0?h: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((s&1)==(t>0?0:1)){if(this.offsets[n]+=t,e==0)return this.lineBreak=!0,this.value=`
`,this;e--}else if(i instanceof m){let a=i.text[r+(t<0?-1:0)];if(this.offsets[n]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=i.children[r+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[n]+=t):(t<0&&this.offsets[n]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof m?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class ke{constructor(e,t,n){this.value="",this.done=!1,this.cursor=new q(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:i}=this.cursor.next(e);return this.pos+=(i.length+e)*t,this.value=i.length<=n?i:t<0?i.slice(i.length-n):i.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!=""}}class ye{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:n,value:i}=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=i,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(v.prototype[Symbol.iterator]=function(){return this.iter()},q.prototype[Symbol.iterator]=ke.prototype[Symbol.iterator]=ye.prototype[Symbol.iterator]=function(){return this});class Se{constructor(e,t,n,i){this.from=e,this.to=t,this.number=n,this.text=i}get length(){return this.to-this.from}}function J(l,e,t){return e=Math.max(0,Math.min(l.length,e)),[e,Math.max(e,Math.min(l.length,t))]}let L="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(l=>l?parseInt(l,36):1);for(let l=1;l<L.length;l++)L[l]+=L[l-1];function Ze(l){for(let e=1;e<L.length;e+=2)if(L[e]>l)return L[e-1]<=l;return!1}function Ie(l){return l>=127462&&l<=127487}const Pe=8205;function $(l,e,t=!0,n=!0){return(t?Ae:Ke)(l,e,n)}function Ae(l,e,t){if(e==l.length)return e;e&&be(l.charCodeAt(e))&&Oe(l.charCodeAt(e-1))&&e--;let n=X(l,e);for(e+=se(n);e<l.length;){let i=X(l,e);if(n==Pe||i==Pe||t&&Ze(i))e+=se(i),n=i;else if(Ie(i)){let s=0,r=e-2;for(;r>=0&&Ie(X(l,r));)s++,r-=2;if(s%2==0)break;e+=2}else break}return e}function Ke(l,e,t){for(;e>0;){let n=Ae(l,e-2,t);if(n<e)return n;e--}return 0}function be(l){return l>=56320&&l<57344}function Oe(l){return l>=55296&&l<56320}function X(l,e){let t=l.charCodeAt(e);if(!Oe(t)||e+1==l.length)return t;let n=l.charCodeAt(e+1);return be(n)?(t-55296<<10)+(n-56320)+65536:t}function Qe(l){return l<=65535?String.fromCharCode(l):(l-=65536,String.fromCharCode((l>>10)+55296,(l&1023)+56320))}function se(l){return l<65536?1:2}const re=/\r\n?|\n/;var C=function(l){return l[l.Simple=0]="Simple",l[l.TrackDel=1]="TrackDel",l[l.TrackBefore=2]="TrackBefore",l[l.TrackAfter=3]="TrackAfter",l}(C||(C={}));class O{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,i=0;t<this.sections.length;){let s=this.sections[t++],r=this.sections[t++];r<0?(e(n,i,s),i+=s):i+=r,n+=s}}iterChangedRanges(e,t=!1){le(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let n=this.sections[t++],i=this.sections[t++];i<0?e.push(n,i):e.push(i,n)}return new O(e)}composeDesc(e){return this.empty?e:e.empty?this:Ee(this,e)}mapDesc(e,t=!1){return e.empty?this:he(this,e,t)}mapPos(e,t=-1,n=C.Simple){let i=0,s=0;for(let r=0;r<this.sections.length;){let h=this.sections[r++],a=this.sections[r++],o=i+h;if(a<0){if(o>e)return s+(e-i);s+=h}else{if(n!=C.Simple&&o>=e&&(n==C.TrackDel&&i<e&&o>e||n==C.TrackBefore&&i<e||n==C.TrackAfter&&o>e))return null;if(o>e||o==e&&t<0&&!h)return e==i||t<0?s:s+a;s+=a}i=o}if(e>i)throw new RangeError(`Position ${e} is out of range for changeset of length ${i}`);return s}touchesRange(e,t=e){for(let n=0,i=0;n<this.sections.length&&i<=t;){let s=this.sections[n++],r=this.sections[n++],h=i+s;if(r>=0&&i<=t&&h>=e)return i<e&&h>t?"cover":!0;i=h}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let n=this.sections[t++],i=this.sections[t++];e+=(e?" ":"")+n+(i>=0?":"+i:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new O(e)}static create(e){return new O(e)}}class k extends O{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 le(this,(t,n,i,s,r)=>e=e.replace(i,i+(n-t),r),!1),e}mapDesc(e,t=!1){return he(this,e,t,!0)}invert(e){let t=this.sections.slice(),n=[];for(let i=0,s=0;i<t.length;i+=2){let r=t[i],h=t[i+1];if(h>=0){t[i]=h,t[i+1]=r;let a=i>>1;for(;n.length<a;)n.push(v.empty);n.push(r?e.slice(s,s+r):v.empty)}s+=r}return new k(t,n)}compose(e){return this.empty?e:e.empty?this:Ee(this,e,!0)}map(e,t=!1){return e.empty?this:he(this,e,t,!0)}iterChanges(e,t=!1){le(this,e,t)}get desc(){return O.create(this.sections)}filter(e){let t=[],n=[],i=[],s=new z(this);e:for(let r=0,h=0;;){let a=r==e.length?1e9:e[r++];for(;h<a||h==a&&s.len==0;){if(s.done)break e;let f=Math.min(s.len,a-h);y(i,f,-1);let u=s.ins==-1?-1:s.off==0?s.ins:0;y(t,f,u),u>0&&R(n,t,s.text),s.forward(f),h+=f}let o=e[r++];for(;h<o;){if(s.done)break e;let f=Math.min(s.len,o-h);y(t,f,-1),y(i,f,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(f),h+=f}}return{changes:new k(t,n),filtered:O.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let n=this.sections[t],i=this.sections[t+1];i<0?e.push(n):i==0?e.push([n]):e.push([n].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,n){let i=[],s=[],r=0,h=null;function a(f=!1){if(!f&&!i.length)return;r<t&&y(i,t-r,-1);let u=new k(i,s);h=h?h.compose(u.map(h)):u,i=[],s=[],r=0}function o(f){if(Array.isArray(f))for(let u of f)o(u);else if(f instanceof k){if(f.length!=t)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`);a(),h=h?h.compose(f.map(h)):f}else{let{from:u,to:d=u,insert:c}=f;if(u>d||u<0||d>t)throw new RangeError(`Invalid change range ${u} to ${d} (in doc of length ${t})`);let p=c?typeof c=="string"?v.of(c.split(n||re)):c:v.empty,b=p.length;if(u==d&&b==0)return;u<r&&a(),u>r&&y(i,u-r,-1),y(i,d-u,b),R(s,i,p),r=d}}return o(e),a(!h),h}static empty(e){return new k(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],n=[];for(let i=0;i<e.length;i++){let s=e[i];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((r,h)=>h&&typeof r!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;n.length<i;)n.push(v.empty);n[i]=v.of(s.slice(1)),t.push(s[0],n[i].length)}}}return new k(t,n)}static createSet(e,t){return new k(e,t)}}function y(l,e,t,n=!1){if(e==0&&t<=0)return;let i=l.length-2;i>=0&&t<=0&&t==l[i+1]?l[i]+=e:e==0&&l[i]==0?l[i+1]+=t:n?(l[i]+=e,l[i+1]+=t):l.push(e,t)}function R(l,e,t){if(t.length==0)return;let n=e.length-2>>1;if(n<l.length)l[l.length-1]=l[l.length-1].append(t);else{for(;l.length<n;)l.push(v.empty);l.push(t)}}function le(l,e,t){let n=l.inserted;for(let i=0,s=0,r=0;r<l.sections.length;){let h=l.sections[r++],a=l.sections[r++];if(a<0)i+=h,s+=h;else{let o=i,f=s,u=v.empty;for(;o+=h,f+=a,a&&n&&(u=u.append(n[r-2>>1])),!(t||r==l.sections.length||l.sections[r+1]<0);)h=l.sections[r++],a=l.sections[r++];e(i,o,s,f,u),i=o,s=f}}}function he(l,e,t,n=!1){let i=[],s=n?[]:null,r=new z(l),h=new z(e);for(let a=-1;;)if(r.ins==-1&&h.ins==-1){let o=Math.min(r.len,h.len);y(i,o,-1),r.forward(o),h.forward(o)}else if(h.ins>=0&&(r.ins<0||a==r.i||r.off==0&&(h.len<r.len||h.len==r.len&&!t))){let o=h.len;for(y(i,h.ins,-1);o;){let f=Math.min(r.len,o);r.ins>=0&&a<r.i&&r.len<=f&&(y(i,0,r.ins),s&&R(s,i,r.text),a=r.i),r.forward(f),o-=f}h.next()}else if(r.ins>=0){let o=0,f=r.len;for(;f;)if(h.ins==-1){let u=Math.min(f,h.len);o+=u,f-=u,h.forward(u)}else if(h.ins==0&&h.len<f)f-=h.len,h.next();else break;y(i,o,a<r.i?r.ins:0),s&&a<r.i&&R(s,i,r.text),a=r.i,r.forward(r.len-f)}else{if(r.done&&h.done)return s?k.createSet(i,s):O.create(i);throw new Error("Mismatched change set lengths")}}function Ee(l,e,t=!1){let n=[],i=t?[]:null,s=new z(l),r=new z(e);for(let h=!1;;){if(s.done&&r.done)return i?k.createSet(n,i):O.create(n);if(s.ins==0)y(n,s.len,0,h),s.next();else if(r.len==0&&!r.done)y(n,0,r.ins,h),i&&R(i,n,r.text),r.next();else{if(s.done||r.done)throw new Error("Mismatched change set lengths");{let a=Math.min(s.len2,r.len),o=n.length;if(s.ins==-1){let f=r.ins==-1?-1:r.off?0:r.ins;y(n,a,f,h),i&&f&&R(i,n,r.text)}else r.ins==-1?(y(n,s.off?0:s.len,a,h),i&&R(i,n,s.textBit(a))):(y(n,s.off?0:s.len,r.off?0:r.ins,h),i&&!r.off&&R(i,n,r.text));h=(s.ins>a||r.ins>=0&&r.len>a)&&(h||n.length>o),s.forward2(a),r.forward(a)}}}}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 this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?v.empty:e[t]}textBit(e){let{inserted:t}=this.set,n=this.i-2>>1;return n>=t.length&&!e?v.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)}}class T{constructor(e,t,n){this.from=e,this.to=t,this.flags=n}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let n,i;return this.empty?n=i=e.mapPos(this.from,t):(n=e.mapPos(this.from,1),i=e.mapPos(this.to,-1)),n==this.from&&i==this.to?this:new T(n,i,this.flags)}extend(e,t=e){if(e<=this.anchor&&t>=this.anchor)return g.range(e,t);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return g.range(this.anchor,n)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return g.range(e.anchor,e.head)}static create(e,t,n){return new T(e,t,n)}}class g{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:g.create(this.ranges.map(n=>n.map(e,t)),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 g([this.main],0)}addRange(e,t=!0){return g.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let n=this.ranges.slice();return n[t]=e,g.create(n,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new g(e.ranges.map(t=>T.fromJSON(t)),e.main)}static single(e,t=e){return new g([g.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let n=0,i=0;i<e.length;i++){let s=e[i];if(s.empty?s.from<=n:s.from<n)return g.normalized(e.slice(),t);n=s.to}return new g(e,t)}static cursor(e,t=0,n,i){return T.create(e,e,(t==0?0:t<0?8:16)|(n==null?7:Math.min(6,n))|(i??16777215)<<6)}static range(e,t,n,i){let s=(n??16777215)<<6|(i==null?7:Math.min(6,i));return t<e?T.create(t,e,48|s):T.create(e,t,(t>e?8:0)|s)}static normalized(e,t=0){let n=e[t];e.sort((i,s)=>i.from-s.from),t=e.indexOf(n);for(let i=1;i<e.length;i++){let s=e[i],r=e[i-1];if(s.empty?s.from<=r.to:s.from<r.to){let h=r.from,a=Math.max(s.to,r.to);i<=t&&t--,e.splice(--i,2,s.anchor>s.head?g.range(a,h):g.range(h,a))}}return new g(e,t)}}function Ce(l,e){for(let t of l.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let ae=0;class A{constructor(e,t,n,i,s){this.combine=e,this.compareInput=t,this.compare=n,this.isStatic=i,this.id=ae++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new A(e.combine||(t=>t),e.compareInput||((t,n)=>t===n),e.compare||(e.combine?(t,n)=>t===n:oe),!!e.static,e.enables)}of(e){return new Y([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Y(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Y(e,this,2,t)}from(e,t){return t||(t=n=>n),this.compute([e],n=>t(n.field(e)))}}function oe(l,e){return l==e||l.length==e.length&&l.every((t,n)=>t===e[n])}class Y{constructor(e,t,n,i){this.dependencies=e,this.facet=t,this.type=n,this.value=i,this.id=ae++}dynamicSlot(e){var t;let n=this.value,i=this.facet.compareInput,s=this.id,r=e[s]>>1,h=this.type==2,a=!1,o=!1,f=[];for(let u of this.dependencies)u=="doc"?a=!0:u=="selection"?o=!0:((t=e[u.id])!==null&&t!==void 0?t:1)&1||f.push(e[u.id]);return{create(u){return u.values[r]=n(u),1},update(u,d){if(a&&d.docChanged||o&&(d.docChanged||d.selection)||fe(u,f)){let c=n(u);if(h?!Me(c,u.values[r],i):!i(c,u.values[r]))return u.values[r]=c,1}return 0},reconfigure:(u,d)=>{let c,p=d.config.address[s];if(p!=null){let b=_(d,p);if(this.dependencies.every(x=>x instanceof A?d.facet(x)===u.facet(x):x instanceof F?d.field(x,!1)==u.field(x,!1):!0)||(h?Me(c=n(u),b,i):i(c=n(u),b)))return u.values[r]=b,0}else c=n(u);return u.values[r]=c,1}}}}function Me(l,e,t){if(l.length!=e.length)return!1;for(let n=0;n<l.length;n++)if(!t(l[n],e[n]))return!1;return!0}function fe(l,e){let t=!1;for(let n of e)U(l,n)&1&&(t=!0);return t}function Xe(l,e,t){let n=t.map(a=>l[a.id]),i=t.map(a=>a.type),s=n.filter(a=>!(a&1)),r=l[e.id]>>1;function h(a){let o=[];for(let f=0;f<n.length;f++){let u=_(a,n[f]);if(i[f]==2)for(let d of u)o.push(d);else o.push(u)}return e.combine(o)}return{create(a){for(let o of n)U(a,o);return a.values[r]=h(a),1},update(a,o){if(!fe(a,s))return 0;let f=h(a);return e.compare(f,a.values[r])?0:(a.values[r]=f,1)},reconfigure(a,o){let f=fe(a,n),u=o.config.facets[e.id],d=o.facet(e);if(u&&!f&&oe(t,u))return a.values[r]=d,0;let c=h(a);return e.compare(c,d)?(a.values[r]=d,0):(a.values[r]=c,1)}}}const Re=A.define({static:!0});class F{constructor(e,t,n,i,s){this.id=e,this.createF=t,this.updateF=n,this.compareF=i,this.spec=s,this.provides=void 0}static define(e){let t=new F(ae++,e.create,e.update,e.compare||((n,i)=>n===i),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Re).find(n=>n.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:n=>(n.values[t]=this.create(n),1),update:(n,i)=>{let s=n.values[t],r=this.updateF(s,i);return this.compareF(s,r)?0:(n.values[t]=r,1)},reconfigure:(n,i)=>i.config.address[this.id]!=null?(n.values[t]=i.field(this),0):(n.values[t]=this.create(n),1)}}init(e){return[this,Re.of({field:this,create:e})]}get extension(){return this}}const B={lowest:4,low:3,default:2,high:1,highest:0};function W(l){return e=>new Te(e,l)}const Ye={highest:W(B.highest),high:W(B.high),default:W(B.default),low:W(B.low),lowest:W(B.lowest)};class Te{constructor(e,t){this.inner=e,this.prec=t}}class H{of(e){return new ue(this,e)}reconfigure(e){return H.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class ue{constructor(e,t){this.compartment=e,this.inner=t}}class ne{constructor(e,t,n,i,s,r){for(this.base=e,this.compartments=t,this.dynamicSlots=n,this.address=i,this.staticValues=s,this.facets=r,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(e,t,n){let i=[],s=Object.create(null),r=new Map;for(let d of _e(e,t,r))d instanceof F?i.push(d):(s[d.facet.id]||(s[d.facet.id]=[])).push(d);let h=Object.create(null),a=[],o=[];for(let d of i)h[d.id]=o.length<<1,o.push(c=>d.slot(c));let f=n?.config.facets;for(let d in s){let c=s[d],p=c[0].facet,b=f&&f[d]||[];if(c.every(x=>x.type==0))if(h[p.id]=a.length<<1|1,oe(b,c))a.push(n.facet(p));else{let x=p.combine(c.map(ie=>ie.value));a.push(n&&p.compare(x,n.facet(p))?n.facet(p):x)}else{for(let x of c)x.type==0?(h[x.id]=a.length<<1|1,a.push(x.value)):(h[x.id]=o.length<<1,o.push(ie=>x.dynamicSlot(ie)));h[p.id]=o.length<<1,o.push(x=>Xe(x,p,c))}}let u=o.map(d=>d(h));return new ne(e,r,u,h,a,s)}}function _e(l,e,t){let n=[[],[],[],[],[]],i=new Map;function s(r,h){let a=i.get(r);if(a!=null){if(a<=h)return;let o=n[a].indexOf(r);o>-1&&n[a].splice(o,1),r instanceof ue&&t.delete(r.compartment)}if(i.set(r,h),Array.isArray(r))for(let o of r)s(o,h);else if(r instanceof ue){if(t.has(r.compartment))throw new RangeError("Duplicate use of compartment in extensions");let o=e.get(r.compartment)||r.inner;t.set(r.compartment,o),s(o,h)}else if(r instanceof Te)s(r.inner,r.prec);else if(r instanceof F)n[h].push(r),r.provides&&s(r.provides,h);else if(r instanceof Y)n[h].push(r),r.facet.extensions&&s(r.facet.extensions,B.default);else{let o=r.extension;if(!o)throw new Error(`Unrecognized extension value in extension set (${r}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(o,h)}}return s(l,B.default),n.reduce((r,h)=>r.concat(h))}function U(l,e){if(e&1)return 2;let t=e>>1,n=l.status[t];if(n==4)throw new Error("Cyclic dependency between fields and/or facets");if(n&2)return n;l.status[t]=4;let i=l.computeSlot(l,l.config.dynamicSlots[t]);return l.status[t]=2|i}function _(l,e){return e&1?l.config.staticValues[e>>1]:l.values[e>>1]}const Be=A.define(),ce=A.define({combine:l=>l.some(e=>e),static:!0}),Fe=A.define({combine:l=>l.length?l[0]:void 0,static:!0}),Je=A.define(),Le=A.define(),Ve=A.define(),Ne=A.define({combine:l=>l.length?l[0]:!1});class V{constructor(e,t){this.type=e,this.value=t}static define(){return new De}}class De{of(e){return new V(this,e)}}class qe{constructor(e){this.map=e}of(e){return new S(this,e)}}class S{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new S(this.type,t)}is(e){return this.type==e}static define(e={}){return new qe(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let n=[];for(let i of e){let s=i.map(t);s&&n.push(s)}return n}}S.reconfigure=S.define(),S.appendConfig=S.define();class I{constructor(e,t,n,i,s,r){this.startState=e,this.changes=t,this.selection=n,this.effects=i,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,n&&Ce(n,t.newLength),s.some(h=>h.type==I.time)||(this.annotations=s.concat(I.time.of(Date.now())))}static create(e,t,n,i,s,r){return new I(e,t,n,i,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(I.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}I.time=V.define(),I.userEvent=V.define(),I.addToHistory=V.define(),I.remote=V.define();function et(l,e){let t=[];for(let n=0,i=0;;){let s,r;if(n<l.length&&(i==e.length||e[i]>=l[n]))s=l[n++],r=l[n++];else if(i<e.length)s=e[i++],r=e[i++];else return t;!t.length||t[t.length-1]<s?t.push(s,r):t[t.length-1]<r&&(t[t.length-1]=r)}}function $e(l,e,t){var n;let i,s,r;return t?(i=e.changes,s=k.empty(e.changes.length),r=l.changes.compose(e.changes)):(i=e.changes.map(l.changes),s=l.changes.mapDesc(e.changes,!0),r=l.changes.compose(i)),{changes:r,selection:e.selection?e.selection.map(s):(n=l.selection)===null||n===void 0?void 0:n.map(i),effects:S.mapEffects(l.effects,i).concat(S.mapEffects(e.effects,s)),annotations:l.annotations.length?l.annotations.concat(e.annotations):e.annotations,scrollIntoView:l.scrollIntoView||e.scrollIntoView}}function de(l,e,t){let n=e.selection,i=N(e.annotations);return e.userEvent&&(i=i.concat(I.userEvent.of(e.userEvent))),{changes:e.changes instanceof k?e.changes:k.of(e.changes||[],t,l.facet(Fe)),selection:n&&(n instanceof g?n:g.single(n.anchor,n.head)),effects:N(e.effects),annotations:i,scrollIntoView:!!e.scrollIntoView}}function ze(l,e,t){let n=de(l,e.length?e[0]:{},l.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let r=!!e[s].sequential;n=$e(n,de(l,e[s],r?n.changes.newLength:l.doc.length),r)}let i=I.create(l,n.changes,n.selection,n.effects,n.annotations,n.scrollIntoView);return nt(t?tt(i):i)}function tt(l){let e=l.startState,t=!0;for(let i of e.facet(Je)){let s=i(l);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:et(t,s))}if(t!==!0){let i,s;if(t===!1)s=l.changes.invertedDesc,i=k.empty(e.doc.length);else{let r=l.changes.filter(t);i=r.changes,s=r.filtered.mapDesc(r.changes).invertedDesc}l=I.create(e,i,l.selection&&l.selection.map(s),S.mapEffects(l.effects,s),l.annotations,l.scrollIntoView)}let n=e.facet(Le);for(let i=n.length-1;i>=0;i--){let s=n[i](l);s instanceof I?l=s:Array.isArray(s)&&s.length==1&&s[0]instanceof I?l=s[0]:l=ze(e,N(s),!1)}return l}function nt(l){let e=l.startState,t=e.facet(Ve),n=l;for(let i=t.length-1;i>=0;i--){let s=t[i](l);s&&Object.keys(s).length&&(n=$e(n,de(e,s,l.changes.newLength),!0))}return n==l?l:I.create(e,l.changes,l.selection,n.effects,n.annotations,n.scrollIntoView)}const it=[];function N(l){return l==null?it:Array.isArray(l)?l:[l]}var M=function(l){return l[l.Word=0]="Word",l[l.Space=1]="Space",l[l.Other=2]="Other",l}(M||(M={}));const st=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let ge;try{ge=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function rt(l){if(ge)return ge.test(l);for(let e=0;e<l.length;e++){let t=l[e];if(/\w/.test(t)||t>"\x80"&&(t.toUpperCase()!=t.toLowerCase()||st.test(t)))return!0}return!1}function lt(l){return e=>{if(!/\S/.test(e))return M.Space;if(rt(e))return M.Word;for(let t=0;t<l.length;t++)if(e.indexOf(l[t])>-1)return M.Word;return M.Other}}class w{constructor(e,t,n,i,s,r){this.config=e,this.doc=t,this.selection=n,this.values=i,this.status=e.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let h=0;h<this.config.dynamicSlots.length;h++)U(this,h<<1);this.computeSlot=null}field(e,t=!0){let n=this.config.address[e.id];if(n==null){if(t)throw new RangeError("Field is not present in this state");return}return U(this,n),_(this,n)}update(...e){return ze(this,e,!0)}applyTransaction(e){let t=this.config,{base:n,compartments:i}=t;for(let h of e.effects)h.is(H.reconfigure)?(t&&(i=new Map,t.compartments.forEach((a,o)=>i.set(o,a)),t=null),i.set(h.value.compartment,h.value.extension)):h.is(S.reconfigure)?(t=null,n=h.value):h.is(S.appendConfig)&&(t=null,n=N(n).concat(h.value));let s;t?s=e.startState.values.slice():(t=ne.resolve(n,i,this),s=new w(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,o)=>o.reconfigure(a,this),null).values);let r=e.startState.facet(ce)?e.newSelection:e.newSelection.asSingle();new w(t,e.newDoc,r,s,(h,a)=>a.update(h,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:g.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,n=e(t.ranges[0]),i=this.changes(n.changes),s=[n.range],r=N(n.effects);for(let h=1;h<t.ranges.length;h++){let a=e(t.ranges[h]),o=this.changes(a.changes),f=o.map(i);for(let d=0;d<h;d++)s[d]=s[d].map(f);let u=i.mapDesc(o,!0);s.push(a.range.map(u)),i=i.compose(f),r=S.mapEffects(r,f).concat(S.mapEffects(N(a.effects),u))}return{changes:i,selection:g.create(s,t.mainIndex),effects:r}}changes(e=[]){return e instanceof k?e:k.of(e,this.doc.length,this.facet(w.lineSeparator))}toText(e){return v.of(e.split(this.facet(w.lineSeparator)||re))}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:(U(this,t),_(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let n in e){let i=e[n];i instanceof F&&this.config.address[i.id]!=null&&(t[n]=i.spec.toJSON(this.field(e[n]),this))}return t}static fromJSON(e,t={},n){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let i=[];if(n){for(let s in n)if(Object.prototype.hasOwnProperty.call(e,s)){let r=n[s],h=e[s];i.push(r.init(a=>r.spec.fromJSON(h,a)))}}return w.create({doc:e.doc,selection:g.fromJSON(e.selection),extensions:t.extensions?i.concat([t.extensions]):i})}static create(e={}){let t=ne.resolve(e.extensions||[],new Map),n=e.doc instanceof v?e.doc:v.of((e.doc||"").split(t.staticFacet(w.lineSeparator)||re)),i=e.selection?e.selection instanceof g?e.selection:g.single(e.selection.anchor,e.selection.head):g.single(0);return Ce(i,n.length),t.staticFacet(ce)||(i=i.asSingle()),new w(t,n,i,t.dynamicSlots.map(()=>null),(s,r)=>r.create(s),null)}get tabSize(){return this.facet(w.tabSize)}get lineBreak(){return this.facet(w.lineSeparator)||`
`}get readOnly(){return this.facet(Ne)}phrase(e,...t){for(let n of this.facet(w.phrases))if(Object.prototype.hasOwnProperty.call(n,e)){e=n[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(n,i)=>{if(i=="$")return"$";let s=+(i||1);return!s||s>t.length?n:t[s-1]})),e}languageDataAt(e,t,n=-1){let i=[];for(let s of this.facet(Be))for(let r of s(this,t,n))Object.prototype.hasOwnProperty.call(r,e)&&i.push(r[e]);return i}charCategorizer(e){return lt(this.languageDataAt("wordChars",e).join(""))}wordAt(e){let{text:t,from:n,length:i}=this.doc.lineAt(e),s=this.charCategorizer(e),r=e-n,h=e-n;for(;r>0;){let a=$(t,r,!1);if(s(t.slice(a,r))!=M.Word)break;r=a}for(;h<i;){let a=$(t,h);if(s(t.slice(h,a))!=M.Word)break;h=a}return r==h?null:g.range(r+n,h+n)}}w.allowMultipleSelections=ce,w.tabSize=A.define({combine:l=>l.length?l[0]:4}),w.lineSeparator=Fe,w.readOnly=Ne,w.phrases=A.define({compare(l,e){let t=Object.keys(l),n=Object.keys(e);return t.length==n.length&&t.every(i=>l[i]==e[i])}}),w.languageData=Be,w.changeFilter=Je,w.transactionFilter=Le,w.transactionExtender=Ve,H.reconfigure=S.define();function ht(l,e,t={}){let n={};for(let i of l)for(let s of Object.keys(i)){let r=i[s],h=n[s];if(h===void 0)n[s]=r;else if(!(h===r||r===void 0))if(Object.hasOwnProperty.call(t,s))n[s]=t[s](h,r);else throw new Error("Config merge conflict for field "+s)}for(let i in e)n[i]===void 0&&(n[i]=e[i]);return n}class j{eq(e){return this==e}range(e,t=e){return D.create(e,t,this)}}j.prototype.startSide=j.prototype.endSide=0,j.prototype.point=!1,j.prototype.mapMode=C.TrackDel;class D{constructor(e,t,n){this.from=e,this.to=t,this.value=n}static create(e,t,n){return new D(e,t,n)}}function pe(l,e){return l.from-e.from||l.value.startSide-e.value.startSide}class ve{constructor(e,t,n,i){this.from=e,this.to=t,this.value=n,this.maxPoint=i}get length(){return this.to[this.to.length-1]}findIndex(e,t,n,i=0){let s=n?this.to:this.from;for(let r=i,h=s.length;;){if(r==h)return r;let a=r+h>>1,o=s[a]-e||(n?this.value[a].endSide:this.value[a].startSide)-t;if(a==r)return o>=0?r:h;o>=0?h=a:r=a+1}}between(e,t,n,i){for(let s=this.findIndex(t,-1e9,!0),r=this.findIndex(n,1e9,!1,s);s<r;s++)if(i(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t){let n=[],i=[],s=[],r=-1,h=-1;for(let a=0;a<this.value.length;a++){let o=this.value[a],f=this.from[a]+e,u=this.to[a]+e,d,c;if(f==u){let p=t.mapPos(f,o.startSide,o.mapMode);if(p==null||(d=c=p,o.startSide!=o.endSide&&(c=t.mapPos(f,o.endSide),c<d)))continue}else if(d=t.mapPos(f,o.startSide),c=t.mapPos(u,o.endSide),d>c||d==c&&o.startSide>0&&o.endSide<=0)continue;(c-d||o.endSide-o.startSide)<0||(r<0&&(r=d),o.point&&(h=Math.max(h,c-d)),n.push(o),i.push(d-r),s.push(c-r))}return{mapped:n.length?new ve(i,s,n,h):null,pos:r}}}class P{constructor(e,t,n,i){this.chunkPos=e,this.chunk=t,this.nextLayer=n,this.maxPoint=i}static create(e,t,n,i){return new P(e,t,n,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(e){let{add:t=[],sort:n=!1,filterFrom:i=0,filterTo:s=this.length}=e,r=e.filter;if(t.length==0&&!r)return this;if(n&&(t=t.slice().sort(pe)),this.isEmpty)return t.length?P.of(t):this;let h=new Ue(this,null,-1).goto(0),a=0,o=[],f=new Z;for(;h.value||a<t.length;)if(a<t.length&&(h.from-t[a].from||h.startSide-t[a].value.startSide)>=0){let u=t[a++];f.addInner(u.from,u.to,u.value)||o.push(u)}else h.rangeIndex==1&&h.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(h.chunkIndex)<t[a].from)&&(!r||i>this.chunkEnd(h.chunkIndex)||s<this.chunkPos[h.chunkIndex])&&f.addChunk(this.chunkPos[h.chunkIndex],this.chunk[h.chunkIndex])?h.nextChunk():((!r||i>h.to||s<h.from||r(h.from,h.to,h.value))&&(f.addInner(h.from,h.to,h.value)||o.push(D.create(h.from,h.to,h.value))),h.next());return f.finishInner(this.nextLayer.isEmpty&&!o.length?P.empty:this.nextLayer.update({add:o,filter:r,filterFrom:i,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],n=[],i=-1;for(let r=0;r<this.chunk.length;r++){let h=this.chunkPos[r],a=this.chunk[r],o=e.touchesRange(h,h+a.length);if(o===!1)i=Math.max(i,a.maxPoint),t.push(a),n.push(e.mapPos(h));else if(o===!0){let{mapped:f,pos:u}=a.map(h,e);f&&(i=Math.max(i,f.maxPoint),t.push(f),n.push(u))}}let s=this.nextLayer.map(e);return t.length==0?s:new P(n,t,s||P.empty,i)}between(e,t,n){if(!this.isEmpty){for(let i=0;i<this.chunk.length;i++){let s=this.chunkPos[i],r=this.chunk[i];if(t>=s&&e<=s+r.length&&r.between(s,e-s,t-s,n)===!1)return}this.nextLayer.between(e,t,n)}}iter(e=0){return K.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return K.from(e).goto(t)}static compare(e,t,n,i,s=-1){let r=e.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=s),h=t.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=s),a=We(r,h,n),o=new G(r,a,s),f=new G(h,a,s);n.iterGaps((u,d,c)=>je(o,u,f,d,c,i)),n.empty&&n.length==0&&je(o,0,f,0,0,i)}static eq(e,t,n=0,i){i==null&&(i=999999999);let s=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0),r=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0);if(s.length!=r.length)return!1;if(!s.length)return!0;let h=We(s,r),a=new G(s,h,0).goto(n),o=new G(r,h,0).goto(n);for(;;){if(a.to!=o.to||!we(a.active,o.active)||a.point&&(!o.point||!a.point.eq(o.point)))return!1;if(a.to>i)return!0;a.next(),o.next()}}static spans(e,t,n,i,s=-1){let r=new G(e,null,s).goto(t),h=t,a=r.openStart;for(;;){let o=Math.min(r.to,n);if(r.point){let f=r.activeForPoint(r.to),u=r.pointFrom<t?f.length+1:r.point.startSide<0?f.length:Math.min(f.length,a);i.point(h,o,r.point,f,u,r.pointRank),a=Math.min(r.openEnd(o),f.length)}else o>h&&(i.span(h,o,r.active,a),a=r.openEnd(o));if(r.to>n)return a+(r.point&&r.to>n?1:0);h=r.to,r.next()}}static of(e,t=!1){let n=new Z;for(let i of e instanceof D?[e]:t?at(e):e)n.add(i.from,i.to,i.value);return n.finish()}static join(e){if(!e.length)return P.empty;let t=e[e.length-1];for(let n=e.length-2;n>=0;n--)for(let i=e[n];i!=P.empty;i=i.nextLayer)t=new P(i.chunkPos,i.chunk,t,Math.max(i.maxPoint,t.maxPoint));return t}}P.empty=new P([],[],null,-1);function at(l){if(l.length>1)for(let e=l[0],t=1;t<l.length;t++){let n=l[t];if(pe(e,n)>0)return l.slice().sort(pe);e=n}return l}P.empty.nextLayer=P.empty;class Z{finishChunk(e){this.chunks.push(new ve(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.addInner(e,t,n)||(this.nextLayer||(this.nextLayer=new Z)).add(e,t,n)}addInner(e,t,n){let i=e-this.lastTo||n.startSide-this.last.endSide;if(i<=0&&(e-this.lastFrom||n.startSide-this.last.startSide)<0)throw new 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(P.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=P.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function We(l,e,t){let n=new Map;for(let s of l)for(let r=0;r<s.chunk.length;r++)s.chunk[r].maxPoint<=0&&n.set(s.chunk[r],s.chunkPos[r]);let i=new Set;for(let s of e)for(let r=0;r<s.chunk.length;r++){let h=n.get(s.chunk[r]);h!=null&&(t?t.mapPos(h):h)==s.chunkPos[r]&&!t?.touchesRange(h,h+s.chunk[r].length)&&i.add(s.chunk[r])}return i}class Ue{constructor(e,t,n,i=0){this.layer=e,this.skip=t,this.minPoint=n,this.rank=i}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 i=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(i)||this.layer.chunkEnd(this.chunkIndex)<e||i.maxPoint<this.minPoint))break;this.chunkIndex++,n=!1}if(this.chunkIndex<this.layer.chunk.length){let i=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!n||this.rangeIndex<i)&&this.setRangeIndex(i)}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}}class K{constructor(e){this.heap=e}static from(e,t=null,n=-1){let i=[];for(let s=0;s<e.length;s++)for(let r=e[s];!r.isEmpty;r=r.nextLayer)r.maxPoint>=n&&i.push(new Ue(r,t,n,s));return i.length==1?i[0]:new K(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 n=this.heap.length>>1;n>=0;n--)me(this.heap,n);return this.next(),this}forward(e,t){for(let n of this.heap)n.forward(e,t);for(let n=this.heap.length>>1;n>=0;n--)me(this.heap,n);(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(),me(this.heap,0)}}}function me(l,e){for(let t=l[e];;){let n=(e<<1)+1;if(n>=l.length)break;let i=l[n];if(n+1<l.length&&i.compare(l[n+1])>=0&&(i=l[n+1],n++),t.compare(i)<0)break;l[n]=t,l[e]=i,e=n}}class G{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=K.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){ee(this.active,e),ee(this.activeTo,e),ee(this.activeRank,e),this.minActive=Ge(this.active,this.activeTo)}addActive(e){let t=0,{value:n,to:i,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||i-this.activeTo[t])>0;)t++;te(this.active,t,n),te(this.activeTo,t,i),te(this.activeRank,t,s),e&&te(e,t,this.cursor.from),this.minActive=Ge(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let n=this.openStart<0?[]:null;for(;;){let i=this.minActive;if(i>-1&&(this.activeTo[i]-this.cursor.from||this.active[i].endSide-this.cursor.startSide)<0){if(this.activeTo[i]>e){this.to=this.activeTo[i],this.endSide=this.active[i].endSide;break}this.removeActive(i),n&&ee(n,i)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let s=this.cursor.value;if(!s.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=s,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=s.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(n){this.openStart=0;for(let i=n.length-1;i>=0&&n[i]<e;i--)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 je(l,e,t,n,i,s){l.goto(e),t.goto(n);let r=n+i,h=n,a=n-e;for(;;){let o=l.to+a-t.to||l.endSide-t.endSide,f=o<0?l.to+a:t.to,u=Math.min(f,r);if(l.point||t.point?l.point&&t.point&&(l.point==t.point||l.point.eq(t.point))&&we(l.activeForPoint(l.to),t.activeForPoint(t.to))||s.comparePoint(h,u,l.point,t.point):u>h&&!we(l.active,t.active)&&s.compareRange(h,u,l.active,t.active),f>r)break;h=f,o<=0&&l.next(),o>=0&&t.next()}}function we(l,e){if(l.length!=e.length)return!1;for(let t=0;t<l.length;t++)if(l[t]!=e[t]&&!l[t].eq(e[t]))return!1;return!0}function ee(l,e){for(let t=e,n=l.length-1;t<n;t++)l[t]=l[t+1];l.pop()}function te(l,e,t){for(let n=l.length-1;n>=e;n--)l[n+1]=l[n];l[e]=t}function Ge(l,e){let t=-1,n=1e9;for(let i=0;i<e.length;i++)(e[i]-n||l[i].endSide-l[t].endSide)<0&&(t=i,n=e[i]);return t}function ot(l,e,t=l.length){let n=0;for(let i=0;i<t;)l.charCodeAt(i)==9?(n+=e-n%e,i++):(n++,i=$(l,i));return n}function ft(l,e,t,n){for(let i=0,s=0;;){if(s>=e)return i;if(i==l.length)break;s+=l.charCodeAt(i)==9?t-s%t:1,i=$(l,i)}return n===!0?-1:l.length}export{V as Annotation,De as AnnotationType,O as ChangeDesc,k as ChangeSet,M as CharCategory,H as Compartment,g as EditorSelection,w as EditorState,A as Facet,Se as Line,C as MapMode,Ye as Prec,D as Range,P as RangeSet,Z as RangeSetBuilder,j as RangeValue,T as SelectionRange,S as StateEffect,qe as StateEffectType,F as StateField,v as Text,I as Transaction,X as codePointAt,se as codePointSize,ht as combineConfig,ot as countColumn,$ as findClusterBreak,ft as findColumn,Qe as fromCodePoint};