class t{lineAt(t){if(t<0||t>this.length)throw new RangeError(`Invalid position ${t} in document of length ${this.length}`);return this.lineInner(t,!1,1,0)}line(t){if(t<1||t>this.lines)throw new RangeError(`Invalid line number ${t} in ${this.lines}-line document`);return this.lineInner(t,!0,1,0)}replace(t,e,i){[t,e]=a(this,t,e);let s=[];return this.decompose(0,t,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(e,this.length,s,1),n.from(s,this.length-(e-t)+i.length)}append(t){return this.replace(this.length,this.length,t)}slice(t,e=this.length){[t,e]=a(this,t,e);let i=[];return this.decompose(t,e,i,0),n.from(i,e-t)}eq(t){if(t==this)return!0;if(t.length!=this.length||t.lines!=this.lines)return!1;let e=this.scanIdentical(t,1),n=this.length-this.scanIdentical(t,-1),i=new r(this),s=new r(t);for(let t=e,r=e;;){if(i.next(t),s.next(t),t=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(r+=i.value.length,i.done||r>=n)return!0}}iter(t=1){return new r(this,t)}iterRange(t,e=this.length){return new h(this,t,e)}iterLines(t,e){let n;if(null==t)n=this.iter();else{null==e&&(e=this.lines+1);let i=this.line(t).from;n=this.iterRange(i,Math.max(i,e==this.lines+1?this.length:e<=1?0:this.line(e-1).to))}return new o(n)}toString(){return this.sliceString(0)}toJSON(){let t=[];return this.flatten(t),t}constructor(){}static of(i){if(0==i.length)throw new RangeError("A document must have at least one line");return 1!=i.length||i[0]?i.length<=32?new e(i):n.from(e.split(i,[])):t.empty}}class e extends t{constructor(t,e=function(t){let e=-1;for(let n of t)e+=n.length+1;return e}(t)){super(),this.text=t,this.length=e}get lines(){return this.text.length}get children(){return null}lineInner(t,e,n,i){for(let s=0;;s++){let r=this.text[s],h=i+r.length;if((e?n:h)>=t)return new l(i,h,n,r);i=h+1,n++}}decompose(t,n,r,h){let o=t<=0&&n>=this.length?this:new e(s(this.text,t,n),Math.min(n,this.length)-Math.max(0,t));if(1&h){let t=r.pop(),n=i(o.text,t.text.slice(),0,o.length);if(n.length<=32)r.push(new e(n,t.length+o.length));else{let t=n.length>>1;r.push(new e(n.slice(0,t)),new e(n.slice(t)))}}else r.push(o)}replace(t,r,h){if(!(h instanceof e))return super.replace(t,r,h);[t,r]=a(this,t,r);let o=i(this.text,i(h.text,s(this.text,0,t)),r),l=this.length+h.length-(r-t);return o.length<=32?new e(o,l):n.from(e.split(o,[]),l)}sliceString(t,e=this.length,n="\n"){[t,e]=a(this,t,e);let i="";for(let s=0,r=0;s<=e&&rt&&r&&(i+=n),ts&&(i+=h.slice(Math.max(0,t-s),e-s)),s=o+1}return i}flatten(t){for(let e of this.text)t.push(e)}scanIdentical(){return 0}static split(t,n){let i=[],s=-1;for(let r of t)i.push(r),s+=r.length+1,32==i.length&&(n.push(new e(i,s)),i=[],s=-1);return s>-1&&n.push(new e(i,s)),n}}class n extends t{constructor(t,e){super(),this.children=t,this.length=e,this.lines=0;for(let e of t)this.lines+=e.lines}lineInner(t,e,n,i){for(let s=0;;s++){let r=this.children[s],h=i+r.length,o=n+r.lines-1;if((e?o:h)>=t)return r.lineInner(t,e,n,i);i=h+1,n=o+1}}decompose(t,e,n,i){for(let s=0,r=0;r<=e&&s=r){let s=i&((r<=t?1:0)|(o>=e?2:0));r>=t&&o<=e&&!s?n.push(h):h.decompose(t-r,e-r,n,s)}r=o+1}}replace(t,e,i){if([t,e]=a(this,t,e),i.lines=r&&e<=o){let l=h.replace(t-r,e-r,i),a=this.lines-h.lines+l.lines;if(l.lines>4&&l.lines>a>>6){let r=this.children.slice();return r[s]=l,new n(r,this.length-(e-t)+i.length)}return super.replace(r,o,l)}r=o+1}return super.replace(t,e,i)}sliceString(t,e=this.length,n="\n"){[t,e]=a(this,t,e);let i="";for(let s=0,r=0;st&&s&&(i+=n),tr&&(i+=h.sliceString(t-r,e-r,n)),r=o+1}return i}flatten(t){for(let e of this.children)e.flatten(t)}scanIdentical(t,e){if(!(t instanceof n))return 0;let i=0,[s,r,h,o]=e>0?[0,0,this.children.length,t.children.length]:[this.children.length-1,t.children.length-1,-1,-1];for(;;s+=e,r+=e){if(s==h||r==o)return i;let n=this.children[s],l=t.children[r];if(n!=l)return i+n.scanIdentical(l,e);i+=n.length+1}}static from(t,i=t.reduce(((t,e)=>t+e.length+1),-1)){let s=0;for(let e of t)s+=e.lines;if(s<32){let n=[];for(let e of t)e.flatten(n);return new e(n,i)}let r=Math.max(32,s>>5),h=r<<1,o=r>>1,l=[],a=0,c=-1,f=[];function u(t){let i;if(t.lines>h&&t instanceof n)for(let e of t.children)u(e);else t.lines>o&&(a>o||!a)?(g(),l.push(t)):t instanceof e&&a&&(i=f[f.length-1])instanceof e&&t.lines+i.lines<=32?(a+=t.lines,c+=t.length+1,f[f.length-1]=new e(i.text.concat(t.text),i.length+1+t.length)):(a+t.lines>r&&g(),a+=t.lines,c+=t.length+1,f.push(t))}function g(){0!=a&&(l.push(1==f.length?f[0]:n.from(f,c)),c=-1,a=f.length=0)}for(let e of t)u(e);return g(),1==l.length?l[0]:new n(l,i)}}function i(t,e,n=0,i=1e9){for(let s=0,r=0,h=!0;r=n&&(l>i&&(o=o.slice(0,i-s)),s0?1:(t instanceof e?t.text.length:t.children.length)<<1]}nextInner(t,n){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],h=r>>1,o=s instanceof e?s.text.length:s.children.length;if(h==(n>0?o:0)){if(0==i)return this.done=!0,this.value="",this;n>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((1&r)==(n>0?0:1)){if(this.offsets[i]+=n,0==t)return this.lineBreak=!0,this.value="\n",this;t--}else if(s instanceof e){let e=s.text[h+(n<0?-1:0)];if(this.offsets[i]+=n,e.length>Math.max(0,t))return this.value=0==t?e:n>0?e.slice(t):e.slice(0,e.length-t),this;t-=e.length}else{let r=s.children[h+(n<0?-1:0)];t>r.length?(t-=r.length,this.offsets[i]+=n):(n<0&&this.offsets[i]--,this.nodes.push(r),this.offsets.push(n>0?1:(r instanceof e?r.text.length:r.children.length)<<1))}}}next(t=0){return t<0&&(this.nextInner(-t,-this.dir),t=this.value.length),this.nextInner(t,this.dir)}}class h{constructor(t,e,n){this.value="",this.done=!1,this.cursor=new r(t,e>n?-1:1),this.pos=e>n?t.length:0,this.from=Math.min(e,n),this.to=Math.max(e,n)}nextInner(t,e){if(e<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;t+=Math.max(0,e<0?this.pos-this.to:this.from-this.pos);let n=e<0?this.pos-this.from:this.to-this.pos;t>n&&(t=n),n-=t;let{value:i}=this.cursor.next(t);return this.pos+=(i.length+t)*e,this.value=i.length<=n?i:e<0?i.slice(i.length-n):i.slice(0,n),this.done=!this.value,this}next(t=0){return t<0?t=Math.max(t,this.from-this.pos):t>0&&(t=Math.min(t,this.to-this.pos)),this.nextInner(t,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&""!=this.value}}class o{constructor(t){this.inner=t,this.afterBreak=!0,this.value="",this.done=!1}next(t=0){let{done:e,lineBreak:n,value:i}=this.inner.next(t);return e&&this.afterBreak?(this.value="",this.afterBreak=!1):e?(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}}"undefined"!=typeof Symbol&&(t.prototype[Symbol.iterator]=function(){return this.iter()},r.prototype[Symbol.iterator]=h.prototype[Symbol.iterator]=o.prototype[Symbol.iterator]=function(){return this});class l{constructor(t,e,n,i){this.from=t,this.to=e,this.number=n,this.text=i}get length(){return this.to-this.from}}function a(t,e,n){return[e=Math.max(0,Math.min(t.length,e)),Math.max(e,Math.min(t.length,n))]}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((t=>t?parseInt(t,36):1));for(let t=1;tt)return c[e-1]<=t;return!1}function u(t){return t>=127462&&t<=127487}const g=8205;function d(t,e,n=!0,i=!0){return(n?p:m)(t,e,i)}function p(t,e,n){if(e==t.length)return e;e&&v(t.charCodeAt(e))&&x(t.charCodeAt(e-1))&&e--;let i=w(t,e);for(e+=y(i);e=0&&u(w(t,i));)n++,i-=2;if(n%2==0)break;e+=2}}}return e}function m(t,e,n){for(;e>0;){let i=p(t,e-2,n);if(i=56320&&t<57344}function x(t){return t>=55296&&t<56320}function w(t,e){let n=t.charCodeAt(e);if(!x(n)||e+1==t.length)return n;let i=t.charCodeAt(e+1);return v(i)?i-56320+(n-55296<<10)+65536:n}function k(t){return t<=65535?String.fromCharCode(t):(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t)))}function y(t){return t<65536?1:2}const S=/\r\n?|\n/;var I=function(t){return t[t.Simple=0]="Simple",t[t.TrackDel=1]="TrackDel",t[t.TrackBefore=2]="TrackBefore",t[t.TrackAfter=3]="TrackAfter",t}(I||(I={}));class b{constructor(t){this.sections=t}get length(){let t=0;for(let e=0;et)return s+(t-i);s+=h}else{if(n!=I.Simple&&l>=t&&(n==I.TrackDel&&it||n==I.TrackBefore&&it))return null;if(l>t||l==t&&e<0&&!h)return t==i||e<0?s:s+o;s+=o}i=l}if(t>i)throw new RangeError(`Position ${t} is out of range for changeset of length ${i}`);return s}touchesRange(t,e=t){for(let n=0,i=0;n=0&&i<=e&&s>=t)return!(ie)||"cover";i=s}return!1}toString(){let t="";for(let e=0;e=0?":"+i:"")}return t}toJSON(){return this.sections}static fromJSON(t){if(!Array.isArray(t)||t.length%2||t.some((t=>"number"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeDesc");return new b(t)}static create(t){return new b(t)}}class P extends b{constructor(t,e){super(t),this.inserted=e}apply(t){if(this.length!=t.length)throw new RangeError("Applying change set to a document with the wrong length");return A(this,((e,n,i,s,r)=>t=t.replace(i,i+(n-e),r)),!1),t}mapDesc(t,e=!1){return O(this,t,e,!0)}invert(e){let n=this.sections.slice(),i=[];for(let s=0,r=0;s=0){n[s]=o,n[s+1]=h;let l=s>>1;for(;i.length0&&M(n,e,s.text),s.forward(t),h+=t}let l=t[r++];for(;h>1].toJSON()))}return t}static of(e,n,i){let s=[],r=[],h=0,o=null;function l(t=!1){if(!t&&!s.length)return;ho||e<0||o>n)throw new RangeError(`Invalid change range ${e} to ${o} (in doc of length ${n})`);let f=c?"string"==typeof c?t.of(c.split(i||S)):c:t.empty,u=f.length;if(e==o&&0==u)return;eh&&E(s,e-h,-1),E(s,o-e,u),M(r,s,f),h=o}}(e),l(!o),o}static empty(t){return new P(t?[t,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let n=[],i=[];for(let s=0;se&&"string"!=typeof t)))throw new RangeError("Invalid JSON representation of ChangeSet");if(1==r.length)n.push(r[0],0);else{for(;i.length=0&&n<=0&&n==t[s+1]?t[s]+=e:0==e&&0==t[s]?t[s+1]+=n:i?(t[s]+=e,t[s+1]+=n):t.push(e,n)}function M(e,n,i){if(0==i.length)return;let s=n.length-2>>1;if(s>1])),!(i||o==e.sections.length||e.sections[o+1]<0);)l=e.sections[o++],a=e.sections[o++];n(r,c,h,f,u),r=c,h=f}}}function O(t,e,n,i=!1){let s=[],r=i?[]:null,h=new T(t),o=new T(e);for(let t=-1;;)if(-1==h.ins&&-1==o.ins){let t=Math.min(h.len,o.len);E(s,t,-1),h.forward(t),o.forward(t)}else if(o.ins>=0&&(h.ins<0||t==h.i||0==h.off&&(o.len=0&&t=0)){if(h.done&&o.done)return r?P.createSet(s,r):b.create(s);throw new Error("Mismatched change set lengths")}{let e=0,n=h.len;for(;n;)if(-1==o.ins){let t=Math.min(n,o.len);e+=t,n-=t,o.forward(t)}else{if(!(0==o.ins&&o.lene||h.ins>=0&&h.len>e)&&(t||i.length>n),r.forward2(e),h.forward(e)}}else E(i,0,h.ins,t),s&&M(s,i,h.text),h.next()}}class T{constructor(t){this.set=t,this.i=0,this.next()}next(){let{sections:t}=this.set;this.i>1;return n>=e.length?t.empty:e[n]}textBit(e){let{inserted:n}=this.set,i=this.i-2>>1;return i>=n.length&&!e?t.empty:n[i].slice(this.off,null==e?void 0:this.off+e)}forward(t){t==this.len?this.next():(this.len-=t,this.off+=t)}forward2(t){-1==this.ins?this.forward(t):t==this.ins?this.next():(this.ins-=t,this.off+=t)}}class C{constructor(t,e,n){this.from=t,this.to=e,this.flags=n}get anchor(){return 32&this.flags?this.to:this.from}get head(){return 32&this.flags?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return 8&this.flags?-1:16&this.flags?1:0}get bidiLevel(){let t=7&this.flags;return 7==t?null:t}get goalColumn(){let t=this.flags>>6;return 16777215==t?void 0:t}map(t,e=-1){let n,i;return this.empty?n=i=t.mapPos(this.from,e):(n=t.mapPos(this.from,1),i=t.mapPos(this.to,-1)),n==this.from&&i==this.to?this:new C(n,i,this.flags)}extend(t,e=t){if(t<=this.anchor&&e>=this.anchor)return N.range(t,e);let n=Math.abs(t-this.anchor)>Math.abs(e-this.anchor)?t:e;return N.range(this.anchor,n)}eq(t,e=!1){return!(this.anchor!=t.anchor||this.head!=t.head||e&&this.empty&&this.assoc!=t.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(t){if(!t||"number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid JSON representation for SelectionRange");return N.range(t.anchor,t.head)}static create(t,e,n){return new C(t,e,n)}}class N{constructor(t,e){this.ranges=t,this.mainIndex=e}map(t,e=-1){return t.empty?this:N.create(this.ranges.map((n=>n.map(t,e))),this.mainIndex)}eq(t,e=!1){if(this.ranges.length!=t.ranges.length||this.mainIndex!=t.mainIndex)return!1;for(let n=0;nt.toJSON())),main:this.mainIndex}}static fromJSON(t){if(!t||!Array.isArray(t.ranges)||"number"!=typeof t.main||t.main>=t.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new N(t.ranges.map((t=>C.fromJSON(t))),t.main)}static single(t,e=t){return new N([N.range(t,e)],0)}static create(t,e=0){if(0==t.length)throw new RangeError("A selection needs at least one range");for(let n=0,i=0;it?8:0)|s)}static normalized(t,e=0){let n=t[e];t.sort(((t,e)=>t.from-e.from)),e=t.indexOf(n);for(let n=1;ni.head?N.range(h,r):N.range(r,h))}}return new N(t,e)}}function F(t,e){for(let n of t.ranges)if(n.to>e)throw new RangeError("Selection points outside of document")}let B=0;class J{constructor(t,e,n,i,s){this.combine=t,this.compareInput=e,this.compare=n,this.isStatic=i,this.id=B++,this.default=t([]),this.extensions="function"==typeof s?s(this):s}get reader(){return this}static define(t={}){return new J(t.combine||(t=>t),t.compareInput||((t,e)=>t===e),t.compare||(t.combine?(t,e)=>t===e:D),!!t.static,t.enables)}of(t){return new L([],this,0,t)}compute(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new L(t,this,1,e)}computeN(t,e){if(this.isStatic)throw new Error("Can't compute a static facet");return new L(t,this,2,e)}from(t,e){return e||(e=t=>t),this.compute([t],(n=>e(n.field(t))))}}function D(t,e){return t==e||t.length==e.length&&t.every(((t,n)=>t===e[n]))}class L{constructor(t,e,n,i){this.dependencies=t,this.facet=e,this.type=n,this.value=i,this.id=B++}dynamicSlot(t){var e;let n=this.value,i=this.facet.compareInput,s=this.id,r=t[s]>>1,h=2==this.type,o=!1,l=!1,a=[];for(let n of this.dependencies)"doc"==n?o=!0:"selection"==n?l=!0:0==(1&(null!==(e=t[n.id])&&void 0!==e?e:1))&&a.push(t[n.id]);return{create:t=>(t.values[r]=n(t),1),update(t,e){if(o&&e.docChanged||l&&(e.docChanged||e.selection)||q(t,a)){let e=n(t);if(h?!j(e,t.values[r],i):!i(e,t.values[r]))return t.values[r]=e,1}return 0},reconfigure:(t,e)=>{let o,l=e.config.address[s];if(null!=l){let s=et(e,l);if(this.dependencies.every((n=>n instanceof J?e.facet(n)===t.facet(n):!(n instanceof V)||e.field(n,!1)==t.field(n,!1)))||(h?j(o=n(t),s,i):i(o=n(t),s)))return t.values[r]=s,0}else o=n(t);return t.values[r]=o,1}}}}function j(t,e,n){if(t.length!=e.length)return!1;for(let i=0;it[e.id])),s=n.map((t=>t.type)),r=i.filter((t=>!(1&t))),h=t[e.id]>>1;function o(t){let n=[];for(let e=0;et===e),t);return t.provide&&(e.provides=t.provide(e)),e}create(t){let e=t.facet(z).find((t=>t.field==this));return((null==e?void 0:e.create)||this.createF)(t)}slot(t){let e=t[this.id]>>1;return{create:t=>(t.values[e]=this.create(t),1),update:(t,n)=>{let i=t.values[e],s=this.updateF(i,n);return this.compareF(i,s)?0:(t.values[e]=s,1)},reconfigure:(t,n)=>null!=n.config.address[this.id]?(t.values[e]=n.field(this),0):(t.values[e]=this.create(t),1)}}init(t){return[this,z.of({field:this,create:t})]}get extension(){return this}}const _=4,W=3,U=2,G=1;function H(t){return e=>new Q(e,t)}const K={highest:H(0),high:H(G),default:H(U),low:H(W),lowest:H(_)};class Q{constructor(t,e){this.inner=t,this.prec=e}}class X{of(t){return new Y(this,t)}reconfigure(t){return X.reconfigure.of({compartment:this,extension:t})}get(t){return t.config.compartments.get(this)}}class Y{constructor(t,e){this.compartment=t,this.inner=e}}class Z{constructor(t,e,n,i,s,r){for(this.base=t,this.compartments=e,this.dynamicSlots=n,this.address=i,this.staticValues=s,this.facets=r,this.statusTemplate=[];this.statusTemplate.length>1]}static resolve(t,e,n){let i=[],s=Object.create(null),r=new Map;for(let n of function(t,e,n){let i=[[],[],[],[],[]],s=new Map;function r(t,h){let o=s.get(t);if(null!=o){if(o<=h)return;let e=i[o].indexOf(t);e>-1&&i[o].splice(e,1),t instanceof Y&&n.delete(t.compartment)}if(s.set(t,h),Array.isArray(t))for(let e of t)r(e,h);else if(t instanceof Y){if(n.has(t.compartment))throw new RangeError("Duplicate use of compartment in extensions");let i=e.get(t.compartment)||t.inner;n.set(t.compartment,i),r(i,h)}else if(t instanceof Q)r(t.inner,t.prec);else if(t instanceof V)i[h].push(t),t.provides&&r(t.provides,h);else if(t instanceof L)i[h].push(t),t.facet.extensions&&r(t.facet.extensions,U);else{let e=t.extension;if(!e)throw new Error(`Unrecognized extension value in extension set (${t}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(e,h)}}return r(t,U),i.reduce(((t,e)=>t.concat(e)))}(t,e,r))n instanceof V?i.push(n):(s[n.facet.id]||(s[n.facet.id]=[])).push(n);let h=Object.create(null),o=[],l=[];for(let t of i)h[t.id]=l.length<<1,l.push((e=>t.slot(e)));let a=null==n?void 0:n.config.facets;for(let t in s){let e=s[t],i=e[0].facet,r=a&&a[t]||[];if(e.every((t=>0==t.type)))if(h[i.id]=o.length<<1|1,D(r,e))o.push(n.facet(i));else{let t=i.combine(e.map((t=>t.value)));o.push(n&&i.compare(t,n.facet(i))?n.facet(i):t)}else{for(let t of e)0==t.type?(h[t.id]=o.length<<1|1,o.push(t.value)):(h[t.id]=l.length<<1,l.push((e=>t.dynamicSlot(e))));h[i.id]=l.length<<1,l.push((t=>$(t,i,e)))}}let c=l.map((t=>t(h)));return new Z(t,r,c,h,o,s)}}function tt(t,e){if(1&e)return 2;let n=e>>1,i=t.status[n];if(4==i)throw new Error("Cyclic dependency between fields and/or facets");if(2&i)return i;t.status[n]=4;let s=t.computeSlot(t,t.config.dynamicSlots[n]);return t.status[n]=2|s}function et(t,e){return 1&e?t.config.staticValues[e>>1]:t.values[e>>1]}const nt=J.define(),it=J.define({combine:t=>t.some((t=>t)),static:!0}),st=J.define({combine:t=>t.length?t[0]:void 0,static:!0}),rt=J.define(),ht=J.define(),ot=J.define(),lt=J.define({combine:t=>!!t.length&&t[0]});class at{constructor(t,e){this.type=t,this.value=e}static define(){return new ct}}class ct{of(t){return new at(this,t)}}class ft{constructor(t){this.map=t}of(t){return new ut(this,t)}}class ut{constructor(t,e){this.type=t,this.value=e}map(t){let e=this.type.map(this.value,t);return void 0===e?void 0:e==this.value?this:new ut(this.type,e)}is(t){return this.type==t}static define(t={}){return new ft(t.map||(t=>t))}static mapEffects(t,e){if(!t.length)return t;let n=[];for(let i of t){let t=i.map(e);t&&n.push(t)}return n}}ut.reconfigure=ut.define(),ut.appendConfig=ut.define();class gt{constructor(t,e,n,i,s,r){this.startState=t,this.changes=e,this.selection=n,this.effects=i,this.annotations=s,this.scrollIntoView=r,this._doc=null,this._state=null,n&&F(n,e.newLength),s.some((t=>t.type==gt.time))||(this.annotations=s.concat(gt.time.of(Date.now())))}static create(t,e,n,i,s,r){return new gt(t,e,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(t){for(let e of this.annotations)if(e.type==t)return e.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(t){let e=this.annotation(gt.userEvent);return!(!e||!(e==t||e.length>t.length&&e.slice(0,t.length)==t&&"."==e[t.length]))}}function dt(t,e){let n=[];for(let i=0,s=0;;){let r,h;if(i=t[i]))r=t[i++],h=t[i++];else{if(!(s=0;s--){let r=n[s](t);r&&Object.keys(r).length&&(i=pt(i,mt(e,r,t.changes.newLength),!0))}return i==t?t:gt.create(e,t.changes,t.selection,i.effects,i.annotations,i.scrollIntoView)}(n?function(t){let e=t.startState,n=!0;for(let i of e.facet(rt)){let e=i(t);if(!1===e){n=!1;break}Array.isArray(e)&&(n=!0===n?e:dt(n,e))}if(!0!==n){let i,s;if(!1===n)s=t.changes.invertedDesc,i=P.empty(e.doc.length);else{let e=t.changes.filter(n);i=e.changes,s=e.filtered.mapDesc(e.changes).invertedDesc}t=gt.create(e,i,t.selection&&t.selection.map(s),ut.mapEffects(t.effects,s),t.annotations,t.scrollIntoView)}let i=e.facet(ht);for(let n=i.length-1;n>=0;n--){let s=i[n](t);t=s instanceof gt?s:Array.isArray(s)&&1==s.length&&s[0]instanceof gt?s[0]:vt(e,wt(s),!1)}return t}(s):s)}gt.time=at.define(),gt.userEvent=at.define(),gt.addToHistory=at.define(),gt.remote=at.define();const xt=[];function wt(t){return null==t?xt:Array.isArray(t)?t:[t]}var kt=function(t){return t[t.Word=0]="Word",t[t.Space=1]="Space",t[t.Other=2]="Other",t}(kt||(kt={}));const yt=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let St;try{St=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch(t){}function It(t){return e=>{if(!/\S/.test(e))return kt.Space;if(function(t){if(St)return St.test(t);for(let e=0;e"€"&&(n.toUpperCase()!=n.toLowerCase()||yt.test(n)))return!0}return!1}(e))return kt.Word;for(let n=0;n-1)return kt.Word;return kt.Other}}class bt{constructor(t,e,n,i,s,r){this.config=t,this.doc=e,this.selection=n,this.values=i,this.status=t.statusTemplate.slice(),this.computeSlot=s,r&&(r._state=this);for(let t=0;ts.set(e,t))),n=null),s.set(e.value.compartment,e.value.extension)):e.is(ut.reconfigure)?(n=null,i=e.value):e.is(ut.appendConfig)&&(n=null,i=wt(i).concat(e.value));if(n)e=t.startState.values.slice();else{n=Z.resolve(i,s,this),e=new bt(n,this.doc,this.selection,n.dynamicSlots.map((()=>null)),((t,e)=>e.reconfigure(t,this)),null).values}let r=t.startState.facet(it)?t.newSelection:t.newSelection.asSingle();new bt(n,t.newDoc,r,e,((e,n)=>n.update(e,t)),t)}replaceSelection(t){return"string"==typeof t&&(t=this.toText(t)),this.changeByRange((e=>({changes:{from:e.from,to:e.to,insert:t},range:N.cursor(e.from+t.length)})))}changeByRange(t){let e=this.selection,n=t(e.ranges[0]),i=this.changes(n.changes),s=[n.range],r=wt(n.effects);for(let n=1;ns.spec.fromJSON(r,t))))}return bt.create({doc:t.doc,selection:N.fromJSON(t.selection),extensions:e.extensions?i.concat([e.extensions]):i})}static create(e={}){let n=Z.resolve(e.extensions||[],new Map),i=e.doc instanceof t?e.doc:t.of((e.doc||"").split(n.staticFacet(bt.lineSeparator)||S)),s=e.selection?e.selection instanceof N?e.selection:N.single(e.selection.anchor,e.selection.head):N.single(0);return F(s,i.length),n.staticFacet(it)||(s=s.asSingle()),new bt(n,i,s,n.dynamicSlots.map((()=>null)),((t,e)=>e.create(t)),null)}get tabSize(){return this.facet(bt.tabSize)}get lineBreak(){return this.facet(bt.lineSeparator)||"\n"}get readOnly(){return this.facet(lt)}phrase(t,...e){for(let e of this.facet(bt.phrases))if(Object.prototype.hasOwnProperty.call(e,t)){t=e[t];break}return e.length&&(t=t.replace(/\$(\$|\d*)/g,((t,n)=>{if("$"==n)return"$";let i=+(n||1);return!i||i>e.length?t:e[i-1]}))),t}languageDataAt(t,e,n=-1){let i=[];for(let s of this.facet(nt))for(let r of s(this,e,n))Object.prototype.hasOwnProperty.call(r,t)&&i.push(r[t]);return i}charCategorizer(t){return It(this.languageDataAt("wordChars",t).join(""))}wordAt(t){let{text:e,from:n,length:i}=this.doc.lineAt(t),s=this.charCategorizer(t),r=t-n,h=t-n;for(;r>0;){let t=d(e,r,!1);if(s(e.slice(t,r))!=kt.Word)break;r=t}for(;ht.length?t[0]:4}),bt.lineSeparator=st,bt.readOnly=lt,bt.phrases=J.define({compare(t,e){let n=Object.keys(t),i=Object.keys(e);return n.length==i.length&&n.every((n=>t[n]==e[n]))}}),bt.languageData=nt,bt.changeFilter=rt,bt.transactionFilter=ht,bt.transactionExtender=ot,X.reconfigure=ut.define();class Et{eq(t){return this==t}range(t,e=t){return Mt.create(t,e,this)}}Et.prototype.startSide=Et.prototype.endSide=0,Et.prototype.point=!1,Et.prototype.mapMode=I.TrackDel;class Mt{constructor(t,e,n){this.from=t,this.to=e,this.value=n}static create(t,e,n){return new Mt(t,e,n)}}function At(t,e){return t.from-e.from||t.value.startSide-e.value.startSide}class Ot{constructor(t,e,n,i){this.from=t,this.to=e,this.value=n,this.maxPoint=i}get length(){return this.to[this.to.length-1]}findIndex(t,e,n,i=0){let s=n?this.to:this.from;for(let r=i,h=s.length;;){if(r==h)return r;let i=r+h>>1,o=s[i]-t||(n?this.value[i].endSide:this.value[i].startSide)-e;if(i==r)return o>=0?r:h;o>=0?h=i:r=i+1}}between(t,e,n,i){for(let s=this.findIndex(e,-1e9,!0),r=this.findIndex(n,1e9,!1,s);sa||l==a&&c.startSide>0&&c.endSide<=0)continue;(a-l||c.endSide-c.startSide)<0||(r<0&&(r=l),c.point&&(h=Math.max(h,a-l)),n.push(c),i.push(l-r),s.push(a-r))}return{mapped:n.length?new Ot(i,s,n,h):null,pos:r}}}class Rt{constructor(t,e,n,i){this.chunkPos=t,this.chunk=e,this.nextLayer=n,this.maxPoint=i}static create(t,e,n,i){return new Rt(t,e,n,i)}get length(){let t=this.chunk.length-1;return t<0?0:Math.max(this.chunkEnd(t),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let t=this.nextLayer.size;for(let e of this.chunk)t+=e.value.length;return t}chunkEnd(t){return this.chunkPos[t]+this.chunk[t].length}update(t){let{add:e=[],sort:n=!1,filterFrom:i=0,filterTo:s=this.length}=t,r=t.filter;if(0==e.length&&!r)return this;if(n&&(e=e.slice().sort(At)),this.isEmpty)return e.length?Rt.of(e):this;let h=new Nt(this,null,-1).goto(0),o=0,l=[],a=new Tt;for(;h.value||o=0){let t=e[o++];a.addInner(t.from,t.to,t.value)||l.push(t)}else 1==h.rangeIndex&&h.chunkIndexthis.chunkEnd(h.chunkIndex)||sh.to||s=s&&t<=s+r.length&&!1===r.between(s,t-s,e-s,n))return}this.nextLayer.between(t,e,n)}}iter(t=0){return Ft.from([this]).goto(t)}get isEmpty(){return this.nextLayer==this}static iter(t,e=0){return Ft.from(t).goto(e)}static compare(t,e,n,i,s=-1){let r=t.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s)),h=e.filter((t=>t.maxPoint>0||!t.isEmpty&&t.maxPoint>=s)),o=Ct(r,h,n),l=new Jt(r,o,s),a=new Jt(h,o,s);n.iterGaps(((t,e,n)=>Dt(l,t,a,e,n,i))),n.empty&&0==n.length&&Dt(l,0,a,0,0,i)}static eq(t,e,n=0,i){null==i&&(i=999999999);let s=t.filter((t=>!t.isEmpty&&e.indexOf(t)<0)),r=e.filter((e=>!e.isEmpty&&t.indexOf(e)<0));if(s.length!=r.length)return!1;if(!s.length)return!0;let h=Ct(s,r),o=new Jt(s,h,0).goto(n),l=new Jt(r,h,0).goto(n);for(;;){if(o.to!=l.to||!Lt(o.active,l.active)||o.point&&(!l.point||!o.point.eq(l.point)))return!1;if(o.to>i)return!0;o.next(),l.next()}}static spans(t,e,n,i,s=-1){let r=new Jt(t,null,s).goto(e),h=e,o=r.openStart;for(;;){let t=Math.min(r.to,n);if(r.point){let n=r.activeForPoint(r.to),s=r.pointFromh&&(i.span(h,t,r.active,o),o=r.openEnd(t));if(r.to>n)return o+(r.point&&r.to>n?1:0);h=r.to,r.next()}}static of(t,e=!1){let n=new Tt;for(let i of t instanceof Mt?[t]:e?function(t){if(t.length>1)for(let e=t[0],n=1;n0)return t.slice().sort(At);e=i}return t}(t):t)n.add(i.from,i.to,i.value);return n.finish()}static join(t){if(!t.length)return Rt.empty;let e=t[t.length-1];for(let n=t.length-2;n>=0;n--)for(let i=t[n];i!=Rt.empty;i=i.nextLayer)e=new Rt(i.chunkPos,i.chunk,e,Math.max(i.maxPoint,e.maxPoint));return e}}Rt.empty=new Rt([],[],null,-1),Rt.empty.nextLayer=Rt.empty;class Tt{finishChunk(t){this.chunks.push(new Ot(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,t&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(t,e,n){this.addInner(t,e,n)||(this.nextLayer||(this.nextLayer=new Tt)).add(t,e,n)}addInner(t,e,n){let i=t-this.lastTo||n.startSide-this.last.endSide;if(i<=0&&(t-this.lastFrom||n.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return!(i<0)&&(250==this.from.length&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=t),this.from.push(t-this.chunkStart),this.to.push(e-this.chunkStart),this.last=n,this.lastFrom=t,this.lastTo=e,this.value.push(n),n.point&&(this.maxPoint=Math.max(this.maxPoint,e-t)),!0)}addChunk(t,e){if((t-this.lastTo||e.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,e.maxPoint),this.chunks.push(e),this.chunkPos.push(t);let n=e.value.length-1;return this.last=e.value[n],this.lastFrom=e.from[n]+t,this.lastTo=e.to[n]+t,!0}finish(){return this.finishInner(Rt.empty)}finishInner(t){if(this.from.length&&this.finishChunk(!1),0==this.chunks.length)return t;let e=Rt.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(t):t,this.setMaxPoint);return this.from=null,e}}function Ct(t,e,n){let i=new Map;for(let e of t)for(let t=0;t=this.minPoint)break}}}setRangeIndex(t){if(t==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex=n&&i.push(new Nt(r,e,n,s));return 1==i.length?i[0]:new Ft(i)}get startSide(){return this.value?this.value.startSide:0}goto(t,e=-1e9){for(let n of this.heap)n.goto(t,e);for(let t=this.heap.length>>1;t>=0;t--)Bt(this.heap,t);return this.next(),this}forward(t,e){for(let n of this.heap)n.forward(t,e);for(let t=this.heap.length>>1;t>=0;t--)Bt(this.heap,t);(this.to-t||this.value.endSide-e)<0&&this.next()}next(){if(0==this.heap.length)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let t=this.heap[0];this.from=t.from,this.to=t.to,this.value=t.value,this.rank=t.rank,t.value&&t.next(),Bt(this.heap,0)}}}function Bt(t,e){for(let n=t[e];;){let i=1+(e<<1);if(i>=t.length)break;let s=t[i];if(i+1=0&&(s=t[i+1],i++),n.compare(s)<0)break;t[i]=n,t[e]=s,e=i}}class Jt{constructor(t,e,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=Ft.from(t,e,n)}goto(t,e=-1e9){return this.cursor.goto(t,e),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=t,this.endSide=e,this.openStart=-1,this.next(),this}forward(t,e){for(;this.minActive>-1&&(this.activeTo[this.minActive]-t||this.active[this.minActive].endSide-e)<0;)this.removeActive(this.minActive);this.cursor.forward(t,e)}removeActive(t){jt(this.active,t),jt(this.activeTo,t),jt(this.activeRank,t),this.minActive=$t(this.active,this.activeTo)}addActive(t){let e=0,{value:n,to:i,rank:s}=this.cursor;for(;e0;)e++;qt(this.active,e,n),qt(this.activeTo,e,i),qt(this.activeRank,e,s),t&&qt(t,e,this.cursor.from),this.minActive=$t(this.active,this.activeTo)}next(){let t=this.to,e=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]>t){this.to=this.activeTo[i],this.endSide=this.active[i].endSide;break}this.removeActive(i),n&&jt(n,i)}else{if(!this.cursor.value){this.to=this.endSide=1e9;break}if(this.cursor.from>t){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}{let t=this.cursor.value;if(t.point){if(!(e&&this.cursor.to==this.to&&this.cursor.from=0&&n[e]=0&&!(this.activeRank[n]t||this.activeTo[n]==t&&this.active[n].endSide>=this.point.endSide)&&e.push(this.active[n]);return e.reverse()}openEnd(t){let e=0;for(let n=this.activeTo.length-1;n>=0&&this.activeTo[n]>t;n--)e++;return e}}function Dt(t,e,n,i,s,r){t.goto(e),n.goto(i);let h=i+s,o=i,l=i-e;for(;;){let e=t.to+l-n.to||t.endSide-n.endSide,i=e<0?t.to+l:n.to,s=Math.min(i,h);if(t.point||n.point?t.point&&n.point&&(t.point==n.point||t.point.eq(n.point))&&Lt(t.activeForPoint(t.to),n.activeForPoint(n.to))||r.comparePoint(o,s,t.point,n.point):s>o&&!Lt(t.active,n.active)&&r.compareRange(o,s,t.active,n.active),i>h)break;o=i,e<=0&&t.next(),e>=0&&n.next()}}function Lt(t,e){if(t.length!=e.length)return!1;for(let n=0;n=e;n--)t[n+1]=t[n];t[e]=n}function $t(t,e){let n=-1,i=1e9;for(let s=0;s=e)return i;if(i==t.length)break;s+=9==t.charCodeAt(i)?n-s%n:1,i=d(t,i)}return!0===i?-1:t.length}export{at as Annotation,ct as AnnotationType,b as ChangeDesc,P as ChangeSet,kt as CharCategory,X as Compartment,N as EditorSelection,bt as EditorState,J as Facet,l as Line,I as MapMode,K as Prec,Mt as Range,Rt as RangeSet,Tt as RangeSetBuilder,Et as RangeValue,C as SelectionRange,ut as StateEffect,ft as StateEffectType,V as StateField,t as Text,gt as Transaction,w as codePointAt,y as codePointSize,Pt as combineConfig,zt as countColumn,d as findClusterBreak,Vt as findColumn,k as fromCodePoint}; //# sourceMappingURL=codemirror_state-BKbyfKsm.js.map